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),
74 // Create an object to read ZDC raw digits
76 fRawReader->Select("ZDC");
78 for(Int_t i=0; i<48; i++){
79 for(Int_t j=0; j<5; j++) fMapADC[i][j]=-1;
84 //_____________________________________________________________________________
85 AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
87 fRawReader(stream.fRawReader),
88 fBuffer(stream.GetRawBuffer()),
89 fEvType(stream.fEvType),
90 fPosition(stream.fPosition),
91 fIsCalib(stream.fIsCalib),
92 fIsDARCHeader(stream.fIsDARCHeader),
93 fIsChMapping(stream.fIsChMapping),
94 fIsADCDataWord(stream.fIsADCDataWord),
95 fIsADCHeader(stream.fIsADCHeader),
96 fIsADCEOB(stream.fIsADCEOB),
97 fSODReading(stream.fSODReading),
98 fIsMapRead(stream.fIsMapRead),
99 fDARCEvBlockLenght(stream.fDARCEvBlockLenght),
100 fDARCBlockAttributes(stream.fDARCBlockAttributes),
101 fDeadfaceOffset(stream.GetDeadfaceOffset()),
102 fDeadbeefOffset(stream.GetDeadbeefOffset()),
103 fDataOffset(stream.GetDataOffset()),
104 fModType(stream.GetModType()),
105 fADCModule(stream.GetADCModule()),
106 fADCNChannels(stream.GetADCNChannels()),
107 fADCChannel(stream.GetADCChannel()),
108 fADCValue(stream.GetADCValue()),
109 fADCGain(stream.GetADCGain()),
110 fIsUnderflow(stream.fIsUnderflow),
111 fIsOverflow(stream.fIsOverflow),
112 fScNWords(stream.GetScNWords()),
113 fScGeo(stream.GetScGeo()),
114 fScTS(stream.GetScTS()),
115 fScTriggerNumber(stream.fScTriggerNumber),
116 fIsScEventGood(stream.fIsScEventGood),
117 fNConnCh(stream.fNConnCh),
118 fCabledSignal(stream.GetCabledSignal())
121 for(Int_t j=0; j<2; j++) fSector[j] = stream.GetSector(j);
122 for(Int_t i=0; i<48; i++){
123 for(Int_t j=0; j<5; j++) fMapADC[i][j] = stream.fMapADC[i][j];
127 //_____________________________________________________________________________
128 AliZDCRawStream& AliZDCRawStream::operator = (const AliZDCRawStream&
131 // Assignment operator
132 Fatal("operator =", "assignment operator not implemented");
136 //_____________________________________________________________________________
137 AliZDCRawStream::~AliZDCRawStream()
143 //_____________________________________________________________________________
144 void AliZDCRawStream::ReadChMap()
146 // Reading channel map
147 printf("\n\t Reading ADC mapping from OCDB\n");
148 AliZDCChMap * chMap = GetChMap();
149 for(Int_t i=0; i<48; i++){
150 fMapADC[i][0] = chMap->GetADCModule(i);
151 fMapADC[i][1] = chMap->GetADCChannel(i);
153 fMapADC[i][3] = chMap->GetDetector(i);
154 fMapADC[i][4] = chMap->GetSector(i);
159 //_____________________________________________________________________________
160 void AliZDCRawStream::ReadCDHHeader()
163 const AliRawDataHeader* header = fRawReader->GetDataHeader();
165 AliError("\t No CDH in raw data streaming\n");
166 fRawReader->AddMajorErrorLog(kCDHError);
170 //printf("\t AliZDCRawStream::ReadCDHHeader -> Data Size = %d\n",fRawReader->GetDataSize());
172 fDARCEvBlockLenght = header->fSize;
173 //printf("\t AliZDCRawStream::ReadCDHHeader -> fDARCEvBlockLenght = %d\n",fDARCEvBlockLenght);
175 UChar_t message = header->GetAttributes();
176 //printf("\t AliZDCRawStream::ReadCDHHeader -> Attributes %x\n",message);
178 if(message & 0x10){ // COSMIC RUN
179 printf("\t STANDALONE_COSMIC RUN raw data found\n");
181 else if(message & 0x20){ // PEDESTAL RUN
182 printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
184 else if(message & 0x30){ // LASER RUN
185 printf("\t STANDALONE_LASER RUN raw data found\n");
188 if(header->GetL1TriggerMessage() & 0x1){ // Calibration bit set in CDH
191 //printf("\t AliZDCRawStream::ReadCDHHeader -> L1TriggerMessage %x\n",header->GetL1TriggerMessage());
192 //printf("\t AliZDCRawStream::ReadCDHHeader -> Calibration bit = %d\n",fIsCalib);
194 UInt_t status = header->GetStatus();
195 //printf("\t AliZDCRawStream::ReadCDHHeader -> status = %d\n",status);
196 if((status & 0x000f) == 0x0001){
197 AliWarning("CDH -> DARC trg0 overlap error\n");
198 fRawReader->AddMajorErrorLog(kDARCError);
200 if((status & 0x000f) == 0x0002){
201 AliWarning("CDH -> DARC trg0 missing error\n");
202 fRawReader->AddMajorErrorLog(kDARCError);
204 if((status & 0x000f) == 0x0004){
205 AliWarning("CDH -> DARC data parity error\n");
206 fRawReader->AddMajorErrorLog(kDARCError);
208 if((status & 0x000f) == 0x0008){
209 AliWarning("CDH -> DARC ctrl parity error\n");
210 fRawReader->AddMajorErrorLog(kDARCError);
213 if((status & 0x00f0) == 0x0010){
214 AliWarning("CDH -> DARC trg unavailable\n");
215 fRawReader->AddMajorErrorLog(kDARCError);
217 if((status & 0x00f0) == 0x0020){
218 AliWarning("CDH -> DARC FEE error\n");
219 fRawReader->AddMajorErrorLog(kDARCError);
222 if((status & 0x0f00) == 0x0200){
223 AliWarning("CDH -> DARC L1 time violation\n");
224 fRawReader->AddMajorErrorLog(kDARCError);
226 if((status & 0x0f00) == 0x0400){
227 AliWarning("CDH -> DARC L2 time-out\n");
228 fRawReader->AddMajorErrorLog(kDARCError);
230 if((status & 0x0f00) == 0x0800){
231 AliWarning("CDH -> DARC prepulse time violation\n");
232 fRawReader->AddMajorErrorLog(kDARCError);
235 if((status & 0xf000) == 0x1000){
236 AliWarning("CDH -> DARC other error\n");
237 fRawReader->AddMajorErrorLog(kDARCError);
241 fIsDARCHeader = kTRUE;
244 //_____________________________________________________________________________
245 Bool_t AliZDCRawStream::Next()
247 // Read the next raw digit
248 // Returns kFALSE if there is no digit left
250 if(!fRawReader->ReadNextInt((UInt_t&) fBuffer)) return kFALSE;
251 fIsChMapping = kFALSE; fIsADCHeader = kFALSE;
252 fIsADCDataWord = kFALSE; fIsADCEOB = kFALSE;
253 fIsUnderflow = kFALSE;
254 fIsOverflow = kFALSE;
255 fSector[0]=fSector[1] = -1;
257 fEvType = fRawReader->GetType();
258 //printf("\n\t AliZDCRawStream::Next() -> ev. type %d\n",fEvType);
259 //printf("\n AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
262 //if(fEvType==7 || fEvType ==8){ //Physics or calibration event
270 if(fBuffer == 0xcafefade){
271 //printf("\n-> AliZDCRawStream::Next() ***** End of ZDC event *****\n\n");
275 // -------------------------------------------
277 // -------------------------------------------
278 // If the CDH has been read then
279 // the DARC header must follow
281 //printf("\t ---- DARC header ----\n");
284 fDeadbeefOffset = 25;
290 fDataOffset = 1+fDeadbeefOffset;
291 fIsDARCHeader = kFALSE;
295 // -------------------------------------------
296 // --- Start of data event
297 // --- decoding mapping of connected ADC ch.
298 // -------------------------------------------
299 // In the SOD event ADC ch. mapping is written
300 if(fEvType==10 && fSODReading){
301 //printf("\n-> AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
303 if(fPosition>fDataOffset){
304 if((fBuffer&0xff000000) == 0xff000000){
305 if(fPosition==(fDataOffset+1)){
306 printf("\n\n\t Reading ZDC mapping from StartOfData event\n");
310 //printf("\n\t End of ZDC StartOfData event\n\n");
311 //printf("AliZDCRawStream: fSODReading after SOD reading set to %d\n", fSODReading);
315 else if((fBuffer&0x80000000)>>31 == 1){
316 // Mapping identification
317 fADCModule = ((fBuffer & 0x7f000000)>>24);
318 fModType = ((fBuffer & 0xfff00)>>8);
319 fADCNChannels = (fBuffer & 0xff);
321 //printf(" ******** GEO %d, mod. type %d, #ch. %d\n",fADCModule,fModType,fADCNChannels);
323 else if(fModType==1 && (fBuffer&0x80000000)>>31 == 0){
325 if((fBuffer&0x40000000)>>30==0){ // high range chain ADC
326 fIsChMapping = kTRUE;
327 fADCChannel = ((fBuffer & 0x3fff0000)>>16);
328 fCabledSignal = (fBuffer&0xffff);
329 //printf("\tADC ch. %d, signal %d\n",fADCChannel,fCabledSignal);
331 fMapADC[fNConnCh][0] = fADCModule;
332 fMapADC[fNConnCh][1] = fADCChannel;
333 fMapADC[fNConnCh][2] = fCabledSignal;
335 // Determining detector and sector
336 // -----------------------------------------
337 // For the decoding of the following lines
338 // look the enum in AliZDCRawStream.h file
339 // -----------------------------------------
340 if((fCabledSignal>=2 && fCabledSignal<=6) || (fCabledSignal>=26 && fCabledSignal<=30)
341 || fCabledSignal==24 || fCabledSignal==48){
342 fMapADC[fNConnCh][3] = 4; //ZNA
344 if(fCabledSignal==2 || fCabledSignal==26) fMapADC[fNConnCh][4]=0;
345 else if(fCabledSignal==3 || fCabledSignal==27) fMapADC[fNConnCh][4]=1;
346 else if(fCabledSignal==4 || fCabledSignal==28) fMapADC[fNConnCh][4]=2;
347 else if(fCabledSignal==5 || fCabledSignal==29) fMapADC[fNConnCh][4]=3;
348 else if(fCabledSignal==6 || fCabledSignal==30) fMapADC[fNConnCh][4]=4;
349 else if(fCabledSignal==24 || fCabledSignal==48) fMapADC[fNConnCh][4]=5;
351 else if((fCabledSignal>=7 && fCabledSignal<=11) || (fCabledSignal>=31 && fCabledSignal<=35)){
352 fMapADC[fNConnCh][3] = 5; //ZPA
354 if(fCabledSignal==7 || fCabledSignal==31) fMapADC[fNConnCh][4]=0;
355 else if(fCabledSignal==8 || fCabledSignal==32) fMapADC[fNConnCh][4]=1;
356 else if(fCabledSignal==9 || fCabledSignal==33) fMapADC[fNConnCh][4]=2;
357 else if(fCabledSignal==10 || fCabledSignal==34) fMapADC[fNConnCh][4]=3;
358 else if(fCabledSignal==11 || fCabledSignal==35) fMapADC[fNConnCh][4]=4;
360 else if((fCabledSignal>=12 && fCabledSignal<=16) || (fCabledSignal>=36 && fCabledSignal<=40)
361 || fCabledSignal==25 || fCabledSignal==49){
362 fMapADC[fNConnCh][3] = 1; //ZNC
364 if(fCabledSignal==12 || fCabledSignal==36) fMapADC[fNConnCh][4]=0;
365 else if(fCabledSignal==13 || fCabledSignal==37) fMapADC[fNConnCh][4]=1;
366 else if(fCabledSignal==14 || fCabledSignal==38) fMapADC[fNConnCh][4]=2;
367 else if(fCabledSignal==15 || fCabledSignal==39) fMapADC[fNConnCh][4]=3;
368 else if(fCabledSignal==16 || fCabledSignal==40) fMapADC[fNConnCh][4]=4;
369 else if(fCabledSignal==25 || fCabledSignal==49) fMapADC[fNConnCh][4]=5;
371 else if((fCabledSignal>=17 && fCabledSignal<=21) || (fCabledSignal>=41 && fCabledSignal<=45)){
372 fMapADC[fNConnCh][3] = 2; //ZPC
374 if(fCabledSignal==17 || fCabledSignal==41) fMapADC[fNConnCh][4]=0;
375 else if(fCabledSignal==18 || fCabledSignal==42) fMapADC[fNConnCh][4]=1;
376 else if(fCabledSignal==19 || fCabledSignal==43) fMapADC[fNConnCh][4]=2;
377 else if(fCabledSignal==20 || fCabledSignal==44) fMapADC[fNConnCh][4]=3;
378 else if(fCabledSignal==21 || fCabledSignal==45) fMapADC[fNConnCh][4]=4;
380 else if(fCabledSignal==22 || fCabledSignal==23 || fCabledSignal==46 || fCabledSignal==47){
381 fMapADC[fNConnCh][3] = 3;
383 if(fCabledSignal==22 || fCabledSignal==46) fMapADC[fNConnCh][4]=1;
384 else if(fCabledSignal==23 || fCabledSignal==47) fMapADC[fNConnCh][4]=2;
387 //if(fNConnCh<48) printf("AliZDCRawStream: datum %d mod. %d ch. %d signal %d, det %d, tow %d\n",
388 // fNConnCh,fADCModule,fADCChannel,fBuffer&0xffff,fMapADC[fNConnCh][3],fMapADC[fNConnCh][4]);
392 // Protection manually set since it returns:
393 // RawData48 mod. 3 ch. 2048 signal 515
394 // to be checked with Pietro!!!!!!!!!!!!!!!!!!!!!!!
395 //AliWarning("\t AliZDCRawStream -> ERROR: no. of cabled channels > 48!!!\n");
400 }// ModType=1 (ADC mapping)
406 // -------------------------------------------
408 // -------------------------------------------
409 if(fPosition<fDeadfaceOffset){
413 else if(fPosition==fDeadfaceOffset){
414 if(fBuffer != 0xdeadface){
415 AliError("AliZDCRawStream -> NO deadface after DARC data\n");
416 fRawReader->AddMajorErrorLog(kDARCError);
424 // -------------------------------------------
425 // --- DARC global data
426 // -------------------------------------------
427 else if(fPosition>fDeadfaceOffset && fPosition<fDeadbeefOffset){
431 else if(fPosition==fDeadbeefOffset){
432 if(fBuffer != 0xdeadbeef){
433 AliError("AliZDCRawStream -> NO deadbeef after DARC global data\n");
434 fRawReader->AddMajorErrorLog(kDARCError);
442 // -------------------------------------------
444 // --- ADC buffer + scaler
445 // -------------------------------------------
446 else if(fPosition>=fDataOffset){
448 //printf("AliZDCRawStream: fSODReading = %d\n", fSODReading);
449 if(!fSODReading && !fIsMapRead) ReadChMap();
451 // Not valid datum before the event
452 // there MUST be a NOT valid datum before the event!!!
453 if(fPosition==fDataOffset){
454 //printf("\t **** ZDC data begin ****\n");
455 if((fBuffer & 0x07000000) == 0x06000000){
456 //printf(" AliZDCRawStream -> Not valid datum in ADC %d,"
457 // "position %d in word data buffer\n",fADCModule,fPosition);
459 else fRawReader->AddMajorErrorLog(kZDCDataError);
462 // If the not valid datum isn't followed by the 1st ADC header
463 // the event is corrupted (i.e., 2 gates arrived before trigger)
464 else if(fPosition==fDataOffset+1){
465 if((fBuffer & 0x07000000) != 0x02000000){
466 AliWarning("ZDC ADC -> The not valid datum is NOT followed by an ADC header!\n");
467 fRawReader->AddMajorErrorLog(kZDCDataError);
471 // Get geo address of current word to determine
472 // if it is a scaler word (geo address == kScalerAddress)
473 // if it is an ADC word (geo address != 8)
474 Int_t kScalerAddress=8;
475 fADCModule = ((fBuffer & 0xf8000000)>>27);
476 if(fADCModule == kScalerAddress){
481 if((fBuffer & 0x07000000) == 0x02000000){
482 fIsADCHeader = kTRUE;
483 fADCNChannels = ((fBuffer & 0x00003f00)>>8);
484 //printf(" AliZDCRawStream -> HEADER: ADC mod.%d has %d ch. \n",fADCModule,fADCNChannels);
487 else if((fBuffer & 0x07000000) == 0x00000000){
488 fIsADCDataWord = kTRUE;
489 fADCChannel = ((fBuffer & 0x1e0000) >> 17);
490 fADCGain = ((fBuffer & 0x10000) >> 16);
491 fADCValue = (fBuffer & 0xfff);
493 //printf(" AliZDCRawStream -> DATA: ADC mod. %d ch. %d gain %d value %d\n",
494 // fADCModule,fADCChannel,fADCGain,fADCValue);
496 // Checking if the channel map for the ADCs has been provided/read
497 if(fMapADC[0][0]==-1){
498 printf("\t ATTENTION!!! No ADC mapping has been found/provided!!!\n");
502 /*for(Int_t ci=0; ci<48; ci++){
503 printf(" %d mod. %d ch. %d detector %d sector %d\n",ci,fMapADC[ci][0],
504 fMapADC[ci][1], fMapADC[ci][3], fMapADC[ci][4]);
507 // Scan of the map to assign the correct volumes
508 Int_t foundMapEntry = kFALSE;
509 for(Int_t k=0; k<48; k++){
510 if(fADCModule==fMapADC[k][0] && fADCChannel==fMapADC[k][1]){
511 fSector[0] = fMapADC[k][3];
512 fSector[1] = fMapADC[k][4];
513 foundMapEntry = kTRUE;
517 if(foundMapEntry==kFALSE){
518 AliWarning(Form("AliZDCRawStream -> No valid entry found in ADC mapping\n"));
519 AliWarning(Form("\t for raw data %d ADCmod. %d ch. %d gain %d\n",
520 fPosition,fADCModule,fADCChannel,fADCGain));
523 //printf("AliZDCRawStream -> ADCmod. %d ch. %d gain %d -> det %d sec %d\n",
524 // fADCModule,fADCChannel,fADCGain,fSector[0],fSector[1]);
527 if(fSector[0]<1 || fSector[0]>5){
528 AliError(Form(" AliZDCRawStream -> No valid detector assignment: %d\n",fSector[0]));
529 fRawReader->AddMajorErrorLog(kInvalidSector);
532 if(fSector[1]<0 || fSector[1]>5){
533 AliError(Form(" AliZDCRawStream -> No valid sector assignment: %d\n",fSector[1]));
534 fRawReader->AddMajorErrorLog(kInvalidSector);
537 if(fADCModule<0 || fADCModule>3){
538 AliError(Form(" AliZDCRawStream -> No valid ADC module: %d\n",fADCModule));
539 fRawReader->AddMajorErrorLog(kInvalidADCModule);
542 // Checking the underflow and overflow bits
543 if(fBuffer & 0x1000) fIsUnderflow = kTRUE;
544 else if (fBuffer & 0x2000) fIsOverflow = kTRUE;
548 else if((fBuffer & 0x07000000) == 0x04000000){
550 //printf(" AliZDCRawStream -> EOB --------------------------\n");
561 //_____________________________________________________________________________
562 void AliZDCRawStream::DecodeScaler()
564 // Decoding scaler event
566 if(!fBuffer & 0x04000000){
567 AliWarning(" AliZDCRawStream -> Scaler header corrupted\n");
568 fIsScEventGood = kFALSE;
570 Int_t scNwords = (Int_t) fScNWords;
571 if(fPosition==scNwords && fBuffer != 0x0){
572 AliWarning(" AliZDCRawStream -> Scaler trailer corrupted\n");
573 fIsScEventGood = kFALSE;
575 fIsScEventGood = kTRUE;
578 fScNWords = (fBuffer & 0x00fc0000)>>18;
579 fScGeo = (fBuffer & 0xf8000000)>>27;
580 fScTS = (fBuffer & 0x00030000)>>16;
581 fScTriggerNumber = (fBuffer & 0x0000ffff);
588 //_____________________________________________________________________________
589 AliCDBStorage* AliZDCRawStream::SetStorage(const char *uri)
591 // Setting the storage
593 AliCDBStorage *storage = AliCDBManager::Instance()->GetStorage(uri);
599 //_____________________________________________________________________________
600 AliZDCChMap* AliZDCRawStream::GetChMap() const
603 // Getting calibration object for ZDC
605 AliCDBEntry *entry = AliCDBManager::Instance()->Get("ZDC/Calib/ChMap");
606 if(!entry) AliFatal("No calibration data loaded!");
608 AliZDCChMap *calibdata = dynamic_cast<AliZDCChMap*> (entry->GetObject());
609 if(!calibdata) AliFatal("Wrong calibration object in calibration file!");