]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/AliHLTMUONProcessor.h
Added:
[u/mrichter/AliRoot.git] / HLT / MUON / AliHLTMUONProcessor.h
1 #ifndef ALIHLTMUONPROCESSOR_H
2 #define ALIHLTMUONPROCESSOR_H
3 /* This file is property of and copyright by the ALICE HLT Project        *
4  * ALICE Experiment at CERN, All rights reserved.                         *
5  * See cxx source for full Copyright notice                               */
6
7 /* $Id: $ */
8
9 ///
10 /// @file   AliHLTMUONProcessor.h
11 /// @author Artur Szostak <artursz@iafrica.com>
12 /// @date   19 May 2008
13 /// @brief  Declaration of a common processor component abstract interface for dHLT components.
14 ///
15
16 #include "AliHLTProcessor.h"
17 #include "AliHLTMUONDataBlockReader.h"
18 #include "AliHLTMUONUtils.h"
19
20 /**
21  * @class AliHLTMUONProcessor
22  * This component class is an abstract base class for dHLT components.
23  * Some common methods useful to all dHLT specific components are implemented
24  * by this class.
25  *
26  * @ingroup alihlt_dimuon_component
27  */
28 class AliHLTMUONProcessor : public AliHLTProcessor
29 {
30 public:
31         /// Default constructor.
32         AliHLTMUONProcessor() : AliHLTProcessor() {}
33         
34         /// Default destructor.
35         virtual ~AliHLTMUONProcessor() {}
36
37 protected:
38
39         /**
40          * Method to check the block structure and log appropriate error messages.
41          * If a problem is found with the data block then an appropriate HLT error
42          * message is logged and the method returns false.
43          * \param block  The lightweight block reader whose data block should be checked.
44          * \param name  A string containing a descriptive name of the data block
45          *          type. This name is used in the logged error messages.
46          * \param checkHeader  Indicates if the common data block header should be checked.
47          * \returns  true if the structure of the block looks OK and false otherwise.
48          * \note  The BlockType should be a class deriving from AliHLTMUONDataBlockReader.
49          */
50         template <class BlockType>
51         bool BlockStructureOk(
52                         const BlockType& block, const char* name,
53                         bool checkHeader = true
54                 ) const;
55         
56         /// Checks the structure of a trigger records data block.
57         bool BlockStructureOk(
58                         const AliHLTMUONTriggerRecordsBlockReader& block,
59                         bool checkHeader = true
60                 ) const
61         {
62                 return BlockStructureOk(block, "trigger records", checkHeader);
63         }
64         
65         /// Checks the structure of a trigger records debug information data block.
66         bool BlockStructureOk(
67                         const AliHLTMUONTrigRecsDebugBlockReader& block,
68                         bool checkHeader = true
69                 ) const
70         {
71                 return BlockStructureOk(block, "trigger records debug information", checkHeader);
72         }
73
74         /// Checks the structure of a reconstructed hits data block.
75         bool BlockStructureOk(
76                         const AliHLTMUONRecHitsBlockReader& block,
77                         bool checkHeader = true
78                 ) const
79         {
80                 return BlockStructureOk(block, "reconstructed hits", checkHeader);
81         }
82         
83         /// Checks the structure of a clusters data block.
84         bool BlockStructureOk(
85                         const AliHLTMUONClustersBlockReader& block,
86                         bool checkHeader = true
87                 ) const
88         {
89                 return BlockStructureOk(block, "clusters", checkHeader);
90         }
91         
92         /// Checks the structure of a ADC channels data block.
93         bool BlockStructureOk(
94                         const AliHLTMUONChannelsBlockReader& block,
95                         bool checkHeader = true
96                 ) const
97         {
98                 return BlockStructureOk(block, "channels", checkHeader);
99         }
100
101         /// Checks the structure of a Manso tracks data block.
102         bool BlockStructureOk(
103                         const AliHLTMUONMansoTracksBlockReader& block,
104                         bool checkHeader = true
105                 ) const
106         {
107                 return BlockStructureOk(block, "Manso tracks", checkHeader);
108         }
109         
110         /// Checks the structure of a Manso track candidates data block.
111         bool BlockStructureOk(
112                         const AliHLTMUONMansoCandidatesBlockReader& block,
113                         bool checkHeader = true
114                 ) const
115         {
116                 return BlockStructureOk(block, "Manso track candidates", checkHeader);
117         }
118
119         /// Checks the structure of a single track trigger decision data block.
120         bool BlockStructureOk(
121                         const AliHLTMUONSinglesDecisionBlockReader& block,
122                         bool checkHeader = true
123                 ) const
124         {
125                 return BlockStructureOk(block, "singles decision", checkHeader);
126         }
127
128         /// Checks the structure of a track pairs trigger decision data block.
129         bool BlockStructureOk(
130                         const AliHLTMUONPairsDecisionBlockReader& block,
131                         bool checkHeader = true
132                 ) const
133         {
134                 return BlockStructureOk(block, "pairs decision", checkHeader);
135         }
136         
137         /**
138          * Fetches the DDL and detector element store objects for MUON mapping.
139          * \param cdbPath  The CDB path to use. If set to NULL and the path has
140          *      not been set in the CDB manager then the default path
141          *      "local://$ALICE_ROOT" is used if the 'useDefault' flag is also true.
142          * \param run  The run number to use. If set to -1 and the run number has
143          *      not been set in the CDB manager then a value of zero is used if
144          *      the 'useDefault' flag is also true.
145          * \param useDefault  If set to true then a default CDB path and run number
146          *      is used if they have not been set and 'cdbPath' == NULL or
147          *      'run' == NULL.
148          * \return Zero if the object could be loaded. Otherwise an error code is
149          *      returned, which is compatible with the HLT framework.
150          * \note AliMpDDLStore::Instance() and AliMpDEStore::Instance() must be used
151          *      to fetch the objects after this method returns a code equal to zero.
152          */
153         int FetchMappingStores(
154                         const char* cdbPath = NULL, Int_t run = -1,
155                         bool useDefault = true
156                 ) const;
157         
158 private:
159
160         // Do not allow copying of this class.
161         /// Not implemented.
162         AliHLTMUONProcessor(const AliHLTMUONProcessor& /*obj*/);
163         /// Not implemented.
164         AliHLTMUONProcessor& operator = (const AliHLTMUONProcessor& /*obj*/);
165         
166         ClassDef(AliHLTMUONProcessor, 0)  // Abstract base class for dHLT specific components.
167 };
168
169 //______________________________________________________________________________
170
171 template <class BlockType>
172 bool AliHLTMUONProcessor::BlockStructureOk(
173                 const BlockType& block, const char* name, bool checkHeader
174         ) const
175 {
176         /// Performs basic checks to see if the input data block structure is OK,
177         /// that it is not corrupt, too short etc...
178         
179         if (not block.BufferSizeOk())
180         {
181                 size_t headerSize = sizeof(typename BlockType::HeaderType);
182                 if (block.BufferSize() < headerSize)
183                 {
184                         HLTError("Received a %s data block with a size of %d bytes,"
185                                 " which is smaller than the minimum valid header size of %d bytes."
186                                 " The block must be corrupt.",
187                                 name, block.BufferSize(), headerSize
188                         );
189                         return false;
190                 }
191                 
192                 size_t expectedWidth = sizeof(typename BlockType::ElementType);
193                 if (block.CommonBlockHeader().fRecordWidth != expectedWidth)
194                 {
195                         HLTError("Received a %s data block with a record"
196                                 " width of %d bytes, but the expected value is %d bytes."
197                                 " The block might be corrupt.",
198                                 name,
199                                 block.CommonBlockHeader().fRecordWidth,
200                                 expectedWidth
201                         );
202                         return false;
203                 }
204                 
205                 HLTError("Received a %s data block with a size of %d bytes,"
206                         " but the block header claims the block should be %d bytes."
207                         " The block might be corrupt.",
208                         name, block.BufferSize(), block.BytesUsed()
209                 );
210                 return false;
211         }
212         
213         if (checkHeader)
214         {
215                 AliHLTMUONUtils::WhyNotValid reason;
216                 if (not AliHLTMUONUtils::HeaderOk(block.BlockHeader(), &reason))
217                 {
218                         HLTError("Received a %s data block which might be corrupt. %s",
219                                 name, AliHLTMUONUtils::FailureReasonToMessage(reason)
220                         );
221                         return false;
222                 }
223         }
224         
225         return true;
226 }
227
228 #endif // ALIHLTMUONPROCESSOR_H