64 #include "AliCodeTimer.h"
81 #include "AliRawReader.h"
82 #include "AliRawDataHeaderSim.h"
83 #include "AliBitPacking.h"
87 #include "TObjArray.h"
88 #include "TStopwatch.h"
89 #include <Riostream.h>
104 fScalerEvent(kFALSE),
106 fBufferSize((((43*
AliMpConstants::ManuNofChannels() + 4)*5 + 10)*5 + 8)*2),
107 fBuffer(new Int_t [fBufferSize])
111 AliDebug(1,
"Standard ctor");
114 fBlockHeader->SetDataKey(fBlockHeader->GetDefaultDataKey());
115 fDspHeader->SetDataKey(fDspHeader->GetDefaultDataKey());
120 AliFatal(
"Could not access mapping from OCDB !");
143 UInt_t trigY, UInt_t posY, UInt_t posX,
144 UInt_t sdevX, UInt_t devX)
148 AliBitPacking::PackWord(locId,word,19,22);
149 AliBitPacking::PackWord(locDec,word,15,18);
150 AliBitPacking::PackWord(trigY,word,14,14);
151 AliBitPacking::PackWord(posY,word,10,13);
152 AliBitPacking::PackWord(sdevX,word,9,9);
153 AliBitPacking::PackWord(devX,word,5,8);
154 AliBitPacking::PackWord(posX,word,0,4);
164 AliCodeTimerAuto(
"",0)
172 AliCodeTimerAuto(
"for Tracker",1)
176 Int_t nDDLs = AliDAQ::NumberOfDdls(
"MUONTRK");
178 Int_t nofBusPatches(0);
180 for (Int_t iDDL = 0; iDDL < nDDLs; ++iDDL )
186 busPatchMap.
SetSize(nofBusPatches);
190 for (Int_t iDDL = 0; iDDL < nDDLs; ++iDDL )
194 AliDebug(1,
"Tracker written");
199 AliCodeTimerAuto(
"for Trigger",1)
207 file[0] =
new AliFstream(AliDAQ::DdlFileName(
"MUONTRG",idDDL));
210 file[1] =
new AliFstream(AliDAQ::DdlFileName(
"MUONTRG",idDDL));
218 AliDebug(1,
"Trigger written");
231 AliCodeTimerAuto(
"",0)
233 static const Int_t kMAXADC = (1<<12)-1;
240 UChar_t channelId = 0;
242 Int_t busPatchId = 0;
243 Int_t currentBusPatchId = -1;
251 while ( ( digit = static_cast<AliMUONVDigit*>(next()) ) )
253 charge = digit->
ADC();
254 if ( charge > kMAXADC )
258 AliError(Form(
"adc value %d above 0x%x for DE %d . Setting to 0x%x. Digit is:",
259 charge,kMAXADC,digit->DetElemId(),kMAXADC));
260 StdoutToAliError(digit->Print());
267 if (busPatchId<0)
continue;
269 if ( digit->ManuId() > 0x7FF ||
270 digit->ManuChannel() > 0x3F )
272 StdoutToAliError(digit->Print(););
273 AliFatal(
"ManuId,ManuChannel are invalid for the digit above.");
276 manuId = ( digit->ManuId() & 0x7FF );
277 channelId = ( digit->ManuChannel() & 0x3F );
281 AliBitPacking::PackWord((UInt_t)manuId,word,18,28);
282 AliBitPacking::PackWord((UInt_t)channelId,word,12,17);
283 AliBitPacking::PackWord((UInt_t)charge,word,0,11);
287 for (Int_t i = 1; i <= 30; ++i)
289 parity ^= ((word >> i) & 0x1);
291 AliBitPacking::PackWord((UInt_t)parity,word,31,31);
293 if ( currentBusPatchId != busPatchId )
297 currentBusPatchId = busPatchId;
306 busPatchMap.
Add(busPatchId,busStruct);
324 AliCodeTimerAuto(
"",0)
327 AliError(
"Raw data header must be set");
338 Int_t totalDDLLength = 0;
343 for (Int_t iBlock = 0; iBlock < 2; ++iBlock)
348 Int_t indexBlk = index;
352 for (Int_t iDsp = 0; iDsp < iDspMax; ++iDsp)
357 Int_t indexDsp = index;
358 index += dspHeaderLength;
361 for (Int_t i = 0; i < iBusPerDSP[iDsp]; ++i)
368 AliWarning(Form(
"Error in bus itr in DDL %d\n", iDDL));
380 index += busHeaderLength;
383 Int_t busLength = busStructPtr->
GetLength();
400 Int_t totalDspLength = index - indexDsp;
401 if ((totalDspLength % 2) == 1)
410 fBuffer[indexDsp+1] = totalDspLength;
411 fBuffer[indexDsp+2] = dspLength;
415 Int_t totalBlkLength = index - indexBlk;
417 totalDDLLength += totalBlkLength;
419 fBuffer[indexBlk+1] = totalBlkLength;
420 fBuffer[indexBlk+2] = blkLength;
434 Int_t headerSize =
sizeof(AliRawDataHeaderV3)/4;
436 fHeader->fSize = (totalDDLLength + headerSize) * 4;
438 AliFstream* file =
new AliFstream(AliDAQ::DdlFileName(
"MUONTRK",iDDL));
440 file->WriteBuffer((
char*)
fHeader,headerSize*4);
441 file->WriteBuffer((
char*)
fBuffer,
sizeof(
int)*index);
458 AliCodeTimerAuto(
"",0)
461 AliError(
"Raw data header must be set");
468 Int_t headerSize =
sizeof(AliRawDataHeaderV3)/4;
483 UChar_t locDec, trigY, posY, posX, regOut;
490 UInt_t eventPhys = 1;
491 UInt_t serialNb = 0xF;
492 Int_t globalFlag = 0;
505 static const Int_t kBufferSize = (16 * (kLocHeaderLength+1) + (kRegHeaderLength+1))* 8
506 + kDarcHeaderLength + kGlobalHeaderLength + 2;
509 static const Int_t kScalerBufferSize = (16 * (kLocHeaderLength + kLocScalerLength +1) +
510 (kRegHeaderLength + kRegScalerLength +1))* 8 +
511 (kDarcHeaderLength + kDarcScalerLength +
512 kGlobalHeaderLength + kGlobalScalerLength + 2);
515 fHeader->fWord2 |= (0x1 << 14);
518 buffer =
new Int_t [kScalerBufferSize];
520 buffer =
new Int_t [kBufferSize];
525 for ( Int_t iDDL = 0; iDDL < 2; ++iDDL )
537 AliBitPacking::PackWord((UInt_t)eventPhys,word,30,30);
538 AliBitPacking::PackWord((UInt_t)serialNb,word,20,23);
539 AliBitPacking::PackWord((UInt_t)globalFlag,word,10,10);
540 AliBitPacking::PackWord((UInt_t)version,word,12,19);
544 index += kDarcHeaderLength;
549 for (Int_t ii = 0; ii < 4; ii++) {
559 index += kDarcScalerLength;
566 index += kGlobalHeaderLength;
571 index += kGlobalScalerLength;
580 for (Int_t iReg = 0; iReg < nCrate; ++iReg) {
586 AliError(Form(
"Missing crate number %d in DDL %d\n", iReg, iDDL));
593 AliError(Form(
"Missing regional board %d in trigger Store\n", crate->
GetId()));
609 AliBitPacking::PackWord((UInt_t)eventPhys,word,31,31);
610 AliBitPacking::PackWord((UInt_t)serialNb,word,20,25);
611 AliBitPacking::PackWord((UInt_t)version,word,8,15);
612 AliBitPacking::PackWord((UInt_t)crate->
GetId(),word,16,19);
613 AliBitPacking::PackWord((UInt_t)regOut,word,0,7);
618 Int_t indexReg = index;
619 index += kRegHeaderLength;
624 index += kRegScalerLength;
635 for (Int_t iLoc = 0; iLoc < nLocalBoard; iLoc++) {
652 devX = locTrg->
LoDev();
655 AliDebug(4,Form(
"loctrg %d, posX %d, posY %d, devX %d\n",
659 LocalWordPacking(word, (UInt_t)iLoc, (UInt_t)locDec, (UInt_t)trigY, (UInt_t)posY,
660 (UInt_t)posX, (UInt_t)sdevX, (UInt_t)devX);
666 buffer[index++] = (Int_t)word;
673 locDec = 0; trigY = 1; posY = 15;
674 posX = 0; devX = 0; sdevX = 1;
675 LocalWordPacking(word, (UInt_t)iLoc, (UInt_t)locDec, (UInt_t)trigY, (UInt_t)posY,
676 (UInt_t)posX, (UInt_t)sdevX, (UInt_t)devX);
687 buffer[index++] = word;
700 index += kLocScalerLength;
717 fHeader->fSize = (index + headerSize) * 4;
718 file[iDDL]->WriteBuffer((
char*)
fHeader,headerSize*4);
719 file[iDDL]->WriteBuffer((
char*)buffer,
sizeof(
int)*index);
Int_t GetLength() const
Return length of raw data.
Int_t * GetHeader()
Return header.
Rawdata local card structure for trigger.
Bool_t IsNotified() const
Return notified flag (not copy card)
void GetBusPerDsp(Int_t *iBusPerDSP) const
AliMpLocalBoard * GetLocalBoard(Int_t localBoardId, Bool_t warn=true) const
UInt_t GetEndOfLocal() const
Return end of local info word.
Interface for a digit container.
UShort_t GetId() const
Return Id.
Int_t GetNofTriggerCrates() const
The class defines the properties of trigger crate.
UInt_t * GetGlobalInput()
Return global input to the global trigger board.
The top container class for DDLs, det elements and bus patched.
Int_t GetLocalBoardId(Int_t index) const
UInt_t GetLocalOutput(Int_t n) const
Return local output Lpt & Hpt.
Int_t GetLength() const
Return local info length in word.
virtual Int_t ADC() const =0
Raw ADC value of this digit.
Int_t GetInputYfrom() const
Get Id from where the Y input are copied.
Int_t GetScalerLength() const
Return scaler length in word.
Bool_t fScalerEvent
flag to generates scaler event
AliMUONDspHeader * fDspHeader
! DDL Dsp header class pointers
static Bool_t LoadDDLStore(Bool_t warn=false)
const AliMpRegionalTrigger * GetRegionalTrigger() const
Return regional trigger object.
Int_t * fBuffer
! internal data buffer
UInt_t GetDisableWord() const
Return Word for "empty" slots.
UInt_t * GetData() const
Return data.
Class that manages the properties of the local board.
void Digits2BusPatchMap(const AliMUONVDigitStore &digitStore, AliMpExMap &busPatchMap)
UShort_t GetX3Pattern() const
Return X strip pattern for chamber 21.
virtual Int_t DetElemId() const =0
The detection element this digit belongs to.
static Int_t GetHeaderLength()
Return header length in word.
Int_t LoStripY() const
Return Y strip in MT11.
Base class of a trigger information store.
virtual ~AliMUONRawWriter()
UShort_t GetY4Pattern() const
Return Y strip pattern for chamber 22.
The class defined electronics properties of DDL.
UShort_t GetX4Pattern() const
Return X strip pattern for chamber 22.
Char_t GetOutput() const
Return regional output (single muon:2, unlike sign:1, like sign:1)
void WriteTrackerDDL(AliMpExMap &busPatchMap, Int_t iDDL)
Reconstructed regional Trigger object.
static AliMpDDLStore * Instance(Bool_t warn=true)
Int_t LoStripX() const
Return X strip in MT11.
UShort_t GetX1Pattern() const
Return X strip pattern for chamber 11.
static UInt_t GetDefaultDataKey()
Return default data key word for Bus Patch Header.
Int_t GetNofBusPatches() const
Int_t Digits2Raw(const AliMUONVDigitStore *digitStore, const AliMUONVTriggerStore *triggerStore)
Int_t WriteTriggerDDL(const AliMUONVTriggerStore &triggerStore, AliFstream *file[2])
Int_t GetBusPatchId(Int_t detElemId, Int_t manuId) const
AliMUONLocalStruct * fLocalStruct
! DDL local structure class pointers
Reconstructed Local Trigger object.
AliRawDataHeaderSim * fHeader
header of DDL
AliMpDDL * GetDDL(Int_t ddlId, Bool_t warn=true) const
virtual AliMUONRegionalTrigger * FindRegional(Int_t boardNumber) const =0
Find a regional trigger by the board number (not an index, it is a number really) ...
UShort_t GetY1Pattern() const
Return Y strip pattern for chamber 11.
UShort_t GetY3Pattern() const
Return Y strip pattern for chamber 21.
Int_t LoSdev() const
Return Sign of Deviation.
virtual TIterator * CreateTrackerIterator() const =0
Create an iterator to loop over tracker digits only.
TObject * GetValue(Int_t keyFirst, Int_t keySecond) const
UShort_t GetY2Pattern() const
Return Y strip pattern for chamber 12.
virtual AliMUONGlobalTrigger * Global() const =0
Return global trigger.
void SetBusPatchId(Int_t b)
Set bus patch id.
Int_t LoDev() const
Return Deviation.
The class defines the properties of regional trigger crate.
static Int_t LocalBoardNofChannels()
Max number of channels per local board.
AliMUONRegHeader * fRegHeader
! DDL regional header class pointers
void Add(Int_t keyFirst, Int_t keySecond, TObject *object)
void SetDataKey(Int_t d)
Set Data key word for bus patch header.
Raw data class for trigger and tracker chambers.
static void LocalWordPacking(UInt_t &word, UInt_t locId, UInt_t locDec, UInt_t trigY, UInt_t posY, UInt_t posX, UInt_t sdevX, UInt_t devX)
Char_t GetLoDecision() const
AliMpTriggerCrate * GetTriggerCrate(TString crateName, Bool_t warn=true) const
AliMUONDarcHeader * fDarcHeader
! DDL darc header class pointers
UChar_t GetGlobalResponse() const
virtual Int_t ManuId() const =0
The electronic card id this digit belongs to (manuId for tracker, localboardId for trigger) ...
Int_t LoTrigY() const
Return Trig Y.
UShort_t GetX2Pattern() const
Return X strip pattern for chamber 12.
void SetLength(Int_t l)
Set length of raw data.
Int_t GetBusPatchId(Int_t index) const
Int_t fBufferSize
! size of internal data buffer
Globally used constants definition.
UInt_t * GetScalers()
Return scalers.
AliMpDDLStore * fDDLStore
! DDL store pointer
Int_t GetBusPatch(const AliMUONVDigit &digit) const
MUON buspatch structure for tracker.
virtual AliMUONLocalTrigger * FindLocal(Int_t boardNumber) const =0
Find a local trigger by the board number (not an index, it is a number really)
Int_t LoCircuit() const
Return Circuit number.
Int_t GetInputXfrom() const
Get Id from where the X input are copied.
Helper class making Root persistent TExMap.
AliMUONBlockHeader * fBlockHeader
! DDL block header class pointers