1 #ifndef ALIFMDRAWREADER_H
2 #define ALIFMDRAWREADER_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights
6 * Latest changes by Christian Holm Christensen <cholm@nbi.dk>
8 * See cxx source for full Copyright notice
10 //____________________________________________________________________
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
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
24 #include <TClonesArray.h>
25 #include "AliFMDUShortMap.h"
27 //____________________________________________________________________
29 class AliAltroRawStreamV3;
33 class AliFMDCalibSampleRate;
34 class AliFMDCalibStripRange;
35 class AliFMDUShortMap;
37 //____________________________________________________________________
38 /** @brief Class to read ALTRO formated raw data from an AliRawReader
41 AliRawReader* reader = new AliRawReaderFile(0);
42 AliFMDRawReader* fmdReader = new AliFMDRawReader(reader);
43 TClonesArray* array = new TClonesArray("AliFMDDigit");
44 fmdReader->ReadAdcs(array);
48 class AliFMDRawReader : public TTask
51 /** Number of possible DDLs */
56 kBadSignal = 0x7FFF // Largest signed 16bit short integer
61 * @param reader Raw reader
62 * @param array Output tree
64 AliFMDRawReader(AliRawReader* reader, TTree* array);
68 virtual ~AliFMDRawReader() {}
69 void SetVerbose(Bool_t verb=kTRUE) { fVerbose = verb; }
71 * Read in, and store in output tree
73 * @param option Not used
75 virtual void Exec(Option_t* option="");
77 * Read ADC's into a TClonesArray of AliFMDDigit objects.
79 * @param array Array to read into
81 * @return @c true on success
83 virtual Bool_t ReadAdcs(TClonesArray* array);
85 * Read ADCs into a unsigned short map.
87 * @param map Map to read into
89 * @return true on success
91 virtual Bool_t ReadAdcs(AliFMDUShortMap& map);
93 * Read SOD event into passed objects.
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
100 * @return @c true on success
102 virtual Bool_t ReadSODevent(AliFMDCalibSampleRate* samplerate,
103 AliFMDCalibStripRange* striprange,
105 TArrayS &pulseLength,
106 Bool_t* detectors=0);
108 * Check of the data from DDL @a ddl is zero-suppressed
110 * @param ddl DDL number (0-2)
112 * @return @c true if the data from this DDL is zero-suppressed.
114 Bool_t IsZeroSuppressed(UShort_t ddl) const { return fZeroSuppress[ddl]; }
116 * The factor used to multiply the noise when making on-line
117 * pedestal subtraction.
119 * @param ddl DDL number (0-2)
121 * @return The factor used.
123 UShort_t NoiseFactor(UShort_t ddl) const { return fNoiseFactor[ddl]; }
126 * Get the next signal
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
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
146 Int_t NextSample(UShort_t& det, Char_t& rng, UShort_t& sec, UShort_t& str,
147 UShort_t& sam, UShort_t& rat, Short_t& adc,
148 Bool_t& zs, UShort_t& fac);
150 * Get the next signal
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
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
168 Int_t NextSignal(UShort_t& det, Char_t& rng,
169 UShort_t& sec, UShort_t& str,
170 Short_t& adc, Bool_t& zs,
173 * Get number of read-out errors. Note, that a channel marked as
174 * bad counts as 10 errors
176 * @param ddl DDL off set ([0,kNDDL-1])
178 * @return Number of seen errors
180 UShort_t GetNErrors(UShort_t ddl) const {return (ddl >= kNDDL ? 0 : fNErrors[ddl]);}
182 * Get the phase of the L1 signal
184 * @param ddl DDL number ([0,kNDDL-1])
186 * @return Phase of the L1 signal in steps of 25ns.
188 UShort_t GetL1Phase(UShort_t ddl) const {return (ddl >= kNDDL ? -1 : fL1Phase[ddl]);}
190 * Whether to keep a sample based on the rate used.
192 * @param samp Sample number
193 * @param rate Over sampling rate
195 * @return Whether to keep the sample or not
197 static Bool_t SelectSample(UShort_t samp, UShort_t rate);
202 * @param o Object to construct from
204 AliFMDRawReader(const AliFMDRawReader& o)
214 fVerbose(o.fVerbose),
216 fNErrChanLen(o.fNErrChanLen),
217 fNErrAddress(o.fNErrAddress)
220 * Assignment operator
222 * @return Reference to this object
224 AliFMDRawReader& operator=(const AliFMDRawReader&) { return *this; }
226 * Process a new DDL. Sets the internal data members fZeroSuppress,
227 * fSampleRate, and fNoiseFactor based on information in the RCU trailer.
229 * @param input Input stream
230 * @param det On return, the detector number
232 * @return negative value in case of problems, the DDL number otherwise
234 Int_t NewDDL(AliAltroRawStreamV3& input, UShort_t& det);
236 * Processs a new channel. Sets the internal data members
237 * fMinStrip, fMaxStrip, and fPreSamp.
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
245 * @return negative value in case of problems, hardware address otherwise
247 Int_t NewChannel(const AliAltroRawStreamV3& input,
248 UShort_t det, Char_t& ring,
249 UShort_t& sec, Short_t& strbase);
251 * Process a new bunch.
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
257 * @return true on success, false otherwise
259 Bool_t NewBunch(const AliAltroRawStreamV3& input,
260 UShort_t& start, UShort_t& length);
262 * Process a new timebin
264 * @param input Input stream
265 * @param i Index into bunch data
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
272 * @return negative value in case of problems, ADC value otherwise
274 Int_t NewSample(const AliAltroRawStreamV3& input,
275 Int_t i, UShort_t t, UShort_t sec,
276 UShort_t strbase, Short_t& str, UShort_t& samp);
280 * Get the number of words
282 * @return Number of 32bit words
284 ULong_t GetNwords() const {return fNbytes / 4;}
286 * Get the next 32bit word from payload
288 * @param idx Which 32bit word to get
292 UInt_t Get32bitWord(Int_t idx);
294 * Get short index for a given half-ring
296 * @param det Detector number
297 * @param ring Ring identifer
298 * @param board Board number
302 Int_t GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) const;
303 void AddError(Int_t ddl, Int_t hwaddr);
304 void ReadbackError(const AliAltroRawStreamV3& input, const char* format, ...);
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
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)
316 AliFMDUShortMap fSeen; // Seen strips
317 UShort_t fNErrors[kNDDL]; // Number of errors per DDL
318 UShort_t fL1Phase[kNDDL]; // Number of errors per DDL
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
324 ClassDef(AliFMDRawReader, 0) // Read FMD raw data into a cache
328 //____________________________________________________________________