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