]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliZDCRawStream.cxx
Updated raw streaming class, scalers+trigger card+PU included
[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   fEvType(0),
44   fPosition(0),
45   fIsCalib(kFALSE),
46   fIsDARCHeader(kFALSE),
47   fIsHeaderMapping(kFALSE),
48   fIsChMapping(kFALSE),
49   fIsADCDataWord(kFALSE),
50   fIsADCHeader(kFALSE),
51   fIsADCEOB(kFALSE),
52   fSODReading(kFALSE),
53   fIsMapRead(kFALSE),
54   fDARCEvBlockLenght(0),  
55   fDARCBlockAttributes(0),
56   fDeadfaceOffset(0),
57   fDeadbeefOffset(0),
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   fDetPattern(0),
76   fTrigCountNWords(0),
77   fIsTrig1stWordRead(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   fIsHist1stWordRead(kFALSE),
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   fEvType(stream.fEvType),
128   fPosition(stream.fPosition),
129   fIsCalib(stream.fIsCalib),
130   fIsDARCHeader(stream.fIsDARCHeader), 
131   fIsHeaderMapping(stream.fIsHeaderMapping),
132   fIsChMapping(stream.fIsChMapping),
133   fIsADCDataWord(stream.fIsADCDataWord), 
134   fIsADCHeader(stream.fIsADCHeader), 
135   fIsADCEOB(stream.fIsADCEOB), 
136   fSODReading(stream.fSODReading),
137   fIsMapRead(stream.fIsMapRead),
138   fDARCEvBlockLenght(stream.fDARCEvBlockLenght),  
139   fDARCBlockAttributes(stream.fDARCBlockAttributes),
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   fDetPattern(stream.fDetPattern),
160   fTrigCountNWords(stream.fTrigCountNWords),
161   fIsTrig1stWordRead(stream.fIsTrig1stWordRead),
162   fTrigCountStart(stream.fTrigCountStart),
163   fMBTrigInput(stream.fMBTrigInput),       
164   fCentralTrigInput(stream.fCentralTrigInput), 
165   fSCentralTrigInput(stream.fSCentralTrigInput),
166   fEMDTrigInput(stream.fEMDTrigInput),     
167   fL0Received(stream.fL0Received),         
168   fMBtrig2CTP(stream.fMBtrig2CTP),         
169   fCentralTrig2CTP(stream.fCentralTrig2CTP),  
170   fSCentralTrig2CTP(stream.fSCentralTrig2CTP), 
171   fEMDTrig2CTP(stream.fEMDTrig2CTP),          
172   fTrigHistNWords(stream.fTrigHistNWords),
173   fIsHist1stWordRead(stream.fIsHist1stWordRead),
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   //printf("\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 = %d\n",fRawReader->GetDataSize());
250
251     fDARCEvBlockLenght = header->fSize;
252     //printf("\t AliZDCRawStream::ReadCDHHeader -> fDARCEvBlockLenght = %d\n",fDARCEvBlockLenght);
253     
254     UChar_t message = header->GetAttributes();
255     //printf("\t AliZDCRawStream::ReadCDHHeader -> Attributes %x\n",message);
256     
257     if(message == 0x0){ // PHYSICS RUN
258        //printf("\t PHYSICS RUN raw data found\n");
259     }
260     else if(message == 0x10){ // COSMIC RUN
261        //printf("\t STANDALONE_COSMIC RUN raw data found\n");
262     }
263     else if(message == 0x20){ // PEDESTAL RUN
264        //printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
265     }
266     else if(message == 0x30){ // LASER RUN
267        //printf("\t STANDALONE_LASER RUN raw data found\n");
268     }
269     else if(message == 0x40){ // CALIBRATION_CENTRAL RUN
270        //printf("\t CALIBRATION_CENTRAL RUN raw data found\n");
271     }
272     else if(message == 0x50){ // CALIBRATION_SEMICENTRAL
273        //printf("\t CALIBRATION_SEMICENTRAL RUN raw data found\n");
274     }
275     else if(message == 0x60){ // CALIBRATION_MB
276        //printf("\t CALIBRATION_MB RUN raw data found\n");
277     }
278     else if(message == 0x70){ // CALIBRATION_EMD
279        //printf("\t CALIBRATION_EMD RUN raw data found\n");
280     }
281     
282     if(header->GetL1TriggerMessage() & 0x1){ // Calibration bit set in CDH
283       fIsCalib = kTRUE;
284     }
285     //printf("\t AliZDCRawStream::ReadCDHHeader -> L1TriggerMessage %x\n",header->GetL1TriggerMessage());
286     //printf("\t AliZDCRawStream::ReadCDHHeader -> Calibration bit = %d\n",fIsCalib);    
287     
288     UInt_t status = header->GetStatus();
289     //printf("\t AliZDCRawStream::ReadCDHHeader -> status = %d\n",status);
290     if((status & 0x000f) == 0x0001){
291       AliDebug(2,"CDH -> DARC trg0 overlap error");
292       fRawReader->AddMajorErrorLog(kDARCError);
293     }
294     if((status & 0x000f) == 0x0002){
295       AliDebug(2,"CDH -> DARC trg0 missing error");
296       fRawReader->AddMajorErrorLog(kDARCError);
297     }
298     if((status & 0x000f) == 0x0004){
299       AliDebug(2,"CDH -> DARC data parity error");
300       fRawReader->AddMajorErrorLog(kDARCError);
301     }
302     if((status & 0x000f) == 0x0008){
303       AliDebug(2,"CDH -> DARC ctrl parity error");
304       fRawReader->AddMajorErrorLog(kDARCError);
305     }
306     //
307     if((status & 0x00f0) == 0x0010){
308       AliDebug(2,"CDH -> DARC trg unavailable");
309       fRawReader->AddMajorErrorLog(kDARCError);
310     }
311     if((status & 0x00f0) == 0x0020){
312       AliDebug(2,"CDH -> DARC FEE error");
313       fRawReader->AddMajorErrorLog(kDARCError);
314     }
315     //
316     if((status & 0x0f00) == 0x0200){
317       AliDebug(2,"CDH -> DARC L1 time violation");
318       fRawReader->AddMajorErrorLog(kDARCError);
319     }
320     if((status & 0x0f00) == 0x0400){
321       AliDebug(2,"CDH -> DARC L2 time-out");
322       fRawReader->AddMajorErrorLog(kDARCError);
323     }
324     if((status & 0x0f00) == 0x0800){
325       AliDebug(2,"CDH -> DARC prepulse time violation");
326       fRawReader->AddMajorErrorLog(kDARCError);
327     }
328     //
329     if((status & 0xf000) == 0x1000){
330       AliDebug(2,"CDH -> DARC other error");
331       fRawReader->AddMajorErrorLog(kDARCError);
332     }
333   }
334   //
335   fIsDARCHeader = kTRUE;
336 }
337
338 //_____________________________________________________________________________
339 Bool_t AliZDCRawStream::Next()
340 {
341   // Read the next raw digit
342   // Returns kFALSE if there is no digit left
343
344   if(!fRawReader->ReadNextInt((UInt_t&) fBuffer)) return kFALSE;
345   const int kNch = 48;
346   Bool_t readScaler = kFALSE;
347   Int_t kFirstADCGeo=0, kLastADCGeo=3, kScalerGeo=8, kPUGeo=29, kTrigScales=30, kTrigHistory=31;
348   fIsHeaderMapping = kFALSE; fIsChMapping = kFALSE; 
349   fIsADCHeader = kFALSE; fIsADCDataWord = kFALSE; fIsADCEOB = kFALSE;
350   fIsUnderflow = kFALSE; fIsOverflow = kFALSE; 
351   fSector[0] = fSector[1] = -1;
352   fTrigCountNWords = 9; fTrigHistNWords = 2;
353   for(Int_t kl=0; kl<4; kl++) fCPTInput[kl] = 0;
354
355   fEvType = fRawReader->GetType();
356   if(fPosition==0){
357     //if(fEvType==7 || fEvType ==8){ //Physics or calibration event
358       //ReadEventHeader();
359       ReadCDHHeader();
360     //}
361     fCurrentCh=0; fCurrScCh=0; fNChannelsOn=0;
362     // Ch. debug
363     //printf("\n  AliZDCRawStream::Next() - ev. type %d",fEvType);
364   }
365   
366   // Ch. debug
367   //printf("\n  AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
368   
369   // *** End of ZDC event
370   if(fBuffer == 0xcafefade){
371     //printf("\n-> AliZDCRawStream::Next() ***** End of ZDC event *****\n\n");
372     return kFALSE;
373   }
374   
375   // -------------------------------------------
376   // --- DARC header
377   // -------------------------------------------
378   // If the CDH has been read then 
379   // the DARC header must follow
380   if(fIsDARCHeader){
381     //printf("\t ---- DARC header ----\n");
382     if(fIsCalib){
383       fDeadfaceOffset = 9;
384       fDeadbeefOffset = 25;
385       readScaler = kTRUE;
386     }
387     else{
388       fDeadfaceOffset = 1;
389       fDeadbeefOffset = 7;
390     }
391     fDataOffset = 1+fDeadbeefOffset;
392     fIsDARCHeader = kFALSE;
393   }
394
395     
396   // -------------------------------------------
397   // --- Start of data event
398   // --- decoding mapping of connected ADC ch.
399   // -------------------------------------------
400   // In the SOD event ADC ch. mapping is written
401   if(fEvType==10 && fSODReading){
402     //printf("\n-> AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
403     
404     if(fPosition>fDataOffset){
405       if((fBuffer&0xff000001) == 0xff000001){ // ************** Mapping
406         if(fPosition==(fDataOffset+1)){ 
407            printf("\n\n ------ AliZDCRawStream -> Reading mapping from StartOfData event ------\n");
408            fCurrentCh=0; fCurrScCh=0;   
409         }
410         else{
411           printf(" ------ AliZDCRawStream -> End of ZDC StartOfData event ------\n\n");
412           //printf("AliZDCRawStream: fSODReading after SOD reading set to %d\n", fSODReading);
413           return kFALSE;
414         }
415       }
416       else if((fBuffer&0xff000002) == 0xff000002){ // ************** Threshold settings
417         fPosition++;
418         return kFALSE;
419       }
420       else if((fBuffer&0x80000000)>>31 == 1){ // --- Mapping header
421         fIsHeaderMapping = kTRUE;
422         fADCModule = ((fBuffer & 0x7f000000)>>24); // GEO address!!!
423         fModType = ((fBuffer & 0x7ff00)>>8); 
424         fADCNChannels = (fBuffer & 0xff);          // # of channels following the header
425         //
426         printf("  ******** GEO %d, mod. type %d, #ch. %d\n",fADCModule,fModType,fADCNChannels);
427       }
428       else if((fBuffer&0x80000000)>>31 == 0){ // --- Mapping channel
429         fADCChannel = ((fBuffer & 0x3fff0000)>>16);
430         fCabledSignal = (fBuffer&0xffff);
431         //
432         if(fModType==1){ // ******** ADCs ********************************
433            // Channel signal
434           if((fBuffer&0x40000000)>>30==0){ // high range chain ADC
435             fIsChMapping = kTRUE;
436             fMapADC[fCurrentCh][0] = fADCModule;
437             fMapADC[fCurrentCh][1] = fADCChannel;
438             fMapADC[fCurrentCh][2] = fCabledSignal;
439             //  - No. of channels on
440             fNChannelsOn++;
441             //
442             // Determining detector and sector
443             // -----------------------------------------
444             //  For the decoding of the following lines 
445             //  look the enum in AliZDCRawStream.h file
446             // -----------------------------------------
447             if((fCabledSignal>=2 && fCabledSignal<=6) || (fCabledSignal>=26 && fCabledSignal<=30)
448               || fCabledSignal==24 || fCabledSignal==48){
449               fMapADC[fCurrentCh][3] = 4; //ZNA
450               //
451               if(fCabledSignal==2 || fCabledSignal==26)       fMapADC[fCurrentCh][4]=0;
452               else if(fCabledSignal==3 || fCabledSignal==27)  fMapADC[fCurrentCh][4]=1;
453               else if(fCabledSignal==4 || fCabledSignal==28)  fMapADC[fCurrentCh][4]=2;
454               else if(fCabledSignal==5 || fCabledSignal==29)  fMapADC[fCurrentCh][4]=3;
455               else if(fCabledSignal==6 || fCabledSignal==30)  fMapADC[fCurrentCh][4]=4;
456               else if(fCabledSignal==24 || fCabledSignal==48) fMapADC[fCurrentCh][4]=5; //Reference PTM
457             }
458             else if((fCabledSignal>=7 && fCabledSignal<=11) || (fCabledSignal>=31 && fCabledSignal<=35)){
459               fMapADC[fCurrentCh][3] = 5; //ZPA
460               //
461               if(fCabledSignal==7 || fCabledSignal==31)       fMapADC[fCurrentCh][4]=0;
462               else if(fCabledSignal==8 || fCabledSignal==32)  fMapADC[fCurrentCh][4]=1;
463               else if(fCabledSignal==9 || fCabledSignal==33)  fMapADC[fCurrentCh][4]=2;
464               else if(fCabledSignal==10 || fCabledSignal==34) fMapADC[fCurrentCh][4]=3;
465               else if(fCabledSignal==11 || fCabledSignal==35) fMapADC[fCurrentCh][4]=4;
466             }
467             else if((fCabledSignal>=12 && fCabledSignal<=16) || (fCabledSignal>=36 && fCabledSignal<=40)
468                || fCabledSignal==25 || fCabledSignal==49){
469               fMapADC[fCurrentCh][3] = 1; //ZNC
470               //
471               if(fCabledSignal==12 || fCabledSignal==36)      fMapADC[fCurrentCh][4]=0;
472               else if(fCabledSignal==13 || fCabledSignal==37) fMapADC[fCurrentCh][4]=1;
473               else if(fCabledSignal==14 || fCabledSignal==38) fMapADC[fCurrentCh][4]=2;
474               else if(fCabledSignal==15 || fCabledSignal==39) fMapADC[fCurrentCh][4]=3;
475               else if(fCabledSignal==16 || fCabledSignal==40) fMapADC[fCurrentCh][4]=4;
476               else if(fCabledSignal==25 || fCabledSignal==49) fMapADC[fCurrentCh][4]=5; //Reference PTM
477             }
478             else if((fCabledSignal>=17 && fCabledSignal<=21) || (fCabledSignal>=41 && fCabledSignal<=45)){
479               fMapADC[fCurrentCh][3] = 2; //ZPC
480               //
481               if(fCabledSignal==17 || fCabledSignal==41)      fMapADC[fCurrentCh][4]=0;
482               else if(fCabledSignal==18 || fCabledSignal==42) fMapADC[fCurrentCh][4]=1;
483               else if(fCabledSignal==19 || fCabledSignal==43) fMapADC[fCurrentCh][4]=2;
484               else if(fCabledSignal==20 || fCabledSignal==44) fMapADC[fCurrentCh][4]=3;
485               else if(fCabledSignal==21 || fCabledSignal==45) fMapADC[fCurrentCh][4]=4;
486             }
487             else if(fCabledSignal==22 || fCabledSignal==23 || fCabledSignal==46 || fCabledSignal==47){
488               fMapADC[fCurrentCh][3] = 3; // ZEM
489               //
490               if(fCabledSignal==22 || fCabledSignal==46)      fMapADC[fCurrentCh][4]=1;
491               else if(fCabledSignal==23 || fCabledSignal==47) fMapADC[fCurrentCh][4]=2;
492             }
493             //Ch. debug
494             //printf("\tADC mod. %d ch. %d signal %d ",fADCModule,fADCChannel,fCabledSignal);
495             //printf("  det. %d sec. %d\n",fMapADC[fCurrentCh][3],fMapADC[fCurrentCh][4]);
496             //
497             fCurrentCh++;
498             //
499           } // high range channels
500         }// ModType=1 (ADC mapping)
501         else if(fModType==2){  // ******** VME scaler **************************
502           fIsChMapping = kTRUE;
503           fScalerMap[fCurrScCh][0] = fADCModule;
504           fScalerMap[fCurrScCh][1] = fADCChannel;
505           fScalerMap[fCurrScCh][2] = fCabledSignal;
506           //
507           // Determining detector and sector
508           // -----------------------------------------
509           //  For the decoding of the following lines 
510           //  look the enum in AliZDCRawStream.h file
511           // -----------------------------------------
512           // NOT CONSIDERING OUT OF TIME OR REFERENCE SIGNALS FOR SCALER!!!!!
513           if(fCabledSignal>=2 && fCabledSignal<=6){
514             fScalerMap[fCurrScCh][3] = 4; //ZNA
515             //
516             if(fCabledSignal==2 )      fScalerMap[fCurrScCh][4]=0;
517             else if(fCabledSignal==3)  fScalerMap[fCurrScCh][4]=1;
518             else if(fCabledSignal==4)  fScalerMap[fCurrScCh][4]=2;
519             else if(fCabledSignal==5)  fScalerMap[fCurrScCh][4]=3;
520             else if(fCabledSignal==6)  fScalerMap[fCurrScCh][4]=4;
521           }
522           else if(fCabledSignal>=7 && fCabledSignal<=11){
523             fScalerMap[fCurrScCh][3] = 5; //ZPA
524             //
525             if(fCabledSignal==7 )      fScalerMap[fCurrScCh][4]=0;
526             else if(fCabledSignal==8)  fScalerMap[fCurrScCh][4]=1;
527             else if(fCabledSignal==9)  fScalerMap[fCurrScCh][4]=2;
528             else if(fCabledSignal==10) fScalerMap[fCurrScCh][4]=3;
529             else if(fCabledSignal==11) fScalerMap[fCurrScCh][4]=4;
530           }
531           else if(fCabledSignal>=12 && fCabledSignal<=16){
532             fScalerMap[fCurrScCh][3] = 1; //ZNC
533             //
534             if(fCabledSignal==12)      fScalerMap[fCurrScCh][4]=0;
535             else if(fCabledSignal==13) fScalerMap[fCurrScCh][4]=1;
536             else if(fCabledSignal==14) fScalerMap[fCurrScCh][4]=2;
537             else if(fCabledSignal==15) fScalerMap[fCurrScCh][4]=3;
538             else if(fCabledSignal==16) fScalerMap[fCurrScCh][4]=4;
539           }
540           else if(fCabledSignal>=17 && fCabledSignal<=21){
541             fScalerMap[fCurrScCh][3] = 2; //ZPC
542             //
543             if(fCabledSignal==17)      fScalerMap[fCurrScCh][4]=0;
544             else if(fCabledSignal==18) fScalerMap[fCurrScCh][4]=1;
545             else if(fCabledSignal==19) fScalerMap[fCurrScCh][4]=2;
546             else if(fCabledSignal==20) fScalerMap[fCurrScCh][4]=3;
547             else if(fCabledSignal==21) fScalerMap[fCurrScCh][4]=4;
548           }
549           else if(fCabledSignal==22 || fCabledSignal==23){
550             fScalerMap[fCurrScCh][3] = 3; // ZEM
551             //
552             if(fCabledSignal==22 )     fScalerMap[fCurrScCh][4]=1;
553             else if(fCabledSignal==23) fScalerMap[fCurrScCh][4]=2;
554           }
555           // Ch debug.
556           //printf("\t VME scaler mod. %d ch. %d, signal %d",fScalerMap[fCurrScCh][0],fADCChannel,fCabledSignal);
557           //if(fCabledSignal!=0 && fCabledSignal!=1) printf("  det. %d sec. %d\n",fScalerMap[fCurrScCh][3],fScalerMap[fCurrScCh][4]);
558           //else printf("  Signal void/not connected\n");
559           
560           fCurrScCh++;
561         }
562         else if(fModType==3){ // **** scalers from trigger card
563           //printf("\t Trigger scaler mod. %d ch. %d, signal %d\n",fADCModule,fADCChannel,fCabledSignal);         
564         }
565         else if(fModType==4){ // **** trigger history from trigger card
566           //printf("\t Trigger card ch. %d, signal %d\n",fADCChannel,fCabledSignal);
567         }
568         else if(fModType==5){ // **** pattern unit
569           //printf("\t P.U. mod. %d ch. %d, signal %d\n",fADCModule,fADCChannel,fCabledSignal);
570         }
571       }//reading channel mapping
572     }
573     fPosition++;
574     return kTRUE;
575   } // SOD event
576   
577   // -------------------------------------------
578   // --- DARC data
579   // -------------------------------------------
580   if(fPosition<fDeadfaceOffset){
581     fPosition++;
582     return kTRUE;
583   }
584   else if(fPosition==fDeadfaceOffset){
585     if(fBuffer != 0xdeadface){
586       AliWarning(" NO deadface after DARC data");
587       fRawReader->AddMajorErrorLog(kDARCError); 
588     }
589     else{
590       fPosition++;
591       return kTRUE;
592     }
593   }
594   
595   // -------------------------------------------
596   // --- DARC global data
597   // -------------------------------------------
598   else if(fPosition>fDeadfaceOffset && fPosition<fDeadbeefOffset){
599     fPosition++;
600     return kTRUE;
601   }
602   else if(fPosition==fDeadbeefOffset){
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   }
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     // Not valid datum before the event 
625     // there MUST be a NOT valid datum before the event!!!
626     if(fPosition==fDataOffset){
627       //printf("\t **** ZDC data begin ****\n");
628       if((fBuffer & 0x07000000) != 0x06000000){
629         fRawReader->AddMajorErrorLog(kZDCDataError);
630       }
631       else if((fBuffer & 0x07000000) == 0x06000001){ // Corrupted event!!!
632         fIsADCEventGood = kFALSE;
633       }
634     }
635     
636     // If the not valid datum isn't followed by the 1st ADC header
637     // the event is corrupted (i.e., 2 gates arrived before trigger)
638     else if(fPosition==fDataOffset+1){
639       if((fBuffer & 0x07000000) != 0x02000000){
640         AliWarning("ZDC ADC -> The not valid datum is NOT followed by an ADC header!");
641         fRawReader->AddMajorErrorLog(kZDCDataError);
642         fIsADCEventGood = kFALSE;
643       }
644     }
645      
646     // Get geo address of current word
647     // - ADC GEO = 0, 1, 2, 3
648     // - VME scaler GEO = 8
649     // - PU GEO = 29
650     // - Trigger card scales GEO = 30
651     // - Trigger card history GEO = 31
652     fADCModule = (Int_t) ((fBuffer & 0xf8000000)>>27);
653     //printf("  AliZDCRawStream -> Module GEO address %d\n",fADCModule);
654     
655     // ************************************ ADC MODULES ************************************
656     if(fADCModule>=kFirstADCGeo && fADCModule<=kLastADCGeo){
657       // *** ADC header
658       if((fBuffer & 0x07000000) == 0x02000000){
659         fIsADCHeader = kTRUE;
660         fADCNChannels = ((fBuffer & 0x00003f00)>>8);
661         //printf("  AliZDCRawStream -> ADC HEADER: mod.%d has %d ch. \n",fADCModule,fADCNChannels);
662       }
663       // *** ADC data word
664       else if((fBuffer & 0x07000000) == 0x00000000){
665         fIsADCDataWord = kTRUE;
666         fADCChannel = ((fBuffer & 0x1e0000) >> 17);
667         fADCGain = ((fBuffer & 0x10000) >> 16);       
668         fADCValue = (fBuffer & 0xfff);  
669         //
670         //printf("  AliZDCRawStream -> ADC DATUM: mod. %d ch. %d gain %d value %d\n",
671         //  fADCModule,fADCChannel,fADCGain,fADCValue);
672         
673         // Checking if the channel map for the ADCs has been provided/read
674         if(fMapADC[0][0]==-1){
675           printf("\t ATTENTION!!! No ADC mapping has been found/provided!!!\n");
676           return kFALSE;
677         }
678         //
679         /*for(Int_t ci=0; ci<kNch; ci++){
680           printf("  %d mod %d ch %d det %d sec %d\n",ci,fMapADC[ci][0],
681           fMapADC[ci][1], fMapADC[ci][3], fMapADC[ci][4]);
682         }*/
683                 
684         // Scan of the map to assign the correct volumes
685         Int_t foundMapEntry = kFALSE;
686         for(Int_t k=0; k<kNch; k++){
687            if(fADCModule==fMapADC[k][0] && fADCChannel==fMapADC[k][1]){
688              fSector[0] = fMapADC[k][3];
689              fSector[1] = fMapADC[k][4];
690              foundMapEntry = kTRUE;
691              break;
692            } 
693         }
694         if(foundMapEntry==kFALSE){
695           AliWarning(Form(" No valid entry in ADC mapping for raw data %d ADCmod. %d ch. %d\n",
696               fPosition,fADCModule,fADCChannel));
697         }
698         //
699         //printf("AliZDCRawStream -> ADCmod. %d ch. %d -> det %d sec %d\n",
700         //  fADCModule,fADCChannel,fSector[0],fSector[1]);
701         
702         // Final checks
703         if(foundMapEntry==kTRUE){
704           if(fSector[0]<1 || fSector[0]>5){
705             AliWarning(Form(" No valid detector assignment: %d",fSector[0]));
706             fRawReader->AddMajorErrorLog(kInvalidSector);
707           }
708           //
709           if(fSector[1]<0 || fSector[1]>5){
710             AliWarning(Form(" No valid sector assignment: %d",fSector[1]));
711             fRawReader->AddMajorErrorLog(kInvalidSector);
712           }
713           //
714           if(fADCModule<0 || fADCModule>3){
715             AliError(Form(" No valid ADC module: %d",fADCModule));
716             fRawReader->AddMajorErrorLog(kInvalidADCModule);
717           }
718         }
719
720         // Checking the underflow and overflow bits
721         if(fBuffer & 0x1000)       fIsUnderflow = kTRUE;
722         else if (fBuffer & 0x2000) fIsOverflow = kTRUE; 
723                 
724       }//ADC data word
725       // *** ADC EOB
726       else if((fBuffer & 0x07000000) == 0x04000000){
727         fIsADCEOB = kTRUE;
728         //printf("  AliZDCRawStream -> EOB --------------------------\n");
729       }
730     }//ADC module
731     // ********************************* VME SCALER HEADER *********************************
732     else if(fADCModule == kScalerGeo){
733       if(fBuffer & 0x04000000 && fIsScHeaderRead==kFALSE){ // *** Scaler header
734         fScGeo = (fBuffer & 0xf8000000)>>27;       
735         fScNWords = (fBuffer & 0x00fc0000)>>18;    
736         fScTriggerSource = (fBuffer & 0x00030000)>>16;     
737         fScTriggerNumber = (fBuffer & 0x0000ffff);
738         fIsScHeaderRead = kTRUE; 
739         fScStartCounter = (Int_t) (fPosition);
740         //Ch. debug
741         //printf("  AliZDCRawStream -> SCALER HEADER: geo %d Nwords %d TrigSource %d TrigNo. %d\n",
742         //   fScGeo,fScNWords,fScTriggerSource,fScTriggerNumber);
743       } 
744       else if(!(fBuffer & 0x04000000)){
745         fIsScEventGood = kFALSE;
746       }
747     }
748     // *********************************** PATTERN UNIT ***********************************
749     else if(fADCModule == kPUGeo){
750       // still to be implemented!!! Not yet in data!!!
751       fDetPattern = (fBuffer & 0x0000003f);
752     }
753     // ******************************** TRIGGER CARD COUNTS ********************************
754     else if(fADCModule == kTrigScales){
755       if(fIsTrig1stWordRead == kFALSE){
756         fTrigCountStart = fPosition;
757         fMBTrigInput = fBuffer;
758         fIsTrig1stWordRead = kTRUE;
759       }
760       else{
761         if(fPosition == fTrigCountStart+1)      fCentralTrigInput = fBuffer;                  
762         else if(fPosition == fTrigCountStart+2) fSCentralTrigInput = fBuffer;
763         else if(fPosition == fTrigCountStart+3) fEMDTrigInput = fBuffer; 
764         else if(fPosition == fTrigCountStart+4) fL0Received = fBuffer;
765         else if(fPosition == fTrigCountStart+5) fMBtrig2CTP = fBuffer;     
766         else if(fPosition == fTrigCountStart+6) fCentralTrig2CTP = fBuffer;  
767         else if(fPosition == fTrigCountStart+7) fSCentralTrig2CTP = fBuffer; 
768         else if(fPosition == fTrigCountStart+8){
769           fEMDTrig2CTP = fBuffer;       
770           fIsTrig1stWordRead = kFALSE;
771         }
772       }
773       
774     }
775     // ********************************** TRIGGER HISTORY **********************************
776     else if(fADCModule == kTrigHistory){
777       if(fIsHist1stWordRead == kFALSE){
778         fIsHist1stWordRead = kTRUE;
779         fPileUpBit1stWord = (fBuffer & 0x80000000) >> 31;
780         fL0Bit1stWord = (fBuffer & 0x40000000) >> 30;        
781         fCentralTrigHist = (fBuffer & 0x3fff8000) >> 14; 
782         fMBTrigHist =  (fBuffer & 0x00007fff);        
783         //
784         fCPTInput[0] = (fBuffer & 0x00000080) >> 6;  // MB bit
785         fCPTInput[1] = (fBuffer & 0x00400000) >> 21; // CENTRAL bit
786       }
787       else{
788         fPileUpBit2ndWord = (fBuffer & 0x80000000) >> 31;
789         fL0Bit2ndWord = (fBuffer & 0x40000000) >> 30;        
790         fSCentralTrigHist = (fBuffer & 0x3fff8000) >> 14; 
791         fEMDTrigHist =  (fBuffer & 0x00007fff);          
792         //
793         fCPTInput[2] = (fBuffer & 0x00000080) >> 6;  // SEMICENTRAL bit
794         fCPTInput[3] = (fBuffer & 0x00400000) >> 21; // EMD bit
795         //
796         // Checking if the event is good
797         // (1) both history word pile up bits must be = 0
798         if(fPileUpBit1stWord==0 && fPileUpBit2ndWord==0) fIsPileUpEvent = kFALSE;
799         else fIsPileUpEvent = kTRUE;
800         // (2) both history word L0 bits must be = 1
801         if(fL0Bit1stWord==1 && fL0Bit2ndWord==1) fIsL0BitSet = kTRUE;
802         else fIsL0BitSet = kFALSE;
803       }
804     } 
805     // ********************************** VME SCALER DATA **********************************
806     //  Reading VME scaler data 
807     if(fIsScHeaderRead && fPosition>=fScStartCounter+1){ // *** Scaler word
808       fADCModule = fScGeo;
809       fScEvCounter = fBuffer;
810       Int_t nWords = (Int_t) (fScNWords);
811       if(fPosition == fScStartCounter+nWords) fIsScHeaderRead = kFALSE;
812       //Ch. debug
813       //printf("  AliZDCRawStream -> scaler datum %d", fScEvCounter);
814     }
815     
816   }
817   fPosition++;
818
819   return kTRUE;
820 }
821
822 //_____________________________________________________________________________
823 AliCDBStorage* AliZDCRawStream::SetStorage(const char *uri) 
824 {
825   // Setting the storage
826   
827   AliCDBStorage *storage = AliCDBManager::Instance()->GetStorage(uri); 
828
829   return storage; 
830 }
831
832
833 //_____________________________________________________________________________
834 AliZDCChMap* AliZDCRawStream::GetChMap() const
835 {
836
837   // Getting calibration object for ZDC
838
839   AliCDBEntry  *entry = AliCDBManager::Instance()->Get("ZDC/Calib/ChMap");
840   if(!entry) AliFatal("No calibration data loaded!");  
841
842   AliZDCChMap *calibdata = dynamic_cast<AliZDCChMap*> (entry->GetObject());
843   if(!calibdata) AliFatal("Wrong calibration object in calibration  file!");
844
845   return calibdata;
846 }