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