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