1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 /** @file AliFMDRawReader.cxx
17 @author Christian Holm Christensen <cholm@nbi.dk>
18 @date Mon Mar 27 12:45:23 2006
19 @brief Class to read raw data
22 //____________________________________________________________________
24 // Class to read ADC values from a AliRawReader object.
26 // This class uses the AliFMDRawStreamer class to read the ALTRO
34 // +-----------------+ <<references>> +--------------+
35 // | AliFMDRawReader |<>----------------| AliRawReader |
36 // +-----------------+ +--------------+
40 // +-----------------+ <<uses>> |
41 // | AliFMDRawStream |------------------------+
42 // +-----------------+
49 // #include <AliLog.h> // ALILOG_H
50 #include "AliFMDDebug.h" // Better debug macros
51 #include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
52 #include "AliFMDDigit.h" // ALIFMDDIGIT_H
53 #include "AliFMDRawStream.h" // ALIFMDRAWSTREAM_H
54 // #include "AliRawReader.h" // ALIRAWREADER_H
55 #include "AliFMDRawReader.h" // ALIFMDRAWREADER_H
56 // #include "AliFMDAltroIO.h" // ALIFMDALTROIO_H
57 // #include <TArrayI.h> // ROOT_TArrayI
58 #include <TTree.h> // ROOT_TTree
59 #include <TClonesArray.h> // ROOT_TClonesArray
60 // #include <iostream>
63 //____________________________________________________________________
64 ClassImp(AliFMDRawReader)
66 ; // This is here to keep Emacs for indenting the next line
69 //____________________________________________________________________
70 AliFMDRawReader::AliFMDRawReader(AliRawReader* reader, TTree* tree)
71 : TTask("FMDRawReader", "Reader of Raw ADC values from the FMD"),
79 //____________________________________________________________________
81 AliFMDRawReader::Exec(Option_t*)
84 TClonesArray* array = new TClonesArray("AliFMDDigit");
89 fTree->Branch("FMD", &array);
91 Int_t nWrite = fTree->Fill();
92 AliFMDDebug(1, ("Got a grand total of %d digits, wrote %d bytes to tree",
93 array->GetEntries(), nWrite));
98 //____________________________________________________________________
100 AliFMDRawReader::ReadAdcs(TClonesArray* array)
102 // Read raw data into the digits array, using AliFMDAltroReader.
104 AliError("No TClonesArray passed");
107 // if (!fReader->ReadHeader()) {
108 // AliError("Couldn't read header");
112 AliFMDParameters* pars = AliFMDParameters::Instance();
113 AliFMDRawStream input(fReader);
115 UShort_t stripMin = 0;
116 UShort_t stripMax = 127;
117 UShort_t preSamp = 0;
123 // Data array is approx twice the size needed.
126 while (input.ReadChannel(ddl, hwaddr, last, data)) {
128 AliFMDDebug(5, ("Read channel 0x%x of size %d", hwaddr, last));
129 UShort_t det, sec, str;
131 if (!pars->Hardware2Detector(ddl, hwaddr, det, ring, sec, str)) {
132 AliError(Form("Failed to get detector id from DDL %d "
133 "and hardware address 0x%x", ddl, hwaddr));
136 rate = pars->GetSampleRate(det, ring, sec, str);
137 stripMin = pars->GetMinStrip(det, ring, sec, str);
138 stripMax = pars->GetMaxStrip(det, ring, sec, str);
139 AliFMDDebug(5, ("DDL 0x%04x, address 0x%03x maps to FMD%d%c[%2d,%3d]",
140 ddl, hwaddr, det, ring, sec, str));
142 // Loop over the `timebins', and make the digits
143 for (size_t i = 0; i < last; i++) {
144 if (i < preSamp) continue;
145 Int_t n = array->GetEntriesFast();
146 UShort_t curStr = str + stripMin + i / rate;
147 if ((curStr-str) > stripMax) {
148 AliError(Form("Current strip is %d but DB says max is %d",
151 AliFMDDebug(5, ("making digit for FMD%d%c[%2d,%3d] from sample %4d",
152 det, ring, sec, curStr, i));
153 new ((*array)[n]) AliFMDDigit(det, ring, sec, curStr, data[i],
154 (rate >= 2 ? data[i+1] : 0),
155 (rate >= 3 ? data[i+2] : 0),
156 (rate >= 4 ? data[i+3] : 0));
165 //____________________________________________________________________
167 AliFMDRawReader::ReadAdcs(TClonesArray* array)
169 // Read raw data into the digits array, using AliFMDAltroReader.
171 AliError("No TClonesArray passed");
174 // if (!fReader->ReadHeader()) {
175 // AliError("Couldn't read header");
179 AliFMDParameters* pars = AliFMDParameters::Instance();
182 fReader->Select("FMD");
184 UShort_t stripMin = 0;
185 UShort_t stripMax = 127;
186 UShort_t preSamp = 0;
190 if (!fReader->ReadNextData(cdata)) break;
191 size_t nchar = fReader->GetDataSize();
192 UShort_t ddl = fReader->GetDDLID();
194 AliFMDDebug(1, ("Reading %d bytes (%d 10bit words) from %d",
195 nchar, nchar * 8 / 10, ddl));
196 // Make a stream to read from
197 std::string str((char*)(cdata), nchar);
198 std::istringstream s(str);
199 // Prep the reader class.
200 AliFMDAltroReader r(s);
201 // Data array is approx twice the size needed.
202 UShort_t data[2048], hwaddr, last;
203 while (r.ReadChannel(hwaddr, last, data) > 0) {
204 AliFMDDebug(5, ("Read channel 0x%x of size %d", hwaddr, last));
205 UShort_t det, sec, str;
207 if (!pars->Hardware2Detector(ddl, hwaddr, det, ring, sec, str)) {
208 AliError(Form("Failed to detector id from DDL %d "
209 "and hardware address 0x%x", ddl, hwaddr));
212 rate = pars->GetSampleRate(det, ring, sec, str);
213 stripMin = pars->GetMinStrip(det, ring, sec, str);
214 stripMax = pars->GetMaxStrip(det, ring, sec, str);
215 AliFMDDebug(5, ("DDL 0x%04x, address 0x%03x maps to FMD%d%c[%2d,%3d]",
216 ddl, hwaddr, det, ring, sec, str));
218 // Loop over the `timebins', and make the digits
219 for (size_t i = 0; i < last; i++) {
220 if (i < preSamp) continue;
221 Int_t n = array->GetEntries();
222 UShort_t curStr = str + stripMin + i / rate;
223 if ((curStr-str) > stripMax) {
224 AliError(Form("Current strip is %d but DB says max is %d",
227 AliFMDDebug(5, ("making digit for FMD%d%c[%2d,%3d] from sample %4d",
228 det, ring, sec, curStr, i));
229 new ((*array)[n]) AliFMDDigit(det, ring, sec, curStr, data[i],
230 (rate >= 2 ? data[i+1] : 0),
231 (rate >= 3 ? data[i+2] : 0));
235 if (r.IsBof()) break;
243 // This is the old method, for comparison. It's really ugly, and far
245 //____________________________________________________________________
247 AliFMDRawReader::Exec(Option_t*)
249 // Read raw data into the digits array
250 // if (!fReader->ReadHeader()) {
251 // Error("ReadAdcs", "Couldn't read header");
256 TClonesArray* array = new TClonesArray("AliFMDDigit");
257 fTree->Branch("FMD", &array);
260 AliFMDParameters* pars = AliFMDParameters::Instance();
261 fSampleRate = pars->GetSampleRate(0);
263 // Use AliAltroRawStream to read the ALTRO format. No need to
264 // reinvent the wheel :-)
265 AliFMDRawStream input(fReader, fSampleRate);
267 fReader->Select("FMD");
271 UShort_t detector = 1; // Must be one here
272 UShort_t oldDetector = 0;
279 // Loop over data in file
284 Int_t ddl = fReader->GetDDLID();
285 AliFMDDebug(10, ("Current DDL is %d", ddl));
286 if (ddl != oldDDL || input.IsNewStrip() || !next) {
287 // Make a new digit, if we have some data (oldDetector == 0,
288 // means that we haven't really read anything yet - that is,
289 // it's the first time we get here).
290 if (oldDetector > 0) {
292 AliFMDDebug(10, ("Add a new strip: FMD%d%c[%2d,%3d] "
293 "(current: FMD%d%c[%2d,%3d])",
294 oldDetector, input.PrevRing(),
295 input.PrevSector() , input.PrevStrip(),
296 detector , input.Ring(), input.Sector(),
298 new ((*array)[n]) AliFMDDigit(oldDetector,
302 counts[0], counts[1], counts[2]);
306 static_cast<AliFMDDigit*>(fFMD->Digits()->
307 UncheckedAt(fFMD->GetNdigits()-1));
312 AliFMDDebug(10, ("Read %d channels for FMD%d",
313 count + 1, detector));
318 // If we got a new DDL, it means we have a new detector.
321 AliFMDDebug(10, ("Read %d channels for FMD%d", count + 1, detector));
322 // Reset counts, and update the DDL cache
325 // Check that we're processing a FMD detector
326 Int_t detId = fReader->GetDetectorID();
327 if (detId != (AliDAQ::DetectorID("FMD"))) {
328 AliError(Form("Detector ID %d != %d",
329 detId, (AliDAQ::DetectorID("FMD"))));
332 // Figure out what detector we're deling with
333 oldDetector = detector;
335 case 0: detector = 1; break;
336 case 1: detector = 2; break;
337 case 2: detector = 3; break;
339 AliError(Form("Unknown DDL 0x%x for FMD", ddl));
342 AliFMDDebug(10, ("Reading ADCs for 0x%x - That is FMD%d",
343 fReader->GetEquipmentId(), detector));
348 counts[input.Sample()] = input.Count();
350 AliFMDDebug(10, ("ADC of FMD%d%c[%2d,%3d] += %d",
351 detector, input.Ring(), input.Sector(),
352 input.Strip(), input.Count()));
353 oldDetector = detector;
361 //____________________________________________________________________