]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructor.h
Trying to fix coding violations.
[u/mrichter/AliRoot.git] / HLT / MUON / OnlineAnalysis / AliHLTMUONHitReconstructor.h
1 #ifndef ALIHLTMUONHITRECONSTRUCTOR_H
2 #define ALIHLTMUONHITRECONSTRUCTOR_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 //Author : Indranil Das, SINP, INDIA
11 //         Sukalyan Chattopadhyay, SINP, INDIA
12 //         
13 //Email :  indra.das@saha.ac.in
14 //         sukalyan.chattopadhyay@saha.ac.in 
15 ///////////////////////////////////////////////
16
17 #include <map>
18
19 #include "AliHLTLogging.h"
20 #include "AliMUONTrackerDDLDecoder.h"
21 #include "AliMUONTrackerDDLDecoderEventHandler.h"
22 #include "AliHLTMUONDataTypes.h"
23
24 #if __GNUC__ && __GNUC__ < 3
25 #define std
26 #endif
27
28
29 extern "C" struct AliHLTMUONRecHitStruct;
30 extern "C" struct AliHLTMUONClusterStruct;
31 extern "C" struct AliHLTMUONChannelStruct;
32 typedef std::map<AliHLTInt32_t, AliHLTInt32_t> IdManuChannelToEntry;
33 typedef IdManuChannelToEntry MaxEntryPerBusPatch;
34
35 class AliHLTMUONHitReconstructor : public AliHLTLogging
36 {
37 public:
38         
39         AliHLTMUONHitReconstructor();
40         virtual ~AliHLTMUONHitReconstructor(void);
41         
42         void SetLookUpTable(
43                         const AliHLTMUONHitRecoLutRow* lookupTable,
44                         const IdManuChannelToEntry* idToEntry,
45                         const MaxEntryPerBusPatch* maxEntryPerBP
46                 );
47         
48         void SetDCCut(AliHLTInt32_t dcCut) { fDCCut = dcCut; }
49         AliHLTInt32_t GetDCCut() const { return fDCCut; }
50         
51         bool Run(
52                         const AliHLTUInt32_t* rawData,
53                         AliHLTUInt32_t rawDataSize,
54                         AliHLTMUONRecHitStruct* const recHit,
55                         AliHLTUInt32_t& nofHit
56                 );
57         
58         /**
59          * Fills the output clusters array with the extra cluster information generated.
60          * If the method GenerateClusterInfo(true) was not called, then no cluster information
61          * is generated and this method will not do anything.
62          * [out] \param clusters  This is the output array that will be filled.
63          * [in/out] \param nofClusters Initially this contains the maximum number of elements
64          *     that can be stored in the clusters array. The method will fill this with
65          *     the actual number of elements stored.
66          * \returns true if all elements were copied and false if there is not enough space in
67          *     the output array.
68          */
69         bool FillClusterData(AliHLTMUONClusterStruct* clusters, AliHLTUInt32_t& nofClusters);
70         
71         /**
72          * Fills the output channels array with the extra channel information generated.
73          * If the method GenerateChannelInfo(true) was not called, then no extra channel
74          * information is generated and this method will not do anything.
75          * [out] \param channels  This is the output array that will be filled.
76          * [in/out] \param nofChannels Initially this contains the maximum number of elements
77          *     that can be stored in the channels array. The method will fill this with
78          *     the actual number of elements stored.
79          * \returns true if all elements were copied and false if there is not enough space in
80          *     the output array.
81          */
82         bool FillChannelData(AliHLTMUONChannelStruct* channels, AliHLTUInt32_t& nofChannels);
83         
84         static AliHLTInt32_t GetkDetectorId() { return fgkDetectorId; }
85         static AliHLTInt32_t GetkDDLOffSet() { return fgkDDLOffSet; }
86         static AliHLTInt32_t GetkNofDDL() { return fgkNofDDL; }
87         static AliHLTInt32_t GetkDDLHeaderSize() { return fgkDDLHeaderSize; }
88         static AliHLTInt32_t GetkNofDetElemInDDL(Int_t iDDL);
89         static AliHLTInt32_t GetkMinDetElemIdInDDL(Int_t iDDL);
90         
91         /// The error recovery mode used for TryRecover.
92         enum ERecoveryMode
93         {
94                 kDontTryRecover = 0,  /// Will not try recover from errors.
95                 kRecoverFull,  /// Try recover from all errors.
96                 kRecoverJustSkip,  /// Just skip any corrupt structures.
97                 kRecoverFromParityErrorsOnly  /// Recover only from parity errors.
98         };
99         
100         /// Returns the recovery mode used for the TryRecover option.
101         /// This controls if the decoder is set to enable recovery logic if
102         /// raw data errors are found.
103         ERecoveryMode TryRecover() const { return fRecoveryMode; }
104         
105         /// Sets if the decoder should enable the error recovery logic and how.
106         void TryRecover(ERecoveryMode mode);
107         
108         /// Returns true if ADC digits with parity errors are skipped.
109         bool SkipParityErrors() const { return fHLTMUONDecoder.GetHandler().SkipParityErrors(); }
110         
111         /// Sets the flag indicating if ADC digits with parity errors are skipped.
112         void SkipParityErrors(bool value) { fHLTMUONDecoder.GetHandler().SkipParityErrors(value); }
113         
114         /// Returns true if messages about parity errors are not printed.
115         bool DontPrintParityErrors() const { return fHLTMUONDecoder.GetHandler().DontPrintParityErrors(); }
116         
117         /// Sets the flag indicating if messages about parity errors are not printed.
118         void DontPrintParityErrors(bool value) { fHLTMUONDecoder.GetHandler().DontPrintParityErrors(value); }
119         
120         /// Returns true if the extra cluster information should be generated.
121         bool GenerateClusterInfo() const { return fGenerateClusterInfo; }
122         
123         /// Sets the flag to indicate if the extra cluster information should be generated.
124         void GenerateClusterInfo(bool value) { fGenerateClusterInfo = value; }
125         
126         /// Returns true if the extra channel information should be generated.
127         bool GenerateChannelInfo() const { return fGenerateChannelInfo; }
128         
129         /// Sets the flag to indicate if the extra channel information should be generated.
130         void GenerateChannelInfo(bool value) { fGenerateChannelInfo = value; }
131         
132         /// Returns the maximum channel multiplicity allowed per cluster.
133         bool MaxChannelMultiplicity() const { return fMaxChannelMult; }
134         
135         /// Sets the maximum channel multiplicity allowed per cluster.
136         /// \note This effects the memory allocation required. Generally M*N number of
137         ///   channel structures will be allocated, where M = fMaxChannelMult and
138         ///   N = the maximum number of hits that can be filled into the output buffers.
139         void MaxChannelMultiplicity(bool value) { fMaxChannelMult = value; }
140         
141         /// Returns the DDL number the component expects data to be received from.
142         AliHLTInt32_t DDLNumber() const { return fDDL; }
143         
144         /// Sets the DDL number the component expects data to be received from.
145         void DDLNumber(AliHLTInt32_t value) { fDDL = (value & 0x1F); }  // 0x1F forces value into our required range.
146
147         bool InitDetElemInDDLArray();
148         bool DeInitDetElemInDDLArray();
149
150 private:
151
152         static const AliHLTInt32_t fgkDetectorId;      // DDL Offset
153         static const AliHLTInt32_t fgkDDLOffSet;       // DDL Offset
154         static const AliHLTInt32_t fgkNofDDL;          // Number of DDL 
155         static const AliHLTInt32_t fgkDDLHeaderSize;   // DDL header size
156         static const AliHLTInt32_t fgkLutLine;         // nof Line in LookupTable
157         static const AliHLTInt32_t fgkMaxNofDataPerDetElem;         // maximum allowed data points per detlem
158         static const AliHLTInt32_t fgkNofDetElemInDDL[20] ;         // nof Detelem in a given ddl
159         static const AliHLTInt32_t fgkMinDetElemIdInDDL[20] ;       // the detelem which has minimum value in ddl
160
161         AliHLTMUONHitReconstructor(const AliHLTMUONHitReconstructor& rhs); // copy constructor
162         AliHLTMUONHitReconstructor& operator=(const AliHLTMUONHitReconstructor& rhs); // assignment operator
163
164         struct AliHLTMUONPad
165         {
166                 AliHLTInt32_t fDetElemId;  // The detector element ID of the pad.
167                 AliHLTInt32_t fIX, fIY;  // The X,Y number of the pad.
168                 AliHLTFloat32_t fRealX, fRealY, fRealZ;   // The real coordinate of the pad.
169                 AliHLTFloat32_t fHalfPadSize; // half padsize in X and Y
170                 AliHLTFloat32_t fPadSizeXY; // padsize in Y for bending plane and X for nonbending
171                 AliHLTInt32_t fPlane;   // The plane and PCB zone ID numbers.
172                 AliHLTFloat32_t fCharge;  // The charge measured on the pad.
173                 AliHLTInt32_t fBusPatch;  // The bus patch of the raw data word from the DDL stream.
174                 AliHLTUInt32_t fRawData;  // The raw data word from the DDL stream.
175         };
176         
177
178         class AliHLTMUONRawDecoder : public AliMUONTrackerDDLDecoderEventHandler, public AliHLTLogging
179         {
180         public:
181         
182                 AliHLTMUONRawDecoder();
183                 virtual ~AliHLTMUONRawDecoder();
184                 
185                 void OnData(UInt_t dataWord, bool parityError);
186                 void OnNewBusPatch(const AliMUONBusPatchHeaderStruct* header, const void* data) ;
187                 
188                 void OnNewBuffer(const void* buffer, UInt_t bufferSize);
189                 void OnError(ErrorCode code, const void* location);
190                 
191                 void SetDCCut(AliHLTInt32_t dcCut) {fDCCut = dcCut;}
192                 void SetPadData(AliHLTMUONPad* const padData) {fPadData = padData;}
193                 void SetLookUpTable(const AliHLTMUONHitRecoLutRow* lookUpTableData) {fkLookUpTableData = lookUpTableData;}
194
195                 void SetIdManuChannelToEntry(const IdManuChannelToEntry* idToEntry) {fkIdToEntry = idToEntry;}
196                 void SetMaxEntryPerBusPatch(const MaxEntryPerBusPatch* maxEntryPerBP) {fkMaxEntryPerBusPatch = maxEntryPerBP;}
197
198                 AliHLTInt32_t DDLNumber() const { return fDDL; }
199                 void DDLNumber(AliHLTInt32_t value) { fDDL = (value & 0x1F); }  // 0x1F forces value into our required range.
200                 // The following two methods have to called after set the ddl
201                 void SetNofFiredDetElemId(AliHLTUInt16_t* const nofDataInDetElem) {fNofDataInDetElem = nofDataInDetElem;}
202                 void SetMaxFiredPerDetElem(AliHLTUInt16_t** const dataCountListPerDetElem) {fDataCountListPerDetElem = dataCountListPerDetElem;}                
203
204
205                 AliHLTInt32_t GetDataCount() const {return fDataCount;}
206                 
207                 /**
208                  * Returns true if the OnError handler method will only generate warning
209                  * messages and rather than error messages.
210                  */
211                 bool WarnOnly() const { return fWarnOnly; }
212                 
213                 /**
214                  * Sets the flag indicating if the OnError method should only generate
215                  * warnings rather than error messages.
216                  */
217                 void WarnOnly(bool value) { fWarnOnly = value; }
218                 
219                 /**
220                  * Returns true if ADC digits with parity errors are skipped.
221                  */
222                 bool SkipParityErrors() const { return fSkipParityErrors; }
223                 
224                 /**
225                  * Sets the flag indicating if ADC digits with parity errors are skipped.
226                  */
227                 void SkipParityErrors(bool value) { fSkipParityErrors = value; }
228                 
229                 /**
230                  * Returns true if messages about parity errors are not printed.
231                  */
232                 bool DontPrintParityErrors() const { return fDontPrintParityErrors; }
233                 
234                 /**
235                  * Sets the flag indicating if messages about parity errors are not printed.
236                  */
237                 void DontPrintParityErrors(bool value) { fDontPrintParityErrors = value; }
238                 
239                 /**
240                  * Returns true if parity error messages are printed as warnings.
241                  */
242                 bool PrintParityErrorAsWarning() const { return fPrintParityErrorAsWarning; }
243                 
244                 /**
245                  * Sets the flag indicating if parity error messages are printed as warnings.
246                  */
247                 void PrintParityErrorAsWarning(bool value) { fPrintParityErrorAsWarning = value; }
248                 
249                 /**
250                  * Returns true if a parity error was found during the last call to Decode.
251                  */
252                 bool ParityErrorFound() const { return fParityErrorFound; }
253                 
254                 /**
255                  * Returns true if a non-parity error was found during the last call to Decode.
256                  */
257                 bool NonParityErrorFound() const { return fNonParityErrorFound; }
258         
259         private:
260                 // Do not allow copying of this class.
261                 /// Not implemented
262                 AliHLTMUONRawDecoder(const AliHLTMUONRawDecoder& rhs); // copy constructor
263                 /// Not implemented
264                 AliHLTMUONRawDecoder& operator=(const AliHLTMUONRawDecoder& rhs); // assignment operator
265         
266                 const void* fkBufferStart;   // Pointer to the start of the current DDL payload buffer.
267                 AliHLTInt32_t fBusPatchId;  // buspatchId
268                 AliHLTInt32_t fDCCut;       // DC Cut value
269                 AliHLTMUONPad* fPadData;    // pointer to the array containing the information of each padhits
270                 const AliHLTMUONHitRecoLutRow* fkLookUpTableData;   // pointer to the array of Lookuptable data
271                 /* AliHLTInt32_t* fNofFiredDetElem;         // counter for detector elements that are fired  */
272                 /* AliHLTInt32_t* fMaxFiredPerDetElem;      // array for detector elements that are fired  */
273                 const IdManuChannelToEntry* fkIdToEntry;  // Mapping between Linenumber to IdManuChannel;
274                 const MaxEntryPerBusPatch* fkMaxEntryPerBusPatch;   // Maximum allowed entry per Buspatch.
275                 
276                 AliHLTInt32_t fDDL;                 // DDL number
277                 AliHLTInt32_t fDataCount;           // Data Counter
278                 AliHLTInt32_t fPrevDetElemId;       // previous detection elementId
279                 AliHLTInt32_t fPadCharge;           // pedestal subtracted pad charge
280                 AliHLTFloat32_t fCharge;            //calibrated pad charge 
281                 AliHLTInt32_t fIdManuChannel;       // id manu channel
282                 AliHLTInt32_t fLutEntry;            // i-th entry in lookuptable
283                 
284                 AliHLTUInt16_t **fDataCountListPerDetElem;               ///< List of datacounts associated with given ddl
285                 AliHLTUInt16_t *fNofDataInDetElem;                       ///< Nof datacount in a ddl
286                 bool fWarnOnly;  ///< Flag indicating if the OnError method should generate warnings rather than error messages.
287                 bool fSkipParityErrors;  ///< Flag indicating if ADC digits with parity errors should be skipped.
288                 bool fDontPrintParityErrors;  ///< Flag for controlling if messages about parity errors should be printed.
289                 bool fPrintParityErrorAsWarning;  ///< Flag for controlling if parity error messages are printed as warnings.
290                 bool fParityErrorFound;  ///< Flag if a parity error was found after a decoding pass.
291                 bool fNonParityErrorFound;  ///< Flag which indicates if a non parity error code was found after a decoding pass.
292                 bool fIsMuchNoisy;  ///< tag for noisy buspatch.
293         };
294
295         AliMUONTrackerDDLDecoder<AliHLTMUONRawDecoder> fHLTMUONDecoder; // robust HLTMUON Decoder
296         
297         AliHLTInt32_t fkBlockHeaderSize;      // Block header size
298         AliHLTInt32_t fkDspHeaderSize;        // DSP header size
299         AliHLTInt32_t fkBuspatchHeaderSize;   // buspatch header size
300         
301         AliHLTInt32_t fDCCut;                 // DC Cut value
302         
303         AliHLTMUONPad* fPadData;  // pointer to the array containing the information of each padhits
304         const AliHLTMUONHitRecoLutRow* fkLookUpTableData;  // pointer to the array of Lookuptable data (The memory is not owned by this component).
305         
306         AliHLTMUONRecHitStruct* fRecPoints;      // Reconstructed hits
307         AliHLTUInt32_t *fRecPointsCount;         // nof reconstructed hit.
308         AliHLTUInt32_t fMaxRecPointsCount;       // max nof reconstructed hit.
309         
310         AliHLTMUONClusterStruct* fClusters;  // Array of output cluster infromation.
311         AliHLTUInt32_t fClusterCount;       // Number of elemenets in fClusters.
312         AliHLTUInt32_t fMaxClusters;        // Maximum number of clusters in fClusters.
313         bool fGenerateClusterInfo;   // Flag indicating if extra cluster information should be generated.
314         AliHLTInt32_t fNewClusterId;  // The ID to use for a new cluster structure.
315         AliHLTInt32_t fDDL;   // The source DDL number of the raw data.
316         
317         AliHLTMUONChannelStruct* fChannels;  // Array of output channel infromation.
318         AliHLTUInt32_t fChannelCount;       // Number of elemenets in fChannels.
319         AliHLTUInt32_t fMaxChannels;        // Maximum number of channels in fChannels.
320         bool fGenerateChannelInfo;   // Flag indicating if extra channel information should be generated.
321         AliHLTUInt32_t fMaxChannelMult;  // Indicates the maximum channel multiplicity per cluster allowed.
322         
323         AliHLTInt32_t fCentralCountB, fCentralCountNB;   // centeral hits.
324         AliHLTInt32_t fDigitPerDDL;                      // Total nof Digits perDDL.
325
326         AliHLTUInt16_t **fDataCountListPerDetElem;               // List of datacounts associated with given ddl
327         AliHLTUInt16_t *fNofDataInDetElem;                       // Nof datacount in a ddl
328         AliHLTInt32_t *fCentralChargeB, *fCentralChargeNB;       // pointer to an array of central hit
329         AliHLTFloat32_t *fRecX, *fRecY;                          // pointer to an array of reconstructed hit
330         AliHLTFloat32_t *fAvgChargeX, *fAvgChargeY;              // average charge on central pad found using CG method
331         AliHLTFloat32_t *fTotChargeX, *fTotChargeY;              // Total charge in bending and nonbending direction
332         AliHLTInt32_t *fNofBChannel, *fNofNBChannel;             // number of channels bending and non-bending.
333         AliHLTInt32_t *fNofYNeighbour;                           // number of neighbour pad in y direction, needed for y-resolution correction
334         AliHLTInt32_t fGetIdTotalData[336][237][2];              // an array of idManuChannel with argument of centralX, centralY and planeType.
335         //AliHLTInt32_t fNofFiredDetElem,fMaxFiredPerDetElem[130];  // counter for detector elements that are fired
336         const IdManuChannelToEntry* fkIdToEntry;   // Mapping between Linenumber to IdManuChannel (The object is not owned by this component).
337         const MaxEntryPerBusPatch* fkMaxEntryPerBusPatch;   // Maximum allowed entry per Buspatch.
338         
339         ERecoveryMode fRecoveryMode;  ///< The recovery mode for the decoder.
340         
341         bool DecodeDDL(const AliHLTUInt32_t* rawData, AliHLTUInt32_t rawDataSize);
342         void FindCentralHits(AliHLTInt32_t iDet);
343         bool FindRecHits();
344         void RecXRecY();
345         bool MergeSlatRecHits();
346         bool MergeQuadRecHits();
347         void Clear();
348
349 };
350
351 #endif // ALIHLTMUONHITRECONSTRUCTOR_H