]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDRawReader.cxx
Added the class AliFMDESDRevertexer for recalculating the
[u/mrichter/AliRoot.git] / FMD / AliFMDRawReader.cxx
CommitLineData
e802be3e 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
e802be3e 15/* $Id$ */
c2fc1258 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
02a27b50 20 @ingroup FMD_rec
c2fc1258 21*/
e802be3e 22//____________________________________________________________________
23//
24// Class to read ADC values from a AliRawReader object.
25//
7684b53c 26// This class uses the AliFMDRawStreamer class to read the ALTRO
27// formatted data.
28//
29// +-------+
30// | TTask |
31// +-------+
32// ^
33// |
34// +-----------------+ <<references>> +--------------+
35// | AliFMDRawReader |<>----------------| AliRawReader |
36// +-----------------+ +--------------+
37// | ^
38// | <<uses>> |
39// V |
40// +-----------------+ <<uses>> |
41// | AliFMDRawStream |------------------------+
42// +-----------------+
43// |
44// V
45// +----------------+
46// | AliAltroStream |
47// +----------------+
48//
f95a63c4 49// #include <AliLog.h> // ALILOG_H
50#include "AliFMDDebug.h" // Better debug macros
1a1fdef7 51#include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
e802be3e 52#include "AliFMDDigit.h" // ALIFMDDIGIT_H
53#include "AliFMDRawStream.h" // ALIFMDRAWSTREAM_H
3effc6e7 54#include "AliRawReader.h" // ALIRAWREADER_H
e802be3e 55#include "AliFMDRawReader.h" // ALIFMDRAWREADER_H
3effc6e7 56#include "AliFMDDebug.h"
57#include "AliFMDCalibSampleRate.h"
58#include "AliFMDCalibStripRange.h"
b995fc28 59#include "AliFMDAltroMapping.h"
c2fc1258 60// #include "AliFMDAltroIO.h" // ALIFMDALTROIO_H
3effc6e7 61#include <TArrayS.h> // ROOT_TArrayS
1a1fdef7 62#include <TTree.h> // ROOT_TTree
63#include <TClonesArray.h> // ROOT_TClonesArray
3effc6e7 64#include <TString.h>
7af3df7f 65#include <iostream>
66#include <climits>
02a27b50 67// #include <iomanip>
e802be3e 68
69//____________________________________________________________________
925e6570 70ClassImp(AliFMDRawReader)
1a1fdef7 71#if 0
72 ; // This is here to keep Emacs for indenting the next line
73#endif
e802be3e 74
75//____________________________________________________________________
1a1fdef7 76AliFMDRawReader::AliFMDRawReader(AliRawReader* reader, TTree* tree)
e802be3e 77 : TTask("FMDRawReader", "Reader of Raw ADC values from the FMD"),
1a1fdef7 78 fTree(tree),
79 fReader(reader),
3effc6e7 80 fSampleRate(1),
81 fData(0),
f38b1653 82 fNbytes(0),
83 fSeen()
e802be3e 84{
56b1929b 85 // Default CTOR
e802be3e 86}
87
c2fc1258 88//____________________________________________________________________
89void
90AliFMDRawReader::Exec(Option_t*)
91{
02a27b50 92 // Read the data
c2fc1258 93 TClonesArray* array = new TClonesArray("AliFMDDigit");
94 if (!fTree) {
95 AliError("No tree");
96 return;
97 }
98 fTree->Branch("FMD", &array);
3effc6e7 99
100
c2fc1258 101 ReadAdcs(array);
102 Int_t nWrite = fTree->Fill();
f95a63c4 103 AliFMDDebug(1, ("Got a grand total of %d digits, wrote %d bytes to tree",
bf37515f 104 array->GetEntriesFast(), nWrite));
c2fc1258 105}
106
107
108#if 1
109//____________________________________________________________________
110Bool_t
111AliFMDRawReader::ReadAdcs(TClonesArray* array)
112{
fd8d0298 113
114 fReader->Select("FMD");
c2fc1258 115 // Read raw data into the digits array, using AliFMDAltroReader.
116 if (!array) {
117 AliError("No TClonesArray passed");
118 return kFALSE;
119 }
f38b1653 120 const UShort_t kUShortMax = (1 << 16) - 1;
121 fSeen.Reset(kUShortMax);
122
d56f2b53 123 // if (!fReader->ReadHeader()) {
124 // AliError("Couldn't read header");
125 // return kFALSE;
126 // }
c2fc1258 127 // Get sample rate
b995fc28 128 AliFMDParameters* pars = AliFMDParameters::Instance();
129 AliFMDAltroMapping* map = pars->GetAltroMap();
130 AliFMDRawStream input(fReader);
9a090ccd 131 AliFMDDebug(5, ("Setting 7 word headers"));
625d7886 132 input.SetShortDataHeader(!pars->HasCompleteHeader());
c2fc1258 133
134 UShort_t stripMin = 0;
f38b1653 135 UShort_t stripMax = 0; // 127;
136 UShort_t preSamp = 0; // 14+5;
5cf05dbb 137
138 Int_t oldddl = -1;
c2fc1258 139 UInt_t ddl = 0;
140 UInt_t rate = 0;
141 UInt_t last = 0;
142 UInt_t hwaddr = 0;
143 // Data array is approx twice the size needed.
144 UShort_t data[2048];
5cf05dbb 145 for (size_t i = 0; i < 2048; i++) data[i] = 0; // kUShortMax;
2b893216 146
625d7886 147 Bool_t isGood = kTRUE;
148 while (isGood) {
149 isGood = input.ReadChannel(ddl, hwaddr, last, data);
7868d9e2 150 // if (!isGood) break;
7af3df7f 151 if (ddl >= UINT_MAX /* UInt_t(-1) */) {
fd8d0298 152 AliFMDDebug(5, ("At end of event with %d digits",
153 array->GetEntriesFast()));
154 break;
155 }
7af3df7f 156 if (UInt_t(oldddl) != ddl) {
5cf05dbb 157 fZeroSuppress[ddl] = input.GetZeroSupp();
158 AliFMDDebug(20, ("RCU @ DDL %d zero suppression: %s",
159 ddl, (fZeroSuppress[ddl] ? "yes" : "no")));
2b893216 160
5cf05dbb 161 // WARNING: We store the noise factor in the 2nd baseline
162 // filters excluded post samples, since we'll never use that
163 // mode.
164 fNoiseFactor[ddl] = input.GetNPostsamples();
165 AliFMDDebug(20, ("RCU @ DDL %d noise factor: %d", ddl,fNoiseFactor[ddl]));
166
167 Int_t nChAddrMismatch = input.GetNChAddrMismatch();
168 Int_t nChLenMismatch = input.GetNChLengthMismatch();
169 if (nChAddrMismatch != 0)
170 AliWarning(Form("Got %d channels with address mis-matches for 0x%03x",
171 nChAddrMismatch, hwaddr));
172 if (nChLenMismatch != 0)
173 AliWarning(Form("Got %d channels with length mis-matches for 0x%03x",
174 nChLenMismatch, hwaddr));
175 oldddl = ddl;
176 }
177 // AliFMDDebug(5, ("Read channel 0x%x of size %d", hwaddr, last));
f38b1653 178
b995fc28 179 UShort_t det, sec, samp, board, chip, channel;
1f12303f 180 Short_t strbase;
181 Char_t ring;
fd8d0298 182
b995fc28 183
184 if (map->DDL2Detector(ddl) < 0) break;
185 det = map->DDL2Detector(ddl);
186 map->ChannelAddress(hwaddr, board, chip, channel);
187 if (!map->Channel2StripBase(board, chip, channel, ring, sec, strbase)) {
1f12303f 188 AliError(Form("Failed to get detector id from DDL %d, "
189 "hardware address 0x%03x", ddl, hwaddr));
190 continue;
191 }
7af3df7f 192 AliFMDDebug(1, ("Board: 0x%02x, Altro: 0x%x, Channel: 0x%x, Length: %4d",
193 board, chip, channel, last));
1f12303f 194
195 stripMin = pars->GetMinStrip(det, ring, sec, strbase);
196 stripMax = pars->GetMaxStrip(det, ring, sec, strbase);
197 preSamp = pars->GetPreSamples(det, ring, sec, strbase);
5cf05dbb 198 // WARNING: We use the number of pre-samples to store the
199 // oversampling rate in.
200 rate = input.GetNPretriggerSamples();
201 if (rate == 0) rate = pars->GetSampleRate(det, ring, sec, strbase);
c2fc1258 202
203 // Loop over the `timebins', and make the digits
204 for (size_t i = 0; i < last; i++) {
f38b1653 205 // if (i < preSamp) continue;
5cf05dbb 206 AliFMDDebug(15, ("0x%04x/0x%03x/%04d %4d", ddl, hwaddr, i, data[i]));
f38b1653 207
b995fc28 208 Short_t stroff = 0;
209 map->Timebin2Strip(sec, i, preSamp, rate, stroff, samp);
210 Short_t str = strbase + stroff;
1f12303f 211
212 AliFMDDebug(10, ("0x%04x/0x%03x/%04d maps to FMD%d%c[%2d,%3d]-%d",
213 ddl, hwaddr, i, det, ring, sec, str, samp));
f38b1653 214 if (str < 0) {
215 AliFMDDebug(8, ("Got presamples at timebin %d", i));
5cf05dbb 216 data[i] = 0; // Reset cache
f38b1653 217 continue;
218 }
219
f38b1653 220 Short_t lstrip = (i - preSamp) / rate + stripMin;
221
222 AliFMDDebug(15, ("Checking if strip %d (%d) in range [%d,%d]",
223 lstrip, str, stripMin, stripMax));
224 if (lstrip < stripMin || lstrip > stripMax) {
225 AliFMDDebug(5, ("FMD%d%c[%02d,%03d]-%d out of range (%3d->%3d)",
226 det, ring, sec, samp, str, stripMin, stripMax));
5cf05dbb 227 data[i] = 0; // Reset cache
f38b1653 228 continue;
229 }
230
231 // Check the cache of indicies
232 Int_t idx = fSeen(det, ring, sec, str);
233 if (idx == kUShortMax) {
234 // We haven't seen this strip yet.
235 fSeen(det, ring, sec, str) = idx = array->GetEntriesFast();
236 AliFMDDebug(7,("making digit for FMD%d%c[%2d,%3d]-%d from timebin %4d",
237 det, ring, sec, str, samp, i));
238 new ((*array)[idx]) AliFMDDigit(det, ring, sec, str);
239 }
240 AliFMDDigit* digit = static_cast<AliFMDDigit*>(array->At(idx));
241 AliFMDDebug(10,
242 ("Setting from FMD%d%c[%2d,%3d]-%d from timebin %4d = %4d",
243 det, ring, sec, str, samp, i, data[i]));
244 digit->SetCount(samp, data[i]);
5cf05dbb 245 data[i] = 0; // Reset cache
c2fc1258 246 }
247 }
248 return kTRUE;
249}
250#else
1e8f773e 251//____________________________________________________________________
d760ea03 252Bool_t
253AliFMDRawReader::ReadAdcs(TClonesArray* array)
1e8f773e 254{
255 // Read raw data into the digits array, using AliFMDAltroReader.
d760ea03 256 if (!array) {
257 AliError("No TClonesArray passed");
258 return kFALSE;
259 }
d56f2b53 260 // if (!fReader->ReadHeader()) {
261 // AliError("Couldn't read header");
262 // return kFALSE;
263 // }
1e8f773e 264 // Get sample rate
265 AliFMDParameters* pars = AliFMDParameters::Instance();
266
267 // Select FMD DDL's
362c9d61 268 fReader->Select("FMD");
1e8f773e 269
270 UShort_t stripMin = 0;
271 UShort_t stripMax = 127;
272 UShort_t preSamp = 0;
273
274 do {
275 UChar_t* cdata;
276 if (!fReader->ReadNextData(cdata)) break;
277 size_t nchar = fReader->GetDataSize();
362c9d61 278 UShort_t ddl = fReader->GetDDLID();
c2fc1258 279 UShort_t rate = 0;
f95a63c4 280 AliFMDDebug(1, ("Reading %d bytes (%d 10bit words) from %d",
1e8f773e 281 nchar, nchar * 8 / 10, ddl));
282 // Make a stream to read from
283 std::string str((char*)(cdata), nchar);
284 std::istringstream s(str);
285 // Prep the reader class.
286 AliFMDAltroReader r(s);
287 // Data array is approx twice the size needed.
288 UShort_t data[2048], hwaddr, last;
289 while (r.ReadChannel(hwaddr, last, data) > 0) {
f95a63c4 290 AliFMDDebug(5, ("Read channel 0x%x of size %d", hwaddr, last));
1e8f773e 291 UShort_t det, sec, str;
292 Char_t ring;
293 if (!pars->Hardware2Detector(ddl, hwaddr, det, ring, sec, str)) {
294 AliError(Form("Failed to detector id from DDL %d "
295 "and hardware address 0x%x", ddl, hwaddr));
296 continue;
297 }
c2fc1258 298 rate = pars->GetSampleRate(det, ring, sec, str);
299 stripMin = pars->GetMinStrip(det, ring, sec, str);
300 stripMax = pars->GetMaxStrip(det, ring, sec, str);
f95a63c4 301 AliFMDDebug(5, ("DDL 0x%04x, address 0x%03x maps to FMD%d%c[%2d,%3d]",
1e8f773e 302 ddl, hwaddr, det, ring, sec, str));
303
304 // Loop over the `timebins', and make the digits
305 for (size_t i = 0; i < last; i++) {
306 if (i < preSamp) continue;
d760ea03 307 Int_t n = array->GetEntries();
1e8f773e 308 UShort_t curStr = str + stripMin + i / rate;
309 if ((curStr-str) > stripMax) {
310 AliError(Form("Current strip is %d but DB says max is %d",
311 curStr, stripMax));
312 }
f95a63c4 313 AliFMDDebug(5, ("making digit for FMD%d%c[%2d,%3d] from sample %4d",
1e8f773e 314 det, ring, sec, curStr, i));
315 new ((*array)[n]) AliFMDDigit(det, ring, sec, curStr, data[i],
316 (rate >= 2 ? data[i+1] : 0),
317 (rate >= 3 ? data[i+2] : 0));
318 if (rate >= 2) i++;
319 if (rate >= 3) i++;
320 }
321 if (r.IsBof()) break;
322 }
323 } while (true);
d760ea03 324 return kTRUE;
325}
326
327
328
1e8f773e 329// This is the old method, for comparison. It's really ugly, and far
330// too convoluted.
e802be3e 331//____________________________________________________________________
332void
333AliFMDRawReader::Exec(Option_t*)
334{
56b1929b 335 // Read raw data into the digits array
d56f2b53 336 // if (!fReader->ReadHeader()) {
337 // Error("ReadAdcs", "Couldn't read header");
338 // return;
339 // }
e802be3e 340
1a1fdef7 341 Int_t n = 0;
342 TClonesArray* array = new TClonesArray("AliFMDDigit");
343 fTree->Branch("FMD", &array);
344
8f6ee336 345 // Get sample rate
346 AliFMDParameters* pars = AliFMDParameters::Instance();
362c9d61 347 fSampleRate = pars->GetSampleRate(0);
8f6ee336 348
e802be3e 349 // Use AliAltroRawStream to read the ALTRO format. No need to
350 // reinvent the wheel :-)
351 AliFMDRawStream input(fReader, fSampleRate);
352 // Select FMD DDL's
362c9d61 353 fReader->Select("FMD");
e802be3e 354
355 Int_t oldDDL = -1;
356 Int_t count = 0;
357 UShort_t detector = 1; // Must be one here
358 UShort_t oldDetector = 0;
359 Bool_t next = kTRUE;
360
361 // local Cache
362 TArrayI counts(10);
363 counts.Reset(-1);
364
365 // Loop over data in file
366 while (next) {
367 next = input.Next();
368
369 count++;
370 Int_t ddl = fReader->GetDDLID();
f95a63c4 371 AliFMDDebug(10, ("Current DDL is %d", ddl));
e802be3e 372 if (ddl != oldDDL || input.IsNewStrip() || !next) {
373 // Make a new digit, if we have some data (oldDetector == 0,
374 // means that we haven't really read anything yet - that is,
375 // it's the first time we get here).
376 if (oldDetector > 0) {
377 // Got a new strip.
f95a63c4 378 AliFMDDebug(10, ("Add a new strip: FMD%d%c[%2d,%3d] "
e802be3e 379 "(current: FMD%d%c[%2d,%3d])",
380 oldDetector, input.PrevRing(),
381 input.PrevSector() , input.PrevStrip(),
382 detector , input.Ring(), input.Sector(),
383 input.Strip()));
1a1fdef7 384 new ((*array)[n]) AliFMDDigit(oldDetector,
385 input.PrevRing(),
386 input.PrevSector(),
387 input.PrevStrip(),
388 counts[0], counts[1], counts[2]);
389 n++;
e802be3e 390#if 0
391 AliFMDDigit* digit =
392 static_cast<AliFMDDigit*>(fFMD->Digits()->
393 UncheckedAt(fFMD->GetNdigits()-1));
394#endif
395 }
396
397 if (!next) {
f95a63c4 398 AliFMDDebug(10, ("Read %d channels for FMD%d",
e802be3e 399 count + 1, detector));
400 break;
401 }
402
403
404 // If we got a new DDL, it means we have a new detector.
405 if (ddl != oldDDL) {
406 if (detector != 0)
f95a63c4 407 AliFMDDebug(10, ("Read %d channels for FMD%d", count + 1, detector));
e802be3e 408 // Reset counts, and update the DDL cache
409 count = 0;
410 oldDDL = ddl;
411 // Check that we're processing a FMD detector
412 Int_t detId = fReader->GetDetectorID();
362c9d61 413 if (detId != (AliDAQ::DetectorID("FMD"))) {
1e8f773e 414 AliError(Form("Detector ID %d != %d",
362c9d61 415 detId, (AliDAQ::DetectorID("FMD"))));
e802be3e 416 break;
417 }
418 // Figure out what detector we're deling with
419 oldDetector = detector;
420 switch (ddl) {
421 case 0: detector = 1; break;
422 case 1: detector = 2; break;
423 case 2: detector = 3; break;
424 default:
1e8f773e 425 AliError(Form("Unknown DDL 0x%x for FMD", ddl));
e802be3e 426 return;
427 }
f95a63c4 428 AliFMDDebug(10, ("Reading ADCs for 0x%x - That is FMD%d",
e802be3e 429 fReader->GetEquipmentId(), detector));
430 }
431 counts.Reset(-1);
432 }
433
434 counts[input.Sample()] = input.Count();
435
f95a63c4 436 AliFMDDebug(10, ("ADC of FMD%d%c[%2d,%3d] += %d",
e802be3e 437 detector, input.Ring(), input.Sector(),
438 input.Strip(), input.Count()));
439 oldDetector = detector;
440 }
1a1fdef7 441 fTree->Fill();
e802be3e 442 return;
443
444}
1e8f773e 445#endif
3effc6e7 446//____________________________________________________________________
447Bool_t AliFMDRawReader::ReadSODevent(AliFMDCalibSampleRate* sampleRate,
448 AliFMDCalibStripRange* stripRange,
449 TArrayS &pulseSize,
f38b1653 450 TArrayS &pulseLength)
451{
3effc6e7 452
453 AliFMDDebug(0, ("Start of SOD/EOD"));
454
455 UInt_t shift_clk[18];
456 UInt_t sample_clk[18];
457 UInt_t strip_low[18];
458 UInt_t strip_high[18];
459 UInt_t pulse_size[18];
460 UInt_t pulse_length[18];
b995fc28 461 AliFMDParameters* param = AliFMDParameters::Instance();
462 AliFMDAltroMapping* map = param->GetAltroMap();
3effc6e7 463
464 while(fReader->ReadNextData(fData)) {
465
466 Int_t ddl = fReader->GetDDLID();
467 Int_t detID = fReader->GetDetectorID();
468 AliFMDDebug(0, (" From reader: DDL number is %d , det ID is %d",ddl,detID));
469
470 fNbytes = fReader->GetDataSize();
471
472 ULong_t nWords = GetNwords();
473 UInt_t trailerLast = Get32bitWord(nWords);
474 AliFMDDebug(20, (" # Bytes: %d, # Words: %d, Last word: 0x%08x",
f38b1653 475 fNbytes, nWords, trailerLast));
3effc6e7 476 if ((trailerLast & 0xFFFF0000) != 0xAAAA0000) {
477 AliWarning(Form("Last word 0x%08x does not match RCU II trailer",
478 trailerLast));
479 return kFALSE;
480 }
481
f38b1653 482 // 7 last bits is size of trailer
483 ULong_t nTrailerWords = trailerLast & 0x7f;
3effc6e7 484 ULong_t nPayloadWords = Get32bitWord(nWords - nTrailerWords+1);
f38b1653 485
3effc6e7 486 AliFMDDebug(20, (" # trailer words: %d, # payload words: %d",
f38b1653 487 nTrailerWords, nPayloadWords));
3effc6e7 488
489
490 for (ULong_t i = 1; i <= nPayloadWords ; i++) {
491 UInt_t payloadWord = Get32bitWord(i);
76d06ffa 492
f38b1653 493 // address is only 24 bit
494 UInt_t address = (0xffffff & payloadWord);
495 UInt_t type = ((address >> 21) & 0xf);
496 UInt_t error = ((address >> 20) & 0x1);
497 UInt_t bcast = ((address >> 18) & 0x1);
498 UInt_t bc_not_altro = ((address >> 17) & 0x1);
499 UInt_t board = ((address >> 12) & 0x1f);
500 UInt_t instruction = 0;
501 UInt_t chip = 0;
502 UInt_t channel = 0;
503 if(bc_not_altro)
504 instruction = address & 0xfff;
505 else {
506 chip = ((address >> 9) & 0x7);
507 channel = ((address >> 5) & 0x5);
508 instruction = (address & 0x1f);
509 }
76d06ffa 510
f38b1653 511 Bool_t readDataWord = kFALSE;
512 switch(type) {
513 case 0x0: // Fec read
514 readDataWord = kTRUE;
515 case 0x1: // Fec cmd
516 case 0x2: // Fec write
517 i++;
518 break;
519 case 0x4: // Loop
520 case 0x5: // Wait
521 break;
522 case 0x6: // End sequence
523 case 0x7: // End Mem
524 i = nPayloadWords + 1;
525 break;
526 default:
527 break;
528 }
76d06ffa 529
f38b1653 530 //Don't read unless we have a FEC_RD
531 if(!readDataWord) continue;
532
533 UInt_t dataWord = Get32bitWord(i);
534 UInt_t data = (0xFFFFF & dataWord) ;
535 //UInt_t data = (0xFFFF & dataWord) ;
3effc6e7 536
f38b1653 537 if(error) {
538 AliWarning(Form("error bit detected at Word 0x%06x; "
539 "error % d, type %d, bc_not_altro %d, "
540 "bcast %d, board 0x%02x, chip 0x%x, "
541 "channel 0x%02x, instruction 0x%03x",
542 address, error, type, bc_not_altro,
543 bcast,board,chip,channel,instruction));
544 //process error
545 continue;
546 }
3effc6e7 547
548
f38b1653 549 switch(instruction) {
3effc6e7 550
f38b1653 551 case 0x01: break; // First ADC T
552 case 0x02: break; // I 3.3 V
553 case 0x03: break; // I 2.5 V altro digital
554 case 0x04: break; // I 2.5 V altro analog
555 case 0x05: break; // I 2.5 V VA
556 case 0x06: break; // First ADC T
557 case 0x07: break; // I 3.3 V
558 case 0x08: break; // I 2.5 V altro digital
559 case 0x09: break; // I 2.5 V altro analog
560 case 0x0A: break; // I 2.5 V VA
561 case 0x2D: break; // Second ADC T
562 case 0x2E: break; // I 1.5 V VA
563 case 0x2F: break; // I -2.0 V
564 case 0x30: break; // I -2.0 V VA
565 case 0x31: break; // 2.5 V Digital driver
566 case 0x32: break; // Second ADC T
567 case 0x33: break; // I 1.5 V VA
568 case 0x34: break; // I -2.0 V
569 case 0x35: break; // I -2.0 V VA
570 case 0x36: break; // 2.5 V Digital driver
571 case 0x37: break; // Third ADC T
572 case 0x38: break; // Temperature sens. 1
573 case 0x39: break; // Temperature sens. 2
574 case 0x3A: break; // U 2.5 altro digital (m)
575 case 0x3B: break; // U 2.5 altro analog (m)
576 case 0x3C: break; // Third ADC T
577 case 0x3D: break; // Temperature sens. 1
578 case 0x3E: break; // Temperature sens. 2
579 case 0x3F: break; // U 2.5 altro digital (m)
580 case 0x40: break; // U 2.5 altro analog (m)
581 case 0x41: break; // Forth ADC T
582 case 0x42: break; // U 2.5 VA (m)
583 case 0x43: break; // U 1.5 VA (m)
584 case 0x44: break; // U -2.0 VA (m)
585 case 0x45: break; // U -2.0 (m)
586 case 0x46: break; // Forth ADC T
587 case 0x47: break; // U 2.5 VA (m)
588 case 0x48: break; // U 1.5 VA (m)
589 case 0x49: break; // U -2.0 VA (m)
590 case 0x4A: break; // U -2.0 (m)
591 // Counters
592 case 0x0B: break; // L1 trigger CouNTer
593 case 0x0C: break; // L2 trigger CouNTer
594 case 0x0D: break; // Sampling CLK CouNTer
595 case 0x0E: break; // DSTB CouNTer
596 // Test mode
597 case 0x0F: break; // Test mode word
598 case 0x10: break; // Undersampling ratio.
599 // Configuration and status
600 case 0x11: break; // Config/Status Register 0
601 case 0x12: break; // Config/Status Register 1
602 case 0x13: break; // Config/Status Register 2
603 case 0x14: break; // Config/Status Register 3
604 case 0x15: break; // Free
605 // Comands:
606 case 0x16: break; // Latch L1, L2, SCLK Counters
607 case 0x17: break; // Clear counters
608 case 0x18: break; // Clear CSR1
609 case 0x19: break; // rstb ALTROs
610 case 0x1A: break; // rstb BC
611 case 0x1B: break; // Start conversion
612 case 0x1C: break; // Scan event length
613 case 0x1D: break; // Read event length
614 case 0x1E: break; // Start test mode
615 case 0x1F: break; // Read acquisition memory
616 // FMD
617 case 0x20: break; // FMDD status
618 case 0x21: break; // L0 counters
619 case 0x22: break; // FMD: Wait to hold
620 case 0x23: break; // FMD: L1 timeout
621 case 0x24: break; // FMD: L2 timeout
622 case 0x25: // FMD: Shift clk
623 shift_clk[board] = ((data >> 8 ) & 0xFF);
624 break;
625 case 0x26: // FMD: Strips
626 strip_low[board] = ((data >> 0 ) & 0xFF);
627 strip_high[board] = ((data >> 8 ) & 0xFF);
628 break;
629 case 0x27: // FMD: Cal pulse
630 pulse_size[board] = ((data >> 8 ) & 0xFF);
631 break;
632 case 0x28: break; // FMD: Shape bias
633 case 0x29: break; // FMD: Shape ref
634 case 0x2A: break; // FMD: Preamp ref
635 case 0x2B: // FMD: Sample clk
636 sample_clk[board] = ((data >> 8 ) & 0xFF);
637 break;
638 case 0x2C: break; // FMD: Commands
639 case 0x4B: // FMD: Cal events
640 pulse_length[board] = ((data >> 0 ) & 0xFF);
641 break;
642 default: break;
3effc6e7 643
f38b1653 644 }
645 AliFMDDebug(50, ("instruction 0x%x, dataword 0x%x",
646 instruction,dataWord));
3effc6e7 647 }
648
f38b1653 649 UShort_t det,sector;
650 Short_t strip;
3effc6e7 651 Char_t ring;
76d06ffa 652
3effc6e7 653 const UInt_t boards[4] = {0,1,16,17};
654 for(Int_t i=0;i<4;i++) {
f38b1653 655 if(ddl==0 && (i==1 || i==3)) continue;
656
3effc6e7 657 UInt_t chip =0, channel=0;
b995fc28 658 det = map->DDL2Detector(ddl);
659 map->Channel2StripBase(boards[i], chip, channel, ring, sector, strip);
76d06ffa 660
661 UInt_t samplerate = 1;
76d06ffa 662 if(sample_clk[boards[i]] == 0) {
f38b1653 663 if(ddl == 0) {
664 Int_t sample1 = sample_clk[boards[0]];
665 Int_t sample2 = sample_clk[boards[2]];
666 if(sample1) sample_clk[boards[i]] = sample1;
667 else sample_clk[boards[i]] = sample2;
668 }
669 else {
670 Int_t sample1 = sample_clk[boards[0]];
671 Int_t sample2 = sample_clk[boards[1]];
672 Int_t sample3 = sample_clk[boards[2]];
673 Int_t sample4 = sample_clk[boards[3]];
674 Int_t agreement = 0;
675 if(sample1 == sample2) agreement++;
676 if(sample1 == sample3) agreement++;
677 if(sample1 == sample4) agreement++;
678 if(sample2 == sample3) agreement++;
679 if(sample2 == sample4) agreement++;
680 if(sample3 == sample4) agreement++;
76d06ffa 681
f38b1653 682 Int_t idx = 0;
683 if(i<3) idx = i+1;
684 else idx = i-1;
685 if(agreement == 3) {
686 sample_clk[boards[i]] = sample_clk[boards[idx]];
687 shift_clk[boards[i]] = shift_clk[boards[idx]];
688 strip_low[boards[i]] = strip_low[boards[idx]];
689 strip_high[boards[i]] = strip_high[boards[idx]];
690 pulse_length[boards[i]] = pulse_length[boards[idx]];
691 pulse_size[boards[i]] = pulse_size[boards[idx]];
692 AliFMDDebug(0, ("Vote taken for ddl %d, board 0x%x",
693 ddl,boards[i]));
76d06ffa 694 }
f38b1653 695 }
76d06ffa 696 }
697
3effc6e7 698 if(sample_clk[boards[i]])
f38b1653 699 samplerate = shift_clk[boards[i]]/sample_clk[boards[i]];
3effc6e7 700 sampleRate->Set(det,ring,sector,0,samplerate);
f38b1653 701 stripRange->Set(det,ring,sector,0,
702 strip_low[boards[i]],strip_high[boards[i]]);
3effc6e7 703
76d06ffa 704 AliFMDDebug(20, ("det %d, ring %c, ",det,ring));
f38b1653 705 pulseLength.AddAt(pulse_length[boards[i]],
706 GetHalfringIndex(det,ring,boards[i]/16));
707 pulseSize.AddAt(pulse_size[boards[i]],
708 GetHalfringIndex(det,ring,boards[i]/16));
76d06ffa 709
3effc6e7 710
76d06ffa 711
712 AliFMDDebug(20, (": Board: 0x%02x\n"
f38b1653 713 "\tstrip_low %3d, strip_high %3d\n"
714 "\tshift_clk %3d, sample_clk %3d\n"
715 "\tpulse_size %3d, pulse_length %3d",
716 boards[i],
717 strip_low[boards[i]], strip_high[boards[i]],
718 shift_clk[boards[i]], sample_clk[boards[i]],
719 pulse_size[boards[i]],pulse_length[boards[i]]));
3effc6e7 720 }
721
722 }
723
724 AliFMDParameters::Instance()->SetSampleRate(sampleRate);
725 AliFMDParameters::Instance()->SetStripRange(stripRange);
726
727 AliFMDDebug(0, ("End of SOD/EOD"));
728
7af3df7f 729 return kTRUE;
3effc6e7 730}
731//____________________________________________________________________
732
733UInt_t AliFMDRawReader::Get32bitWord(Int_t idx)
734{
735 // This method returns the 32 bit word at a given
736 // position inside the raw data payload.
737 // The 'index' points to the beginning of the next word.
738 // The method is supposed to be endian (platform)
739 // independent.
740 if (!fData) {
741 AliFatal("Raw data paylod buffer is not yet initialized !");
742 }
743
744 Int_t index = 4*idx;
745
746 if (index < 4) {
747 // fRawReader->AddFatalErrorLog(k32bitWordReadErr,Form("pos = %d",index));
748 // PrintDebug();
749 AliWarning(Form("Invalid raw data payload position (%d) !",index));
750 }
751
752 UInt_t word = 0;
76d06ffa 753
3effc6e7 754 word = fData[--index] << 24;
755 word |= fData[--index] << 16;
756 word |= fData[--index] << 8;
757 word |= fData[--index] << 0 ;
e802be3e 758
3effc6e7 759 return word;
760}
761//_____________________________________________________________________
f38b1653 762Int_t AliFMDRawReader::GetHalfringIndex(UShort_t det, Char_t ring,
763 UShort_t board) {
3effc6e7 764
765 UShort_t iring = (ring == 'I' ? 1 : 0);
766
767 Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
768
76d06ffa 769 return index-2;
3effc6e7 770
771}
e802be3e 772//____________________________________________________________________
773//
774// EOF
775//