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),
53 fDARCEvBlockLenght(0),
54 fDARCBlockAttributes(0),
70 fIsScEventGood(kFALSE),
75 // Create an object to read ZDC raw digits
77 fRawReader->Select("ZDC");
80 for(Int_t i=0; i<kNch; i++){
81 for(Int_t j=0; j<5; j++) fMapADC[i][j]=-1;
86 //_____________________________________________________________________________
87 AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
89 fRawReader(stream.fRawReader),
90 fBuffer(stream.GetRawBuffer()),
91 fEvType(stream.fEvType),
92 fPosition(stream.fPosition),
93 fIsCalib(stream.fIsCalib),
94 fIsDARCHeader(stream.fIsDARCHeader),
95 fIsChMapping(stream.fIsChMapping),
96 fIsADCDataWord(stream.fIsADCDataWord),
97 fIsADCHeader(stream.fIsADCHeader),
98 fIsADCEOB(stream.fIsADCEOB),
99 fSODReading(stream.fSODReading),
100 fIsMapRead(stream.fIsMapRead),
101 fDARCEvBlockLenght(stream.fDARCEvBlockLenght),
102 fDARCBlockAttributes(stream.fDARCBlockAttributes),
103 fDeadfaceOffset(stream.GetDeadfaceOffset()),
104 fDeadbeefOffset(stream.GetDeadbeefOffset()),
105 fDataOffset(stream.GetDataOffset()),
106 fModType(stream.GetModType()),
107 fADCModule(stream.GetADCModule()),
108 fADCNChannels(stream.GetADCNChannels()),
109 fADCChannel(stream.GetADCChannel()),
110 fADCValue(stream.GetADCValue()),
111 fADCGain(stream.GetADCGain()),
112 fIsUnderflow(stream.fIsUnderflow),
113 fIsOverflow(stream.fIsOverflow),
114 fScNWords(stream.GetScNWords()),
115 fScGeo(stream.GetScGeo()),
116 fScTS(stream.GetScTS()),
117 fScTriggerNumber(stream.fScTriggerNumber),
118 fIsScEventGood(stream.fIsScEventGood),
119 fNChannelsOn(stream.fNChannelsOn),
120 fNConnCh(stream.fNConnCh),
121 fCabledSignal(stream.GetCabledSignal())
125 for(Int_t j=0; j<2; j++) fSector[j] = stream.GetSector(j);
126 for(Int_t i=0; i<kNch; i++){
127 for(Int_t j=0; j<5; j++) fMapADC[i][j] = stream.fMapADC[i][j];
131 //_____________________________________________________________________________
132 AliZDCRawStream& AliZDCRawStream::operator = (const AliZDCRawStream&
135 // Assignment operator
136 Fatal("operator =", "assignment operator not implemented");
140 //_____________________________________________________________________________
141 AliZDCRawStream::~AliZDCRawStream()
147 //_____________________________________________________________________________
148 void AliZDCRawStream::ReadChMap()
150 // Reading channel map
152 printf("\n\t Reading ZDC ADC mapping from OCDB\n");
153 AliZDCChMap * chMap = GetChMap();
155 for(Int_t i=0; i<kNch; i++){
156 fMapADC[i][0] = chMap->GetADCModule(i);
157 fMapADC[i][1] = chMap->GetADCChannel(i);
159 fMapADC[i][3] = chMap->GetDetector(i);
160 fMapADC[i][4] = chMap->GetSector(i);
165 //_____________________________________________________________________________
166 void AliZDCRawStream::ReadCDHHeader()
169 const AliRawDataHeader* header = fRawReader->GetDataHeader();
171 AliError(" No CDH in raw data streaming");
172 fRawReader->AddMajorErrorLog(kCDHError);
176 //printf("\t AliZDCRawStream::ReadCDHHeader -> Data Size = %d\n",fRawReader->GetDataSize());
178 fDARCEvBlockLenght = header->fSize;
179 //printf("\t AliZDCRawStream::ReadCDHHeader -> fDARCEvBlockLenght = %d\n",fDARCEvBlockLenght);
181 UChar_t message = header->GetAttributes();
182 //printf("\t AliZDCRawStream::ReadCDHHeader -> Attributes %x\n",message);
184 if(message & 0x0){ // PHYSICS RUN
185 //printf("\t PHYSICS RUN raw data found\n");
187 else if(message & 0x10){ // COSMIC RUN
188 //printf("\t STANDALONE_COSMIC RUN raw data found\n");
190 else if(message & 0x20){ // PEDESTAL RUN
191 //printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
193 else if(message & 0x30){ // LASER RUN
194 //printf("\t STANDALONE_LASER RUN raw data found\n");
196 else if(message & 0x40){ // CALIBRATION_CENTRAL RUN
197 //printf("\t CALIBRATION_CENTRAL RUN raw data found\n");
199 else if(message & 0x50){ // CALIBRATION_SEMICENTRAL
200 //printf("\t CALIBRATION_SEMICENTRAL RUN raw data found\n");
202 else if(message & 0x60){ // CALIBRATION_MB
203 //printf("\t CALIBRATION_MB RUN raw data found\n");
205 else if(message & 0x70){ // CALIBRATION_EMD
206 //printf("\t CALIBRATION_EMD RUN raw data found\n");
209 if(header->GetL1TriggerMessage() & 0x1){ // Calibration bit set in CDH
212 //printf("\t AliZDCRawStream::ReadCDHHeader -> L1TriggerMessage %x\n",header->GetL1TriggerMessage());
213 //printf("\t AliZDCRawStream::ReadCDHHeader -> Calibration bit = %d\n",fIsCalib);
215 UInt_t status = header->GetStatus();
216 //printf("\t AliZDCRawStream::ReadCDHHeader -> status = %d\n",status);
217 if((status & 0x000f) == 0x0001){
218 AliWarning("CDH -> DARC trg0 overlap error");
219 fRawReader->AddMajorErrorLog(kDARCError);
221 if((status & 0x000f) == 0x0002){
222 AliWarning("CDH -> DARC trg0 missing error");
223 fRawReader->AddMajorErrorLog(kDARCError);
225 if((status & 0x000f) == 0x0004){
226 AliWarning("CDH -> DARC data parity error");
227 fRawReader->AddMajorErrorLog(kDARCError);
229 if((status & 0x000f) == 0x0008){
230 AliWarning("CDH -> DARC ctrl parity error");
231 fRawReader->AddMajorErrorLog(kDARCError);
234 if((status & 0x00f0) == 0x0010){
235 AliWarning("CDH -> DARC trg unavailable");
236 fRawReader->AddMajorErrorLog(kDARCError);
238 if((status & 0x00f0) == 0x0020){
239 AliWarning("CDH -> DARC FEE error");
240 fRawReader->AddMajorErrorLog(kDARCError);
243 if((status & 0x0f00) == 0x0200){
244 AliWarning("CDH -> DARC L1 time violation");
245 fRawReader->AddMajorErrorLog(kDARCError);
247 if((status & 0x0f00) == 0x0400){
248 AliWarning("CDH -> DARC L2 time-out");
249 fRawReader->AddMajorErrorLog(kDARCError);
251 if((status & 0x0f00) == 0x0800){
252 AliWarning("CDH -> DARC prepulse time violation");
253 fRawReader->AddMajorErrorLog(kDARCError);
256 if((status & 0xf000) == 0x1000){
257 AliWarning("CDH -> DARC other error");
258 fRawReader->AddMajorErrorLog(kDARCError);
262 fIsDARCHeader = kTRUE;
265 //_____________________________________________________________________________
266 Bool_t AliZDCRawStream::Next()
268 // Read the next raw digit
269 // Returns kFALSE if there is no digit left
271 if(!fRawReader->ReadNextInt((UInt_t&) fBuffer)) return kFALSE;
273 Bool_t readScaler = kFALSE;
274 fIsChMapping = kFALSE; fIsADCHeader = kFALSE;
275 fIsADCDataWord = kFALSE; fIsADCEOB = kFALSE;
276 fIsUnderflow = kFALSE;
277 fIsOverflow = kFALSE;
278 fSector[0] = fSector[1] = -1;
280 fEvType = fRawReader->GetType();
282 //printf("\n\t AliZDCRawStream::Next() -> ev. type %d\n",fEvType);
283 //printf("\n AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
286 //if(fEvType==7 || fEvType ==8){ //Physics or calibration event
293 // *** End of ZDC event
294 if(fBuffer == 0xcafefade){
295 //printf("\n-> AliZDCRawStream::Next() ***** End of ZDC event *****\n\n");
299 // -------------------------------------------
301 // -------------------------------------------
302 // If the CDH has been read then
303 // the DARC header must follow
305 //printf("\t ---- DARC header ----\n");
308 fDeadbeefOffset = 25;
315 fDataOffset = 1+fDeadbeefOffset;
316 fIsDARCHeader = kFALSE;
320 // -------------------------------------------
321 // --- Start of data event
322 // --- decoding mapping of connected ADC ch.
323 // -------------------------------------------
324 // In the SOD event ADC ch. mapping is written
325 if(fEvType==10 && fSODReading){
326 //printf("\n-> AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
328 if(fPosition>fDataOffset){
329 if((fBuffer&0xff000000) == 0xff000000){
330 if(fPosition==(fDataOffset+1)){
331 printf("\n\n\t AliZDCRawStream -> Reading mapping from StartOfData event\n");
335 //printf("\n\t AliZDCRawStream -> End of ZDC StartOfData event\n\n");
336 //printf("AliZDCRawStream: fSODReading after SOD reading set to %d\n", fSODReading);
340 else if((fBuffer&0x80000000)>>31 == 1){
341 // Mapping identification
342 fADCModule = ((fBuffer & 0x7f000000)>>24);
343 fModType = ((fBuffer & 0x7ff00)>>8);
344 fADCNChannels = (fBuffer & 0xff);
346 //printf(" ******** GEO %d, mod. type %d, #ch. %d\n",fADCModule,fModType,fADCNChannels);
348 else if(fModType==1 && (fBuffer&0x80000000)>>31 == 0){
350 if((fBuffer&0x40000000)>>30==0){ // high range chain ADC
351 fIsChMapping = kTRUE;
352 fADCChannel = ((fBuffer & 0x3fff0000)>>16);
353 fCabledSignal = (fBuffer&0xffff);
354 //printf("\tADC ch. %d, signal %d\n",fADCChannel,fCabledSignal);
356 fMapADC[fNConnCh][0] = fADCModule;
357 fMapADC[fNConnCh][1] = fADCChannel;
358 fMapADC[fNConnCh][2] = fCabledSignal;
360 // Determining detector and sector
361 // -----------------------------------------
362 // For the decoding of the following lines
363 // look the enum in AliZDCRawStream.h file
364 // -----------------------------------------
365 if((fCabledSignal>=2 && fCabledSignal<=6) || (fCabledSignal>=26 && fCabledSignal<=30)
366 || fCabledSignal==24 || fCabledSignal==48){
367 fMapADC[fNConnCh][3] = 4; //ZNA
369 if(fCabledSignal==2 || fCabledSignal==26) fMapADC[fNConnCh][4]=0;
370 else if(fCabledSignal==3 || fCabledSignal==27) fMapADC[fNConnCh][4]=1;
371 else if(fCabledSignal==4 || fCabledSignal==28) fMapADC[fNConnCh][4]=2;
372 else if(fCabledSignal==5 || fCabledSignal==29) fMapADC[fNConnCh][4]=3;
373 else if(fCabledSignal==6 || fCabledSignal==30) fMapADC[fNConnCh][4]=4;
374 else if(fCabledSignal==24 || fCabledSignal==48) fMapADC[fNConnCh][4]=5;
376 else if((fCabledSignal>=7 && fCabledSignal<=11) || (fCabledSignal>=31 && fCabledSignal<=35)){
377 fMapADC[fNConnCh][3] = 5; //ZPA
379 if(fCabledSignal==7 || fCabledSignal==31) fMapADC[fNConnCh][4]=0;
380 else if(fCabledSignal==8 || fCabledSignal==32) fMapADC[fNConnCh][4]=1;
381 else if(fCabledSignal==9 || fCabledSignal==33) fMapADC[fNConnCh][4]=2;
382 else if(fCabledSignal==10 || fCabledSignal==34) fMapADC[fNConnCh][4]=3;
383 else if(fCabledSignal==11 || fCabledSignal==35) fMapADC[fNConnCh][4]=4;
385 else if((fCabledSignal>=12 && fCabledSignal<=16) || (fCabledSignal>=36 && fCabledSignal<=40)
386 || fCabledSignal==25 || fCabledSignal==49){
387 fMapADC[fNConnCh][3] = 1; //ZNC
389 if(fCabledSignal==12 || fCabledSignal==36) fMapADC[fNConnCh][4]=0;
390 else if(fCabledSignal==13 || fCabledSignal==37) fMapADC[fNConnCh][4]=1;
391 else if(fCabledSignal==14 || fCabledSignal==38) fMapADC[fNConnCh][4]=2;
392 else if(fCabledSignal==15 || fCabledSignal==39) fMapADC[fNConnCh][4]=3;
393 else if(fCabledSignal==16 || fCabledSignal==40) fMapADC[fNConnCh][4]=4;
394 else if(fCabledSignal==25 || fCabledSignal==49) fMapADC[fNConnCh][4]=5;
396 else if((fCabledSignal>=17 && fCabledSignal<=21) || (fCabledSignal>=41 && fCabledSignal<=45)){
397 fMapADC[fNConnCh][3] = 2; //ZPC
399 if(fCabledSignal==17 || fCabledSignal==41) fMapADC[fNConnCh][4]=0;
400 else if(fCabledSignal==18 || fCabledSignal==42) fMapADC[fNConnCh][4]=1;
401 else if(fCabledSignal==19 || fCabledSignal==43) fMapADC[fNConnCh][4]=2;
402 else if(fCabledSignal==20 || fCabledSignal==44) fMapADC[fNConnCh][4]=3;
403 else if(fCabledSignal==21 || fCabledSignal==45) fMapADC[fNConnCh][4]=4;
405 else if(fCabledSignal==22 || fCabledSignal==23 || fCabledSignal==46 || fCabledSignal==47){
406 fMapADC[fNConnCh][3] = 3;
408 if(fCabledSignal==22 || fCabledSignal==46) fMapADC[fNConnCh][4]=1;
409 else if(fCabledSignal==23 || fCabledSignal==47) fMapADC[fNConnCh][4]=2;
414 // Protection manually set since it returned:
415 // RawData48 mod. 3 ch. 2048 signal 515
416 // to be checked with Pietro!!!!!!!!!!!!!!!!!!!!!!!
417 AliDebug(2," No. of cabled channels > kNch !!!");
422 }// ModType=1 (ADC mapping)
423 //else if(fModType!=1){
431 // -------------------------------------------
433 // -------------------------------------------
434 if(fPosition<fDeadfaceOffset){
438 else if(fPosition==fDeadfaceOffset){
439 if(fBuffer != 0xdeadface){
440 AliWarning(" NO deadface after DARC data");
441 fRawReader->AddMajorErrorLog(kDARCError);
449 // -------------------------------------------
450 // --- DARC global data
451 // -------------------------------------------
452 else if(fPosition>fDeadfaceOffset && fPosition<fDeadbeefOffset){
456 else if(fPosition==fDeadbeefOffset){
457 if(fBuffer != 0xdeadbeef){
458 AliWarning(" NO deadbeef after DARC global data");
459 fRawReader->AddMajorErrorLog(kDARCError);
467 // -------------------------------------------
469 // --- ADC buffer + scaler
470 // -------------------------------------------
471 else if(fPosition>=fDataOffset){
473 //printf("AliZDCRawStream: fSODReading = %d\n", fSODReading);
474 if(!fSODReading && !fIsMapRead) ReadChMap();
476 // Not valid datum before the event
477 // there MUST be a NOT valid datum before the event!!!
478 if(fPosition==fDataOffset){
479 //printf("\t **** ZDC data begin ****\n");
480 if((fBuffer & 0x07000000) != 0x06000000){
481 fRawReader->AddMajorErrorLog(kZDCDataError);
484 //printf(" AliZDCRawStream -> Not valid datum in ADC %d,"
485 // "position %d in word data buffer\n",fADCModule,fPosition);
489 // If the not valid datum isn't followed by the 1st ADC header
490 // the event is corrupted (i.e., 2 gates arrived before trigger)
491 else if(fPosition==fDataOffset+1){
492 if((fBuffer & 0x07000000) != 0x02000000){
493 AliWarning("ZDC ADC -> The not valid datum is NOT followed by an ADC header!");
494 fRawReader->AddMajorErrorLog(kZDCDataError);
498 // Get geo address of current word to determine if:
499 // - it is a scaler word (geo address == kScalerAddress)
500 // - it is an ADC word (geo address <= 3)
501 Int_t kScalerAddress=8;
502 fADCModule = ((fBuffer & 0xf8000000)>>27);
503 if(fADCModule == kScalerAddress){
506 else if(fADCModule>=0 && fADCModule<=3){//ADC modules (0,1,2,3)
508 if((fBuffer & 0x07000000) == 0x02000000){
509 fIsADCHeader = kTRUE;
510 fADCNChannels = ((fBuffer & 0x00003f00)>>8);
511 if(fADCModule==0) fNChannelsOn = fADCNChannels;
512 else fNChannelsOn += fADCNChannels;
513 //printf(" AliZDCRawStream -> ADC HEADER: mod.%d has %d ch. \n",fADCModule,fADCNChannels);
516 else if((fBuffer & 0x07000000) == 0x00000000){
517 fIsADCDataWord = kTRUE;
518 fADCChannel = ((fBuffer & 0x1e0000) >> 17);
519 fADCGain = ((fBuffer & 0x10000) >> 16);
520 fADCValue = (fBuffer & 0xfff);
522 //printf(" AliZDCRawStream -> DATA: ADC mod. %d ch. %d gain %d value %d\n",
523 // fADCModule,fADCChannel,fADCGain,fADCValue);
525 // Checking if the channel map for the ADCs has been provided/read
526 if(fMapADC[0][0]==-1){
527 printf("\t ATTENTION!!! No ADC mapping has been found/provided!!!\n");
531 /*for(Int_t ci=0; ci<kNch; ci++){
532 printf(" %d mod %d ch %d det %d sec %d\n",ci,fMapADC[ci][0],
533 fMapADC[ci][1], fMapADC[ci][3], fMapADC[ci][4]);
536 // Scan of the map to assign the correct volumes
537 Int_t foundMapEntry = kFALSE;
538 for(Int_t k=0; k<kNch; k++){
539 if(fADCModule==fMapADC[k][0] && fADCChannel==fMapADC[k][1]){
540 fSector[0] = fMapADC[k][3];
541 fSector[1] = fMapADC[k][4];
542 foundMapEntry = kTRUE;
546 if(foundMapEntry==kFALSE){
547 AliWarning(Form(" No valid entry found in ADC mapping for raw data %d ADCmod. %d ch. %d gain %d\n",
548 fPosition,fADCModule,fADCChannel,fADCGain));
551 //printf("AliZDCRawStream -> ADCmod. %d ch. %d gain %d -> det %d sec %d\n",
552 // fADCModule,fADCChannel,fADCGain,fSector[0],fSector[1]);
555 if(foundMapEntry==kTRUE){
556 if(fSector[0]<1 || fSector[0]>5){
557 AliWarning(Form(" No valid detector assignment: %d",fSector[0]));
558 fRawReader->AddMajorErrorLog(kInvalidSector);
561 if(fSector[1]<0 || fSector[1]>5){
562 AliWarning(Form(" No valid sector assignment: %d",fSector[1]));
563 fRawReader->AddMajorErrorLog(kInvalidSector);
566 if(fADCModule<0 || fADCModule>3){
567 AliError(Form(" No valid ADC module: %d",fADCModule));
568 fRawReader->AddMajorErrorLog(kInvalidADCModule);
572 // Checking the underflow and overflow bits
573 if(fBuffer & 0x1000) fIsUnderflow = kTRUE;
574 else if (fBuffer & 0x2000) fIsOverflow = kTRUE;
578 else if((fBuffer & 0x07000000) == 0x04000000){
580 //printf(" AliZDCRawStream -> EOB --------------------------\n");
591 //_____________________________________________________________________________
592 void AliZDCRawStream::DecodeScaler()
594 // Decoding scaler event
596 if(!fBuffer & 0x04000000){
597 AliWarning(" Scaler header corrupted");
598 fIsScEventGood = kFALSE;
600 Int_t scNwords = (Int_t) fScNWords;
601 if(fPosition==scNwords && fBuffer != 0x0){
602 AliWarning(" Scaler trailer corrupted");
603 fIsScEventGood = kFALSE;
605 fIsScEventGood = kTRUE;
608 fScNWords = (fBuffer & 0x00fc0000)>>18;
609 fScGeo = (fBuffer & 0xf8000000)>>27;
610 fScTS = (fBuffer & 0x00030000)>>16;
611 fScTriggerNumber = (fBuffer & 0x0000ffff);
618 //_____________________________________________________________________________
619 AliCDBStorage* AliZDCRawStream::SetStorage(const char *uri)
621 // Setting the storage
623 AliCDBStorage *storage = AliCDBManager::Instance()->GetStorage(uri);
629 //_____________________________________________________________________________
630 AliZDCChMap* AliZDCRawStream::GetChMap() const
633 // Getting calibration object for ZDC
635 AliCDBEntry *entry = AliCDBManager::Instance()->Get("ZDC/Calib/ChMap");
636 if(!entry) AliFatal("No calibration data loaded!");
638 AliZDCChMap *calibdata = dynamic_cast<AliZDCChMap*> (entry->GetObject());
639 if(!calibdata) AliFatal("Wrong calibration object in calibration file!");