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");
79 for(Int_t i=0; i<fNChannelsOn; i++){
80 for(Int_t j=0; j<5; j++) fMapADC[i][j]=-1;
85 //_____________________________________________________________________________
86 AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
88 fRawReader(stream.fRawReader),
89 fBuffer(stream.GetRawBuffer()),
90 fEvType(stream.fEvType),
91 fPosition(stream.fPosition),
92 fIsCalib(stream.fIsCalib),
93 fIsDARCHeader(stream.fIsDARCHeader),
94 fIsChMapping(stream.fIsChMapping),
95 fIsADCDataWord(stream.fIsADCDataWord),
96 fIsADCHeader(stream.fIsADCHeader),
97 fIsADCEOB(stream.fIsADCEOB),
98 fSODReading(stream.fSODReading),
99 fIsMapRead(stream.fIsMapRead),
100 fDARCEvBlockLenght(stream.fDARCEvBlockLenght),
101 fDARCBlockAttributes(stream.fDARCBlockAttributes),
102 fDeadfaceOffset(stream.GetDeadfaceOffset()),
103 fDeadbeefOffset(stream.GetDeadbeefOffset()),
104 fDataOffset(stream.GetDataOffset()),
105 fModType(stream.GetModType()),
106 fADCModule(stream.GetADCModule()),
107 fADCNChannels(stream.GetADCNChannels()),
108 fADCChannel(stream.GetADCChannel()),
109 fADCValue(stream.GetADCValue()),
110 fADCGain(stream.GetADCGain()),
111 fIsUnderflow(stream.fIsUnderflow),
112 fIsOverflow(stream.fIsOverflow),
113 fScNWords(stream.GetScNWords()),
114 fScGeo(stream.GetScGeo()),
115 fScTS(stream.GetScTS()),
116 fScTriggerNumber(stream.fScTriggerNumber),
117 fIsScEventGood(stream.fIsScEventGood),
118 fNChannelsOn(stream.fNChannelsOn),
119 fNConnCh(stream.fNConnCh),
120 fCabledSignal(stream.GetCabledSignal())
123 for(Int_t j=0; j<2; j++) fSector[j] = stream.GetSector(j);
124 for(Int_t i=0; i<fNChannelsOn; i++){
125 for(Int_t j=0; j<5; j++) fMapADC[i][j] = stream.fMapADC[i][j];
129 //_____________________________________________________________________________
130 AliZDCRawStream& AliZDCRawStream::operator = (const AliZDCRawStream&
133 // Assignment operator
134 Fatal("operator =", "assignment operator not implemented");
138 //_____________________________________________________________________________
139 AliZDCRawStream::~AliZDCRawStream()
145 //_____________________________________________________________________________
146 void AliZDCRawStream::ReadChMap()
148 // Reading channel map
149 printf("\n\t Reading ADC mapping from OCDB\n");
150 AliZDCChMap * chMap = GetChMap();
152 for(Int_t i=0; i<fNChannelsOn; i++){
153 fMapADC[i][0] = chMap->GetADCModule(i);
154 fMapADC[i][1] = chMap->GetADCChannel(i);
156 fMapADC[i][3] = chMap->GetDetector(i);
157 fMapADC[i][4] = chMap->GetSector(i);
162 //_____________________________________________________________________________
163 void AliZDCRawStream::ReadCDHHeader()
166 const AliRawDataHeader* header = fRawReader->GetDataHeader();
168 AliError(" No CDH in raw data streaming");
169 fRawReader->AddMajorErrorLog(kCDHError);
173 //printf("\t AliZDCRawStream::ReadCDHHeader -> Data Size = %d\n",fRawReader->GetDataSize());
175 fDARCEvBlockLenght = header->fSize;
176 //printf("\t AliZDCRawStream::ReadCDHHeader -> fDARCEvBlockLenght = %d\n",fDARCEvBlockLenght);
178 UChar_t message = header->GetAttributes();
179 //printf("\t AliZDCRawStream::ReadCDHHeader -> Attributes %x\n",message);
181 if(message & 0x10){ // COSMIC RUN
182 printf("\t STANDALONE_COSMIC RUN raw data found\n");
184 else if(message & 0x20){ // PEDESTAL RUN
185 printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
187 else if(message & 0x30){ // LASER RUN
188 printf("\t STANDALONE_LASER RUN raw data found\n");
191 if(header->GetL1TriggerMessage() & 0x1){ // Calibration bit set in CDH
194 //printf("\t AliZDCRawStream::ReadCDHHeader -> L1TriggerMessage %x\n",header->GetL1TriggerMessage());
195 //printf("\t AliZDCRawStream::ReadCDHHeader -> Calibration bit = %d\n",fIsCalib);
197 UInt_t status = header->GetStatus();
198 //printf("\t AliZDCRawStream::ReadCDHHeader -> status = %d\n",status);
199 if((status & 0x000f) == 0x0001){
200 AliWarning("CDH -> DARC trg0 overlap error");
201 fRawReader->AddMajorErrorLog(kDARCError);
203 if((status & 0x000f) == 0x0002){
204 AliWarning("CDH -> DARC trg0 missing error");
205 fRawReader->AddMajorErrorLog(kDARCError);
207 if((status & 0x000f) == 0x0004){
208 AliWarning("CDH -> DARC data parity error");
209 fRawReader->AddMajorErrorLog(kDARCError);
211 if((status & 0x000f) == 0x0008){
212 AliWarning("CDH -> DARC ctrl parity error");
213 fRawReader->AddMajorErrorLog(kDARCError);
216 if((status & 0x00f0) == 0x0010){
217 AliWarning("CDH -> DARC trg unavailable");
218 fRawReader->AddMajorErrorLog(kDARCError);
220 if((status & 0x00f0) == 0x0020){
221 AliWarning("CDH -> DARC FEE error");
222 fRawReader->AddMajorErrorLog(kDARCError);
225 if((status & 0x0f00) == 0x0200){
226 AliWarning("CDH -> DARC L1 time violation");
227 fRawReader->AddMajorErrorLog(kDARCError);
229 if((status & 0x0f00) == 0x0400){
230 AliWarning("CDH -> DARC L2 time-out");
231 fRawReader->AddMajorErrorLog(kDARCError);
233 if((status & 0x0f00) == 0x0800){
234 AliWarning("CDH -> DARC prepulse time violation");
235 fRawReader->AddMajorErrorLog(kDARCError);
238 if((status & 0xf000) == 0x1000){
239 AliWarning("CDH -> DARC other error");
240 fRawReader->AddMajorErrorLog(kDARCError);
244 fIsDARCHeader = kTRUE;
247 //_____________________________________________________________________________
248 Bool_t AliZDCRawStream::Next()
250 // Read the next raw digit
251 // Returns kFALSE if there is no digit left
253 if(!fRawReader->ReadNextInt((UInt_t&) fBuffer)) return kFALSE;
254 fIsChMapping = kFALSE; fIsADCHeader = kFALSE;
255 fIsADCDataWord = kFALSE; fIsADCEOB = kFALSE;
256 fIsUnderflow = kFALSE;
257 fIsOverflow = kFALSE;
258 fSector[0]=fSector[1] = -1;
260 fEvType = fRawReader->GetType();
261 //printf("\n\t AliZDCRawStream::Next() -> ev. type %d\n",fEvType);
262 //printf("\n AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
265 //if(fEvType==7 || fEvType ==8){ //Physics or calibration event
272 // *** End of ZDC event
273 if(fBuffer == 0xcafefade){
274 //printf("\n-> AliZDCRawStream::Next() ***** End of ZDC event *****\n\n");
278 // -------------------------------------------
280 // -------------------------------------------
281 // If the CDH has been read then
282 // the DARC header must follow
284 //printf("\t ---- DARC header ----\n");
287 fDeadbeefOffset = 25;
293 fDataOffset = 1+fDeadbeefOffset;
294 fIsDARCHeader = kFALSE;
298 // -------------------------------------------
299 // --- Start of data event
300 // --- decoding mapping of connected ADC ch.
301 // -------------------------------------------
302 // In the SOD event ADC ch. mapping is written
303 if(fEvType==10 && fSODReading){
304 //printf("\n-> AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
306 if(fPosition>fDataOffset){
307 if((fBuffer&0xff000000) == 0xff000000){
308 if(fPosition==(fDataOffset+1)){
309 printf("\n\n\t AliZDCRawStream -> Reading mapping from StartOfData event\n");
313 printf("\n\t AliZDCRawStream -> End of ZDC StartOfData event\n\n");
314 //printf("AliZDCRawStream: fSODReading after SOD reading set to %d\n", fSODReading);
318 else if((fBuffer&0x80000000)>>31 == 1){
319 // Mapping identification
320 fADCModule = ((fBuffer & 0x7f000000)>>24);
321 fModType = ((fBuffer & 0x7ff00)>>8);
322 fADCNChannels = (fBuffer & 0xff);
324 //printf(" ******** GEO %d, mod. type %d, #ch. %d\n",fADCModule,fModType,fADCNChannels);
326 else if(fModType==1 && (fBuffer&0x80000000)>>31 == 0){
328 if((fBuffer&0x40000000)>>30==0){ // high range chain ADC
329 fIsChMapping = kTRUE;
330 fADCChannel = ((fBuffer & 0x3fff0000)>>16);
331 fCabledSignal = (fBuffer&0xffff);
332 //printf("\tADC ch. %d, signal %d\n",fADCChannel,fCabledSignal);
334 fMapADC[fNConnCh][0] = fADCModule;
335 fMapADC[fNConnCh][1] = fADCChannel;
336 fMapADC[fNConnCh][2] = fCabledSignal;
338 // Determining detector and sector
339 // -----------------------------------------
340 // For the decoding of the following lines
341 // look the enum in AliZDCRawStream.h file
342 // -----------------------------------------
343 if((fCabledSignal>=2 && fCabledSignal<=6) || (fCabledSignal>=26 && fCabledSignal<=30)
344 || fCabledSignal==24 || fCabledSignal==48){
345 fMapADC[fNConnCh][3] = 4; //ZNA
347 if(fCabledSignal==2 || fCabledSignal==26) fMapADC[fNConnCh][4]=0;
348 else if(fCabledSignal==3 || fCabledSignal==27) fMapADC[fNConnCh][4]=1;
349 else if(fCabledSignal==4 || fCabledSignal==28) fMapADC[fNConnCh][4]=2;
350 else if(fCabledSignal==5 || fCabledSignal==29) fMapADC[fNConnCh][4]=3;
351 else if(fCabledSignal==6 || fCabledSignal==30) fMapADC[fNConnCh][4]=4;
352 else if(fCabledSignal==24 || fCabledSignal==48) fMapADC[fNConnCh][4]=5;
354 else if((fCabledSignal>=7 && fCabledSignal<=11) || (fCabledSignal>=31 && fCabledSignal<=35)){
355 fMapADC[fNConnCh][3] = 5; //ZPA
357 if(fCabledSignal==7 || fCabledSignal==31) fMapADC[fNConnCh][4]=0;
358 else if(fCabledSignal==8 || fCabledSignal==32) fMapADC[fNConnCh][4]=1;
359 else if(fCabledSignal==9 || fCabledSignal==33) fMapADC[fNConnCh][4]=2;
360 else if(fCabledSignal==10 || fCabledSignal==34) fMapADC[fNConnCh][4]=3;
361 else if(fCabledSignal==11 || fCabledSignal==35) fMapADC[fNConnCh][4]=4;
363 else if((fCabledSignal>=12 && fCabledSignal<=16) || (fCabledSignal>=36 && fCabledSignal<=40)
364 || fCabledSignal==25 || fCabledSignal==49){
365 fMapADC[fNConnCh][3] = 1; //ZNC
367 if(fCabledSignal==12 || fCabledSignal==36) fMapADC[fNConnCh][4]=0;
368 else if(fCabledSignal==13 || fCabledSignal==37) fMapADC[fNConnCh][4]=1;
369 else if(fCabledSignal==14 || fCabledSignal==38) fMapADC[fNConnCh][4]=2;
370 else if(fCabledSignal==15 || fCabledSignal==39) fMapADC[fNConnCh][4]=3;
371 else if(fCabledSignal==16 || fCabledSignal==40) fMapADC[fNConnCh][4]=4;
372 else if(fCabledSignal==25 || fCabledSignal==49) fMapADC[fNConnCh][4]=5;
374 else if((fCabledSignal>=17 && fCabledSignal<=21) || (fCabledSignal>=41 && fCabledSignal<=45)){
375 fMapADC[fNConnCh][3] = 2; //ZPC
377 if(fCabledSignal==17 || fCabledSignal==41) fMapADC[fNConnCh][4]=0;
378 else if(fCabledSignal==18 || fCabledSignal==42) fMapADC[fNConnCh][4]=1;
379 else if(fCabledSignal==19 || fCabledSignal==43) fMapADC[fNConnCh][4]=2;
380 else if(fCabledSignal==20 || fCabledSignal==44) fMapADC[fNConnCh][4]=3;
381 else if(fCabledSignal==21 || fCabledSignal==45) fMapADC[fNConnCh][4]=4;
383 else if(fCabledSignal==22 || fCabledSignal==23 || fCabledSignal==46 || fCabledSignal==47){
384 fMapADC[fNConnCh][3] = 3;
386 if(fCabledSignal==22 || fCabledSignal==46) fMapADC[fNConnCh][4]=1;
387 else if(fCabledSignal==23 || fCabledSignal==47) fMapADC[fNConnCh][4]=2;
390 //if(fNConnCh<fNChannelsOn) printf(" %d mod %d ch %d code %d det %d sec %d\n",
391 // fNConnCh,fADCModule,fADCChannel,fBuffer&0xffff,fMapADC[fNConnCh][3],fMapADC[fNConnCh][4]);
394 if(fNConnCh>=fNChannelsOn){
395 // Protection manually set since it returns:
396 // RawData48 mod. 3 ch. 2048 signal 515
397 // to be checked with Pietro!!!!!!!!!!!!!!!!!!!!!!!
398 //AliWarning(" No. of cabled channels > fNChannelsOn!!!");
403 }// ModType=1 (ADC mapping)
409 // -------------------------------------------
411 // -------------------------------------------
412 if(fPosition<fDeadfaceOffset){
416 else if(fPosition==fDeadfaceOffset){
417 if(fBuffer != 0xdeadface){
418 AliError(" NO deadface after DARC data");
419 fRawReader->AddMajorErrorLog(kDARCError);
427 // -------------------------------------------
428 // --- DARC global data
429 // -------------------------------------------
430 else if(fPosition>fDeadfaceOffset && fPosition<fDeadbeefOffset){
434 else if(fPosition==fDeadbeefOffset){
435 if(fBuffer != 0xdeadbeef){
436 AliError(" NO deadbeef after DARC global data");
437 fRawReader->AddMajorErrorLog(kDARCError);
445 // -------------------------------------------
447 // --- ADC buffer + scaler
448 // -------------------------------------------
449 else if(fPosition>=fDataOffset){
451 //printf("AliZDCRawStream: fSODReading = %d\n", fSODReading);
452 if(!fSODReading && !fIsMapRead) ReadChMap();
454 // Not valid datum before the event
455 // there MUST be a NOT valid datum before the event!!!
456 if(fPosition==fDataOffset){
457 //printf("\t **** ZDC data begin ****\n");
458 if((fBuffer & 0x07000000) == 0x06000000){
459 //printf(" AliZDCRawStream -> Not valid datum in ADC %d,"
460 // "position %d in word data buffer\n",fADCModule,fPosition);
462 else fRawReader->AddMajorErrorLog(kZDCDataError);
465 // If the not valid datum isn't followed by the 1st ADC header
466 // the event is corrupted (i.e., 2 gates arrived before trigger)
467 else if(fPosition==fDataOffset+1){
468 if((fBuffer & 0x07000000) != 0x02000000){
469 AliWarning("ZDC ADC -> The not valid datum is NOT followed by an ADC header!");
470 fRawReader->AddMajorErrorLog(kZDCDataError);
474 // Get geo address of current word to determine
475 // if it is a scaler word (geo address == kScalerAddress)
476 // if it is an ADC word (geo address != 8)
477 Int_t kScalerAddress=8;
478 fADCModule = ((fBuffer & 0xf8000000)>>27);
479 if(fADCModule == kScalerAddress){
484 if((fBuffer & 0x07000000) == 0x02000000){
485 fIsADCHeader = kTRUE;
486 fADCNChannels = ((fBuffer & 0x00003f00)>>8);
487 //printf(" AliZDCRawStream -> HEADER: ADC mod.%d has %d ch. \n",fADCModule,fADCNChannels);
490 else if((fBuffer & 0x07000000) == 0x00000000){
491 fIsADCDataWord = kTRUE;
492 fADCChannel = ((fBuffer & 0x1e0000) >> 17);
493 fADCGain = ((fBuffer & 0x10000) >> 16);
494 fADCValue = (fBuffer & 0xfff);
496 //printf(" AliZDCRawStream -> DATA: ADC mod. %d ch. %d gain %d value %d\n",
497 // fADCModule,fADCChannel,fADCGain,fADCValue);
499 // Checking if the channel map for the ADCs has been provided/read
500 if(fMapADC[0][0]==-1){
501 printf("\t ATTENTION!!! No ADC mapping has been found/provided!!!\n");
505 /*for(Int_t ci=0; ci<fNChannelsOn; ci++){
506 printf(" %d mod %d ch %d det %d sec %d\n",ci,fMapADC[ci][0],
507 fMapADC[ci][1], fMapADC[ci][3], fMapADC[ci][4]);
510 // Scan of the map to assign the correct volumes
511 Int_t foundMapEntry = kFALSE;
512 for(Int_t k=0; k<fNChannelsOn; k++){
513 if(fADCModule==fMapADC[k][0] && fADCChannel==fMapADC[k][1]){
514 fSector[0] = fMapADC[k][3];
515 fSector[1] = fMapADC[k][4];
516 foundMapEntry = kTRUE;
520 if(foundMapEntry==kFALSE){
521 AliWarning(Form(" No valid entry found in ADC mapping for raw data %d ADCmod. %d ch. %d gain %d\n",
522 fPosition,fADCModule,fADCChannel,fADCGain));
525 //printf("AliZDCRawStream -> ADCmod. %d ch. %d gain %d -> det %d sec %d\n",
526 // fADCModule,fADCChannel,fADCGain,fSector[0],fSector[1]);
529 if(fSector[0]<1 || fSector[0]>5){
530 AliError(Form(" No valid detector assignment: %d",fSector[0]));
531 fRawReader->AddMajorErrorLog(kInvalidSector);
534 if(fSector[1]<0 || fSector[1]>5){
535 AliError(Form(" No valid sector assignment: %d",fSector[1]));
536 fRawReader->AddMajorErrorLog(kInvalidSector);
539 if(fADCModule<0 || fADCModule>3){
540 AliError(Form(" No valid ADC module: %d",fADCModule));
541 fRawReader->AddMajorErrorLog(kInvalidADCModule);
544 // Checking the underflow and overflow bits
545 if(fBuffer & 0x1000) fIsUnderflow = kTRUE;
546 else if (fBuffer & 0x2000) fIsOverflow = kTRUE;
550 else if((fBuffer & 0x07000000) == 0x04000000){
552 //printf(" AliZDCRawStream -> EOB --------------------------\n");
563 //_____________________________________________________________________________
564 void AliZDCRawStream::DecodeScaler()
566 // Decoding scaler event
568 if(!fBuffer & 0x04000000){
569 AliWarning(" Scaler header corrupted");
570 fIsScEventGood = kFALSE;
572 Int_t scNwords = (Int_t) fScNWords;
573 if(fPosition==scNwords && fBuffer != 0x0){
574 AliWarning(" Scaler trailer corrupted");
575 fIsScEventGood = kFALSE;
577 fIsScEventGood = kTRUE;
580 fScNWords = (fBuffer & 0x00fc0000)>>18;
581 fScGeo = (fBuffer & 0xf8000000)>>27;
582 fScTS = (fBuffer & 0x00030000)>>16;
583 fScTriggerNumber = (fBuffer & 0x0000ffff);
590 //_____________________________________________________________________________
591 AliCDBStorage* AliZDCRawStream::SetStorage(const char *uri)
593 // Setting the storage
595 AliCDBStorage *storage = AliCDBManager::Instance()->GetStorage(uri);
601 //_____________________________________________________________________________
602 AliZDCChMap* AliZDCRawStream::GetChMap() const
605 // Getting calibration object for ZDC
607 AliCDBEntry *entry = AliCDBManager::Instance()->Get("ZDC/Calib/ChMap");
608 if(!entry) AliFatal("No calibration data loaded!");
610 AliZDCChMap *calibdata = dynamic_cast<AliZDCChMap*> (entry->GetObject());
611 if(!calibdata) AliFatal("Wrong calibration object in calibration file!");