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