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