Major update required to handle old and new AliHLTEventDDL structures within HLT...
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTReadoutList.h
CommitLineData
c580e182 1//-*- Mode: C++ -*-
15ede44e 2// $Id$
dce3e5ce 3#ifndef ALIHLTREADOUTLIST_H
4#define ALIHLTREADOUTLIST_H
5/* This file is property of and copyright by the ALICE HLT Project *
6 * ALICE Experiment at CERN, All rights reserved. *
7 * See cxx source for full Copyright notice */
8
9/// @file AliHLTReadoutList.h
10/// @author Artur Szostak <artursz@iafrica.com>
11/// @date 19 Nov 2008
12/// @brief Declaration of the AliHLTReadoutList class used to handle AliHLTEventDDL structures.
13
1462df14 14#include "TNamed.h"
dce3e5ce 15#include "AliHLTDataTypes.h"
16
1b9a175e 17/**
18 * \class AliHLTReadoutList
19 * This class is used as an interface or wrapper to the AliHLTEventDDL structure.
20 * It makes it easy to manipulate the bits in this structure, which define what DDLs
21 * should be readout by DAQ.
22 * Several operators are also overloaded which are meant to be used in the trigger
23 * menu specification for the AliHLTGlobalTrigger. It allows one to construct
24 * expressions for the readout lists, which is necessary to be able to evaluate
25 * or compose the final readout list, given multiple input readout lists received
26 * from individual components that derive from AliHLTTrigger.
27 * The operators implemented are:
28 * | applies a bitwise or on the DDL bits.
29 * & applies a bitwise and on the DDL bits.
30 * ^ applies a bitwise xor on the DDL bits.
31 * ~ applies a bitwise not on the DDL bits.
1b9a175e 32 * - unsets the bits in readout list A that are set in readout list B.
33 * This effectively applies A & (A ^ B).
34 */
1462df14 35class AliHLTReadoutList : public TNamed
dce3e5ce 36{
37 public:
38
39 /**
40 * Identifiers for different detectors used by methods in AliHLTReadoutList.
41 */
42 enum EDetectorId
43 {
89413559 44 kNoDetector = 0, /// No detector value
dce3e5ce 45 kITSSPD = 0x1 << 0, /// ID for SPD detector
46 kITSSDD = 0x1 << 1, /// ID for SDD detector
47 kITSSSD = 0x1 << 2, /// ID for SSD detector
48 kTPC = 0x1 << 3, /// ID for TPC detector
49 kTRD = 0x1 << 4, /// ID for TRD detector
50 kTOF = 0x1 << 5, /// ID for TOF detector
51 kHMPID = 0x1 << 6, /// ID for HMPID detector
52 kPHOS = 0x1 << 7, /// ID for PHOS detector
53 kCPV = 0x1 << 8, /// ID for CPV detector
54 kPMD = 0x1 << 9, /// ID for PMD detector
55 kMUONTRK = 0x1 << 10, /// ID for MUON tracking chambers
56 kMUONTRG = 0x1 << 11, /// ID for MUON trigger detector
57 kFMD = 0x1 << 12, /// ID for FMD detector
58 kT0 = 0x1 << 13, /// ID for T0 detector
59 kV0 = 0x1 << 14, /// ID for V0 detector
60 kZDC = 0x1 << 15, /// ID for ZDC detector
61 kACORDE = 0x1 << 16, /// ID for ACORDE detector
62 kTRG = 0x1 << 17, /// ID for TRG detector
63 kEMCAL = 0x1 << 18, /// ID for EMCAL detector
64 kDAQTEST = 0x1 << 19, /// ID for DAQ_TEST detector
65 kHLT = 0x1 << 30, /// ID for HLT detector
66 // kALLDET sets readout for all detectors except DAQ_TEST
67 kALLDET = (kITSSPD | kITSSDD | kITSSSD | kTPC | kTRD | kTOF | kHMPID | kPHOS
68 | kCPV | kPMD | kMUONTRK | kMUONTRG | kFMD | kT0 | kV0 | kZDC
69 | kACORDE | kTRG | kEMCAL | kHLT)
70 };
71
89413559 72 /// Converts a detector ID to a user readable string.
73 static const char* DetectorIdToString(EDetectorId id);
74
dce3e5ce 75 /**
76 * Default constructor.
77 */
78 AliHLTReadoutList();
79
80 /**
81 * Constructor to select which detectors to enable for readout.
82 * \param enabledDetectors Detector bit field. Can be any values for
83 * EDetectorId or'ed together.
84 */
85 AliHLTReadoutList(Int_t enabledDetectors);
86
87 /**
88 * Constructor to select which detectors and DDLs to enable for readout.
89 * \param enabledList The string format is a space separated list where
90 * each item is either a detector acronym name or DDL number.
91 * Invalid sub-strings are simply ignored. The special ALL string is
92 * equivalent to kALLDET for AliHLTReadoutList(Int_t enabledDetectors).
93 */
94 AliHLTReadoutList(const char* enabledList);
95
96 /**
97 * Constructor to create readout list from AliHLTEventDDL structure.
98 * \param list The AliHLTEventDDL structure from which to create this object.
99 */
100 AliHLTReadoutList(const AliHLTEventDDL& list);
101
102 /**
103 * The copy constructor performs a deep copy.
104 * \param list The readout list to copy from.
105 */
106 AliHLTReadoutList(const AliHLTReadoutList& list);
107
108 /**
109 * Default destructor.
110 */
111 virtual ~AliHLTReadoutList();
112
8b745301 113 /**
114 * Checks if the readout list is empty, i.e. all DDLs are disabled.
115 * \returns true if the readout list is empty and false otherwise.
116 */
117 bool Empty() const;
118
acc7214e 119 /**
120 * Disables all bits in the readout list.
121 * \param option This parameter is ignored.
122 * The method is inherited from TObject.
123 */
124 virtual void Clear(Option_t* option = "");
125
dce3e5ce 126 /**
127 * Enables a specific DDL bit in the readout list.
128 * \param ddlId The ID number of the DDL to enable.
129 */
130 void EnableDDLBit(Int_t ddlId)
131 {
132 SetDDLBit(ddlId, kTRUE);
133 }
134
135 /**
136 * Disables a specific DDL bit in the readout list.
137 * \param ddlId The ID number of the DDL to disable.
138 */
139 void DisableDDLBit(Int_t ddlId)
140 {
141 SetDDLBit(ddlId, kFALSE);
142 }
143
144 /**
145 * Fetches the bit value for a particular DDL in the readout list.
146 * \param ddlId The ID number of the DDL to fetch.
147 * \return the bit value for the specified DDL.
148 */
149 Bool_t GetDDLBit(Int_t ddlId) const;
150
151 /**
152 * Sets the bit value for a particular DDL in the readout list.
153 * \param ddlId The ID number of the DDL to set.
154 * \param state The value to set the bit to.
155 */
156 void SetDDLBit(Int_t ddlId, Bool_t state);
157
158 /**
159 * Checks if a particular DDL is enabled for readout.
160 * \param ddlId The ID number of the DDL to check.
161 * \return the if the DDL is enabled for readout.
162 */
163 bool IsDDLEnabled(Int_t ddlId) const
164 {
165 return GetDDLBit(ddlId) == kTRUE;
166 }
167
168 /**
169 * Checks if a particular DDL is disabled for readout.
170 * \param ddlId The ID number of the DDL to check.
171 * \return the if the DDL is disabled for readout.
172 */
173 bool IsDDLDisabled(Int_t ddlId) const
174 {
175 return GetDDLBit(ddlId) == kFALSE;
176 }
177
178 /**
179 * Enables all DDLs for a particular detector or detectors.
180 * \param detector A bitmap of detectors to enable. Should be any values from
181 * EDetectorId that can be or'ed together for multiple detector selection.
182 */
183 void Enable(Int_t detector);
184
185 /**
186 * Disables all DDLs for a particular detector or detectors.
187 * \param detector A bitmap of detectors to disable. Should be any values from
188 * EDetectorId that can be or'ed together for multiple detector selection.
189 */
190 void Disable(Int_t detector);
191
52f67e50 192 /**
89413559 193 * Checks if a particular detector's DDLs are all enabled for readout.
52f67e50 194 * \param detector A bitmap of detectors to check. Should be any values from
195 * EDetectorId that can be or'ed together for multiple detector selection.
196 * \return true if all DDLs for the specified detectors are enabled for readout.
197 */
89413559 198 bool DetectorEnabled(Int_t detector) const;
199
200 /**
201 * Checks if a particular detector's DDLs are all disabled for readout.
202 * \param detector A bitmap of detectors to check. Should be any values from
203 * EDetectorId that can be or'ed together for multiple detector selection.
204 * \return true if all DDLs for the specified detectors are disabled for readout.
205 * \note If both DetectorEnabled(x) and DetectorDisabled(x) return false then
206 * it means that only part of the detectors DDLs are enabled.
207 */
208 bool DetectorDisabled(Int_t detector) const;
209
210 /**
211 * Returns the first word of DDL bits for a given detector in the internal structure.
212 * \param detector The detector code for which to return the starting word.
213 * \returns the first word of DDL bits for the detector or -1 if an invalid code is given.
214 */
215 static Int_t GetFirstWord(EDetectorId detector);
216
217 /**
218 * Returns the first word of DDL bits for a given detector in the internal structure.
219 * \param detector The detector code for which to return the starting word.
220 * \returns the first word of DDL bits for the detector or -1 if an invalid code is given.
221 */
222 static Int_t GetWordCount(EDetectorId detector);
223
224 /**
225 * Returns the first detector with non-zero DDL bits.
226 * \param startAfter The detector code after which to start looking from.
227 * If kTOF is used for example then only detectors after kTOF will be checked,
228 * not including kTOF, in the order of precedence indicated by EDetectorId.
229 * \returns the code of the first used detector.
230 */
231 EDetectorId GetFirstUsedDetector(EDetectorId startAfter = kNoDetector) const;
52f67e50 232
dce3e5ce 233 /**
234 * Inherited from TObject. Prints the DDLs that will be readout according to
235 * this readout list.
236 * \param option This is not used by this method.
237 */
238 virtual void Print(Option_t* option = "") const;
239
240 /**
241 * This typecast operator converts the readout list to the AliHLTEventDDL
242 * structure format.
243 * \return Copy of the AliHLTEventDDL raw structure.
244 */
245 operator AliHLTEventDDL () const { return fReadoutList; }
246
247 /**
248 * This typecast operator converts the readout list to the AliHLTEventDDL
249 * structure format.
250 * \return Reference to the AliHLTEventDDL raw structure.
251 */
252 operator AliHLTEventDDL& () { return fReadoutList; }
15ede44e 253
254 /**
255 * Access method to the binary buffer.
256 * \return pointer to the binary buffer.
257 */
258 AliHLTEventDDL* Buffer() { return &fReadoutList; }
259
78f642dc 260 /**
261 * Access method to the binary buffer.
262 * \return const pointer to the binary buffer.
263 */
264 const AliHLTEventDDL* Buffer() const { return &fReadoutList; }
265
15ede44e 266 /**
267 * Access to the size of the binary buffer.
268 * \return size of the binary buffer
269 */
78f642dc 270 unsigned BufferSize() const { return sizeof(fReadoutList); }
dce3e5ce 271
272 /**
273 * Assignment operator performs a deep copy.
274 * \param list The readout list to copy from.
275 * \return A reference to this object.
276 */
277 AliHLTReadoutList& operator = (const AliHLTReadoutList& list);
278
279 /**
280 * This operator performs a bitwise inclusive or operation on all DDL bits
281 * between this readout and <i>list</i>.
282 * \param list The right hand side readout list to operate on.
283 * \return A reference to this object.
284 */
285 AliHLTReadoutList& operator |= (const AliHLTReadoutList& list);
e5339167 286
287 /// same as operator |=
288 AliHLTReadoutList& OrEq(const AliHLTReadoutList& list);
dce3e5ce 289
290 /**
291 * This operator performs a bitwise exclusive or (xor) operation on all DDL
292 * bits between this readout and <i>list</i>.
293 * \param list The right hand side readout list to operate on.
294 * \return A reference to this object.
295 */
296 AliHLTReadoutList& operator ^= (const AliHLTReadoutList& list);
e5339167 297
298 /// same as operator ^=
299 AliHLTReadoutList& XorEq(const AliHLTReadoutList& list);
dce3e5ce 300
301 /**
302 * This operator performs a bitwise and operation on all DDL bits between
303 * this readout and <i>list</i>.
304 * \param list The right hand side readout list to operate on.
305 * \return A reference to this object.
306 */
307 AliHLTReadoutList& operator &= (const AliHLTReadoutList& list);
e5339167 308
309 /// same as operator &=
310 AliHLTReadoutList& AndEq(const AliHLTReadoutList& list);
dce3e5ce 311
dce3e5ce 312 /**
313 * This operator performs the effective operation of "this and (this xor list)".
314 * It removes all the DDLs specified in list from this readout list.
315 * \param list The right hand side readout list to operate on.
316 * \return A reference to this object.
317 */
318 AliHLTReadoutList& operator -= (const AliHLTReadoutList& list);
319
320 /**
321 * This operator performs a bitwise ones compliment on all DDL bits of this
322 * readout list.
323 * \return The result of the unary operator.
324 */
325 AliHLTReadoutList operator ~ () const;
326
327 /**
328 * This operator performs a bitwise inclusive or operation on all DDL bits
329 * between this readout and <i>list</i>.
330 * \param list The right hand side readout list to operate on.
331 * \return The result of the binary operator.
332 */
333 AliHLTReadoutList operator | (const AliHLTReadoutList& list) const
334 {
335 AliHLTReadoutList result = *this;
336 return result.operator |= (list);
337 }
338
339 /**
340 * This operator performs a bitwise exclusive or (xor) operation on all DDL
341 * bits between this readout and <i>list</i>.
342 * \param list The right hand side readout list to operate on.
343 * \return The result of the binary operator.
344 */
345 AliHLTReadoutList operator ^ (const AliHLTReadoutList& list) const
346 {
347 AliHLTReadoutList result = *this;
348 return result.operator ^= (list);
349 }
350
351 /**
352 * This operator performs a bitwise and operation on all DDL bits between
353 * this readout and <i>list</i>.
354 * \param list The right hand side readout list to operate on.
355 * \return The result of the binary operator.
356 */
357 AliHLTReadoutList operator & (const AliHLTReadoutList& list) const
358 {
359 AliHLTReadoutList result = *this;
360 return result.operator &= (list);
361 }
362
dce3e5ce 363 /**
364 * This operator performs the effective operation of "this and (this xor list)".
0910cc2f 365 * i.e. the set difference.
dce3e5ce 366 * It removes all the DDLs specified in list from this readout list.
367 * \param list The right hand side readout list to operate on.
368 * \return The result of the binary operator.
369 */
370 AliHLTReadoutList operator - (const AliHLTReadoutList& list) const
371 {
372 AliHLTReadoutList result = *this;
373 return result.operator -= (list);
374 }
375
376 private:
377
378 /**
379 * Decodes the word index and bit index within that word for the readout list structure.
380 * \param ddlId <i>[in]</i> The ID number of the DDL to decode.
381 * \param wordIndex <i>[out]</i> the word index of the word to modify or check
382 * within fReadoutList.fList
383 * \param bitIndex <i>[out]</i> the bit index of the bit to modify or check
384 * within the word pointed to by <i>wordIndex</i>.
385 * \return true if the ddlId was decoded and false if it was invalid.
386 * \note We do not check extensively if the ddlId is invalid. Just simple checks
387 * are performed to see that we do not overflow the buffer fReadoutList.fList.
388 */
389 static bool DecodeDDLID(Int_t ddlId, Int_t& wordIndex, Int_t& bitIndex);
390
391 AliHLTEventDDL fReadoutList; /// The DDL readout list structure.
392
a9a3028c 393 ClassDef(AliHLTReadoutList, 3) // Readout list object used for manipulating and storing an AliHLTEventDDL structure.
dce3e5ce 394
395};
396
397#endif // ALIHLTREADOUTLIST_H
398