]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0RawReader.cxx
f146111ef6353eeb4f7ea9c0be2fa45923157834
[u/mrichter/AliRoot.git] / T0 / AliT0RawReader.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 // T0 
21 // Class for reading T0 RAW data in TOF data format
22 // Alla.Maevskaya@cern.ch
23 //
24 //____________________________________________________________________
25
26 #include "AliT0RawReader.h"
27 #include "AliT0Parameters.h"
28 #include "AliBitPacking.h"
29 #include "TBits.h"
30
31 //#include <Riostream.h>
32 #include "AliLog.h"
33  
34 ClassImp(AliT0RawReader)
35   
36   AliT0RawReader::AliT0RawReader (AliRawReader *rawReader, Bool_t isOnline)
37     :  TTask("T0RawReader","read raw T0 data"),
38        fRawReader(rawReader),
39        fData(NULL),
40        fPosition(0),
41        fParam(NULL),
42        fIsOnline(isOnline)
43 {
44   //
45 // create an object to read T0raw digits
46   AliDebug(1,"Start ");
47  
48   fRawReader->Reset();
49   fRawReader->Select("T0");
50   fParam = AliT0Parameters::Instance();  
51   if (fIsOnline)
52     fParam->InitIfOnline();
53   else 
54     fParam->Init();
55  
56 }
57  AliT0RawReader::~AliT0RawReader ()
58 {
59   // 
60 }
61
62
63 Bool_t  AliT0RawReader::Next()
64 {
65 // read the next raw digit
66 // returns kFALSE if there is no digit left
67 //"LookUpTable":
68 // Amplitude LED TRM=0; chain=0; TDC 0 -5        channel 0,2,4,6
69 // Time CFD      TRM=0; chain=0; TDC 6 - 11      channel 0,2,4,6
70 // mean time     TRM=0; chain=0; TDC 12          channel 0
71 // T0A           TRM=0; chain=0; TDC 12          channel 2
72 // T0C           TRM=0; chain=0; TDC 12          channel 4
73 // vertex        TRM=0; chain=0; TDC 12          channel 6
74 // mult QTC0        TRM=0; chain=0; TDC 13          channel 0
75 // mult QTC1        TRM=0; chain=0; TDC 13          channel 2
76
77 // Charge QTC0   TRM=1; chain=0; TDC 0 -5        channel 0,2,4,6
78 // Charge QTC1   TRM=1; chain=0; TDC 6 - 11      channel 0,2,4,6
79 // T0A trigger          TRM=1; chain=0; TDC 12          channel 0
80 // T0C trigger          TRM=1; chain=0; TDC 12          channel 2
81 // vertex trigger       TRM=1; chain=0; TDC 12          channel 4
82 // trigger central      TRM=1; chain=0; TDC 13          channel 0
83 // tigger semicenral    TRM=1; chain=0; TDC 13          channel 2
84 //
85 // allData array collect data from all channels in one :
86 // allData[0] - allData[23] 24 CFD channels
87 // allData[24] -   allData[47] 24 LED channels
88 //  allData[48]  mean (T0) signal  
89 // allData[49]   time difference (vertex)
90
91  
92   UInt_t word;
93   Int_t time=0,  itdc=0, ichannel=0, uu; 
94   Int_t numberOfWordsInTRM=0, iTRM=0;
95   Int_t tdcTime, koef,hit=0;
96   Int_t koefhits[110];
97   Int_t trmChainHeader =  0x00000000;
98   Int_t  trmChainTrailer =  0x10000000;
99   
100   Int_t  filler =  0x70000000;
101   Bool_t correct=kTRUE;
102   Int_t header;
103
104    Int_t fNTRM = fParam->GetNumberOfTRMs();
105    for ( Int_t k=0; k<110; k++) {
106     koefhits[k]=0;
107     for ( Int_t jj=0; jj<5; jj++) {
108       fAllData[k][jj]=0;
109      }
110    }
111     do {
112       if (!fRawReader->ReadNextData(fData)) return kFALSE;
113     } while (fRawReader->GetDataSize() == 0);
114     
115     fPosition = 0;
116     //    cout.setf( ios_base::hex, ios_base::basefield );
117     
118     //DRM header
119     for (Int_t i=0; i<6; i++) {
120       word = GetNextWord();
121       if(i==0 &&  AliBitPacking::UnpackWord(word,4,20) ==7) fNTRM=0;
122       //      cout<<" DRM header "<<word<<endl;
123       header = AliBitPacking::UnpackWord(word,28,31);
124       if( header !=4 )
125         {
126           AliWarning(Form(" !!!! wrong  DRM header  %x!!!!", word));
127           fRawReader->AddFatalErrorLog(kWrongDRMHeader,Form("w=%x",word));
128           break;
129         }
130     }
131     // cout<<" nTRMs "<<fNTRM<<endl;
132       for (Int_t ntrm=0; ntrm< fNTRM; ntrm++)
133       {
134         //TRMheader  
135         word = GetNextWord();
136         header = AliBitPacking::UnpackWord(word,28,31);
137         Int_t event = AliBitPacking::UnpackWord(word,4,15);
138         //      cout<<" TRM header "<<word<<" event "<<event<<endl;
139         if ( header != 4 )
140           {
141             AliWarning(Form(" !!!! wrong TRM header  %x!!!!", word));
142             fRawReader->AddMajorErrorLog(kWrongTRMHeader,Form("w=%x",word));
143             break;
144           }
145         numberOfWordsInTRM=AliBitPacking::UnpackWord(word,4,16);
146         //cout<<" numberOfWordsInTRM "<<numberOfWordsInTRM<<endl;
147         iTRM=AliBitPacking::UnpackWord(word,0,3);
148         for( Int_t ichain=0; ichain<2; ichain++)
149           {
150             //chain header
151             word = GetNextWord();
152             //  cout<<" chain header "<<word<<endl;
153             uu = word & trmChainHeader;
154             if(uu != trmChainHeader) 
155               {
156                 AliWarning(Form(" !!!! wrong CHAIN  0  header %x!!!!", word));
157                 fRawReader->AddMajorErrorLog(kWrongChain0Header,Form("w=%x",word));
158                 break;
159               }
160             word = GetNextWord();
161             // cout<<" next "<<word<<endl;
162             tdcTime =  AliBitPacking::UnpackWord(word,31,31);   
163             while(tdcTime==1)
164               {
165                 //                      cout<<" packed "<<word<<endl;
166                 itdc=AliBitPacking::UnpackWord(word,24,27);
167                 ichannel=AliBitPacking::UnpackWord(word,21,23);
168                 time=AliBitPacking::UnpackWord(word,0,20);
169                 
170                 koef = fParam->GetChannel(iTRM,itdc,ichain,ichannel);
171                 if (koef != 0 ) 
172                   //              cout<<"RawReader>> "<<"koef "<<koef<<" trm "<<iTRM<<
173                   //                " tdc "<<itdc<<" chain "<<ichain<<
174                   //                " channel "<<ichannel<<" time "<<time<<endl;
175                 if (koef ==-1 ){
176                   AliWarning(Form("Incorrect lookup table ! "));
177                   fRawReader->AddMajorErrorLog(kIncorrectLUT);
178                   correct=kFALSE;
179                 }
180                 if(correct){
181                   hit=koefhits[koef];
182                   if(hit>5) {  
183                     AliWarning(Form("Too many hits for %i channel  ! ",koef)); 
184                     break; 
185                   }
186                   fAllData[koef][hit]=time; 
187                   koefhits[koef]++;
188                 }
189                 word = GetNextWord();
190                 //              cout<<" next word in cycle "<<word<<endl;
191                 tdcTime =  AliBitPacking::UnpackWord(word,31,31);   
192                 
193               }
194             
195             // cout<<" chain trailer "<<word<<endl;
196             uu = word&trmChainTrailer;
197             if(uu != trmChainTrailer )
198               {
199                 AliWarning(Form(" !!!! wrong CHAIN 0 trailer %x !!!!", word));
200                 fRawReader->AddMajorErrorLog(kWrongChain0Trailer,Form("w=%x",word));
201                 break;
202               }
203           }
204             
205         word = GetNextWord(); //TRM trailer
206         //      cout<<" TRM trailer "<<word<<endl;
207         header = AliBitPacking::UnpackWord(word,28,31);
208         if( header !=5 )
209           {
210             AliWarning(Form(" !!!! wrong TRM GLOBAL trailer  %x!!!!", word));
211             fRawReader->AddMajorErrorLog(kWrongTRMTrailer,Form("w=%x",word));
212             break;
213           }
214       } //TRM loop
215     word = GetNextWord(); //
216     // cout<<" after TRM trailer "<<word<<endl;
217     if (word == filler )  word = GetNextWord(); 
218      header = AliBitPacking::UnpackWord(word,28,31);
219      if( header !=5 )
220        {
221          AliWarning(Form(" !!!! wrong DRM GLOBAL trailer  %x!!!!", word));
222          fRawReader->AddFatalErrorLog(kWrongDRMTrailer,Form("w=%x",word));
223       }
224      // cout.setf( ios_base::dec, ios_base::basefield );
225          
226      return kTRUE;
227 }
228 //_____________________________________________________________________________
229 Int_t AliT0RawReader::GetPosition()
230 {
231   // Sets the position in the
232   // input stream
233   if (((fRawReader->GetDataSize() * 8) % 32) != 0)
234     AliFatal(Form("Incorrect raw data size ! %d words are found !",fRawReader->GetDataSize()));
235   return (fRawReader->GetDataSize() * 8) / 32;
236 }
237 //_____________________________________________________________________________
238 UInt_t AliT0RawReader::GetNextWord()
239 {
240   // Read the next 32 bit word in backward direction
241   // The input stream access is given by fData and fPosition
242
243
244   //   fPosition--;
245   Int_t iBit = fPosition * 32;
246   Int_t iByte = iBit / 8;
247
248   UInt_t word = 0;
249   word  = fData[iByte+3]<<24;
250   word |= fData[iByte+2]<<16;
251   word |= fData[iByte+1]<<8;
252   word |= fData[iByte];
253    fPosition++;
254
255   return word;
256
257 }
258