]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliZDCRawStream.cxx
Minor changes
[u/mrichter/AliRoot.git] / ZDC / AliZDCRawStream.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 // This class provides access to ZDC digits in raw data.                     //
21 //                                                                           //
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.                      //
26 //                                                                           //
27 ///////////////////////////////////////////////////////////////////////////////
28
29 #include <TSystem.h>
30 #include "AliZDCRawStream.h"
31 #include "AliRawReader.h"
32 #include "AliRawDataHeader.h"
33 #include "AliRawEventHeaderBase.h"
34 #include "AliLog.h"
35
36 ClassImp(AliZDCRawStream)
37
38
39 //_____________________________________________________________________________
40 AliZDCRawStream::AliZDCRawStream(AliRawReader* rawReader) :
41   fRawReader(rawReader),
42   fBuffer(0),
43   fEvType(0),
44   fPosition(0),
45   fIsCalib(kFALSE),
46   fIsDARCHeader(kFALSE),
47   fIsChMapping(kFALSE),
48   fIsADCDataWord(kFALSE),
49   fIsADCHeader(kFALSE),
50   fIsADCEOB(kFALSE),
51   fSODReading(kFALSE),
52   fIsMapRead(kFALSE),
53   fDARCEvBlockLenght(0),  
54   fDARCBlockAttributes(0),
55   fDeadfaceOffset(0),
56   fDeadbeefOffset(0),
57   fDataOffset(0),
58   fModType(-1),
59   fADCModule(-1),
60   fADCNChannels(-1),     
61   fADCChannel(-1),       
62   fADCValue(-1),         
63   fADCGain(-1),
64   fScNWords(0),   
65   fScGeo(0),      
66   fScTS(0),       
67   fScTriggerNumber(0),
68   fIsScEventGood(kFALSE),
69   fNConnCh(-1),
70   fCabledSignal(-1)
71 {
72   // Create an object to read ZDC raw digits
73   fRawReader->Reset();
74   fRawReader->Select("ZDC");
75   //
76   for(Int_t i=0; i<48; i++){
77     for(Int_t j=0; j<5; j++) fMapADC[i][j]=-1;
78   }
79
80 }
81
82 //_____________________________________________________________________________
83 AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
84   TObject(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())
115 {
116   // Copy constructor
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];
120   }
121 }
122
123 //_____________________________________________________________________________
124 AliZDCRawStream& AliZDCRawStream::operator = (const AliZDCRawStream& 
125                                               /* stream */)
126 {
127   // Assignment operator
128   Fatal("operator =", "assignment operator not implemented");
129   return *this;
130 }
131
132 //_____________________________________________________________________________
133 AliZDCRawStream::~AliZDCRawStream()
134 {
135 // Destructor
136
137 }
138
139 //_____________________________________________________________________________
140 void AliZDCRawStream::ReadChMap()
141 {
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);
148     fMapADC[i][2] = -1;
149     fMapADC[i][3] = chMap->GetDetector(i);
150     fMapADC[i][4] = chMap->GetSector(i);
151   }
152   fIsMapRead = kTRUE;
153 }
154
155 //_____________________________________________________________________________
156 void AliZDCRawStream::ReadCDHHeader()
157 {
158   // Reading CDH 
159   const AliRawDataHeader* header = fRawReader->GetDataHeader();
160   if(!header) {
161       AliError("\t No CDH in raw data streaming\n");
162       fRawReader->AddMajorErrorLog(kCDHError);
163       return;
164   }
165   else{
166     //printf("\t AliZDCRawStream::ReadCDHHeader -> Data Size = %d\n",fRawReader->GetDataSize());
167
168     fDARCEvBlockLenght = header->fSize;
169     //printf("\t AliZDCRawStream::ReadCDHHeader -> fDARCEvBlockLenght = %d\n",fDARCEvBlockLenght);
170     
171     //UChar_t message = header->GetAttributes();
172     //printf("\t AliZDCRawStream::ReadCDHHeader -> Attributes %x\n",message);
173     
174     /*if(message & 0x10){ // COSMIC RUN
175        printf("\t STANDALONE_COSMIC RUN raw data found\n");
176     }
177     else if(message & 0x20){ // PEDESTAL RUN
178        printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
179     }
180     else if(message & 0x30){ // LASER RUN
181        printf("\t STANDALONE_LASER RUN raw data found\n");
182     }*/
183     
184     if(header->GetL1TriggerMessage() & 0x1){ // Calibration bit set in CDH
185       fIsCalib = kTRUE;
186     }
187     //printf("\t AliZDCRawStream::ReadCDHHeader -> L1TriggerMessage %x\n",header->GetL1TriggerMessage());
188     //printf("\t AliZDCRawStream::ReadCDHHeader -> Calibration bit = %d\n",fIsCalib);    
189     
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);
195     }
196     if(status & 0x000f == 0x0002){
197       AliWarning("CDH -> DARC trg0 missing error\n");
198       fRawReader->AddMajorErrorLog(kDARCError);
199     }
200     if(status & 0x000f == 0x0004){
201       AliWarning("CDH -> DARC data parity error\n");
202       fRawReader->AddMajorErrorLog(kDARCError);
203     }
204     if(status & 0x000f == 0x0008){
205       AliWarning("CDH -> DARC ctrl parity error\n");
206       fRawReader->AddMajorErrorLog(kDARCError);
207     }
208     //
209     if(status & 0x00f0 == 0x0010){
210       AliWarning("CDH -> DARC trg unavailable\n");
211       fRawReader->AddMajorErrorLog(kDARCError);
212     }
213     if(status & 0x00f0 == 0x0020){
214       AliWarning("CDH -> DARC FEE error\n");
215       fRawReader->AddMajorErrorLog(kDARCError);
216     }
217     //
218     if(status & 0x0f00 == 0x0200){
219       AliWarning("CDH -> DARC L1 time violation\n");
220       fRawReader->AddMajorErrorLog(kDARCError);
221     }
222     if(status & 0x0f00 == 0x0400){
223       AliWarning("CDH -> DARC L2 time-out\n");
224       fRawReader->AddMajorErrorLog(kDARCError);
225     }
226     if(status & 0x0f00 == 0x0800){
227       AliWarning("CDH -> DARC prepulse time violation\n");
228       fRawReader->AddMajorErrorLog(kDARCError);
229     }
230     //
231     if(status & 0xf000 == 0x1000){
232       AliWarning("CDH -> DARC other error\n");
233       fRawReader->AddMajorErrorLog(kDARCError);
234     }
235   }
236   //
237   fIsDARCHeader = kTRUE;
238 }
239
240 //_____________________________________________________________________________
241 Bool_t AliZDCRawStream::Next()
242 {
243   // Read the next raw digit
244   // Returns kFALSE if there is no digit left
245
246   if(!fRawReader->ReadNextInt((UInt_t&) fBuffer)) return kFALSE;
247   fIsChMapping = kFALSE; fIsADCHeader = kFALSE; 
248   fIsADCDataWord = kFALSE; fIsADCEOB = kFALSE;
249   
250   fEvType = fRawReader->GetType();
251   //printf("\n\t AliZDCRawStream::Next() -> ev. type %d\n",fEvType);
252   
253   if(fPosition==0){
254     //if(fEvType==7 || fEvType ==8){ //Physics or calibration event
255       //ReadEventHeader();
256       ReadCDHHeader();
257     //}
258     fNConnCh=0;
259   }
260   //printf("\n  AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
261   
262   // -------------------------------------------
263   // --- DARC header
264   // -------------------------------------------
265   // If the CDH has been read then 
266   // the DARC header must follow
267   if(fIsDARCHeader){
268     //printf("\t ---- DARC header ----\n");
269     if(fIsCalib){
270       fDeadfaceOffset = 9;
271       fDeadbeefOffset = 25;
272     }
273     else{
274       fDeadfaceOffset = 1;
275       fDeadbeefOffset = 7;
276     }
277     fDataOffset = 1+fDeadbeefOffset;
278     fIsDARCHeader = kFALSE;
279   }
280   
281     
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);
289     
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");
294            fNConnCh=0;  
295         }
296         else{
297           printf("\n\t End of ZDC StartOfData event\n\n");
298           //printf("AliZDCRawStream: fSODReading after SOD reading set to %d\n", fSODReading);
299           return kFALSE;
300         }
301       }
302       else if((fBuffer&0x80000000)>>31 == 1){
303         // Mapping identification
304         fADCModule = ((fBuffer & 0x7f000000)>>24);
305         fModType = ((fBuffer & 0xfff00)>>8);
306         fADCNChannels = (fBuffer & 0xff);
307         //
308         printf("\tGEO %d, mod. type %d, #ch. %d\n",fADCModule,fModType,fADCNChannels);
309       }
310       else if(fModType==1 && (fBuffer&0x80000000)>>31 == 0){
311         // Channel signal
312         if((fBuffer&0x40000000)>>30==0){ // high range chain ADC
313           fIsChMapping = kTRUE;
314           fADCChannel = ((fBuffer & 0x3fff0000)>>16);
315           fCabledSignal = (fBuffer&0xffff);
316           //
317           //printf("\tADC ch. %d, signal %d\n",fADCChannel,fCabledSignal);
318           //
319           fMapADC[fNConnCh][0] = fADCModule;
320           fMapADC[fNConnCh][1] = fADCChannel;
321           fMapADC[fNConnCh][2] = fCabledSignal;
322           //
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
331             //
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;
338           }
339           else if((fCabledSignal>=7 && fCabledSignal<=11) || (fCabledSignal>=31 && fCabledSignal<=35)){
340             fMapADC[fNConnCh][3] = 5; //ZPA
341             //
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;
347           }
348           else if((fCabledSignal>=12 && fCabledSignal<=16) || (fCabledSignal>=36 && fCabledSignal<=40)
349              || fCabledSignal==25 || fCabledSignal==49){
350             fMapADC[fNConnCh][3] = 1; //ZNC
351             //
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;
358           }
359           else if((fCabledSignal>=17 && fCabledSignal<=21) || (fCabledSignal>=41 && fCabledSignal<=45)){
360             fMapADC[fNConnCh][3] = 2; //ZPC
361             //
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;
367           }
368           else if(fCabledSignal==22 || fCabledSignal==23 || fCabledSignal==46 || fCabledSignal==47){
369             fMapADC[fNConnCh][3] = 3;
370             //
371             if(fCabledSignal==22 || fCabledSignal==46)      fMapADC[fNConnCh][4]=1;
372             else if(fCabledSignal==23 || fCabledSignal==47) fMapADC[fNConnCh][4]=2;
373           }
374           //
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]);
377           //
378           fNConnCh++;
379           if(fNConnCh>48){
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");
384             return kTRUE;
385           }
386         }
387       }// ModType=1 (ADC mapping)
388     }
389     fPosition++;
390     return kTRUE;
391   } // SOD event
392   
393   // -------------------------------------------
394   // --- DARC data
395   // -------------------------------------------
396   if(fPosition<fDeadfaceOffset){
397     fPosition++;
398     return kTRUE;
399   }
400   else if(fPosition==fDeadfaceOffset){
401     if(fBuffer != 0xdeadface){
402       AliError("AliZDCRawStream -> NO deadface after DARC data\n");
403       fRawReader->AddMajorErrorLog(kDARCError);  
404     }
405     else{
406       fPosition++;
407       return kTRUE;
408     }
409   }
410   
411   // -------------------------------------------
412   // --- DARC global data
413   // -------------------------------------------
414   else if(fPosition>fDeadfaceOffset && fPosition<fDeadbeefOffset){
415     fPosition++;
416     return kTRUE;
417   }
418   else if(fPosition==fDeadbeefOffset){
419     if(fBuffer != 0xdeadbeef){
420       AliError("AliZDCRawStream -> NO deadbeef after DARC global data\n");
421       fRawReader->AddMajorErrorLog(kDARCError);  
422     }
423     else{
424       fPosition++;
425       return kTRUE;
426     }
427   }
428
429   // -------------------------------------------
430   // --- ZDC data
431   // --- ADC buffer + scaler
432   // -------------------------------------------
433   else if(fPosition>=fDataOffset){
434     
435     //printf("AliZDCRawStream: fSODReading = %d\n", fSODReading);
436     if(!fSODReading && !fIsMapRead) ReadChMap();
437     
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);
445       }
446       else fRawReader->AddMajorErrorLog(kZDCDataError);
447     }
448     
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);
455       }
456     }
457      
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){
464       DecodeScaler();
465     }
466     else{//ADC module
467       // *** End of event
468       if(fBuffer == 0xcafefade){
469         //printf("  AliZDCRawStream ->  End of ZDC event!\n");
470       }
471       // *** ADC header
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);
476       }
477       // *** ADC data word
478       else if((fBuffer & 0x07000000) == 0x00000000){
479         fIsADCDataWord = kTRUE;
480         fADCChannel = ((fBuffer & 0x1e0000) >> 17);
481         fADCGain = ((fBuffer & 0x10000) >> 16);       
482         fADCValue = (fBuffer & 0xfff);  
483         
484         //printf("  AliZDCRawStream -> DATA: ADC mod. %d ch. %d gain %d value %d\n",
485         //  fADCModule,fADCChannel,fADCGain,fADCValue);
486
487         // Valid ADC data (not underflow nor overflow)
488         if(!(fBuffer & 0x1000) && !(fBuffer & 0x2000)){ 
489         
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");
493             return kFALSE;
494             // Temporary solution (to be changed!!!!)
495             // mapping read from ShuttleInput dir
496             /*char * mapFileName=gSystem->ExpandPathName("$(ALICE_ROOT)/ZDC/ShuttleInput/ZDCChMapping.dat");
497             FILE *file; 
498             Int_t ival[48][6];
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]);
503                 }
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];
509               }
510             }
511             else{
512                 printf("File %s not found\n",mapFileName);
513                 return kFALSE;
514             }*/
515           }
516           //
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]);
520           }
521           */
522           
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];
528                break;
529              } 
530           }
531           //
532           //printf("AliZDCRawStream -> ADCmod. %d ADCch %d det %d, sec %d\n",
533           //  fADCModule,fADCChannel,fSector[0],fSector[1]);
534           
535           // Final checks
536           if(fSector[0]<1 || fSector[0]>5){
537             AliError(Form("      AliZDCRawStream -> No valid detector assignment: %d\n",fSector[0]));
538             fRawReader->AddMajorErrorLog(kInvalidSector);
539           }
540           //
541           if(fSector[1]<0 || fSector[1]>5){
542             AliError(Form("      AliZDCRawStream -> No valid sector assignment: %d\n",fSector[1]));
543             fRawReader->AddMajorErrorLog(kInvalidSector);
544           }
545           //
546           if(fADCModule<0 || fADCModule>3){
547             AliError(Form("      AliZDCRawStream -> No valid ADC module: %d\n",fADCModule));
548             fRawReader->AddMajorErrorLog(kInvalidADCModule);
549           }
550
551         }//No underflow nor overflow    
552       }//ADC data word
553       // *** ADC EOB
554       else if((fBuffer & 0x07000000) == 0x04000000){
555         fIsADCEOB = kTRUE;
556         //printf("  AliZDCRawStream -> EOB --------------------------\n");
557       }
558      }//ADC module
559         
560     
561   }
562   fPosition++;
563
564   return kTRUE;
565 }
566
567 //_____________________________________________________________________________
568 void AliZDCRawStream::DecodeScaler()
569 {
570   // Decoding scaler event
571   
572   if(!fBuffer & 0x04000000){
573     AliWarning("        AliZDCRawStream -> Scaler header corrupted\n");
574     fIsScEventGood = kFALSE; 
575   }
576   Int_t scNwords = (Int_t) fScNWords;
577   if(fPosition==scNwords && fBuffer != 0x0){
578     AliWarning("        AliZDCRawStream -> Scaler trailer corrupted\n");
579     fIsScEventGood = kFALSE; 
580   }
581   fIsScEventGood = kTRUE;
582   
583   if(fPosition==0){
584     fScNWords = (fBuffer & 0x00fc0000)>>18;        
585     fScGeo = (fBuffer & 0xf8000000)>>27;           
586     fScTS = (fBuffer & 0x00030000)>>16;    
587     fScTriggerNumber = (fBuffer & 0x0000ffff);
588   }
589    
590   fPosition++;
591   
592 }
593
594 //_____________________________________________________________________________
595 AliCDBStorage* AliZDCRawStream::SetStorage(const char *uri) 
596 {
597   // Setting the storage
598   
599   AliCDBStorage *storage = AliCDBManager::Instance()->GetStorage(uri); 
600
601   return storage; 
602 }
603
604
605 //_____________________________________________________________________________
606 AliZDCChMap* AliZDCRawStream::GetChMap() const
607 {
608
609   // Getting calibration object for ZDC
610
611   AliCDBEntry  *entry = AliCDBManager::Instance()->Get("ZDC/Calib/ChMap");
612   if(!entry) AliFatal("No calibration data loaded!");  
613
614   AliZDCChMap *calibdata = dynamic_cast<AliZDCChMap*> (entry->GetObject());
615   if(!calibdata) AliFatal("Wrong calibration object in calibration  file!");
616
617   return calibdata;
618 }