1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 /** @file AliFMDRawReader.cxx
17 @author Christian Holm Christensen <cholm@nbi.dk>
18 @date Mon Mar 27 12:45:23 2006
19 @brief Class to read raw data
22 //____________________________________________________________________
24 // Class to read ADC values from a AliRawReader object.
26 // This class uses the AliFMDRawStreamer class to read the ALTRO
34 // +-----------------+ <<references>> +--------------+
35 // | AliFMDRawReader |<>----------------| AliRawReader |
36 // +-----------------+ +--------------+
40 // +-----------------+ <<uses>> |
41 // | AliFMDRawStream |------------------------+
42 // +-----------------+
49 // #include <AliLog.h> // ALILOG_H
50 #include "AliFMDDebug.h" // Better debug macros
51 #include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
52 #include "AliFMDDigit.h" // ALIFMDDIGIT_H
53 #include "AliFMDSDigit.h" // ALIFMDSDIGIT_H
54 // #include "AliFMDRawStream.h" // ALIFMDRAWSTREAM_H
55 #include "AliRawReader.h" // ALIRAWREADER_H
56 #include "AliFMDRawReader.h" // ALIFMDRAWREADER_H
57 #include "AliFMDDebug.h"
58 #include "AliFMDCalibSampleRate.h"
59 #include "AliFMDCalibStripRange.h"
60 #include "AliFMDAltroMapping.h"
61 #include "AliFMDUShortMap.h"
62 // #include "AliFMDAltroIO.h" // ALIFMDALTROIO_H
63 #include "AliAltroRawStreamV3.h"
64 #include <TArrayS.h> // ROOT_TArrayS
65 #include <TTree.h> // ROOT_TTree
66 #include <TClonesArray.h> // ROOT_TClonesArray
72 //____________________________________________________________________
73 ClassImp(AliFMDRawReader)
75 ; // This is here to keep Emacs for indenting the next line
78 //____________________________________________________________________
79 AliFMDRawReader::AliFMDRawReader(AliRawReader* reader, TTree* tree)
80 : TTask("FMDRawReader", "Reader of Raw ADC values from the FMD"),
96 for (Int_t i = 0; i < 3; i++) {
98 fZeroSuppress[i] = kFALSE;
105 //____________________________________________________________________
107 AliFMDRawReader::Exec(Option_t*)
110 TClonesArray* array = new TClonesArray("AliFMDDigit");
115 fTree->Branch("FMD", &array);
119 Int_t nWrite = fTree->Fill();
120 AliDebugF(1,"Got a grand total of %d digits, wrote %d bytes to tree",
121 array->GetEntriesFast(), nWrite);
125 //____________________________________________________________________
127 AliFMDRawReader::AddError(Int_t ddl, Int_t hwaddr)
129 Int_t nErr = fErrors.GetEntries();
130 TObject* o = new (fErrors[nErr]) TObject;
131 o->SetUniqueID((ddl & 0xFF) << 12 | (hwaddr & 0xFFF));
133 //____________________________________________________________________
135 AliFMDRawReader::ReadbackError(const AliAltroRawStreamV3& input,
136 const char* format, ...)
138 static char buf[512];
140 va_start(ap, format);
141 vsnprintf(buf, 511, format, ap);
145 // { AliWarning(buf); }
146 if (AliDebugLevel() > 10) {
149 input.HexDumpChannel();
152 Int_t ddl = input.GetDDLNumber();
153 Int_t hwaddr = input.GetHWAddress();
155 fReader->AddMinorErrorLog(AliAltroRawStreamV3::kAltroPayloadErr,buf);
156 AddError(ddl, hwaddr);
160 //____________________________________________________________________
162 AliFMDRawReader::NewDDL(AliAltroRawStreamV3& input, UShort_t& det)
164 // Process a new DDL. Sets the internal data members fZeroSuppress,
165 // fSampleRate, and fNoiseFactor based on information in the RCU trailer.
168 // input Input stream
169 // det On return, the detector number
172 // negative value in case of problems, the DDL number otherwise
174 // Get the DDL number
175 UInt_t ddl = input.GetDDLNumber();
176 AliDebugF(2,"DDL number %d", ddl);
178 // Note, previously, the ALTROCFG1 register was interpreted as
180 // Bits Value Description
181 // 0- 3 0/1 1st Baseline filter, mode
182 // 4- 5 Over-1 2nd baseline filter, # of pre-samples
183 // 6- 9 factor 2nd baseline filter, # of post-samples
184 // 10- 0 2nd baseline filter, enable
185 // 11-12 00 Zero suppression, glitch filter mode
186 // 13-15 001 Zero suppression, # of post samples
187 // 16-17 01 Zero suppression, # of pre samples
188 // 18 0/1 Zero suppression, enable
190 // The interpretation used in AliAltroRawStreamerV3 - which
191 // corresponds directly to ALTRO DPCFG register - is
193 // Bits Value Description
194 // 0- 3 0/1 1st Baseline filter, mode
195 // 4 0 Polarity (if '1', then "1's inverse")
196 // 5- 6 01 Zero suppression, # of pre samples
197 // 7-10 0001 Zero suppression, # of post samples
198 // 11 0 2nd baseline filter, enable
199 // 12-13 00 Zero suppression, glitch filter mode
200 // 14-16 factor 2nd baseline filter, # of post-samples
201 // 17-18 01 2nd baseline filter, # of pre-samples
202 // 19 0/1 Zero suppression, enable
204 // From ALTRO DPCF2 we get
206 // 20-23 rate Pre-samples
208 // Writing 'x' for variable values, that means we have the
209 // following patterns for the 2 cases
211 // bit # 20 16 12 8 4 0
212 // old |0x01|0010|00xx|xxxx|xxxx|
213 // new |x01x|xx00|0000|1010|xxxx|
215 // That means that we can check if bits 10-13 are '1000' or
216 // '0000', which will tell us if the value was written with the
217 // new or the old interpretation. That is, we can check that
219 // if (((altrocfg1 >> 10) & 0x8) == 0x8) {
220 // // old interpretation
223 // // New interpretation
226 // That means, that we should never
228 // - change the # of zero suppression post samples
229 // - Turn on 2nd baseline correction
230 // - Change the zero-suppression glitch filter mode
232 // This change as introduced in version 1.2 of Rcu++
234 UInt_t cfg1 = input.GetAltroCFG1();
235 if (((cfg1 >> 10) & 0x8) == 0x8) {
236 UInt_t cfg2 = input.GetAltroCFG2();
237 AliDebugF(3,"We have data from older MiniConf 0x%x cfg2=0x%08x",
238 ((cfg1 >> 10) & 0x8), cfg2);
239 fZeroSuppress[ddl] = (cfg1 >> 0) & 0x1;
240 fNoiseFactor[ddl] = (cfg1 >> 6) & 0xF;
241 fSampleRate[ddl] = (cfg2 >> 20) & 0xF;
244 AliDebugF(3,"We have data from newer MiniConf 0x%x",
245 ((cfg1 >> 10) & 0x8));
246 fZeroSuppress[ddl] = input.GetZeroSupp();
247 // WARNING: We store the noise factor in the 2nd baseline
248 // filters excluded post samples, since we'll never use that
250 // fNoiseFactor[ddl] = input.GetNPostsamples();
251 fNoiseFactor[ddl] = input.GetNNonZSPostsamples();
252 // WARNING: We store the sample rate in the number of pre-trigger
253 // samples, since we'll never use that mode.
254 fSampleRate[ddl] = input.GetNPretriggerSamples();
257 AliDebugF(10,"Phase of DDL=%d is %g (%d)", ddl, input.GetL1Phase(),
258 input.GetAltroCFG2() & 0x1F);
259 fL1Phase[ddl] = input.GetAltroCFG2() & 0x1F; // input.GetL1Phase();
260 AliDebugF(3,"RCU @ DDL %d zero suppression: %s",
261 ddl, (fZeroSuppress[ddl] ? "yes" : "no"));
262 AliDebugF(3,"RCU @ DDL %d noise factor: %d", ddl,fNoiseFactor[ddl]);
263 AliDebugF(3,"RCU @ DDL %d sample rate: %d", ddl,fSampleRate[ddl]);
267 Int_t nChAddrMismatch = input.GetNChAddrMismatch();
268 Int_t nChLenMismatch = input.GetNChLengthMismatch();
269 if (nChAddrMismatch != 0) {
271 "Got %d channels with address mis-matches for 0x%03x",
272 nChAddrMismatch, ddl);
273 fNErrAddress += nChAddrMismatch;
275 if (nChLenMismatch != 0) {
277 "Got %d channels with length mis-matches for 0x%03x",
278 nChLenMismatch, ddl);
279 fNErrChanLen += nChLenMismatch;
282 // Map DDL number to the detector number
283 AliFMDParameters* pars = AliFMDParameters::Instance();
284 AliFMDAltroMapping* map = pars->GetAltroMap();
285 if (map->DDL2Detector(ddl) < 0) return -1;
286 det = map->DDL2Detector(ddl);
288 if (AliLog::GetDebugLevel("FMD", 0) > 5)
289 input.PrintRCUTrailer();
293 //____________________________________________________________________
295 AliFMDRawReader::NewChannel(const AliAltroRawStreamV3& input, UShort_t det,
296 Char_t& ring, UShort_t& sec, Short_t& strbase)
298 // Processs a new channel. Sets the internal data members
299 // fMinStrip, fMaxStrip, and fPreSamp.
302 // input Input stream
303 // ring On return, the ring identifier
304 // sec On return, the sector number
305 // strbase On return, the strip base
308 // negative value in case of problems, hardware address otherwise
310 // Get the hardware address, and map that to detector coordinates
311 UShort_t board, chip, channel;
312 Int_t ddl = input.GetDDLNumber();
313 Int_t hwaddr = input.GetHWAddress();
314 if (input.IsChannelBad()) {
315 ReadbackError(input, "Ignoring channel %03d/0x%03x with errors",
320 AliFMDParameters* pars = AliFMDParameters::Instance();
321 AliFMDAltroMapping* map = pars->GetAltroMap();
322 // Map to hardware stuff
323 map->ChannelAddress(hwaddr, board, chip, channel);
324 // Then try to map to detector address
325 if (!map->Channel2StripBase(board, chip, channel, ring, sec, strbase)) {
326 AliErrorF("Failed to get detector id from DDL %d, "
327 "hardware address 0x%03x", ddl, hwaddr);
330 AliDebugF(7,"Board: 0x%02x, Altro: 0x%x, Channel: 0x%x",
331 board, chip, channel);
333 // Get the 'conditions'
334 fMinStrip = pars->GetMinStrip(det, ring, sec, strbase);
335 fMaxStrip = pars->GetMaxStrip(det, ring, sec, strbase);
336 fPreSamp = pars->GetPreSamples(det, ring, sec, strbase);
337 if (fSampleRate[ddl] == 0) {
338 AliDebugF(7,"Get sample rate for RCU @ DDL %d from OCDB", ddl);
339 fSampleRate[ddl] = pars->GetSampleRate(det, ring, sec, strbase);
341 AliDebugF(7,"RCU @ DDL %d sample rate: %d", ddl,fSampleRate[ddl]);
346 //____________________________________________________________________
348 AliFMDRawReader::NewBunch(const AliAltroRawStreamV3& input,
349 UShort_t& start, UShort_t& length)
352 // Do some checks on the bunch data
354 Int_t ddl = input.GetDDLNumber();
355 Int_t hwaddr = input.GetHWAddress();
356 UShort_t nSamples = input.GetNSamplesPerCh() + fPreSamp;
357 UShort_t tstart = input.GetStartTimeBin();
358 length = input.GetBunchLength();
360 if (tstart >= nSamples) {
362 "Bunch in %03d/0x%03x has an start time greater "
363 "than number of samples: 0x%x >= 0x%x",
364 ddl, hwaddr, tstart, nSamples);
367 if ((int(tstart) - length + 1) < 0) {
369 "Bunch in %03d/0x%03x has an invalid length and "
370 "start time: 0x%x,0x%x (%d-%d+1=%d<0)",
371 ddl, hwaddr, length, tstart, tstart, length,
372 int(tstart)-length+1);
375 if (tstart >= start) {
377 "Bunch in %03d/0x%03x has early start time: "
378 "0x%x >= 0x%x", ddl, hwaddr, tstart, start);
385 //____________________________________________________________________
387 AliFMDRawReader::NewSample(const AliAltroRawStreamV3& input,
388 Int_t i, UShort_t t, UShort_t sec,
389 UShort_t strbase, Short_t& str, UShort_t& samp)
391 // Process a new timebin
394 // input Input stream
395 // i Index into bunch data
397 // strbase Base of strip numbers for this channel
398 // str On return, the strip number
399 // samp On return, the sample number
402 // negative value in case of problems, ADC value otherwise
403 if (t < fPreSamp) return -1;
405 Int_t ddl = input.GetDDLNumber();
406 Int_t hwa = input.GetHWAddress();
407 const UShort_t* data = input.GetSignals();
408 Short_t adc = data[i];
409 AliDebugF(10,"0x%04x/0x%03x/%04d %4d", ddl, hwa, t, adc);
411 AliFMDParameters* pars = AliFMDParameters::Instance();
412 AliFMDAltroMapping* map = pars->GetAltroMap();
416 map->Timebin2Strip(sec, t, fPreSamp, fSampleRate[ddl], stroff, samp);
417 str = strbase + stroff;
419 AliDebugF(20,"0x%04x/0x%03x/%04d=%4d maps to strip %3d sample %d "
420 "(pre: %d, min: %d, max: %d, rate: %d)",
421 ddl, hwa, t, adc, str, samp, fPreSamp,
422 fMinStrip, fMaxStrip, fSampleRate[ddl]);
424 AliDebugF(10,"Got presamples at timebin %d", i);
428 // VA1 Local strip number
429 Short_t lstrip = (t - fPreSamp) / fSampleRate[ddl] + fMinStrip;
431 AliDebugF(15,"Checking if strip %d (%d) in range [%d,%d]",
432 lstrip, str, fMinStrip, fMaxStrip);
433 if (lstrip < fMinStrip || lstrip > fMaxStrip) {
434 AliDebugF(10,"Strip %03d-%d (%d,%d) from t=%d out of range (%3d->%3d)",
435 str, samp, lstrip, stroff, t, fMinStrip, fMaxStrip);
438 // Possibly do pedestal subtraction of signal
440 AliWarningF("ADC value out of range: %4d", adc);
444 //____________________________________________________________________
446 AliFMDRawReader::NextSample(UShort_t& det, Char_t& rng, UShort_t& sec,
447 UShort_t& str, UShort_t& sam, UShort_t& rat,
448 Short_t& adc, Bool_t& zs, UShort_t& fac)
450 // Scan current event for next signal. It returns kFALSE when
451 // there's no more data in the event.
453 // Note, that this member function is in principle very fast, but
454 // contains less error checking. In particular, channels that have
455 // bad bunches cannot be checked here. Seeing a bad bunch will only
456 // skip the remainder of the channel and not reset the already read
457 // digits. This is potentially dangerous.
460 // det On return, contain the detector number
461 // rng On return, contain the ring identifier
462 // sec On return, contain the sector number
463 // str On return, contain the strip number
464 // sam On return, contain the sample number
465 // rat On return, contain the sample rate
466 // adc On return, contain the ADC counts
467 // zs On return, contain the zero-supp. flag
468 // fac On return, contain the zero-supp. noise factor
472 // -1 Read sample belongs to a bad bunch
473 // >0 Good status - contains bit mask of values
478 static AliAltroRawStreamV3 stream(fReader); // = 0;
479 static Int_t ddl = -1;
480 static UShort_t tdet = 0;
481 static Char_t trng = '\0';
482 static UShort_t tsec = 0;
483 static Short_t tstr = 0;
484 static Short_t bstr = -1;
485 static UShort_t tsam = 0;
486 // static UInt_t trate = 0;
487 static Int_t hwaddr = -1;
488 static UShort_t start = 0;
489 static UShort_t length = 0;
490 static Short_t t = -1;
493 if (stream.GetDDLNumber() < 0) {
495 fReader->Select("FMD");
497 stream.SelectRawData("FMD");
498 stream.SetCheckAltroPayload(false);
499 for (Int_t j = 0; j < kNDDL; j++) fNErrors[j] = 0;
514 AliDebugF(15, "t=%4d, start=%4d, length=%4d", t, start, length);
515 if (t < start - length + 1) {
516 AliDebugF(10,"Time t=%d < start-length+1=%d-%d+1 (%3d/0x%03x)",
517 t, start, length, ddl, hwaddr);
518 if (hwaddr > 0xFFF ||
520 !stream.NextBunch()) {
521 if (AliDebugLevel() >= 10 && hwaddr > 0xFFF) {
522 AliDebug(10,"Last channel read was marked bad");
524 if (AliDebugLevel() >= 10 && hwaddr < 0) {
525 AliDebug(10,"No more channels");
527 AliDebug(10,"No next bunch, or first entry");
528 if (ddl < 0 || !stream.NextChannel()) {
529 if (AliDebugLevel() >= 10 && ddl < 0) {
530 AliDebug(10,"No DDL");
532 AliDebug(10,"No next channel, or first entry");
533 if (!stream.NextDDL()) {
534 AliDebug(10,"No more DDLs");
538 ddl = NewDDL(stream, tdet);
539 AliDebugF(5,"New DDL: %d (%d)", ddl, tdet);
543 hwaddr = NewChannel(stream, tdet, trng, tsec, bstr);
544 if (hwaddr > 0xFFF) fNErrors[ddl] += 1;
545 AliDebugF(5,"New Channel: %3d/0x%03x", ddl, hwaddr);
550 if (!NewBunch(stream, start, length)) {
551 // AliWarning(Form("Bad bunch in %3d/0x%03x read - "
552 // "should progress to next channel "
553 // "(t=%4d,start=%4d,length=%4d)",
554 // ddl, hwaddr, t,start, length));
555 hwaddr = 0xFFFF; // Bad channel
558 AliDebugF(5, "New bunch in %3d/0x%03x: start=0x%03x, length=%4d",
559 ddl, hwaddr, start, length);
563 AliDebugF(10,"Got new bunch FMD%d%c[%2d], bunch @ %d, length=%d",
564 tdet, trng, tsec, start, length);
566 Int_t tadc = NewSample(stream, i, t, tsec, bstr, tstr, tsam);
567 AliDebugF(10,"New sample FMD%d%c[%2d,%3d]-%d = 0x%03x",
568 tdet, trng, tsec, tstr, tsam, tadc);
577 rat = fSampleRate[ddl];
578 zs = fZeroSuppress[ddl];
579 fac = fNoiseFactor[ddl];
582 AliDebugF(10,"Returning FMD%d%c[%2d,%3d]-%d = 0x%03x (%d,%d,%d)",
583 det, rng, sec, str, sam, adc, rat, zs, fac);
589 AliDebugF(5,"Returning 0x%02x", ret);
594 //____________________________________________________________________
596 AliFMDRawReader::NextSignal(UShort_t& det, Char_t& rng,
597 UShort_t& sec, UShort_t& str,
598 Short_t& adc, Bool_t& zs,
602 // Get the next signal
605 // det On return, the detector
606 // rng On return, the ring
607 // sec On return, the sector
608 // str On return, the strip
609 // adc On return, the ADC value
610 // zs On return, whether zero-supp. is enabled
611 // fac On return, the usd noise factor
614 // true if valid data is returned
619 if ((ret = NextSample(det, rng, sec, str, samp, rate, adc, zs, fac)) <= 0)
622 Bool_t take = SelectSample(samp, rate);
629 //____________________________________________________________________
631 AliFMDRawReader::SelectSample(UShort_t samp, UShort_t rate)
633 // Check if the passed sample is the one we need
634 Bool_t take = kFALSE;
636 case 1: take = kTRUE; break;
637 case 2: if (samp == 1) take = kTRUE; break;
638 case 3: if (samp == 1) take = kTRUE; break;
639 case 4: if (samp == 2) take = kTRUE; break;
640 default: if (samp == rate-2) take = kTRUE; break;
646 //____________________________________________________________________
648 AliFMDRawReader::ReadAdcs(TClonesArray* array)
650 // Read ADC values from raw input into passed TClonesArray of AliFMDDigit
652 AliDebug(3,"Reading ADC values into a TClonesArray");
654 // Read raw data into the digits array, using AliFMDAltroReader.
656 AliError("No TClonesArray passed");
659 // static ULong_t unique = 0;
660 const UShort_t kUShortMax = (1 << 16) - 1;
661 fSeen.Reset(kUShortMax);
665 for (Int_t ddl = 0; ddl < kNDDL; ddl++) fNErrors[ddl] = 0;
667 AliAltroRawStreamV3 input(fReader);
669 input.SetCheckAltroPayload(false);
670 input.SelectRawData("FMD");
672 // Loop over input RORCs
673 while (input.NextDDL()) {
675 Int_t ddl = NewDDL(input, det);
679 while (input.NextChannel()) {
680 // Get the hardware address, and map that to detector coordinates
684 Int_t hwaddr = NewChannel(input, det, ring, sec, strbase);
685 if (hwaddr < 0) break;
686 if (hwaddr > 0xFFF) continue;
688 UShort_t start = 0x3FF;
689 Bool_t errors = false;
693 while (input.NextBunch()) {
694 // Get Lenght of bunch, and pointer to the data
695 const UShort_t* data = input.GetSignals();
697 if (!NewBunch(input, start, length)) {
703 // Loop over the data and store it.
704 for (Int_t i = 0; i < length; i++) {
709 Int_t adc = NewSample(input, i, t, sec, strbase, str, samp);
710 if (adc <= 0) continue;
711 UShort_t counts = adc;
713 AliDebugF(10,"FMD%d%c[%02d,%03d]-%d: %4d",
714 det, ring, sec, str, samp, counts);
715 // Check the cache of indicies
716 Int_t idx = fSeen(det, ring, sec, str);
717 AliFMDDigit* digit = 0;
718 if (idx == kUShortMax) {
719 // We haven't seen this strip yet.
720 fSeen(det, ring, sec, str) = idx = array->GetEntriesFast();
721 AliDebugF(7, "making digit @ %5d for FMD%d%c[%2d,%3d]-%d "
722 "from %3d/0x%03x/%4d (def: %d)",
723 idx, det, ring, sec, str, samp, ddl, hwaddr, t,
725 digit = new ((*array)[idx]) AliFMDDigit(det, ring, sec, str);
726 digit->SetDefaultCounts(fSampleRate[ddl]);
729 digit = static_cast<AliFMDDigit*>(array->At(idx));
731 if (first < 0) first = idx;
733 AliDebugF(5,"Setting FMD%d%c[%2d,%3d]-%d from timebin "
734 "%4d=%4d (%4d)", det, ring, sec, str, samp, t,
736 digit->SetCount(samp, counts);
737 if (AliLog::GetDebugLevel("FMD","") >= 5) digit->Print();
741 AliDebugF(2,"Channel %3d/0x%03x contain errors, "
742 "resetting index %d to %d", ddl, hwaddr, first, last);
744 for (Int_t i = first; i <= last; i++) {
745 AliFMDDigit* digit = static_cast<AliFMDDigit*>(array->At(i));
746 for (Int_t j = 0; j < fSampleRate[ddl]; j++) {
747 AliDebugF(10,"Resetting strip %s=%d",
748 digit->GetName(),digit->Counts());
749 digit->SetCount(j, kBadSignal);
754 // if (errors && (AliDebugLevel() > 0)) input.HexDumpChannel();
757 if (fNErrors[0] > 0 || fNErrors[1] > 0 || fNErrors[2] > 0 ||
758 fNErrChanLen > 0 || fNErrAddress > 0) {
760 AliLog::SetPrintRepetitions(false);
761 AliWarningF("R/O errors: FMD1=%d, FMD2=%d, FMD3=%d, "
762 "Channel Length=%d, address=%d",
763 fNErrors[0], fNErrors[1], fNErrors[2],
764 fNErrChanLen, fNErrAddress);
765 AliLog::SetPrintRepetitions(true);
767 if (fVerbose && fErrors.GetEntries() > 0) {
769 Int_t nErr = fErrors.GetEntries();
770 for (Int_t i = 0; i < nErr; i++) {
771 UInt_t where = fErrors.At(i)->GetUniqueID();
772 if (i % 6 == 0) msg.Append("\n");
773 msg.Append(Form(" %3d/0x%03x", (where >> 12) & 0xFF, (where & 0xFFF)));
776 AliLog::SetPrintRepetitions(false);
777 AliWarningF("Got %d errors in channels %s", nErr, msg.Data());
778 AliLog::SetPrintRepetitions(true);
782 //____________________________________________________________________
784 AliFMDRawReader::ReadAdcs(AliFMDUShortMap& map)
786 // Read ADC values from raw input into passed TClonesArray of AliFMDDigit
788 AliDebug(3,"Reading ADC values into a map");
790 // const UShort_t kUShortMax = (1 << 16) - 1;
791 for (Int_t ddl = 0; ddl < kNDDL; ddl++) fNErrors[ddl] = 0;
793 AliAltroRawStreamV3 input(fReader);
795 input.SetCheckAltroPayload(false);
796 input.SelectRawData("FMD");
798 // Loop over input RORCs
799 while (input.NextDDL()) {
801 Int_t ddl = NewDDL(input, det);
805 while (input.NextChannel()) {
806 // Get the hardware address, and map that to detector coordinates
810 Int_t hwaddr = NewChannel(input, det, ring, sec, strbase);
811 if (hwaddr < 0) break;
812 if (hwaddr > 0xFFF) continue;
814 UShort_t start = 0x3FF;
815 Bool_t errors = false;
819 while (input.NextBunch()) {
820 // Get Lenght of bunch, and pointer to the data
821 // const UShort_t* data = input.GetSignals();
823 if (!NewBunch(input, start, length)) {
829 // Loop over the data and store it.
830 for (Int_t i = 0; i < length; i++) {
835 Int_t adc = NewSample(input, i, t, sec, strbase, str, samp);
836 if (adc < 0) continue;
837 UShort_t counts = adc;
839 AliDebugF(10, "FMD%d%c[%02d,%03d]-%d: %4d",
840 det, ring, sec, str, samp, counts);
841 if (SelectSample(samp, fSampleRate[ddl]))
842 map(det,ring,sec,str) = counts;
843 if (first < 0) first = str;
848 AliDebugF(2, "Channel %3d/0x%03x contain errors, "
849 "resetting strips %d to %d", ddl, hwaddr, first, last);
851 Int_t ds = first <= last ? 1 : -1;
852 for (Int_t i = first; i != last+ds; i += ds) {
853 AliDebugF(10, "Resetting strip FMD%d%c[%02d,%03d]=%d",
854 det,ring,sec,i,map(det,ring,sec,i));
855 map(det,ring,sec,i) = kBadSignal;
864 //____________________________________________________________________
865 Bool_t AliFMDRawReader::ReadSODevent(AliFMDCalibSampleRate* sampleRate,
866 AliFMDCalibStripRange* stripRange,
868 TArrayS &pulseLength,
872 // Read SOD event into passed objects.
875 // samplerate The sample rate object to fill
876 // striprange The strip range object to fill
877 // pulseSize The pulse size object to fill
878 // pulseLength The pulse length (in events) object to fill
881 // @c true on success
883 AliDebug(0,"Start of SOD/EOD");
885 UInt_t shift_clk[18];
886 UInt_t sample_clk[18];
887 UInt_t strip_low[18];
888 UInt_t strip_high[18];
889 UInt_t pulse_size[18];
890 UInt_t pulse_length[18];
891 for (size_t i = 0; i < 18; i++) {
899 AliFMDParameters* param = AliFMDParameters::Instance();
900 AliFMDAltroMapping* map = param->GetAltroMap();
902 AliAltroRawStreamV3 streamer(fReader);
904 streamer.SelectRawData("FMD");
905 //fReader->GetDDLID();
906 while (streamer.NextDDL()) {
907 Int_t ddl = streamer.GetDDLNumber();
908 Int_t detID = fReader->GetDetectorID();
909 if (detectors) detectors[map->DDL2Detector(ddl)-1] = kTRUE;
910 AliDebugF(0," From reader: DDL number is %d , det ID is %d",ddl,detID);
912 ULong_t nPayloadWords = streamer.GetRCUPayloadSizeInSOD();
913 UChar_t* payloadData = streamer.GetRCUPayloadInSOD();
914 UInt_t* payloadWords = reinterpret_cast<UInt_t*>(payloadData);
915 //UInt_t* payloadWords = streamer.GetRCUPayloadInSOD();
917 //std::cout<<nPayloadWords<<" "<<ddl<<std::endl;
918 for (ULong_t i = 1; i <= nPayloadWords ; i++, payloadWords++) {
919 UInt_t payloadWord = *payloadWords; // Get32bitWord(i);
921 //std::cout<<i<<Form(" word: 0x%x",payloadWord)<<std::endl;
922 // address is only 24 bit
923 UInt_t address = (0xffffff & payloadWord);
924 UInt_t type = ((address >> 21) & 0xf);
925 UInt_t error = ((address >> 20) & 0x1);
926 UInt_t bcast = ((address >> 18) & 0x1);
927 UInt_t bc_not_altro = ((address >> 17) & 0x1);
928 UInt_t board = ((address >> 12) & 0x1f);
929 UInt_t instruction = 0;
933 instruction = address & 0xfff;
935 chip = ((address >> 9) & 0x7);
936 channel = ((address >> 5) & 0x5);
937 instruction = (address & 0x1f);
940 Bool_t readDataWord = kFALSE;
942 case 0x0: // Fec read
943 readDataWord = kTRUE;
945 case 0x2: // Fec write
952 case 0x6: // End sequence
954 i = nPayloadWords + 1;
960 //Don't read unless we have a FEC_RD
961 if(!readDataWord) continue;
963 UInt_t dataWord = *payloadWords;//Get32bitWord(i);
964 UInt_t data = (0xFFFFF & dataWord) ;
965 //UInt_t data = (0xFFFF & dataWord) ;
968 AliWarningF("error bit detected at Word 0x%06x; "
969 "error % d, type %d, bc_not_altro %d, "
970 "bcast %d, board 0x%02x, chip 0x%x, "
971 "channel 0x%02x, instruction 0x%03x",
972 address, error, type, bc_not_altro,
973 bcast,board,chip,channel,instruction);
979 switch(instruction) {
981 case 0x01: break; // First ADC T
982 case 0x02: break; // I 3.3 V
983 case 0x03: break; // I 2.5 V altro digital
984 case 0x04: break; // I 2.5 V altro analog
985 case 0x05: break; // I 2.5 V VA
986 case 0x06: break; // First ADC T
987 case 0x07: break; // I 3.3 V
988 case 0x08: break; // I 2.5 V altro digital
989 case 0x09: break; // I 2.5 V altro analog
990 case 0x0A: break; // I 2.5 V VA
991 case 0x2D: break; // Second ADC T
992 case 0x2E: break; // I 1.5 V VA
993 case 0x2F: break; // I -2.0 V
994 case 0x30: break; // I -2.0 V VA
995 case 0x31: break; // 2.5 V Digital driver
996 case 0x32: break; // Second ADC T
997 case 0x33: break; // I 1.5 V VA
998 case 0x34: break; // I -2.0 V
999 case 0x35: break; // I -2.0 V VA
1000 case 0x36: break; // 2.5 V Digital driver
1001 case 0x37: break; // Third ADC T
1002 case 0x38: break; // Temperature sens. 1
1003 case 0x39: break; // Temperature sens. 2
1004 case 0x3A: break; // U 2.5 altro digital (m)
1005 case 0x3B: break; // U 2.5 altro analog (m)
1006 case 0x3C: break; // Third ADC T
1007 case 0x3D: break; // Temperature sens. 1
1008 case 0x3E: break; // Temperature sens. 2
1009 case 0x3F: break; // U 2.5 altro digital (m)
1010 case 0x40: break; // U 2.5 altro analog (m)
1011 case 0x41: break; // Forth ADC T
1012 case 0x42: break; // U 2.5 VA (m)
1013 case 0x43: break; // U 1.5 VA (m)
1014 case 0x44: break; // U -2.0 VA (m)
1015 case 0x45: break; // U -2.0 (m)
1016 case 0x46: break; // Forth ADC T
1017 case 0x47: break; // U 2.5 VA (m)
1018 case 0x48: break; // U 1.5 VA (m)
1019 case 0x49: break; // U -2.0 VA (m)
1020 case 0x4A: break; // U -2.0 (m)
1022 case 0x0B: break; // L1 trigger CouNTer
1023 case 0x0C: break; // L2 trigger CouNTer
1024 case 0x0D: break; // Sampling CLK CouNTer
1025 case 0x0E: break; // DSTB CouNTer
1027 case 0x0F: break; // Test mode word
1028 case 0x10: break; // Undersampling ratio.
1029 // Configuration and status
1030 case 0x11: break; // Config/Status Register 0
1031 case 0x12: break; // Config/Status Register 1
1032 case 0x13: break; // Config/Status Register 2
1033 case 0x14: break; // Config/Status Register 3
1034 case 0x15: break; // Free
1036 case 0x16: break; // Latch L1, L2, SCLK Counters
1037 case 0x17: break; // Clear counters
1038 case 0x18: break; // Clear CSR1
1039 case 0x19: break; // rstb ALTROs
1040 case 0x1A: break; // rstb BC
1041 case 0x1B: break; // Start conversion
1042 case 0x1C: break; // Scan event length
1043 case 0x1D: break; // Read event length
1044 case 0x1E: break; // Start test mode
1045 case 0x1F: break; // Read acquisition memory
1047 case 0x20: break; // FMDD status
1048 case 0x21: break; // L0 counters
1049 case 0x22: break; // FMD: Wait to hold
1050 case 0x23: break; // FMD: L1 timeout
1051 case 0x24: break; // FMD: L2 timeout
1052 case 0x25: // FMD: Shift clk
1053 shift_clk[board] = ((data >> 8 ) & 0xFF);
1054 AliDebugF(30, "Read shift_clk=%d for board 0x%02x",
1055 shift_clk[board], board);
1057 case 0x26: // FMD: Strips
1058 strip_low[board] = ((data >> 0 ) & 0xFF);
1059 strip_high[board] = ((data >> 8 ) & 0xFF);
1061 case 0x27: // FMD: Cal pulse
1062 pulse_size[board] = ((data >> 8 ) & 0xFF);
1064 case 0x28: break; // FMD: Shape bias
1065 case 0x29: break; // FMD: Shape ref
1066 case 0x2A: break; // FMD: Preamp ref
1067 case 0x2B: // FMD: Sample clk
1068 sample_clk[board] = ((data >> 8 ) & 0xFF);
1069 AliDebugF(30,"Read sample_clk=%d for board 0x%02x",
1070 sample_clk[board], board);
1072 case 0x2C: break; // FMD: Commands
1073 case 0x4B: // FMD: Cal events
1074 pulse_length[board] = ((data >> 0 ) & 0xFF);
1079 AliDebugF(50,"instruction 0x%x, dataword 0x%x",
1080 instruction,dataWord);
1081 } // End of loop over Result memory event
1084 UShort_t sector = 0;
1088 const UInt_t boards[4] = {0,1,16,17};
1089 for(Int_t i=0;i<4;i++) {
1090 if(ddl==0 && (i==1 || i==3)) continue;
1092 UInt_t chip =0, channel=0;
1093 det = map->DDL2Detector(ddl);
1094 map->Channel2StripBase(boards[i], chip, channel, ring, sector, strip);
1096 UInt_t samplerate = 0;
1098 if(sample_clk[boards[i]] == 0) {
1100 Int_t sample1 = sample_clk[boards[0]];
1101 Int_t sample2 = sample_clk[boards[2]];
1102 if(sample1) sample_clk[boards[i]] = sample1;
1103 else sample_clk[boards[i]] = sample2;
1106 Int_t sample1 = sample_clk[boards[0]];
1107 Int_t sample2 = sample_clk[boards[1]];
1108 Int_t sample3 = sample_clk[boards[2]];
1109 Int_t sample4 = sample_clk[boards[3]];
1110 Int_t agreement = 0;
1111 if(sample1 == sample2) agreement++;
1112 if(sample1 == sample3) agreement++;
1113 if(sample1 == sample4) agreement++;
1114 if(sample2 == sample3) agreement++;
1115 if(sample2 == sample4) agreement++;
1116 if(sample3 == sample4) agreement++;
1121 if(agreement == 3) {
1122 sample_clk[boards[i]] = sample_clk[boards[idx]];
1123 shift_clk[boards[i]] = shift_clk[boards[idx]];
1124 strip_low[boards[i]] = strip_low[boards[idx]];
1125 strip_high[boards[i]] = strip_high[boards[idx]];
1126 pulse_length[boards[i]] = pulse_length[boards[idx]];
1127 pulse_size[boards[i]] = pulse_size[boards[idx]];
1128 AliDebugF(3,"Vote taken for ddl %d, board 0x%x",
1135 if(sample_clk[boards[i]])
1136 samplerate = shift_clk[boards[i]]/sample_clk[boards[i]];
1137 AliDebugF(10,"Sample rate for board 0x%02x is %d",
1138 boards[i], samplerate);
1139 sampleRate->Set(det,ring,sector,0,samplerate);
1140 stripRange->Set(det,ring,sector,0,
1141 strip_low[boards[i]],strip_high[boards[i]]);
1143 AliDebugF(20,"det %d, ring %c, ",det,ring);
1144 pulseLength.AddAt(pulse_length[boards[i]],
1145 GetHalfringIndex(det,ring,boards[i]/16));
1146 pulseSize.AddAt(pulse_size[boards[i]],
1147 GetHalfringIndex(det,ring,boards[i]/16));
1151 AliDebugF(20,": Board: 0x%02x\n"
1152 "\tstrip_low %3d, strip_high %3d\n"
1153 "\tshift_clk %3d, sample_clk %3d\n"
1154 "\tpulse_size %3d, pulse_length %3d",
1156 strip_low[boards[i]], strip_high[boards[i]],
1157 shift_clk[boards[i]], sample_clk[boards[i]],
1158 pulse_size[boards[i]],pulse_length[boards[i]]);
1163 AliFMDParameters::Instance()->SetSampleRate(sampleRate);
1164 AliFMDParameters::Instance()->SetStripRange(stripRange);
1166 AliDebug(0,"End of SOD/EOD");
1170 //____________________________________________________________________
1172 UInt_t AliFMDRawReader::Get32bitWord(Int_t idx)
1174 // This method returns the 32 bit word at a given
1175 // position inside the raw data payload.
1176 // The 'index' points to the beginning of the next word.
1177 // The method is supposed to be endian (platform)
1180 AliFatal("Raw data paylod buffer is not yet initialized !");
1183 Int_t index = 4*idx;
1186 // fRawReader->AddFatalErrorLog(k32bitWordReadErr,Form("pos = %d",index));
1188 AliWarningF("Invalid raw data payload position (%d) !",index);
1193 word = fData[--index] << 24;
1194 word |= fData[--index] << 16;
1195 word |= fData[--index] << 8;
1196 word |= fData[--index] << 0 ;
1200 //_____________________________________________________________________
1201 Int_t AliFMDRawReader::GetHalfringIndex(UShort_t det, Char_t ring,
1202 UShort_t board) const
1205 // Get short index for a given half-ring
1208 // det Detector number
1209 // ring Ring identifer
1210 // board Board number
1215 UShort_t iring = (ring == 'I' ? 1 : 0);
1217 Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
1223 //____________________________________________________________________