]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCDigitReaderRaw.h
code documentation
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCDigitReaderRaw.h
1 // XEmacs -*-C++-*-
2 // @(#) $Id$
3
4 #ifndef ALIHLTTPCDIGITREADERRAW_H
5 #define ALIHLTTPCDIGITREADERRAW_H
6
7 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
8  * See cxx source for full Copyright notice                               */
9
10 /** @file   AliHLTTPCDigitReaderRaw.h
11     @author Timm Steinbeck, Jochen Thaeder, Matthias Richter
12     @date   
13     @brief  A digit reader implementation for the RAW data coming from the RCU.
14 */
15
16 #include "TObject.h"
17
18 #include "AliHLTTPCDigitReader.h"
19 #include "AliHLTDataTypes.h"
20
21 /**
22  * @class AliHLTTPCDigitReaderRaw
23  * A digit reader implementation for the RAW data coming from the RCU.
24  * The reader decodes the data package to the level of the ALtro 10 bit words.
25  *
26  * The reader supports the following data format modes:
27  *  - 0: RCU Data format as delivered during TPC commissioning, pads/padrows 
28  *    are sorted, RCU trailer is one 32 bit word.
29  *  - 1: As 0, but pads/padrows are delivered "as is", without sorting
30  *  - 2: As 0, but RCU trailer is 3 32 bit words.
31  *  - 3: As 1, but RCU trailer is 3 32 bit words.
32  *  - 4: As 0, but RCU trailer is 2 32 bit words.
33  *  - 5: As 1, but RCU trailer is 2 32 bit words.
34  * @ingroup alihlt_tpc
35  */
36 class AliHLTTPCDigitReaderRaw : public AliHLTTPCDigitReader  {
37 public:
38
39   /** decode mode of the reader */
40   enum RawReaderMode {
41     /** 0: RCU Data format as delivered during TPC commissioning, pads/padrows
42      *  are sorted, RCU trailer is one 32 bit word. */
43     kSorted1Trailerword=0,
44     /** 1: As 0, but pads/padrows are delivered "as is", without sorting */
45     kUnsorted1Trailerword,
46     /** 2: As 0, but RCU trailer is 3 32 bit words. */
47     kSorted3Trailerword,
48     /** 3: As 1, but RCU trailer is 3 32 bit words. */
49     kUnsorted3Trailerword,
50     /** 4: As 0, but RCU trailer is 2 32 bit words. */
51     kSorted2Trailerword,
52     /** 5: As 1, but RCU trailer is 2 32 bit words. */
53     kUnsorted2Trailerword,
54     /** number of modes */
55     kNofRawReaderModes
56   };
57
58   /** standard constructor
59    * @param formatVersion  Data Format version numbers:
60    *  - 0: RCU Data format as delivered during TPC commissioning, pads/padrows
61    *    are sorted, RCU trailer is one 32 bit word.
62    *  - 1: As 0, but pads/padrows are delivered "as is", without sorting
63    *  - 2: As 0, but RCU trailer is 3 32 bit words.
64    *  - 3: As 1, but RCU trailer is 3 32 bit words.
65    *  - 4: As 0, but RCU trailer is 2 32 bit words.
66    *  - 5: As 1, but RCU trailer is 2 32 bit words.
67    */
68   AliHLTTPCDigitReaderRaw( unsigned formatVersion );
69   /** destructor */
70   virtual ~AliHLTTPCDigitReaderRaw();
71     
72   /**
73    * Init the reader with a data block.
74    * The function fetches the first and last row for the readout partition
75    * from @ref AliHLTTPCTransform.
76    * @param ptr     pointer to data buffer
77    * @param size    size of the data buffer
78    * @param patch   patch (readout partition) number within the slice
79    * @param slice   sector no (0 to 35)
80    */
81   virtual int InitBlock(void* ptr,unsigned long size, Int_t patch, Int_t slice);
82
83   /**
84    * Old Init function.
85    * <b>Note:</b> This method is for backward compatibility only, not for further
86    * use. The <i>firstrow</i> and <i>lastrow</i> parameters are fetched from
87    * @ref AliHLTTPCTransform. The method is implemented in the raw reader base class
88    * but is defined here to keep the signature of the library interface.
89    *
90    * @param ptr       pointer to data buffer
91    * @param size      size of the data buffer
92    * @param firstrow  first row occuring in the data
93    * @param lastrow   last row occuring in the data
94    * @param patch     patch (readout partition) number within the slice
95    * @param slice     sector no (0 to 35)
96    */
97   int InitBlock(void* ptr,unsigned long size,Int_t firstrow,Int_t lastrow, Int_t patch, Int_t slice);
98
99   // Deliver values sorted for format 0, otherwise pass through to corresponding *Real* method
100   virtual bool NextSignal();
101   virtual int GetRow();
102   virtual int GetPad();
103   virtual int GetSignal();
104   virtual int GetTime();
105
106   /**
107    * Get pointer and size of the data of the current ALTRO channel.
108    * @param pTgt        target to receive the pointer to the buffer
109    * @param hwAddress   target to receive the hardware address
110    * @return size of the buffer set to pTgt in bytes on success, 
111    *         neg error code if failed
112    */
113   int GetAltroChannelRawData(void* &pTgt, AliHLTUInt16_t &hwAddress);
114
115   bool Verify( bool verify )
116   {
117     bool old = fVerify;
118     fVerify=verify;
119     return old;
120   }
121
122   bool GetVerify() const
123   {
124     return fVerify;
125   }
126
127   //
128   // Deliver values unsorted
129   //
130   /** unsorted next value */
131   bool RealNext();
132   /** row of current value */
133   int GetRealRow() const;
134   /** pad of current value */
135   int GetRealPad() const;
136   /** signal of current value */
137   int GetRealSignal();
138   /** time of current value */
139   int GetRealTime() const;
140
141   //
142   // Low level methods for accessing the data
143   //
144   /** get rcu trailer word of the raw data */
145   AliHLTUInt32_t GetRCUTrailer( unsigned offset=0 ) const;
146
147   /** move to next altro block and set internal variables */
148   bool NextAltroBlock();
149
150   /** hardware address of the current altro block */
151   AliHLTUInt32_t GetAltroBlockHWaddr() const;
152
153   /** get no of 10bit words in the current altro block */
154   unsigned GetAltroBlock10BitWordCnt() const;
155
156   /** ndx counts from end, 0 is last */
157   AliHLTUInt64_t GetAltroBlock40BitWord( unsigned long ndx ) const;
158
159   /** ndx counts from end, 0 is last */
160   AliHLTUInt16_t GetAltroBlock10BitWord( unsigned long ndx );
161
162   /** ndx counts from end, 0 is last */
163   AliHLTUInt16_t GetAltroBlockReal10BitWord( unsigned long ndx );
164
165     unsigned GetAltroBlockPositionBytes() const
166         {return fAltroBlockPositionBytes;}
167     unsigned GetAltroBlockLengthBytes() const
168         {return fAltroBlockLengthBytes;}
169
170     /** Return length of trailing RCU data block in bytes */
171     unsigned GetRCUDataBlockLength() const;
172     unsigned GetCommonDataHeaderSize() const;
173         
174     Bool_t ApplyMapping();
175
176   Int_t GetRow( unsigned patch, unsigned hwAddr );
177   Int_t GetPad( unsigned patch, unsigned hwAddr );
178   unsigned GetMaxHWA( unsigned patch ) const;
179
180   /**
181    * This function decodes the rawreadermode set in HLT***Components
182    * or the AliHLTGUI and returns the integer value of @ref RawReaderMode.
183    * @param mode const Char_t * argument <br>
184    *    sorted_3_trailerword -> @ref kSorted3Trailerword <br>
185    *    sorted_2_trailerword -> @ref kSorted2Trailerword <br>
186    *    sorted_1_trailerword -> @ref kSorted1Trailerword <br>
187    *    unsorted_3_trailerword -> @ref kUnsorted3Trailerword <br>
188    *    unsorted_2_trailerword -> @ref kUnsorted2Trailerword <br>
189    *    unsorted_1_trailerword -> @ref kUnsorted1Trailerword <br>
190    * @return rawreadermode @ref RawReaderMode and -1 if decoding fails
191    */
192   static Int_t DecodeMode(const Char_t *mode);
193
194   /**
195    * This function sets the rawreadermode from an enum.
196    * The name was chosen in order to use the two methods with either
197    * a Char_t array or an Int_t.
198    * @param mode mode enum @ref RawReaderMode
199    * @return rawreadermode @ref RawReaderMode and -1 if decoding fails
200    */
201   static Int_t DecodeMode(Int_t mode);
202
203 protected:
204
205   /** the raw data buffer (external buffer) */
206   AliHLTUInt8_t* fBuffer;                                          //! transient
207   /** size of the raw data buffer */
208   unsigned long fBufferSize;                                       // see above
209     /*
210     Int_t fFirstRow;
211     Int_t fLastRow;
212     */
213
214   /** patch (readout partition) specification of the raw data buffer */
215   Int_t fPatch;                                                    // see above
216
217   /** slice (sector) specification of the raw data buffer */
218   Int_t fSlice;                                                    // see above
219
220   /** the current row no */
221   Int_t fRow;                                                      // see above
222
223   /** the current pad no */
224   Int_t fPad;                                                      // see above
225
226
227   /** position of the current ALTRO block*/
228   unsigned fAltroBlockPositionBytes;                               // see above
229
230   /** length of the current ALTRO block*/
231   unsigned fAltroBlockLengthBytes;                                 // see above
232   
233   /** hardware of the current ALTRO block*/
234   AliHLTUInt16_t fAltroBlockHWAddress;                             // see above
235
236   /** no of 10 bit words in the current ALTRO block*/
237   AliHLTUInt16_t fAltroBlock10BitWordCnt;                          // see above
238
239   /** no of additional 10 bit fill words in the current ALTRO block*/
240   AliHLTUInt16_t fAltroBlock10BitFillWordCnt;                      // see above
241
242   /** version of data format */
243   unsigned fDataFormatVersion;                                     // see above
244
245   /** position of the current bunch of timebins */  
246   unsigned fBunchPosition;                                         // see above
247   /** first timebin of current bunch */  
248   unsigned fBunchTimebinStart;                                     // see above
249   /** length of current bunch */  
250   unsigned fBunchLength;                                           // see above
251   /** word counter in bunch */  
252   unsigned fWordInBunch;                                           // see above
253
254   /** verify the consistency of the Altro blocks */
255   bool fVerify;                                                    // see above
256
257 private:
258   /** copy constructor prohibited */
259   AliHLTTPCDigitReaderRaw(const AliHLTTPCDigitReaderRaw& src);
260   /** assignment operator prohibited */
261   AliHLTTPCDigitReaderRaw& operator=(const AliHLTTPCDigitReaderRaw& src);
262   /** number of patches */ 
263   static const Int_t fgkNofPatches=6;                              // see above
264   /** dimension of each mapping array */ 
265   static const Int_t fgkMappingDimension=2;                        // see above
266
267   /** size of mapping arrays */
268   static const Int_t fgkMapping0Size=3200;                         // see above
269   /** size of mapping array for patch 1 */
270   static const Int_t fgkMapping1Size=3584;                         // see above
271   /** size of mapping array for patch 2 */
272   static const Int_t fgkMapping2Size=3200;                         // see above
273   /** size of mapping array for patch 3 */
274   static const Int_t fgkMapping3Size=3328;                         // see above
275   /** size of mapping array for patch 4 */
276   static const Int_t fgkMapping4Size=3328;                         // see above
277   /** size of mapping array for patch 5 */
278   static const Int_t fgkMapping5Size=3328;                         // see above
279
280   /** mapping array for patch 0 */
281   static Int_t fgMapping0[fgkMapping0Size][fgkMappingDimension];   // see above
282   /** mapping array for patch 1 */
283   static Int_t fgMapping1[fgkMapping1Size][fgkMappingDimension];   // see above
284   /** mapping array for patch 2 */
285   static Int_t fgMapping2[fgkMapping2Size][fgkMappingDimension];   // see above
286   /** mapping array for patch 3 */
287   static Int_t fgMapping3[fgkMapping3Size][fgkMappingDimension];   // see above
288   /** mapping array for patch 4 */
289   static Int_t fgMapping4[fgkMapping4Size][fgkMappingDimension];   // see above
290   /** mapping array for patch 5 */
291   static Int_t fgMapping5[fgkMapping5Size][fgkMappingDimension];   // see above
292
293   static unsigned fgMaxHWA[fgkNofPatches];                         // see above
294
295   // For reordering
296   /** current row */
297   Int_t fCurrentRow;                                               // see above
298   /** current pad */
299   Int_t fCurrentPad;                                               // see above
300   /** current bin */
301   Int_t fCurrentBin;                                               // see above
302  
303   /** ofsset of the first row */
304   Int_t fRowOffset;                                                // see above
305   /** nimber of rows */
306   Int_t fNRows;                                                    // see above
307   
308   /** max number of rows */
309   Int_t fNMaxRows;                                                 // see above
310   /** max number of pads */
311   Int_t fNMaxPads;                                                 // see above
312   /** number of time bins */
313   Int_t fNTimeBins;                                                // see above
314
315   Int_t *fData;                                                    //! transient
316
317   /** indicate a virgin object and throw the warnig only once */
318   Int_t fMapErrThrown;                                             //! transient 
319
320   ClassDef(AliHLTTPCDigitReaderRaw, 1)
321     
322 };
323
324 #endif