//_____________________________________________________________________________
AliMUONPreprocessor::AliMUONPreprocessor(const char* detName, AliShuttleInterface* shuttle)
: AliPreprocessor(detName, shuttle),
+ fIsValid(kFALSE),
fSubprocessors(new TObjArray()),
- fProcessDCS(kFALSE),
- fIsValid(kFALSE)
+ fProcessDCS(kFALSE)
{
/// ctor
}
#include "AliMUONTriggerIO.h"
#include "AliLog.h"
+#include "AliMpCDB.h"
#include "AliMpDDLStore.h"
#include "AliMpTriggerCrate.h"
+#include "AliMUONTriggerLut.h"
#include "AliMUONCalibParamNI.h"
#include "AliMUONVStore.h"
#include <Riostream.h>
/// to be used by Shuttle and Trigger DA.
///
/// \author Laurent Aphecetche, Subatech
+/// \author Bogdan Vulpescu, LPC Clermont-Ferrand
/// \cond CLASSIMP
ClassImp(AliMUONTriggerIO)
/// ctor
}
+//_____________________________________________________________________________
+AliMUONTriggerIO::AliMUONTriggerIO(const char* regionalFileToRead) :
+TObject(), fLocalBoardIds(), fNofLocalBoards(0)
+{
+ /// ctor
+ ReadRegional(regionalFileToRead,0);
+}
+
//_____________________________________________________________________________
AliMUONTriggerIO::~AliMUONTriggerIO()
{
/// dtor
}
+//_____________________________________________________________________________
+void
+AliMUONTriggerIO::DeCompAddress(UChar_t &ypos, UChar_t &ytri, UChar_t &xdev, UChar_t &xpos,
+ UShort_t address) const
+{
+ /// decompose the 15-bits address
+
+ UChar_t bitsYpos = 4;
+ UChar_t bitsYtri = 1;
+ UChar_t bitsXdev = 5;
+ // UChar_t bitsXpos = 5;
+
+ UShort_t maskYpos = 0x000F; // ...0 00001111
+ UShort_t maskYtri = 0x0001; // ...0 00000001
+ UShort_t maskXdev = 0x001F; // ...0 00011111
+ UShort_t maskXpos = 0x001F; // ...0 00011111
+
+ ypos = address & maskYpos;
+ ytri = (address >> bitsYpos) & maskYtri;
+ xdev = (address >> (bitsYpos+bitsYtri)) & maskXdev;
+ xpos = (address >> (bitsYpos+bitsYtri+bitsXdev)) & maskXpos;
+}
+
+//_____________________________________________________________________________
+void
+AliMUONTriggerIO::FillLut(AliMUONTriggerLut& lut,
+ Int_t icirc, UChar_t istripX, UChar_t idev,
+ Int_t lutLpt[16][2], Int_t lutHpt[16][2])
+{
+ /// Fill the LUT histograms
+
+ if (icirc == 0 && istripX == 0 && idev == 0)
+ {
+ AliDebug(1,"Copy board, not filled ...");
+ return;
+ }
+
+ Short_t iLptPlus, iLptMinu, iLptUnde;
+ Short_t iHptPlus, iHptMinu, iHptUnde;
+
+ iLptPlus = iLptMinu = iLptUnde = 0;
+ iHptPlus = iHptMinu = iHptUnde = 0;
+
+ for (Int_t istripY=0; istripY<16; istripY++)
+ {
+ if (lutLpt[istripY][1] == 0 && lutLpt[istripY][0] ==1)
+ iLptMinu=iLptMinu+(1 << istripY);
+ if (lutLpt[istripY][1] == 1 && lutLpt[istripY][0] ==0)
+ iLptPlus=iLptPlus+(1 << istripY);
+ if (lutLpt[istripY][1] == 1 && lutLpt[istripY][0] ==1)
+ iLptUnde=iLptUnde+(1 << istripY);
+
+ if (lutHpt[istripY][1] == 0 && lutHpt[istripY][0] ==1)
+ iHptMinu=iHptMinu+(1 << istripY);
+ if (lutHpt[istripY][1] == 1 && lutHpt[istripY][0] ==0)
+ iHptPlus=iHptPlus+(1 << istripY);
+ if (lutHpt[istripY][1] == 1 && lutHpt[istripY][0] ==1)
+ iHptUnde=iHptUnde+(1 << istripY);
+
+ } // loop on istripY
+
+ lut.SetContent("LptMinu",icirc,istripX,idev,iLptMinu);
+ lut.SetContent("LptUnde",icirc,istripX,idev,iLptUnde);
+ lut.SetContent("LptPlus",icirc,istripX,idev,iLptPlus);
+
+ lut.SetContent("HptMinu",icirc,istripX,idev,iLptMinu);
+ lut.SetContent("HptUnde",icirc,istripX,idev,iLptUnde);
+ lut.SetContent("HptPlus",icirc,istripX,idev,iLptPlus);
+}
+
//_____________________________________________________________________________
Int_t
AliMUONTriggerIO::LocalBoardId(Int_t index) const
return nLocalBoards;
}
+//_____________________________________________________________________________
+void
+AliMUONTriggerIO::ReadLocalLUT(AliMUONTriggerLut& lut,
+ Int_t localBoardId,
+ FILE* flut)
+{
+ /// Read the LUT for one local board from an online file
+
+ UShort_t address;
+
+ UChar_t buffer;
+ UChar_t mask1 = 0xF0;
+ UChar_t mask2 = 0x0F;
+ UChar_t maskLpt = 0x0C;
+ UChar_t maskHpt = 0x03;
+ UChar_t lh, lpt, hpt;
+
+ UChar_t xpos, xdev, ypos, ytri;
+
+ Int_t lutLpt[16][2], lutHpt[16][2];
+
+ Int_t boardnr = localBoardId;
+
+ AliDebug(1,Form("Reading LUT values for local board %d",boardnr));
+
+ Int_t ny = 0;
+
+ // create the 32767 addresses for the 4-bits lpt and hpt half-bytes
+ for (UShort_t ilut = 0; ilut < 0x7FFF; ilut += 2)
+ {
+ // read two lut addresses at once
+ fread(&buffer,1,1,flut);
+
+ // 1st 4-bits half-byte
+ address = ilut;
+ lh = (buffer & mask1) >> 4;
+
+ // Lpt and Hpt response
+ lpt = (lh & maskLpt) >> 2;
+ hpt = lh & maskHpt;
+
+ // decompose the 15-bits address
+ DeCompAddress(ypos,ytri,xdev,xpos,address);
+
+ // calculate group of y-strips
+ if (ny < 16)
+ {
+ lutLpt[ny][0] = lpt & 1;
+ lutLpt[ny][1] = (lpt & 2) >> 1;
+ lutHpt[ny][0] = hpt & 1;
+ lutHpt[ny][1] = (hpt & 2) >> 1;
+ ny++;
+ if (ny == 16)
+ {
+ ny = 0;
+ // ytri == 1 means no trigger in y-direction
+ if (ytri == 0)
+ {
+ FillLut(lut,boardnr,xpos,xdev,lutLpt,lutHpt);
+ }
+ }
+ }
+
+ // 2nd 4-bits half-byte
+ address = ilut+1;
+ lh = (buffer & mask2);
+
+ // Lpt and Hpt response
+ lpt = (lh & maskLpt) >> 2;
+ hpt = lh & maskHpt;
+
+ // decompose the 15-bits address
+ DeCompAddress(ypos,ytri,xdev,xpos,address);
+
+ // calculate group of y-strips
+ if (ny < 16)
+ {
+ lutLpt[ny][0] = lpt & 1;
+ lutLpt[ny][1] = (lpt & 2) >> 1;
+ lutHpt[ny][0] = hpt & 1;
+ lutHpt[ny][1] = (hpt & 2) >> 1;
+ ny++;
+ if (ny == 16)
+ {
+ ny = 0;
+ // ytri == 1 means no trigger in y-direction
+ if (ytri == 0)
+ {
+ FillLut(lut,boardnr,xpos,xdev,lutLpt,lutHpt);
+ }
+ }
+ }
+ }
+}
+
+//_____________________________________________________________________________
+Bool_t
+AliMUONTriggerIO::ReadLUT(const char* lutFileToRead, AliMUONTriggerLut& lut)
+{
+ /// Fill the LUT object from online file
+
+ if ( !NofLocalBoards() )
+ {
+ AliError("No local board id defined. Must read a regional file first");
+ return kFALSE;
+ }
+
+ FILE* flut = fopen(gSystem->ExpandPathName(lutFileToRead),"rb");
+ if (!flut)
+ {
+ AliError(Form("Could not create output LUT file %s",lutFileToRead));
+ return kFALSE;
+ }
+
+ for ( Int_t i = 0; i < NofLocalBoards(); ++i )
+ {
+ ReadLocalLUT(lut,LocalBoardId(i),flut);
+ }
+
+ fclose(flut);
+
+ return kTRUE;
+
+}
+
//_____________________________________________________________________________
Bool_t
AliMUONTriggerIO::ReadMasks(const char* localFile,
const char* regionalFile,
- const char* globalFile,
+ const char* /* globalFile */,
AliMUONVStore* localMasks,
AliMUONVStore* regionalMasks,
- AliMUONVCalibParam* globalMasks)
+ AliMUONVCalibParam* /* globalMasks */)
{
/// Fill the various masks store from files
Int_t nCrates(0);
+ if (!AliMpDDLStore::Instance(kFALSE))
+ {
+ AliMpCDB::LoadDDLStore();
+ }
+
while (!in.eof())
{
in.getline(name,80);
return nCrates;
}
+
+//_____________________________________________________________________________
+Bool_t
+AliMUONTriggerIO::WriteLUT(const AliMUONTriggerLut& lut,
+ const char* lutFileToWrite)
+{
+ /// Convert an offline lut into an online (binary) lut file
+
+ if ( !NofLocalBoards() )
+ {
+ AliError("No local board id defined. Must read a regional file first");
+ return kFALSE;
+ }
+
+ FILE* flut = fopen(gSystem->ExpandPathName(lutFileToWrite),"wb");
+ if (!flut)
+ {
+ AliError(Form("Could not create output LUT file %s",lutFileToWrite));
+ return kFALSE;
+ }
+
+ for ( Int_t i = 0; i < NofLocalBoards(); ++i )
+ {
+ WriteLocalLUT(lut,LocalBoardId(i),flut);
+ }
+
+ fclose(flut);
+
+ return kTRUE;
+}
+
+//_____________________________________________________________________________
+void
+AliMUONTriggerIO::WriteLocalLUT(const AliMUONTriggerLut& lut,
+ Int_t localBoardId,
+ FILE* flut)
+{
+ /// loop over the address for the 4-bits lpt and hpt decisions
+
+ const Int_t kMaskYpos = 0x0F;
+ const Int_t kMaskYtri = 0x01;
+ const Int_t kMaskXdev = 0x1F;
+ const Int_t kMaskXpos = 0x1F;
+
+ for (Int_t i = 0; i < 32768; ++i)
+ {
+ Int_t lutLpt[2] = { 0 };
+ Int_t lutHpt[2] = { 0 };
+
+ // decompose address
+ Int_t iYpos = i & kMaskYpos;
+ Int_t iYtri = ( i >> 4 ) & kMaskYtri;
+ Int_t iXdev = ( i >> ( 4 + 1 ) ) & kMaskXdev;
+ Int_t iXpos = ( i >> ( 4 + 1 + 5 ) ) & kMaskXpos;
+
+ // iYtri == 1 means no trigger in y-direction
+ if (iYtri == 0)
+ {
+ lut.GetLutOutput(localBoardId,iXpos,iXdev,iYpos,lutLpt,lutHpt);
+ }
+
+ UChar_t buffer;
+
+ // fill byte
+ if (i%2 == 0)
+ {
+ // upper half-byte
+ buffer = 0;
+ buffer += lutLpt[1] << 7;
+ buffer += lutLpt[0] << 6;
+ buffer += lutHpt[1] << 5;
+ buffer += lutHpt[0] << 4;
+ } else {
+ // lower half-byte
+ buffer += lutLpt[1] << 3;
+ buffer += lutLpt[0] << 2;
+ buffer += lutHpt[1] << 1;
+ buffer += lutHpt[0] << 0;
+ fwrite(&buffer,1,1,flut);
+ }
+ }
+}
+
// Author Laurent Aphecetche, Subatech
#ifndef ROOT_TArrayI
-# include "TArrayI.h"
+# include <TArrayI.h>
#endif
#ifndef ROOT_TObject
-# include "TObject.h"
+# include <TObject.h>
#endif
-//class AliMUONTriggerLut;
+#include <Riostream.h>
+
+class AliMUONTriggerLut;
class AliMUONVCalibParam;
class AliMUONVStore;
{
public:
AliMUONTriggerIO();
+ AliMUONTriggerIO(const char* regionalFileToRead);
virtual ~AliMUONTriggerIO();
Bool_t ReadMasks(const char* localFile,
AliMUONVStore* regionalMasks,
AliMUONVCalibParam* globalMasks);
+ Bool_t ReadLUT(const char* lutFileToRead, AliMUONTriggerLut& lut);
+
+ Bool_t WriteLUT(const AliMUONTriggerLut& lut,
+ const char* lutFileToWrite);
+
// void SetLocalBoardIds(const TArrayI& localBoardIds);
// Bool_t WriteMasks(AliMUONVStore* localMasks,
private:
+ void DeCompAddress(UChar_t &ypos, UChar_t &ytri, UChar_t &xdev, UChar_t &xpos,
+ UShort_t address) const;
+
+ void FillLut(AliMUONTriggerLut& lut,
+ Int_t icirc, UChar_t istripX, UChar_t idev,
+ Int_t lutLpt[16][2], Int_t lutHpt[16][2]) ;
+
Int_t LocalBoardId(Int_t index) const;
/// Return number of local boards
Int_t ReadLocalMasks(const char* localFile, AliMUONVStore& localMasks) const;
+ void ReadLocalLUT(AliMUONTriggerLut& lut, Int_t localBoardId, FILE* flut);
+
+ void WriteLocalLUT(const AliMUONTriggerLut& lut, Int_t localBoardId,
+ FILE* flut);
+
// void WriteRegional() const;
private:
/// Local Trigger Look Up Table
/// reading interface LUT data is stored into TH3S histograms and readout
/// from the Local Trigger algorithm
+///
+/// Histograms structure is :
+/// X 234 bins, 1 to 235 = local board number
+/// Y 31 bins, 0 to 31 = x strip
+/// Z 31 bins, 0 to 31 = x deviation
+/// content = Short_t = y strip mask
+///
+/// overflow bin is used !
+///
/// \author Philippe Crochet
//-----------------------------------------------------------------------------
#include "AliLog.h"
-#include "TFile.h"
-#include "TH3.h"
+#include <TFile.h>
+#include <TH3.h>
+#include <TMap.h>
+#include <TObjString.h>
/// \cond CLASSIMP
ClassImp(AliMUONTriggerLut)
fHptUnde(0),
fAptPlus(0),
fAptMinu(0),
- fAptUnde(0)
+ fAptUnde(0),
+ fMap(0x0)
{
/// ctor
}
delete fAptPlus;
delete fAptMinu;
delete fAptUnde;
+ delete fMap;
+}
+
+//----------------------------------------------------------------------
+Int_t
+AliMUONTriggerLut::Compare(TH3* h1, TH3* h2) const
+{
+/// Return 0 if both histograms are strictly equal (at the bin-by-bin level)
+
+ AliDebug(1,Form("h1 %s h2 %s",h1 ? h1->GetName() : "null", h2 ? h2->GetName() : "null"));
+
+ if (!h1 || !h2)
+ {
+ return 0;
+ }
+
+ for ( Int_t i = 0; i < h1->GetBufferSize(); ++i )
+ {
+ Double_t x1 = h1->GetBinContent(i);
+ Double_t x2 = h2->GetBinContent(i);
+ if ( x1 != x2 ) return 0;
+ }
+
+ AliDebug(1,"same");
+
+ return 1;
+}
+
+//----------------------------------------------------------------------
+Int_t
+AliMUONTriggerLut::Compare(const TObject* object) const
+{
+/// Return 0 if the two luts are strictly equal
+
+ const AliMUONTriggerLut* lut = static_cast<const AliMUONTriggerLut*>(object);
+
+ Int_t rvLpt(0);
+
+ rvLpt += Compare(fLptPlus,lut->fLptPlus);
+ rvLpt += Compare(fLptMinu,lut->fLptMinu);
+ rvLpt += Compare(fLptUnde,lut->fLptUnde);
+
+ Int_t rvHpt(0);
+
+ rvHpt += Compare(fHptPlus,lut->fHptPlus);
+ rvHpt += Compare(fHptMinu,lut->fHptMinu);
+ rvHpt += Compare(fHptUnde,lut->fHptUnde);
+
+ Int_t rv(0);
+
+ rv += Compare(fAptPlus,lut->fAptPlus);
+ rv += Compare(fAptMinu,lut->fAptMinu);
+ rv += Compare(fAptUnde,lut->fAptUnde);
+
+ AliDebug(1,Form("Same Lpt %d Hpt %d Apt %d",rvLpt,rvHpt,rv));
+
+ if ( rvLpt == 3 && rvHpt == 3 )
+ {
+ return 0;
+ }
+
+ return 1;
}
//----------------------------------------------------------------------
AliDebug(1,Form("filename=%s",filename));
-// fLptPlus = (TH3*)(f.Get("LptPlus")->Clone());
-// fLptMinu = (TH3*)(f.Get("LptMinu")->Clone());
-// fLptUnde = (TH3*)(f.Get("LptUnde")->Clone());
-// fHptPlus = (TH3*)(f.Get("HptPlus")->Clone());
-// fHptMinu = (TH3*)(f.Get("HptMinu")->Clone());
-// fHptUnde = (TH3*)(f.Get("HptUnde")->Clone());
-// fAptPlus = (TH3*)(f.Get("AptPlus")->Clone());
-// fAptMinu = (TH3*)(f.Get("AptMinu")->Clone());
-// fAptUnde = (TH3*)(f.Get("AptUnde")->Clone());
-
fLptPlus = (TH3*)(f.Get("LptPlus"));
fLptMinu = (TH3*)(f.Get("LptMinu"));
fLptUnde = (TH3*)(f.Get("LptUnde"));
fAptPlus->SetDirectory(0);
fAptMinu->SetDirectory(0);
fAptUnde->SetDirectory(0);
+
+ RegisterHistos();
+}
+
+//----------------------------------------------------------------------
+void
+AliMUONTriggerLut::RegisterHistos()
+{
+/// Add histos to our internal map
+
+ Add(fLptPlus);
+ Add(fLptMinu);
+ Add(fLptUnde);
+
+ Add(fHptPlus);
+ Add(fHptMinu);
+ Add(fHptUnde);
+
+ Add(fAptPlus);
+ Add(fAptMinu);
+ Add(fAptUnde);
+}
+
+//----------------------------------------------------------------------
+void
+AliMUONTriggerLut::Add(TH3* h)
+{
+ /// Update internal map
+ if (!fMap)
+ {
+ fMap = new TMap;
+ fMap->SetOwner(kTRUE);
+ }
+
+ if (h) fMap->Add(new TObjString(h->GetName()),h);
+}
+
+//----------------------------------------------------------------------
+void
+AliMUONTriggerLut::SetContent(const char* hname, Int_t icirc, UChar_t istripX,
+ UChar_t idev, Short_t value)
+{
+ /// Set the content of one bin of one histogram
+
+ if (!fMap)
+ {
+ //..........................................circuit/stripX/deviation
+ fLptPlus = new TH3S("LptPlus","LptPlus",234,0,234,31,0,31,31,0,31);
+ fLptMinu = new TH3S("LptMinu","LptMinu",234,0,234,31,0,31,31,0,31);
+ fLptUnde = new TH3S("LptUnde","LptUnde",234,0,234,31,0,31,31,0,31);
+
+ fHptPlus = new TH3S("HptPlus","HptPlus",234,0,234,31,0,31,31,0,31);
+ fHptMinu = new TH3S("HptMinu","HptMinu",234,0,234,31,0,31,31,0,31);
+ fHptUnde = new TH3S("HptUnde","HptUnde",234,0,234,31,0,31,31,0,31);
+
+ RegisterHistos();
+ }
+
+ TH3* h = static_cast<TH3*>(fMap->GetValue(hname));
+
+ Int_t bin = h->GetBin(icirc,istripX,idev);
+ h->SetBinContent(bin,value);
}
//----------------------------------------------------------------------
void AliMUONTriggerLut::GetLutOutput(Int_t circuit, Int_t xstrip, Int_t idev,
- Int_t ystrip, Int_t lutLpt[2],
- Int_t lutHpt[2])
+ Int_t ystrip, Int_t lutLpt[2],
+ Int_t lutHpt[2]) const
{
/// Return output of LuT for corresponding TH3S
if ( !fLptPlus )
{
- ReadFromFile("$(ALICE_ROOT)/MUON/data/MUONTriggerLut.root");
+ AliError("LUT not initialized");
+// ReadFromFile("$(ALICE_ROOT)/MUON/data/MUONTriggerLut.root");
}
Int_t bin;
}
//----------------------------------------------------------------------
-Int_t AliMUONTriggerLut::GetMask(Int_t ystrip)
+Int_t AliMUONTriggerLut::GetMask(Int_t ystrip) const
{
/// Return the mask corresponding to ystrip
#include <TNamed.h>
class TH3;
+class TMap;
//----------------------------------------------
class AliMUONTriggerLut : public TNamed
AliMUONTriggerLut(); // constructor
virtual ~AliMUONTriggerLut(); // destructor
- void ReadFromFile(const char* filename);
+ Int_t Compare(const TObject* object) const;
void GetLutOutput(Int_t circuit, Int_t xstrip, Int_t idev, Int_t ystrip,
- Int_t lutLpt[2], Int_t lutHpt[2]);
+ Int_t lutLpt[2], Int_t lutHpt[2]) const;
+
+ void ReadFromFile(const char* filename);
+
+ void SetContent(const char* hname, Int_t icirc, UChar_t istripX,
+ UChar_t idev, Short_t value);
private:
- /// Not implemented copy constructor
+
+ /// Not implemented copy constructor
AliMUONTriggerLut (const AliMUONTriggerLut& AliMUONTriggerLut);
/// Not implemented assignment operator
AliMUONTriggerLut& operator=(const AliMUONTriggerLut& AliMUONTriggerLut);
- Int_t GetMask(Int_t ystrip);
+ void Add(TH3* h);
+ Int_t Compare(TH3* h1, TH3* h2) const;
+
+ Int_t GetMask(Int_t ystrip) const;
+
+ void RegisterHistos();
+
private:
TH3 *fLptPlus; ///< 3-d histogram with 234x32x31 bins Low pt Plus
TH3 *fLptMinu; ///< 3-d histogram with 234x32x31 bins Low pt Minus
TH3 *fAptMinu; ///< 3-d histogram with 234x32x31 bins All pt Minus
TH3 *fAptUnde; ///< 3-d histogram with 234x32x31 bins All pt Undefined
- ClassDef(AliMUONTriggerLut,1) // Trigger Look up Table class
+ TMap* fMap; //!< from name to histo
+
+ ClassDef(AliMUONTriggerLut,2) // Trigger Look up Table class
};
#endif
AliMUONTriggerIO tio;
- tio.ReadMasks(GetFileName("LOCAL").Data(),
- GetFileName("REGIONAL").Data(),
- GetFileName("GLOBAL").Data(),
- fLocalMasks,fRegionalMasks,fGlobalMasks);
+ Bool_t ok = tio.ReadMasks(GetFileName("LOCAL").Data(),
+ GetFileName("REGIONAL").Data(),
+ GetFileName("GLOBAL").Data(),
+ fLocalMasks,fRegionalMasks,fGlobalMasks);
+
+ if (!ok)
+ {
+ Master()->Log("ERROR : ReadMasks failed");
+ delete fLocalMasks;
+ delete fRegionalMasks;
+ delete fGlobalMasks;
+ fLocalMasks = 0x0;
+ fRegionalMasks = 0x0;
+ fGlobalMasks = 0x0;
+ }
delete fLUT;
- fLUT = 0x0; // new AliMUONTriggerLut;
+ fLUT = new AliMUONTriggerLut;
-// Master()->Log(Form("Reading trigger LUT for Run %d startTime %ld endTime %ld",
-// run,startTime,endTime));
-// tio.ReadLut(lutFile,fLUT);
+ Master()->Log(Form("Reading trigger LUT for Run %d startTime %ld endTime %ld",
+ run,startTime,endTime));
+
+ tio.ReadLUT(GetFileName("LUT").Data(),*fLUT);
+
+ if (!ok)
+ {
+ Master()->Log("ERROR : ReadLUT failed");
+ delete fLUT;
+ fLUT = 0x0;
+ }
}
//_____________________________________________________________________________