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