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