]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliZDCRawStream.cxx
Bug corrected in QA checker
[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   fReadOutCard(-1),
44   fEvType(0),
45   fPosition(0),
46   fIsCalib(kFALSE),
47   fIsDARCHeader(kFALSE),
48   fIsHeaderMapping(kFALSE),
49   fIsChMapping(kFALSE),
50   fIsADCDataWord(kFALSE),
51   fIsADCHeader(kFALSE),
52   fIsADCEOB(kFALSE),
53   fSODReading(kFALSE),
54   fIsMapRead(kFALSE),
55   fDeadfaceOffset(-1),
56   fDeadbeefOffset(-1),
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   fIsScalerWord(kFALSE),
75   fDetPattern(0),
76   fTrigCountNWords(0),
77   fIsTriggerScaler(kFALSE),
78   fTrigCountStart(0),
79   fMBTrigInput(0),         
80   fCentralTrigInput(0), 
81   fSCentralTrigInput(0),
82   fEMDTrigInput(0),     
83   fL0Received(0),          
84   fMBtrig2CTP(0),          
85   fCentralTrig2CTP(0),  
86   fSCentralTrig2CTP(0), 
87   fEMDTrig2CTP(0),            
88   fTrigHistNWords(0),
89   fIsTriggerHistory(kFALSE),
90   fTrigHistStart(0),
91   fPileUpBit1stWord(0),
92   fL0Bit1stWord(0),
93   fCentralTrigHist(0),
94   fMBTrigHist(0),
95   fPileUpBit2ndWord(0),
96   fL0Bit2ndWord(0), 
97   fSCentralTrigHist(0),
98   fEMDTrigHist(0),
99   fNChannelsOn(0),
100   fCurrentCh(-1),
101   fCabledSignal(-1),
102   fCurrScCh(-1),
103   fIsADCEventGood(kTRUE),
104   fIsL0BitSet(kTRUE),
105   fIsPileUpEvent(kFALSE),
106   fIsADDChannel(kFALSE),
107   fADDADCdatum(0),
108   fIsTDCHeaderRead(kFALSE),
109   fTDCStartCounter(0),
110   fIsZDCTDCHeader(kFALSE),
111   fIsZDCTDCdatum(kFALSE),
112   fZDCTDCdatum(0),
113   fIsADDTDCHeader(kFALSE),
114   fIsADDTDCdatum(kFALSE),
115   fADDTDCdatum(0)
116 {
117   // Create an object to read ZDC raw digits
118   fRawReader->Reset();
119   fRawReader->Select("ZDC");
120   //
121   const int kNch = 48;
122   for(Int_t i=0; i<kNch; i++){
123     for(Int_t j=0; j<5; j++){
124       fMapADC[i][j]=-1;
125       if(i<32) fScalerMap[i][j]=-1;
126     }
127   }
128   
129   for(Int_t k=0; k<4; k++) fCPTInput[k] = 0;
130
131 }
132
133 //_____________________________________________________________________________
134 AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
135   TObject(stream),
136   fRawReader(stream.fRawReader),
137   fBuffer(stream.GetRawBuffer()),
138   fReadOutCard(stream.GetReadOutCard()),
139   fEvType(stream.fEvType),
140   fPosition(stream.fPosition),
141   fIsCalib(stream.fIsCalib),
142   fIsDARCHeader(stream.fIsDARCHeader), 
143   fIsHeaderMapping(stream.fIsHeaderMapping),
144   fIsChMapping(stream.fIsChMapping),
145   fIsADCDataWord(stream.fIsADCDataWord), 
146   fIsADCHeader(stream.fIsADCHeader), 
147   fIsADCEOB(stream.fIsADCEOB), 
148   fSODReading(stream.fSODReading),
149   fIsMapRead(stream.fIsMapRead),
150   fDeadfaceOffset(stream.GetDeadfaceOffset()),
151   fDeadbeefOffset(stream.GetDeadbeefOffset()),
152   fDataOffset(stream.GetDataOffset()),
153   fModType(stream.GetModType()),
154   fADCModule(stream.GetADCModule()),     
155   fADCNChannels(stream.GetADCNChannels()),       
156   fADCChannel(stream.GetADCChannel()),   
157   fADCValue(stream.GetADCValue()),       
158   fADCGain(stream.GetADCGain()),
159   fIsUnderflow(stream.fIsUnderflow),
160   fIsOverflow(stream.fIsOverflow),
161   fScGeo(stream.GetScGeo()),      
162   fScNWords(stream.GetScNWords()),        
163   fScTriggerSource(stream.GetScTriggerSource()),          
164   fScTriggerNumber(stream.fScTriggerNumber),
165   fIsScEventGood(stream.fIsScEventGood),
166   fIsScHeaderRead(stream.fIsScHeaderRead),
167   fScStartCounter(stream.fScStartCounter),
168   fScEvCounter(stream.fScEvCounter),
169   fIsScalerWord(stream.fIsScalerWord),
170   fDetPattern(stream.fDetPattern),
171   fTrigCountNWords(stream.fTrigCountNWords),
172   fIsTriggerScaler(stream.fIsTriggerScaler),
173   fTrigCountStart(stream.fTrigCountStart),
174   fMBTrigInput(stream.fMBTrigInput),       
175   fCentralTrigInput(stream.fCentralTrigInput), 
176   fSCentralTrigInput(stream.fSCentralTrigInput),
177   fEMDTrigInput(stream.fEMDTrigInput),     
178   fL0Received(stream.fL0Received),         
179   fMBtrig2CTP(stream.fMBtrig2CTP),         
180   fCentralTrig2CTP(stream.fCentralTrig2CTP),  
181   fSCentralTrig2CTP(stream.fSCentralTrig2CTP), 
182   fEMDTrig2CTP(stream.fEMDTrig2CTP),          
183   fTrigHistNWords(stream.fTrigHistNWords),
184   fIsTriggerHistory(stream.fIsTriggerHistory),
185   fTrigHistStart(stream.fTrigHistStart),
186   fPileUpBit1stWord(stream.fPileUpBit1stWord),
187   fL0Bit1stWord(stream.fL0Bit1stWord), 
188   fCentralTrigHist(stream.fCentralTrigHist),
189   fMBTrigHist(stream.fMBTrigHist),
190   fPileUpBit2ndWord(stream.fPileUpBit2ndWord),
191   fL0Bit2ndWord(stream.fL0Bit2ndWord), 
192   fSCentralTrigHist(stream.fSCentralTrigHist),
193   fEMDTrigHist(stream.fEMDTrigHist),
194   fNChannelsOn(stream.fNChannelsOn),
195   fCurrentCh(stream.fCurrentCh),
196   fCabledSignal(stream.GetCabledSignal()),
197   fCurrScCh(stream.fCurrScCh),
198   fIsADCEventGood(stream.fIsADCEventGood),
199   fIsL0BitSet(stream.fIsL0BitSet),
200   fIsPileUpEvent(stream.fIsPileUpEvent),
201   fIsADDChannel(stream.fIsADDChannel),
202   fADDADCdatum(stream.fADDADCdatum),
203   fIsTDCHeaderRead(stream.fIsTDCHeaderRead),
204   fTDCStartCounter(stream.fTDCStartCounter),
205   fIsZDCTDCHeader(stream.fIsZDCTDCHeader),
206   fIsZDCTDCdatum(stream.fIsZDCTDCdatum),
207   fZDCTDCdatum(stream.fZDCTDCdatum),
208   fIsADDTDCHeader(stream.fIsADDTDCHeader),
209   fIsADDTDCdatum(stream.fIsADDTDCdatum),
210   fADDTDCdatum(stream.fADDTDCdatum)
211 {
212   // Copy constructor
213   const int kNch = 48;
214   for(Int_t j=0; j<2; j++) fSector[j] = stream.GetSector(j);     
215   for(Int_t i=0; i<kNch; i++){
216     for(Int_t j=0; j<5; j++){
217       fMapADC[i][j] = stream.fMapADC[i][j];
218       if(i<32) fScalerMap[i][j] = stream.fMapADC[i][j];
219     }
220   }
221   
222   for(Int_t k=0; k<4; k++) fCPTInput[k] = stream.fCPTInput[k];
223 }
224
225 //_____________________________________________________________________________
226 AliZDCRawStream& AliZDCRawStream::operator = (const AliZDCRawStream& 
227                                               /* stream */)
228 {
229   // Assignment operator
230   Fatal("operator =", "assignment operator not implemented");
231   return *this;
232 }
233
234 //_____________________________________________________________________________
235 AliZDCRawStream::~AliZDCRawStream()
236 {
237 // Destructor
238
239 }
240
241 //_____________________________________________________________________________
242 void AliZDCRawStream::ReadChMap()
243 {
244   // Reading channel map
245   const int kNch = 48;
246   AliDebug(2,"\t Reading ZDC ADC mapping from OCDB\n");
247   AliZDCChMap * chMap = GetChMap();
248   //chMap->Print("");
249   for(Int_t i=0; i<kNch; i++){
250     fMapADC[i][0] = chMap->GetADCModule(i);
251     fMapADC[i][1] = chMap->GetADCChannel(i);
252     fMapADC[i][2] = -1;
253     fMapADC[i][3] = chMap->GetDetector(i);
254     fMapADC[i][4] = chMap->GetSector(i);
255   }
256   fIsMapRead = kTRUE;
257 }
258
259 //_____________________________________________________________________________
260 void AliZDCRawStream::ReadCDHHeader()
261 {
262   // Reading CDH 
263   const AliRawDataHeader* header = fRawReader->GetDataHeader();
264   if(!header) {
265       AliError(" No CDH in raw data streaming");
266       fRawReader->AddMajorErrorLog(kCDHError);
267       return;
268   }
269   else{
270     //printf("\t AliZDCRawStream::ReadCDHHeader -> Data Size = %x\n",fRawReader->GetDataSize());
271
272     UChar_t message = header->GetAttributes();
273     //printf("\t AliZDCRawStream::ReadCDHHeader -> Attributes %x\n",message);
274     
275     if((message & 0xf0) == 0x0){ // PHYSICS RUN
276        //printf("\t PHYSICS RUN raw data found\n");
277     }
278     else if((message & 0xf0) == 0x10){ // COSMIC RUN
279        //printf("\t STANDALONE_COSMIC RUN raw data found\n");
280     }
281     else if((message & 0xf0) == 0x20){ // PEDESTAL RUN
282        //printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
283     }
284     else if((message & 0xf0) == 0x30){ // LASER RUN
285        //printf("\t STANDALONE_LASER RUN raw data found\n");
286     }
287     else if((message & 0xf0) == 0x40){ // CALIBRATION_CENTRAL RUN
288        //printf("\t CALIBRATION_CENTRAL RUN raw data found\n");
289     }
290     else if((message & 0xf0) == 0x50){ // CALIBRATION_SEMICENTRAL
291        //printf("\t CALIBRATION_SEMICENTRAL RUN raw data found\n");
292     }
293     else if((message & 0xf0) == 0x60){ // CALIBRATION_MB
294        //printf("\t CALIBRATION_MB RUN raw data found\n");
295     }
296     else if((message & 0xf0) == 0x70){ // CALIBRATION_EMD
297        //printf("\t CALIBRATION_EMD RUN raw data found\n");
298     }
299     // *** Checking the bit indicating the used readout card
300     // (the payload is different in the 2 cases!)
301     if((message & 0x08) == 0){  // ** DARC card
302        fReadOutCard = 0;
303        fIsDARCHeader = kTRUE;
304        //AliInfo("\t ZDC readout card used: DARC");
305     }
306     else if((message & 0x08) == 0x08){  // ** ZRC card
307        fReadOutCard = 1;
308        //AliInfo("\t ZDC readout card used: ZRC");
309     }
310
311     if(header->GetL1TriggerMessage() & 0x1){ // Calibration bit set in CDH
312       fIsCalib = kTRUE;
313     }
314     //printf("\t AliZDCRawStream::ReadCDHHeader -> L1TriggerMessage %x\n",header->GetL1TriggerMessage());
315     //printf("\t AliZDCRawStream::ReadCDHHeader -> Calibration bit = %d\n",fIsCalib);    
316     
317 /*    UInt_t status = header->GetStatus();
318     //printf("\t AliZDCRawStream::ReadCDHHeader -> status = %d\n",status);
319     if((status & 0x000f) == 0x0001){
320       AliDebug(2,"CDH -> DARC trg0 overlap error");
321       fRawReader->AddMajorErrorLog(kDARCError);
322     }
323     if((status & 0x000f) == 0x0002){
324       AliDebug(2,"CDH -> DARC trg0 missing error");
325       fRawReader->AddMajorErrorLog(kDARCError);
326     }
327     if((status & 0x000f) == 0x0004){
328       AliDebug(2,"CDH -> DARC data parity error");
329       fRawReader->AddMajorErrorLog(kDARCError);
330     }
331     if((status & 0x000f) == 0x0008){
332       AliDebug(2,"CDH -> DARC ctrl parity error");
333       fRawReader->AddMajorErrorLog(kDARCError);
334     }
335     //
336     if((status & 0x00f0) == 0x0010){
337       AliDebug(2,"CDH -> DARC trg unavailable");
338       fRawReader->AddMajorErrorLog(kDARCError);
339     }
340     if((status & 0x00f0) == 0x0020){
341       AliDebug(2,"CDH -> DARC FEE error");
342       fRawReader->AddMajorErrorLog(kDARCError);
343     }
344     //
345     if((status & 0x0f00) == 0x0200){
346       AliDebug(2,"CDH -> DARC L1 time violation");
347       fRawReader->AddMajorErrorLog(kDARCError);
348     }
349     if((status & 0x0f00) == 0x0400){
350       AliDebug(2,"CDH -> DARC L2 time-out");
351       fRawReader->AddMajorErrorLog(kDARCError);
352     }
353     if((status & 0x0f00) == 0x0800){
354       AliDebug(2,"CDH -> DARC prepulse time violation");
355       fRawReader->AddMajorErrorLog(kDARCError);
356     }
357     //
358     if((status & 0xf000) == 0x1000){
359       AliDebug(2,"CDH -> DARC other error");
360       fRawReader->AddMajorErrorLog(kDARCError);
361     }
362     */
363   }
364   
365 }
366
367 //_____________________________________________________________________________
368 Bool_t AliZDCRawStream::Next()
369 {
370   // Read the next raw digit
371   // Returns kFALSE if there is no digit left
372
373   if(!fRawReader->ReadNextInt((UInt_t&) fBuffer)) return kFALSE;
374   const int kNch = 48;
375   //
376   fIsHeaderMapping = kFALSE; fIsChMapping = kFALSE; 
377   fIsADCHeader = kFALSE; fIsADCDataWord = kFALSE; fIsADCEOB = kFALSE;
378   fIsZDCTDCdatum = kFALSE; fIsADDChannel = kFALSE; fIsADDTDCdatum=kFALSE;
379   fIsUnderflow = kFALSE; fIsOverflow = kFALSE; fIsScalerWord = kFALSE;
380   fSector[0] = fSector[1] = -1;
381   for(Int_t kl=0; kl<4; kl++) fCPTInput[kl] = 0;
382
383   fEvType = fRawReader->GetType();
384   if(fPosition==0){
385     //if(fEvType==7 || fEvType ==8){ //Physics or calibration event
386       ReadCDHHeader();
387     //}
388     fCurrentCh=0; fCurrScCh=0; fNChannelsOn=0;
389     // Ch. debug
390     //printf("\n  AliZDCRawStream::Next() - ev. type %d",fEvType);
391   }
392   
393   // Ch. debug
394   //printf("\n  AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
395   
396   // *** End of ZDC event
397   if(fBuffer == 0xcafefade){
398     //printf("\n  AliZDCRawStream::Next() ***** End of ZDC event *****\n\n");
399     return kFALSE;
400   }
401   
402   // -------------------------------------------
403   // --- DARC header
404   // -------------------------------------------
405   // If the CDH has been read then 
406   // the DARC header must follow
407   if(fReadOutCard==0 && fIsDARCHeader){
408     //printf("\t ---- DARC header ----\n");
409     if(fIsCalib){
410       fDeadfaceOffset = 9;
411       fDeadbeefOffset = 25;
412     }
413     else{
414       fDeadfaceOffset = 1;
415       fDeadbeefOffset = 7;
416     }
417     fDataOffset = 1+fDeadbeefOffset;
418     fIsDARCHeader = kFALSE;
419   }
420     
421   // ---------------------------------------------
422   // --- Start of data event (SOD)             ---
423   // --- decoding mapping of connected ADC ch. ---
424   // ---------------------------------------------
425   // In the SOD event ADC ch. mapping is written
426   if(fEvType==10){
427    if(fSODReading){
428     
429     if(fPosition>=fDataOffset){
430       if((fBuffer&0xff000001) == 0xff000001){ // ************** Mapping
431         // DARC 1st datum @ fDataOffset+1 \ ZRC 1st valid datum @ fDataOffset=0
432         if((fPosition==fDataOffset+1) || (fPosition==fDataOffset)){ 
433            printf("\n\n ------ AliZDCRawStream -> Reading mapping from StartOfData event ------\n");
434            fCurrentCh=0; fCurrScCh=0;   
435         }
436         else{
437           printf(" ------ AliZDCRawStream -> End of ZDC StartOfData event ------\n\n");
438           fSODReading = kFALSE;
439           return kFALSE;
440         }
441       }
442       else if((fBuffer&0xff000002) == 0xff000002){ // ************** Threshold settings
443         fPosition++;
444         return kFALSE; // !!!!!!!!!!!!!!!!!!!!!  For the moment thresholds are not read
445       }
446       else if((fBuffer&0x80000000)>>31 == 1){ // --- Mapping header
447         fIsHeaderMapping = kTRUE;
448         fADCModule = ((fBuffer & 0x7f000000)>>24); // GEO address!!!
449         fModType = ((fBuffer & 0x7ff00)>>8); 
450         fADCNChannels = (fBuffer & 0xff);          // # of channels following the header
451         //
452         printf("  ******** GEO %d, mod. type %d, #ch. %d\n",fADCModule,fModType,fADCNChannels);
453       }
454       else if((fBuffer&0x80000000)>>31 == 0){ // --- Mapping channel
455         fADCChannel = ((fBuffer & 0x3fff0000)>>16);
456         fCabledSignal = (fBuffer&0xffff);
457         //
458         if(fModType == kV965){ // ******** ADCs ********************************
459           // Channel signal
460           if((fBuffer&0x40000000)>>30==0 && fADCModule<=kLastADCGeo){ // *ZDC* high range chain ADC
461             fIsChMapping = kTRUE;
462             fMapADC[fCurrentCh][0] = fADCModule;
463             fMapADC[fCurrentCh][1] = fADCChannel;
464             fMapADC[fCurrentCh][2] = fCabledSignal;
465             //  - No. of channels on
466             fNChannelsOn++;
467             //
468             // Determining detector and sector
469             // -----------------------------------------
470             //  For the decoding of the following lines 
471             //  look the enum in AliZDCRawStream.h file
472             // -----------------------------------------
473             if((fCabledSignal>=2 && fCabledSignal<=6) || (fCabledSignal>=26 && fCabledSignal<=30)
474               || fCabledSignal==24 || fCabledSignal==48){
475               fMapADC[fCurrentCh][3] = 4; //ZNA
476               //
477               if(fCabledSignal==kZNAC || fCabledSignal==kZNACoot)       fMapADC[fCurrentCh][4]=0;
478               else if(fCabledSignal==kZNA1 || fCabledSignal==kZNA1oot)  fMapADC[fCurrentCh][4]=1;
479               else if(fCabledSignal==kZNA2 || fCabledSignal==kZNA2oot)  fMapADC[fCurrentCh][4]=2;
480               else if(fCabledSignal==kZNA3 || fCabledSignal==kZNA3oot)  fMapADC[fCurrentCh][4]=3;
481               else if(fCabledSignal==kZNA4 || fCabledSignal==kZNA4oot)  fMapADC[fCurrentCh][4]=4;
482               else if(fCabledSignal==kZDCAMon || fCabledSignal==kZDCAMonoot) fMapADC[fCurrentCh][4]=5; //Reference PTM
483             }
484             else if((fCabledSignal>=7 && fCabledSignal<=11) || (fCabledSignal>=31 && fCabledSignal<=35)){
485               fMapADC[fCurrentCh][3] = 5; //ZPA
486               //
487               if(fCabledSignal==kZPAC || fCabledSignal==kZPACoot)      fMapADC[fCurrentCh][4]=0;
488               else if(fCabledSignal==kZPA1 || fCabledSignal==kZPA1oot) fMapADC[fCurrentCh][4]=1;
489               else if(fCabledSignal==kZPA2 || fCabledSignal==kZPA2oot) fMapADC[fCurrentCh][4]=2;
490               else if(fCabledSignal==kZPA3 || fCabledSignal==kZPA3oot) fMapADC[fCurrentCh][4]=3;
491               else if(fCabledSignal==kZPA4 || fCabledSignal==kZPA4oot) fMapADC[fCurrentCh][4]=4;
492             }
493             else if((fCabledSignal>=12 && fCabledSignal<=16) || (fCabledSignal>=36 && fCabledSignal<=40)
494                || fCabledSignal==25 || fCabledSignal==49){
495               fMapADC[fCurrentCh][3] = 1; //ZNC
496               //
497               if(fCabledSignal==kZNCC || fCabledSignal==kZNCCoot)      fMapADC[fCurrentCh][4]=0;
498               else if(fCabledSignal==kZNC1 || fCabledSignal==kZNC1oot) fMapADC[fCurrentCh][4]=1;
499               else if(fCabledSignal==kZNC2 || fCabledSignal==kZNC2oot) fMapADC[fCurrentCh][4]=2;
500               else if(fCabledSignal==kZNC3 || fCabledSignal==kZNC3oot) fMapADC[fCurrentCh][4]=3;
501               else if(fCabledSignal==kZNC4 || fCabledSignal==kZNC4oot) fMapADC[fCurrentCh][4]=4;
502               else if(fCabledSignal==kZDCCMon || fCabledSignal==kZDCCMonoot) fMapADC[fCurrentCh][4]=5; //Reference PTM
503             }
504             else if((fCabledSignal>=17 && fCabledSignal<=21) || (fCabledSignal>=41 && fCabledSignal<=45)){
505               fMapADC[fCurrentCh][3] = 2; //ZPC
506               //
507               if(fCabledSignal==kZPCC || fCabledSignal==kZPCCoot)   fMapADC[fCurrentCh][4]=0;
508               else if(fCabledSignal==kZPC1 || fCabledSignal==kZPC1oot) fMapADC[fCurrentCh][4]=1;
509               else if(fCabledSignal==kZPC2 || fCabledSignal==kZPC2oot) fMapADC[fCurrentCh][4]=2;
510               else if(fCabledSignal==kZPC3 || fCabledSignal==kZPC3oot) fMapADC[fCurrentCh][4]=3;
511               else if(fCabledSignal==kZPC4 || fCabledSignal==kZPC4oot) fMapADC[fCurrentCh][4]=4;
512             }
513             else if(fCabledSignal==22 || fCabledSignal==23 || fCabledSignal==46 || fCabledSignal==47){
514               fMapADC[fCurrentCh][3] = 3; // ZEM
515               //
516               if(fCabledSignal==kZEM1 || fCabledSignal==kZEM1oot)      fMapADC[fCurrentCh][4]=1;
517               else if(fCabledSignal==kZEM2 || fCabledSignal==kZEM2oot) fMapADC[fCurrentCh][4]=2;
518             }
519             //Ch. debug
520             //printf("\tADC mod. %d ch. %d signal %d ",fADCModule,fADCChannel,fCabledSignal);
521             //printf("  det. %d sec. %d\n",fMapADC[fCurrentCh][3],fMapADC[fCurrentCh][4]);
522             //
523             fCurrentCh++;
524             //
525           } // high range channels
526         }// ModType=1 (ADC mapping)
527         else if(fModType == kV830){  // ******** VME scaler **************************
528           fIsChMapping = kTRUE;
529           fScalerMap[fCurrScCh][0] = fADCModule;
530           fScalerMap[fCurrScCh][1] = fADCChannel;
531           fScalerMap[fCurrScCh][2] = fCabledSignal;
532           //
533           // Determining detector and sector
534           // -----------------------------------------
535           //  For the decoding of the following lines 
536           //  look the enum in AliZDCRawStream.h file
537           // -----------------------------------------
538           // NOT CONSIDERING OUT OF TIME OR REFERENCE SIGNALS FOR SCALER!!!!!
539           if((fCabledSignal>=2 && fCabledSignal<=6) ||
540              (fCabledSignal>=61 && fCabledSignal<=65)){
541             fScalerMap[fCurrScCh][3] = 4; //ZNA
542             //
543             if(fCabledSignal==kZNAC || fCabledSignal==kZNACD)      fScalerMap[fCurrScCh][4]=0;
544             else if(fCabledSignal==kZNA1 || fCabledSignal==kZNA1D) fScalerMap[fCurrScCh][4]=1;
545             else if(fCabledSignal==kZNA2 || fCabledSignal==kZNA2D) fScalerMap[fCurrScCh][4]=2;
546             else if(fCabledSignal==kZNA3 || fCabledSignal==kZNA3D) fScalerMap[fCurrScCh][4]=3;
547             else if(fCabledSignal==kZNA4 || fCabledSignal==kZNA4D) fScalerMap[fCurrScCh][4]=4;
548           }
549           else if((fCabledSignal>=7 && fCabledSignal<=11) ||
550              (fCabledSignal>=66 && fCabledSignal<=70)){
551             fScalerMap[fCurrScCh][3] = 5; //ZPA
552             //
553             if(fCabledSignal==kZPAC || fCabledSignal==kZPACD)      fScalerMap[fCurrScCh][4]=0;
554             else if(fCabledSignal==kZPA1 || fCabledSignal==kZPA1D) fScalerMap[fCurrScCh][4]=1;
555             else if(fCabledSignal==kZPA2 || fCabledSignal==kZPA2D) fScalerMap[fCurrScCh][4]=2;
556             else if(fCabledSignal==kZPA3 || fCabledSignal==kZPA3D) fScalerMap[fCurrScCh][4]=3;
557             else if(fCabledSignal==kZPA4 || fCabledSignal==kZPA4D) fScalerMap[fCurrScCh][4]=4;
558           }
559           else if((fCabledSignal>=12 && fCabledSignal<=16) ||
560              (fCabledSignal>=71 && fCabledSignal<=75)){
561             fScalerMap[fCurrScCh][3] = 1; //ZNC
562             //
563             if(fCabledSignal==kZNCC || fCabledSignal==kZNCCD)      fScalerMap[fCurrScCh][4]=0;
564             else if(fCabledSignal==kZNC1 || fCabledSignal==kZNC1D) fScalerMap[fCurrScCh][4]=1;
565             else if(fCabledSignal==kZNC2 || fCabledSignal==kZNC2D) fScalerMap[fCurrScCh][4]=2;
566             else if(fCabledSignal==kZNC3 || fCabledSignal==kZNC3D) fScalerMap[fCurrScCh][4]=3;
567             else if(fCabledSignal==kZNC4 || fCabledSignal==kZNC4D) fScalerMap[fCurrScCh][4]=4;
568           }
569           else if((fCabledSignal>=17 && fCabledSignal<=21) ||
570              (fCabledSignal>=76 && fCabledSignal<=80)){
571             fScalerMap[fCurrScCh][3] = 2; //ZPC
572             //
573             if(fCabledSignal==kZPCC || fCabledSignal==kZPCCD) fScalerMap[fCurrScCh][4]=0;
574             else if(fCabledSignal==kZPC1 || fCabledSignal==kZPC1D)  fScalerMap[fCurrScCh][4]=1;
575             else if(fCabledSignal==kZPC2 || fCabledSignal==kZPC2D)  fScalerMap[fCurrScCh][4]=2;
576             else if(fCabledSignal==kZPC3 || fCabledSignal==kZPC3D)  fScalerMap[fCurrScCh][4]=3;
577             else if(fCabledSignal==kZPC4 || fCabledSignal==kZPC4D)  fScalerMap[fCurrScCh][4]=4;
578           }
579           else if(fCabledSignal==22 || fCabledSignal==23 ||
580                   fCabledSignal==81 || fCabledSignal==82){
581             fScalerMap[fCurrScCh][3] = 3; // ZEM
582             //
583             if(fCabledSignal==kZEM1 || fCabledSignal==kZEM1D)      fScalerMap[fCurrScCh][4]=1;
584             else if(fCabledSignal==kZEM2 || fCabledSignal==kZEM2D) fScalerMap[fCurrScCh][4]=2;
585           }
586           // Ch debug.
587           //printf("\t VME scaler mod. %d ch. %d, signal %d",fScalerMap[fCurrScCh][0],fADCChannel,fCabledSignal);
588           //if(fCabledSignal!=0 && fCabledSignal!=1) printf("  det. %d sec. %d\n",fScalerMap[fCurrScCh][3],fScalerMap[fCurrScCh][4]);
589           //else printf("  Signal void/not connected\n");
590           
591           fCurrScCh++;
592         }
593         /*else if(fModType == kTRG){ // **** scalers from trigger card
594           //printf("\t Trigger scaler mod. %d ch. %d, signal %d\n",fADCModule,fADCChannel,fCabledSignal);         
595         }
596         else if(fModType == kTRGI){ // **** trigger history from trigger card
597           //printf("\t Trigger card ch. %d, signal %d\n",fADCChannel,fCabledSignal);
598         }
599         else if(fModType == kPU){ // **** pattern unit
600           //printf("\t P.U. mod. %d ch. %d, signal %d\n",fADCModule,fADCChannel,fCabledSignal);
601         }*/
602       }//reading channel mapping
603     }
604    } // if fSODREading
605    fPosition++;
606    return kTRUE;
607   } // ------------------------------- SOD event
608   
609   // -------------------------------------------
610   // --- DARC data
611   // -------------------------------------------
612   if(fPosition<fDeadfaceOffset && fReadOutCard==0){
613     fPosition++;
614     return kTRUE;
615   }
616   else if(fPosition==fDeadfaceOffset && fReadOutCard==0){
617     if(fBuffer != 0xdeadface){
618       //AliWarning(" NO deadface after DARC data");
619       fRawReader->AddMajorErrorLog(kDARCError); 
620     }
621     else{
622       fPosition++;
623       return kTRUE;
624     }
625   }
626   else if(fPosition>fDeadfaceOffset && fPosition<fDeadbeefOffset && fReadOutCard==0){
627     fPosition++;
628     return kTRUE;
629   }
630   else if(fPosition==fDeadbeefOffset && fReadOutCard==0){
631     if(fBuffer != 0xdeadbeef){
632       //AliWarning(" NO deadbeef after DARC global data");
633       fRawReader->AddMajorErrorLog(kDARCError);  
634       fPosition++;
635       return kFALSE;
636     }
637     else{
638       fPosition++;
639       return kTRUE;
640     }
641   } // ------------------------------- End of DARC data
642   
643   // ---------------------------------------------
644   // --- ZDC data
645   // --- ADCs + VME scaler + trigger card + P.U.
646   // ---------------------------------------------
647   else if(fPosition>=fDataOffset){
648     
649     //printf("AliZDCRawStream: fSODReading = %d\n", fSODReading);
650     if(!fSODReading && !fIsMapRead) ReadChMap();
651     
652     //  !!!!!!!!!!!!!!! DARC readout card only !!!!!!!!!!!
653     // Not valid datum before the event 
654     // there MUST be a NOT valid datum before the event!!!
655     if(fReadOutCard==0){
656       if(fPosition==fDataOffset){ 
657         //printf("\t **** ZDC data begin ****\n");
658         if((fBuffer & 0x07000000) != 0x06000000){
659           fRawReader->AddMajorErrorLog(kZDCDataError);
660         }
661         else if((fBuffer & 0x07000000) == 0x06000001){ // Corrupted event!!!
662           fIsADCEventGood = kFALSE;
663         }
664       }
665     
666       // If the not valid datum isn't followed by the 1st ADC header
667       // the event is corrupted (i.e., 2 gates arrived before trigger)
668       else if(fPosition==fDataOffset+1){ 
669         if((fBuffer & 0x07000000) != 0x02000000){
670           AliWarning("ZDC ADC -> The not valid datum is NOT followed by an ADC header!");
671           fRawReader->AddMajorErrorLog(kZDCDataError);
672           fIsADCEventGood = kFALSE;
673           fPosition++;
674           return kFALSE;
675         }
676       }
677     }
678      
679     // Get geo address of current word
680     if(fIsTDCHeaderRead && fIsZDCTDCHeader) fADCModule = kZDCTDCGeo;
681     else if(fIsTDCHeaderRead && fIsADDTDCHeader) fADCModule = kADDTDCGeo;
682     else fADCModule = (Int_t) ((fBuffer & 0xf8000000)>>27);
683     
684     // ************************************ ADC MODULES ************************************
685     if(fADCModule>=kFirstADCGeo && fADCModule<=kLastADCGeo){
686       // *** ADC header
687       if((fBuffer & 0x07000000) == 0x02000000){
688         fIsADCHeader = kTRUE;
689         fADCNChannels = ((fBuffer & 0x00003f00)>>8);
690         //printf("  AliZDCRawStream -> ADC HEADER: mod.%d has %d ch. \n",fADCModule,fADCNChannels);
691       }
692       // *** ADC data word
693       else if((fBuffer & 0x07000000) == 0x00000000){
694         fIsADCDataWord = kTRUE;
695         fADCChannel = ((fBuffer & 0x1e0000) >> 17);
696         fADCGain = ((fBuffer & 0x10000) >> 16);       
697         fADCValue = (fBuffer & 0xfff);  
698         //
699         //printf("  AliZDCRawStream -> ADC DATUM: mod. %d ch. %d gain %d value %d\n",
700         //  fADCModule,fADCChannel,fADCGain,fADCValue);
701         
702         // Checking if the channel map for the ADCs has been provided/read
703         if(fMapADC[0][0]==-1){
704           printf("\t ATTENTION!!! No ADC mapping has been found/provided!!!\n");
705           return kFALSE;
706         }
707         //
708         /*for(Int_t ci=0; ci<kNch; ci++){
709           printf("  %d mod %d ch %d det %d sec %d\n",ci,fMapADC[ci][0],
710           fMapADC[ci][1], fMapADC[ci][3], fMapADC[ci][4]);
711         }*/
712                 
713         // Scan of the map to assign the correct volumes
714         Int_t foundMapEntry = kFALSE;
715         for(Int_t k=0; k<kNch; k++){
716            if(fADCModule==fMapADC[k][0] && fADCChannel==fMapADC[k][1]){
717              fSector[0] = fMapADC[k][3];
718              fSector[1] = fMapADC[k][4];
719              foundMapEntry = kTRUE;
720              break;
721            } 
722         }
723         if(foundMapEntry==kFALSE){
724           AliWarning(Form(" No valid entry in ADC mapping for raw data %d ADCmod. %d ch. %d\n",
725               fPosition,fADCModule,fADCChannel));
726         }
727         //
728         //printf("AliZDCRawStream -> ADCmod. %d ch. %d -> det %d sec %d\n",
729         //  fADCModule,fADCChannel,fSector[0],fSector[1]);
730         
731         // Final checks
732         if(foundMapEntry==kTRUE){
733           if(fSector[0]<1 || fSector[0]>5){
734             AliWarning(Form(" No valid detector assignment: %d",fSector[0]));
735             fRawReader->AddMajorErrorLog(kInvalidSector);
736           }
737           //
738           if(fSector[1]<0 || fSector[1]>5){
739             AliWarning(Form(" No valid sector assignment: %d",fSector[1]));
740             fRawReader->AddMajorErrorLog(kInvalidSector);
741           }
742           //
743           if(fADCModule<0 || fADCModule>3){
744             AliError(Form(" No valid ADC module: %d",fADCModule));
745             fRawReader->AddMajorErrorLog(kInvalidADCModule);
746           }
747         }
748
749         // Checking the underflow and overflow bits
750         if(fBuffer & 0x1000)       fIsUnderflow = kTRUE;
751         else if (fBuffer & 0x2000) fIsOverflow = kTRUE; 
752                 
753       }//ADC data word
754       // *** ADC EOB
755       else if((fBuffer & 0x07000000) == 0x04000000){
756         fIsADCEOB = kTRUE;
757         //printf("  AliZDCRawStream -> EOB --------------------------\n");
758       }
759     }//ADC module
760     // ********************************* ADD ADC *********************************
761     else if(fADCModule == kADDADCGeo){
762       // *** ADC header
763       if((fBuffer & 0x07000000) == 0x02000000){
764         fIsADCHeader = kTRUE;
765         fADCNChannels = ((fBuffer & 0x00003f00)>>8);
766         //printf("  AliZDCRawStream -> ADD ADC HEADER: mod.%d has %d ch. \n",fADCModule,fADCNChannels);
767       }
768       // *** ADC data word
769       else if((fBuffer & 0x07000000) == 0x00000000){
770         fIsADDChannel = kTRUE;
771         fADCChannel = ((fBuffer & 0x1e0000) >> 17);
772         fADCGain = ((fBuffer & 0x10000) >> 16);       
773         fADCValue = (fBuffer & 0xfff);  
774         //
775         //printf("  ADD ADC DATUM -> mod. %d ch. %d gain %d value %d\n",
776         //  fADCModule,fADCChannel,fADCGain,fADCValue);
777       }
778       // *** ADC EOB
779       else if((fBuffer & 0x07000000) == 0x04000000){
780         fIsADCEOB = kTRUE;
781         //printf("  AliZDCRawStream -> EOB --------------------------\n");
782       }
783     }
784     // ********************************* TDC *********************************
785     else if(fADCModule==kTDCFakeGeo && fIsTDCHeaderRead==kFALSE){
786       // *** TDC header
787       fIsTDCHeaderRead = kTRUE;
788       fTDCStartCounter = fPosition;
789       // GEO address from TDC header
790       fADCModule = (Int_t) (fBuffer & 0x1f);
791       if(fADCModule==kZDCTDCGeo){ // *** ZDC TDC
792         fIsZDCTDCHeader = kTRUE;
793         //Ch. debug
794         //printf("  AliZDCRawStream -> ZDC TDC: mod.%d\n",fADCModule);
795       }
796       else if (fADCModule==kADDTDCGeo){ // *** ADD TDC
797         fIsADDTDCHeader = kTRUE;
798         //Ch. debug
799         //printf("  AliZDCRawStream -> ADD TDC: mod.%d\n",fADCModule);
800       }
801     }
802     // ********************************* VME SCALER HEADER *********************************
803     else if(fADCModule == kScalerGeo){
804       if(fBuffer & 0x04000000 && fIsScHeaderRead==kFALSE){ // *** Scaler header
805         fScGeo = (fBuffer & 0xf8000000)>>27;       
806         fScNWords = (fBuffer & 0x00fc0000)>>18;    
807         fScTriggerSource = (fBuffer & 0x00030000)>>16;     
808         fScTriggerNumber = (fBuffer & 0x0000ffff);
809         fIsScHeaderRead = kTRUE; 
810         fScStartCounter = fPosition;
811         //Ch. debug
812         //printf("  AliZDCRawStream -> VME SCALER HEADER: geo %d Nwords %d TrigSource %d TrigNo. %d\n",
813         //   fScGeo,fScNWords,fScTriggerSource,fScTriggerNumber);
814       } 
815       else if(!(fBuffer & 0x04000000)){
816         fIsScEventGood = kFALSE;
817       }
818     }
819     // *********************************** PATTERN UNIT ***********************************
820     else if(fADCModule == kPUGeo){
821       // still to be implemented!!! Not yet in data!!!
822       fDetPattern = (fBuffer & 0x0000003f);
823       // Ch. debug
824       //printf("  AliZDCRawStream -> Pattern Unit\n");
825       
826     }
827     // ******************************** TRIGGER CARD COUNTS ********************************
828     else if(fADCModule == kTrigScales){
829       if(fIsTriggerScaler == kFALSE){
830         fTrigCountNWords = (Int_t) ((fBuffer & 0xfc0000)>>17);
831         fTrigCountStart = fPosition;
832         fIsTriggerScaler = kTRUE;
833       }
834       // Ch. debug
835       //printf("  AliZDCRawStream -> Trigger Scaler header\n");      
836     }
837     // ********************************** TRIGGER HISTORY **********************************
838     else if(fADCModule == kTrigHistory){
839       if(fIsTriggerHistory == kFALSE){
840         fTrigHistNWords = (Int_t) ((fBuffer & 0xfc0000)>>17);
841         fTrigHistStart = fPosition;
842         fIsTriggerHistory = kTRUE;
843       }
844       // Ch. debug
845       //printf("  AliZDCRawStream -> Trigger History header\n");
846       
847     } 
848     // ********************************** VME SCALER DATA **********************************
849     //  Reading VME scaler data 
850     if(fIsScHeaderRead && fPosition>=fScStartCounter+1){ // *** Scaler word
851       fADCModule=kScalerGeo; fIsADCDataWord=kFALSE; fIsScalerWord=kTRUE;
852       fScEvCounter = fBuffer;
853       Int_t nWords = (Int_t) (fScNWords);
854       if(fPosition == fScStartCounter+nWords) fIsScHeaderRead = kFALSE;
855       //Ch. debug
856       //printf("  AliZDCRawStream -> scaler datum %d", fScEvCounter);
857     }
858     // ********************************** ZDC TDC DATA **********************************
859     //  ZDC TDC data
860     if(fIsTDCHeaderRead && fIsZDCTDCHeader && fPosition>=fTDCStartCounter+1){ 
861       fIsADCDataWord=kFALSE; fIsScalerWord=kFALSE;
862       if(((fBuffer & 0xf0000000)==0x00000000) && (((fBuffer & 0x08000000) >> 27) == 0)){ // TDC datum
863         fADCChannel = (Int_t) ((fBuffer & 0x3e00000) >> 21);
864         fIsZDCTDCdatum = kTRUE;
865         fZDCTDCdatum = (Int_t) (fBuffer & 0x1fffff);
866         // Ch. debug
867         //printf("  AliZDCRawStream -> ZDC TDC mod. %d ch. %d datum %d\n",fADCModule,fADCChannel,fZDCTDCdatum);
868       }
869       if(((fBuffer & 0xf0000000) == 0x80000000) && ((fBuffer & 0x08000000) >> 27) == 0){
870         // Trailer
871         fIsTDCHeaderRead = kFALSE;
872         // Ch. debug
873         //printf("  AliZDCRawStream -> ZDC TDC global trailer\n");
874       }
875     }
876     // ********************************** ADD TDC DATA **********************************
877     //  ADD TDC data
878     if(fIsTDCHeaderRead && fIsADDTDCHeader && fPosition>=fTDCStartCounter+1){ 
879       fIsADCDataWord=kFALSE; fIsScalerWord=kFALSE;
880       if(((fBuffer & 0xf0000000)==0x00000000) && (((fBuffer & 0x08000000) >> 27) == 0)){ // TDC datum
881         fADCChannel = (Int_t) ((fBuffer & 0x3e00000) >> 21);
882         fIsADDTDCdatum = kTRUE;
883         fADDTDCdatum = (Int_t) (fBuffer & 0x1fffff);
884         // Ch. debug
885         //printf("  AliZDCRawStream -> ADD TDC mod. %d ch. %d datum %d\n",fADCModule,fADCChannel,fADDTDCdatum);
886       }
887       if(((fBuffer & 0xf0000000) == 0x80000000) && ((fBuffer & 0x08000000) >> 27) == 0){
888         // Trailer
889         fIsTDCHeaderRead = kFALSE;
890         // Ch. debug
891         //printf("  AliZDCRawStream -> ADD TDC global trailer\n");
892       }
893     }
894     // ******************************** TRIGGER SCALER DATA ********************************
895     //  Reading trigger scaler data 
896     if(fIsTriggerScaler && fPosition>=fTrigCountStart+1){
897       fADCModule = kTrigScales; fIsADCDataWord = kFALSE;        
898       if(fPosition == fTrigCountStart+1)      fMBTrigInput = fBuffer;               
899       else if(fPosition == fTrigCountStart+2) fCentralTrigInput = fBuffer;                  
900       else if(fPosition == fTrigCountStart+3) fSCentralTrigInput = fBuffer;
901       else if(fPosition == fTrigCountStart+4) fEMDTrigInput = fBuffer; 
902       else if(fPosition == fTrigCountStart+5) fL0Received = fBuffer;
903       else if(fPosition == fTrigCountStart+6) fMBtrig2CTP = fBuffer;     
904       else if(fPosition == fTrigCountStart+7) fCentralTrig2CTP = fBuffer;  
905       else if(fPosition == fTrigCountStart+8) fSCentralTrig2CTP = fBuffer; 
906       else if(fPosition == fTrigCountStart+9){
907         fEMDTrig2CTP = fBuffer;       
908         fIsTriggerScaler = kFALSE;
909       }
910       // Ch. debug
911       //printf("  AliZDCRawStream -> Trigger Scaler datum %d\n", fPosition-fTrigCountStart);
912     }
913     // ******************************* TRIGGER HISTORY WORDS ******************************
914     //  Reading trigger history
915     if(fIsTriggerHistory && fPosition>=fTrigHistStart+1){
916         fADCModule = kTrigHistory; fIsADCDataWord = kFALSE;     
917         if(fPosition == fTrigHistStart+1){
918           fPileUpBit1stWord = (fBuffer & 0x80000000) >> 31;
919           fL0Bit1stWord = (fBuffer & 0x40000000) >> 30;        
920           fCentralTrigHist = (fBuffer & 0x3fff8000) >> 14; 
921           fMBTrigHist =  (fBuffer & 0x00007fff);        
922           //
923           fCPTInput[0] = (fBuffer & 0x00000080) >> 6;  // MB bit
924           fCPTInput[1] = (fBuffer & 0x00400000) >> 21; // CENTRAL bit
925         }
926         
927         else if(fPosition == fTrigHistStart+fTrigHistNWords){
928           fPileUpBit2ndWord = (fBuffer & 0x80000000) >> 31;
929           fL0Bit2ndWord = (fBuffer & 0x40000000) >> 30;      
930           fSCentralTrigHist = (fBuffer & 0x3fff8000) >> 14; 
931           fEMDTrigHist =  (fBuffer & 0x00007fff);        
932           //
933           fCPTInput[2] = (fBuffer & 0x00000080) >> 6;  // SEMICENTRAL bit
934           fCPTInput[3] = (fBuffer & 0x00400000) >> 21; // EMD bit
935           //
936           fIsTriggerHistory = kFALSE;
937           
938           // Checking if the event is good
939           // (1) both history word pile up bits must be = 0
940           if(fPileUpBit1stWord==0 && fPileUpBit2ndWord==0) fIsPileUpEvent = kFALSE;
941           else{
942             fIsPileUpEvent = kTRUE;
943             printf("  AliZDCRawStream -> PILE UP EVENT: bitPileUp0 %d bitPileUp1 %d\n",
944                 fPileUpBit1stWord, fPileUpBit2ndWord);
945           }
946           // (2) both history word L0 bits must be = 1
947           if(fL0Bit1stWord==1 && fL0Bit2ndWord==1) fIsL0BitSet = kTRUE;
948           else{
949             fIsL0BitSet = kFALSE;
950             printf("  AliZDCRawStream -> L0 wrongly set: bitL0word0 %d bitL0word1 %d\n",
951                 fL0Bit1stWord, fL0Bit2ndWord);
952           }
953         }       
954         // Ch. debug
955         //printf("  AliZDCRawStream -> Trigger history word %d\n", fPosition-fTrigHistStart);
956     }
957     
958   }
959
960   fPosition++;
961
962   return kTRUE;
963 }
964
965 //_____________________________________________________________________________
966 AliCDBStorage* AliZDCRawStream::SetStorage(const char *uri) 
967 {
968   // Setting the storage
969   
970   AliCDBStorage *storage = AliCDBManager::Instance()->GetStorage(uri); 
971
972   return storage; 
973 }
974
975
976 //_____________________________________________________________________________
977 AliZDCChMap* AliZDCRawStream::GetChMap() const
978 {
979
980   // Getting calibration object for ZDC
981
982   AliCDBEntry  *entry = AliCDBManager::Instance()->Get("ZDC/Calib/ChMap");
983   if(!entry) AliFatal("No calibration data loaded!");  
984
985   AliZDCChMap *calibdata = dynamic_cast<AliZDCChMap*> (entry->GetObject());
986   if(!calibdata) AliFatal("Wrong calibration object in calibration  file!");
987
988   return calibdata;
989 }