]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDRawReader.h
bug fixed
[u/mrichter/AliRoot.git] / FMD / AliFMDRawReader.h
1 #ifndef ALIFMDRAWREADER_H
2 #define ALIFMDRAWREADER_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights
4  * reserved. 
5  *
6  * Latest changes by Christian Holm Christensen <cholm@nbi.dk>
7  *
8  * See cxx source for full Copyright notice                               
9  */
10 //____________________________________________________________________
11 // 
12 // Class to read ADC values from a AliRawReader object. 
13 // Note, that it uses an ALTRO reader, which is wrong. 
14 // Perhaps we need to implement it our selves
15 // 
16 /* $Id$ */
17 /** @file    AliFMDRawReader.h
18     @author  Christian Holm Christensen <cholm@nbi.dk>
19     @date    Mon Mar 27 12:45:23 2006
20     @brief   Class to read raw data 
21     @ingroup FMD_rec
22 */
23 #ifndef ROOT_TTask
24 # include <TTask.h>
25 #endif
26 #include "AliFMDUShortMap.h"
27
28 //____________________________________________________________________
29 class AliRawReader;
30 class AliAltroRawStreamV3;
31 class TTree;
32 class TClonesArray;
33 class TArrayS;
34 class AliFMDCalibSampleRate;
35 class AliFMDCalibStripRange;
36
37 //____________________________________________________________________
38 /** @brief Class to read ALTRO formated raw data from an AliRawReader
39     object. 
40     @code 
41     AliRawReader*    reader    = new AliRawReaderFile(0);
42     AliFMDRawReader* fmdReader = new AliFMDRawReader(reader);
43     TClonesArray*    array     = new TClonesArray("AliFMDDigit");
44     fmdReader->ReadAdcs(array);
45     @endcode 
46     @ingroup FMD_rec
47 */
48 class AliFMDRawReader : public TTask 
49 {
50 public:
51   /** 
52    * CTOR 
53    *
54    * @param reader Raw reader
55    * @param array  Output tree 
56    */
57   AliFMDRawReader(AliRawReader* reader, TTree* array);
58   /** 
59    * DTOR 
60    */
61   virtual ~AliFMDRawReader() {}
62   /** 
63    * Read in, and store in output tree 
64    *
65    * @param option Not used 
66    */
67   virtual void   Exec(Option_t* option="");
68   /**
69    * Read ADC's into a TClonesArray of AliFMDDigit objects. 
70    *
71    * @param array       Array to read into 
72    * @param summable    Create SDigits rather than digits 
73    * @param pedSub      Whether to do pedestal subtraction.
74    * @param noiseFactor If we do pedestal subtraction, then this is
75    *        the number we use to suppress remenants of the noise.
76    * 
77    * @return @c true on success 
78    */
79   virtual Bool_t ReadAdcs(TClonesArray* array);
80   /** 
81    * Read SOD event into passed objects.
82    * 
83    * @param samplerate   The sample rate object to fill
84    * @param striprange   The strip range object to fill
85    * @param pulseSize    The pulse size object to fill
86    * @param pulseLength  The pulse length (in events) object to fill
87    * 
88    * @return @c true on success
89    */  
90   virtual Bool_t ReadSODevent(AliFMDCalibSampleRate* samplerate, 
91                               AliFMDCalibStripRange* striprange, 
92                               TArrayS &pulseSize, 
93                               TArrayS &pulseLength, 
94                               Bool_t* detectors=0);
95   /** 
96    * Check of the data from DDL @a ddl is zero-suppressed
97    * 
98    * @param ddl DDL number (0-2)
99    * 
100    * @return @c true if the data from this DDL is zero-suppressed. 
101    */  
102   Bool_t IsZeroSuppressed(UShort_t ddl) const { return fZeroSuppress[ddl]; }
103   /** 
104    * The factor used to multiply the noise when making on-line
105    * pedestal subtraction.
106    * 
107    * @param ddl DDL number (0-2)
108    * 
109    * @return The factor used. 
110    */
111   UShort_t NoiseFactor(UShort_t ddl) const { return fNoiseFactor[ddl]; }
112
113   /** 
114    * Get the next signal
115    * 
116    * @param det  On return, the detector
117    * @param rng  On return, the ring
118    * @param sec  On return, the sector
119    * @param str  On return, the strip
120    * @param sam  On return, the sample
121    * @param rat  On return, the sample rate
122    * @param adc  On return, the ADC value
123    * @param zs   On return, whether zero-supp. is enabled
124    * @param fac  On return, the usd noise factor
125    * 
126    * @return true if valid data is returned
127    */
128   Bool_t NextSample(UShort_t& det, Char_t&   rng, UShort_t& sec, UShort_t& str,
129                     UShort_t& sam, UShort_t& rat, Short_t&  adc, 
130                     Bool_t&   zs,  UShort_t& fac);
131   /** 
132    * Get the next signal
133    * 
134    * @param det  On return, the detector
135    * @param rng  On return, the ring
136    * @param sec  On return, the sector
137    * @param str  On return, the strip
138    * @param adc  On return, the ADC value
139    * @param zs   On return, whether zero-supp. is enabled
140    * @param fac  On return, the usd noise factor
141    * 
142    * @return true if valid data is returned
143    */
144   Bool_t NextSignal(UShort_t& det, Char_t&   rng, 
145                     UShort_t& sec, UShort_t& str, 
146                     Short_t&  adc, Bool_t&   zs, 
147                     UShort_t& fac);
148   /** 
149    * Whether to keep a sample based on the rate used. 
150    * 
151    * @param samp Sample number 
152    * @param rate Over sampling rate
153    * 
154    * @return Whether to keep the sample or not
155    */
156   static Bool_t SelectSample(UShort_t samp, UShort_t rate);
157 protected:
158   /** 
159    * Copy constructor 
160    * 
161    * @param o Object to construct from
162    */  
163   AliFMDRawReader(const AliFMDRawReader& o) 
164     : TTask(o), 
165       fTree(0), 
166       fReader(0), 
167       fData(0),
168       fNbytes(0), 
169       fMinStrip(0), 
170       fMaxStrip(127),
171       fPreSamp(14+5),
172       fSeen(0)
173   {}
174   /** 
175    * Assignment operator
176    * 
177    * @return Reference to this object
178    */
179   AliFMDRawReader& operator=(const AliFMDRawReader&) { return *this; }
180   /** 
181    * Process a new DDL.  Sets the internal data members fZeroSuppress, 
182    * fSampleRate, and fNoiseFactor based on information in the RCU trailer. 
183    * 
184    * @param input Input stream
185    * @param det   On return, the detector number
186    * 
187    * @return negative value in case of problems, the DDL number otherwise
188    */
189   Int_t NewDDL(AliAltroRawStreamV3& input, UShort_t& det);
190   /** 
191    * Processs a new channel.  Sets the internal data members
192    * fMinStrip, fMaxStrip, and fPreSamp. 
193    * 
194    * @param input   Input stream
195    * @param det     Detector number
196    * @param ring    On return, the ring identifier 
197    * @param sec     On return, the sector number
198    * @param strbase On return, the strip base
199    * 
200    * @return negative value in case of problems, hardware address otherwise
201    */
202   Int_t NewChannel(AliAltroRawStreamV3& input, UShort_t det, Char_t&  ring, 
203                    UShort_t& sec, Short_t& strbase);
204
205   /** 
206    * Process a new timebin
207    * 
208    * @param input   Input stream
209    * @param i       Index into bunch data
210    * @param t       Time
211    * @param sec     Sector number
212    * @param strbase Base of strip numbers for this channel
213    * @param str     On return, the strip number
214    * @param samp    On return, the sample number
215    * 
216    * @return negative value in case of problems, ADC value otherwise
217    */  
218   Int_t NewSample(AliAltroRawStreamV3& input, Int_t i, UShort_t t, UShort_t sec,
219                   UShort_t  strbase, Short_t&  str, UShort_t& samp);
220
221   /** 
222    * 
223    * Get the number of words 
224    * 
225    * @return Number of 32bit words 
226    */
227   ULong_t GetNwords() const {return fNbytes / 4;}
228   /** 
229    * Get the next 32bit word from payload
230    * 
231    * @param idx Which 32bit word to get
232    * 
233    * @return 
234    */
235   UInt_t Get32bitWord(Int_t idx);
236   /** 
237    * Get short index for a given half-ring
238    * 
239    * @param det   Detector number
240    * @param ring  Ring identifer
241    * @param board Board number
242    * 
243    * @return 
244    */
245   Int_t GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board);
246   TTree*          fTree;            //! Pointer to tree to read into 
247   AliRawReader*   fReader;          //! Pointer to raw reader 
248   UShort_t        fSampleRate[3];   // The sample rate (if 0,inferred from data)
249   UChar_t*        fData;            // Data pointer
250   ULong_t         fNbytes;          // Number of bytes
251   Bool_t          fZeroSuppress[3]; // Zero suppression flag
252   UShort_t        fNoiseFactor[3];  // Noise factor 
253   UShort_t        fMinStrip;        // Current minimum strip number (0)
254   UShort_t        fMaxStrip;        // Current maximum strip number (127)
255   UShort_t        fPreSamp;         // Current number of pre-samples (14+5)
256   AliFMDUShortMap fSeen;
257   
258   ClassDef(AliFMDRawReader, 0) // Read FMD raw data into a cache 
259 };
260
261 #endif
262 //____________________________________________________________________
263 //
264 // Local Variables:
265 //   mode: C++
266 // End:
267 //
268 // EOF
269 //
270