Line data Source code
1 : //-*- Mode: C++ -*-
2 : // $Id$
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 :
14 : #include "TNamed.h"
15 : #include "AliHLTDataTypes.h"
16 :
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.
32 : * - unsets the bits in readout list A that are set in readout list B.
33 : * This effectively applies A & (A ^ B).
34 : */
35 : class AliHLTReadoutList : public TNamed
36 : {
37 : public:
38 :
39 : /**
40 : * Identifiers for different detectors used by methods in AliHLTReadoutList.
41 : */
42 : enum EDetectorId
43 : {
44 : kNoDetector = 0, /// No detector value
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 : kAD = 0x1 << 21, /// ID for AD detector
66 : kHLT = 0x1 << 30, /// ID for HLT detector
67 : // kALLDET sets readout for all detectors except DAQ_TEST
68 : kALLDET = (kITSSPD | kITSSDD | kITSSSD | kTPC | kTRD | kTOF | kHMPID | kPHOS
69 : | kCPV | kPMD | kMUONTRK | kMUONTRG | kFMD | kT0 | kV0 | kZDC
70 : | kACORDE | kTRG | kEMCAL | kAD | kHLT)
71 : };
72 :
73 : /// Converts a detector ID to a user readable string.
74 : static const char* DetectorIdToString(EDetectorId id);
75 :
76 : /**
77 : * Default constructor.
78 : */
79 : AliHLTReadoutList();
80 :
81 : /**
82 : * Constructor to select which detectors to enable for readout.
83 : * \param enabledDetectors Detector bit field. Can be any values for
84 : * EDetectorId or'ed together.
85 : */
86 : AliHLTReadoutList(Int_t enabledDetectors);
87 :
88 : /**
89 : * Constructor to select which detectors and DDLs to enable for readout.
90 : * \param enabledList The string format is a space separated list where
91 : * each item is either a detector acronym name or DDL number.
92 : * Invalid sub-strings are simply ignored. The special ALL string is
93 : * equivalent to kALLDET for AliHLTReadoutList(Int_t enabledDetectors).
94 : */
95 : AliHLTReadoutList(const char* enabledList);
96 :
97 : /**
98 : * Constructor to create readout list from AliHLTEventDDL structure.
99 : * \param list The AliHLTEventDDL structure from which to create this object.
100 : */
101 : AliHLTReadoutList(const AliHLTEventDDL& list);
102 :
103 : /**
104 : * The copy constructor performs a deep copy.
105 : * \param list The readout list to copy from.
106 : */
107 : AliHLTReadoutList(const AliHLTReadoutList& list);
108 :
109 : /**
110 : * Default destructor.
111 : */
112 : virtual ~AliHLTReadoutList();
113 :
114 : /**
115 : * Checks if the readout list is empty, i.e. all DDLs are disabled.
116 : * \returns true if the readout list is empty and false otherwise.
117 : */
118 : bool Empty() const;
119 :
120 : /**
121 : * Disables all bits in the readout list.
122 : * \param option This parameter is ignored.
123 : * The method is inherited from TObject.
124 : */
125 : virtual void Clear(Option_t* option = "");
126 :
127 : /**
128 : * Enables a specific DDL bit in the readout list.
129 : * \param ddlId The ID number of the DDL to enable.
130 : */
131 : void EnableDDLBit(Int_t ddlId)
132 : {
133 0 : SetDDLBit(ddlId, kTRUE);
134 0 : }
135 :
136 : /**
137 : * Disables a specific DDL bit in the readout list.
138 : * \param ddlId The ID number of the DDL to disable.
139 : */
140 : void DisableDDLBit(Int_t ddlId)
141 : {
142 0 : SetDDLBit(ddlId, kFALSE);
143 0 : }
144 :
145 : /**
146 : * Fetches the bit value for a particular DDL in the readout list.
147 : * \param ddlId The ID number of the DDL to fetch.
148 : * \return the bit value for the specified DDL.
149 : */
150 : Bool_t GetDDLBit(Int_t ddlId) const;
151 :
152 : /**
153 : * Sets the bit value for a particular DDL in the readout list.
154 : * \param ddlId The ID number of the DDL to set.
155 : * \param state The value to set the bit to.
156 : */
157 : void SetDDLBit(Int_t ddlId, Bool_t state);
158 :
159 : /**
160 : * Checks if a particular DDL is enabled for readout.
161 : * \param ddlId The ID number of the DDL to check.
162 : * \return the if the DDL is enabled for readout.
163 : */
164 : bool IsDDLEnabled(Int_t ddlId) const
165 : {
166 0 : return GetDDLBit(ddlId) == kTRUE;
167 : }
168 :
169 : /**
170 : * Checks if a particular DDL is disabled for readout.
171 : * \param ddlId The ID number of the DDL to check.
172 : * \return the if the DDL is disabled for readout.
173 : */
174 : bool IsDDLDisabled(Int_t ddlId) const
175 : {
176 0 : return GetDDLBit(ddlId) == kFALSE;
177 : }
178 :
179 : /**
180 : * Enables all DDLs for a particular detector or detectors.
181 : * \param detector A bitmap of detectors to enable. Should be any values from
182 : * EDetectorId that can be or'ed together for multiple detector selection.
183 : */
184 : void Enable(Int_t detector);
185 :
186 : /**
187 : * Disables all DDLs for a particular detector or detectors.
188 : * \param detector A bitmap of detectors to disable. Should be any values from
189 : * EDetectorId that can be or'ed together for multiple detector selection.
190 : */
191 : void Disable(Int_t detector);
192 :
193 : /**
194 : * Checks if a particular detector's DDLs are all enabled for readout.
195 : * \param detector A bitmap of detectors to check. Should be any values from
196 : * EDetectorId that can be or'ed together for multiple detector selection.
197 : * \return true if all DDLs for the specified detectors are enabled for readout.
198 : */
199 : bool DetectorEnabled(Int_t detector) const;
200 :
201 : /**
202 : * Checks if a particular detector's DDLs are all disabled for readout.
203 : * \param detector A bitmap of detectors to check. Should be any values from
204 : * EDetectorId that can be or'ed together for multiple detector selection.
205 : * \return true if all DDLs for the specified detectors are disabled for readout.
206 : * \note If both DetectorEnabled(x) and DetectorDisabled(x) return false then
207 : * it means that only part of the detectors DDLs are enabled.
208 : */
209 : bool DetectorDisabled(Int_t detector) const;
210 :
211 : /**
212 : * Returns the first word of DDL bits for a given detector in the internal structure.
213 : * \param detector The detector code for which to return the starting word.
214 : * \returns the first word of DDL bits for the detector or -1 if an invalid code is given.
215 : */
216 : static Int_t GetFirstWord(EDetectorId detector);
217 :
218 : /**
219 : * Returns the first word of DDL bits for a given detector in the internal structure.
220 : * \param detector The detector code for which to return the starting word.
221 : * \returns the first word of DDL bits for the detector or -1 if an invalid code is given.
222 : */
223 : static Int_t GetWordCount(EDetectorId detector);
224 :
225 : /**
226 : * Returns the corresponding detector ID code for the given word index into the
227 : * internal data structure.
228 : * \param wordindex The position of the word from the start of the DDL readout bit list.
229 : * \returns the code of the corresponding detector or kNoDetector if invalid.
230 : */
231 : static EDetectorId GetDetectorFromWord(Int_t wordindex);
232 :
233 : /**
234 : * Returns the first detector with non-zero DDL bits.
235 : * \param startAfter The detector code after which to start looking from.
236 : * If kTOF is used for example then only detectors after kTOF will be checked,
237 : * not including kTOF, in the order of precedence indicated by EDetectorId.
238 : * \returns the code of the first used detector.
239 : */
240 : EDetectorId GetFirstUsedDetector(EDetectorId startAfter = kNoDetector) const;
241 :
242 : /**
243 : * Inherited from TObject. Prints the DDLs that will be readout according to
244 : * this readout list.
245 : * \param option This is not used by this method.
246 : */
247 : virtual void Print(Option_t* option = "") const;
248 :
249 : /**
250 : * This typecast operator converts the readout list to the AliHLTEventDDL
251 : * structure format.
252 : * \return Constant reference to the AliHLTEventDDL raw structure.
253 : */
254 0 : operator const AliHLTEventDDL& () const { return fReadoutList; }
255 :
256 : /**
257 : * This typecast operator converts the readout list to the AliHLTEventDDL
258 : * structure format.
259 : * \return Reference to the AliHLTEventDDL raw structure.
260 : */
261 0 : operator AliHLTEventDDL& () { return fReadoutList; }
262 :
263 : /**
264 : * Access method to the binary buffer.
265 : * \return pointer to the binary buffer.
266 : */
267 0 : AliHLTEventDDL* Buffer() { return &fReadoutList; }
268 :
269 : /**
270 : * Access method to the binary buffer.
271 : * \return const pointer to the binary buffer.
272 : */
273 0 : const AliHLTEventDDL* Buffer() const { return &fReadoutList; }
274 :
275 : /**
276 : * Access to the size of the binary buffer.
277 : * \return size of the binary buffer
278 : */
279 0 : unsigned BufferSize() const { return sizeof(fReadoutList); }
280 :
281 : /**
282 : * Assignment operator performs a deep copy.
283 : * \param list The readout list to copy from.
284 : * \return A reference to this object.
285 : */
286 : AliHLTReadoutList& operator = (const AliHLTReadoutList& list);
287 :
288 : /**
289 : * This operator performs a bitwise inclusive or operation on all DDL bits
290 : * between this readout and <i>list</i>.
291 : * \param list The right hand side readout list to operate on.
292 : * \return A reference to this object.
293 : */
294 : AliHLTReadoutList& operator |= (const AliHLTReadoutList& list);
295 :
296 : /// same as operator |=
297 : AliHLTReadoutList& OrEq(const AliHLTReadoutList& list);
298 :
299 : /**
300 : * This operator performs a bitwise exclusive or (xor) operation on all DDL
301 : * bits between this readout and <i>list</i>.
302 : * \param list The right hand side readout list to operate on.
303 : * \return A reference to this object.
304 : */
305 : AliHLTReadoutList& operator ^= (const AliHLTReadoutList& list);
306 :
307 : /// same as operator ^=
308 : AliHLTReadoutList& XorEq(const AliHLTReadoutList& list);
309 :
310 : /**
311 : * This operator performs a bitwise and operation on all DDL bits between
312 : * this readout and <i>list</i>.
313 : * \param list The right hand side readout list to operate on.
314 : * \return A reference to this object.
315 : */
316 : AliHLTReadoutList& operator &= (const AliHLTReadoutList& list);
317 :
318 : /// same as operator &=
319 : AliHLTReadoutList& AndEq(const AliHLTReadoutList& list);
320 :
321 : /**
322 : * This operator performs the effective operation of "this and (this xor list)".
323 : * It removes all the DDLs specified in list from this readout list.
324 : * \param list The right hand side readout list to operate on.
325 : * \return A reference to this object.
326 : */
327 : AliHLTReadoutList& operator -= (const AliHLTReadoutList& list);
328 :
329 : /**
330 : * This operator performs a bitwise ones compliment on all DDL bits of this
331 : * readout list.
332 : * \return The result of the unary operator.
333 : */
334 : AliHLTReadoutList operator ~ () const;
335 :
336 : /**
337 : * This operator performs a bitwise inclusive or operation on all DDL bits
338 : * between this readout and <i>list</i>.
339 : * \param list The right hand side readout list to operate on.
340 : * \return The result of the binary operator.
341 : */
342 : AliHLTReadoutList operator | (const AliHLTReadoutList& list) const
343 : {
344 0 : AliHLTReadoutList result = *this;
345 0 : return result.operator |= (list);
346 0 : }
347 :
348 : /**
349 : * This operator performs a bitwise exclusive or (xor) operation on all DDL
350 : * bits between this readout and <i>list</i>.
351 : * \param list The right hand side readout list to operate on.
352 : * \return The result of the binary operator.
353 : */
354 : AliHLTReadoutList operator ^ (const AliHLTReadoutList& list) const
355 : {
356 0 : AliHLTReadoutList result = *this;
357 0 : return result.operator ^= (list);
358 0 : }
359 :
360 : /**
361 : * This operator performs a bitwise and operation on all DDL bits between
362 : * this readout and <i>list</i>.
363 : * \param list The right hand side readout list to operate on.
364 : * \return The result of the binary operator.
365 : */
366 : AliHLTReadoutList operator & (const AliHLTReadoutList& list) const
367 : {
368 0 : AliHLTReadoutList result = *this;
369 0 : return result.operator &= (list);
370 0 : }
371 :
372 : /**
373 : * This operator performs the effective operation of "this and (this xor list)".
374 : * i.e. the set difference.
375 : * It removes all the DDLs specified in list from this readout list.
376 : * \param list The right hand side readout list to operate on.
377 : * \return The result of the binary operator.
378 : */
379 : AliHLTReadoutList operator - (const AliHLTReadoutList& list) const
380 : {
381 0 : AliHLTReadoutList result = *this;
382 0 : return result.operator -= (list);
383 0 : }
384 :
385 : /**
386 : * Decodes the word index and bit index within that word for the readout list structure.
387 : * \param [in] ddlId The ID number of the DDL to decode.
388 : * \param [out] wordIndex the word index of the word to modify or check within fReadoutList.fList
389 : * \param [out] bitIndex the bit index of the bit to modify or check
390 : * within the word pointed to by <i>wordIndex</i>.
391 : * \return true if the ddlId was decoded and false if it was invalid.
392 : * \note We do not check extensively if the ddlId is invalid. Just simple checks
393 : * are performed to see that we do not overflow the buffer fReadoutList.fList.
394 : */
395 : static bool DecodeDDLID(Int_t ddlId, Int_t& wordIndex, Int_t& bitIndex);
396 :
397 :
398 : private:
399 :
400 : /**
401 : * This method fills the internal bit field structure taking care of converting
402 : * from the old format to the new one.
403 : * \param list The raw DDL readout list bits.
404 : */
405 : void FillStruct(const AliHLTEventDDL& list);
406 :
407 : AliHLTEventDDL fReadoutList; /// The DDL readout list structure.
408 :
409 126 : ClassDef(AliHLTReadoutList, 4) // Readout list object used for manipulating and storing an AliHLTEventDDL structure.
410 :
411 : };
412 :
413 : #endif // ALIHLTREADOUTLIST_H
414 :
|