]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/AliHLTMUONUtils.h
Getting rid of warning.
[u/mrichter/AliRoot.git] / HLT / MUON / AliHLTMUONUtils.h
1 #ifndef ALIHLTMUONUTILS_H
2 #define ALIHLTMUONUTILS_H
3 /* Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 /* $Id$ */
7
8 ///
9 /// @file   AliHLTMUONUtils.h
10 /// @author Artur Szostak <artursz@iafrica.com>
11 /// @date   17 May 2007
12 /// @brief  Class containing various dimuon HLT utility routines and macros.
13 ///
14
15 #include "TObject.h"
16 #include "AliHLTMUONDataTypes.h"
17 #include <ostream>
18
19 // Forward declare structures.
20 extern "C" {
21 struct AliHLTMUONTriggerRecordStruct;
22 struct AliHLTMUONTriggerRecordsBlockStruct;
23 struct AliHLTMUONTrigRecInfoStruct;
24 struct AliHLTMUONTrigRecsDebugBlockStruct;
25 struct AliHLTMUONRecHitStruct;
26 struct AliHLTMUONRecHitsBlockStruct;
27 struct AliHLTMUONClusterStruct;
28 struct AliHLTMUONClustersBlockStruct;
29 struct AliHLTMUONChannelStruct;
30 struct AliHLTMUONChannelsBlockStruct;
31 struct AliHLTMUONMansoTrackStruct;
32 struct AliHLTMUONMansoTracksBlockStruct;
33 struct AliHLTMUONMansoCandidateStruct;
34 struct AliHLTMUONMansoCandidatesBlockStruct;
35 struct AliHLTMUONTrackDecisionStruct;
36 struct AliHLTMUONSinglesDecisionBlockStruct;
37 struct AliHLTMUONPairDecisionStruct;
38 struct AliHLTMUONPairsDecisionBlockStruct;
39 } // extern "C"
40
41 /**
42  * AliHLTMUONUtils contains arbitrary utility methods to be used in various
43  * parts of the dimuon HLT system.
44  * These include methods to perform basic sanity checks on the integrity of
45  * data blocks.
46  */
47 class AliHLTMUONUtils
48 {
49 public:
50         /**
51          * This packs the given parameters into the bits of a word appropriate
52          * for AliHLTMUONTriggerRecordStruct::fFlags.
53          * @param sign    The particle sign.
54          * @param hitset  Flags to indicate if the corresponding fHits[i] elements
55          *                was set/filled.
56          * @return  Returns the 32 bit packed word.
57          */
58         static AliHLTUInt32_t PackTriggerRecordFlags(
59                         AliHLTMUONParticleSign sign, const bool hitset[4]
60                 );
61
62         /**
63          * This unpacks the AliHLTMUONTriggerRecordStruct::fFlags bits into
64          * its component fields.
65          * @param flags  The flags from an AliHLTMUONTriggerRecordStruct structure.
66          * @param sign    Sets this to the particle sign.
67          * @param hitset  Sets the array elements to indicate if the corresponding
68          *                fHits[i] element was set/filled.
69          */
70         static void UnpackTriggerRecordFlags(
71                         AliHLTUInt32_t flags, // [in]
72                         AliHLTMUONParticleSign& sign, // [out]
73                         bool hitset[4] // [out]
74                 );
75         
76         /**
77          * This packs the given parameters into the bits of a word appropriate
78          * for AliHLTMUONRecHitStruct::fFlags.
79          * @param chamber    The chamber number in the range [0..13].
80          * @param detElemId  Detector element ID number.
81          * @return  Returns the 32 bit packed word.
82          */
83         static AliHLTUInt32_t PackRecHitFlags(
84                         AliHLTUInt8_t chamber, AliHLTUInt16_t detElemId
85                 );
86
87         /**
88          * This unpacks the AliHLTMUONRecHitStruct::fFlags bits into
89          * its component fields.
90          * [in]  @param flags  The flags from an AliHLTMUONRecHitStruct structure.
91          * [out] @param chamber    Sets the chamber number in the range [0..13].
92          * [out] @param detElemId  Sets the detector element ID number.
93          */
94         static void UnpackRecHitFlags(
95                         AliHLTUInt32_t flags, // [in]
96                         AliHLTUInt8_t& chamber, // [out]
97                         AliHLTUInt16_t& detElemId // [out]
98                 );
99
100         /**
101          * This packs the given parameters into the bits of a word appropriate
102          * for AliHLTMUONMansoTrackStruct::fFlags.
103          * @param sign    The particle sign.
104          * @param hitset  Flags to indicate if the corresponding fHits[i] elements
105          *                was set/filled.
106          * @return  Returns the 32 bit packed word.
107          */
108         static AliHLTUInt32_t PackMansoTrackFlags(
109                         AliHLTMUONParticleSign sign, const bool hitset[4]
110                 )
111         {
112                 return PackTriggerRecordFlags(sign, hitset);
113         }
114
115         /**
116          * This unpacks the AliHLTMUONMansoTrackStruct::fFlags bits into
117          * its component fields.
118          * @param flags  The flags from an AliHLTMUONMansoTrackStruct structure.
119          * @param sign    Sets this to the particle sign.
120          * @param hitset  Sets the array elements to indicate if the corresponding
121          *                fHits[i] element was set/filled.
122          */
123         static void UnpackMansoTrackFlags(
124                         AliHLTUInt32_t flags, // [in]
125                         AliHLTMUONParticleSign& sign, // [out]
126                         bool hitset[4] // [out]
127                 )
128         {
129                 UnpackTriggerRecordFlags(flags, sign, hitset);
130         }
131         
132         /**
133          * This packs the given parameters into the bits of a word appropriate
134          * for AliHLTMUONTrackDecisionStruct::fTriggerBits.
135          * @param highPt  Has the track passed the high pt cut.
136          * @param lowPt   Has the track passed the low pt cut.
137          * @return  Returns the 32 bit packed word.
138          */
139         static AliHLTUInt32_t PackTrackDecisionBits(bool highPt, bool lowPt);
140         
141         /**
142          * This unpacks the AliHLTMUONTrackDecisionStruct::fTriggerBits bits into
143          * its component fields.
144          * @param bits  The trigger bits from an AliHLTMUONTrackDecisionStruct
145          *              structure.
146          * @param highPt Sets this to the value of the high pt cut bit.
147          * @param lowPt  Sets this to the value of the low pt cut bit.
148          */
149         static void UnpackTrackDecisionBits(
150                         AliHLTUInt32_t bits, // [in]
151                         bool& highPt, // [out]
152                         bool& lowPt // [out]
153                 );
154         
155         /**
156          * This packs the given parameters into the bits of a word appropriate
157          * for AliHLTMUONPairDecisionStruct::fTriggerBits.
158          *
159          * @param highMass Has the track pair passed the high invariant mass cut.
160          * @param lowMass  Has the track pair passed the low invariant mass cut.
161          * @param unlike   Does the track pair have unlike signs.
162          * @param highPtCount The number of tracks that passed the high pt cut
163          *                    in the pair.
164          * @param lowPtCount  The number of tracks that passed the low pt cut
165          *                    in the pair.
166          * @return  Returns the 32 bit packed word.
167          *
168          * Note: Must have highPtCount + lowPtCount <= 2 and unlike == true if
169          * highMass or lowMass is true.
170          */
171         static AliHLTUInt32_t PackPairDecisionBits(
172                         bool highMass, bool lowMass, bool unlike,
173                         AliHLTUInt8_t highPtCount, AliHLTUInt8_t lowPtCount
174                 );
175         
176         /**
177          * This unpacks the AliHLTMUONPairDecisionStruct::fTriggerBits bits into
178          * its component fields.
179          * @param bits  The trigger bits from an AliHLTMUONPairDecisionStruct
180          *              structure.
181          * @param highMass Sets this to the value of the high invariant mass cut bit.
182          * @param lowMass  Sets this to the value of the low invariant mass cut bit.
183          * @param unlike   Sets this if the pair is unlike sign.
184          * @param highPtCount Sets this to the high pt count bits.
185          * @param lowPtCount  Sets this to the low pt count bits.
186          */
187         static void UnpackPairDecisionBits(
188                         AliHLTUInt32_t bits, // [in]
189                         bool& highMass, // [out]
190                         bool& lowMass, // [out]
191                         bool& unlike, // [out]
192                         AliHLTUInt8_t& highPtCount, // [out]
193                         AliHLTUInt8_t& lowPtCount // [out]
194                 );
195         
196         /**
197          * This packs the given parameters into the 32bit Pub/Sub specification
198          * word in the data block descriptor.
199          *
200          * @param ddl  The list of DDLs forming part of the readout. ddl[0]
201          *             indicates DDL number 2560, ddl[1] is for DDL 2561 and so
202          *             on up to ddl[19]. ddl[20] and ddl[21] will be for the
203          *             trigger DDLs 2816 and 2817 respectively.
204          * @return  Returns the 32 bit packed specification word.
205          */
206         static AliHLTUInt32_t PackSpecBits(
207                         const bool ddl[22]
208                 );
209         
210         /**
211          * This unpacks the AliHLTMUONPairDecisionStruct::fTriggerBits bits into
212          * its component fields.
213          * @param bits  The Pub/Sub specification word from a data block descriptor.
214          * @param ddl  The output list of DDLs forming part of the readout. ddl[0]
215          *             indicates DDL number 2560, ddl[1] is for DDL 2561 and so
216          *             on up to ddl[19]. ddl[20] and ddl[21] will be for the
217          *             trigger DDLs 2816 and 2817 respectively.
218          */
219         static void UnpackSpecBits(
220                         AliHLTUInt32_t bits, // [in]
221                         bool ddl[22] // [out]
222                 );
223
224         /**
225          * This method converts the DDL number for the muon spectrometer in the
226          * range [0..21] to the equipment ID number.
227          * @param ddlNo  The DDL number in the range [0..21].
228          * @return  Returns the equipment ID number or -1 if ddlNo was invalid.
229          */
230         static AliHLTInt32_t DDLNumberToEquipId(AliHLTInt32_t ddlNo);
231         
232         /**
233          * This method converts the equipment ID number for a muon spectrometer
234          * DDL to the DDL number in the range [0..21].
235          * @param id  The equipment ID of the DDL.
236          * @return  Returns the DDL number in the range [0..21] or -1 if the
237          *          equipment ID was invalid.
238          */
239         static AliHLTInt32_t EquipIdToDDLNumber(AliHLTInt32_t id);
240         
241         /**
242          * This method converts a 32 bit data block specification for a MUON-HLT
243          * data block into its corresponding DDL equipment ID number.
244          * It is assumed that the specification is for a data block comming from
245          * a single DDL source. If more than one DDL contributed to the data block
246          * then -1 is returned.
247          * @param spec  The 32 bit specification for a data block.
248          * @return  Returns the equipment ID corresponding to the specification
249          *          or -1 if the specification was invalid.
250          */
251         static AliHLTInt32_t SpecToEquipId(AliHLTUInt32_t spec);
252         
253         /**
254          * This method converts a equipment ID number for a DDL into its corresponding
255          * 32 bit data block specification for the MUON-HLT.
256          * @param id  The equipment ID number of the DDL.
257          * @return  Returns the 32 bit data block specification or 0x0 if the
258          *          equipment ID was invalid.
259          */
260         static AliHLTUInt32_t EquipIdToSpec(AliHLTInt32_t id);
261         
262         /**
263          * This method converts a 32 bit data block specification for a MUON-HLT
264          * data block into its corresponding DDL number in the range [0..21].
265          * It is assumed that the specification is for a data block comming from
266          * a single DDL source. If more than one DDL contributed to the data block
267          * then -1 is returned.
268          * @param spec  The 32 bit specification for a data block.
269          * @return  Returns the corresponding DDL number for the specification
270          *          or -1 if the specification was invalid.
271          */
272         static AliHLTInt32_t SpecToDDLNumber(AliHLTUInt32_t spec);
273         
274         /**
275          * This method converts a DDL number in the range [0..21] into its
276          * corresponding 32 bit data block specification for the MUON-HLT.
277          * @param ddlNo  The equipment ID number of the DDL.
278          * @return  Returns the 32 bit data block specification or 0x0 if the
279          *          DDL number was invalid (out of range).
280          */
281         static AliHLTUInt32_t DDLNumberToSpec(AliHLTInt32_t ddlNo);
282
283         /**
284          * Returns true if the given specification was for a single trigger DDL.
285          */
286         static bool IsTriggerDDL(AliHLTUInt32_t spec)
287         {
288                 AliHLTInt32_t ddl = SpecToDDLNumber(spec);
289                 return (20 <= ddl and ddl <= 21);
290         }
291
292         /**
293          * Returns true if the given specification was for a single tracker DDL.
294          */
295         static bool IsTrackerDDL(AliHLTUInt32_t spec)
296         {
297                 AliHLTInt32_t ddl = SpecToDDLNumber(spec);
298                 return (0 <= ddl and ddl <= 19);
299         }
300
301         /**
302          * Returns true if the given specification is in principle valid.
303          * It checks if the bits that should be zero are indeed zero.
304          */
305         static bool IsSpecValid(AliHLTUInt32_t spec)
306         {
307                 AliHLTUInt32_t mask = ~((1 << 22) - 1);  // First 22 bits indicate DDL number.
308                 return (spec & mask) == 0x0;
309         }
310
311         /**
312          * Returns true if the data specification indicates the data block contains
313          * information generated from a trigger DDL or data fragments thereof.
314          */
315         static bool ContainsDataFromTrigger(AliHLTUInt32_t spec)
316         {
317                 AliHLTUInt32_t mask = ((1 << 22) - 1) & ~((1 << 20) - 1);
318                 return (spec & mask) != 0x0;
319         }
320
321         /**
322          * Returns true if the data specification indicates the data block contains
323          * information generated from a tracker DDL or data fragments thereof.
324          */
325         static bool ContainsDataFromTracker(AliHLTUInt32_t spec)
326         {
327                 AliHLTUInt32_t mask = ((1 << 20) - 1);
328                 return (spec & mask) != 0x0;
329         }
330         
331         /**
332          * Parses the string containing the type name of a dHLT data block and
333          * returns the corresponding AliHLTMUONDataBlockType value.
334          * \param  type  The string containing the type name.
335          * \returns  The data block type or kUnknownDataBlock if the type name
336          *      is invalid.
337          */
338         static AliHLTMUONDataBlockType ParseCommandLineTypeString(const char* type);
339         
340         /**
341          * Converts a type ID to a type string to be used for the dHLT FilePublisher
342          * component configuration parameters for example.
343          */
344         static const char* DataBlockTypeToString(AliHLTMUONDataBlockType type);
345         
346         /**
347          * These codes indicate the reason why a data block failed its
348          * validity check.
349          */
350         enum WhyNotValid
351         {
352                 kNoReason,   ///< There was no reason for failure.
353                 kHeaderContainsWrongType,  ///< The common header contains an incorrect type ID.
354                 kHeaderContainsWrongRecordWidth,  ///< The common header contains an incorrect data record width.
355                 kInvalidIdValue,  ///< The structure identifier does not have a valid value.
356                 kInvalidTriggerIdValue,  ///< The trigger structure identifier does not have a valid value.
357                 kInvalidTrackIdValue,  ///< The track structure identifier does not have a valid value.
358                 kReservedBitsNotZero,  ///< Reserved bits have not been set to zero.
359                 kParticleSignBitsNotValid,  ///< The particle sign bits are not a valid value.
360                 kHitNotMarkedAsNil,  ///< A hit was marked as not found, but the corresponding hit structure was not set to nil.
361                 kInvalidDetElementNumber,  ///< An invalid detector element ID was found.
362                 kInvalidChamberNumber,  ///< An invalid chamber number was found.
363                 kHitIsNil,  ///< The hit cannot be set to a nil value.
364                 kInvalidChannelCount,  ///< The number of channels indicated is zero or outside the valid range.
365                 kInvalidBusPatchId,  ///< The bus patch ID is outside the valid range.
366                 kInvalidManuId,  ///< The MANU ID is outside the valid range.
367                 kInvalidChannelAddress,  ///< The MANU channel address is outside the valid range.
368                 kInvalidSignal,  ///< The ADC signal value is outside the valid range.
369                 kDataWordDifferent, ///< The raw data word is different from the unpacked values.
370                 kChiSquareInvalid,  ///< The chi squared value must be a positive value or -1 indicating a fitting error.
371                 kMomentumVectorNotZero, ///< The chi sqaured value is set to -1, but momentum vector not zero.
372                 kRoiRadiusInvalid, ///< The region of interest radius is invalid.
373                 kHitNotWithinRoi, ///< A tracks hit is not within the corresponding region of interest.
374                 kPtValueNotValid,  ///< The pT value is not positive nor -1 indicating an invalid value.
375                 kPairTrackIdsAreIdentical,  ///< The track IDs of the track pair are identical.
376                 kMassValueNotValid,  ///< The invariant mass value is not positive nor -1 indicating an invalid value.
377                 kLowPtCountInvalid,  ///< The low pT trigger count is greater than 2, which is invalid.
378                 kHighPtCountInvalid,  ///< The high pT trigger count is greater than 2, which is invalid.
379                 kFoundDuplicateIDs,  ///< Found duplicate identifiers, but they should all be unique.
380                 kFoundDuplicateHits,  ///< Found duplicate hits.
381                 kFoundDuplicateTriggers  ///< Found duplicate trigger decisions.
382         };
383         
384         /**
385          * This method converts the WhyNotValid enumeration to a string representation.
386          */
387         static const char* FailureReasonToString(WhyNotValid reason);
388         
389         /**
390          * This method returns a string containing a user readable message explaining
391          * the reason for failure described by the WhyNotValid enumeration.
392          */
393         static const char* FailureReasonToMessage(WhyNotValid reason);
394
395         /**
396          * Method used to check if the header information corresponds to the
397          * supposed type of the trigger records data block.
398          * This method will return either kHeaderContainsWrongType or
399          * kHeaderContainsWrongRecordWidth as the reason code.
400          * [in]  \param block  The data block to check.
401          * [out] \param reason  If this is not NULL, then the variable pointed to
402          *      by this pointer will be filled with the reason code describing why
403          *      the header is not valid, if and only if a problem is found with
404          *      the data.
405          * \returns  true if there is no problem with the header and false otherwise.
406          */
407         static bool HeaderOk(const AliHLTMUONTriggerRecordsBlockStruct& block, WhyNotValid* reason = NULL)
408         {
409                 AliHLTUInt32_t count = 1;
410                 return HeaderOk(block, reason, count);
411         }
412         
413         /**
414          * Method used to check if the header information corresponds to the
415          * supposed type of the trigger debug information data block.
416          * This method will return either kHeaderContainsWrongType or
417          * kHeaderContainsWrongRecordWidth as the reason code.
418          * [in]  \param block  The data block to check.
419          * [out] \param reason  If this is not NULL, then the variable pointed to
420          *      by this pointer will be filled with the reason code describing why
421          *      the header is not valid, if and only if a problem is found with
422          *      the data.
423          * \returns  true if there is no problem with the header and false otherwise.
424          */
425         static bool HeaderOk(const AliHLTMUONTrigRecsDebugBlockStruct& block, WhyNotValid* reason = NULL)
426         {
427                 AliHLTUInt32_t count = 1;
428                 return HeaderOk(block, reason, count);
429         }
430         
431         /**
432          * Method used to check if the header information corresponds to the
433          * supposed type of the reconstructed hits data block.
434          * This method will return either kHeaderContainsWrongType or
435          * kHeaderContainsWrongRecordWidth as the reason code.
436          * [in]  \param block  The data block to check.
437          * [out] \param reason  If this is not NULL, then the variable pointed to
438          *      by this pointer will be filled with the reason code describing why
439          *      the header is not valid, if and only if a problem is found with
440          *      the data.
441          * \returns  true if there is no problem with the header and false otherwise.
442          */
443         static bool HeaderOk(const AliHLTMUONRecHitsBlockStruct& block, WhyNotValid* reason = NULL)
444         {
445                 AliHLTUInt32_t count = 1;
446                 return HeaderOk(block, reason, count);
447         }
448         
449         /**
450          * Method used to check if the header information corresponds to the
451          * supposed type of the clusters data block.
452          * This method will return either kHeaderContainsWrongType or
453          * kHeaderContainsWrongRecordWidth as the reason code.
454          * [in]  \param block  The data block to check.
455          * [out] \param reason  If this is not NULL, then the variable pointed to
456          *      by this pointer will be filled with the reason code describing why
457          *      the header is not valid, if and only if a problem is found with
458          *      the data.
459          * \returns  true if there is no problem with the header and false otherwise.
460          */
461         static bool HeaderOk(const AliHLTMUONClustersBlockStruct& block, WhyNotValid* reason = NULL)
462         {
463                 AliHLTUInt32_t count = 1;
464                 return HeaderOk(block, reason, count);
465         }
466         
467         /**
468          * Method used to check if the header information corresponds to the
469          * supposed type of the channels data block.
470          * This method will return either kHeaderContainsWrongType or
471          * kHeaderContainsWrongRecordWidth as the reason code.
472          * [in]  \param block  The data block to check.
473          * [out] \param reason  If this is not NULL, then the variable pointed to
474          *      by this pointer will be filled with the reason code describing why
475          *      the header is not valid, if and only if a problem is found with
476          *      the data.
477          * \returns  true if there is no problem with the header and false otherwise.
478          */
479         static bool HeaderOk(const AliHLTMUONChannelsBlockStruct& block, WhyNotValid* reason = NULL)
480         {
481                 AliHLTUInt32_t count = 1;
482                 return HeaderOk(block, reason, count);
483         }
484         
485         /**
486          * Method used to check if the header information corresponds to the
487          * supposed type of the Manso tracks data block.
488          * This method will return either kHeaderContainsWrongType or
489          * kHeaderContainsWrongRecordWidth as the reason code.
490          * [in]  \param block  The data block to check.
491          * [out] \param reason  If this is not NULL, then the variable pointed to
492          *      by this pointer will be filled with the reason code describing why
493          *      the header is not valid, if and only if a problem is found with
494          *      the data.
495          * \returns  true if there is no problem with the header and false otherwise.
496          */
497         static bool HeaderOk(const AliHLTMUONMansoTracksBlockStruct& block, WhyNotValid* reason = NULL)
498         {
499                 AliHLTUInt32_t count = 1;
500                 return HeaderOk(block, reason, count);
501         }
502         
503         /**
504          * Method used to check if the header information corresponds to the
505          * supposed type of the Manso candidates data block.
506          * This method will return either kHeaderContainsWrongType or
507          * kHeaderContainsWrongRecordWidth as the reason code.
508          * [in]  \param block  The data block to check.
509          * [out] \param reason  If this is not NULL, then the variable pointed to
510          *      by this pointer will be filled with the reason code describing why
511          *      the header is not valid, if and only if a problem is found with
512          *      the data.
513          * \returns  true if there is no problem with the header and false otherwise.
514          */
515         static bool HeaderOk(const AliHLTMUONMansoCandidatesBlockStruct& block, WhyNotValid* reason = NULL)
516         {
517                 AliHLTUInt32_t count = 1;
518                 return HeaderOk(block, reason, count);
519         }
520         
521         /**
522          * Method used to check if the header information corresponds to the
523          * supposed type of the single tracks dHLT trigger decision data block.
524          * This method will return either kHeaderContainsWrongType or
525          * kHeaderContainsWrongRecordWidth as the reason code.
526          * [in]  \param block  The data block to check.
527          * [out] \param reason  If this is not NULL, then the variable pointed to
528          *      by this pointer will be filled with the reason code describing why
529          *      the header is not valid, if and only if a problem is found with
530          *      the data.
531          * \returns  true if there is no problem with the header and false otherwise.
532          */
533         static bool HeaderOk(const AliHLTMUONSinglesDecisionBlockStruct& block, WhyNotValid* reason = NULL)
534         {
535                 AliHLTUInt32_t count = 1;
536                 return HeaderOk(block, reason, count);
537         }
538         
539         /**
540          * Method used to check if the header information corresponds to the
541          * supposed type of the track pairs dHLT trigger decision data block.
542          * This method will return either kHeaderContainsWrongType or
543          * kHeaderContainsWrongRecordWidth as the reason code.
544          * [in]  \param block  The data block to check.
545          * [out] \param reason  If this is not NULL, then the variable pointed to
546          *      by this pointer will be filled with the reason code describing why
547          *      the header is not valid, if and only if a problem is found with
548          *      the data.
549          * \returns  true if there is no problem with the header and false otherwise.
550          */
551         static bool HeaderOk(const AliHLTMUONPairsDecisionBlockStruct& block, WhyNotValid* reason = NULL)
552         {
553                 AliHLTUInt32_t count = 1;
554                 return HeaderOk(block, reason, count);
555         }
556
557         /**
558          * Methods used to check if the header information corresponds to the
559          * supposed type of the data block.
560          * If the 'reason' parameter should point to an array which will store
561          * the reason codes indicating the problems with the data block.
562          * The 'reasonCount' parameter should initialy contain the number of
563          * elements that can be stored in reason. When the method exits it will
564          * store the number of elements in the 'reason' array actually filled.
565          */
566         static bool HeaderOk(
567                         const AliHLTMUONTriggerRecordsBlockStruct& block,
568                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
569                 );
570         
571         static bool HeaderOk(
572                         const AliHLTMUONTrigRecsDebugBlockStruct& block,
573                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
574                 );
575         
576         static bool HeaderOk(
577                         const AliHLTMUONRecHitsBlockStruct& block,
578                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
579                 );
580         
581         static bool HeaderOk(
582                         const AliHLTMUONClustersBlockStruct& block,
583                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
584                 );
585         
586         static bool HeaderOk(
587                         const AliHLTMUONChannelsBlockStruct& block,
588                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
589                 );
590         
591         static bool HeaderOk(
592                         const AliHLTMUONMansoTracksBlockStruct& block,
593                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
594                 );
595         
596         static bool HeaderOk(
597                         const AliHLTMUONMansoCandidatesBlockStruct& block,
598                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
599                 );
600         
601         static bool HeaderOk(
602                         const AliHLTMUONSinglesDecisionBlockStruct& block,
603                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
604                 );
605         
606         static bool HeaderOk(
607                         const AliHLTMUONPairsDecisionBlockStruct& block,
608                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
609                 );
610         
611         /**
612          * This method is used to check more extensively if the integrity of the
613          * trigger record structure is OK and returns true in that case.
614          * [in] \param tr  The trigger record structure to check.
615          * [out] \param reason  If this is not NULL, then it will be filled with
616          *      the reason code describing why the structure is not valid, if and
617          *      only if a problem is found with the data.
618          * \returns  true if there is no problem with the structure and false otherwise.
619          */
620         static bool IntegrityOk(
621                         const AliHLTMUONTriggerRecordStruct& tr,
622                         WhyNotValid* reason = NULL
623                 )
624         {
625                 AliHLTUInt32_t count = 1;
626                 return IntegrityOk(tr, reason, count);
627         }
628         
629         /**
630          * This method is used to check more extensively if the integrity of the
631          * dHLT raw internal data block is OK and returns true in that case.
632          * [in] \param block  The trigger record data block to check.
633          * [out] \param reason  If this is not NULL, then it will be filled with
634          *      the reason code describing why the data block is not valid, if and
635          *      only if a problem is found with the data.
636          * [out] \param recordNum  If this is not NULL, then it will be filled with
637          *      the number of the trigger record that had a problem. This value will
638          *      only contain a valid value if the method RecordNumberWasSet(*reason)
639          *      returns true. Thus, 'reason' must be set.
640          * \returns  true if there is no problem with the data and false otherwise.
641          */
642         static bool IntegrityOk(
643                         const AliHLTMUONTriggerRecordsBlockStruct& block,
644                         WhyNotValid* reason = NULL, AliHLTUInt32_t* recordNum = NULL
645                 )
646         {
647                 AliHLTUInt32_t count = 1;
648                 return IntegrityOk(block, reason, recordNum, count);
649         }
650         
651         /**
652          * This method is used to check more extensively if the integrity of the
653          * trigger record debug information structure is OK and returns true in that case.
654          * [in] \param trigInfo  The trigger record debug information structure to check.
655          * [out] \param reason  If this is not NULL, then it will be filled with
656          *      the reason code describing why the structure is not valid, if and
657          *      only if a problem is found with the data.
658          * \returns  true if there is no problem with the structure and false otherwise.
659          */
660         static bool IntegrityOk(
661                         const AliHLTMUONTrigRecInfoStruct& trigInfo,
662                         WhyNotValid* reason = NULL
663                 )
664         {
665                 AliHLTUInt32_t count = 1;
666                 return IntegrityOk(trigInfo, reason, count);
667         }
668         
669         /**
670          * This method is used to check more extensively if the integrity of the
671          * dHLT raw internal data block is OK and returns true in that case.
672          * [in] \param block  The trigger record debugging information data block to check.
673          * [out] \param reason  If this is not NULL, then it will be filled with
674          *      the reason code describing why the data block is not valid, if and
675          *      only if a problem is found with the data.
676          * [out] \param recordNum  If this is not NULL, then it will be filled with
677          *      the number of the trigger record debug information structure that had
678          *      a problem. This value will only contain a valid value if the method
679          *      RecordNumberWasSet(*reason) returns true. Thus, 'reason' must be set.
680          * \returns  true if there is no problem with the data and false otherwise.
681          */
682         static bool IntegrityOk(
683                         const AliHLTMUONTrigRecsDebugBlockStruct& block,
684                         WhyNotValid* reason = NULL, AliHLTUInt32_t* recordNum = NULL
685                 )
686         {
687                 AliHLTUInt32_t count = 1;
688                 return IntegrityOk(block, reason, recordNum, count);
689         }
690         
691         /**
692          * This method is used to check more extensively if the integrity of the
693          * reconstructed hit structure is OK and returns true in that case.
694          * [in] \param hit  The reconstructed hit structure to check.
695          * [out] \param reason  If this is not NULL, then it will be filled with
696          *      the reason code describing why the structure is not valid, if and
697          *      only if a problem is found with the data.
698          * \returns  true if there is no problem with the data and false otherwise.
699          */
700         static bool IntegrityOk(
701                         const AliHLTMUONRecHitStruct& hit,
702                         WhyNotValid* reason = NULL
703                 )
704         {
705                 AliHLTUInt32_t count = 1;
706                 return IntegrityOk(hit, reason, count);
707         }
708         
709         /**
710          * This method is used to check more extensively if the integrity of the
711          * dHLT raw internal data block is OK and returns true in that case.
712          * [in] \param block  The reconstructed hits data block to check.
713          * [out] \param reason  If this is not NULL, then it will be filled with
714          *      the reason code describing why the data block is not valid, if and
715          *      only if a problem is found with the data.
716          * [out] \param recordNum  If this is not NULL, then it will be filled with
717          *      the number of the cluster structure that had a problem. This value
718          *      will only contain a valid value if the method
719          *      RecordNumberWasSet(*reason) returns true. Thus, 'reason' must be set.
720          * \returns  true if there is no problem with the data and false otherwise.
721          */
722         static bool IntegrityOk(
723                         const AliHLTMUONRecHitsBlockStruct& block,
724                         WhyNotValid* reason = NULL, AliHLTUInt32_t* recordNum = NULL
725                 )
726         {
727                 AliHLTUInt32_t count = 1;
728                 return IntegrityOk(block, reason, recordNum, count);
729         }
730         
731         /**
732          * This method is used to check more extensively if the integrity of the
733          * cluster data structure is OK and returns true in that case.
734          * [in] \param cluster  The cluster structure to check.
735          * [out] \param reason  If this is not NULL, then it will be filled with
736          *      the reason code describing why the structure is not valid, if and
737          *      only if a problem is found with the data.
738          * \returns  true if there is no problem with the data and false otherwise.
739          */
740         static bool IntegrityOk(
741                         const AliHLTMUONClusterStruct& cluster,
742                         WhyNotValid* reason = NULL
743                 )
744         {
745                 AliHLTUInt32_t count = 1;
746                 return IntegrityOk(cluster, reason, count);
747         }
748         
749         /**
750          * This method is used to check more extensively if the integrity of the
751          * dHLT raw internal data block is OK and returns true in that case.
752          * [in] \param block  The clusters data block to check.
753          * [out] \param reason  If this is not NULL, then it will be filled with
754          *      the reason code describing why the data block is not valid, if and
755          *      only if a problem is found with the data.
756          * [out] \param recordNum  If this is not NULL, then it will be filled with
757          *      the number of the cluster structure that had a problem. This value
758          *      will only contain a valid value if the method
759          *      RecordNumberWasSet(*reason) returns true. Thus, 'reason' must be set.
760          * \returns  true if there is no problem with the data and false otherwise.
761          */
762         static bool IntegrityOk(
763                         const AliHLTMUONClustersBlockStruct& block,
764                         WhyNotValid* reason = NULL, AliHLTUInt32_t* recordNum = NULL
765                 )
766         {
767                 AliHLTUInt32_t count = 1;
768                 return IntegrityOk(block, reason, recordNum, count);
769         }
770         
771         /**
772          * This method is used to check more extensively if the integrity of the
773          * channel data structure is OK and returns true in that case.
774          * [in] \param cluster  The channel structure to check.
775          * [out] \param reason  If this is not NULL, then it will be filled with
776          *      the reason code describing why the structure is not valid, if and
777          *      only if a problem is found with the data.
778          * \returns  true if there is no problem with the data and false otherwise.
779          */
780         static bool IntegrityOk(
781                         const AliHLTMUONChannelStruct& channel,
782                         WhyNotValid* reason = NULL
783                 )
784         {
785                 AliHLTUInt32_t count = 1;
786                 return IntegrityOk(channel, reason, count);
787         }
788         
789         /**
790          * This method is used to check more extensively if the integrity of the
791          * dHLT raw internal data block is OK and returns true in that case.
792          * [in] \param block  The ADC channels data block to check.
793          * [out] \param reason  If this is not NULL, then it will be filled with
794          *      the reason code describing why the data block is not valid, if and
795          *      only if a problem is found with the data.
796          * [out] \param recordNum  If this is not NULL, then it will be filled with
797          *      the number of the channel structure that had a problem. This value
798          *      will only contain a valid value if the method
799          *      RecordNumberWasSet(*reason) returns true. Thus, 'reason' must be set.
800          * \returns  true if there is no problem with the data and false otherwise.
801          */
802         static bool IntegrityOk(
803                         const AliHLTMUONChannelsBlockStruct& block,
804                         WhyNotValid* reason = NULL, AliHLTUInt32_t* recordNum = NULL
805                 )
806         {
807                 AliHLTUInt32_t count = 1;
808                 return IntegrityOk(block, reason, recordNum, count);
809         }
810         
811         /**
812          * This method is used to check more extensively if the integrity of the
813          * Manso track structure is OK and returns true in that case.
814          * [in] \param track  The Manso track structure to check.
815          * [out] \param reason  If this is not NULL, then it will be filled with
816          *      the reason code describing why the structure is not valid, if and
817          *      only if a problem is found with the data.
818          * \returns  true if there is no problem with the structure and false otherwise.
819          */
820         static bool IntegrityOk(
821                         const AliHLTMUONMansoTrackStruct& track,
822                         WhyNotValid* reason = NULL
823                 )
824         {
825                 AliHLTUInt32_t count = 1;
826                 return IntegrityOk(track, reason, count);
827         }
828         
829         /**
830          * This method is used to check more extensively if the integrity of the
831          * dHLT raw internal data block is OK and returns true in that case.
832          * [in] \param block  The Manso track data block to check.
833          * [out] \param reason  If this is not NULL, then it will be filled with
834          *      the reason code describing why the data block is not valid, if and
835          *      only if a problem is found with the data.
836          * [out] \param recordNum  If this is not NULL, then it will be filled with
837          *      the number of the Manso track structure that had a problem.
838          *      This value will only contain a valid value if the method
839          *      RecordNumberWasSet(*reason) returns true. Thus, 'reason' must be set.
840          * \returns  true if there is no problem with the data and false otherwise.
841          */
842         static bool IntegrityOk(
843                         const AliHLTMUONMansoTracksBlockStruct& block,
844                         WhyNotValid* reason = NULL, AliHLTUInt32_t* recordNum = NULL
845                 )
846         {
847                 AliHLTUInt32_t count = 1;
848                 return IntegrityOk(block, reason, recordNum, count);
849         }
850         
851         /**
852          * This method is used to check more extensively if the integrity of the
853          * Manso track candidate structure is OK and returns true in that case.
854          * [in] \param candidate  The Manso track candidate structure to check.
855          * [out] \param reason  If this is not NULL, then it will be filled with
856          *      the reason code describing why the structure is not valid, if and
857          *      only if a problem is found with the data.
858          * \returns  true if there is no problem with the structure and false otherwise.
859          */
860         static bool IntegrityOk(
861                         const AliHLTMUONMansoCandidateStruct& candidate,
862                         WhyNotValid* reason = NULL
863                 )
864         {
865                 AliHLTUInt32_t count = 1;
866                 return IntegrityOk(candidate, reason, count);
867         }
868         
869         /**
870          * This method is used to check more extensively if the integrity of the
871          * dHLT raw internal data block is OK and returns true in that case.
872          * [in] \param block  The Manso track candidate data block to check.
873          * [out] \param reason  If this is not NULL, then it will be filled with
874          *      the reason code describing why the data block is not valid, if and
875          *      only if a problem is found with the data.
876          * [out] \param recordNum  If this is not NULL, then it will be filled with
877          *      the number of the Manso track candidate structure that had a problem.
878          *      This value will only contain a valid value if the method
879          *      RecordNumberWasSet(*reason) returns true. Thus, 'reason' must be set.
880          * \returns  true if there is no problem with the data and false otherwise.
881          */
882         static bool IntegrityOk(
883                         const AliHLTMUONMansoCandidatesBlockStruct& block,
884                         WhyNotValid* reason = NULL, AliHLTUInt32_t* recordNum = NULL
885                 )
886         {
887                 AliHLTUInt32_t count = 1;
888                 return IntegrityOk(block, reason, recordNum, count);
889         }
890         
891         /**
892          * This method is used to check more extensively if the integrity of the
893          * single track trigger decision structure is OK and returns true in that case.
894          * [in] \param decision  The trigger decision structure to check.
895          * [out] \param reason  If this is not NULL, then it will be filled with
896          *      the reason code describing why the structure is not valid, if and
897          *      only if a problem is found with the data.
898          * \returns  true if there is no problem with the structure and false otherwise.
899          */
900         static bool IntegrityOk(
901                         const AliHLTMUONTrackDecisionStruct& decision,
902                         WhyNotValid* reason = NULL
903                 )
904         {
905                 AliHLTUInt32_t count = 1;
906                 return IntegrityOk(decision, reason, count);
907         }
908         
909         /**
910          * This method is used to check more extensively if the integrity of the
911          * dHLT raw internal data block is OK and returns true in that case.
912          * [in] \param block  The single track trigger decision data block to check.
913          * [out] \param reason  If this is not NULL, then it will be filled with
914          *      the reason code describing why the data block is not valid, if and
915          *      only if a problem is found with the data.
916          * [out] \param recordNum  If this is not NULL, then it will be filled with
917          *      the number of the single track trigger decision structure that had
918          *      a problem. This value will only contain a valid value if the method
919          *      RecordNumberWasSet(*reason) returns true. Thus, 'reason' must be set.
920          * \returns  true if there is no problem with the data and false otherwise.
921          */
922         static bool IntegrityOk(
923                         const AliHLTMUONSinglesDecisionBlockStruct& block,
924                         WhyNotValid* reason = NULL, AliHLTUInt32_t* recordNum = NULL
925                 )
926         {
927                 AliHLTUInt32_t count = 1;
928                 return IntegrityOk(block, reason, recordNum, count);
929         }
930         
931         /**
932          * This method is used to check more extensively if the integrity of the
933          * track pair trigger decision structure is OK and returns true in that case.
934          * [in] \param decision  The trigger decision structure to check.
935          * [out] \param reason  If this is not NULL, then it will be filled with
936          *      the reason code describing why the structure is not valid, if and
937          *      only if a problem is found with the data.
938          * \returns  true if there is no problem with the structure and false otherwise.
939          */
940         static bool IntegrityOk(
941                         const AliHLTMUONPairDecisionStruct& decision,
942                         WhyNotValid* reason = NULL
943                 )
944         {
945                 AliHLTUInt32_t count = 1;
946                 return IntegrityOk(decision, reason, count);
947         }
948         
949         /**
950          * This method is used to check more extensively if the integrity of the
951          * dHLT raw internal data block is OK and returns true in that case.
952          * [in] \param block  The track pair trigger decision data block to check.
953          * [out] \param reason  If this is not NULL, then it will be filled with
954          *      the reason code describing why the data block is not valid, if and
955          *      only if a problem is found with the data.
956          * [out] \param recordNum  If this is not NULL, then it will be filled with
957          *      the number of the track pairs trigger decision structure that had
958          *      a problem. This value will only contain a valid value if the method
959          *      RecordNumberWasSet(*reason) returns true. Thus, 'reason' must be set.
960          * \returns  true if there is no problem with the data and false otherwise.
961          */
962         static bool IntegrityOk(
963                         const AliHLTMUONPairsDecisionBlockStruct& block,
964                         WhyNotValid* reason = NULL, AliHLTUInt32_t* recordNum = NULL
965                 )
966         {
967                 AliHLTUInt32_t count = 1;
968                 return IntegrityOk(block, reason, recordNum, count);
969         }
970
971         /**
972          * Methods used to check more extensively if the integrity of various
973          * types of data blocks are Ok and returns true in that case.
974          * These can be slow and should generally only be used for debugging.
975          * The methods are able to return multiple reasons for the problems related
976          * to the data block under test.
977          */
978         static bool IntegrityOk(
979                         const AliHLTMUONTriggerRecordStruct& tr,
980                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
981                 );
982         
983         static bool IntegrityOk(
984                         const AliHLTMUONTriggerRecordsBlockStruct& block,
985                         WhyNotValid* reason, AliHLTUInt32_t* recordNum,
986                         AliHLTUInt32_t& reasonCount
987                 );
988         
989         static bool IntegrityOk(
990                         const AliHLTMUONTrigRecInfoStruct& trigInfo,
991                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
992                 );
993         
994         static bool IntegrityOk(
995                         const AliHLTMUONTrigRecsDebugBlockStruct& block,
996                         WhyNotValid* reason, AliHLTUInt32_t* recordNum,
997                         AliHLTUInt32_t& reasonCount
998                 );
999         
1000         static bool IntegrityOk(
1001                         const AliHLTMUONRecHitStruct& hit,
1002                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
1003                 );
1004         
1005         static bool IntegrityOk(
1006                         const AliHLTMUONRecHitsBlockStruct& block,
1007                         WhyNotValid* reason, AliHLTUInt32_t* recordNum,
1008                         AliHLTUInt32_t& reasonCount
1009                 );
1010         
1011         static bool IntegrityOk(
1012                         const AliHLTMUONClusterStruct& cluster,
1013                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
1014                 );
1015         
1016         static bool IntegrityOk(
1017                         const AliHLTMUONClustersBlockStruct& block,
1018                         WhyNotValid* reason, AliHLTUInt32_t* recordNum,
1019                         AliHLTUInt32_t& reasonCount
1020                 );
1021         
1022         static bool IntegrityOk(
1023                         const AliHLTMUONChannelStruct& channel,
1024                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
1025                 );
1026         
1027         static bool IntegrityOk(
1028                         const AliHLTMUONChannelsBlockStruct& block,
1029                         WhyNotValid* reason, AliHLTUInt32_t* recordNum,
1030                         AliHLTUInt32_t& reasonCount
1031                 );
1032         
1033         static bool IntegrityOk(
1034                         const AliHLTMUONMansoTrackStruct& track,
1035                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
1036                 );
1037         
1038         static bool IntegrityOk(
1039                         const AliHLTMUONMansoTracksBlockStruct& block,
1040                         WhyNotValid* reason, AliHLTUInt32_t* recordNum,
1041                         AliHLTUInt32_t& reasonCount
1042                 );
1043         
1044         static bool IntegrityOk(
1045                         const AliHLTMUONMansoCandidateStruct& candidate,
1046                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
1047                 );
1048         
1049         static bool IntegrityOk(
1050                         const AliHLTMUONMansoCandidatesBlockStruct& block,
1051                         WhyNotValid* reason, AliHLTUInt32_t* recordNum,
1052                         AliHLTUInt32_t& reasonCount
1053                 );
1054         
1055         static bool IntegrityOk(
1056                         const AliHLTMUONTrackDecisionStruct& decision,
1057                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
1058                 );
1059         
1060         static bool IntegrityOk(
1061                         const AliHLTMUONSinglesDecisionBlockStruct& block,
1062                         WhyNotValid* reason, AliHLTUInt32_t* recordNum,
1063                         AliHLTUInt32_t& reasonCount
1064                 );
1065         
1066         static bool IntegrityOk(
1067                         const AliHLTMUONPairDecisionStruct& decision,
1068                         WhyNotValid* reason, AliHLTUInt32_t& reasonCount
1069                 );
1070         
1071         static bool IntegrityOk(
1072                         const AliHLTMUONPairsDecisionBlockStruct& block,
1073                         WhyNotValid* reason, AliHLTUInt32_t* recordNum,
1074                         AliHLTUInt32_t& reasonCount
1075                 );
1076         
1077         /**
1078          * Returns true if the \em recordNum in the corresponding IntegrityOk method
1079          * would have been set, if it returned false and a reason was set.
1080          * This helper method makes it easy to test if the \em recordNum parameter
1081          * is filled with a valid value or not.
1082          */
1083         static bool RecordNumberWasSet(WhyNotValid reason);
1084
1085 private:
1086         // Should never have to create, copy or destroy this object.
1087         AliHLTMUONUtils();
1088         AliHLTMUONUtils(const AliHLTMUONUtils& obj);
1089         virtual ~AliHLTMUONUtils();
1090         AliHLTMUONUtils& operator = (const AliHLTMUONUtils& obj);
1091         
1092         ClassDef(AliHLTMUONUtils, 0);  // Interface for helpful dHLT utility methods.
1093 };
1094
1095 //_____________________________________________________________________________
1096
1097 inline std::ostream& operator << (std::ostream& stream, AliHLTMUONUtils::WhyNotValid reason)
1098 {
1099         /// Stream operator for the WhyNotValid enumeration for usage with
1100         /// std::ostream classes. Allows usages such as:
1101         /// AliHLTMUONUtils::WhyNotValid r; std::cout << r;
1102         
1103         stream << AliHLTMUONUtils::FailureReasonToString(reason);
1104         return stream;
1105 }
1106
1107 //_____________________________________________________________________________
1108
1109 // Since c++ is missing a finally "keyword" we define one. Its usage is identical
1110 // to a try..finally statement in Java etc.. however, since it is officialy a macro
1111 // one must use the ( ) brackets instead of { }
1112 // If the compiler supports __finally use it otherwise make our own.
1113 #if defined(__BORLANDC__)
1114 #       define finally(str) __finally{str}
1115 #else
1116 #       define finally(code) \
1117                 catch(...) \
1118                 { \
1119                         code \
1120                         throw; \
1121                 }; \
1122                 code
1123 #endif // __BORLANDC__
1124
1125 // Here we define the DebugTrace(message) macro for easy embedding of debug
1126 // information into the dimuon HLT code. Its usage is meant to be for generating
1127 // traces of the program which are only useful during full scale debugging.
1128 // Log messages should use the standard HLT logging mechanisms.
1129 // The output is only generated in programs compiled with the DEBUG directive
1130 // defined. Here is a usage example:
1131 //
1132 //  // statements...
1133 //  DebugTrace("some debug information.");
1134 //  // statements...
1135 //
1136 // One can also use C++ ostream operators and manipulators like so:
1137 //
1138 //  // statements...
1139 //  int x, y;
1140 //  DebugTrace("x = " << x << " and y = 0x" << std::hex << y );
1141 //  // statements...
1142 //
1143 #ifdef DEBUG
1144 #       include <iostream>
1145 #       define DebugTrace(message) {std::cout << message << std::endl;}
1146 #else // DEBUG
1147 #       define DebugTrace(message)
1148 #endif // DEBUG
1149
1150
1151 #endif // ALIHLTMUONUTILS_H