Suppressed secondary decision ased in reco-time set kMultSec flag (Anton)
[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*/
e802be3e 23#ifndef ROOT_TTask
24# include <TTask.h>
25#endif
f38b1653 26#include "AliFMDUShortMap.h"
e802be3e 27
28//____________________________________________________________________
29class AliRawReader;
e2c858f2 30class AliAltroRawStreamV3;
1a1fdef7 31class TTree;
d760ea03 32class TClonesArray;
3effc6e7 33class TArrayS;
34class AliFMDCalibSampleRate;
35class AliFMDCalibStripRange;
f4b75c28 36class AliFMDUShortMap;
e802be3e 37
38//____________________________________________________________________
9f662337 39/** @brief Class to read ALTRO formated raw data from an AliRawReader
40 object.
41 @code
42 AliRawReader* reader = new AliRawReaderFile(0);
43 AliFMDRawReader* fmdReader = new AliFMDRawReader(reader);
44 TClonesArray* array = new TClonesArray("AliFMDDigit");
45 fmdReader->ReadAdcs(array);
46 @endcode
47 @ingroup FMD_rec
48*/
e802be3e 49class AliFMDRawReader : public TTask
50{
51public:
f4b75c28 52 /** Number of possible DDLs */
53 enum {
54 kNDDL = 3
55 };
56 enum {
57 kBadSignal = 0x7FFF // Largest signed 16bit short integer
58 };
faf80567 59 /**
60 * CTOR
61 *
62 * @param reader Raw reader
63 * @param array Output tree
64 */
1a1fdef7 65 AliFMDRawReader(AliRawReader* reader, TTree* array);
faf80567 66 /**
67 * DTOR
68 */
088f8e79 69 virtual ~AliFMDRawReader() {}
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);
5cf05dbb 84 /**
f4b75c28 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);
92 /**
5cf05dbb 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),
60e95d46 213 fSeen(0)
b5ee4425 214 {}
e2c858f2 215 /**
216 * Assignment operator
217 *
218 * @return Reference to this object
219 */
02a27b50 220 AliFMDRawReader& operator=(const AliFMDRawReader&) { return *this; }
e2c858f2 221 /**
222 * Process a new DDL. Sets the internal data members fZeroSuppress,
223 * fSampleRate, and fNoiseFactor based on information in the RCU trailer.
224 *
225 * @param input Input stream
226 * @param det On return, the detector number
227 *
228 * @return negative value in case of problems, the DDL number otherwise
229 */
230 Int_t NewDDL(AliAltroRawStreamV3& input, UShort_t& det);
231 /**
232 * Processs a new channel. Sets the internal data members
233 * fMinStrip, fMaxStrip, and fPreSamp.
234 *
235 * @param input Input stream
236 * @param det Detector number
237 * @param ring On return, the ring identifier
238 * @param sec On return, the sector number
239 * @param strbase On return, the strip base
240 *
241 * @return negative value in case of problems, hardware address otherwise
242 */
09b6c804 243 Int_t NewChannel(const AliAltroRawStreamV3& input,
244 UShort_t det, Char_t& ring,
e2c858f2 245 UShort_t& sec, Short_t& strbase);
f4b75c28 246 /**
247 * Process a new bunch.
248 *
249 * @param input Input stream
250 * @param start On input, the old start time. On return, the start time
251 * @param length On return, the bunch length
252 *
253 * @return true on success, false otherwise
254 */
255 Bool_t NewBunch(const AliAltroRawStreamV3& input,
256 UShort_t& start, UShort_t& length);
e2c858f2 257 /**
258 * Process a new timebin
259 *
260 * @param input Input stream
261 * @param i Index into bunch data
262 * @param t Time
263 * @param sec Sector number
264 * @param strbase Base of strip numbers for this channel
265 * @param str On return, the strip number
266 * @param samp On return, the sample number
267 *
268 * @return negative value in case of problems, ADC value otherwise
269 */
09b6c804 270 Int_t NewSample(const AliAltroRawStreamV3& input,
271 Int_t i, UShort_t t, UShort_t sec,
e2c858f2 272 UShort_t strbase, Short_t& str, UShort_t& samp);
273
274 /**
275 *
276 * Get the number of words
277 *
278 * @return Number of 32bit words
279 */
3effc6e7 280 ULong_t GetNwords() const {return fNbytes / 4;}
e2c858f2 281 /**
282 * Get the next 32bit word from payload
283 *
284 * @param idx Which 32bit word to get
285 *
286 * @return
287 */
3effc6e7 288 UInt_t Get32bitWord(Int_t idx);
e2c858f2 289 /**
290 * Get short index for a given half-ring
291 *
292 * @param det Detector number
293 * @param ring Ring identifer
294 * @param board Board number
295 *
296 * @return
297 */
09b6c804 298 Int_t GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) const;
f4b75c28 299 TTree* fTree; //! Pointer to tree to read into
300 AliRawReader* fReader; //! Pointer to raw reader
301 UShort_t fSampleRate[kNDDL];// The sample rate (if 0,infer from data)
302 UChar_t* fData; // Data pointer
303 ULong_t fNbytes; // Number of bytes
304 Bool_t fZeroSuppress[kNDDL]; // Zero suppression flag
305 UShort_t fNoiseFactor[kNDDL]; // Noise factor
e2c858f2 306 UShort_t fMinStrip; // Current minimum strip number (0)
307 UShort_t fMaxStrip; // Current maximum strip number (127)
308 UShort_t fPreSamp; // Current number of pre-samples (14+5)
09b6c804 309 AliFMDUShortMap fSeen; // Seen strips
f4b75c28 310 UShort_t fNErrors[kNDDL]; // Number of errors per DDL
311 UShort_t fL1Phase[kNDDL]; // Number of errors per DDL
3effc6e7 312
e802be3e 313 ClassDef(AliFMDRawReader, 0) // Read FMD raw data into a cache
314};
315
316#endif
317//____________________________________________________________________
318//
319// Local Variables:
320// mode: C++
321// End:
322//
323// EOF
324//
6c652449 325