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