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