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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // This class provides access to ZDC digits in raw data. //
22 // It loops over all ZDC digits in the raw data given by the AliRawReader. //
23 // The Next method goes to the next digit. If there are no digits left //
24 // it returns kFALSE. //
25 // Getters provide information about the current digit. //
27 ///////////////////////////////////////////////////////////////////////////////
30 #include "AliZDCRawStream.h"
31 #include "AliRawReader.h"
32 #include "AliRawDataHeader.h"
33 #include "AliRawEventHeaderBase.h"
36 ClassImp(AliZDCRawStream)
39 //_____________________________________________________________________________
40 AliZDCRawStream::AliZDCRawStream(AliRawReader* rawReader) :
41 fRawReader(rawReader),
46 fIsDARCHeader(kFALSE),
48 fIsADCDataWord(kFALSE),
51 fDARCEvBlockLenght(0),
52 fDARCBlockAttributes(0),
66 fIsScEventGood(kFALSE),
70 // Create an object to read ZDC raw digits
72 fRawReader->Select("ZDC");
74 for(Int_t i=0; i<48; i++){
75 for(Int_t j=0; j<5; j++) fMapADC[i][j]=-1;
80 //_____________________________________________________________________________
81 AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
83 fRawReader(stream.fRawReader),
84 fBuffer(stream.GetRawBuffer()),
85 fEvType(stream.fEvType),
86 fPosition(stream.fPosition),
87 fIsCalib(stream.fIsCalib),
88 fIsDARCHeader(stream.fIsDARCHeader),
89 fIsChMapping(stream.fIsChMapping),
90 fIsADCDataWord(stream.fIsADCDataWord),
91 fIsADCHeader(stream.fIsADCHeader),
92 fIsADCEOB(stream.fIsADCEOB),
93 fDARCEvBlockLenght(stream.fDARCEvBlockLenght),
94 fDARCBlockAttributes(stream.fDARCBlockAttributes),
95 fDeadfaceOffset(stream.GetDeadfaceOffset()),
96 fDeadbeefOffset(stream.GetDeadbeefOffset()),
97 fDataOffset(stream.GetDataOffset()),
98 fModType(stream.GetModType()),
99 fADCModule(stream.GetADCModule()),
100 fADCNChannels(stream.GetADCNChannels()),
101 fADCChannel(stream.GetADCChannel()),
102 fADCValue(stream.GetADCValue()),
103 fADCGain(stream.GetADCGain()),
104 fScNWords(stream.GetScNWords()),
105 fScGeo(stream.GetScGeo()),
106 fScTS(stream.GetScTS()),
107 fScTriggerNumber(stream.fScTriggerNumber),
108 fIsScEventGood(stream.fIsScEventGood),
109 fNConnCh(stream.fNConnCh),
110 fCabledSignal(stream.GetCabledSignal())
113 for(Int_t j=0; j<2; j++) fSector[j] = stream.GetSector(j);
114 for(Int_t i=0; i<48; i++){
115 for(Int_t j=0; j<5; j++) fMapADC[i][j] = stream.fMapADC[i][j];
119 //_____________________________________________________________________________
120 AliZDCRawStream& AliZDCRawStream::operator = (const AliZDCRawStream&
123 // Assignment operator
124 Fatal("operator =", "assignment operator not implemented");
128 //_____________________________________________________________________________
129 AliZDCRawStream::~AliZDCRawStream()
135 //_____________________________________________________________________________
136 void AliZDCRawStream::ReadChMap()
138 // Reading channel map
141 //_____________________________________________________________________________
142 void AliZDCRawStream::ReadCDHHeader()
145 const AliRawDataHeader* header = fRawReader->GetDataHeader();
147 AliError("\t No CDH in raw data streaming\n");
148 fRawReader->AddMajorErrorLog(kCDHError);
150 // For the moment to debug the classe the event is read
151 // also if the CDH is not present in the data buffer
152 // ******* TO BE CHANGED!!! ***************************
156 //printf("\t AliZDCRawStream::ReadCDHHeader -> Data Size = %d\n",fRawReader->GetDataSize());
158 fDARCEvBlockLenght = header->fSize;
159 //printf("\t AliZDCRawStream::ReadCDHHeader -> fDARCEvBlockLenght = %d\n",fDARCEvBlockLenght);
161 //UChar_t message = header->GetAttributes();
162 //printf("\t AliZDCRawStream::ReadCDHHeader -> Attributes %x\n",message);
164 /*if(message & 0x10){ // COSMIC RUN
165 printf("\t STANDALONE_COSMIC RUN raw data found\n");
167 else if(message & 0x20){ // PEDESTAL RUN
168 printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
170 else if(message & 0x30){ // LASER RUN
171 printf("\t STANDALONE_LASER RUN raw data found\n");
174 if(header->GetL1TriggerMessage() & 0x1){ // Calibration bit set in CDH
177 //printf("\t AliZDCRawStream::ReadCDHHeader -> L1TriggerMessage %x\n",header->GetL1TriggerMessage());
178 //printf("\t AliZDCRawStream::ReadCDHHeader -> Calibration bit = %d\n",fIsCalib);
180 UInt_t status = header->GetStatus();
181 //printf("\t AliZDCRawStream::ReadCDHHeader -> status = %d\n",status);
182 if(status & 0x000f == 0x0001){
183 AliWarning("CDH -> DARC trg0 overlap error\n");
184 fRawReader->AddMajorErrorLog(kDARCError);
186 if(status & 0x000f == 0x0002){
187 AliWarning("CDH -> DARC trg0 missing error\n");
188 fRawReader->AddMajorErrorLog(kDARCError);
190 if(status & 0x000f == 0x0004){
191 AliWarning("CDH -> DARC data parity error\n");
192 fRawReader->AddMajorErrorLog(kDARCError);
194 if(status & 0x000f == 0x0008){
195 AliWarning("CDH -> DARC ctrl parity error\n");
196 fRawReader->AddMajorErrorLog(kDARCError);
199 if(status & 0x00f0 == 0x0010){
200 AliWarning("CDH -> DARC trg unavailable\n");
201 fRawReader->AddMajorErrorLog(kDARCError);
203 if(status & 0x00f0 == 0x0020){
204 AliWarning("CDH -> DARC FEE error\n");
205 fRawReader->AddMajorErrorLog(kDARCError);
208 if(status & 0x0f00 == 0x0200){
209 AliWarning("CDH -> DARC L1 time violation\n");
210 fRawReader->AddMajorErrorLog(kDARCError);
212 if(status & 0x0f00 == 0x0400){
213 AliWarning("CDH -> DARC L2 time-out\n");
214 fRawReader->AddMajorErrorLog(kDARCError);
216 if(status & 0x0f00 == 0x0800){
217 AliWarning("CDH -> DARC prepulse time violation\n");
218 fRawReader->AddMajorErrorLog(kDARCError);
221 if(status & 0xf000 == 0x1000){
222 AliWarning("CDH -> DARC other error\n");
223 fRawReader->AddMajorErrorLog(kDARCError);
227 fIsDARCHeader = kTRUE;
230 //_____________________________________________________________________________
231 Bool_t AliZDCRawStream::Next()
233 // Read the next raw digit
234 // Returns kFALSE if there is no digit left
236 if(!fRawReader->ReadNextInt((UInt_t&) fBuffer)) return kFALSE;
237 fIsChMapping = kFALSE; fIsADCHeader = kFALSE;
238 fIsADCDataWord = kFALSE; fIsADCEOB = kFALSE;
240 fEvType = fRawReader->GetType();
241 //printf("\n\t AliZDCRawStream::Next() -> ev. type %d\n",fEvType);
244 //if(fEvType==7 || fEvType ==8){ //Physics or calibration event
250 //printf("\n AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
252 // -------------------------------------------
254 // -------------------------------------------
256 //printf("\t ---- DARC header ----\n");
259 fDeadbeefOffset = 25;
265 fDataOffset = 1+fDeadbeefOffset;
266 fIsDARCHeader = kFALSE;
270 // -------------------------------------------
271 // --- Start of data event
272 // --- decoding mapping of connected ADC ch.
273 // -------------------------------------------
275 if(fPosition>fDataOffset){
276 if((fBuffer&0xff000000) == 0xff000000){
277 if(fPosition==(fDataOffset+1)){
278 printf("\n\n\t Reading ZDC mapping from StartOfData event\n");
282 //printf("\n\t End of StartOfData event\n\n");
286 else if((fBuffer&0x80000000)>>31 == 1){
287 // Mapping identification
288 fADCModule = ((fBuffer & 0x7f000000)>>24);
289 fModType = ((fBuffer & 0xfff000)>>8);
290 fADCNChannels = (fBuffer & 0xff);
292 //printf("\tGEO %d, mod. type %d, #ch. %d\n",fADCModule,fModType,fADCNChannels);
294 else if(fModType==0 && (fBuffer&0x80000000)>>31 == 0){
296 if((fBuffer&0x40000000)>>30==0){ // high range chain ADC
297 fIsChMapping = kTRUE;
298 fADCChannel = ((fBuffer & 0x3fff0000)>>16);
299 fCabledSignal = (fBuffer&0xffff);
300 fMapADC[fNConnCh][0] = fADCModule;
301 fMapADC[fNConnCh][1] = fADCChannel;
302 fMapADC[fNConnCh][2] = fCabledSignal;
304 // Determining detector and sector
305 // -----------------------------------------
306 // For the decoding of the following lines
307 // look the enum in AliZDCRawStream.h file
308 // -----------------------------------------
309 if((fCabledSignal>=2 && fCabledSignal<=6) || (fCabledSignal>=26 && fCabledSignal<=30)
310 || fCabledSignal==24 || fCabledSignal==48){
311 fMapADC[fNConnCh][3] = 4; //ZNA
313 if(fCabledSignal==2 || fCabledSignal==26) fMapADC[fNConnCh][4]=0;
314 else if(fCabledSignal==3 || fCabledSignal==27) fMapADC[fNConnCh][4]=1;
315 else if(fCabledSignal==4 || fCabledSignal==28) fMapADC[fNConnCh][4]=2;
316 else if(fCabledSignal==5 || fCabledSignal==29) fMapADC[fNConnCh][4]=3;
317 else if(fCabledSignal==6 || fCabledSignal==30) fMapADC[fNConnCh][4]=4;
318 else if(fCabledSignal==24 || fCabledSignal==48) fMapADC[fNConnCh][4]=5;
320 else if((fCabledSignal>=7 && fCabledSignal<=11) || (fCabledSignal>=31 && fCabledSignal<=35)){
321 fMapADC[fNConnCh][3] = 5; //ZPA
323 if(fCabledSignal==7 || fCabledSignal==31) fMapADC[fNConnCh][4]=0;
324 else if(fCabledSignal==8 || fCabledSignal==32) fMapADC[fNConnCh][4]=1;
325 else if(fCabledSignal==9 || fCabledSignal==33) fMapADC[fNConnCh][4]=2;
326 else if(fCabledSignal==10 || fCabledSignal==34) fMapADC[fNConnCh][4]=3;
327 else if(fCabledSignal==11 || fCabledSignal==35) fMapADC[fNConnCh][4]=4;
329 else if((fCabledSignal>=12 && fCabledSignal<=16) || (fCabledSignal>=36 && fCabledSignal<=40)
330 || fCabledSignal==25 || fCabledSignal==49){
331 fMapADC[fNConnCh][3] = 1; //ZNC
333 if(fCabledSignal==12 || fCabledSignal==36) fMapADC[fNConnCh][4]=0;
334 else if(fCabledSignal==13 || fCabledSignal==37) fMapADC[fNConnCh][4]=1;
335 else if(fCabledSignal==14 || fCabledSignal==38) fMapADC[fNConnCh][4]=2;
336 else if(fCabledSignal==15 || fCabledSignal==39) fMapADC[fNConnCh][4]=3;
337 else if(fCabledSignal==16 || fCabledSignal==40) fMapADC[fNConnCh][4]=4;
338 else if(fCabledSignal==25 || fCabledSignal==49) fMapADC[fNConnCh][4]=5;
340 else if((fCabledSignal>=17 && fCabledSignal<=21) || (fCabledSignal>=41 && fCabledSignal<=45)){
341 fMapADC[fNConnCh][3] = 2; //ZPC
343 if(fCabledSignal==17 || fCabledSignal==41) fMapADC[fNConnCh][4]=0;
344 else if(fCabledSignal==18 || fCabledSignal==42) fMapADC[fNConnCh][4]=1;
345 else if(fCabledSignal==19 || fCabledSignal==43) fMapADC[fNConnCh][4]=2;
346 else if(fCabledSignal==20 || fCabledSignal==44) fMapADC[fNConnCh][4]=3;
347 else if(fCabledSignal==21 || fCabledSignal==45) fMapADC[fNConnCh][4]=4;
349 else if(fCabledSignal==22 || fCabledSignal==23 || fCabledSignal==46 || fCabledSignal==47){
350 fMapADC[fNConnCh][3] = 3;
352 if(fCabledSignal==22 || fCabledSignal==46) fMapADC[fNConnCh][4]=1;
353 else if(fCabledSignal==23 || fCabledSignal==47) fMapADC[fNConnCh][4]=2;
356 //printf("AliZDCRawStream -> datum %d mod. %d ch. %d signal %d, det %d, tow %d\n",
357 // fNConnCh,fADCModule,fADCChannel,fBuffer&0xffff,fMapADC[fNConnCh][3],fMapADC[fNConnCh][4]);
361 // Protection manually set since it returns:
362 // RawData48 mod. 3 ch. 2048 signal 515
363 // to be checked with Pietro!!!!!!!!!!!!!!!!!!!!!!!
364 //AliWarning("\t AliZDCRawStream -> ERROR: no. of cabled channels > 48!!!\n");
374 // -------------------------------------------
376 // -------------------------------------------
377 if(fPosition<fDeadfaceOffset){
381 else if(fPosition==fDeadfaceOffset){
382 if(fBuffer != 0xdeadface){
383 AliWarning("AliZDCRawStream -> NO deadface after DARC data\n");
384 fRawReader->AddMajorErrorLog(kDARCError);
392 // -------------------------------------------
393 // --- DARC global data
394 // -------------------------------------------
395 else if(fPosition>fDeadfaceOffset && fPosition<fDeadbeefOffset){
399 else if(fPosition==fDeadbeefOffset){
400 if(fBuffer != 0xdeadbeef){
401 AliWarning("AliZDCRawStream -> NO deadbeef after DARC global data\n");
402 fRawReader->AddMajorErrorLog(kDARCError);
410 // -------------------------------------------
412 // --- ADC buffer + scaler
413 // -------------------------------------------
414 else if(fPosition>=fDataOffset){
416 // Not valid datum before the event
417 // there MUST be a NOT valid datum before the event!!!
418 if(fPosition==fDataOffset){
419 //printf("\t **** ZDC data begin ****\n");
420 if((fBuffer & 0x07000000) == 0x06000000){
421 //printf(" AliZDCRawStream -> Not valid datum in ADC %d,"
422 // "position %d in word data buffer\n",fADCModule,fPosition);
424 else fRawReader->AddMajorErrorLog(kZDCDataError);
427 // If the not valid datum isn't followed by the 1st ADC header
428 // the event is corrupted (i.e., 2 gates arrived before trigger)
429 else if(fPosition==fDataOffset+1){
430 if((fBuffer & 0x07000000) != 0x02000000){
431 AliWarning("ZDC ADC -> The not valid datum is NOT followed by an ADC header!\n");
432 fRawReader->AddMajorErrorLog(kZDCDataError);
436 // Get geo address of current word to determine
437 // if it is a scaler word (geo address == kScalerAddress)
438 // if it is an ADC word (geo address != 8)
439 Int_t kScalerAddress=8;
440 fADCModule = ((fBuffer & 0xf8000000)>>27);
441 if(fADCModule == kScalerAddress){
446 if(fBuffer == 0xcafefade){
447 //printf(" AliZDCRawStream -> End of ZDC event!\n");
450 else if((fBuffer & 0x07000000) == 0x02000000){
451 fIsADCHeader = kTRUE;
452 fADCNChannels = ((fBuffer & 0x00003f00)>>8);
453 //printf(" AliZDCRawStream -> HEADER: ADC mod.%d has %d ch. \n",fADCModule,fADCNChannels);
456 else if((fBuffer & 0x07000000) == 0x00000000){
457 fIsADCDataWord = kTRUE;
458 fADCChannel = ((fBuffer & 0x1e0000) >> 17);
459 fADCGain = ((fBuffer & 0x10000) >> 16);
460 fADCValue = (fBuffer & 0xfff);
462 //printf(" AliZDCRawStream -> DATA: ADC mod. %d ch. %d gain %d value %d\n",
463 // fADCModule,fADCChannel,fADCGain,fADCValue);
465 // Valid ADC data (not underflow nor overflow)
466 if(!(fBuffer & 0x1000) && !(fBuffer & 0x2000)){
468 // Checking if the channel map for the ADCs has been provided/read
469 if(fMapADC[0][0]==-1){
470 // Temporary solution (to be changed!!!!)
471 //printf("\t ATTENTION!!! No ADC mapping has been found/provided!!!\n");
473 char * mapFileName=gSystem->ExpandPathName("$ALICE_ROOT/ZDC/ShuttleInput/ZDCChMapping.dat");
476 if((file = fopen(mapFileName,"r")) != NULL){
477 for(Int_t j=0; j<48; j++){
478 for(Int_t k=0; k<6; k++){
479 fscanf(file,"%d",&ival[j][k]);
481 fMapADC[j][0] = ival[j][1];
482 fMapADC[j][1] = ival[j][2];
483 fMapADC[j][2] = ival[j][3];
484 fMapADC[j][3] = ival[j][4];
485 fMapADC[j][4] = ival[j][5];
489 printf("File %s not found\n",mapFileName);
495 //printf("\n Reading map!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
496 /*for(Int_t ci=0; ci<48; ci++){
497 printf(" %d mod. %d ch. %d signal %d\n",ci,fMapADC[ci][0],
498 fMapADC[ci][1], fMapADC[ci][2]);
501 for(Int_t k=0; k<48; k++){
502 if(fADCModule==fMapADC[k][0] && fADCChannel==fMapADC[k][1]){
503 fSector[0] = fMapADC[k][3];
504 fSector[1] = fMapADC[k][4];
509 //printf("AliZDCRawStream -> ADCmod. %d ADCch %d det %d, sec %d\n",
510 // fADCModule,fADCChannel,fSector[0],fSector[1]);
512 if(fADCModule<0 || fADCModule>3){
513 AliWarning(Form(" AliZDCRawStream -> No valid ADC module: %d\n",fADCModule));
514 fRawReader->AddMajorErrorLog(kInvalidADCModule);
517 }//No underflow nor overflow
520 else if((fBuffer & 0x07000000) == 0x04000000){
522 //printf(" AliZDCRawStream -> EOB --------------------------\n");
533 //_____________________________________________________________________________
534 void AliZDCRawStream::DecodeScaler()
536 // Decoding scaler event
538 if(!fBuffer & 0x04000000){
539 AliWarning(" AliZDCRawStream -> Scaler header corrupted\n");
540 fIsScEventGood = kFALSE;
542 Int_t scNwords = (Int_t) fScNWords;
543 if(fPosition==scNwords && fBuffer != 0x0){
544 AliWarning(" AliZDCRawStream -> Scaler trailer corrupted\n");
545 fIsScEventGood = kFALSE;
547 fIsScEventGood = kTRUE;
550 fScNWords = (fBuffer & 0x00fc0000)>>18;
551 fScGeo = (fBuffer & 0xf8000000)>>27;
552 fScTS = (fBuffer & 0x00030000)>>16;
553 fScTriggerNumber = (fBuffer & 0x0000ffff);