]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDRawReader.cxx
changes to include AliPerformanceMach component (Michael Knichel)
[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
faf80567 53#include "AliFMDSDigit.h" // ALIFMDSDIGIT_H
e2c858f2 54// #include "AliFMDRawStream.h" // ALIFMDRAWSTREAM_H
3effc6e7 55#include "AliRawReader.h" // ALIRAWREADER_H
e802be3e 56#include "AliFMDRawReader.h" // ALIFMDRAWREADER_H
3effc6e7 57#include "AliFMDDebug.h"
58#include "AliFMDCalibSampleRate.h"
59#include "AliFMDCalibStripRange.h"
b995fc28 60#include "AliFMDAltroMapping.h"
c2fc1258 61// #include "AliFMDAltroIO.h" // ALIFMDALTROIO_H
e2c858f2 62#include "AliAltroRawStreamV3.h"
3effc6e7 63#include <TArrayS.h> // ROOT_TArrayS
1a1fdef7 64#include <TTree.h> // ROOT_TTree
65#include <TClonesArray.h> // ROOT_TClonesArray
3effc6e7 66#include <TString.h>
7af3df7f 67#include <iostream>
68#include <climits>
02a27b50 69// #include <iomanip>
e802be3e 70
71//____________________________________________________________________
925e6570 72ClassImp(AliFMDRawReader)
1a1fdef7 73#if 0
74 ; // This is here to keep Emacs for indenting the next line
75#endif
e802be3e 76
77//____________________________________________________________________
1a1fdef7 78AliFMDRawReader::AliFMDRawReader(AliRawReader* reader, TTree* tree)
e802be3e 79 : TTask("FMDRawReader", "Reader of Raw ADC values from the FMD"),
1a1fdef7 80 fTree(tree),
81 fReader(reader),
faf80567 82 // fSampleRate(1),
3effc6e7 83 fData(0),
f38b1653 84 fNbytes(0),
e2c858f2 85 fMinStrip(0),
86 fMaxStrip(127),
87 fPreSamp(14+5),
60e95d46 88 fSeen(0)
e802be3e 89{
56b1929b 90 // Default CTOR
faf80567 91 for (Int_t i = 0; i < 3; i++) {
92 fSampleRate[i] = 0;
93 fZeroSuppress[i] = kFALSE;
94 fNoiseFactor[i] = 1;
95 }
e802be3e 96}
97
c2fc1258 98//____________________________________________________________________
99void
100AliFMDRawReader::Exec(Option_t*)
101{
02a27b50 102 // Read the data
c2fc1258 103 TClonesArray* array = new TClonesArray("AliFMDDigit");
104 if (!fTree) {
105 AliError("No tree");
106 return;
107 }
108 fTree->Branch("FMD", &array);
3effc6e7 109
110
c2fc1258 111 ReadAdcs(array);
112 Int_t nWrite = fTree->Fill();
f95a63c4 113 AliFMDDebug(1, ("Got a grand total of %d digits, wrote %d bytes to tree",
bf37515f 114 array->GetEntriesFast(), nWrite));
3915b9ac 115 delete array;
c2fc1258 116}
117
e2c858f2 118//____________________________________________________________________
119Int_t
120AliFMDRawReader::NewDDL(AliAltroRawStreamV3& input, UShort_t& det)
121{
122 // Process a new DDL. Sets the internal data members fZeroSuppress,
123 // fSampleRate, and fNoiseFactor based on information in the RCU trailer.
124 //
125 // Parameters:
126 // input Input stream
127 // det On return, the detector number
128 //
129 // Return value:
130 // negative value in case of problems, the DDL number otherwise
131
132 // Get the DDL number
133 UInt_t ddl = input.GetDDLNumber();
134 AliFMDDebug(2, ("DDL number %d", ddl));
135
3afd9281 136 /* Note, previously, the ALTROCFG1 register was interpreted as
137 *
138 * Bits Value Description
139 * 0- 3 0/1 1st Baseline filter, mode
140 * 4- 5 Over-1 2nd baseline filter, # of pre-samples
141 * 6- 9 factor 2nd baseline filter, # of post-samples
142 * 10- 0 2nd baseline filter, enable
143 * 11-12 00 Zero suppression, glitch filter mode
144 * 13-15 001 Zero suppression, # of post samples
145 * 16-17 01 Zero suppression, # of pre samples
146 * 18 0/1 Zero suppression, enable
147 *
148 * The interpretation used in AliAltroRawStreamerV3 - which
149 * corresponds directly to ALTRO DPCFG register - is
150 *
151 * Bits Value Description
152 * 0- 3 0/1 1st Baseline filter, mode
153 * 4 0 Polarity (if '1', then "1's inverse")
154 * 5- 6 01 Zero suppression, # of pre samples
155 * 7-10 0001 Zero suppression, # of post samples
156 * 11 0 2nd baseline filter, enable
157 * 12-13 00 Zero suppression, glitch filter mode
158 * 14-16 factor 2nd baseline filter, # of post-samples
159 * 17-18 01 2nd baseline filter, # of pre-samples
160 * 19 0/1 Zero suppression, enable
161 *
162 * Writing 'x' for variable values, that means we have the
163 * following patterns for the 2 cases
164 *
165 * bit # 20 16 12 8 4 0
166 * old |0x01|0010|00xx|xxxx|xxxx|
167 * new |x01x|xx00|0000|1010|xxxx|
168 *
169 * That means that we can check if bits 10-13 are '1000' or
170 * '0000', which will tell us if the value was written with the
171 * new or the old interpretation. That is, we can check that
172 *
173 * if (((altrocfg1 >> 10) & 0x8) == 0x8) {
174 * // old interpretation
175 * }
176 * else {
177 * // New interpretation
178 * }
179 *
180 * That means, that we should never
181 *
182 * - change the # of zero suppression post samples
183 * - Turn on 2nd baseline correction
184 * - Change the zero-suppression glitch filter mode
185 *
186 * This change as introduced in version 1.2 of Rcu++
187 */
188 UInt_t cfg1 = input.GetAltroCFG1();
189 if (((cfg1 >> 10) & 0x8) == 0x8) {
190 UInt_t cfg2 = input.GetAltroCFG2();
4b25407d 191 AliFMDDebug(3, ("We have data from older MiniConf 0x%x cfg2=0x%08x",
192 ((cfg1 >> 10) & 0x8), cfg2));
193 fZeroSuppress[ddl] = (cfg1 >> 0) & 0x1;
194 fNoiseFactor[ddl] = (cfg1 >> 6) & 0xF;
195 fSampleRate[ddl] = (cfg2 >> 20) & 0xF;
3afd9281 196 }
197 else {
4b25407d 198 AliFMDDebug(3, ("We have data from newer MiniConf 0x%x",
199 ((cfg1 >> 10) & 0x8)));
3afd9281 200 fZeroSuppress[ddl] = input.GetZeroSupp();
201 // WARNING: We store the noise factor in the 2nd baseline
202 // filters excluded post samples, since we'll never use that
203 // mode.
204 fNoiseFactor[ddl] = input.GetNPostsamples();
205 // WARNING: We store the sample rate in the number of pre-trigger
206 // samples, since we'll never use that mode.
207 fSampleRate[ddl] = input.GetNPretriggerSamples();
208 }
e2c858f2 209 AliFMDDebug(3, ("RCU @ DDL %d zero suppression: %s",
210 ddl, (fZeroSuppress[ddl] ? "yes" : "no")));
3afd9281 211 AliFMDDebug(3, ("RCU @ DDL %d noise factor: %d", ddl,fNoiseFactor[ddl]));
e2c858f2 212 AliFMDDebug(3, ("RCU @ DDL %d sample rate: %d", ddl,fSampleRate[ddl]));
213
3afd9281 214
e2c858f2 215 // Get Errors seen
216 Int_t nChAddrMismatch = input.GetNChAddrMismatch();
217 Int_t nChLenMismatch = input.GetNChLengthMismatch();
218 if (nChAddrMismatch != 0)
219 AliWarning(Form("Got %d channels with address mis-matches for 0x%03x",
220 nChAddrMismatch, ddl));
221 if (nChLenMismatch != 0)
222 AliWarning(Form("Got %d channels with length mis-matches for 0x%03x",
223 nChLenMismatch, ddl));
224
225 // Map DDL number to the detector number
226 AliFMDParameters* pars = AliFMDParameters::Instance();
227 AliFMDAltroMapping* map = pars->GetAltroMap();
228 if (map->DDL2Detector(ddl) < 0) return -1;
229 det = map->DDL2Detector(ddl);
230
231 if (AliLog::GetDebugLevel("FMD", 0) > 5)
232 input.PrintRCUTrailer();
233 return ddl;
234}
235
236//____________________________________________________________________
237Int_t
238AliFMDRawReader::NewChannel(AliAltroRawStreamV3& input, UShort_t det,
239 Char_t& ring, UShort_t& sec, Short_t& strbase)
240{
241 // Processs a new channel. Sets the internal data members
242 // fMinStrip, fMaxStrip, and fPreSamp.
243 //
244 // Parameter:
245 // input Input stream
246 // ring On return, the ring identifier
247 // sec On return, the sector number
248 // strbase On return, the strip base
249 //
250 // Return value
251 // negative value in case of problems, hardware address otherwise
252
253 // Get the hardware address, and map that to detector coordinates
254 UShort_t board, chip, channel;
255 Int_t ddl = input.GetDDLNumber();
256 Int_t hwaddr = input.GetHWAddress();
257 if (input.IsChannelBad()) {
258 AliError(Form("Channel 0x%03x is marked as bad!", hwaddr));
259 }
260
261 AliFMDParameters* pars = AliFMDParameters::Instance();
262 AliFMDAltroMapping* map = pars->GetAltroMap();
263 // Map to hardware stuff
264 map->ChannelAddress(hwaddr, board, chip, channel);
265 // Then try to map to detector address
266 if (!map->Channel2StripBase(board, chip, channel, ring, sec, strbase)) {
267 AliError(Form("Failed to get detector id from DDL %d, "
268 "hardware address 0x%03x", ddl, hwaddr));
269 return -1;
270 }
4b25407d 271 AliFMDDebug(4, ("Board: 0x%02x, Altro: 0x%x, Channel: 0x%x",
e2c858f2 272 board, chip, channel));
273
274 // Get the 'conditions'
275 fMinStrip = pars->GetMinStrip(det, ring, sec, strbase);
276 fMaxStrip = pars->GetMaxStrip(det, ring, sec, strbase);
277 fPreSamp = pars->GetPreSamples(det, ring, sec, strbase);
278 if (fSampleRate[ddl] == 0)
279 fSampleRate[ddl] = pars->GetSampleRate(det, ring, sec, strbase);
280
281 return hwaddr;
282}
283
284//____________________________________________________________________
285Int_t
286AliFMDRawReader::NewSample(AliAltroRawStreamV3& input,
287 Int_t i, UShort_t t, UShort_t sec,
288 UShort_t strbase, Short_t& str, UShort_t& samp)
289{
290 // Process a new timebin
291 //
292 // Parameters:
293 // input Input stream
294 // i Index into bunch data
295 // t Time
296 // strbase Base of strip numbers for this channel
297 // str On return, the strip number
298 // samp On return, the sample number
299 //
300 // Return value
301 // negative value in case of problems, ADC value otherwise
302 if (t < fPreSamp) return -1;
303
304 Int_t ddl = input.GetDDLNumber();
305 Int_t hwa = input.GetHWAddress();
306 const UShort_t* data = input.GetSignals();
307 Short_t adc = data[i];
308 AliFMDDebug(10, ("0x%04x/0x%03x/%04d %4d", ddl, hwa, t, adc));
309
310 AliFMDParameters* pars = AliFMDParameters::Instance();
311 AliFMDAltroMapping* map = pars->GetAltroMap();
312
313 samp = 0;
314 Short_t stroff = 0;
315 map->Timebin2Strip(sec, t, fPreSamp, fSampleRate[ddl], stroff, samp);
316 str = strbase + stroff;
317
86878381 318 AliFMDDebug(20, ("0x%04x/0x%03x/%04d=%4d maps to strip %3d sample %d "
e2c858f2 319 "(pre: %d, min: %d, max: %d, rate: %d)",
86878381 320 ddl, hwa, t, adc, str, samp, fPreSamp,
e2c858f2 321 fMinStrip, fMaxStrip, fSampleRate[ddl]));
322 if (str < 0) {
323 AliFMDDebug(10, ("Got presamples at timebin %d", i));
324 return -1;
325 }
326
327 // VA1 Local strip number
328 Short_t lstrip = (t - fPreSamp) / fSampleRate[ddl] + fMinStrip;
329
330 AliFMDDebug(15, ("Checking if strip %d (%d) in range [%d,%d]",
331 lstrip, str, fMinStrip, fMaxStrip));
332 if (lstrip < fMinStrip || lstrip > fMaxStrip) {
86878381 333 AliFMDDebug(10, ("Strip %03d-%d (%d,%d) from t=%d out of range (%3d->%3d)",
e2c858f2 334 str, samp, lstrip, stroff, t, fMinStrip, fMaxStrip));
86878381 335 adc = -1;
e2c858f2 336 }
337 // Possibly do pedestal subtraction of signal
338 if (adc > 1023)
339 AliWarning(Form("ADC value out of range: %4d", adc));
340 return adc;
341}
342
b5014544 343//____________________________________________________________________
344Bool_t
faf80567 345AliFMDRawReader::NextSample(UShort_t& det, Char_t& rng, UShort_t& sec,
346 UShort_t& str, UShort_t& sam, UShort_t& rat,
347 Short_t& adc, Bool_t& zs, UShort_t& fac)
b5014544 348{
349 // Scan current event for next signal. It returns kFALSE when
350 // there's no more data in the event.
e2c858f2 351 static AliAltroRawStreamV3 stream(fReader); // = 0;
b5014544 352 static Int_t ddl = -1;
b5014544 353 static UShort_t tdet = 0;
354 static Char_t trng = '\0';
355 static UShort_t tsec = 0;
356 static Short_t tstr = 0;
357 static Short_t bstr = -1;
e2c858f2 358 static UShort_t tsam = 0;
faf80567 359 static UInt_t trate = 0;
b5014544 360 static Int_t hwaddr = -1;
e2c858f2 361 static UShort_t start = 0;
362 static UShort_t length = 0;
363 static Short_t t = -1;
364 static Int_t i = 0;
365 // First entry!
b5014544 366 if (stream.GetDDLNumber() < 0) {
367 fReader->Select("FMD");
368
b5014544 369 // Reset variables
370 ddl = -1;
faf80567 371 trate = 0;
b5014544 372 tdet = 0;
373 trng = '\0';
374 tsec = 0;
375 tstr = 0;
faf80567 376 tsam = -1;
b5014544 377 hwaddr = -1;
378 }
e2c858f2 379
b5014544 380 do {
e2c858f2 381 if (t < start - length + 1) {
382 if (!stream.NextBunch()) {
383 if (!stream.NextChannel()) {
384 if (!stream.NextDDL()) {
385 stream.Reset();
386 return kFALSE;
387 }
388 ddl = NewDDL(stream, tdet);
389 }
390 hwaddr = NewChannel(stream, tdet, trng, tsec, bstr);
391 }
392 start = stream.GetStartTimeBin();
393 length = stream.GetBunchLength();
394 t = start;
395 i = 0;
b5014544 396 }
e2c858f2 397 Int_t tadc = NewSample(stream, i, t, tsec, bstr, tstr, tsam);
398 if (tadc >= 0) {
399 det = tdet;
400 rng = trng;
401 sec = tsec;
402 str = tstr;
403 sam = tsam;
404 adc = tadc;
405 rat = fSampleRate[ddl];
406 zs = fZeroSuppress[ddl];
407 fac = fNoiseFactor[ddl];
408 t--;
409 i++;
410 break;
b5014544 411 }
b5014544 412 } while (true);
e2c858f2 413
b5014544 414 return kTRUE;
415}
416
e2c858f2 417
faf80567 418//____________________________________________________________________
419Bool_t
420AliFMDRawReader::NextSignal(UShort_t& det, Char_t& rng,
421 UShort_t& sec, UShort_t& str,
422 Short_t& adc, Bool_t& zs,
423 UShort_t& fac)
424{
425
426 do {
427 UShort_t samp, rate;
428 if (!NextSample(det, rng, sec, str, samp, rate, adc, zs, fac))
429 return kFALSE;
430
431 Bool_t take = kFALSE;
432 switch (rate) {
433 case 1: take = kTRUE; break;
434 case 2: if (samp == 1) take = kTRUE; break;
435 case 3: if (samp == 1) take = kTRUE; break;
436 case 4: if (samp == 2) take = kTRUE; break;
437 default: if (samp == rate-2) take = kTRUE; break;
438 }
439 if (!take) continue;
440 break;
441 } while (true);
442 return kTRUE;
443}
444
445//____________________________________________________________________
446Bool_t
447AliFMDRawReader::SelectSample(UShort_t samp, UShort_t rate)
448{
e2c858f2 449 // Check if the passed sample is the one we need
faf80567 450 Bool_t take = kFALSE;
451 switch (rate) {
452 case 1: take = kTRUE; break;
453 case 2: if (samp == 1) take = kTRUE; break;
454 case 3: if (samp == 1) take = kTRUE; break;
455 case 4: if (samp == 2) take = kTRUE; break;
456 default: if (samp == rate-2) take = kTRUE; break;
457 }
458
459 return take;
460}
461
c2fc1258 462//____________________________________________________________________
463Bool_t
464AliFMDRawReader::ReadAdcs(TClonesArray* array)
465{
e2c858f2 466 // Read ADC values from raw input into passed TClonesArray of AliFMDDigit
467 // objects.
468 AliFMDDebug(2, ("Reading ADC values into a TClonesArray"));
469
c2fc1258 470 // Read raw data into the digits array, using AliFMDAltroReader.
471 if (!array) {
472 AliError("No TClonesArray passed");
473 return kFALSE;
474 }
f38b1653 475 const UShort_t kUShortMax = (1 << 16) - 1;
476 fSeen.Reset(kUShortMax);
f38b1653 477
e2c858f2 478 AliAltroRawStreamV3 input(fReader);
479 input.Reset();
480 input.SelectRawData("FMD");
1e8f773e 481
e2c858f2 482 // Loop over input RORCs
483 while (input.NextDDL()) {
484 UShort_t det = 0;
485 Int_t ddl = NewDDL(input, det);
486 if (ddl < 0) break;
487
488 while (input.NextChannel()) {
489 // Get the hardware address, and map that to detector coordinates
1e8f773e 490 Char_t ring;
e2c858f2 491 UShort_t sec;
492 Short_t strbase;
493 Int_t hwaddr = NewChannel(input, det, ring, sec, strbase);
494 if (hwaddr < 0) break;
495
496 // Loop over bunches
497 while (input.NextBunch()) {
498 // Get Lenght of bunch, and pointer to the data
499 const UShort_t* data = input.GetSignals();
500 UShort_t start = input.GetStartTimeBin();
501 UShort_t length = input.GetBunchLength();
502
503 // Loop over the data and store it.
504 for (Int_t i = 0; i < length; i++) {
505 // Time
506 Short_t str;
507 UShort_t samp;
508 Int_t t = start - i;
509 Int_t adc = NewSample(input, i, t, sec, strbase, str, samp);
510 if (adc < 0) continue;
511 UShort_t counts = adc;
512
513 AliFMDDebug(10, ("FMD%d%c[%02d,%03d]-%d: %4d",
514 det, ring, sec, str, samp, counts));
515 // Check the cache of indicies
516 Int_t idx = fSeen(det, ring, sec, str);
86878381 517 AliFMDDigit* digit = 0;
e2c858f2 518 if (idx == kUShortMax) {
519 // We haven't seen this strip yet.
520 fSeen(det, ring, sec, str) = idx = array->GetEntriesFast();
521 AliFMDDebug(7,("making digit for FMD%d%c[%2d,%3d]-%d "
522 "from timebin %4d",
523 det, ring, sec, str, samp, t));
86878381 524 digit = new ((*array)[idx]) AliFMDDigit(det, ring, sec, str);
525 digit->SetDefaultCounts(fSampleRate[ddl]);
e2c858f2 526 }
86878381 527 else
528 digit = static_cast<AliFMDDigit*>(array->At(idx));
e2c858f2 529 AliFMDDebug(10, ("Setting FMD%d%c[%2d,%3d]-%d "
530 "from timebin %4d=%4d (%4d)",
531 det, ring, sec, str, samp, t, counts, data[i]));
532 digit->SetCount(samp, counts);
533 } // for (i)
534 } // while (bunch)
535 } // while (channel)
536 } // while (ddl)
d760ea03 537 return kTRUE;
538}
539
3effc6e7 540//____________________________________________________________________
541Bool_t AliFMDRawReader::ReadSODevent(AliFMDCalibSampleRate* sampleRate,
542 AliFMDCalibStripRange* stripRange,
543 TArrayS &pulseSize,
408bf2b4 544 TArrayS &pulseLength,
545 Bool_t* detectors)
f38b1653 546{
3effc6e7 547
548 AliFMDDebug(0, ("Start of SOD/EOD"));
549
550 UInt_t shift_clk[18];
551 UInt_t sample_clk[18];
552 UInt_t strip_low[18];
553 UInt_t strip_high[18];
554 UInt_t pulse_size[18];
555 UInt_t pulse_length[18];
1986c52b 556 for (size_t i = 0; i < 18; i++) {
557 shift_clk[i] = 0;
558 sample_clk[i] = 0;
559 strip_low[i] = 0;
560 strip_high[i] = 0;
561 pulse_size[i] = 0;
562 pulse_length[i] = 0;
563 }
b995fc28 564 AliFMDParameters* param = AliFMDParameters::Instance();
565 AliFMDAltroMapping* map = param->GetAltroMap();
3effc6e7 566
86878381 567 AliAltroRawStreamV3 streamer(fReader);
568 streamer.Reset();
569 streamer.SelectRawData("FMD");
570 //fReader->GetDDLID();
86878381 571 while (streamer.NextDDL()) {
572 Int_t ddl = streamer.GetDDLNumber();
573 Int_t detID = fReader->GetDetectorID();
574 if (detectors) detectors[map->DDL2Detector(ddl)-1] = kTRUE;
575 AliFMDDebug(0, (" From reader: DDL number is %d , det ID is %d",ddl,detID));
133f1578 576
86878381 577 ULong_t nPayloadWords = streamer.GetRCUPayloadSizeInSOD();
578 UChar_t* payloadData = streamer.GetRCUPayloadInSOD();
579 UInt_t* payloadWords = reinterpret_cast<UInt_t*>(payloadData);
580 //UInt_t* payloadWords = streamer.GetRCUPayloadInSOD();
581
a0354a2a 582 //std::cout<<nPayloadWords<<" "<<ddl<<std::endl;
86878381 583 for (ULong_t i = 1; i <= nPayloadWords ; i++, payloadWords++) {
584 UInt_t payloadWord = *payloadWords; // Get32bitWord(i);
3effc6e7 585
a0354a2a 586 //std::cout<<i<<Form(" word: 0x%x",payloadWord)<<std::endl;
f38b1653 587 // address is only 24 bit
588 UInt_t address = (0xffffff & payloadWord);
589 UInt_t type = ((address >> 21) & 0xf);
590 UInt_t error = ((address >> 20) & 0x1);
591 UInt_t bcast = ((address >> 18) & 0x1);
592 UInt_t bc_not_altro = ((address >> 17) & 0x1);
593 UInt_t board = ((address >> 12) & 0x1f);
594 UInt_t instruction = 0;
595 UInt_t chip = 0;
596 UInt_t channel = 0;
597 if(bc_not_altro)
598 instruction = address & 0xfff;
599 else {
600 chip = ((address >> 9) & 0x7);
601 channel = ((address >> 5) & 0x5);
602 instruction = (address & 0x1f);
603 }
76d06ffa 604
f38b1653 605 Bool_t readDataWord = kFALSE;
606 switch(type) {
607 case 0x0: // Fec read
608 readDataWord = kTRUE;
609 case 0x1: // Fec cmd
610 case 0x2: // Fec write
86878381 611 i++;
612 payloadWords++;
f38b1653 613 break;
614 case 0x4: // Loop
615 case 0x5: // Wait
616 break;
617 case 0x6: // End sequence
618 case 0x7: // End Mem
86878381 619 i = nPayloadWords + 1;
f38b1653 620 break;
621 default:
622 break;
623 }
76d06ffa 624
f38b1653 625 //Don't read unless we have a FEC_RD
626 if(!readDataWord) continue;
627
86878381 628 UInt_t dataWord = *payloadWords;//Get32bitWord(i);
f38b1653 629 UInt_t data = (0xFFFFF & dataWord) ;
630 //UInt_t data = (0xFFFF & dataWord) ;
3effc6e7 631
f38b1653 632 if(error) {
633 AliWarning(Form("error bit detected at Word 0x%06x; "
634 "error % d, type %d, bc_not_altro %d, "
635 "bcast %d, board 0x%02x, chip 0x%x, "
636 "channel 0x%02x, instruction 0x%03x",
637 address, error, type, bc_not_altro,
638 bcast,board,chip,channel,instruction));
639 //process error
640 continue;
641 }
3effc6e7 642
643
f38b1653 644 switch(instruction) {
3effc6e7 645
f38b1653 646 case 0x01: break; // First ADC T
647 case 0x02: break; // I 3.3 V
648 case 0x03: break; // I 2.5 V altro digital
649 case 0x04: break; // I 2.5 V altro analog
650 case 0x05: break; // I 2.5 V VA
651 case 0x06: break; // First ADC T
652 case 0x07: break; // I 3.3 V
653 case 0x08: break; // I 2.5 V altro digital
654 case 0x09: break; // I 2.5 V altro analog
655 case 0x0A: break; // I 2.5 V VA
656 case 0x2D: break; // Second ADC T
657 case 0x2E: break; // I 1.5 V VA
658 case 0x2F: break; // I -2.0 V
659 case 0x30: break; // I -2.0 V VA
660 case 0x31: break; // 2.5 V Digital driver
661 case 0x32: break; // Second ADC T
662 case 0x33: break; // I 1.5 V VA
663 case 0x34: break; // I -2.0 V
664 case 0x35: break; // I -2.0 V VA
665 case 0x36: break; // 2.5 V Digital driver
666 case 0x37: break; // Third ADC T
667 case 0x38: break; // Temperature sens. 1
668 case 0x39: break; // Temperature sens. 2
669 case 0x3A: break; // U 2.5 altro digital (m)
670 case 0x3B: break; // U 2.5 altro analog (m)
671 case 0x3C: break; // Third ADC T
672 case 0x3D: break; // Temperature sens. 1
673 case 0x3E: break; // Temperature sens. 2
674 case 0x3F: break; // U 2.5 altro digital (m)
675 case 0x40: break; // U 2.5 altro analog (m)
676 case 0x41: break; // Forth ADC T
677 case 0x42: break; // U 2.5 VA (m)
678 case 0x43: break; // U 1.5 VA (m)
679 case 0x44: break; // U -2.0 VA (m)
680 case 0x45: break; // U -2.0 (m)
681 case 0x46: break; // Forth ADC T
682 case 0x47: break; // U 2.5 VA (m)
683 case 0x48: break; // U 1.5 VA (m)
684 case 0x49: break; // U -2.0 VA (m)
685 case 0x4A: break; // U -2.0 (m)
686 // Counters
687 case 0x0B: break; // L1 trigger CouNTer
688 case 0x0C: break; // L2 trigger CouNTer
689 case 0x0D: break; // Sampling CLK CouNTer
690 case 0x0E: break; // DSTB CouNTer
691 // Test mode
692 case 0x0F: break; // Test mode word
693 case 0x10: break; // Undersampling ratio.
694 // Configuration and status
695 case 0x11: break; // Config/Status Register 0
696 case 0x12: break; // Config/Status Register 1
697 case 0x13: break; // Config/Status Register 2
698 case 0x14: break; // Config/Status Register 3
699 case 0x15: break; // Free
700 // Comands:
701 case 0x16: break; // Latch L1, L2, SCLK Counters
702 case 0x17: break; // Clear counters
703 case 0x18: break; // Clear CSR1
704 case 0x19: break; // rstb ALTROs
705 case 0x1A: break; // rstb BC
706 case 0x1B: break; // Start conversion
707 case 0x1C: break; // Scan event length
708 case 0x1D: break; // Read event length
709 case 0x1E: break; // Start test mode
710 case 0x1F: break; // Read acquisition memory
711 // FMD
712 case 0x20: break; // FMDD status
713 case 0x21: break; // L0 counters
714 case 0x22: break; // FMD: Wait to hold
715 case 0x23: break; // FMD: L1 timeout
716 case 0x24: break; // FMD: L2 timeout
717 case 0x25: // FMD: Shift clk
718 shift_clk[board] = ((data >> 8 ) & 0xFF);
1986c52b 719 AliFMDDebug(30, ("Read shift_clk=%d for board 0x%02x",
133f1578 720 shift_clk[board], board));
f38b1653 721 break;
722 case 0x26: // FMD: Strips
723 strip_low[board] = ((data >> 0 ) & 0xFF);
724 strip_high[board] = ((data >> 8 ) & 0xFF);
725 break;
726 case 0x27: // FMD: Cal pulse
727 pulse_size[board] = ((data >> 8 ) & 0xFF);
728 break;
729 case 0x28: break; // FMD: Shape bias
730 case 0x29: break; // FMD: Shape ref
731 case 0x2A: break; // FMD: Preamp ref
732 case 0x2B: // FMD: Sample clk
733 sample_clk[board] = ((data >> 8 ) & 0xFF);
1986c52b 734 AliFMDDebug(30, ("Read sample_clk=%d for board 0x%02x",
133f1578 735 sample_clk[board], board));
f38b1653 736 break;
737 case 0x2C: break; // FMD: Commands
738 case 0x4B: // FMD: Cal events
739 pulse_length[board] = ((data >> 0 ) & 0xFF);
740 break;
741 default: break;
3effc6e7 742
f38b1653 743 }
744 AliFMDDebug(50, ("instruction 0x%x, dataword 0x%x",
745 instruction,dataWord));
86878381 746 } // End of loop over Result memory event
3effc6e7 747
133f1578 748 UShort_t det = 0;
749 UShort_t sector = 0;
750 Short_t strip = -1;
751 Char_t ring = '\0';
76d06ffa 752
3effc6e7 753 const UInt_t boards[4] = {0,1,16,17};
754 for(Int_t i=0;i<4;i++) {
f38b1653 755 if(ddl==0 && (i==1 || i==3)) continue;
756
3effc6e7 757 UInt_t chip =0, channel=0;
b995fc28 758 det = map->DDL2Detector(ddl);
759 map->Channel2StripBase(boards[i], chip, channel, ring, sector, strip);
76d06ffa 760
1986c52b 761 UInt_t samplerate = 0;
762#if USE_VOTE
76d06ffa 763 if(sample_clk[boards[i]] == 0) {
f38b1653 764 if(ddl == 0) {
765 Int_t sample1 = sample_clk[boards[0]];
766 Int_t sample2 = sample_clk[boards[2]];
767 if(sample1) sample_clk[boards[i]] = sample1;
768 else sample_clk[boards[i]] = sample2;
769 }
770 else {
771 Int_t sample1 = sample_clk[boards[0]];
772 Int_t sample2 = sample_clk[boards[1]];
773 Int_t sample3 = sample_clk[boards[2]];
774 Int_t sample4 = sample_clk[boards[3]];
775 Int_t agreement = 0;
776 if(sample1 == sample2) agreement++;
777 if(sample1 == sample3) agreement++;
778 if(sample1 == sample4) agreement++;
779 if(sample2 == sample3) agreement++;
780 if(sample2 == sample4) agreement++;
781 if(sample3 == sample4) agreement++;
76d06ffa 782
f38b1653 783 Int_t idx = 0;
784 if(i<3) idx = i+1;
785 else idx = i-1;
786 if(agreement == 3) {
787 sample_clk[boards[i]] = sample_clk[boards[idx]];
788 shift_clk[boards[i]] = shift_clk[boards[idx]];
789 strip_low[boards[i]] = strip_low[boards[idx]];
790 strip_high[boards[i]] = strip_high[boards[idx]];
791 pulse_length[boards[i]] = pulse_length[boards[idx]];
792 pulse_size[boards[i]] = pulse_size[boards[idx]];
1986c52b 793 AliFMDDebug(3, ("Vote taken for ddl %d, board 0x%x",
f38b1653 794 ddl,boards[i]));
76d06ffa 795 }
f38b1653 796 }
76d06ffa 797 }
1986c52b 798#endif
76d06ffa 799
3effc6e7 800 if(sample_clk[boards[i]])
f38b1653 801 samplerate = shift_clk[boards[i]]/sample_clk[boards[i]];
1986c52b 802 AliFMDDebug(10, ("Sample rate for board 0x%02x is %d",
803 boards[i], samplerate));
3effc6e7 804 sampleRate->Set(det,ring,sector,0,samplerate);
f38b1653 805 stripRange->Set(det,ring,sector,0,
806 strip_low[boards[i]],strip_high[boards[i]]);
3effc6e7 807
76d06ffa 808 AliFMDDebug(20, ("det %d, ring %c, ",det,ring));
f38b1653 809 pulseLength.AddAt(pulse_length[boards[i]],
810 GetHalfringIndex(det,ring,boards[i]/16));
811 pulseSize.AddAt(pulse_size[boards[i]],
812 GetHalfringIndex(det,ring,boards[i]/16));
76d06ffa 813
3effc6e7 814
76d06ffa 815
816 AliFMDDebug(20, (": Board: 0x%02x\n"
f38b1653 817 "\tstrip_low %3d, strip_high %3d\n"
818 "\tshift_clk %3d, sample_clk %3d\n"
819 "\tpulse_size %3d, pulse_length %3d",
820 boards[i],
821 strip_low[boards[i]], strip_high[boards[i]],
822 shift_clk[boards[i]], sample_clk[boards[i]],
823 pulse_size[boards[i]],pulse_length[boards[i]]));
86878381 824 }
1986c52b 825
826 }
3effc6e7 827
828 AliFMDParameters::Instance()->SetSampleRate(sampleRate);
829 AliFMDParameters::Instance()->SetStripRange(stripRange);
830
831 AliFMDDebug(0, ("End of SOD/EOD"));
832
7af3df7f 833 return kTRUE;
3effc6e7 834}
835//____________________________________________________________________
836
837UInt_t AliFMDRawReader::Get32bitWord(Int_t idx)
838{
839 // This method returns the 32 bit word at a given
840 // position inside the raw data payload.
841 // The 'index' points to the beginning of the next word.
842 // The method is supposed to be endian (platform)
843 // independent.
844 if (!fData) {
845 AliFatal("Raw data paylod buffer is not yet initialized !");
846 }
847
848 Int_t index = 4*idx;
849
850 if (index < 4) {
851 // fRawReader->AddFatalErrorLog(k32bitWordReadErr,Form("pos = %d",index));
852 // PrintDebug();
853 AliWarning(Form("Invalid raw data payload position (%d) !",index));
854 }
855
856 UInt_t word = 0;
76d06ffa 857
3effc6e7 858 word = fData[--index] << 24;
859 word |= fData[--index] << 16;
860 word |= fData[--index] << 8;
861 word |= fData[--index] << 0 ;
e802be3e 862
3effc6e7 863 return word;
864}
865//_____________________________________________________________________
f38b1653 866Int_t AliFMDRawReader::GetHalfringIndex(UShort_t det, Char_t ring,
867 UShort_t board) {
3effc6e7 868
869 UShort_t iring = (ring == 'I' ? 1 : 0);
870
871 Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
872
76d06ffa 873 return index-2;
3effc6e7 874
875}
e2c858f2 876
e802be3e 877//____________________________________________________________________
878//
879// EOF
880//
6c652449 881