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),
68 fIsScEventGood(kFALSE),
72 // Create an object to read ZDC raw digits
74 fRawReader->Select("ZDC");
76 for(Int_t i=0; i<48; i++){
77 for(Int_t j=0; j<5; j++) fMapADC[i][j]=-1;
82 //_____________________________________________________________________________
83 AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
85 fRawReader(stream.fRawReader),
86 fBuffer(stream.GetRawBuffer()),
87 fEvType(stream.fEvType),
88 fPosition(stream.fPosition),
89 fIsCalib(stream.fIsCalib),
90 fIsDARCHeader(stream.fIsDARCHeader),
91 fIsChMapping(stream.fIsChMapping),
92 fIsADCDataWord(stream.fIsADCDataWord),
93 fIsADCHeader(stream.fIsADCHeader),
94 fIsADCEOB(stream.fIsADCEOB),
95 fSODReading(stream.fSODReading),
96 fIsMapRead(stream.fIsMapRead),
97 fDARCEvBlockLenght(stream.fDARCEvBlockLenght),
98 fDARCBlockAttributes(stream.fDARCBlockAttributes),
99 fDeadfaceOffset(stream.GetDeadfaceOffset()),
100 fDeadbeefOffset(stream.GetDeadbeefOffset()),
101 fDataOffset(stream.GetDataOffset()),
102 fModType(stream.GetModType()),
103 fADCModule(stream.GetADCModule()),
104 fADCNChannels(stream.GetADCNChannels()),
105 fADCChannel(stream.GetADCChannel()),
106 fADCValue(stream.GetADCValue()),
107 fADCGain(stream.GetADCGain()),
108 fScNWords(stream.GetScNWords()),
109 fScGeo(stream.GetScGeo()),
110 fScTS(stream.GetScTS()),
111 fScTriggerNumber(stream.fScTriggerNumber),
112 fIsScEventGood(stream.fIsScEventGood),
113 fNConnCh(stream.fNConnCh),
114 fCabledSignal(stream.GetCabledSignal())
117 for(Int_t j=0; j<2; j++) fSector[j] = stream.GetSector(j);
118 for(Int_t i=0; i<48; i++){
119 for(Int_t j=0; j<5; j++) fMapADC[i][j] = stream.fMapADC[i][j];
123 //_____________________________________________________________________________
124 AliZDCRawStream& AliZDCRawStream::operator = (const AliZDCRawStream&
127 // Assignment operator
128 Fatal("operator =", "assignment operator not implemented");
132 //_____________________________________________________________________________
133 AliZDCRawStream::~AliZDCRawStream()
139 //_____________________________________________________________________________
140 void AliZDCRawStream::ReadChMap()
142 // Reading channel map
143 //printf("\n\t Reading map from OCDB\n");
144 AliZDCChMap * chMap = GetChMap();
145 for(Int_t i=0; i<48; i++){
146 fMapADC[i][0] = chMap->GetADCModule(i);
147 fMapADC[i][1] = chMap->GetADCChannel(i);
149 fMapADC[i][3] = chMap->GetDetector(i);
150 fMapADC[i][4] = chMap->GetSector(i);
155 //_____________________________________________________________________________
156 void AliZDCRawStream::ReadCDHHeader()
159 const AliRawDataHeader* header = fRawReader->GetDataHeader();
161 AliError("\t No CDH in raw data streaming\n");
162 fRawReader->AddMajorErrorLog(kCDHError);
166 //printf("\t AliZDCRawStream::ReadCDHHeader -> Data Size = %d\n",fRawReader->GetDataSize());
168 fDARCEvBlockLenght = header->fSize;
169 //printf("\t AliZDCRawStream::ReadCDHHeader -> fDARCEvBlockLenght = %d\n",fDARCEvBlockLenght);
171 //UChar_t message = header->GetAttributes();
172 //printf("\t AliZDCRawStream::ReadCDHHeader -> Attributes %x\n",message);
174 /*if(message & 0x10){ // COSMIC RUN
175 printf("\t STANDALONE_COSMIC RUN raw data found\n");
177 else if(message & 0x20){ // PEDESTAL RUN
178 printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
180 else if(message & 0x30){ // LASER RUN
181 printf("\t STANDALONE_LASER RUN raw data found\n");
184 if(header->GetL1TriggerMessage() & 0x1){ // Calibration bit set in CDH
187 //printf("\t AliZDCRawStream::ReadCDHHeader -> L1TriggerMessage %x\n",header->GetL1TriggerMessage());
188 //printf("\t AliZDCRawStream::ReadCDHHeader -> Calibration bit = %d\n",fIsCalib);
190 UInt_t status = header->GetStatus();
191 //printf("\t AliZDCRawStream::ReadCDHHeader -> status = %d\n",status);
192 if(status & 0x000f == 0x0001){
193 AliWarning("CDH -> DARC trg0 overlap error\n");
194 fRawReader->AddMajorErrorLog(kDARCError);
196 if(status & 0x000f == 0x0002){
197 AliWarning("CDH -> DARC trg0 missing error\n");
198 fRawReader->AddMajorErrorLog(kDARCError);
200 if(status & 0x000f == 0x0004){
201 AliWarning("CDH -> DARC data parity error\n");
202 fRawReader->AddMajorErrorLog(kDARCError);
204 if(status & 0x000f == 0x0008){
205 AliWarning("CDH -> DARC ctrl parity error\n");
206 fRawReader->AddMajorErrorLog(kDARCError);
209 if(status & 0x00f0 == 0x0010){
210 AliWarning("CDH -> DARC trg unavailable\n");
211 fRawReader->AddMajorErrorLog(kDARCError);
213 if(status & 0x00f0 == 0x0020){
214 AliWarning("CDH -> DARC FEE error\n");
215 fRawReader->AddMajorErrorLog(kDARCError);
218 if(status & 0x0f00 == 0x0200){
219 AliWarning("CDH -> DARC L1 time violation\n");
220 fRawReader->AddMajorErrorLog(kDARCError);
222 if(status & 0x0f00 == 0x0400){
223 AliWarning("CDH -> DARC L2 time-out\n");
224 fRawReader->AddMajorErrorLog(kDARCError);
226 if(status & 0x0f00 == 0x0800){
227 AliWarning("CDH -> DARC prepulse time violation\n");
228 fRawReader->AddMajorErrorLog(kDARCError);
231 if(status & 0xf000 == 0x1000){
232 AliWarning("CDH -> DARC other error\n");
233 fRawReader->AddMajorErrorLog(kDARCError);
237 fIsDARCHeader = kTRUE;
240 //_____________________________________________________________________________
241 Bool_t AliZDCRawStream::Next()
243 // Read the next raw digit
244 // Returns kFALSE if there is no digit left
246 if(!fRawReader->ReadNextInt((UInt_t&) fBuffer)) return kFALSE;
247 fIsChMapping = kFALSE; fIsADCHeader = kFALSE;
248 fIsADCDataWord = kFALSE; fIsADCEOB = kFALSE;
250 fEvType = fRawReader->GetType();
251 //printf("\n\t AliZDCRawStream::Next() -> ev. type %d\n",fEvType);
254 //if(fEvType==7 || fEvType ==8){ //Physics or calibration event
260 //printf("\n AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
262 // -------------------------------------------
264 // -------------------------------------------
265 // If the CDH has been read then
266 // the DARC header must follow
268 //printf("\t ---- DARC header ----\n");
271 fDeadbeefOffset = 25;
277 fDataOffset = 1+fDeadbeefOffset;
278 fIsDARCHeader = kFALSE;
282 // -------------------------------------------
283 // --- Start of data event
284 // --- decoding mapping of connected ADC ch.
285 // -------------------------------------------
286 // In the SOD event ADC ch. mapping is written
287 if(fEvType==10 && fSODReading){
288 //printf("\n AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
290 if(fPosition>fDataOffset){
291 if((fBuffer&0xff000000) == 0xff000000){
292 if(fPosition==(fDataOffset+1)){
293 printf("\n\n\t Reading ZDC mapping from StartOfData event\n");
297 printf("\n\t End of ZDC StartOfData event\n\n");
298 //printf("AliZDCRawStream: fSODReading after SOD reading set to %d\n", fSODReading);
302 else if((fBuffer&0x80000000)>>31 == 1){
303 // Mapping identification
304 fADCModule = ((fBuffer & 0x7f000000)>>24);
305 fModType = ((fBuffer & 0xfff00)>>8);
306 fADCNChannels = (fBuffer & 0xff);
308 printf("\tGEO %d, mod. type %d, #ch. %d\n",fADCModule,fModType,fADCNChannels);
310 else if(fModType==1 && (fBuffer&0x80000000)>>31 == 0){
312 if((fBuffer&0x40000000)>>30==0){ // high range chain ADC
313 fIsChMapping = kTRUE;
314 fADCChannel = ((fBuffer & 0x3fff0000)>>16);
315 fCabledSignal = (fBuffer&0xffff);
317 //printf("\tADC ch. %d, signal %d\n",fADCChannel,fCabledSignal);
319 fMapADC[fNConnCh][0] = fADCModule;
320 fMapADC[fNConnCh][1] = fADCChannel;
321 fMapADC[fNConnCh][2] = fCabledSignal;
323 // Determining detector and sector
324 // -----------------------------------------
325 // For the decoding of the following lines
326 // look the enum in AliZDCRawStream.h file
327 // -----------------------------------------
328 if((fCabledSignal>=2 && fCabledSignal<=6) || (fCabledSignal>=26 && fCabledSignal<=30)
329 || fCabledSignal==24 || fCabledSignal==48){
330 fMapADC[fNConnCh][3] = 4; //ZNA
332 if(fCabledSignal==2 || fCabledSignal==26) fMapADC[fNConnCh][4]=0;
333 else if(fCabledSignal==3 || fCabledSignal==27) fMapADC[fNConnCh][4]=1;
334 else if(fCabledSignal==4 || fCabledSignal==28) fMapADC[fNConnCh][4]=2;
335 else if(fCabledSignal==5 || fCabledSignal==29) fMapADC[fNConnCh][4]=3;
336 else if(fCabledSignal==6 || fCabledSignal==30) fMapADC[fNConnCh][4]=4;
337 else if(fCabledSignal==24 || fCabledSignal==48) fMapADC[fNConnCh][4]=5;
339 else if((fCabledSignal>=7 && fCabledSignal<=11) || (fCabledSignal>=31 && fCabledSignal<=35)){
340 fMapADC[fNConnCh][3] = 5; //ZPA
342 if(fCabledSignal==7 || fCabledSignal==31) fMapADC[fNConnCh][4]=0;
343 else if(fCabledSignal==8 || fCabledSignal==32) fMapADC[fNConnCh][4]=1;
344 else if(fCabledSignal==9 || fCabledSignal==33) fMapADC[fNConnCh][4]=2;
345 else if(fCabledSignal==10 || fCabledSignal==34) fMapADC[fNConnCh][4]=3;
346 else if(fCabledSignal==11 || fCabledSignal==35) fMapADC[fNConnCh][4]=4;
348 else if((fCabledSignal>=12 && fCabledSignal<=16) || (fCabledSignal>=36 && fCabledSignal<=40)
349 || fCabledSignal==25 || fCabledSignal==49){
350 fMapADC[fNConnCh][3] = 1; //ZNC
352 if(fCabledSignal==12 || fCabledSignal==36) fMapADC[fNConnCh][4]=0;
353 else if(fCabledSignal==13 || fCabledSignal==37) fMapADC[fNConnCh][4]=1;
354 else if(fCabledSignal==14 || fCabledSignal==38) fMapADC[fNConnCh][4]=2;
355 else if(fCabledSignal==15 || fCabledSignal==39) fMapADC[fNConnCh][4]=3;
356 else if(fCabledSignal==16 || fCabledSignal==40) fMapADC[fNConnCh][4]=4;
357 else if(fCabledSignal==25 || fCabledSignal==49) fMapADC[fNConnCh][4]=5;
359 else if((fCabledSignal>=17 && fCabledSignal<=21) || (fCabledSignal>=41 && fCabledSignal<=45)){
360 fMapADC[fNConnCh][3] = 2; //ZPC
362 if(fCabledSignal==17 || fCabledSignal==41) fMapADC[fNConnCh][4]=0;
363 else if(fCabledSignal==18 || fCabledSignal==42) fMapADC[fNConnCh][4]=1;
364 else if(fCabledSignal==19 || fCabledSignal==43) fMapADC[fNConnCh][4]=2;
365 else if(fCabledSignal==20 || fCabledSignal==44) fMapADC[fNConnCh][4]=3;
366 else if(fCabledSignal==21 || fCabledSignal==45) fMapADC[fNConnCh][4]=4;
368 else if(fCabledSignal==22 || fCabledSignal==23 || fCabledSignal==46 || fCabledSignal==47){
369 fMapADC[fNConnCh][3] = 3;
371 if(fCabledSignal==22 || fCabledSignal==46) fMapADC[fNConnCh][4]=1;
372 else if(fCabledSignal==23 || fCabledSignal==47) fMapADC[fNConnCh][4]=2;
375 //printf("AliZDCRawStream -> datum %d mod. %d ch. %d signal %d, det %d, tow %d\n",
376 // fNConnCh,fADCModule,fADCChannel,fBuffer&0xffff,fMapADC[fNConnCh][3],fMapADC[fNConnCh][4]);
380 // Protection manually set since it returns:
381 // RawData48 mod. 3 ch. 2048 signal 515
382 // to be checked with Pietro!!!!!!!!!!!!!!!!!!!!!!!
383 //AliWarning("\t AliZDCRawStream -> ERROR: no. of cabled channels > 48!!!\n");
387 }// ModType=1 (ADC mapping)
393 // -------------------------------------------
395 // -------------------------------------------
396 if(fPosition<fDeadfaceOffset){
400 else if(fPosition==fDeadfaceOffset){
401 if(fBuffer != 0xdeadface){
402 AliError("AliZDCRawStream -> NO deadface after DARC data\n");
403 fRawReader->AddMajorErrorLog(kDARCError);
411 // -------------------------------------------
412 // --- DARC global data
413 // -------------------------------------------
414 else if(fPosition>fDeadfaceOffset && fPosition<fDeadbeefOffset){
418 else if(fPosition==fDeadbeefOffset){
419 if(fBuffer != 0xdeadbeef){
420 AliError("AliZDCRawStream -> NO deadbeef after DARC global data\n");
421 fRawReader->AddMajorErrorLog(kDARCError);
429 // -------------------------------------------
431 // --- ADC buffer + scaler
432 // -------------------------------------------
433 else if(fPosition>=fDataOffset){
435 //printf("AliZDCRawStream: fSODReading = %d\n", fSODReading);
436 if(!fSODReading && !fIsMapRead) ReadChMap();
438 // Not valid datum before the event
439 // there MUST be a NOT valid datum before the event!!!
440 if(fPosition==fDataOffset){
441 //printf("\t **** ZDC data begin ****\n");
442 if((fBuffer & 0x07000000) == 0x06000000){
443 //printf(" AliZDCRawStream -> Not valid datum in ADC %d,"
444 // "position %d in word data buffer\n",fADCModule,fPosition);
446 else fRawReader->AddMajorErrorLog(kZDCDataError);
449 // If the not valid datum isn't followed by the 1st ADC header
450 // the event is corrupted (i.e., 2 gates arrived before trigger)
451 else if(fPosition==fDataOffset+1){
452 if((fBuffer & 0x07000000) != 0x02000000){
453 AliWarning("ZDC ADC -> The not valid datum is NOT followed by an ADC header!\n");
454 fRawReader->AddMajorErrorLog(kZDCDataError);
458 // Get geo address of current word to determine
459 // if it is a scaler word (geo address == kScalerAddress)
460 // if it is an ADC word (geo address != 8)
461 Int_t kScalerAddress=8;
462 fADCModule = ((fBuffer & 0xf8000000)>>27);
463 if(fADCModule == kScalerAddress){
468 if(fBuffer == 0xcafefade){
469 //printf(" AliZDCRawStream -> End of ZDC event!\n");
472 else if((fBuffer & 0x07000000) == 0x02000000){
473 fIsADCHeader = kTRUE;
474 fADCNChannels = ((fBuffer & 0x00003f00)>>8);
475 //printf(" AliZDCRawStream -> HEADER: ADC mod.%d has %d ch. \n",fADCModule,fADCNChannels);
478 else if((fBuffer & 0x07000000) == 0x00000000){
479 fIsADCDataWord = kTRUE;
480 fADCChannel = ((fBuffer & 0x1e0000) >> 17);
481 fADCGain = ((fBuffer & 0x10000) >> 16);
482 fADCValue = (fBuffer & 0xfff);
484 //printf(" AliZDCRawStream -> DATA: ADC mod. %d ch. %d gain %d value %d\n",
485 // fADCModule,fADCChannel,fADCGain,fADCValue);
487 // Valid ADC data (not underflow nor overflow)
488 if(!(fBuffer & 0x1000) && !(fBuffer & 0x2000)){
490 // Checking if the channel map for the ADCs has been provided/read
491 if(fMapADC[0][0]==-1){
492 printf("\t ATTENTION!!! No ADC mapping has been found/provided!!!\n");
494 // Temporary solution (to be changed!!!!)
495 // mapping read from ShuttleInput dir
496 /*char * mapFileName=gSystem->ExpandPathName("$(ALICE_ROOT)/ZDC/ShuttleInput/ZDCChMapping.dat");
499 if((file = fopen(mapFileName,"r")) != NULL){
500 for(Int_t j=0; j<48; j++){
501 for(Int_t k=0; k<6; k++){
502 fscanf(file,"%d",&ival[j][k]);
504 fMapADC[j][0] = ival[j][1];
505 fMapADC[j][1] = ival[j][2];
506 fMapADC[j][2] = ival[j][3];
507 fMapADC[j][3] = ival[j][4];
508 fMapADC[j][4] = ival[j][5];
512 printf("File %s not found\n",mapFileName);
517 /*for(Int_t ci=0; ci<48; ci++){
518 printf(" %d mod. %d ch. %d signal %d\n",ci,fMapADC[ci][0],
519 fMapADC[ci][1], fMapADC[ci][2]);
523 // Scan of the map to assign the correct volumes
524 for(Int_t k=0; k<48; k++){
525 if(fADCModule==fMapADC[k][0] && fADCChannel==fMapADC[k][1]){
526 fSector[0] = fMapADC[k][3];
527 fSector[1] = fMapADC[k][4];
532 //printf("AliZDCRawStream -> ADCmod. %d ADCch %d det %d, sec %d\n",
533 // fADCModule,fADCChannel,fSector[0],fSector[1]);
536 if(fSector[0]<1 || fSector[0]>5){
537 AliError(Form(" AliZDCRawStream -> No valid detector assignment: %d\n",fSector[0]));
538 fRawReader->AddMajorErrorLog(kInvalidSector);
541 if(fSector[1]<0 || fSector[1]>5){
542 AliError(Form(" AliZDCRawStream -> No valid sector assignment: %d\n",fSector[1]));
543 fRawReader->AddMajorErrorLog(kInvalidSector);
546 if(fADCModule<0 || fADCModule>3){
547 AliError(Form(" AliZDCRawStream -> No valid ADC module: %d\n",fADCModule));
548 fRawReader->AddMajorErrorLog(kInvalidADCModule);
551 }//No underflow nor overflow
554 else if((fBuffer & 0x07000000) == 0x04000000){
556 //printf(" AliZDCRawStream -> EOB --------------------------\n");
567 //_____________________________________________________________________________
568 void AliZDCRawStream::DecodeScaler()
570 // Decoding scaler event
572 if(!fBuffer & 0x04000000){
573 AliWarning(" AliZDCRawStream -> Scaler header corrupted\n");
574 fIsScEventGood = kFALSE;
576 Int_t scNwords = (Int_t) fScNWords;
577 if(fPosition==scNwords && fBuffer != 0x0){
578 AliWarning(" AliZDCRawStream -> Scaler trailer corrupted\n");
579 fIsScEventGood = kFALSE;
581 fIsScEventGood = kTRUE;
584 fScNWords = (fBuffer & 0x00fc0000)>>18;
585 fScGeo = (fBuffer & 0xf8000000)>>27;
586 fScTS = (fBuffer & 0x00030000)>>16;
587 fScTriggerNumber = (fBuffer & 0x0000ffff);
594 //_____________________________________________________________________________
595 AliCDBStorage* AliZDCRawStream::SetStorage(const char *uri)
597 // Setting the storage
599 AliCDBStorage *storage = AliCDBManager::Instance()->GetStorage(uri);
605 //_____________________________________________________________________________
606 AliZDCChMap* AliZDCRawStream::GetChMap() const
609 // Getting calibration object for ZDC
611 AliCDBEntry *entry = AliCDBManager::Instance()->Get("ZDC/Calib/ChMap");
612 if(!entry) AliFatal("No calibration data loaded!");
614 AliZDCChMap *calibdata = dynamic_cast<AliZDCChMap*> (entry->GetObject());
615 if(!calibdata) AliFatal("Wrong calibration object in calibration file!");