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