]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliZDCRawStream.cxx
Remove High Voltage STATus values from preprocessor configuration
[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   fIsChMapping(kFALSE),
48   fIsADCDataWord(kFALSE),
49   fIsADCHeader(kFALSE),
50   fIsADCEOB(kFALSE),
51   fDARCEvBlockLenght(0),  
52   fDARCBlockAttributes(0),
53   fDeadfaceOffset(0),
54   fDeadbeefOffset(0),
55   fDataOffset(0),
56   fModType(-1),
57   fADCModule(-1),
58   fADCNChannels(-1),     
59   fADCChannel(-1),       
60   fADCValue(-1),         
61   fADCGain(-1),
62   fNConnCh(-1),
63   fCabledSignal(-1)
64 {
65   // Create an object to read ZDC raw digits
66   fRawReader->Reset();
67   fRawReader->Select("ZDC");
68   //
69   for(Int_t i=0; i<48; i++){
70     for(Int_t j=0; j<5; j++) fMapADC[i][j]=-1;
71   }
72
73 }
74
75 //_____________________________________________________________________________
76 AliZDCRawStream::AliZDCRawStream(const AliZDCRawStream& stream) :
77   TObject(stream),
78   fRawReader(stream.fRawReader),
79   fBuffer(stream.GetRawBuffer()),
80   fEvType(stream.fEvType),
81   fPosition(stream.fPosition),
82   fIsCalib(stream.fIsCalib),
83   fIsDARCHeader(stream.fIsDARCHeader), 
84   fIsChMapping(stream.fIsChMapping),
85   fIsADCDataWord(stream.fIsADCDataWord), 
86   fIsADCHeader(stream.fIsADCHeader), 
87   fIsADCEOB(stream.fIsADCEOB), 
88   fDARCEvBlockLenght(stream.fDARCEvBlockLenght),  
89   fDARCBlockAttributes(stream.fDARCBlockAttributes),
90   fDeadfaceOffset(stream.GetDeadfaceOffset()),
91   fDeadbeefOffset(stream.GetDeadbeefOffset()),
92   fDataOffset(stream.GetDataOffset()),
93   fModType(stream.GetModType()),
94   fADCModule(stream.GetADCModule()),     
95   fADCNChannels(stream.GetADCNChannels()),       
96   fADCChannel(stream.GetADCChannel()),   
97   fADCValue(stream.GetADCValue()),       
98   fADCGain(stream.GetADCGain()),
99   fNConnCh(stream.fNConnCh),
100   fCabledSignal(stream.GetCabledSignal())
101 {
102   // Copy constructor
103   for(Int_t j=0; j<2; j++) fSector[j] = stream.GetSector(j);     
104   for(Int_t i=0; i<48; i++){
105     for(Int_t j=0; j<5; j++) fMapADC[i][j] = stream.fMapADC[i][j];
106   }
107 }
108
109 //_____________________________________________________________________________
110 AliZDCRawStream& AliZDCRawStream::operator = (const AliZDCRawStream& 
111                                               /* stream */)
112 {
113   // Assignment operator
114   Fatal("operator =", "assignment operator not implemented");
115   return *this;
116 }
117
118 //_____________________________________________________________________________
119 AliZDCRawStream::~AliZDCRawStream()
120 {
121 // Destructor
122
123 }
124
125 //_____________________________________________________________________________
126 void AliZDCRawStream::ReadChMap()
127 {
128   // Reading channel map
129 }
130
131 //_____________________________________________________________________________
132 void AliZDCRawStream::ReadCDHHeader()
133 {
134   // Reading CDH 
135   const AliRawDataHeader* header = fRawReader->GetDataHeader();
136   if(!header) {
137       AliError("\t No CDH in raw data streaming\n");
138       fRawReader->AddMajorErrorLog(kCDHError);
139       //
140       // For the moment to debug the classe the event is read
141       // also if the CDH is not present in the data buffer
142       // ******* TO BE CHANGED!!! ***************************
143       //return;
144   }
145   else{
146     //printf("\t AliZDCRawStream::ReadCDHHeader -> Data Size = %d\n",fRawReader->GetDataSize());
147
148     fDARCEvBlockLenght = header->fSize;
149     //printf("\t AliZDCRawStream::ReadCDHHeader -> fDARCEvBlockLenght = %d\n",fDARCEvBlockLenght);
150     
151     //UChar_t message = header->GetAttributes();
152     //printf("\t AliZDCRawStream::ReadCDHHeader -> Attributes %x\n",message);
153     
154     /*if(message & 0x10){ // COSMIC RUN
155        printf("\t STANDALONE_COSMIC RUN raw data found\n");
156     }
157     else if(message & 0x20){ // PEDESTAL RUN
158        printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
159     }
160     else if(message & 0x30){ // LASER RUN
161        printf("\t STANDALONE_LASER RUN raw data found\n");
162     }*/
163     
164     if(header->GetL1TriggerMessage() & 0x1){ // Calibration bit set in CDH
165       fIsCalib = kTRUE;
166     }
167     //printf("\t AliZDCRawStream::ReadCDHHeader -> L1TriggerMessage %x\n",header->GetL1TriggerMessage());
168     //printf("\t AliZDCRawStream::ReadCDHHeader -> Calibration bit = %d\n",fIsCalib);    
169     
170     UInt_t status = header->GetStatus();
171     //printf("\t AliZDCRawStream::ReadCDHHeader -> status = %d\n",status);
172     if(status & 0x000f == 0x0001){
173       AliWarning("CDH -> DARC trg0 overlap error\n");
174       fRawReader->AddMajorErrorLog(kDARCError);
175     }
176     if(status & 0x000f == 0x0002){
177       AliWarning("CDH -> DARC trg0 missing error\n");
178       fRawReader->AddMajorErrorLog(kDARCError);
179     }
180     if(status & 0x000f == 0x0004){
181       AliWarning("CDH -> DARC data parity error\n");
182       fRawReader->AddMajorErrorLog(kDARCError);
183     }
184     if(status & 0x000f == 0x0008){
185       AliWarning("CDH -> DARC ctrl parity error\n");
186       fRawReader->AddMajorErrorLog(kDARCError);
187     }
188     //
189     if(status & 0x00f0 == 0x0010){
190       AliWarning("CDH -> DARC trg unavailable\n");
191       fRawReader->AddMajorErrorLog(kDARCError);
192     }
193     if(status & 0x00f0 == 0x0020){
194       AliWarning("CDH -> DARC FEE error\n");
195       fRawReader->AddMajorErrorLog(kDARCError);
196     }
197     //
198     if(status & 0x0f00 == 0x0200){
199       AliWarning("CDH -> DARC L1 time violation\n");
200       fRawReader->AddMajorErrorLog(kDARCError);
201     }
202     if(status & 0x0f00 == 0x0400){
203       AliWarning("CDH -> DARC L2 time-out\n");
204       fRawReader->AddMajorErrorLog(kDARCError);
205     }
206     if(status & 0x0f00 == 0x0800){
207       AliWarning("CDH -> DARC prepulse time violation\n");
208       fRawReader->AddMajorErrorLog(kDARCError);
209     }
210     //
211     if(status & 0xf000 == 0x1000){
212       AliWarning("CDH -> DARC other error\n");
213       fRawReader->AddMajorErrorLog(kDARCError);
214     }
215   }
216   //
217   fIsDARCHeader = kTRUE;
218 }
219
220
221 //_____________________________________________________________________________
222 Bool_t AliZDCRawStream::Next()
223 {
224   // Read the next raw digit
225   // Returns kFALSE if there is no digit left
226
227   if(!fRawReader->ReadNextInt((UInt_t&) fBuffer)) return kFALSE;
228   fIsChMapping = kFALSE; fIsADCHeader = kFALSE; 
229   fIsADCDataWord = kFALSE; fIsADCEOB = kFALSE;
230   
231   fEvType = fRawReader->GetType();
232   //printf("\n\t AliZDCRawStream::Next() -> ev. type %d\n",fEvType);
233   
234   if(fPosition==0){
235     //if(fEvType==7 || fEvType ==8){ //Physics or calibration event
236       //ReadEventHeader();
237       ReadCDHHeader();
238     //}
239     fNConnCh=0;
240   }
241   //printf("\n  AliZDCRawStream::Next() - fBuffer[%d] = %x\n",fPosition, fBuffer);
242   
243   // -------------------------------------------
244   // --- DARC header
245   // -------------------------------------------
246   if(fIsDARCHeader){
247     //printf("\t ---- DARC header ----\n");
248     if(fIsCalib){
249       fDeadfaceOffset = 9;
250       fDeadbeefOffset = 25;
251     }
252     else{
253       fDeadfaceOffset = 1;
254       fDeadbeefOffset = 7;
255     }
256     fDataOffset = 1+fDeadbeefOffset;
257     fIsDARCHeader = kFALSE;
258   }
259   
260     
261   // -------------------------------------------
262   // --- Start of data event
263   // --- decoding mapping of connected ADC ch.
264   // -------------------------------------------
265   if(fEvType==10){
266     if(fPosition>fDataOffset){
267       if((fBuffer&0xff000000) == 0xff000000){
268         if(fPosition==(fDataOffset+1)){ 
269            printf("\n\n\t Reading ZDC mapping from StartOfData event\n");
270            fNConnCh=0;  
271         }
272         else{
273           //printf("\n\t End of StartOfData event\n\n");
274           return kTRUE;
275         }
276       }
277       else if((fBuffer&0x80000000)>>31 == 1){
278         // Mapping identification
279         fADCModule = ((fBuffer & 0x7f000000)>>24);
280         fModType = ((fBuffer & 0xfff000)>>8);
281         fADCNChannels = (fBuffer & 0xff);
282         //
283         //printf("\tGEO %d, mod. type %d, #ch. %d\n",fADCModule,fModType,fADCNChannels);
284       }
285       else if(fModType==0 && (fBuffer&0x80000000)>>31 == 0){
286         // Channel signal
287         if((fBuffer&0x40000000)>>30==0){ // high range chain ADC
288           fIsChMapping = kTRUE;
289           fADCChannel = ((fBuffer & 0x3fff0000)>>16);
290           fCabledSignal = (fBuffer&0xffff);
291           fMapADC[fNConnCh][0] = fADCModule;
292           fMapADC[fNConnCh][1] = fADCChannel;
293           fMapADC[fNConnCh][2] = fCabledSignal;
294           //
295           // Determining detector and sector
296           // -----------------------------------------
297           //  For the decoding of the following lines 
298           //  look the enum in AliZDCRawStream.h file
299           // -----------------------------------------
300           if((fCabledSignal>=2 && fCabledSignal<=6) || (fCabledSignal>=26 && fCabledSignal<=30)
301              || fCabledSignal==24 || fCabledSignal==48){
302             fMapADC[fNConnCh][3] = 4;
303             //
304             if(fCabledSignal==2 || fCabledSignal==26) fMapADC[fNConnCh][4]=0;
305             else if(fCabledSignal==3 || fCabledSignal==27) fMapADC[fNConnCh][4]=1;
306             else if(fCabledSignal==4 || fCabledSignal==28) fMapADC[fNConnCh][4]=2;
307             else if(fCabledSignal==5 || fCabledSignal==29) fMapADC[fNConnCh][4]=3;
308             else if(fCabledSignal==6 || fCabledSignal==30) fMapADC[fNConnCh][4]=4;
309             else if(fCabledSignal==24 || fCabledSignal==48) fMapADC[fNConnCh][4]=5;
310           }
311           else if((fCabledSignal>=7 && fCabledSignal<=11) || (fCabledSignal>=31 && fCabledSignal<=35)){
312             fMapADC[fNConnCh][3] = 5;
313             //
314             if(fCabledSignal==7 || fCabledSignal==31) fMapADC[fNConnCh][4]=0;
315             else if(fCabledSignal==8 || fCabledSignal==32) fMapADC[fNConnCh][4]=1;
316             else if(fCabledSignal==9 || fCabledSignal==33) fMapADC[fNConnCh][4]=2;
317             else if(fCabledSignal==10 || fCabledSignal==34) fMapADC[fNConnCh][4]=3;
318             else if(fCabledSignal==11 || fCabledSignal==35) fMapADC[fNConnCh][4]=4;
319           }
320           else if((fCabledSignal>=12 && fCabledSignal<=16) || (fCabledSignal>=36 && fCabledSignal<=40)
321              || fCabledSignal==25 || fCabledSignal==49){
322             fMapADC[fNConnCh][3] = 3;
323             //
324             if(fCabledSignal==12 || fCabledSignal==36) fMapADC[fNConnCh][4]=0;
325             else if(fCabledSignal==13 || fCabledSignal==37) fMapADC[fNConnCh][4]=1;
326             else if(fCabledSignal==14 || fCabledSignal==38) fMapADC[fNConnCh][4]=2;
327             else if(fCabledSignal==15 || fCabledSignal==39) fMapADC[fNConnCh][4]=3;
328             else if(fCabledSignal==16 || fCabledSignal==40) fMapADC[fNConnCh][4]=4;
329             else if(fCabledSignal==25 || fCabledSignal==49) fMapADC[fNConnCh][4]=5;
330           }
331           else if((fCabledSignal>=17 && fCabledSignal<=21) || (fCabledSignal>=41 && fCabledSignal<=45)){
332             fMapADC[fNConnCh][3] = 1;
333             //
334             if(fCabledSignal==17 || fCabledSignal==41) fMapADC[fNConnCh][4]=0;
335             else if(fCabledSignal==18 || fCabledSignal==42) fMapADC[fNConnCh][4]=1;
336             else if(fCabledSignal==19 || fCabledSignal==43) fMapADC[fNConnCh][4]=2;
337             else if(fCabledSignal==20 || fCabledSignal==44) fMapADC[fNConnCh][4]=3;
338             else if(fCabledSignal==21 || fCabledSignal==45) fMapADC[fNConnCh][4]=4;
339           }
340           else if(fCabledSignal==22 || fCabledSignal==23 || fCabledSignal==46 || fCabledSignal==47){
341             fMapADC[fNConnCh][3] = 2;
342             //
343             if(fCabledSignal==22 || fCabledSignal==46) fMapADC[fNConnCh][4]=1;
344             else if(fCabledSignal==23 || fCabledSignal==47) fMapADC[fNConnCh][4]=2;
345           }
346           //
347           //printf("AliZDCRawStream -> datum %d mod. %d ch. %d signal %d, det %d, tow %d\n",
348           //   fNConnCh,fADCModule,fADCChannel,fBuffer&0xffff,fMapADC[fNConnCh][3],fMapADC[fNConnCh][4]);
349           //
350           fNConnCh++;
351           if(fNConnCh>48){
352             // Protection manually set since it returns:
353             // RawData48 mod. 3 ch. 2048 signal 515
354             // to be checked with Pietro!!!!!!!!!!!!!!!!!!!!!!!
355             AliWarning("\t AliZDCRawStream -> ERROR: no. of cabled channels > 48!!!\n");
356             return kFALSE;
357           }
358         }
359       }
360     }
361     fPosition++;
362     return kTRUE;
363   }
364   
365   // -------------------------------------------
366   // --- DARC data
367   // -------------------------------------------
368   if(fPosition<fDeadfaceOffset){
369     fPosition++;
370     return kTRUE;
371   }
372   else if(fPosition==fDeadfaceOffset){
373     if(fBuffer != 0xdeadface){
374       AliWarning("AliZDCRawStream -> NO deadface after DARC data\n");
375       fRawReader->AddMajorErrorLog(kDARCError);  
376     }
377     else{
378       fPosition++;
379       return kTRUE;
380     }
381   }
382   
383   // -------------------------------------------
384   // --- DARC global data
385   // -------------------------------------------
386   else if(fPosition>fDeadfaceOffset && fPosition<fDeadbeefOffset){
387     fPosition++;
388     return kTRUE;
389   }
390   else if(fPosition==fDeadbeefOffset){
391     if(fBuffer != 0xdeadbeef){
392       AliWarning("AliZDCRawStream -> NO deadbeef after DARC global data\n");
393       fRawReader->AddMajorErrorLog(kDARCError);  
394     }
395     else{
396       fPosition++;
397       return kTRUE;
398     }
399   }
400
401   // -------------------------------------------
402   // --- ZDC data
403   // --- ADC buffer + scaler
404   // -------------------------------------------
405   else if(fPosition>=fDataOffset){
406   
407     // Not valid datum before the event 
408     // there MUST be a NOT valid datum before the event!!!
409     if(fPosition==fDataOffset){
410       //printf("\t **** ZDC data begin ****\n");
411       if((fBuffer & 0x07000000) == 0x06000000){
412         //printf("    AliZDCRawStream -> Not valid datum in ADC %d,"
413         //       "position %d in word data buffer\n",fADCModule,fPosition);
414       }
415       else fRawReader->AddMajorErrorLog(kZDCDataError);
416     }
417     
418     // If the not valid datum isn't followed by the 1st ADC header
419     // the event is corrupted (i.e., 2 gates arrived before trigger)
420     else if(fPosition==fDataOffset+1){
421       if((fBuffer & 0x07000000) != 0x02000000){
422         AliWarning("ZDC ADC -> The not valid datum is NOT followed by an ADC header!\n");
423         fRawReader->AddMajorErrorLog(kZDCDataError);
424       }
425     }
426      
427     // Get geo address of current word to determine
428     // if it is a scaler word (geo address == kScalerAddress)
429     // if it is an ADC word (geo address != 8)
430     Int_t kScalerAddress=8;
431     fADCModule = ((fBuffer & 0xf8000000)>>27);
432     if(fADCModule == kScalerAddress){
433       DecodeScaler();
434     }
435     else{//ADC module
436       // *** End of event
437       if(fBuffer == 0xcafefade){
438         //printf("  AliZDCRawStream ->  End of ZDC event!\n");
439       }
440       // *** ADC header
441       else if((fBuffer & 0x07000000) == 0x02000000){
442         fIsADCHeader = kTRUE;
443         fADCNChannels = ((fBuffer & 0x00003f00)>>8);
444         //printf("  AliZDCRawStream -> HEADER: ADC mod.%d has %d ch. \n",fADCModule,fADCNChannels);
445       }
446       // *** ADC data word
447       else if((fBuffer & 0x07000000) == 0x00000000){
448         fIsADCDataWord = kTRUE;
449         fADCChannel = ((fBuffer & 0x1e0000) >> 17);
450         fADCGain = ((fBuffer & 0x10000) >> 16);       
451         fADCValue = (fBuffer & 0xfff);  
452         
453         //printf("  AliZDCRawStream -> DATA: ADC mod. %d ch. %d gain %d value %d\n",
454         //  fADCModule,fADCChannel,fADCGain,fADCValue);
455
456         // Valid ADC data (not underflow nor overflow)
457         if(!(fBuffer & 0x1000) && !(fBuffer & 0x2000)){ 
458         
459           // Checking if the channel map for the ADCs has been provided/read
460           if(fMapADC[0][0]==-1){
461             // Temporary solution (to be changed!!!!)
462             //printf("\t ATTENTION!!! No ADC mapping has been found/provided!!!\n");
463             //return kFALSE;
464             char * mapFileName=gSystem->ExpandPathName("$ALICE_ROOT/ZDC/ShuttleInput/ZDCChMapping.dat");
465             FILE *file; 
466             Int_t ival[48][6];
467             if((file = fopen(mapFileName,"r")) != NULL){
468               for(Int_t j=0; j<48; j++){
469                 for(Int_t k=0; k<6; k++){
470                   fscanf(file,"%d",&ival[j][k]);
471                 }
472                 fMapADC[j][0] = ival[j][1];
473                 fMapADC[j][1] = ival[j][2];
474                 fMapADC[j][2] = ival[j][3];
475                 fMapADC[j][3] = ival[j][4];
476                 fMapADC[j][4] = ival[j][5];
477               }
478             }
479             else{
480                 printf("File %s not found\n",mapFileName);
481                 return kFALSE;
482             }
483
484           }
485           //
486           //printf("\n Reading map!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
487           /*for(Int_t ci=0; ci<48; ci++){
488             printf("  %d mod. %d ch. %d signal %d\n",ci,fMapADC[ci][0],
489             fMapADC[ci][1], fMapADC[ci][2]);
490           }
491           */
492           for(Int_t k=0; k<48; k++){
493              if(fADCModule==fMapADC[k][0] && fADCChannel==fMapADC[k][1]){
494                fSector[0] = fMapADC[k][3];
495                fSector[1] = fMapADC[k][4];
496                break;
497              } 
498           }
499           //
500           //printf("AliZDCRawStream -> ADCmod. %d ADCch %d det %d, sec %d\n",
501           //  fADCModule,fADCChannel,fSector[0],fSector[1]);
502           
503           if(fADCModule<0 || fADCModule>3){
504             AliWarning(Form("    AliZDCRawStream -> No valid ADC module: %d\n",fADCModule));
505             fRawReader->AddMajorErrorLog(kInvalidADCModule);
506           }
507
508         }//No underflow nor overflow    
509       }//ADC data word
510       // *** ADC EOB
511       else if((fBuffer & 0x07000000) == 0x04000000){
512         fIsADCEOB = kTRUE;
513         //printf("  AliZDCRawStream -> EOB --------------------------\n");
514       }
515      }//ADC module
516         
517     
518   }
519   fPosition++;
520
521   return kTRUE;
522 }