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() :
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) :
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) :
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) :
120 // Constructor to create readout list from AliHLTEventDDL structure.
121 // See header file for more details.
123 memcpy(&fReadoutList, &list, sizeof(fReadoutList));
127 AliHLTReadoutList::AliHLTReadoutList(const AliHLTReadoutList& list) :
131 // Copy constructor performs a deep copy.
133 memcpy(&fReadoutList, &list.fReadoutList, sizeof(fReadoutList));
137 AliHLTReadoutList::~AliHLTReadoutList()
139 // Default destructor.
143 bool AliHLTReadoutList::Empty() const
145 // Returns true if the readout list has no DDLs enabled.
147 for (size_t i = 0; i < sizeof(fReadoutList.fList) / sizeof(fReadoutList.fList[0]); i++)
149 if (fReadoutList.fList[i] != 0x0) return false;
155 void AliHLTReadoutList::Clear(Option_t* /*option*/)
157 // Resets all the DDL readout bits.
158 memset(fReadoutList.fList, 0x0, sizeof(fReadoutList.fList));
162 bool AliHLTReadoutList::DecodeDDLID(Int_t ddlId, Int_t& wordIndex, Int_t& bitIndex)
164 // Decodes the word index and bit index within that word for the readout list structure.
165 // See header file for more details.
167 // The detector number is bits 15..8 of ddlId and DDL number is bits 7..0.
168 Int_t detNum = ddlId >> 8;
169 Int_t ddlNum = ddlId & 0xFF;
175 else if (detNum == 3)
177 wordIndex = detNum + (ddlNum >> 5);
179 else if (detNum == 4)
181 wordIndex = detNum + 7;
183 else if (detNum == 5)
185 wordIndex = detNum + 7 + (ddlNum >> 5);
187 else if (detNum == 30)
193 wordIndex = detNum + 9;
196 if (wordIndex < 0 or gkAliHLTDDLListSize <= wordIndex) return false;
198 // The bit index within the word indicated by wordIndex.
199 bitIndex = (ddlId & 0xFF) % 32;
204 Bool_t AliHLTReadoutList::GetDDLBit(Int_t ddlId) const
206 // Fetches the bit value for a particular DDL in the readout list.
207 // See header file for more details.
209 Int_t wordIndex, bitIndex;
210 if (! DecodeDDLID(ddlId, wordIndex, bitIndex)) return kFALSE;
211 return ((fReadoutList.fList[wordIndex] >> bitIndex) & 0x1) == 0x1;
215 void AliHLTReadoutList::SetDDLBit(Int_t ddlId, Bool_t state)
217 // Sets the bit value for a particular DDL in the readout list.
218 // See header file for more details.
220 Int_t wordIndex, bitIndex;
221 if (! DecodeDDLID(ddlId, wordIndex, bitIndex)) return;
223 // To set, 'OR' word with bit mask
225 fReadoutList.fList[wordIndex] |= (0x00000001 << bitIndex);
226 // To unset, 'AND' word with bit mask
228 fReadoutList.fList[wordIndex] &= (0xFFFFFFFF ^ (0x00000001 << bitIndex));
232 void AliHLTReadoutList::Enable(Int_t detector)
234 // Enables all DDLs for a particular detector or detectors.
235 // See header file for more details.
237 if ((detector & kITSSPD) != 0) fReadoutList.fList[0] = 0x000FFFFF;
238 if ((detector & kITSSDD) != 0) fReadoutList.fList[1] = 0x00FFFFFF;
239 if ((detector & kITSSSD) != 0) fReadoutList.fList[2] = 0x0000FFFF;
240 if ((detector & kTPC) != 0)
242 fReadoutList.fList[3] = 0xFFFFFFFF;
243 fReadoutList.fList[4] = 0xFFFFFFFF;
244 fReadoutList.fList[5] = 0xFFFFFFFF;
245 fReadoutList.fList[6] = 0xFFFFFFFF;
246 fReadoutList.fList[7] = 0xFFFFFFFF;
247 fReadoutList.fList[8] = 0xFFFFFFFF;
248 fReadoutList.fList[9] = 0x00FFFFFF;
249 fReadoutList.fList[10] = 0x00000000;
251 if ((detector & kTRD) != 0) fReadoutList.fList[11] = 0x0003FFFF;
252 if ((detector & kTOF) != 0)
254 fReadoutList.fList[12] = 0xFFFFFFFF;
255 fReadoutList.fList[13] = 0xFFFFFFFF;
256 fReadoutList.fList[14] = 0x000000FF;
258 if ((detector & kHMPID) != 0) fReadoutList.fList[15] = 0x00003FFF;
259 if ((detector & kPHOS) != 0) fReadoutList.fList[16] = 0x000FFFFF;
260 if ((detector & kCPV) != 0) fReadoutList.fList[17] = 0x000003FF;
261 if ((detector & kPMD) != 0) fReadoutList.fList[18] = 0x0000003F;
262 if ((detector & kMUONTRK) != 0) fReadoutList.fList[19] = 0x000FFFFF;
263 if ((detector & kMUONTRG) != 0) fReadoutList.fList[20] = 0x00000003;
264 if ((detector & kFMD) != 0) fReadoutList.fList[21] = 0x00000007;
265 if ((detector & kT0) != 0) fReadoutList.fList[22] = 0x00000001;
266 if ((detector & kV0) != 0) fReadoutList.fList[23] = 0x00000001;
267 if ((detector & kZDC) != 0) fReadoutList.fList[24] = 0x00000001;
268 if ((detector & kACORDE) != 0) fReadoutList.fList[25] = 0x00000001;
269 if ((detector & kTRG) != 0) fReadoutList.fList[26] = 0x00000001;
270 if ((detector & kEMCAL) != 0) fReadoutList.fList[27] = 0x00FFFFFF;
271 if ((detector & kDAQTEST) != 0) fReadoutList.fList[28] = 0x00000001;
272 if ((detector & kHLT) != 0) fReadoutList.fList[29] = 0x000003FF;
276 void AliHLTReadoutList::Disable(Int_t detector)
278 // Disables all DDLs for a particular detector or detectors.
279 // See header file for more details.
281 if ((detector & kITSSPD) != 0) fReadoutList.fList[0] = 0x00000000;
282 if ((detector & kITSSDD) != 0) fReadoutList.fList[1] = 0x00000000;
283 if ((detector & kITSSSD) != 0) fReadoutList.fList[2] = 0x00000000;
284 if ((detector & kTPC) != 0)
286 fReadoutList.fList[3] = 0x00000000;
287 fReadoutList.fList[4] = 0x00000000;
288 fReadoutList.fList[5] = 0x00000000;
289 fReadoutList.fList[6] = 0x00000000;
290 fReadoutList.fList[7] = 0x00000000;
291 fReadoutList.fList[8] = 0x00000000;
292 fReadoutList.fList[9] = 0x00000000;
293 fReadoutList.fList[10] = 0x00000000;
295 if ((detector & kTRD) != 0) fReadoutList.fList[11] = 0x00000000;
296 if ((detector & kTOF) != 0)
298 fReadoutList.fList[12] = 0x00000000;
299 fReadoutList.fList[13] = 0x00000000;
300 fReadoutList.fList[14] = 0x00000000;
302 if ((detector & kHMPID) != 0) fReadoutList.fList[15] = 0x00000000;
303 if ((detector & kPHOS) != 0) fReadoutList.fList[16] = 0x00000000;
304 if ((detector & kCPV) != 0) fReadoutList.fList[17] = 0x00000000;
305 if ((detector & kPMD) != 0) fReadoutList.fList[18] = 0x00000000;
306 if ((detector & kMUONTRK) != 0) fReadoutList.fList[19] = 0x00000000;
307 if ((detector & kMUONTRG) != 0) fReadoutList.fList[20] = 0x00000000;
308 if ((detector & kFMD) != 0) fReadoutList.fList[21] = 0x00000000;
309 if ((detector & kT0) != 0) fReadoutList.fList[22] = 0x00000000;
310 if ((detector & kV0) != 0) fReadoutList.fList[23] = 0x00000000;
311 if ((detector & kZDC) != 0) fReadoutList.fList[24] = 0x00000000;
312 if ((detector & kACORDE) != 0) fReadoutList.fList[25] = 0x00000000;
313 if ((detector & kTRG) != 0) fReadoutList.fList[26] = 0x00000000;
314 if ((detector & kEMCAL) != 0) fReadoutList.fList[27] = 0x00000000;
315 if ((detector & kDAQTEST) != 0) fReadoutList.fList[28] = 0x00000000;
316 if ((detector & kHLT) != 0) fReadoutList.fList[29] = 0x00000000;
320 bool AliHLTReadoutList::DetectorEnabled(Int_t detector) const
322 // Checks if a particular detector's DDLs are enabled.
323 // See header file for more details.
326 if ((detector & kITSSPD) != 0) result &= fReadoutList.fList[0] == 0x000FFFFF;
327 if ((detector & kITSSDD) != 0) result &= fReadoutList.fList[1] == 0x00FFFFFF;
328 if ((detector & kITSSSD) != 0) result &= fReadoutList.fList[2] == 0x0000FFFF;
329 if ((detector & kTPC) != 0)
331 result &= fReadoutList.fList[3] == 0xFFFFFFFF;
332 result &= fReadoutList.fList[4] == 0xFFFFFFFF;
333 result &= fReadoutList.fList[5] == 0xFFFFFFFF;
334 result &= fReadoutList.fList[6] == 0xFFFFFFFF;
335 result &= fReadoutList.fList[7] == 0xFFFFFFFF;
336 result &= fReadoutList.fList[8] == 0xFFFFFFFF;
337 result &= fReadoutList.fList[9] == 0x00FFFFFF;
339 if ((detector & kTRD) != 0) result &= fReadoutList.fList[11] == 0x0003FFFF;
340 if ((detector & kTOF) != 0)
342 result &= fReadoutList.fList[12] == 0xFFFFFFFF;
343 result &= fReadoutList.fList[13] == 0xFFFFFFFF;
344 result &= fReadoutList.fList[14] == 0x000000FF;
346 if ((detector & kHMPID) != 0) result &= fReadoutList.fList[15] == 0x00003FFF;
347 if ((detector & kPHOS) != 0) result &= fReadoutList.fList[16] == 0x000FFFFF;
348 if ((detector & kCPV) != 0) result &= fReadoutList.fList[17] == 0x000003FF;
349 if ((detector & kPMD) != 0) result &= fReadoutList.fList[18] == 0x0000003F;
350 if ((detector & kMUONTRK) != 0) result &= fReadoutList.fList[19] == 0x000FFFFF;
351 if ((detector & kMUONTRG) != 0) result &= fReadoutList.fList[20] == 0x00000003;
352 if ((detector & kFMD) != 0) result &= fReadoutList.fList[21] == 0x00000007;
353 if ((detector & kT0) != 0) result &= fReadoutList.fList[22] == 0x00000001;
354 if ((detector & kV0) != 0) result &= fReadoutList.fList[23] == 0x00000001;
355 if ((detector & kZDC) != 0) result &= fReadoutList.fList[24] == 0x00000001;
356 if ((detector & kACORDE) != 0) result &= fReadoutList.fList[25] == 0x00000001;
357 if ((detector & kTRG) != 0) result &= fReadoutList.fList[26] == 0x00000001;
358 if ((detector & kEMCAL) != 0) result &= fReadoutList.fList[27] == 0x00FFFFFF;
359 if ((detector & kDAQTEST) != 0) result &= fReadoutList.fList[28] == 0x00000001;
360 if ((detector & kHLT) != 0) result &= fReadoutList.fList[29] == 0x000003FF;
366 void AliHLTReadoutList::Print(Option_t* /*option*/) const
368 // Prints the DDLs that will be readout according to this readout list.
370 cout << "Readout enabled for DDLs:" << endl;
371 for (Int_t i = 0; i < AliHLTDAQ::NumberOfDetectors(); i++)
373 Int_t maxddls = AliHLTDAQ::NumberOfDdls(i);
374 cout << AliHLTDAQ::DetectorName(i) << ":";
375 bool nonefound = true;
376 for (Int_t j = 0; j < maxddls; j++)
378 Int_t ddlId = ( ((i == AliHLTDAQ::NumberOfDetectors()-1) ? 30 : i) << 8 ) + j;
379 if (GetDDLBit(ddlId))
381 cout << " " << ddlId;
385 if (nonefound) cout << " none";
391 AliHLTReadoutList& AliHLTReadoutList::operator = (const AliHLTReadoutList& list)
393 // Assignment operator performs a deep copy.
395 TObject::operator = (list);
398 memcpy(&fReadoutList, &list.fReadoutList, sizeof(fReadoutList));
404 AliHLTReadoutList& AliHLTReadoutList::operator |= (const AliHLTReadoutList& list)
406 // This operator performs a bitwise inclusive or operation on all DDL bits.
407 // See header file for more details.
409 assert( fReadoutList.fCount == gkAliHLTDDLListSize );
410 for (Int_t i = 0; i < gkAliHLTDDLListSize; i++)
412 fReadoutList.fList[i] |= list.fReadoutList.fList[i];
418 AliHLTReadoutList& AliHLTReadoutList::operator ^= (const AliHLTReadoutList& list)
420 // This operator performs a bitwise exclusive or (xor) operation on all DDL bits.
421 // See header file for more details.
423 assert( fReadoutList.fCount == gkAliHLTDDLListSize );
424 for (Int_t i = 0; i < gkAliHLTDDLListSize; i++)
426 fReadoutList.fList[i] ^= list.fReadoutList.fList[i];
432 AliHLTReadoutList& AliHLTReadoutList::operator &= (const AliHLTReadoutList& list)
434 // This operator performs a bitwise and operation on all DDL bits.
435 // See header file for more details.
437 assert( fReadoutList.fCount == gkAliHLTDDLListSize );
438 for (Int_t i = 0; i < gkAliHLTDDLListSize; i++)
440 fReadoutList.fList[i] &= list.fReadoutList.fList[i];
446 AliHLTReadoutList& AliHLTReadoutList::operator -= (const AliHLTReadoutList& list)
448 // This operator removes all the DDLs specified in list from this readout list.
449 // See header file for more details.
451 assert( fReadoutList.fCount == gkAliHLTDDLListSize );
452 for (Int_t i = 0; i < gkAliHLTDDLListSize; i++)
454 // Effectively apply: this = this & (~ (this & list))
455 // i.e. this = this & (this ^ list)
456 fReadoutList.fList[i] &= fReadoutList.fList[i] ^ list.fReadoutList.fList[i];
462 AliHLTReadoutList AliHLTReadoutList::operator ~ () const
464 // This operator performs a bitwise ones compliment on all DDL bits.
465 // See header file for more details.
467 AliHLTReadoutList readoutlist;
468 readoutlist.fReadoutList.fCount = fReadoutList.fCount;
469 readoutlist.fReadoutList.fList[0] = 0x000FFFFF & (~fReadoutList.fList[0]);
470 readoutlist.fReadoutList.fList[1] = 0x00FFFFFF & (~fReadoutList.fList[1]);
471 readoutlist.fReadoutList.fList[2] = 0x0000FFFF & (~fReadoutList.fList[2]);
472 readoutlist.fReadoutList.fList[3] = 0xFFFFFFFF & (~fReadoutList.fList[3]);
473 readoutlist.fReadoutList.fList[4] = 0xFFFFFFFF & (~fReadoutList.fList[4]);
474 readoutlist.fReadoutList.fList[5] = 0xFFFFFFFF & (~fReadoutList.fList[5]);
475 readoutlist.fReadoutList.fList[6] = 0xFFFFFFFF & (~fReadoutList.fList[6]);
476 readoutlist.fReadoutList.fList[7] = 0xFFFFFFFF & (~fReadoutList.fList[7]);
477 readoutlist.fReadoutList.fList[8] = 0xFFFFFFFF & (~fReadoutList.fList[8]);
478 readoutlist.fReadoutList.fList[9] = 0x00FFFFFF & (~fReadoutList.fList[9]);
479 readoutlist.fReadoutList.fList[10] = 0x00000000 & (~fReadoutList.fList[10]);
480 readoutlist.fReadoutList.fList[11] = 0x0003FFFF & (~fReadoutList.fList[11]);
481 readoutlist.fReadoutList.fList[12] = 0xFFFFFFFF & (~fReadoutList.fList[12]);
482 readoutlist.fReadoutList.fList[13] = 0xFFFFFFFF & (~fReadoutList.fList[13]);
483 readoutlist.fReadoutList.fList[14] = 0x000000FF & (~fReadoutList.fList[14]);
484 readoutlist.fReadoutList.fList[15] = 0x00003FFF & (~fReadoutList.fList[15]);
485 readoutlist.fReadoutList.fList[16] = 0x000FFFFF & (~fReadoutList.fList[16]);
486 readoutlist.fReadoutList.fList[17] = 0x000003FF & (~fReadoutList.fList[17]);
487 readoutlist.fReadoutList.fList[18] = 0x0000003F & (~fReadoutList.fList[18]);
488 readoutlist.fReadoutList.fList[19] = 0x000FFFFF & (~fReadoutList.fList[19]);
489 readoutlist.fReadoutList.fList[20] = 0x00000003 & (~fReadoutList.fList[20]);
490 readoutlist.fReadoutList.fList[21] = 0x00000007 & (~fReadoutList.fList[21]);
491 readoutlist.fReadoutList.fList[22] = 0x00000001 & (~fReadoutList.fList[22]);
492 readoutlist.fReadoutList.fList[23] = 0x00000001 & (~fReadoutList.fList[23]);
493 readoutlist.fReadoutList.fList[24] = 0x00000001 & (~fReadoutList.fList[24]);
494 readoutlist.fReadoutList.fList[25] = 0x00000001 & (~fReadoutList.fList[25]);
495 readoutlist.fReadoutList.fList[26] = 0x00000001 & (~fReadoutList.fList[26]);
496 readoutlist.fReadoutList.fList[27] = 0x00FFFFFF & (~fReadoutList.fList[27]);
497 readoutlist.fReadoutList.fList[28] = 0x00000001 & (~fReadoutList.fList[28]);
498 readoutlist.fReadoutList.fList[29] = 0x000003FF & (~fReadoutList.fList[29]);