Line data Source code
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 */
6 :
7 : // $Id$
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
15 :
16 : Artur Szostak <artursz@iafrica.com>:
17 : Completely reimplemented the lookup table to a simplified format.
18 : **********************************************************************/
19 :
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 :
28 : #include "AliHLTLogging.h"
29 : #include "AliHLTMUONDataTypes.h"
30 : #include "AliMUONTriggerDDLDecoder.h"
31 : #include "AliMUONTriggerDDLDecoderEventHandler.h"
32 :
33 : extern "C" struct AliHLTMUONRecHitStruct;
34 : extern "C" struct AliHLTMUONTriggerRecordStruct;
35 : extern "C" struct AliHLTMUONTrigRecInfoStruct;
36 : extern "C" struct AliHLTMUONTriggerRecoLutRow;
37 :
38 :
39 : class AliHLTMUONTriggerReconstructor : public AliHLTLogging
40 : {
41 : public:
42 :
43 : AliHLTMUONTriggerReconstructor();
44 : virtual ~AliHLTMUONTriggerReconstructor();
45 :
46 : bool Run(
47 : const AliHLTUInt8_t* rawData,
48 : AliHLTUInt32_t rawDataSize,
49 : bool scalarEvent,
50 : AliHLTMUONTriggerRecordStruct* trigRecord,
51 : AliHLTUInt32_t& nofTrigRec
52 : );
53 :
54 : /**
55 : * Returns a pointer to the lookup table used to map between channel
56 : * addresses and geometrical strip positions.
57 : */
58 0 : AliHLTMUONTriggerRecoLookupTable* LookupTableBuffer() { return fDecoder.GetHandler().LookupTableBuffer(); }
59 :
60 : /// Returns the size of the lookup table.
61 0 : size_t LookupTableSize() const { return fDecoder.GetHandler().LookupTableSize(); }
62 :
63 : /// Returns true if the decoder is set to enable recovery logic if
64 : /// raw data errors are found.
65 0 : bool TryRecover() const { return fDecoder.TryRecover(); };
66 :
67 : /// Sets if the decoder should enable the error recovery logic.
68 : void TryRecover(bool value);
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 0 : void SetDDL(AliHLTInt32_t ddl) { fDecoder.GetHandler().SetDDL(ddl); }
75 :
76 : /**
77 : * Returns true if the output buffer was overflowed in the last call to Run.
78 : */
79 0 : 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 0 : 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 0 : void UseCrateId(bool value) { fDecoder.GetHandler().UseCrateId(value); }
106 :
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 0 : void UseLocalId(bool value) { fDecoder.GetHandler().UseLocalId(value); }
120 :
121 : /// Return the flag indicating if the debug information is stored during decoding.
122 0 : bool StoreDebugInfo() const { return fDecoder.GetHandler().StoreDebugInfo(); }
123 :
124 : /// Sets the flag indicating if the debug information should be stored.
125 0 : void StoreDebugInfo(bool value) { fDecoder.GetHandler().StoreDebugInfo(value); }
126 :
127 : /// Returns the number of elements in the debug information buffer.
128 0 : AliHLTUInt32_t InfoBufferCount() const { return fDecoder.GetHandler().InfoBufferCount(); }
129 :
130 : /// Returns the debug information buffer.
131 0 : const AliHLTMUONTrigRecInfoStruct* InfoBuffer() const { return fDecoder.GetHandler().InfoBuffer(); }
132 :
133 : /// Empty the info buffer.
134 0 : void ZeroInfoBuffer() { fDecoder.GetHandler().ZeroInfoBuffer(); }
135 :
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 0 : void DontPrintWrongEventError(bool value) { fDecoder.GetHandler().DontPrintWrongEventError(value); }
147 :
148 : private:
149 :
150 : class AliDecoderHandler : public AliMUONTriggerDDLDecoderEventHandler, public AliHLTLogging
151 : {
152 : public:
153 :
154 : AliDecoderHandler();
155 :
156 : /// Default destructor.
157 : virtual ~AliDecoderHandler();
158 :
159 : /// Returns a pointer to the lookup table.
160 0 : AliHLTMUONTriggerRecoLookupTable* LookupTableBuffer() { return &fLookupTable; }
161 :
162 : /// Returns the size of the lookup table.
163 0 : 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 0 : 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 0 : 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 0 : fOutputTrigRecs = buf;
196 0 : fOutputTrigRecsCount = 0;
197 0 : fOverflowed = false;
198 0 : }
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 0 : void SuppressPartialTriggers(bool s) { fSuppressPartialTriggers = s; }
209 :
210 : /**
211 : * Returns true if the output buffer was overflowed.
212 : */
213 0 : bool OverflowedOutputBuffer() const { return fOverflowed; }
214 :
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 0 : void WarnOnly(bool value) { fWarnOnly = value; }
226 :
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 0 : void UseCrateId(bool value) { fUseCrateId = value; }
240 :
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 0 : void UseLocalId(bool value) { fUseLocalId = value; }
254 :
255 : /**
256 : * Sets the DDL bit according to the DDL value given.
257 : */
258 0 : void SetDDL(AliHLTInt32_t ddl) { fDDLBit = (ddl == 20 ? 0x00 : 0x80); }
259 :
260 : // Methods inherited from AliMUONTriggerDDLDecoderEventHandler:
261 :
262 : /// Called for each new buffer. Just remember the start location of the buffer.
263 : void OnNewBuffer(const void* buffer, UInt_t /*bufferSize*/)
264 : {
265 0 : assert( buffer != NULL );
266 0 : fBufferStart = buffer;
267 0 : fHadWrongEventTypeError = fHadNonWrongEventTypeError = false;
268 0 : }
269 :
270 : /**
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.
275 : */
276 : void OnNewRegionalStructV2(
277 : UInt_t num,
278 : const AliMUONRegionalHeaderStruct* regionalStruct,
279 : const AliMUONRegionalScalarsStruct* /*scalars*/,
280 : const void* /*data*/
281 : );
282 :
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 : */
298 : void OnLocalStructV2(
299 : UInt_t num,
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);
306 :
307 : /// Return the flag indicating if the debug information is stored during decoding.
308 0 : bool StoreDebugInfo() const { return fStoreInfo; }
309 :
310 : /// Sets the flag indicating if the debug information should be stored.
311 0 : void StoreDebugInfo(bool value) { fStoreInfo = value; }
312 :
313 : /// Returns the number of elements in the debug information buffer.
314 0 : AliHLTUInt32_t InfoBufferCount() const { return fInfoBufferCount; }
315 :
316 : /// Returns the debug information buffer.
317 0 : const AliHLTMUONTrigRecInfoStruct* InfoBuffer() const { return fInfoBuffer; }
318 :
319 : /// Empty the info buffer.
320 0 : void ZeroInfoBuffer() { fInfoBufferCount = 0; }
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 0 : 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 0 : 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 0 : 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 0 : bool HadNonWrongEventTypeError() const { return fHadNonWrongEventTypeError; }
342 :
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 :
350 : /**
351 : * Finds the strip bits / positions on MT1 that were fired in
352 : * the current local trigger structure decision.
353 : */
354 : bool FindStripsOnMT1(AliHLTInt32_t& xPos, AliHLTInt32_t& yPos);
355 :
356 : /**
357 : * Selects the correct X strip patterns to use in FindXStrips.
358 : * \param [out] strips Resulting array of X strip patterns to use
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.
366 : * \param [in] xpos Array of X strip positions generated by FindXStrips.
367 : * Values are in the range [0..47].
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.
370 : */
371 : void SelectYPatterns(AliHLTInt32_t xpos[4], AliHLTUInt32_t strips[4], AliHLTUInt8_t locId[4]);
372 :
373 : /**
374 : * Tries to find the fired X strips for chambers 11 to 14.
375 : */
376 : void FindXStrips(AliHLTInt32_t startPos, AliHLTUInt64_t strips[4], AliHLTInt32_t pos[4]);
377 :
378 : /**
379 : * Tries to find the fired Y strips for chambers 11 to 14.
380 : */
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);
387 :
388 : /**
389 : * Reconstructs a hit with global position coordinates from strip
390 : * information on a given chamber.
391 : */
392 : void ReconstructHit(
393 : AliHLTUInt64_t xStrips, AliHLTUInt32_t yStrips,
394 : AliHLTInt32_t xPos, AliHLTInt32_t yPos, AliHLTUInt8_t yLocId,
395 : AliHLTUInt8_t chamber, AliHLTMUONRecHitStruct& hit
396 : );
397 :
398 : /**
399 : * Converts the fCurrentStruct local trigger structure from the L0
400 : * into a trigger record.
401 : */
402 : void ProcessLocalStruct();
403 :
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.
429 :
430 : static const AliMUONLocalInfoStruct fgkNullStruct; ///< Empty structure marker.
431 : };
432 :
433 : /// Not implemented
434 : AliHLTMUONTriggerReconstructor(const AliHLTMUONTriggerReconstructor& rhs); // copy constructor
435 : /// Not implemented
436 : AliHLTMUONTriggerReconstructor& operator = (const AliHLTMUONTriggerReconstructor& rhs); // assignment operator
437 :
438 : AliMUONTriggerDDLDecoder<AliDecoderHandler> fDecoder; ///< Raw DDL data decoder.
439 : };
440 :
441 : #endif // AliHLTMUONTRIGGERRECONSTRUCTOR_H
|