]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliZDCRawStream.cxx
Updates
[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   fIsUnderflow(kFALSE),
65   fIsOverflow(kFALSE),
66   fScNWords(0),   
67   fScGeo(0),      
68   fScTS(0),       
69   fScTriggerNumber(0),
70   fIsScEventGood(kFALSE),
71   fNChannelsOn(0),
72   fNConnCh(-1),
73   fCabledSignal(-1)
74 {
75   // Create an object to read ZDC raw digits
76   fRawReader->Reset();
77   fRawReader->Select("ZDC");
78   //
79   const int kNch = 48;
80   for(Int_t i=0; i<kNch; i++){
81     for(Int_t j=0; j<5; j++) fMapADC[i][j]=-1;
82   }
83
84 }
85
86 //_____________________________________________________________________________
87 AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
88   TObject(stream),
89   fRawReader(stream.fRawReader),
90   fBuffer(stream.GetRawBuffer()),
91   fEvType(stream.fEvType),
92   fPosition(stream.fPosition),
93   fIsCalib(stream.fIsCalib),
94   fIsDARCHeader(stream.fIsDARCHeader), 
95   fIsChMapping(stream.fIsChMapping),
96   fIsADCDataWord(stream.fIsADCDataWord), 
97   fIsADCHeader(stream.fIsADCHeader), 
98   fIsADCEOB(stream.fIsADCEOB), 
99   fSODReading(stream.fSODReading),
100   fIsMapRead(stream.fIsMapRead),
101   fDARCEvBlockLenght(stream.fDARCEvBlockLenght),  
102   fDARCBlockAttributes(stream.fDARCBlockAttributes),
103   fDeadfaceOffset(stream.GetDeadfaceOffset()),
104   fDeadbeefOffset(stream.GetDeadbeefOffset()),
105   fDataOffset(stream.GetDataOffset()),
106   fModType(stream.GetModType()),
107   fADCModule(stream.GetADCModule()),     
108   fADCNChannels(stream.GetADCNChannels()),       
109   fADCChannel(stream.GetADCChannel()),   
110   fADCValue(stream.GetADCValue()),       
111   fADCGain(stream.GetADCGain()),
112   fIsUnderflow(stream.fIsUnderflow),
113   fIsOverflow(stream.fIsOverflow),
114   fScNWords(stream.GetScNWords()),        
115   fScGeo(stream.GetScGeo()),      
116   fScTS(stream.GetScTS()),        
117   fScTriggerNumber(stream.fScTriggerNumber),
118   fIsScEventGood(stream.fIsScEventGood),
119   fNChannelsOn(stream.fNChannelsOn),
120   fNConnCh(stream.fNConnCh),
121   fCabledSignal(stream.GetCabledSignal())
122 {
123   // Copy constructor
124   const int kNch = 48;
125   for(Int_t j=0; j<2; j++) fSector[j] = stream.GetSector(j);     
126   for(Int_t i=0; i<kNch; i++){
127     for(Int_t j=0; j<5; j++) fMapADC[i][j] = stream.fMapADC[i][j];
128   }
129 }
130
131 //_____________________________________________________________________________
132 AliZDCRawStream& AliZDCRawStream::operator = (const AliZDCRawStream& 
133                                               /* stream */)
134 {
135   // Assignment operator
136   Fatal("operator =", "assignment operator not implemented");
137   return *this;
138 }
139
140 //_____________________________________________________________________________
141 AliZDCRawStream::~AliZDCRawStream()
142 {
143 // Destructor
144
145 }
146
147 //_____________________________________________________________________________
148 void AliZDCRawStream::ReadChMap()
149 {
150   // Reading channel map
151   const int kNch = 48;
152   printf("\n\t Reading ZDC ADC mapping from OCDB\n");
153   AliZDCChMap * chMap = GetChMap();
154   //chMap->Print("");
155   for(Int_t i=0; i<kNch; i++){
156     fMapADC[i][0] = chMap->GetADCModule(i);
157     fMapADC[i][1] = chMap->GetADCChannel(i);
158     fMapADC[i][2] = -1;
159     fMapADC[i][3] = chMap->GetDetector(i);
160     fMapADC[i][4] = chMap->GetSector(i);
161   }
162   fIsMapRead = kTRUE;
163 }
164
165 //_____________________________________________________________________________
166 void AliZDCRawStream::ReadCDHHeader()
167 {
168   // Reading CDH 
169   const AliRawDataHeader* header = fRawReader->GetDataHeader();
170   if(!header) {
171       AliError(" No CDH in raw data streaming");
172       fRawReader->AddMajorErrorLog(kCDHError);
173       return;
174   }
175   else{
176     //printf("\t AliZDCRawStream::ReadCDHHeader -> Data Size = %d\n",fRawReader->GetDataSize());
177
178     fDARCEvBlockLenght = header->fSize;
179     //printf("\t AliZDCRawStream::ReadCDHHeader -> fDARCEvBlockLenght = %d\n",fDARCEvBlockLenght);
180     
181     UChar_t message = header->GetAttributes();
182     //printf("\t AliZDCRawStream::ReadCDHHeader -> Attributes %x\n",message);
183     
184     if(message & 0x0){ // PHYSICS RUN
185        //printf("\t PHYSICS RUN raw data found\n");
186     }
187     else if(message & 0x10){ // COSMIC RUN
188        //printf("\t STANDALONE_COSMIC RUN raw data found\n");
189     }
190     else if(message & 0x20){ // PEDESTAL RUN
191        //printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
192     }
193     else if(message & 0x30){ // LASER RUN
194        //printf("\t STANDALONE_LASER RUN raw data found\n");
195     }
196     else if(message & 0x40){ // CALIBRATION_CENTRAL RUN
197        //printf("\t CALIBRATION_CENTRAL RUN raw data found\n");
198     }
199     else if(message & 0x50){ // CALIBRATION_SEMICENTRAL
200        //printf("\t CALIBRATION_SEMICENTRAL RUN raw data found\n");
201     }
202     else if(message & 0x60){ // CALIBRATION_MB
203        //printf("\t CALIBRATION_MB RUN raw data found\n");
204     }
205     else if(message & 0x70){ // CALIBRATION_EMD
206        //printf("\t CALIBRATION_EMD RUN raw data found\n");
207     }
208     
209     if(header->GetL1TriggerMessage() & 0x1){ // Calibration bit set in CDH
210       fIsCalib = kTRUE;
211     }
212     //printf("\t AliZDCRawStream::ReadCDHHeader -> L1TriggerMessage %x\n",header->GetL1TriggerMessage());
213     //printf("\t AliZDCRawStream::ReadCDHHeader -> Calibration bit = %d\n",fIsCalib);    
214     
215     UInt_t status = header->GetStatus();
216     //printf("\t AliZDCRawStream::ReadCDHHeader -> status = %d\n",status);
217     if((status & 0x000f) == 0x0001){
218       AliWarning("CDH -> DARC trg0 overlap error");
219       fRawReader->AddMajorErrorLog(kDARCError);
220     }
221     if((status & 0x000f) == 0x0002){
222       AliWarning("CDH -> DARC trg0 missing error");
223       fRawReader->AddMajorErrorLog(kDARCError);
224     }
225     if((status & 0x000f) == 0x0004){
226       AliWarning("CDH -> DARC data parity error");
227       fRawReader->AddMajorErrorLog(kDARCError);
228     }
229     if((status & 0x000f) == 0x0008){
230       AliWarning("CDH -> DARC ctrl parity error");
231       fRawReader->AddMajorErrorLog(kDARCError);
232     }
233     //
234     if((status & 0x00f0) == 0x0010){
235       AliWarning("CDH -> DARC trg unavailable");
236       fRawReader->AddMajorErrorLog(kDARCError);
237     }
238     if((status & 0x00f0) == 0x0020){
239       AliWarning("CDH -> DARC FEE error");
240       fRawReader->AddMajorErrorLog(kDARCError);
241     }
242     //
243     if((status & 0x0f00) == 0x0200){
244       AliWarning("CDH -> DARC L1 time violation");
245       fRawReader->AddMajorErrorLog(kDARCError);
246     }
247     if((status & 0x0f00) == 0x0400){
248       AliWarning("CDH -> DARC L2 time-out");
249       fRawReader->AddMajorErrorLog(kDARCError);
250     }
251     if((status & 0x0f00) == 0x0800){
252       AliWarning("CDH -> DARC prepulse time violation");
253       fRawReader->AddMajorErrorLog(kDARCError);
254     }
255     //
256     if((status & 0xf000) == 0x1000){
257       AliWarning("CDH -> DARC other error");
258       fRawReader->AddMajorErrorLog(kDARCError);
259     }
260   }
261   //
262   fIsDARCHeader = kTRUE;
263 }
264
265 //_____________________________________________________________________________
266 Bool_t AliZDCRawStream::Next()
267 {
268   // Read the next raw digit
269   // Returns kFALSE if there is no digit left
270
271   if(!fRawReader->ReadNextInt((UInt_t&) fBuffer)) return kFALSE;
272   const int kNch = 48;
273   Bool_t readScaler = kFALSE;
274   fIsChMapping = kFALSE; fIsADCHeader = kFALSE; 
275   fIsADCDataWord = kFALSE; fIsADCEOB = kFALSE;
276   fIsUnderflow = kFALSE;
277   fIsOverflow = kFALSE; 
278   fSector[0] = fSector[1] = -1;
279   
280   fEvType = fRawReader->GetType();
281   // CH. debug
282   //printf("\n\t AliZDCRawStream::Next() -> ev. type %d\n",fEvType);
283   //printf("\n  AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
284   
285   if(fPosition==0){
286     //if(fEvType==7 || fEvType ==8){ //Physics or calibration event
287       //ReadEventHeader();
288       ReadCDHHeader();
289     //}
290     fNConnCh=0;
291   }
292   
293   // *** End of ZDC event
294   if(fBuffer == 0xcafefade){
295     //printf("\n-> AliZDCRawStream::Next() ***** End of ZDC event *****\n\n");
296     return kFALSE;
297   }
298   
299   // -------------------------------------------
300   // --- DARC header
301   // -------------------------------------------
302   // If the CDH has been read then 
303   // the DARC header must follow
304   if(fIsDARCHeader){
305     //printf("\t ---- DARC header ----\n");
306     if(fIsCalib){
307       fDeadfaceOffset = 9;
308       fDeadbeefOffset = 25;
309       readScaler = kTRUE;
310     }
311     else{
312       fDeadfaceOffset = 1;
313       fDeadbeefOffset = 7;
314     }
315     fDataOffset = 1+fDeadbeefOffset;
316     fIsDARCHeader = kFALSE;
317   }
318
319     
320   // -------------------------------------------
321   // --- Start of data event
322   // --- decoding mapping of connected ADC ch.
323   // -------------------------------------------
324   // In the SOD event ADC ch. mapping is written
325   if(fEvType==10 && fSODReading){
326     //printf("\n-> AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
327     
328     if(fPosition>fDataOffset){
329       if((fBuffer&0xff000000) == 0xff000000){
330         if(fPosition==(fDataOffset+1)){ 
331            printf("\n\n\t AliZDCRawStream -> Reading mapping from StartOfData event\n");
332            fNConnCh=0;  
333         }
334         else{
335           //printf("\n\t AliZDCRawStream -> End of ZDC StartOfData event\n\n");
336           //printf("AliZDCRawStream: fSODReading after SOD reading set to %d\n", fSODReading);
337           return kFALSE;
338         }
339       }
340       else if((fBuffer&0x80000000)>>31 == 1){
341         // Mapping identification
342         fADCModule = ((fBuffer & 0x7f000000)>>24);
343         fModType = ((fBuffer & 0x7ff00)>>8);
344         fADCNChannels = (fBuffer & 0xff);
345         //
346         //printf("  ******** GEO %d, mod. type %d, #ch. %d\n",fADCModule,fModType,fADCNChannels);
347       }
348       else if(fModType==1 && (fBuffer&0x80000000)>>31 == 0){
349         // Channel signal
350         if((fBuffer&0x40000000)>>30==0){ // high range chain ADC
351           fIsChMapping = kTRUE;
352           fADCChannel = ((fBuffer & 0x3fff0000)>>16);
353           fCabledSignal = (fBuffer&0xffff);
354           //printf("\tADC ch. %d, signal %d\n",fADCChannel,fCabledSignal);
355           //
356           fMapADC[fNConnCh][0] = fADCModule;
357           fMapADC[fNConnCh][1] = fADCChannel;
358           fMapADC[fNConnCh][2] = fCabledSignal;
359           //
360           // Determining detector and sector
361           // -----------------------------------------
362           //  For the decoding of the following lines 
363           //  look the enum in AliZDCRawStream.h file
364           // -----------------------------------------
365           if((fCabledSignal>=2 && fCabledSignal<=6) || (fCabledSignal>=26 && fCabledSignal<=30)
366              || fCabledSignal==24 || fCabledSignal==48){
367             fMapADC[fNConnCh][3] = 4; //ZNA
368             //
369             if(fCabledSignal==2 || fCabledSignal==26)       fMapADC[fNConnCh][4]=0;
370             else if(fCabledSignal==3 || fCabledSignal==27)  fMapADC[fNConnCh][4]=1;
371             else if(fCabledSignal==4 || fCabledSignal==28)  fMapADC[fNConnCh][4]=2;
372             else if(fCabledSignal==5 || fCabledSignal==29)  fMapADC[fNConnCh][4]=3;
373             else if(fCabledSignal==6 || fCabledSignal==30)  fMapADC[fNConnCh][4]=4;
374             else if(fCabledSignal==24 || fCabledSignal==48) fMapADC[fNConnCh][4]=5;
375           }
376           else if((fCabledSignal>=7 && fCabledSignal<=11) || (fCabledSignal>=31 && fCabledSignal<=35)){
377             fMapADC[fNConnCh][3] = 5; //ZPA
378             //
379             if(fCabledSignal==7 || fCabledSignal==31)       fMapADC[fNConnCh][4]=0;
380             else if(fCabledSignal==8 || fCabledSignal==32)  fMapADC[fNConnCh][4]=1;
381             else if(fCabledSignal==9 || fCabledSignal==33)  fMapADC[fNConnCh][4]=2;
382             else if(fCabledSignal==10 || fCabledSignal==34) fMapADC[fNConnCh][4]=3;
383             else if(fCabledSignal==11 || fCabledSignal==35) fMapADC[fNConnCh][4]=4;
384           }
385           else if((fCabledSignal>=12 && fCabledSignal<=16) || (fCabledSignal>=36 && fCabledSignal<=40)
386              || fCabledSignal==25 || fCabledSignal==49){
387             fMapADC[fNConnCh][3] = 1; //ZNC
388             //
389             if(fCabledSignal==12 || fCabledSignal==36)      fMapADC[fNConnCh][4]=0;
390             else if(fCabledSignal==13 || fCabledSignal==37) fMapADC[fNConnCh][4]=1;
391             else if(fCabledSignal==14 || fCabledSignal==38) fMapADC[fNConnCh][4]=2;
392             else if(fCabledSignal==15 || fCabledSignal==39) fMapADC[fNConnCh][4]=3;
393             else if(fCabledSignal==16 || fCabledSignal==40) fMapADC[fNConnCh][4]=4;
394             else if(fCabledSignal==25 || fCabledSignal==49) fMapADC[fNConnCh][4]=5;
395           }
396           else if((fCabledSignal>=17 && fCabledSignal<=21) || (fCabledSignal>=41 && fCabledSignal<=45)){
397             fMapADC[fNConnCh][3] = 2; //ZPC
398             //
399             if(fCabledSignal==17 || fCabledSignal==41)      fMapADC[fNConnCh][4]=0;
400             else if(fCabledSignal==18 || fCabledSignal==42) fMapADC[fNConnCh][4]=1;
401             else if(fCabledSignal==19 || fCabledSignal==43) fMapADC[fNConnCh][4]=2;
402             else if(fCabledSignal==20 || fCabledSignal==44) fMapADC[fNConnCh][4]=3;
403             else if(fCabledSignal==21 || fCabledSignal==45) fMapADC[fNConnCh][4]=4;
404           }
405           else if(fCabledSignal==22 || fCabledSignal==23 || fCabledSignal==46 || fCabledSignal==47){
406             fMapADC[fNConnCh][3] = 3;
407             //
408             if(fCabledSignal==22 || fCabledSignal==46)      fMapADC[fNConnCh][4]=1;
409             else if(fCabledSignal==23 || fCabledSignal==47) fMapADC[fNConnCh][4]=2;
410           }
411           //
412           fNConnCh++;
413           if(fNConnCh>=kNch){
414             // Protection manually set since it returned:
415             // RawData48 mod. 3 ch. 2048 signal 515
416             // to be checked with Pietro!!!!!!!!!!!!!!!!!!!!!!!
417             AliDebug(2," No. of cabled channels > kNch !!!");
418             fPosition++;
419             return kTRUE;
420           }
421         }
422       }// ModType=1 (ADC mapping)
423       //else if(fModType!=1){
424         
425       //}
426     }
427     fPosition++;
428     return kTRUE;
429   } // SOD event
430   
431   // -------------------------------------------
432   // --- DARC data
433   // -------------------------------------------
434   if(fPosition<fDeadfaceOffset){
435     fPosition++;
436     return kTRUE;
437   }
438   else if(fPosition==fDeadfaceOffset){
439     if(fBuffer != 0xdeadface){
440       AliWarning(" NO deadface after DARC data");
441       fRawReader->AddMajorErrorLog(kDARCError);  
442     }
443     else{
444       fPosition++;
445       return kTRUE;
446     }
447   }
448   
449   // -------------------------------------------
450   // --- DARC global data
451   // -------------------------------------------
452   else if(fPosition>fDeadfaceOffset && fPosition<fDeadbeefOffset){
453     fPosition++;
454     return kTRUE;
455   }
456   else if(fPosition==fDeadbeefOffset){
457     if(fBuffer != 0xdeadbeef){
458       AliWarning(" NO deadbeef after DARC global data");
459       fRawReader->AddMajorErrorLog(kDARCError);  
460     }
461     else{
462       fPosition++;
463       return kTRUE;
464     }
465   }
466
467   // -------------------------------------------
468   // --- ZDC data
469   // --- ADC buffer + scaler
470   // -------------------------------------------
471   else if(fPosition>=fDataOffset){
472     
473     //printf("AliZDCRawStream: fSODReading = %d\n", fSODReading);
474     if(!fSODReading && !fIsMapRead) ReadChMap();
475     
476     // Not valid datum before the event 
477     // there MUST be a NOT valid datum before the event!!!
478     if(fPosition==fDataOffset){
479       //printf("\t **** ZDC data begin ****\n");
480       if((fBuffer & 0x07000000) != 0x06000000){
481         fRawReader->AddMajorErrorLog(kZDCDataError);
482       }
483       /*else{
484         //printf("    AliZDCRawStream -> Not valid datum in ADC %d,"
485         //       "position %d in word data buffer\n",fADCModule,fPosition);
486       }*/
487     }
488     
489     // If the not valid datum isn't followed by the 1st ADC header
490     // the event is corrupted (i.e., 2 gates arrived before trigger)
491     else if(fPosition==fDataOffset+1){
492       if((fBuffer & 0x07000000) != 0x02000000){
493         AliWarning("ZDC ADC -> The not valid datum is NOT followed by an ADC header!");
494         fRawReader->AddMajorErrorLog(kZDCDataError);
495       }
496     }
497      
498     // Get geo address of current word to determine if:
499     // - it is a scaler word (geo address == kScalerAddress)
500     // - it is an ADC word (geo address <= 3)
501     Int_t kScalerAddress=8;
502     fADCModule = ((fBuffer & 0xf8000000)>>27);
503     if(fADCModule == kScalerAddress){
504       DecodeScaler();
505     } 
506     else if(fADCModule>=0 && fADCModule<=3){//ADC modules (0,1,2,3)
507       // *** ADC header
508       if((fBuffer & 0x07000000) == 0x02000000){
509         fIsADCHeader = kTRUE;
510         fADCNChannels = ((fBuffer & 0x00003f00)>>8);
511         if(fADCModule==0) fNChannelsOn = fADCNChannels;
512         else fNChannelsOn += fADCNChannels;
513         //printf("  AliZDCRawStream -> ADC HEADER: mod.%d has %d ch. \n",fADCModule,fADCNChannels);
514       }
515       // *** ADC data word
516       else if((fBuffer & 0x07000000) == 0x00000000){
517         fIsADCDataWord = kTRUE;
518         fADCChannel = ((fBuffer & 0x1e0000) >> 17);
519         fADCGain = ((fBuffer & 0x10000) >> 16);       
520         fADCValue = (fBuffer & 0xfff);  
521         
522         //printf("  AliZDCRawStream -> DATA: ADC mod. %d ch. %d gain %d value %d\n",
523         //  fADCModule,fADCChannel,fADCGain,fADCValue);
524         
525         // Checking if the channel map for the ADCs has been provided/read
526         if(fMapADC[0][0]==-1){
527           printf("\t ATTENTION!!! No ADC mapping has been found/provided!!!\n");
528           return kFALSE;
529         }
530         //
531         /*for(Int_t ci=0; ci<kNch; ci++){
532           printf("  %d mod %d ch %d det %d sec %d\n",ci,fMapADC[ci][0],
533           fMapADC[ci][1], fMapADC[ci][3], fMapADC[ci][4]);
534         }*/
535                 
536         // Scan of the map to assign the correct volumes
537         Int_t foundMapEntry = kFALSE;
538         for(Int_t k=0; k<kNch; k++){
539            if(fADCModule==fMapADC[k][0] && fADCChannel==fMapADC[k][1]){
540              fSector[0] = fMapADC[k][3];
541              fSector[1] = fMapADC[k][4];
542              foundMapEntry = kTRUE;
543              break;
544            } 
545         }
546         if(foundMapEntry==kFALSE){
547           AliWarning(Form(" No valid entry found in ADC mapping for raw data %d ADCmod. %d ch. %d gain %d\n",
548               fPosition,fADCModule,fADCChannel,fADCGain));
549         }
550         //
551         //printf("AliZDCRawStream -> ADCmod. %d ch. %d gain %d -> det %d sec %d\n",
552         //  fADCModule,fADCChannel,fADCGain,fSector[0],fSector[1]);
553         
554         // Final checks
555         if(foundMapEntry==kTRUE){
556           if(fSector[0]<1 || fSector[0]>5){
557             AliWarning(Form(" No valid detector assignment: %d",fSector[0]));
558             fRawReader->AddMajorErrorLog(kInvalidSector);
559           }
560           //
561           if(fSector[1]<0 || fSector[1]>5){
562             AliWarning(Form(" No valid sector assignment: %d",fSector[1]));
563             fRawReader->AddMajorErrorLog(kInvalidSector);
564           }
565           //
566           if(fADCModule<0 || fADCModule>3){
567             AliError(Form(" No valid ADC module: %d",fADCModule));
568             fRawReader->AddMajorErrorLog(kInvalidADCModule);
569           }
570         }
571
572         // Checking the underflow and overflow bits
573         if(fBuffer & 0x1000)       fIsUnderflow = kTRUE;
574         else if (fBuffer & 0x2000) fIsOverflow = kTRUE; 
575                 
576       }//ADC data word
577       // *** ADC EOB
578       else if((fBuffer & 0x07000000) == 0x04000000){
579         fIsADCEOB = kTRUE;
580         //printf("  AliZDCRawStream -> EOB --------------------------\n");
581       }
582      }//ADC module
583         
584     
585   }
586   fPosition++;
587
588   return kTRUE;
589 }
590
591 //_____________________________________________________________________________
592 void AliZDCRawStream::DecodeScaler()
593 {
594   // Decoding scaler event
595   
596   if(!fBuffer & 0x04000000){
597     AliWarning(" Scaler header corrupted");
598     fIsScEventGood = kFALSE; 
599   }
600   Int_t scNwords = (Int_t) fScNWords;
601   if(fPosition==scNwords && fBuffer != 0x0){
602     AliWarning(" Scaler trailer corrupted");
603     fIsScEventGood = kFALSE; 
604   }
605   fIsScEventGood = kTRUE;
606   
607   if(fPosition==0){
608     fScNWords = (fBuffer & 0x00fc0000)>>18;        
609     fScGeo = (fBuffer & 0xf8000000)>>27;           
610     fScTS = (fBuffer & 0x00030000)>>16;    
611     fScTriggerNumber = (fBuffer & 0x0000ffff);
612   }
613    
614   fPosition++;
615   
616 }
617
618 //_____________________________________________________________________________
619 AliCDBStorage* AliZDCRawStream::SetStorage(const char *uri) 
620 {
621   // Setting the storage
622   
623   AliCDBStorage *storage = AliCDBManager::Instance()->GetStorage(uri); 
624
625   return storage; 
626 }
627
628
629 //_____________________________________________________________________________
630 AliZDCChMap* AliZDCRawStream::GetChMap() const
631 {
632
633   // Getting calibration object for ZDC
634
635   AliCDBEntry  *entry = AliCDBManager::Instance()->Get("ZDC/Calib/ChMap");
636   if(!entry) AliFatal("No calibration data loaded!");  
637
638   AliZDCChMap *calibdata = dynamic_cast<AliZDCChMap*> (entry->GetObject());
639   if(!calibdata) AliFatal("Wrong calibration object in calibration  file!");
640
641   return calibdata;
642 }