2 /**************************************************************************
3 * This file is property of and copyright by the ALICE HLT Project *
4 * ALICE Experiment at CERN, All rights reserved. *
6 * Primary Authors: Artur Szostak <artursz@iafrica.com> *
7 * for The ALICE HLT Project. *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
18 /// @file AliHLTReadoutList.cxx
19 /// @author Artur Szostak <artursz@iafrica.com>
21 /// @brief Implementation of the AliHLTReadoutList class.
23 /// The AliHLTReadoutList class is used as an interface to the AliHLTEventDDL
24 /// structure. It makes it easy to manipulate the bits in this structure, which
25 /// define what DDLs should be readout by DAQ.
26 /// Several operators are also overloaded which are meant to be used in the trigger
27 /// menu specification for the AliHLTGlobalTrigger. It allows one to construct
28 /// expressions for the readout lists, which is necessary to be able to evaluate
29 /// or compose the final readout list, given multiple input readout lists received
30 /// from individual components that derive from AliHLTTrigger.
32 #include "AliHLTReadoutList.h"
33 #include "AliHLTDAQ.h"
34 #include "Riostream.h"
36 #include "TObjString.h"
37 #include "TObjArray.h"
40 ClassImp(AliHLTReadoutList)
43 AliHLTReadoutList::AliHLTReadoutList() :
44 TNamed("AliHLTReadoutList", "Readout list object used for manipulating and storing an AliHLTEventDDL structure."),
47 // Default constructor.
49 fReadoutList.fCount = gkAliHLTDDLListSize; // Required by ALICE-INT-2007-015
50 memset(fReadoutList.fList, 0x0, sizeof(fReadoutList.fList));
54 AliHLTReadoutList::AliHLTReadoutList(Int_t enabledDetectors) :
55 TNamed("AliHLTReadoutList", "Readout list object used for manipulating and storing an AliHLTEventDDL structure."),
58 // Constructor to select which detectors to enable for readout.
59 // See header file for more details.
61 fReadoutList.fCount = gkAliHLTDDLListSize; // Required by ALICE-INT-2007-015
62 memset(fReadoutList.fList, 0x0, sizeof(fReadoutList.fList));
63 Enable(enabledDetectors);
67 AliHLTReadoutList::AliHLTReadoutList(const char* enabledList) :
68 TNamed("AliHLTReadoutList", "Readout list object used for manipulating and storing an AliHLTEventDDL structure."),
71 // Constructor to select which detectors and DDLs to enable for readout.
72 // See header file for more details.
74 fReadoutList.fCount = gkAliHLTDDLListSize; // Required by ALICE-INT-2007-015
75 memset(fReadoutList.fList, 0x0, sizeof(fReadoutList.fList));
77 TString str(enabledList);
79 Int_t enabledDetectors = 0;
80 if (str.Contains("ITSSPD")) enabledDetectors |= kITSSPD;
81 if (str.Contains("ITSSDD")) enabledDetectors |= kITSSDD;
82 if (str.Contains("ITSSSD")) enabledDetectors |= kITSSSD;
83 if (str.Contains("TPC")) enabledDetectors |= kTPC;
84 if (str.Contains("TRD")) enabledDetectors |= kTRD;
85 if (str.Contains("TOF")) enabledDetectors |= kTOF;
86 if (str.Contains("HMPID")) enabledDetectors |= kHMPID;
87 if (str.Contains("PHOS")) enabledDetectors |= kPHOS;
88 if (str.Contains("CPV")) enabledDetectors |= kCPV;
89 if (str.Contains("PMD")) enabledDetectors |= kPMD;
90 if (str.Contains("MUONTRK")) enabledDetectors |= kMUONTRK;
91 if (str.Contains("MUONTRG")) enabledDetectors |= kMUONTRG;
92 if (str.Contains("FMD")) enabledDetectors |= kFMD;
93 if (str.Contains("T0")) enabledDetectors |= kT0;
94 if (str.Contains("V0")) enabledDetectors |= kV0;
95 if (str.Contains("ZDC")) enabledDetectors |= kZDC;
96 if (str.Contains("ACORDE")) enabledDetectors |= kACORDE;
97 if (str.Contains("TRG")) enabledDetectors |= kTRG;
98 if (str.Contains("EMCAL")) enabledDetectors |= kEMCAL;
99 if (str.Contains("DAQTEST")) enabledDetectors |= kDAQTEST;
100 if (str.Contains("HLT")) enabledDetectors |= kHLT;
101 if (str.Contains("ALL")) enabledDetectors |= kALLDET;
102 Enable(enabledDetectors);
104 TObjArray* list = str.Tokenize(" ");
106 const TObjString* objstr = NULL;
107 while ((objstr = dynamic_cast<const TObjString*>(next())) != NULL)
109 str = objstr->GetString();
110 if (str.IsDigit()) EnableDDLBit(str.Atoi());
116 AliHLTReadoutList::AliHLTReadoutList(const AliHLTEventDDL& list) :
117 TNamed("AliHLTReadoutList", "Readout list object used for manipulating and storing an AliHLTEventDDL structure."),
120 // Constructor to create readout list from AliHLTEventDDL structure.
121 // See header file for more details.
122 memset(&fReadoutList, 0, sizeof(fReadoutList));
123 // handle lists of different sizes, copy only the overlapping part of the list
124 fReadoutList.fCount=sizeof(fReadoutList.fList)/sizeof(AliHLTUInt32_t);
125 memcpy(&fReadoutList.fList, &list.fList, (fReadoutList.fCount<list.fCount?fReadoutList.fCount:list.fCount)*sizeof(AliHLTUInt32_t));
129 AliHLTReadoutList::AliHLTReadoutList(const AliHLTReadoutList& list) :
133 // Copy constructor performs a deep copy.
135 memcpy(&fReadoutList, &list.fReadoutList, sizeof(fReadoutList));
139 AliHLTReadoutList::~AliHLTReadoutList()
141 // Default destructor.
145 bool AliHLTReadoutList::Empty() const
147 // Returns true if the readout list has no DDLs enabled.
149 for (size_t i = 0; i < sizeof(fReadoutList.fList) / sizeof(fReadoutList.fList[0]); i++)
151 if (fReadoutList.fList[i] != 0x0) return false;
157 void AliHLTReadoutList::Clear(Option_t* /*option*/)
159 // Resets all the DDL readout bits.
160 memset(fReadoutList.fList, 0x0, sizeof(fReadoutList.fList));
164 bool AliHLTReadoutList::DecodeDDLID(Int_t ddlId, Int_t& wordIndex, Int_t& bitIndex)
166 // Decodes the word index and bit index within that word for the readout list structure.
167 // See header file for more details.
169 // The detector number is bits 15..8 of ddlId and DDL number is bits 7..0.
170 Int_t detNum = ddlId >> 8;
171 Int_t ddlNum = ddlId & 0xFF;
175 // the 3 ITS detectors have one word each
178 else if (detNum == 3)
180 // the TPC bitfield has in total 8 words
181 wordIndex = detNum + (ddlNum >> 5);
183 else if (detNum == 4)
185 // the TRD bitfield starts at position 11 (3 ITS + 8 TPC)
186 wordIndex = detNum + 7;
188 else if (detNum == 5)
190 // TOF has 72 DDLs, the bitfield is 3 words starting at position 12
191 wordIndex = detNum + 7 + (ddlNum >> 5);
193 else if (detNum == 30)
195 // the HLT bitfield is in the last word
200 // all other detectors fit into one word, the offset is due to
202 wordIndex = detNum + 9;
205 if (wordIndex < 0 or gkAliHLTDDLListSize <= wordIndex) return false;
207 // The bit index within the word indicated by wordIndex.
208 bitIndex = (ddlId & 0xFF) % 32;
213 Bool_t AliHLTReadoutList::GetDDLBit(Int_t ddlId) const
215 // Fetches the bit value for a particular DDL in the readout list.
216 // See header file for more details.
218 Int_t wordIndex, bitIndex;
219 if (! DecodeDDLID(ddlId, wordIndex, bitIndex)) return kFALSE;
220 return ((fReadoutList.fList[wordIndex] >> bitIndex) & 0x1) == 0x1;
224 void AliHLTReadoutList::SetDDLBit(Int_t ddlId, Bool_t state)
226 // Sets the bit value for a particular DDL in the readout list.
227 // See header file for more details.
229 Int_t wordIndex, bitIndex;
230 if (! DecodeDDLID(ddlId, wordIndex, bitIndex)) return;
232 // To set, 'OR' word with bit mask
234 fReadoutList.fList[wordIndex] |= (0x00000001 << bitIndex);
235 // To unset, 'AND' word with bit mask
237 fReadoutList.fList[wordIndex] &= (0xFFFFFFFF ^ (0x00000001 << bitIndex));
241 void AliHLTReadoutList::Enable(Int_t detector)
243 // Enables all DDLs for a particular detector or detectors.
244 // See header file for more details.
246 if ((detector & kITSSPD) != 0) fReadoutList.fList[0] = 0x000FFFFF;
247 if ((detector & kITSSDD) != 0) fReadoutList.fList[1] = 0x00FFFFFF;
248 if ((detector & kITSSSD) != 0) fReadoutList.fList[2] = 0x0000FFFF;
249 if ((detector & kTPC) != 0)
251 fReadoutList.fList[3] = 0xFFFFFFFF;
252 fReadoutList.fList[4] = 0xFFFFFFFF;
253 fReadoutList.fList[5] = 0xFFFFFFFF;
254 fReadoutList.fList[6] = 0xFFFFFFFF;
255 fReadoutList.fList[7] = 0xFFFFFFFF;
256 fReadoutList.fList[8] = 0xFFFFFFFF;
257 fReadoutList.fList[9] = 0x00FFFFFF;
258 fReadoutList.fList[10] = 0x00000000;
260 if ((detector & kTRD) != 0) fReadoutList.fList[11] = 0x0003FFFF;
261 if ((detector & kTOF) != 0)
263 fReadoutList.fList[12] = 0xFFFFFFFF;
264 fReadoutList.fList[13] = 0xFFFFFFFF;
265 fReadoutList.fList[14] = 0x000000FF;
267 if ((detector & kHMPID) != 0) fReadoutList.fList[15] = 0x00003FFF;
268 if ((detector & kPHOS) != 0) fReadoutList.fList[16] = 0x000FFFFF;
269 if ((detector & kCPV) != 0) fReadoutList.fList[17] = 0x000003FF;
270 if ((detector & kPMD) != 0) fReadoutList.fList[18] = 0x0000003F;
271 if ((detector & kMUONTRK) != 0) fReadoutList.fList[19] = 0x000FFFFF;
272 if ((detector & kMUONTRG) != 0) fReadoutList.fList[20] = 0x00000003;
273 if ((detector & kFMD) != 0) fReadoutList.fList[21] = 0x00000007;
274 if ((detector & kT0) != 0) fReadoutList.fList[22] = 0x00000001;
275 if ((detector & kV0) != 0) fReadoutList.fList[23] = 0x00000001;
276 if ((detector & kZDC) != 0) fReadoutList.fList[24] = 0x00000001;
277 if ((detector & kACORDE) != 0) fReadoutList.fList[25] = 0x00000001;
278 if ((detector & kTRG) != 0) fReadoutList.fList[26] = 0x00000001;
279 if ((detector & kEMCAL) != 0) fReadoutList.fList[27] = 0x00FFFFFF;
280 if ((detector & kDAQTEST) != 0) fReadoutList.fList[28] = 0x00000001;
281 if ((detector & kHLT) != 0) fReadoutList.fList[29] = 0x000003FF;
285 void AliHLTReadoutList::Disable(Int_t detector)
287 // Disables all DDLs for a particular detector or detectors.
288 // See header file for more details.
290 if ((detector & kITSSPD) != 0) fReadoutList.fList[0] = 0x00000000;
291 if ((detector & kITSSDD) != 0) fReadoutList.fList[1] = 0x00000000;
292 if ((detector & kITSSSD) != 0) fReadoutList.fList[2] = 0x00000000;
293 if ((detector & kTPC) != 0)
295 fReadoutList.fList[3] = 0x00000000;
296 fReadoutList.fList[4] = 0x00000000;
297 fReadoutList.fList[5] = 0x00000000;
298 fReadoutList.fList[6] = 0x00000000;
299 fReadoutList.fList[7] = 0x00000000;
300 fReadoutList.fList[8] = 0x00000000;
301 fReadoutList.fList[9] = 0x00000000;
302 fReadoutList.fList[10] = 0x00000000;
304 if ((detector & kTRD) != 0) fReadoutList.fList[11] = 0x00000000;
305 if ((detector & kTOF) != 0)
307 fReadoutList.fList[12] = 0x00000000;
308 fReadoutList.fList[13] = 0x00000000;
309 fReadoutList.fList[14] = 0x00000000;
311 if ((detector & kHMPID) != 0) fReadoutList.fList[15] = 0x00000000;
312 if ((detector & kPHOS) != 0) fReadoutList.fList[16] = 0x00000000;
313 if ((detector & kCPV) != 0) fReadoutList.fList[17] = 0x00000000;
314 if ((detector & kPMD) != 0) fReadoutList.fList[18] = 0x00000000;
315 if ((detector & kMUONTRK) != 0) fReadoutList.fList[19] = 0x00000000;
316 if ((detector & kMUONTRG) != 0) fReadoutList.fList[20] = 0x00000000;
317 if ((detector & kFMD) != 0) fReadoutList.fList[21] = 0x00000000;
318 if ((detector & kT0) != 0) fReadoutList.fList[22] = 0x00000000;
319 if ((detector & kV0) != 0) fReadoutList.fList[23] = 0x00000000;
320 if ((detector & kZDC) != 0) fReadoutList.fList[24] = 0x00000000;
321 if ((detector & kACORDE) != 0) fReadoutList.fList[25] = 0x00000000;
322 if ((detector & kTRG) != 0) fReadoutList.fList[26] = 0x00000000;
323 if ((detector & kEMCAL) != 0) fReadoutList.fList[27] = 0x00000000;
324 if ((detector & kDAQTEST) != 0) fReadoutList.fList[28] = 0x00000000;
325 if ((detector & kHLT) != 0) fReadoutList.fList[29] = 0x00000000;
329 bool AliHLTReadoutList::DetectorEnabled(Int_t detector) const
331 // Checks if a particular detector's DDLs are enabled.
332 // See header file for more details.
335 if ((detector & kITSSPD) != 0) result &= fReadoutList.fList[0] == 0x000FFFFF;
336 if ((detector & kITSSDD) != 0) result &= fReadoutList.fList[1] == 0x00FFFFFF;
337 if ((detector & kITSSSD) != 0) result &= fReadoutList.fList[2] == 0x0000FFFF;
338 if ((detector & kTPC) != 0)
340 result &= fReadoutList.fList[3] == 0xFFFFFFFF;
341 result &= fReadoutList.fList[4] == 0xFFFFFFFF;
342 result &= fReadoutList.fList[5] == 0xFFFFFFFF;
343 result &= fReadoutList.fList[6] == 0xFFFFFFFF;
344 result &= fReadoutList.fList[7] == 0xFFFFFFFF;
345 result &= fReadoutList.fList[8] == 0xFFFFFFFF;
346 result &= fReadoutList.fList[9] == 0x00FFFFFF;
348 if ((detector & kTRD) != 0) result &= fReadoutList.fList[11] == 0x0003FFFF;
349 if ((detector & kTOF) != 0)
351 result &= fReadoutList.fList[12] == 0xFFFFFFFF;
352 result &= fReadoutList.fList[13] == 0xFFFFFFFF;
353 result &= fReadoutList.fList[14] == 0x000000FF;
355 if ((detector & kHMPID) != 0) result &= fReadoutList.fList[15] == 0x00003FFF;
356 if ((detector & kPHOS) != 0) result &= fReadoutList.fList[16] == 0x000FFFFF;
357 if ((detector & kCPV) != 0) result &= fReadoutList.fList[17] == 0x000003FF;
358 if ((detector & kPMD) != 0) result &= fReadoutList.fList[18] == 0x0000003F;
359 if ((detector & kMUONTRK) != 0) result &= fReadoutList.fList[19] == 0x000FFFFF;
360 if ((detector & kMUONTRG) != 0) result &= fReadoutList.fList[20] == 0x00000003;
361 if ((detector & kFMD) != 0) result &= fReadoutList.fList[21] == 0x00000007;
362 if ((detector & kT0) != 0) result &= fReadoutList.fList[22] == 0x00000001;
363 if ((detector & kV0) != 0) result &= fReadoutList.fList[23] == 0x00000001;
364 if ((detector & kZDC) != 0) result &= fReadoutList.fList[24] == 0x00000001;
365 if ((detector & kACORDE) != 0) result &= fReadoutList.fList[25] == 0x00000001;
366 if ((detector & kTRG) != 0) result &= fReadoutList.fList[26] == 0x00000001;
367 if ((detector & kEMCAL) != 0) result &= fReadoutList.fList[27] == 0x00FFFFFF;
368 if ((detector & kDAQTEST) != 0) result &= fReadoutList.fList[28] == 0x00000001;
369 if ((detector & kHLT) != 0) result &= fReadoutList.fList[29] == 0x000003FF;
375 void AliHLTReadoutList::Print(Option_t* /*option*/) const
377 // Prints the DDLs that will be readout according to this readout list.
379 cout << "Readout enabled for DDLs:" << endl;
380 for (Int_t i = 0; i < AliHLTDAQ::NumberOfDetectors(); i++)
382 Int_t maxddls = AliHLTDAQ::NumberOfDdls(i);
383 cout << AliHLTDAQ::DetectorName(i) << ":";
384 bool nonefound = true;
385 for (Int_t j = 0; j < maxddls; j++)
387 Int_t ddlId = ( ((i == AliHLTDAQ::NumberOfDetectors()-1) ? 30 : i) << 8 ) + j;
388 if (GetDDLBit(ddlId))
390 cout << " " << ddlId;
394 if (nonefound) cout << " none";
400 AliHLTReadoutList& AliHLTReadoutList::operator = (const AliHLTReadoutList& list)
402 // Assignment operator performs a deep copy.
404 TObject::operator = (list);
407 memcpy(&fReadoutList, &list.fReadoutList, sizeof(fReadoutList));
413 AliHLTReadoutList& AliHLTReadoutList::operator |= (const AliHLTReadoutList& list)
415 // This operator performs a bitwise inclusive or operation on all DDL bits.
416 // See header file for more details.
421 AliHLTReadoutList& AliHLTReadoutList::OrEq(const AliHLTReadoutList& list)
423 // a bitwise inclusive or operation on all DDL bits.
424 // See header file for more details.
426 assert( fReadoutList.fCount == (unsigned)gkAliHLTDDLListSize );
427 for (Int_t i = 0; i < gkAliHLTDDLListSize; i++)
429 fReadoutList.fList[i] |= list.fReadoutList.fList[i];
435 AliHLTReadoutList& AliHLTReadoutList::operator ^= (const AliHLTReadoutList& list)
437 // This operator performs a bitwise exclusive or (xor) operation on all DDL bits.
438 // See header file for more details.
444 AliHLTReadoutList& AliHLTReadoutList::XorEq(const AliHLTReadoutList& list)
446 // bitwise exclusive or (xor) operation on all DDL bits.
447 // See header file for more details.
449 assert( fReadoutList.fCount == (unsigned)gkAliHLTDDLListSize );
450 for (Int_t i = 0; i < gkAliHLTDDLListSize; i++)
452 fReadoutList.fList[i] ^= list.fReadoutList.fList[i];
458 AliHLTReadoutList& AliHLTReadoutList::operator &= (const AliHLTReadoutList& list)
460 // This operator performs a bitwise and operation on all DDL bits.
461 // See header file for more details.
467 AliHLTReadoutList& AliHLTReadoutList::AndEq(const AliHLTReadoutList& list)
469 // bitwise and operation on all DDL bits.
470 // See header file for more details.
472 assert( fReadoutList.fCount == (unsigned)gkAliHLTDDLListSize );
473 for (Int_t i = 0; i < gkAliHLTDDLListSize; i++)
475 fReadoutList.fList[i] &= list.fReadoutList.fList[i];
480 AliHLTReadoutList& AliHLTReadoutList::operator -= (const AliHLTReadoutList& list)
482 // This operator removes all the DDLs specified in list from this readout list.
483 // See header file for more details.
485 assert( fReadoutList.fCount == (unsigned)gkAliHLTDDLListSize );
486 for (Int_t i = 0; i < gkAliHLTDDLListSize; i++)
488 // Effectively apply: this = this & (~ (this & list))
489 // i.e. this = this & (this ^ list)
490 fReadoutList.fList[i] &= fReadoutList.fList[i] ^ list.fReadoutList.fList[i];
496 AliHLTReadoutList AliHLTReadoutList::operator ~ () const
498 // This operator performs a bitwise ones compliment on all DDL bits.
499 // See header file for more details.
501 AliHLTReadoutList readoutlist;
502 readoutlist.fReadoutList.fCount = fReadoutList.fCount;
503 readoutlist.fReadoutList.fList[0] = 0x000FFFFF & (~fReadoutList.fList[0]);
504 readoutlist.fReadoutList.fList[1] = 0x00FFFFFF & (~fReadoutList.fList[1]);
505 readoutlist.fReadoutList.fList[2] = 0x0000FFFF & (~fReadoutList.fList[2]);
506 readoutlist.fReadoutList.fList[3] = 0xFFFFFFFF & (~fReadoutList.fList[3]);
507 readoutlist.fReadoutList.fList[4] = 0xFFFFFFFF & (~fReadoutList.fList[4]);
508 readoutlist.fReadoutList.fList[5] = 0xFFFFFFFF & (~fReadoutList.fList[5]);
509 readoutlist.fReadoutList.fList[6] = 0xFFFFFFFF & (~fReadoutList.fList[6]);
510 readoutlist.fReadoutList.fList[7] = 0xFFFFFFFF & (~fReadoutList.fList[7]);
511 readoutlist.fReadoutList.fList[8] = 0xFFFFFFFF & (~fReadoutList.fList[8]);
512 readoutlist.fReadoutList.fList[9] = 0x00FFFFFF & (~fReadoutList.fList[9]);
513 readoutlist.fReadoutList.fList[10] = 0x00000000 & (~fReadoutList.fList[10]);
514 readoutlist.fReadoutList.fList[11] = 0x0003FFFF & (~fReadoutList.fList[11]);
515 readoutlist.fReadoutList.fList[12] = 0xFFFFFFFF & (~fReadoutList.fList[12]);
516 readoutlist.fReadoutList.fList[13] = 0xFFFFFFFF & (~fReadoutList.fList[13]);
517 readoutlist.fReadoutList.fList[14] = 0x000000FF & (~fReadoutList.fList[14]);
518 readoutlist.fReadoutList.fList[15] = 0x00003FFF & (~fReadoutList.fList[15]);
519 readoutlist.fReadoutList.fList[16] = 0x000FFFFF & (~fReadoutList.fList[16]);
520 readoutlist.fReadoutList.fList[17] = 0x000003FF & (~fReadoutList.fList[17]);
521 readoutlist.fReadoutList.fList[18] = 0x0000003F & (~fReadoutList.fList[18]);
522 readoutlist.fReadoutList.fList[19] = 0x000FFFFF & (~fReadoutList.fList[19]);
523 readoutlist.fReadoutList.fList[20] = 0x00000003 & (~fReadoutList.fList[20]);
524 readoutlist.fReadoutList.fList[21] = 0x00000007 & (~fReadoutList.fList[21]);
525 readoutlist.fReadoutList.fList[22] = 0x00000001 & (~fReadoutList.fList[22]);
526 readoutlist.fReadoutList.fList[23] = 0x00000001 & (~fReadoutList.fList[23]);
527 readoutlist.fReadoutList.fList[24] = 0x00000001 & (~fReadoutList.fList[24]);
528 readoutlist.fReadoutList.fList[25] = 0x00000001 & (~fReadoutList.fList[25]);
529 readoutlist.fReadoutList.fList[26] = 0x00000001 & (~fReadoutList.fList[26]);
530 readoutlist.fReadoutList.fList[27] = 0x00FFFFFF & (~fReadoutList.fList[27]);
531 readoutlist.fReadoutList.fList[28] = 0x00000001 & (~fReadoutList.fList[28]);
532 readoutlist.fReadoutList.fList[29] = 0x000003FF & (~fReadoutList.fList[29]);