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