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),
51 fDARCEvBlockLenght(0),
52 fDARCBlockAttributes(0),
65 // Create an object to read ZDC raw digits
67 fRawReader->Select("ZDC");
69 for(Int_t i=0; i<48; i++){
70 for(Int_t j=0; j<5; j++) fMapADC[i][j]=-1;
75 //_____________________________________________________________________________
76 AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
78 fRawReader(stream.fRawReader),
79 fBuffer(stream.GetRawBuffer()),
80 fEvType(stream.fEvType),
81 fPosition(stream.fPosition),
82 fIsCalib(stream.fIsCalib),
83 fIsDARCHeader(stream.fIsDARCHeader),
84 fIsChMapping(stream.fIsChMapping),
85 fIsADCDataWord(stream.fIsADCDataWord),
86 fIsADCHeader(stream.fIsADCHeader),
87 fIsADCEOB(stream.fIsADCEOB),
88 fDARCEvBlockLenght(stream.fDARCEvBlockLenght),
89 fDARCBlockAttributes(stream.fDARCBlockAttributes),
90 fDeadfaceOffset(stream.GetDeadfaceOffset()),
91 fDeadbeefOffset(stream.GetDeadbeefOffset()),
92 fDataOffset(stream.GetDataOffset()),
93 fModType(stream.GetModType()),
94 fADCModule(stream.GetADCModule()),
95 fADCNChannels(stream.GetADCNChannels()),
96 fADCChannel(stream.GetADCChannel()),
97 fADCValue(stream.GetADCValue()),
98 fADCGain(stream.GetADCGain()),
99 fNConnCh(stream.fNConnCh),
100 fCabledSignal(stream.GetCabledSignal())
103 for(Int_t j=0; j<2; j++) fSector[j] = stream.GetSector(j);
104 for(Int_t i=0; i<48; i++){
105 for(Int_t j=0; j<5; j++) fMapADC[i][j] = stream.fMapADC[i][j];
109 //_____________________________________________________________________________
110 AliZDCRawStream& AliZDCRawStream::operator = (const AliZDCRawStream&
113 // Assignment operator
114 Fatal("operator =", "assignment operator not implemented");
118 //_____________________________________________________________________________
119 AliZDCRawStream::~AliZDCRawStream()
125 //_____________________________________________________________________________
126 void AliZDCRawStream::ReadChMap()
128 // Reading channel map
131 //_____________________________________________________________________________
132 void AliZDCRawStream::ReadCDHHeader()
135 const AliRawDataHeader* header = fRawReader->GetDataHeader();
137 AliError("\t No CDH in raw data streaming\n");
138 fRawReader->AddMajorErrorLog(kCDHError);
140 // For the moment to debug the classe the event is read
141 // also if the CDH is not present in the data buffer
142 // ******* TO BE CHANGED!!! ***************************
146 //printf("\t AliZDCRawStream::ReadCDHHeader -> Data Size = %d\n",fRawReader->GetDataSize());
148 fDARCEvBlockLenght = header->fSize;
149 //printf("\t AliZDCRawStream::ReadCDHHeader -> fDARCEvBlockLenght = %d\n",fDARCEvBlockLenght);
151 //UChar_t message = header->GetAttributes();
152 //printf("\t AliZDCRawStream::ReadCDHHeader -> Attributes %x\n",message);
154 /*if(message & 0x10){ // COSMIC RUN
155 printf("\t STANDALONE_COSMIC RUN raw data found\n");
157 else if(message & 0x20){ // PEDESTAL RUN
158 printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
160 else if(message & 0x30){ // LASER RUN
161 printf("\t STANDALONE_LASER RUN raw data found\n");
164 if(header->GetL1TriggerMessage() & 0x1){ // Calibration bit set in CDH
167 //printf("\t AliZDCRawStream::ReadCDHHeader -> L1TriggerMessage %x\n",header->GetL1TriggerMessage());
168 //printf("\t AliZDCRawStream::ReadCDHHeader -> Calibration bit = %d\n",fIsCalib);
170 UInt_t status = header->GetStatus();
171 //printf("\t AliZDCRawStream::ReadCDHHeader -> status = %d\n",status);
172 if(status & 0x000f == 0x0001){
173 AliWarning("CDH -> DARC trg0 overlap error\n");
174 fRawReader->AddMajorErrorLog(kDARCError);
176 if(status & 0x000f == 0x0002){
177 AliWarning("CDH -> DARC trg0 missing error\n");
178 fRawReader->AddMajorErrorLog(kDARCError);
180 if(status & 0x000f == 0x0004){
181 AliWarning("CDH -> DARC data parity error\n");
182 fRawReader->AddMajorErrorLog(kDARCError);
184 if(status & 0x000f == 0x0008){
185 AliWarning("CDH -> DARC ctrl parity error\n");
186 fRawReader->AddMajorErrorLog(kDARCError);
189 if(status & 0x00f0 == 0x0010){
190 AliWarning("CDH -> DARC trg unavailable\n");
191 fRawReader->AddMajorErrorLog(kDARCError);
193 if(status & 0x00f0 == 0x0020){
194 AliWarning("CDH -> DARC FEE error\n");
195 fRawReader->AddMajorErrorLog(kDARCError);
198 if(status & 0x0f00 == 0x0200){
199 AliWarning("CDH -> DARC L1 time violation\n");
200 fRawReader->AddMajorErrorLog(kDARCError);
202 if(status & 0x0f00 == 0x0400){
203 AliWarning("CDH -> DARC L2 time-out\n");
204 fRawReader->AddMajorErrorLog(kDARCError);
206 if(status & 0x0f00 == 0x0800){
207 AliWarning("CDH -> DARC prepulse time violation\n");
208 fRawReader->AddMajorErrorLog(kDARCError);
211 if(status & 0xf000 == 0x1000){
212 AliWarning("CDH -> DARC other error\n");
213 fRawReader->AddMajorErrorLog(kDARCError);
217 fIsDARCHeader = kTRUE;
221 //_____________________________________________________________________________
222 Bool_t AliZDCRawStream::Next()
224 // Read the next raw digit
225 // Returns kFALSE if there is no digit left
227 if(!fRawReader->ReadNextInt((UInt_t&) fBuffer)) return kFALSE;
228 fIsChMapping = kFALSE; fIsADCHeader = kFALSE;
229 fIsADCDataWord = kFALSE; fIsADCEOB = kFALSE;
231 fEvType = fRawReader->GetType();
232 //printf("\n\t AliZDCRawStream::Next() -> ev. type %d\n",fEvType);
235 //if(fEvType==7 || fEvType ==8){ //Physics or calibration event
241 //printf("\n AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
243 // -------------------------------------------
245 // -------------------------------------------
247 //printf("\t ---- DARC header ----\n");
250 fDeadbeefOffset = 25;
256 fDataOffset = 1+fDeadbeefOffset;
257 fIsDARCHeader = kFALSE;
261 // -------------------------------------------
262 // --- Start of data event
263 // --- decoding mapping of connected ADC ch.
264 // -------------------------------------------
266 if(fPosition>fDataOffset){
267 if((fBuffer&0xff000000) == 0xff000000){
268 if(fPosition==(fDataOffset+1)){
269 printf("\n\n\t Reading ZDC mapping from StartOfData event\n");
273 //printf("\n\t End of StartOfData event\n\n");
277 else if((fBuffer&0x80000000)>>31 == 1){
278 // Mapping identification
279 fADCModule = ((fBuffer & 0x7f000000)>>24);
280 fModType = ((fBuffer & 0xfff000)>>8);
281 fADCNChannels = (fBuffer & 0xff);
283 //printf("\tGEO %d, mod. type %d, #ch. %d\n",fADCModule,fModType,fADCNChannels);
285 else if(fModType==0 && (fBuffer&0x80000000)>>31 == 0){
287 if((fBuffer&0x40000000)>>30==0){ // high range chain ADC
288 fIsChMapping = kTRUE;
289 fADCChannel = ((fBuffer & 0x3fff0000)>>16);
290 fCabledSignal = (fBuffer&0xffff);
291 fMapADC[fNConnCh][0] = fADCModule;
292 fMapADC[fNConnCh][1] = fADCChannel;
293 fMapADC[fNConnCh][2] = fCabledSignal;
295 // Determining detector and sector
296 // -----------------------------------------
297 // For the decoding of the following lines
298 // look the enum in AliZDCRawStream.h file
299 // -----------------------------------------
300 if((fCabledSignal>=2 && fCabledSignal<=6) || (fCabledSignal>=26 && fCabledSignal<=30)
301 || fCabledSignal==24 || fCabledSignal==48){
302 fMapADC[fNConnCh][3] = 4; //ZNA
304 if(fCabledSignal==2 || fCabledSignal==26) fMapADC[fNConnCh][4]=0;
305 else if(fCabledSignal==3 || fCabledSignal==27) fMapADC[fNConnCh][4]=1;
306 else if(fCabledSignal==4 || fCabledSignal==28) fMapADC[fNConnCh][4]=2;
307 else if(fCabledSignal==5 || fCabledSignal==29) fMapADC[fNConnCh][4]=3;
308 else if(fCabledSignal==6 || fCabledSignal==30) fMapADC[fNConnCh][4]=4;
309 else if(fCabledSignal==24 || fCabledSignal==48) fMapADC[fNConnCh][4]=5;
311 else if((fCabledSignal>=7 && fCabledSignal<=11) || (fCabledSignal>=31 && fCabledSignal<=35)){
312 fMapADC[fNConnCh][3] = 5; //ZPA
314 if(fCabledSignal==7 || fCabledSignal==31) fMapADC[fNConnCh][4]=0;
315 else if(fCabledSignal==8 || fCabledSignal==32) fMapADC[fNConnCh][4]=1;
316 else if(fCabledSignal==9 || fCabledSignal==33) fMapADC[fNConnCh][4]=2;
317 else if(fCabledSignal==10 || fCabledSignal==34) fMapADC[fNConnCh][4]=3;
318 else if(fCabledSignal==11 || fCabledSignal==35) fMapADC[fNConnCh][4]=4;
320 else if((fCabledSignal>=12 && fCabledSignal<=16) || (fCabledSignal>=36 && fCabledSignal<=40)
321 || fCabledSignal==25 || fCabledSignal==49){
322 fMapADC[fNConnCh][3] = 1; //ZNC
324 if(fCabledSignal==12 || fCabledSignal==36) fMapADC[fNConnCh][4]=0;
325 else if(fCabledSignal==13 || fCabledSignal==37) fMapADC[fNConnCh][4]=1;
326 else if(fCabledSignal==14 || fCabledSignal==38) fMapADC[fNConnCh][4]=2;
327 else if(fCabledSignal==15 || fCabledSignal==39) fMapADC[fNConnCh][4]=3;
328 else if(fCabledSignal==16 || fCabledSignal==40) fMapADC[fNConnCh][4]=4;
329 else if(fCabledSignal==25 || fCabledSignal==49) fMapADC[fNConnCh][4]=5;
331 else if((fCabledSignal>=17 && fCabledSignal<=21) || (fCabledSignal>=41 && fCabledSignal<=45)){
332 fMapADC[fNConnCh][3] = 2; //ZPC
334 if(fCabledSignal==17 || fCabledSignal==41) fMapADC[fNConnCh][4]=0;
335 else if(fCabledSignal==18 || fCabledSignal==42) fMapADC[fNConnCh][4]=1;
336 else if(fCabledSignal==19 || fCabledSignal==43) fMapADC[fNConnCh][4]=2;
337 else if(fCabledSignal==20 || fCabledSignal==44) fMapADC[fNConnCh][4]=3;
338 else if(fCabledSignal==21 || fCabledSignal==45) fMapADC[fNConnCh][4]=4;
340 else if(fCabledSignal==22 || fCabledSignal==23 || fCabledSignal==46 || fCabledSignal==47){
341 fMapADC[fNConnCh][3] = 3;
343 if(fCabledSignal==22 || fCabledSignal==46) fMapADC[fNConnCh][4]=1;
344 else if(fCabledSignal==23 || fCabledSignal==47) fMapADC[fNConnCh][4]=2;
347 //printf("AliZDCRawStream -> datum %d mod. %d ch. %d signal %d, det %d, tow %d\n",
348 // fNConnCh,fADCModule,fADCChannel,fBuffer&0xffff,fMapADC[fNConnCh][3],fMapADC[fNConnCh][4]);
352 // Protection manually set since it returns:
353 // RawData48 mod. 3 ch. 2048 signal 515
354 // to be checked with Pietro!!!!!!!!!!!!!!!!!!!!!!!
355 AliWarning("\t AliZDCRawStream -> ERROR: no. of cabled channels > 48!!!\n");
365 // -------------------------------------------
367 // -------------------------------------------
368 if(fPosition<fDeadfaceOffset){
372 else if(fPosition==fDeadfaceOffset){
373 if(fBuffer != 0xdeadface){
374 AliWarning("AliZDCRawStream -> NO deadface after DARC data\n");
375 fRawReader->AddMajorErrorLog(kDARCError);
383 // -------------------------------------------
384 // --- DARC global data
385 // -------------------------------------------
386 else if(fPosition>fDeadfaceOffset && fPosition<fDeadbeefOffset){
390 else if(fPosition==fDeadbeefOffset){
391 if(fBuffer != 0xdeadbeef){
392 AliWarning("AliZDCRawStream -> NO deadbeef after DARC global data\n");
393 fRawReader->AddMajorErrorLog(kDARCError);
401 // -------------------------------------------
403 // --- ADC buffer + scaler
404 // -------------------------------------------
405 else if(fPosition>=fDataOffset){
407 // Not valid datum before the event
408 // there MUST be a NOT valid datum before the event!!!
409 if(fPosition==fDataOffset){
410 //printf("\t **** ZDC data begin ****\n");
411 if((fBuffer & 0x07000000) == 0x06000000){
412 //printf(" AliZDCRawStream -> Not valid datum in ADC %d,"
413 // "position %d in word data buffer\n",fADCModule,fPosition);
415 else fRawReader->AddMajorErrorLog(kZDCDataError);
418 // If the not valid datum isn't followed by the 1st ADC header
419 // the event is corrupted (i.e., 2 gates arrived before trigger)
420 else if(fPosition==fDataOffset+1){
421 if((fBuffer & 0x07000000) != 0x02000000){
422 AliWarning("ZDC ADC -> The not valid datum is NOT followed by an ADC header!\n");
423 fRawReader->AddMajorErrorLog(kZDCDataError);
427 // Get geo address of current word to determine
428 // if it is a scaler word (geo address == kScalerAddress)
429 // if it is an ADC word (geo address != 8)
430 Int_t kScalerAddress=8;
431 fADCModule = ((fBuffer & 0xf8000000)>>27);
432 if(fADCModule == kScalerAddress){
437 if(fBuffer == 0xcafefade){
438 //printf(" AliZDCRawStream -> End of ZDC event!\n");
441 else if((fBuffer & 0x07000000) == 0x02000000){
442 fIsADCHeader = kTRUE;
443 fADCNChannels = ((fBuffer & 0x00003f00)>>8);
444 //printf(" AliZDCRawStream -> HEADER: ADC mod.%d has %d ch. \n",fADCModule,fADCNChannels);
447 else if((fBuffer & 0x07000000) == 0x00000000){
448 fIsADCDataWord = kTRUE;
449 fADCChannel = ((fBuffer & 0x1e0000) >> 17);
450 fADCGain = ((fBuffer & 0x10000) >> 16);
451 fADCValue = (fBuffer & 0xfff);
453 //printf(" AliZDCRawStream -> DATA: ADC mod. %d ch. %d gain %d value %d\n",
454 // fADCModule,fADCChannel,fADCGain,fADCValue);
456 // Valid ADC data (not underflow nor overflow)
457 if(!(fBuffer & 0x1000) && !(fBuffer & 0x2000)){
459 // Checking if the channel map for the ADCs has been provided/read
460 if(fMapADC[0][0]==-1){
461 // Temporary solution (to be changed!!!!)
462 //printf("\t ATTENTION!!! No ADC mapping has been found/provided!!!\n");
464 char * mapFileName=gSystem->ExpandPathName("$ALICE_ROOT/ZDC/ShuttleInput/ZDCChMapping.dat");
467 if((file = fopen(mapFileName,"r")) != NULL){
468 for(Int_t j=0; j<48; j++){
469 for(Int_t k=0; k<6; k++){
470 fscanf(file,"%d",&ival[j][k]);
472 fMapADC[j][0] = ival[j][1];
473 fMapADC[j][1] = ival[j][2];
474 fMapADC[j][2] = ival[j][3];
475 fMapADC[j][3] = ival[j][4];
476 fMapADC[j][4] = ival[j][5];
480 printf("File %s not found\n",mapFileName);
486 //printf("\n Reading map!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
487 /*for(Int_t ci=0; ci<48; ci++){
488 printf(" %d mod. %d ch. %d signal %d\n",ci,fMapADC[ci][0],
489 fMapADC[ci][1], fMapADC[ci][2]);
492 for(Int_t k=0; k<48; k++){
493 if(fADCModule==fMapADC[k][0] && fADCChannel==fMapADC[k][1]){
494 fSector[0] = fMapADC[k][3];
495 fSector[1] = fMapADC[k][4];
500 //printf("AliZDCRawStream -> ADCmod. %d ADCch %d det %d, sec %d\n",
501 // fADCModule,fADCChannel,fSector[0],fSector[1]);
503 if(fADCModule<0 || fADCModule>3){
504 AliWarning(Form(" AliZDCRawStream -> No valid ADC module: %d\n",fADCModule));
505 fRawReader->AddMajorErrorLog(kInvalidADCModule);
508 }//No underflow nor overflow
511 else if((fBuffer & 0x07000000) == 0x04000000){
513 //printf(" AliZDCRawStream -> EOB --------------------------\n");