1 #ifndef AliHLTMUONTRIGGERRECONSTRUCTOR_H
2 #define AliHLTMUONTRIGGERRECONSTRUCTOR_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 */
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
16 Artur Szostak <artursz@iafrica.com>:
17 Completely reimplemented the lookup table to a simplified format.
18 **********************************************************************/
21 /// @file AliHLTMUONTriggerReconstructor.h
22 /// @author Indranil Das <indra.das@saha.ac.in>,
23 /// Artur Szostak <artursz@iafrica.com>
25 /// @brief Declaration of the AliHLTMUONTriggerReconstructor class for processing trigger DDL data.
28 #include "AliHLTLogging.h"
29 #include "AliHLTMUONDataTypes.h"
30 #include "AliMUONTriggerDDLDecoder.h"
31 #include "AliMUONTriggerDDLDecoderEventHandler.h"
33 extern "C" struct AliHLTMUONRecHitStruct;
34 extern "C" struct AliHLTMUONTriggerRecordStruct;
35 extern "C" struct AliHLTMUONTrigRecInfoStruct;
36 extern "C" struct AliHLTMUONTriggerRecoLutRow;
39 class AliHLTMUONTriggerReconstructor : public AliHLTLogging
43 AliHLTMUONTriggerReconstructor();
44 virtual ~AliHLTMUONTriggerReconstructor();
47 const AliHLTUInt8_t* rawData,
48 AliHLTUInt32_t rawDataSize,
50 AliHLTMUONTriggerRecordStruct* trigRecord,
51 AliHLTUInt32_t& nofTrigRec
55 * Returns a pointer to the lookup table used to map between channel
56 * addresses and geometrical strip positions.
58 AliHLTMUONTriggerRecoLookupTable* LookupTableBuffer() { return fDecoder.GetHandler().LookupTableBuffer(); }
60 /// Returns the size of the lookup table.
61 size_t LookupTableSize() const { return fDecoder.GetHandler().LookupTableSize(); }
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(); };
67 /// Sets if the decoder should enable the error recovery logic.
68 void TryRecover(bool value);
71 * Sets the DDL bit according to the DDL value given.
72 * It is used to keep the trigger record IDs unique.
74 void SetDDL(AliHLTInt32_t ddl) { fDecoder.GetHandler().SetDDL(ddl); }
77 * Returns true if the output buffer was overflowed in the last call to Run.
79 bool OverflowedOutputBuffer() const { return fDecoder.GetHandler().OverflowedOutputBuffer(); }
82 * Returns the flag specifying if we should suppress partial trigger records.
83 * Partial triggers do not pass the 3/4'ths coincidence requirement.
85 bool SuppressPartialTriggers() const { return fDecoder.GetHandler().SuppressPartialTriggers(); }
88 * Sets the flag specifying if we should suppress partial trigger records.
89 * Partial triggers do not pass the 3/4'ths coincidence requirement.
91 void SuppressPartialTriggers(bool s) { fDecoder.GetHandler().SuppressPartialTriggers(s); }
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.
98 bool UseCrateId() const { return fDecoder.GetHandler().UseCrateId(); }
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.
105 void UseCrateId(bool value) { fDecoder.GetHandler().UseCrateId(value); }
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.
112 bool UseLocalId() const { return fDecoder.GetHandler().UseLocalId(); }
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.
119 void UseLocalId(bool value) { fDecoder.GetHandler().UseLocalId(value); }
121 /// Return the flag indicating if the debug information is stored during decoding.
122 bool StoreDebugInfo() const { return fDecoder.GetHandler().StoreDebugInfo(); }
124 /// Sets the flag indicating if the debug information should be stored.
125 void StoreDebugInfo(bool value) { fDecoder.GetHandler().StoreDebugInfo(value); }
127 /// Returns the number of elements in the debug information buffer.
128 AliHLTUInt32_t InfoBufferCount() const { return fDecoder.GetHandler().InfoBufferCount(); }
130 /// Returns the debug information buffer.
131 const AliHLTMUONTrigRecInfoStruct* InfoBuffer() const { return fDecoder.GetHandler().InfoBuffer(); }
133 /// Empty the info buffer.
134 void ZeroInfoBuffer() { fDecoder.GetHandler().ZeroInfoBuffer(); }
137 * Returns the flag indicating if the error message for a wrong event type found
138 * in the DARC header should be suppressed.
140 bool DontPrintWrongEventError() const { return fDecoder.GetHandler().DontPrintWrongEventError(); }
143 * Sets the flag indicating if the error message for a wrong event type found
144 * in the DARC header should be suppressed.
146 void DontPrintWrongEventError(bool value) { fDecoder.GetHandler().DontPrintWrongEventError(value); }
150 class AliDecoderHandler : public AliMUONTriggerDDLDecoderEventHandler, public AliHLTLogging
156 /// Default destructor.
157 virtual ~AliDecoderHandler();
159 /// Returns a pointer to the lookup table.
160 AliHLTMUONTriggerRecoLookupTable* LookupTableBuffer() { return &fLookupTable; }
162 /// Returns the size of the lookup table.
163 size_t LookupTableSize() const { return sizeof(fLookupTable); }
166 * Returns the maximum number of trigger records that can be
167 * written to the output buffer.
169 AliHLTUInt32_t MaxOutputTrigRecs() const { return fMaxOutputTrigRecs; }
172 * Sets the maximum number of trigger records that can be
173 * written to the output buffer.
175 void MaxOutputTrigRecs(AliHLTUInt32_t n) { fMaxOutputTrigRecs = n; }
178 * Returns the number of reconstructed trigger records actually
179 * stored in the output buffer.
181 AliHLTUInt32_t OutputTrigRecsCount() const { return fOutputTrigRecsCount; }
184 * Returns the pointer to the output buffer which stores reconstructed
187 AliHLTMUONTriggerRecordStruct* OutputTrigRecs() const { return fOutputTrigRecs; }
190 * Sets the pointer to the output buffer which stores reconstructed
191 * trigger records. Also resets the number of trigger records stored.
193 void OutputTrigRecs(AliHLTMUONTriggerRecordStruct* buf)
195 fOutputTrigRecs = buf;
196 fOutputTrigRecsCount = 0;
201 * Returns the flag specifying if we should suppress partial trigger records.
203 bool SuppressPartialTriggers() const { return fSuppressPartialTriggers; }
206 * Sets the flag specifying if we should suppress partial trigger records.
208 void SuppressPartialTriggers(bool s) { fSuppressPartialTriggers = s; }
211 * Returns true if the output buffer was overflowed.
213 bool OverflowedOutputBuffer() const { return fOverflowed; }
216 * Returns true if the OnError handler method will only generate warning
217 * messages and rather than error messages.
219 bool WarnOnly() const { return fWarnOnly; }
222 * Sets the flag indicating if the OnError method should only generate
223 * warnings rather than error messages.
225 void WarnOnly(bool value) { fWarnOnly = value; }
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.
232 bool UseCrateId() const { return fUseCrateId; }
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.
239 void UseCrateId(bool value) { fUseCrateId = value; }
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.
246 bool UseLocalId() const { return fUseLocalId; }
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.
253 void UseLocalId(bool value) { fUseLocalId = value; }
256 * Sets the DDL bit according to the DDL value given.
258 void SetDDL(AliHLTInt32_t ddl) { fDDLBit = (ddl == 20 ? 0x00 : 0x80); }
260 // Methods inherited from AliMUONTriggerDDLDecoderEventHandler:
262 /// Called for each new buffer. Just remember the start location of the buffer.
263 void OnNewBuffer(const void* buffer, UInt_t /*bufferSize*/)
265 assert( buffer != NULL );
266 fBufferStart = buffer;
267 fHadWrongEventTypeError = fHadNonWrongEventTypeError = false;
271 * Sets the regional structure sequencial number and decodes the crate ID.
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.
276 void OnNewRegionalStructV2(
278 const AliMUONRegionalHeaderStruct* regionalStruct,
279 const AliMUONRegionalScalarsStruct* /*scalars*/,
284 * Updates the local trigger structure pointers and processes the
285 * the last local trigger.
287 void OnEndOfRegionalStructV2(
289 const AliMUONRegionalHeaderStruct* regionalStruct,
290 const AliMUONRegionalScalarsStruct* scalars,
295 * Updates the local trigger structure pointers and processes the
296 * current local trigger.
298 void OnLocalStructV2(
300 const AliMUONLocalInfoStruct* localStruct,
301 const AliMUONLocalScalarsStruct* scalars
304 /// Logs an error message if there was a decoding problem with the DDL payload.
305 void OnError(ErrorCode code, const void* location);
307 /// Return the flag indicating if the debug information is stored during decoding.
308 bool StoreDebugInfo() const { return fStoreInfo; }
310 /// Sets the flag indicating if the debug information should be stored.
311 void StoreDebugInfo(bool value) { fStoreInfo = value; }
313 /// Returns the number of elements in the debug information buffer.
314 AliHLTUInt32_t InfoBufferCount() const { return fInfoBufferCount; }
316 /// Returns the debug information buffer.
317 const AliHLTMUONTrigRecInfoStruct* InfoBuffer() const { return fInfoBuffer; }
319 /// Empty the info buffer.
320 void ZeroInfoBuffer() { fInfoBufferCount = 0; }
323 * Returns the flag indicating if the error message for a wrong event type found
324 * in the DARC header should be suppressed.
326 bool DontPrintWrongEventError() const { return fDontPrintWrongEventError; }
329 * Sets the flag indicating if the error message for a wrong event type found
330 * in the DARC header should be suppressed.
332 void DontPrintWrongEventError(bool value) { fDontPrintWrongEventError = value; }
334 /// Returns true if the last decoded DDL had a wrong event type error in the DARC header.
335 bool HadWrongEventTypeError() const { return fHadWrongEventTypeError; }
338 * Returns true if the last decoded DDL had a different error than just a
339 * wrong event type error in the DARC header.
341 bool HadNonWrongEventTypeError() const { return fHadNonWrongEventTypeError; }
344 // Do not allow copying of this class.
346 AliDecoderHandler(const AliDecoderHandler& rhs); // copy constructor
348 AliDecoderHandler& operator = (const AliDecoderHandler& rhs); // assignment operator
351 * Finds the strip bits / positions on MT1 that were fired in
352 * the current local trigger structure decision.
354 bool FindStripsOnMT1(AliHLTInt32_t& xPos, AliHLTInt32_t& yPos);
357 * Selects the correct X strip patterns to use in FindXStrips.
358 * [out] \param strips Resulting array of X strip patterns to use
359 * for chambers 11 to 14.
361 void SelectXPatterns(AliHLTUInt64_t strips[4]);
364 * Selects the correct Y strip patterns to use in FindYStrips and local IDs for
365 * finding the correct row in the lookup table.
366 * [in] \param xpos Array of X strip positions generated by FindXStrips.
367 * Values are in the range [0..47].
368 * [out] \param strips Resulting array of Y strip patterns to use.
369 * [out] \param locId Resulting array of local IDs to use for the lookup table.
371 void SelectYPatterns(AliHLTInt32_t xpos[4], AliHLTUInt32_t strips[4], AliHLTUInt8_t locId[4]);
374 * Tries to find the fired X strips for chambers 11 to 14.
376 void FindXStrips(AliHLTInt32_t startPos, AliHLTUInt64_t strips[4], AliHLTInt32_t pos[4]);
379 * Tries to find the fired Y strips for chambers 11 to 14.
381 void FindYStrips(AliHLTInt32_t startPos, AliHLTUInt32_t strips[4], AliHLTInt32_t pos[4]);
384 * Fetches the appropriate LUT row for a given X strip position.
386 const AliHLTMUONTriggerRecoLutRow& GetLutRowX(AliHLTInt32_t xPos, AliHLTUInt8_t chamber);
389 * Reconstructs a hit with global position coordinates from strip
390 * information on a given chamber.
393 AliHLTUInt64_t xStrips, AliHLTUInt32_t yStrips,
394 AliHLTInt32_t xPos, AliHLTInt32_t yPos, AliHLTUInt8_t yLocId,
395 AliHLTUInt8_t chamber, AliHLTMUONRecHitStruct& hit
399 * Converts the fCurrentStruct local trigger structure from the L0
400 * into a trigger record.
402 void ProcessLocalStruct();
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.
410 AliHLTInt32_t fDDLBit; ///< The DDL bit used to generate unique trigger record IDs.
411 bool fSuppressPartialTriggers; ///< Flag to indicate if we should suppres partial triggers.
412 bool fOverflowed; ///< Flag to indicate if we overflowed the output buffer.
413 bool fWarnOnly; ///< Flag indicating if the OnError method should generate warnings rather than error messages.
414 bool fUseLocalId; ///< Flag to indicate if the local structure ID as found in the local structures should be used or not.
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.
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.
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.
430 static const AliMUONLocalInfoStruct fgkNullStruct; ///< Empty structure marker.
434 AliHLTMUONTriggerReconstructor(const AliHLTMUONTriggerReconstructor& rhs); // copy constructor
436 AliHLTMUONTriggerReconstructor& operator = (const AliHLTMUONTriggerReconstructor& rhs); // assignment operator
438 AliMUONTriggerDDLDecoder<AliDecoderHandler> fDecoder; ///< Raw DDL data decoder.
441 #endif // AliHLTMUONTRIGGERRECONSTRUCTOR_H