55 #include "AliRawReader.h" 63 #include "AliAltroRawStreamV3.h" 66 #include <TClonesArray.h> 80 : TTask(
"FMDRawReader",
"Reader of Raw ADC values from the FMD"),
96 for (Int_t i = 0; i < 3; i++) {
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);
129 Int_t nErr =
fErrors.GetEntries();
130 TObject* o =
new (
fErrors[nErr]) TObject;
131 o->SetUniqueID((ddl & 0xFF) << 12 | (hwaddr & 0xFFF));
136 const char* format, ...)
138 static char buf[512];
140 va_start(ap, format);
141 vsnprintf(buf, 511, format, ap);
149 input.HexDumpChannel();
152 Int_t ddl = input.GetDDLNumber();
153 Int_t hwaddr = input.GetHWAddress();
155 fReader->AddMinorErrorLog(AliAltroRawStreamV3::kAltroPayloadErr,buf);
175 UInt_t ddl = input.GetDDLNumber();
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);
244 AliDebugF(3,
"We have data from newer MiniConf 0x%x",
245 ((cfg1 >> 10) & 0x8));
257 AliDebugF(10,
"Phase of DDL=%d is %g (%d)", ddl, input.GetL1Phase(),
258 input.GetAltroCFG2() & 0x1F);
259 fL1Phase[ddl] = input.GetAltroCFG2() & 0x1F;
260 AliDebugF(3,
"RCU @ DDL %d zero suppression: %s",
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);
275 if (nChLenMismatch != 0) {
277 "Got %d channels with length mis-matches for 0x%03x",
278 nChLenMismatch, ddl);
289 input.PrintRCUTrailer();
296 Char_t& ring, UShort_t& sec, Short_t& strbase)
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",
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);
338 AliDebugF(7,
"Get sample rate for RCU @ DDL %d from OCDB", ddl);
349 UShort_t& start, UShort_t& length)
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);
388 Int_t i, UShort_t t, UShort_t sec,
389 UShort_t strbase, Short_t& str, UShort_t& samp)
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);
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,
424 AliDebugF(10,
"Got presamples at timebin %d", i);
431 AliDebugF(15,
"Checking if strip %d (%d) in range [%d,%d]",
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);
447 UShort_t& str, UShort_t& sam, UShort_t& rat,
448 Short_t& adc, Bool_t& zs, UShort_t& fac)
478 static AliAltroRawStreamV3 stream(
fReader);
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;
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) {
497 stream.SelectRawData(
"FMD");
498 stream.SetCheckAltroPayload(
false);
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()) {
522 AliDebug(10,
"Last channel read was marked bad");
527 AliDebug(10,
"No next bunch, or first entry");
528 if (ddl < 0 || !stream.NextChannel()) {
532 AliDebug(10,
"No next channel, or first entry");
533 if (!stream.NextDDL()) {
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)) {
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);
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);
597 UShort_t& sec, UShort_t& str,
598 Short_t& adc, Bool_t& zs,
619 if ((ret =
NextSample(det, rng, sec, str, samp, rate, adc, zs, fac)) <= 0)
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;
652 AliDebug(3,
"Reading ADC values into a TClonesArray");
660 const UShort_t kUShortMax = (1 << 16) - 1;
667 AliAltroRawStreamV3 input(
fReader);
669 input.SetCheckAltroPayload(
false);
670 input.SelectRawData(
"FMD");
673 while (input.NextDDL()) {
675 Int_t ddl =
NewDDL(input, det);
679 while (input.NextChannel()) {
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;
693 while (input.NextBunch()) {
695 const UShort_t* data = input.GetSignals();
697 if (!
NewBunch(input, start, length)) {
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);
716 Int_t idx =
fSeen(det, ring, sec, str);
718 if (idx == kUShortMax) {
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);
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,
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++) {
761 AliWarningF(
"R/O errors: FMD1=%d, FMD2=%d, FMD3=%d, " 762 "Channel Length=%d, address=%d",
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)));
777 AliWarningF(
"Got %d errors in channels %s", nErr, msg.Data());
788 AliDebug(3,
"Reading ADC values into a map");
793 AliAltroRawStreamV3 input(
fReader);
795 input.SetCheckAltroPayload(
false);
796 input.SelectRawData(
"FMD");
799 while (input.NextDDL()) {
801 Int_t ddl =
NewDDL(input, det);
805 while (input.NextChannel()) {
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;
819 while (input.NextBunch()) {
823 if (!
NewBunch(input, start, length)) {
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);
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));
868 TArrayS &pulseLength,
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++) {
902 AliAltroRawStreamV3 streamer(
fReader);
904 streamer.SelectRawData(
"FMD");
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);
918 for (ULong_t i = 1; i <= nPayloadWords ; i++, payloadWords++) {
919 UInt_t payloadWord = *payloadWords;
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;
943 readDataWord = kTRUE;
954 i = nPayloadWords + 1;
961 if(!readDataWord)
continue;
963 UInt_t dataWord = *payloadWords;
964 UInt_t data = (0xFFFFF & dataWord) ;
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) {
1053 shift_clk[board] = ((data >> 8 ) & 0xFF);
1054 AliDebugF(30,
"Read shift_clk=%d for board 0x%02x",
1055 shift_clk[board], board);
1058 strip_low[board] = ((data >> 0 ) & 0xFF);
1059 strip_high[board] = ((data >> 8 ) & 0xFF);
1062 pulse_size[board] = ((data >> 8 ) & 0xFF);
1068 sample_clk[board] = ((data >> 8 ) & 0xFF);
1069 AliDebugF(30,
"Read sample_clk=%d for board 0x%02x",
1070 sample_clk[board], board);
1074 pulse_length[board] = ((data >> 0 ) & 0xFF);
1079 AliDebugF(50,
"instruction 0x%x, dataword 0x%x",
1080 instruction,dataWord);
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;
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]],
1146 pulseSize.AddAt(pulse_size[boards[i]],
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]]);
1180 AliFatal(
"Raw data paylod buffer is not yet initialized !");
1183 Int_t index = 4*idx;
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 ;
1202 UShort_t board)
const 1215 UShort_t iring = (ring ==
'I' ? 1 : 0);
1217 Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
Int_t NextSample(UShort_t &det, Char_t &rng, UShort_t &sec, UShort_t &str, UShort_t &sam, UShort_t &rat, Short_t &adc, Bool_t &zs, UShort_t &fac)
void ReadbackError(const AliAltroRawStreamV3 &input, const char *format,...)
Int_t GetHalfringIndex(UShort_t det, Char_t ring, UShort_t board) const
UShort_t GetMaxStrip(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
Map of an integer per strip.
virtual void Exec(Option_t *option="")
void Print(Option_t *opt="") const
UInt_t ChannelAddress(UShort_t board, UShort_t altro, UShort_t channel) const
Bool_t NewBunch(const AliAltroRawStreamV3 &input, UShort_t &start, UShort_t &length)
void Set(UShort_t det, Char_t ring, UShort_t sec, UShort_t str, UShort_t rate)
void AddError(Int_t ddl, Int_t hwaddr)
Short_t DDL2Detector(UInt_t ddl) const
This class is a singleton that handles various parameters of the FMD detectors. This class reads from...
Manager of FMD parameters.
Class to read ALTRO formated raw data from an AliRawReader object.
Per digitizer card pulser calibration.
AliFMDAltroMapping * GetAltroMap() const
void SetSampleRate(UShort_t r=2)
virtual void Reset(const UShort_t &val=UShort_t())
Bool_t fZeroSuppress[kNDDL]
Per digitizer card pulser calibration.
Per strip of unisgned shorts (16 bit) data.
#define AliWarning(message)
Per digitizer card pulser calibration.
AliFMDRawReader(AliRawReader *reader, TTree *array)
Map HW address to detector coordinates and back again.
void SetDefaultCounts(UShort_t rate)
Int_t NextSignal(UShort_t &det, Char_t &rng, UShort_t &sec, UShort_t &str, Short_t &adc, Bool_t &zs, UShort_t &fac)
void SetStripRange(UShort_t min=0, UShort_t max=127)
UShort_t fNoiseFactor[kNDDL]
static Bool_t SelectSample(UShort_t samp, UShort_t rate)
UInt_t Get32bitWord(Int_t idx)
Bool_t Channel2StripBase(UShort_t board, UShort_t altro, UShort_t chan, Char_t &ring, UShort_t &sec, Short_t &str) const
UShort_t fSampleRate[kNDDL]
Pointer to raw reader.
AliRawReader * fReader
Pointer to tree to read into.
Class that encodes a map to/from ALTRO hardware address to FMD detector coordinates.
virtual Bool_t ReadAdcs(TClonesArray *array)
virtual Bool_t ReadSODevent(AliFMDCalibSampleRate *samplerate, AliFMDCalibStripRange *striprange, TArrayS &pulseSize, TArrayS &pulseLength, Bool_t *detectors=0)
static AliFMDParameters * Instance()
void Set(UShort_t det, Char_t ring, UShort_t sec, UShort_t str, UShort_t min, UShort_t max)
#define AliWarningF(message,...)
#define AliFatal(message)
const char * GetName() const
#define AliDebug(logLevel, message)
Per digitizer card pulser calibration.
Int_t NewChannel(const AliAltroRawStreamV3 &input, UShort_t det, Char_t &ring, UShort_t &sec, Short_t &strbase)
UShort_t GetPreSamples(UShort_t, Char_t, UShort_t, UShort_t) const
static void SetPrintRepetitions(Bool_t on)
static Int_t GetDebugLevel(const char *module, const char *className)
void Timebin2Strip(UShort_t sec, UShort_t timebin, UShort_t preSamples, UShort_t sampleRate, Short_t &strip, UShort_t &sample) const
#define AliError(message)
Int_t NewDDL(AliAltroRawStreamV3 &input, UShort_t &det)
#define AliErrorF(message,...)
#define AliDebugF(logLevel, format,...)
UShort_t GetSampleRate(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
void SetCount(UShort_t s, Short_t c)
Int_t NewSample(const AliAltroRawStreamV3 &input, Int_t i, UShort_t t, UShort_t sec, UShort_t strbase, Short_t &str, UShort_t &samp)
UShort_t GetMinStrip(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const