]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/MUON/OnlineAnalysis/AliHLTMUONTriggerReconstructor.h
Update master to aliroot
[u/mrichter/AliRoot.git] / HLT / MUON / OnlineAnalysis / AliHLTMUONTriggerReconstructor.h
CommitLineData
6efe69e7 1#ifndef AliHLTMUONTRIGGERRECONSTRUCTOR_H
2#define AliHLTMUONTRIGGERRECONSTRUCTOR_H
b39b98c8 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 */
6efe69e7 6
1d8ae082 7// $Id$
6efe69e7 8
9/**********************************************************************
10 Created on : 16/05/2007
11 Purpose : This class is supposed to read the trigger DDL files and
12 give the output AliHLTMUONTriggerRecordStruct
13 Author : Indranil Das, HEP Division, SINP
14 Email : indra.das@saha.ac.in | indra.ehep@gmail.com
b39b98c8 15
16 Artur Szostak <artursz@iafrica.com>:
17 Completely reimplemented the lookup table to a simplified format.
6efe69e7 18**********************************************************************/
19
69c14678 20///
21/// @file AliHLTMUONTriggerReconstructor.h
22/// @author Indranil Das <indra.das@saha.ac.in>,
23/// Artur Szostak <artursz@iafrica.com>
24/// @date 16 May 2007
25/// @brief Declaration of the AliHLTMUONTriggerReconstructor class for processing trigger DDL data.
26///
27
227e7192 28#include "AliHLTLogging.h"
c95cf30c 29#include "AliHLTMUONDataTypes.h"
69c14678 30#include "AliMUONTriggerDDLDecoder.h"
31#include "AliMUONTriggerDDLDecoderEventHandler.h"
c95cf30c 32
a3d4b6ba 33extern "C" struct AliHLTMUONRecHitStruct;
c95cf30c 34extern "C" struct AliHLTMUONTriggerRecordStruct;
462e3880 35extern "C" struct AliHLTMUONTrigRecInfoStruct;
36extern "C" struct AliHLTMUONTriggerRecoLutRow;
960d54ad 37
6efe69e7 38
39class AliHLTMUONTriggerReconstructor : public AliHLTLogging
40{
80590aa1 41public:
42
80590aa1 43 AliHLTMUONTriggerReconstructor();
44 virtual ~AliHLTMUONTriggerReconstructor();
45
80590aa1 46 bool Run(
69c14678 47 const AliHLTUInt8_t* rawData,
80590aa1 48 AliHLTUInt32_t rawDataSize,
a5d4696f 49 bool scalarEvent,
80590aa1 50 AliHLTMUONTriggerRecordStruct* trigRecord,
a3d4b6ba 51 AliHLTUInt32_t& nofTrigRec
80590aa1 52 );
53
69c14678 54 /**
55 * Returns a pointer to the lookup table used to map between channel
56 * addresses and geometrical strip positions.
57 */
58 AliHLTMUONTriggerRecoLookupTable* LookupTableBuffer() { return fDecoder.GetHandler().LookupTableBuffer(); }
59
60 /// Returns the size of the lookup table.
61 size_t LookupTableSize() const { return fDecoder.GetHandler().LookupTableSize(); }
a5d4696f 62
63 /// Returns true if the decoder is set to enable recovery logic if
64 /// raw data errors are found.
65 bool TryRecover() const { return fDecoder.TryRecover(); };
66
67 /// Sets if the decoder should enable the error recovery logic.
68 void TryRecover(bool value);
406c5bc3 69
70 /**
71 * Sets the DDL bit according to the DDL value given.
72 * It is used to keep the trigger record IDs unique.
73 */
74 void SetDDL(AliHLTInt32_t ddl) { fDecoder.GetHandler().SetDDL(ddl); }
75
a3d4b6ba 76 /**
77 * Returns true if the output buffer was overflowed in the last call to Run.
78 */
79 bool OverflowedOutputBuffer() const { return fDecoder.GetHandler().OverflowedOutputBuffer(); }
80
81 /**
82 * Returns the flag specifying if we should suppress partial trigger records.
83 * Partial triggers do not pass the 3/4'ths coincidence requirement.
84 */
85 bool SuppressPartialTriggers() const { return fDecoder.GetHandler().SuppressPartialTriggers(); }
86
87 /**
88 * Sets the flag specifying if we should suppress partial trigger records.
89 * Partial triggers do not pass the 3/4'ths coincidence requirement.
90 */
91 void SuppressPartialTriggers(bool s) { fDecoder.GetHandler().SuppressPartialTriggers(s); }
92
93 /**
94 * Returns true if the crate ID as found in the regional header
95 * will be used for lookups in the LUT, rather than the sequencial
96 * index number of the header.
97 */
98 bool UseCrateId() const { return fDecoder.GetHandler().UseCrateId(); }
99
100 /**
101 * Sets the flag indicating if the crate ID as found in the regional
102 * header should be used for lookups in the LUT, rather than the
103 * sequencial index number of the header.
104 */
105 void UseCrateId(bool value) { fDecoder.GetHandler().UseCrateId(value); }
106
2b7af22a 107 /**
108 * Returns true if the local board ID as found in the local structure
109 * will be used for lookups in the LUT, rather than the sequencial
110 * index number of the structure.
111 */
112 bool UseLocalId() const { return fDecoder.GetHandler().UseLocalId(); }
113
114 /**
115 * Sets the flag indicating if the local board ID as found in the local
116 * structure should be used for lookups in the LUT, rather than the
117 * sequencial index number of the structure.
118 */
119 void UseLocalId(bool value) { fDecoder.GetHandler().UseLocalId(value); }
120
462e3880 121 /// Return the flag indicating if the debug information is stored during decoding.
122 bool StoreDebugInfo() const { return fDecoder.GetHandler().StoreDebugInfo(); }
123
124 /// Sets the flag indicating if the debug information should be stored.
125 void StoreDebugInfo(bool value) { fDecoder.GetHandler().StoreDebugInfo(value); }
126
127 /// Returns the number of elements in the debug information buffer.
128 AliHLTUInt32_t InfoBufferCount() const { return fDecoder.GetHandler().InfoBufferCount(); }
129
130 /// Returns the debug information buffer.
131 const AliHLTMUONTrigRecInfoStruct* InfoBuffer() const { return fDecoder.GetHandler().InfoBuffer(); }
132
133 /// Empty the info buffer.
134 void ZeroInfoBuffer() { fDecoder.GetHandler().ZeroInfoBuffer(); }
135
aae30cc5 136 /**
137 * Returns the flag indicating if the error message for a wrong event type found
138 * in the DARC header should be suppressed.
139 */
140 bool DontPrintWrongEventError() const { return fDecoder.GetHandler().DontPrintWrongEventError(); }
141
142 /**
143 * Sets the flag indicating if the error message for a wrong event type found
144 * in the DARC header should be suppressed.
145 */
146 void DontPrintWrongEventError(bool value) { fDecoder.GetHandler().DontPrintWrongEventError(value); }
147
b39b98c8 148private:
80590aa1 149
69c14678 150 class AliDecoderHandler : public AliMUONTriggerDDLDecoderEventHandler, public AliHLTLogging
151 {
152 public:
153
154 AliDecoderHandler();
155
156 /// Default destructor.
462e3880 157 virtual ~AliDecoderHandler();
69c14678 158
159 /// Returns a pointer to the lookup table.
160 AliHLTMUONTriggerRecoLookupTable* LookupTableBuffer() { return &fLookupTable; }
161
162 /// Returns the size of the lookup table.
163 size_t LookupTableSize() const { return sizeof(fLookupTable); }
164
165 /**
166 * Returns the maximum number of trigger records that can be
167 * written to the output buffer.
168 */
169 AliHLTUInt32_t MaxOutputTrigRecs() const { return fMaxOutputTrigRecs; }
170
171 /**
172 * Sets the maximum number of trigger records that can be
173 * written to the output buffer.
174 */
175 void MaxOutputTrigRecs(AliHLTUInt32_t n) { fMaxOutputTrigRecs = n; }
176
177 /**
178 * Returns the number of reconstructed trigger records actually
179 * stored in the output buffer.
180 */
181 AliHLTUInt32_t OutputTrigRecsCount() const { return fOutputTrigRecsCount; }
182
183 /**
184 * Returns the pointer to the output buffer which stores reconstructed
185 * trigger records.
186 */
187 AliHLTMUONTriggerRecordStruct* OutputTrigRecs() const { return fOutputTrigRecs; }
188
189 /**
190 * Sets the pointer to the output buffer which stores reconstructed
191 * trigger records. Also resets the number of trigger records stored.
192 */
193 void OutputTrigRecs(AliHLTMUONTriggerRecordStruct* buf)
194 {
195 fOutputTrigRecs = buf;
196 fOutputTrigRecsCount = 0;
197 fOverflowed = false;
198 }
199
200 /**
201 * Returns the flag specifying if we should suppress partial trigger records.
202 */
203 bool SuppressPartialTriggers() const { return fSuppressPartialTriggers; }
204
205 /**
206 * Sets the flag specifying if we should suppress partial trigger records.
207 */
208 void SuppressPartialTriggers(bool s) { fSuppressPartialTriggers = s; }
209
210 /**
211 * Returns true if the output buffer was overflowed.
212 */
213 bool OverflowedOutputBuffer() const { return fOverflowed; }
214
a5d4696f 215 /**
216 * Returns true if the OnError handler method will only generate warning
217 * messages and rather than error messages.
218 */
219 bool WarnOnly() const { return fWarnOnly; }
220
221 /**
222 * Sets the flag indicating if the OnError method should only generate
223 * warnings rather than error messages.
224 */
225 void WarnOnly(bool value) { fWarnOnly = value; }
69c14678 226
a3d4b6ba 227 /**
228 * Returns true if the crate ID as found in the regional header
229 * will be used for lookups in the LUT, rather than the sequencial
230 * index number of the header.
231 */
232 bool UseCrateId() const { return fUseCrateId; }
233
234 /**
235 * Sets the flag indicating if the crate ID as found in the regional
236 * header should be used for lookups in the LUT, rather than the
237 * sequencial index number of the header.
238 */
239 void UseCrateId(bool value) { fUseCrateId = value; }
240
2b7af22a 241 /**
242 * Returns true if the local board ID as found in the local structure
243 * will be used for lookups in the LUT, rather than the sequencial
244 * index number of the structure.
245 */
246 bool UseLocalId() const { return fUseLocalId; }
247
248 /**
249 * Sets the flag indicating if the local board ID as found in the local
250 * structure should be used for lookups in the LUT, rather than the
251 * sequencial index number of the structure.
252 */
253 void UseLocalId(bool value) { fUseLocalId = value; }
254
406c5bc3 255 /**
256 * Sets the DDL bit according to the DDL value given.
257 */
258 void SetDDL(AliHLTInt32_t ddl) { fDDLBit = (ddl == 20 ? 0x00 : 0x80); }
259
a3d4b6ba 260 // Methods inherited from AliMUONTriggerDDLDecoderEventHandler:
69c14678 261
a3d4b6ba 262 /// Called for each new buffer. Just remember the start location of the buffer.
263 void OnNewBuffer(const void* buffer, UInt_t /*bufferSize*/)
69c14678 264 {
a3d4b6ba 265 assert( buffer != NULL );
266 fBufferStart = buffer;
aae30cc5 267 fHadWrongEventTypeError = fHadNonWrongEventTypeError = false;
69c14678 268 }
269
a3d4b6ba 270 /**
271 * Sets the regional structure sequencial number and decodes the crate ID.
462e3880 272 * Also zero the local structure pointers.
273 * If fUseCrateId is false then we use the sequencial number instead. This
274 * might be necessary for incorrectly generated or buggy raw data.
a3d4b6ba 275 */
276 void OnNewRegionalStructV2(
277 UInt_t num,
278 const AliMUONRegionalHeaderStruct* regionalStruct,
69c14678 279 const AliMUONRegionalScalarsStruct* /*scalars*/,
280 const void* /*data*/
462e3880 281 );
69c14678 282
462e3880 283 /**
284 * Updates the local trigger structure pointers and processes the
285 * the last local trigger.
286 */
287 void OnEndOfRegionalStructV2(
288 UInt_t num,
289 const AliMUONRegionalHeaderStruct* regionalStruct,
290 const AliMUONRegionalScalarsStruct* scalars,
291 const void* data
292 );
293
294 /**
295 * Updates the local trigger structure pointers and processes the
296 * current local trigger.
297 */
a3d4b6ba 298 void OnLocalStructV2(
299 UInt_t num,
69c14678 300 const AliMUONLocalInfoStruct* localStruct,
301 const AliMUONLocalScalarsStruct* scalars
302 );
303
304 /// Logs an error message if there was a decoding problem with the DDL payload.
305 void OnError(ErrorCode code, const void* location);
462e3880 306
307 /// Return the flag indicating if the debug information is stored during decoding.
308 bool StoreDebugInfo() const { return fStoreInfo; }
309
310 /// Sets the flag indicating if the debug information should be stored.
311 void StoreDebugInfo(bool value) { fStoreInfo = value; }
312
313 /// Returns the number of elements in the debug information buffer.
314 AliHLTUInt32_t InfoBufferCount() const { return fInfoBufferCount; }
315
316 /// Returns the debug information buffer.
317 const AliHLTMUONTrigRecInfoStruct* InfoBuffer() const { return fInfoBuffer; }
318
319 /// Empty the info buffer.
320 void ZeroInfoBuffer() { fInfoBufferCount = 0; }
aae30cc5 321
322 /**
323 * Returns the flag indicating if the error message for a wrong event type found
324 * in the DARC header should be suppressed.
325 */
326 bool DontPrintWrongEventError() const { return fDontPrintWrongEventError; }
327
328 /**
329 * Sets the flag indicating if the error message for a wrong event type found
330 * in the DARC header should be suppressed.
331 */
332 void DontPrintWrongEventError(bool value) { fDontPrintWrongEventError = value; }
333
334 /// Returns true if the last decoded DDL had a wrong event type error in the DARC header.
335 bool HadWrongEventTypeError() const { return fHadWrongEventTypeError; }
336
337 /**
338 * Returns true if the last decoded DDL had a different error than just a
339 * wrong event type error in the DARC header.
340 */
341 bool HadNonWrongEventTypeError() const { return fHadNonWrongEventTypeError; }
342
69c14678 343 private:
344 // Do not allow copying of this class.
345 /// Not implemented
346 AliDecoderHandler(const AliDecoderHandler& rhs); // copy constructor
347 /// Not implemented
348 AliDecoderHandler& operator = (const AliDecoderHandler& rhs); // assignment operator
349
a3d4b6ba 350 /**
462e3880 351 * Finds the strip bits / positions on MT1 that were fired in
352 * the current local trigger structure decision.
a3d4b6ba 353 */
462e3880 354 bool FindStripsOnMT1(AliHLTInt32_t& xPos, AliHLTInt32_t& yPos);
355
356 /**
357 * Selects the correct X strip patterns to use in FindXStrips.
8984a6aa 358 * \param [out] strips Resulting array of X strip patterns to use
462e3880 359 * for chambers 11 to 14.
360 */
361 void SelectXPatterns(AliHLTUInt64_t strips[4]);
362
363 /**
364 * Selects the correct Y strip patterns to use in FindYStrips and local IDs for
365 * finding the correct row in the lookup table.
8984a6aa 366 * \param [in] xpos Array of X strip positions generated by FindXStrips.
462e3880 367 * Values are in the range [0..47].
8984a6aa 368 * \param [out] strips Resulting array of Y strip patterns to use.
369 * \param [out] locId Resulting array of local IDs to use for the lookup table.
462e3880 370 */
371 void SelectYPatterns(AliHLTInt32_t xpos[4], AliHLTUInt32_t strips[4], AliHLTUInt8_t locId[4]);
a3d4b6ba 372
373 /**
374 * Tries to find the fired X strips for chambers 11 to 14.
375 */
462e3880 376 void FindXStrips(AliHLTInt32_t startPos, AliHLTUInt64_t strips[4], AliHLTInt32_t pos[4]);
a3d4b6ba 377
378 /**
379 * Tries to find the fired Y strips for chambers 11 to 14.
380 */
462e3880 381 void FindYStrips(AliHLTInt32_t startPos, AliHLTUInt32_t strips[4], AliHLTInt32_t pos[4]);
382
383 /**
384 * Fetches the appropriate LUT row for a given X strip position.
385 */
386 const AliHLTMUONTriggerRecoLutRow& GetLutRowX(AliHLTInt32_t xPos, AliHLTUInt8_t chamber);
a3d4b6ba 387
388 /**
389 * Reconstructs a hit with global position coordinates from strip
390 * information on a given chamber.
391 */
392 void ReconstructHit(
462e3880 393 AliHLTUInt64_t xStrips, AliHLTUInt32_t yStrips,
394 AliHLTInt32_t xPos, AliHLTInt32_t yPos, AliHLTUInt8_t yLocId,
a3d4b6ba 395 AliHLTUInt8_t chamber, AliHLTMUONRecHitStruct& hit
396 );
397
462e3880 398 /**
399 * Converts the fCurrentStruct local trigger structure from the L0
400 * into a trigger record.
401 */
402 void ProcessLocalStruct();
403
69c14678 404 AliHLTMUONTriggerRecoLookupTable fLookupTable; ///< The lookup table used for mapping between channel addresses and geometrical information.
405 const void* fBufferStart; ///< Pointer to the start of the current DDL payload buffer.
406 AliHLTUInt32_t fMaxOutputTrigRecs; ///< Maximum number of reconstructed trigger records that can be stored in fOutputTrigRecs.
407 AliHLTUInt32_t fOutputTrigRecsCount; ///< The number of reconstructed trigger records actually stored in fOutputTrigRecs.
408 AliHLTMUONTriggerRecordStruct* fOutputTrigRecs; ///< Pointer to the output buffer of trigger records structures.
409 AliHLTInt32_t fTrigRecId; ///< A running counter for the trigger record ID.
406c5bc3 410 AliHLTInt32_t fDDLBit; ///< The DDL bit used to generate unique trigger record IDs.
69c14678 411 bool fSuppressPartialTriggers; ///< Flag to indicate if we should suppres partial triggers.
412 bool fOverflowed; ///< Flag to indicate if we overflowed the output buffer.
a5d4696f 413 bool fWarnOnly; ///< Flag indicating if the OnError method should generate warnings rather than error messages.
2b7af22a 414 bool fUseLocalId; ///< Flag to indicate if the local structure ID as found in the local structures should be used or not.
a3d4b6ba 415 bool fUseCrateId; ///< Flag to indicate if the crate ID as found in the regional header structures should be used or not.
416 AliHLTInt8_t fCurrentCrateId; ///< The current trigger crate ID number from the regional header.
417 UInt_t fCurrentRegional; ///< Index number of current regional structure being decoded.
462e3880 418 UInt_t fNextLocalIndex; ///< Index number of fNextStruct local structure being decoded.
419 const AliMUONLocalInfoStruct* fPrevStruct; ///< Previous local trigger structure.
420 const AliMUONLocalInfoStruct* fCurrentStruct; ///< Current local trigger structure.
421 const AliMUONLocalInfoStruct* fNextStruct; ///< Next local trigger structure.
422 bool fStoreInfo; ///< Store debug information in fInfoBuffer.
423 AliHLTUInt32_t fInfoBufferSize; ///< Number of elements storable in fInfoBuffer.
424 AliHLTUInt32_t fInfoBufferCount; ///< Number of elements stored in the fInfoBuffer.
425 AliHLTMUONTrigRecInfoStruct* fInfoBuffer; ///< Buffer for storing the debug information.
aae30cc5 426 bool fDontPrintWrongEventError; ///< Flag indicating if the error message for kWrongEventType is suppressed or not.
427 bool fHadWrongEventTypeError; ///< Flag indicating if a kWrongEventType error was found in the last decoded DDL.
428 bool fHadNonWrongEventTypeError; ///< Flag indicating if a different error than kWrongEventType was found in the last decoded DDL.
429
462e3880 430 static const AliMUONLocalInfoStruct fgkNullStruct; ///< Empty structure marker.
69c14678 431 };
432
433 /// Not implemented
80590aa1 434 AliHLTMUONTriggerReconstructor(const AliHLTMUONTriggerReconstructor& rhs); // copy constructor
69c14678 435 /// Not implemented
436 AliHLTMUONTriggerReconstructor& operator = (const AliHLTMUONTriggerReconstructor& rhs); // assignment operator
80590aa1 437
69c14678 438 AliMUONTriggerDDLDecoder<AliDecoderHandler> fDecoder; ///< Raw DDL data decoder.
6efe69e7 439};
440
441#endif // AliHLTMUONTRIGGERRECONSTRUCTOR_H