]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/AliHLTMUONUtils.h
Adding internal HLT data blocks for debugging information from the trigger chambers.
[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   
12  * @brief  Class containing various dimuon HLT utility routines and macros.
13  */
14
15 #include "AliHLTMUONDataTypes.h"
16
17 // Forward declare structures.
18 extern "C" {
19 struct AliHLTMUONTriggerRecordsBlockStruct;
20 struct AliHLTMUONTrigRecsDebugBlockStruct;
21 struct AliHLTMUONTriggerChannelsBlockStruct;
22 struct AliHLTMUONRecHitsBlockStruct;
23 struct AliHLTMUONClustersBlockStruct;
24 struct AliHLTMUONChannelsBlockStruct;
25 } // extern "C"
26
27 /**
28  * AliHLTMUONUtils contains arbitrary utility methods to be used in various
29  * parts of the dimuon HLT system.
30  * These include methods to perform basic sanity checks on the integrity of
31  * data blocks.
32  */
33 class AliHLTMUONUtils
34 {
35 public:
36         /**
37          * This packs the given parameters into the bits of a word appropriate
38          * for AliHLTMUONTriggerRecordStruct::fFlags.
39          * @param sign    The particle sign.
40          * @param hitset  Flags to indicate if the corresponding fHits[i] elements
41          *                was set/filled.
42          * @return  Returns the 32 bit packed word.
43          */
44         static AliHLTUInt32_t PackTriggerRecordFlags(
45                         AliHLTMUONParticleSign sign, bool hitset[4]
46                 );
47
48         /**
49          * This unpacks the AliHLTMUONTriggerRecordStruct::fFlags bits into
50          * its component fields.
51          * @param flags  The flags from an AliHLTMUONTriggerRecordStruct structure.
52          * @param sign    Sets this to the particle sign.
53          * @param hitset  Sets the array elements to indicate if the corresponding
54          *                fHits[i] element was set/filled.
55          */
56         static void UnpackTriggerRecordFlags(
57                         AliHLTUInt32_t flags, // [in]
58                         AliHLTMUONParticleSign& sign, // [out]
59                         bool hitset[4] // [out]
60                 );
61
62         /**
63          * This packs the given parameters into the bits of a word appropriate
64          * for AliHLTMUONMansoTrackStruct::fFlags.
65          * @param sign    The particle sign.
66          * @param hitset  Flags to indicate if the corresponding fHits[i] elements
67          *                was set/filled.
68          * @return  Returns the 32 bit packed word.
69          */
70         static AliHLTUInt32_t PackMansoTrackFlags(
71                         AliHLTMUONParticleSign sign, bool hitset[4]
72                 )
73         {
74                 return PackTriggerRecordFlags(sign, hitset);
75         }
76
77         /**
78          * This unpacks the AliHLTMUONMansoTrackStruct::fFlags bits into
79          * its component fields.
80          * @param flags  The flags from an AliHLTMUONMansoTrackStruct structure.
81          * @param sign    Sets this to the particle sign.
82          * @param hitset  Sets the array elements to indicate if the corresponding
83          *                fHits[i] element was set/filled.
84          */
85         static void UnpackMansoTrackFlags(
86                         AliHLTUInt32_t flags, // [in]
87                         AliHLTMUONParticleSign& sign, // [out]
88                         bool hitset[4] // [out]
89                 )
90         {
91                 UnpackTriggerRecordFlags(flags, sign, hitset);
92         }
93
94         /**
95          * Methods used to check if the header information corresponds to the
96          * supposed type of the data block.
97          */
98         static bool HeaderOk(const AliHLTMUONTriggerRecordsBlockStruct& block);
99         static bool HeaderOk(const AliHLTMUONTrigRecsDebugBlockStruct& block);
100         static bool HeaderOk(const AliHLTMUONTriggerChannelsBlockStruct& block);
101         static bool HeaderOk(const AliHLTMUONRecHitsBlockStruct& block);
102         static bool HeaderOk(const AliHLTMUONClustersBlockStruct& block);
103         static bool HeaderOk(const AliHLTMUONChannelsBlockStruct& block);
104
105         /**
106          * Methods used to check extensively if the integrity of various types
107          * of data blocks are Ok and returns true in that case.
108          * These can be slow and should generally only be used for debugging.
109          */
110         static bool IntegrityOk(const AliHLTMUONTriggerRecordsBlockStruct& block);
111         static bool IntegrityOk(const AliHLTMUONTrigRecsDebugBlockStruct& block);
112         static bool IntegrityOk(const AliHLTMUONTriggerChannelsBlockStruct& block);
113         static bool IntegrityOk(const AliHLTMUONRecHitsBlockStruct& block);
114         static bool IntegrityOk(const AliHLTMUONClustersBlockStruct& block);
115         static bool IntegrityOk(const AliHLTMUONChannelsBlockStruct& block);
116
117 private:
118         // Should never have to create or destroy this object.
119         AliHLTMUONUtils();
120         ~AliHLTMUONUtils();
121 };
122
123 //_____________________________________________________________________________
124
125 // Since c++ is missing a finally "keyword" we define one. Its usage is identical
126 // to a try..finally statement in Java etc.. however, since it is officialy a macro
127 // one must use the ( ) brackets instead of { }
128 // If the compiler supports __finally use it otherwise make our own.
129 #if defined(__BORLANDC__)
130 #       define finally(str) __finally{str}
131 #else
132 #       define finally(code) \
133                 catch(...) \
134                 { \
135                         code \
136                         throw; \
137                 }; \
138                 code
139 #endif // __BORLANDC__
140
141 // If we do not already have them, then define logical operators that are easier
142 // to read. 'and' = &&, 'or' = ||, 'not' = !
143 #if ! defined(__GNUC__) && ! defined(__CINT__)
144 #       define and &&
145 #       define or ||
146 #       define not !
147 #endif // __GNUC__ | __CINT__
148
149
150 // Here we define the DebugTrace(message) macro for easy embedding of debug
151 // information into the dimuon HLT code. Its usage is meant to be for generating
152 // traces of the program which are only useful during full scale debugging.
153 // Log messages should use the standard HLT logging mechanisms.
154 // The output is only generated in programs compiled with the DEBUG directive
155 // defined. Here is a usage example:
156 //
157 //  // statements...
158 //  DebugTrace("some debug information.");
159 //  // statements...
160 //
161 // One can also use C++ ostream operators and manipulators like so:
162 //
163 //  // statements...
164 //  int x, y;
165 //  DebugMsg("x = " << x << " and y = 0x" << std::hex << y );
166 //  // statements...
167 //
168 #ifdef DEBUG
169 #       include <ostream>
170 #       define DebugTrace(message) {std::cout << message << std::endl;}
171 #else // DEBUG
172 #       define DebugTrace(message)
173 #endif // DEBUG
174
175
176 #endif // ALIHLTMUONUTILS_H