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 map 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);
261 //if(fEvType==7 || fEvType ==8){ //Physics or calibration event
267 //printf("\n AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
269 // -------------------------------------------
271 // -------------------------------------------
272 // If the CDH has been read then
273 // the DARC header must follow
275 //printf("\t ---- DARC header ----\n");
278 fDeadbeefOffset = 25;
284 fDataOffset = 1+fDeadbeefOffset;
285 fIsDARCHeader = kFALSE;
289 // -------------------------------------------
290 // --- Start of data event
291 // --- decoding mapping of connected ADC ch.
292 // -------------------------------------------
293 // In the SOD event ADC ch. mapping is written
294 if(fEvType==10 && fSODReading){
295 //printf("\n AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
297 if(fPosition>fDataOffset){
298 if((fBuffer&0xff000000) == 0xff000000){
299 if(fPosition==(fDataOffset+1)){
300 printf("\n\n\t Reading ZDC mapping from StartOfData event\n");
304 printf("\n\t End of ZDC StartOfData event\n\n");
305 //printf("AliZDCRawStream: fSODReading after SOD reading set to %d\n", fSODReading);
309 else if((fBuffer&0x80000000)>>31 == 1){
310 // Mapping identification
311 fADCModule = ((fBuffer & 0x7f000000)>>24);
312 fModType = ((fBuffer & 0xfff00)>>8);
313 fADCNChannels = (fBuffer & 0xff);
315 //printf("\tGEO %d, mod. type %d, #ch. %d\n",fADCModule,fModType,fADCNChannels);
317 else if(fModType==1 && (fBuffer&0x80000000)>>31 == 0){
319 if((fBuffer&0x40000000)>>30==0){ // high range chain ADC
320 fIsChMapping = kTRUE;
321 fADCChannel = ((fBuffer & 0x3fff0000)>>16);
322 fCabledSignal = (fBuffer&0xffff);
324 //printf("\tADC ch. %d, signal %d\n",fADCChannel,fCabledSignal);
326 fMapADC[fNConnCh][0] = fADCModule;
327 fMapADC[fNConnCh][1] = fADCChannel;
328 fMapADC[fNConnCh][2] = fCabledSignal;
330 // Determining detector and sector
331 // -----------------------------------------
332 // For the decoding of the following lines
333 // look the enum in AliZDCRawStream.h file
334 // -----------------------------------------
335 if((fCabledSignal>=2 && fCabledSignal<=6) || (fCabledSignal>=26 && fCabledSignal<=30)
336 || fCabledSignal==24 || fCabledSignal==48){
337 fMapADC[fNConnCh][3] = 4; //ZNA
339 if(fCabledSignal==2 || fCabledSignal==26) fMapADC[fNConnCh][4]=0;
340 else if(fCabledSignal==3 || fCabledSignal==27) fMapADC[fNConnCh][4]=1;
341 else if(fCabledSignal==4 || fCabledSignal==28) fMapADC[fNConnCh][4]=2;
342 else if(fCabledSignal==5 || fCabledSignal==29) fMapADC[fNConnCh][4]=3;
343 else if(fCabledSignal==6 || fCabledSignal==30) fMapADC[fNConnCh][4]=4;
344 else if(fCabledSignal==24 || fCabledSignal==48) fMapADC[fNConnCh][4]=5;
346 else if((fCabledSignal>=7 && fCabledSignal<=11) || (fCabledSignal>=31 && fCabledSignal<=35)){
347 fMapADC[fNConnCh][3] = 5; //ZPA
349 if(fCabledSignal==7 || fCabledSignal==31) fMapADC[fNConnCh][4]=0;
350 else if(fCabledSignal==8 || fCabledSignal==32) fMapADC[fNConnCh][4]=1;
351 else if(fCabledSignal==9 || fCabledSignal==33) fMapADC[fNConnCh][4]=2;
352 else if(fCabledSignal==10 || fCabledSignal==34) fMapADC[fNConnCh][4]=3;
353 else if(fCabledSignal==11 || fCabledSignal==35) fMapADC[fNConnCh][4]=4;
355 else if((fCabledSignal>=12 && fCabledSignal<=16) || (fCabledSignal>=36 && fCabledSignal<=40)
356 || fCabledSignal==25 || fCabledSignal==49){
357 fMapADC[fNConnCh][3] = 1; //ZNC
359 if(fCabledSignal==12 || fCabledSignal==36) fMapADC[fNConnCh][4]=0;
360 else if(fCabledSignal==13 || fCabledSignal==37) fMapADC[fNConnCh][4]=1;
361 else if(fCabledSignal==14 || fCabledSignal==38) fMapADC[fNConnCh][4]=2;
362 else if(fCabledSignal==15 || fCabledSignal==39) fMapADC[fNConnCh][4]=3;
363 else if(fCabledSignal==16 || fCabledSignal==40) fMapADC[fNConnCh][4]=4;
364 else if(fCabledSignal==25 || fCabledSignal==49) fMapADC[fNConnCh][4]=5;
366 else if((fCabledSignal>=17 && fCabledSignal<=21) || (fCabledSignal>=41 && fCabledSignal<=45)){
367 fMapADC[fNConnCh][3] = 2; //ZPC
369 if(fCabledSignal==17 || fCabledSignal==41) fMapADC[fNConnCh][4]=0;
370 else if(fCabledSignal==18 || fCabledSignal==42) fMapADC[fNConnCh][4]=1;
371 else if(fCabledSignal==19 || fCabledSignal==43) fMapADC[fNConnCh][4]=2;
372 else if(fCabledSignal==20 || fCabledSignal==44) fMapADC[fNConnCh][4]=3;
373 else if(fCabledSignal==21 || fCabledSignal==45) fMapADC[fNConnCh][4]=4;
375 else if(fCabledSignal==22 || fCabledSignal==23 || fCabledSignal==46 || fCabledSignal==47){
376 fMapADC[fNConnCh][3] = 3;
378 if(fCabledSignal==22 || fCabledSignal==46) fMapADC[fNConnCh][4]=1;
379 else if(fCabledSignal==23 || fCabledSignal==47) fMapADC[fNConnCh][4]=2;
382 //printf("AliZDCRawStream -> datum %d mod. %d ch. %d signal %d, det %d, tow %d\n",
383 // fNConnCh,fADCModule,fADCChannel,fBuffer&0xffff,fMapADC[fNConnCh][3],fMapADC[fNConnCh][4]);
387 // Protection manually set since it returns:
388 // RawData48 mod. 3 ch. 2048 signal 515
389 // to be checked with Pietro!!!!!!!!!!!!!!!!!!!!!!!
390 //AliWarning("\t AliZDCRawStream -> ERROR: no. of cabled channels > 48!!!\n");
394 }// ModType=1 (ADC mapping)
400 // -------------------------------------------
402 // -------------------------------------------
403 if(fPosition<fDeadfaceOffset){
407 else if(fPosition==fDeadfaceOffset){
408 if(fBuffer != 0xdeadface){
409 AliError("AliZDCRawStream -> NO deadface after DARC data\n");
410 fRawReader->AddMajorErrorLog(kDARCError);
418 // -------------------------------------------
419 // --- DARC global data
420 // -------------------------------------------
421 else if(fPosition>fDeadfaceOffset && fPosition<fDeadbeefOffset){
425 else if(fPosition==fDeadbeefOffset){
426 if(fBuffer != 0xdeadbeef){
427 AliError("AliZDCRawStream -> NO deadbeef after DARC global data\n");
428 fRawReader->AddMajorErrorLog(kDARCError);
436 // -------------------------------------------
438 // --- ADC buffer + scaler
439 // -------------------------------------------
440 else if(fPosition>=fDataOffset){
442 //printf("AliZDCRawStream: fSODReading = %d\n", fSODReading);
443 if(!fSODReading && !fIsMapRead) ReadChMap();
445 // Not valid datum before the event
446 // there MUST be a NOT valid datum before the event!!!
447 if(fPosition==fDataOffset){
448 //printf("\t **** ZDC data begin ****\n");
449 if((fBuffer & 0x07000000) == 0x06000000){
450 //printf(" AliZDCRawStream -> Not valid datum in ADC %d,"
451 // "position %d in word data buffer\n",fADCModule,fPosition);
453 else fRawReader->AddMajorErrorLog(kZDCDataError);
456 // If the not valid datum isn't followed by the 1st ADC header
457 // the event is corrupted (i.e., 2 gates arrived before trigger)
458 else if(fPosition==fDataOffset+1){
459 if((fBuffer & 0x07000000) != 0x02000000){
460 AliWarning("ZDC ADC -> The not valid datum is NOT followed by an ADC header!\n");
461 fRawReader->AddMajorErrorLog(kZDCDataError);
465 // Get geo address of current word to determine
466 // if it is a scaler word (geo address == kScalerAddress)
467 // if it is an ADC word (geo address != 8)
468 Int_t kScalerAddress=8;
469 fADCModule = ((fBuffer & 0xf8000000)>>27);
470 if(fADCModule == kScalerAddress){
475 if(fBuffer == 0xcafefade){
476 //printf(" AliZDCRawStream -> End of ZDC event!\n");
479 else if((fBuffer & 0x07000000) == 0x02000000){
480 fIsADCHeader = kTRUE;
481 fADCNChannels = ((fBuffer & 0x00003f00)>>8);
482 //printf(" AliZDCRawStream -> HEADER: ADC mod.%d has %d ch. \n",fADCModule,fADCNChannels);
485 else if((fBuffer & 0x07000000) == 0x00000000){
486 fIsADCDataWord = kTRUE;
487 fADCChannel = ((fBuffer & 0x1e0000) >> 17);
488 fADCGain = ((fBuffer & 0x10000) >> 16);
489 fADCValue = (fBuffer & 0xfff);
491 //printf(" AliZDCRawStream -> DATA: ADC mod. %d ch. %d gain %d value %d\n",
492 // fADCModule,fADCChannel,fADCGain,fADCValue);
494 // Checking if the channel map for the ADCs has been provided/read
495 if(fMapADC[0][0]==-1){
496 printf("\t ATTENTION!!! No ADC mapping has been found/provided!!!\n");
500 /*for(Int_t ci=0; ci<48; ci++){
501 printf(" %d mod. %d ch. %d detector %d sector %d\n",ci,fMapADC[ci][0],
502 fMapADC[ci][1], fMapADC[ci][3], fMapADC[ci][4]);
505 // Scan of the map to assign the correct volumes
506 Int_t foundMapEntry = kFALSE;
507 for(Int_t k=0; k<48; k++){
508 if(fADCModule==fMapADC[k][0] && fADCChannel==fMapADC[k][1]){
509 fSector[0] = fMapADC[k][3];
510 fSector[1] = fMapADC[k][4];
511 foundMapEntry = kTRUE;
515 if(foundMapEntry==kFALSE){
516 AliWarning(Form("AliZDCRawStream -> No valid entry found in ADC mapping\n"));
517 AliWarning(Form("\t for raw data %d ADCmod. %d ch. %d gain %d\n",
518 fPosition,fADCModule,fADCChannel,fADCGain));
521 //printf("AliZDCRawStream -> ADCmod. %d ch. %d gain %d -> det %d sec %d\n",
522 // fADCModule,fADCChannel,fADCGain,fSector[0],fSector[1]);
525 if(fSector[0]<1 || fSector[0]>5){
526 AliError(Form(" AliZDCRawStream -> No valid detector assignment: %d\n",fSector[0]));
527 fRawReader->AddMajorErrorLog(kInvalidSector);
530 if(fSector[1]<0 || fSector[1]>5){
531 AliError(Form(" AliZDCRawStream -> No valid sector assignment: %d\n",fSector[1]));
532 fRawReader->AddMajorErrorLog(kInvalidSector);
535 if(fADCModule<0 || fADCModule>3){
536 AliError(Form(" AliZDCRawStream -> No valid ADC module: %d\n",fADCModule));
537 fRawReader->AddMajorErrorLog(kInvalidADCModule);
540 // Checking the underflow and overflow bits
541 if(fBuffer & 0x1000) fIsUnderflow = kTRUE;
542 else if (fBuffer & 0x2000) fIsOverflow = kTRUE;
546 else if((fBuffer & 0x07000000) == 0x04000000){
548 //printf(" AliZDCRawStream -> EOB --------------------------\n");
559 //_____________________________________________________________________________
560 void AliZDCRawStream::DecodeScaler()
562 // Decoding scaler event
564 if(!fBuffer & 0x04000000){
565 AliWarning(" AliZDCRawStream -> Scaler header corrupted\n");
566 fIsScEventGood = kFALSE;
568 Int_t scNwords = (Int_t) fScNWords;
569 if(fPosition==scNwords && fBuffer != 0x0){
570 AliWarning(" AliZDCRawStream -> Scaler trailer corrupted\n");
571 fIsScEventGood = kFALSE;
573 fIsScEventGood = kTRUE;
576 fScNWords = (fBuffer & 0x00fc0000)>>18;
577 fScGeo = (fBuffer & 0xf8000000)>>27;
578 fScTS = (fBuffer & 0x00030000)>>16;
579 fScTriggerNumber = (fBuffer & 0x0000ffff);
586 //_____________________________________________________________________________
587 AliCDBStorage* AliZDCRawStream::SetStorage(const char *uri)
589 // Setting the storage
591 AliCDBStorage *storage = AliCDBManager::Instance()->GetStorage(uri);
597 //_____________________________________________________________________________
598 AliZDCChMap* AliZDCRawStream::GetChMap() const
601 // Getting calibration object for ZDC
603 AliCDBEntry *entry = AliCDBManager::Instance()->Get("ZDC/Calib/ChMap");
604 if(!entry) AliFatal("No calibration data loaded!");
606 AliZDCChMap *calibdata = dynamic_cast<AliZDCChMap*> (entry->GetObject());
607 if(!calibdata) AliFatal("Wrong calibration object in calibration file!");