]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDRawReader.h
ALIROOT-5420 ALIROOT-5683 Fixes in CheckData to take into account the possibility...
[u/mrichter/AliRoot.git] / FMD / AliFMDRawReader.h
CommitLineData
e802be3e 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 */
e802be3e 10//____________________________________________________________________
11//
12// Class to read ADC values from a AliRawReader object.
088f8e79 13// Note, that it uses an ALTRO reader, which is wrong.
14// Perhaps we need to implement it our selves
e802be3e 15//
02a27b50 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*/
8c79980b 23#include <TTask.h>
24#include <TClonesArray.h>
f38b1653 25#include "AliFMDUShortMap.h"
e802be3e 26
27//____________________________________________________________________
28class AliRawReader;
e2c858f2 29class AliAltroRawStreamV3;
1a1fdef7 30class TTree;
d760ea03 31class TClonesArray;
3effc6e7 32class TArrayS;
33class AliFMDCalibSampleRate;
34class AliFMDCalibStripRange;
f4b75c28 35class AliFMDUShortMap;
e802be3e 36
37//____________________________________________________________________
9f662337 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*/
e802be3e 48class AliFMDRawReader : public TTask
49{
50public:
f4b75c28 51 /** Number of possible DDLs */
52 enum {
53 kNDDL = 3
54 };
55 enum {
56 kBadSignal = 0x7FFF // Largest signed 16bit short integer
57 };
faf80567 58 /**
59 * CTOR
60 *
61 * @param reader Raw reader
62 * @param array Output tree
63 */
1a1fdef7 64 AliFMDRawReader(AliRawReader* reader, TTree* array);
faf80567 65 /**
66 * DTOR
67 */
088f8e79 68 virtual ~AliFMDRawReader() {}
8c79980b 69 void SetVerbose(Bool_t verb=kTRUE) { fVerbose = verb; }
faf80567 70 /**
71 * Read in, and store in output tree
72 *
73 * @param option Not used
74 */
d760ea03 75 virtual void Exec(Option_t* option="");
faf80567 76 /**
77 * Read ADC's into a TClonesArray of AliFMDDigit objects.
78 *
79 * @param array Array to read into
faf80567 80 *
81 * @return @c true on success
82 */
d760ea03 83 virtual Bool_t ReadAdcs(TClonesArray* array);
f4b75c28 84 /**
85 * Read ADCs into a unsigned short map.
86 *
87 * @param map Map to read into
88 *
89 * @return true on success
90 */
91 virtual Bool_t ReadAdcs(AliFMDUShortMap& map);
5cf05dbb 92 /**
93 * Read SOD event into passed objects.
94 *
95 * @param samplerate The sample rate object to fill
96 * @param striprange The strip range object to fill
97 * @param pulseSize The pulse size object to fill
98 * @param pulseLength The pulse length (in events) object to fill
99 *
100 * @return @c true on success
101 */
3effc6e7 102 virtual Bool_t ReadSODevent(AliFMDCalibSampleRate* samplerate,
103 AliFMDCalibStripRange* striprange,
104 TArrayS &pulseSize,
408bf2b4 105 TArrayS &pulseLength,
106 Bool_t* detectors=0);
5cf05dbb 107 /**
108 * Check of the data from DDL @a ddl is zero-suppressed
109 *
110 * @param ddl DDL number (0-2)
111 *
112 * @return @c true if the data from this DDL is zero-suppressed.
113 */
114 Bool_t IsZeroSuppressed(UShort_t ddl) const { return fZeroSuppress[ddl]; }
115 /**
116 * The factor used to multiply the noise when making on-line
117 * pedestal subtraction.
118 *
119 * @param ddl DDL number (0-2)
120 *
121 * @return The factor used.
122 */
123 UShort_t NoiseFactor(UShort_t ddl) const { return fNoiseFactor[ddl]; }
124
faf80567 125 /**
126 * Get the next signal
127 *
128 * @param det On return, the detector
129 * @param rng On return, the ring
130 * @param sec On return, the sector
131 * @param str On return, the strip
132 * @param sam On return, the sample
133 * @param rat On return, the sample rate
134 * @param adc On return, the ADC value
135 * @param zs On return, whether zero-supp. is enabled
136 * @param fac On return, the usd noise factor
137 *
f4b75c28 138 * @return 0 if there's no more data. -1 if the read sample
139 * corresponds to a bad bunch in the channel. Positive return
140 * values represent a bit mask of
141 * - 0x1 New DDL
142 * - 0x2 New Channel
143 * - 0x4 New Bunch
144 * - 0x8 New Sample
faf80567 145 */
f4b75c28 146 Int_t NextSample(UShort_t& det, Char_t& rng, UShort_t& sec, UShort_t& str,
faf80567 147 UShort_t& sam, UShort_t& rat, Short_t& adc,
148 Bool_t& zs, UShort_t& fac);
149 /**
150 * Get the next signal
151 *
152 * @param det On return, the detector
153 * @param rng On return, the ring
154 * @param sec On return, the sector
155 * @param str On return, the strip
156 * @param adc On return, the ADC value
157 * @param zs On return, whether zero-supp. is enabled
158 * @param fac On return, the usd noise factor
159 *
f4b75c28 160 * @return 0 if there's no more data. -1 if the read sample
161 * corresponds to a bad bunch in the channel. Positive return
162 * values represent a bit mask of
163 * - 0x1 New DDL
164 * - 0x2 New Channel
165 * - 0x4 New Bunch
166 * - 0x8 New Sample
faf80567 167 */
f4b75c28 168 Int_t NextSignal(UShort_t& det, Char_t& rng,
169 UShort_t& sec, UShort_t& str,
170 Short_t& adc, Bool_t& zs,
171 UShort_t& fac);
172 /**
173 * Get number of read-out errors. Note, that a channel marked as
174 * bad counts as 10 errors
175 *
176 * @param ddl DDL off set ([0,kNDDL-1])
177 *
178 * @return Number of seen errors
179 */
180 UShort_t GetNErrors(UShort_t ddl) const {return (ddl >= kNDDL ? 0 : fNErrors[ddl]);}
181 /**
182 * Get the phase of the L1 signal
183 *
184 * @param ddl DDL number ([0,kNDDL-1])
185 *
186 * @return Phase of the L1 signal in steps of 25ns.
187 */
188 UShort_t GetL1Phase(UShort_t ddl) const {return (ddl >= kNDDL ? -1 : fL1Phase[ddl]);}
faf80567 189 /**
190 * Whether to keep a sample based on the rate used.
191 *
192 * @param samp Sample number
193 * @param rate Over sampling rate
194 *
195 * @return Whether to keep the sample or not
196 */
197 static Bool_t SelectSample(UShort_t samp, UShort_t rate);
e802be3e 198protected:
e2c858f2 199 /**
200 * Copy constructor
201 *
202 * @param o Object to construct from
203 */
b5ee4425 204 AliFMDRawReader(const AliFMDRawReader& o)
205 : TTask(o),
206 fTree(0),
207 fReader(0),
3effc6e7 208 fData(0),
f38b1653 209 fNbytes(0),
e2c858f2 210 fMinStrip(0),
211 fMaxStrip(127),
212 fPreSamp(14+5),
8c79980b 213 fSeen(0),
214 fVerbose(o.fVerbose),
215 fErrors(o.fErrors),
216 fNErrChanLen(o.fNErrChanLen),
217 fNErrAddress(o.fNErrAddress)
b5ee4425 218 {}
e2c858f2 219 /**
220 * Assignment operator
221 *
222 * @return Reference to this object
223 */
02a27b50 224 AliFMDRawReader& operator=(const AliFMDRawReader&) { return *this; }
e2c858f2 225 /**
226 * Process a new DDL. Sets the internal data members fZeroSuppress,
227 * fSampleRate, and fNoiseFactor based on information in the RCU trailer.
228 *
229 * @param input Input stream
230 * @param det On return, the detector number
231 *
232 * @return negative value in case of problems, the DDL number otherwise
233 */
234 Int_t NewDDL(AliAltroRawStreamV3& input, UShort_t& det);
235 /**
236 * Processs a new channel. Sets the internal data members
237 * fMinStrip, fMaxStrip, and fPreSamp.
238 *
239 * @param input Input stream
240 * @param det Detector number
241 * @param ring On return, the ring identifier
242 * @param sec On return, the sector number
243 * @param strbase On return, the strip base
244 *
245 * @return negative value in case of problems, hardware address otherwise
246 */
09b6c804 247 Int_t NewChannel(const AliAltroRawStreamV3& input,
248 UShort_t det, Char_t& ring,
e2c858f2 249 UShort_t& sec, Short_t& strbase);
f4b75c28 250 /**
251 * Process a new bunch.
252 *
253 * @param input Input stream
254 * @param start On input, the old start time. On return, the start time
255 * @param length On return, the bunch length
256 *
257 * @return true on success, false otherwise
258 */
259 Bool_t NewBunch(const AliAltroRawStreamV3& input,
260 UShort_t& start, UShort_t& length);
e2c858f2 261 /**
262 * Process a new timebin
263 *
264 * @param input Input stream
265 * @param i Index into bunch data
266 * @param t Time
267 * @param sec Sector number
268 * @param strbase Base of strip numbers for this channel
269 * @param str On return, the strip number
270 * @param samp On return, the sample number
271 *
272 * @return negative value in case of problems, ADC value otherwise
273 */
09b6c804 274 Int_t NewSample(const AliAltroRawStreamV3& input,
275 Int_t i, UShort_t t, UShort_t sec,
e2c858f2 276 UShort_t strbase, Short_t& str, UShort_t& samp);
277
278 /**
279 *
280 * Get the number of words
281 *
282 * @return Number of 32bit words
283 */
3effc6e7 284 ULong_t GetNwords() const {return fNbytes / 4;}
e2c858f2 285 /**
286 * Get the next 32bit word from payload
287 *
288 * @param idx Which 32bit word to get
289 *
290 * @return
291 */
3effc6e7 292 UInt_t Get32bitWord(Int_t idx);
e2c858f2 293 /**
294 * Get short index for a given half-ring
295 *
296 * @param det Detector number
297 * @param ring Ring identifer
298 * @param board Board number
299 *
300 * @return
301 */
09b6c804 302 Int_t GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) const;
8c79980b 303 void AddError(Int_t ddl, Int_t hwaddr);
304 void ReadbackError(const AliAltroRawStreamV3& input, const char* format, ...);
305
f4b75c28 306 TTree* fTree; //! Pointer to tree to read into
307 AliRawReader* fReader; //! Pointer to raw reader
308 UShort_t fSampleRate[kNDDL];// The sample rate (if 0,infer from data)
309 UChar_t* fData; // Data pointer
310 ULong_t fNbytes; // Number of bytes
311 Bool_t fZeroSuppress[kNDDL]; // Zero suppression flag
312 UShort_t fNoiseFactor[kNDDL]; // Noise factor
e2c858f2 313 UShort_t fMinStrip; // Current minimum strip number (0)
314 UShort_t fMaxStrip; // Current maximum strip number (127)
315 UShort_t fPreSamp; // Current number of pre-samples (14+5)
09b6c804 316 AliFMDUShortMap fSeen; // Seen strips
f4b75c28 317 UShort_t fNErrors[kNDDL]; // Number of errors per DDL
318 UShort_t fL1Phase[kNDDL]; // Number of errors per DDL
8c79980b 319 Bool_t fVerbose; // Whether to be verbose
320 TClonesArray fErrors; // Clones array of channels with errors
321 UShort_t fNErrChanLen; // Number of channel length errors
322 UShort_t fNErrAddress; // Number of address errors
3effc6e7 323
e802be3e 324 ClassDef(AliFMDRawReader, 0) // Read FMD raw data into a cache
325};
326
327#endif
328//____________________________________________________________________
329//
330// Local Variables:
331// mode: C++
332// End:
333//
334// EOF
335//
6c652449 336