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
26 #include "AliFMDUShortMap.h"
28 //____________________________________________________________________
30 class AliAltroRawStreamV3;
34 class AliFMDCalibSampleRate;
35 class AliFMDCalibStripRange;
36 class AliFMDUShortMap;
38 //____________________________________________________________________
39 /** @brief Class to read ALTRO formated raw data from an AliRawReader
42 AliRawReader* reader = new AliRawReaderFile(0);
43 AliFMDRawReader* fmdReader = new AliFMDRawReader(reader);
44 TClonesArray* array = new TClonesArray("AliFMDDigit");
45 fmdReader->ReadAdcs(array);
49 class AliFMDRawReader : public TTask
52 /** Number of possible DDLs */
57 kBadSignal = 0x7FFF // Largest signed 16bit short integer
62 * @param reader Raw reader
63 * @param array Output tree
65 AliFMDRawReader(AliRawReader* reader, TTree* array);
69 virtual ~AliFMDRawReader() {}
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)
216 * Assignment operator
218 * @return Reference to this object
220 AliFMDRawReader& operator=(const AliFMDRawReader&) { return *this; }
222 * Process a new DDL. Sets the internal data members fZeroSuppress,
223 * fSampleRate, and fNoiseFactor based on information in the RCU trailer.
225 * @param input Input stream
226 * @param det On return, the detector number
228 * @return negative value in case of problems, the DDL number otherwise
230 Int_t NewDDL(AliAltroRawStreamV3& input, UShort_t& det);
232 * Processs a new channel. Sets the internal data members
233 * fMinStrip, fMaxStrip, and fPreSamp.
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
241 * @return negative value in case of problems, hardware address otherwise
243 Int_t NewChannel(const AliAltroRawStreamV3& input,
244 UShort_t det, Char_t& ring,
245 UShort_t& sec, Short_t& strbase);
247 * Process a new bunch.
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
253 * @return true on success, false otherwise
255 Bool_t NewBunch(const AliAltroRawStreamV3& input,
256 UShort_t& start, UShort_t& length);
258 * Process a new timebin
260 * @param input Input stream
261 * @param i Index into bunch data
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
268 * @return negative value in case of problems, ADC value otherwise
270 Int_t NewSample(const AliAltroRawStreamV3& input,
271 Int_t i, UShort_t t, UShort_t sec,
272 UShort_t strbase, Short_t& str, UShort_t& samp);
276 * Get the number of words
278 * @return Number of 32bit words
280 ULong_t GetNwords() const {return fNbytes / 4;}
282 * Get the next 32bit word from payload
284 * @param idx Which 32bit word to get
288 UInt_t Get32bitWord(Int_t idx);
290 * Get short index for a given half-ring
292 * @param det Detector number
293 * @param ring Ring identifer
294 * @param board Board number
298 Int_t GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) const;
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
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)
309 AliFMDUShortMap fSeen; // Seen strips
310 UShort_t fNErrors[kNDDL]; // Number of errors per DDL
311 UShort_t fL1Phase[kNDDL]; // Number of errors per DDL
313 ClassDef(AliFMDRawReader, 0) // Read FMD raw data into a cache
317 //____________________________________________________________________