violations 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
94249139 22// Alla.Maevskaya@cern.ch
f16935f7 23//
94249139 24//____________________________________________________________________
25
dc7ca31d 26#include "AliT0RawReader.h"
e0bba6cc 27#include "AliT0Parameters.h"
dc7ca31d 28#include "AliBitPacking.h"
29#include "TBits.h"
30
94249139 31//#include <Riostream.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),
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
dc7ca31d 62
63Bool_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
e0bba6cc 91
dc7ca31d 92 UInt_t word;
5325480c 93 Int_t time=0, itdc=0, ichannel=0, uu;
dc7ca31d 94 Int_t numberOfWordsInTRM=0, iTRM=0;
5325480c 95 Int_t tdcTime, koef,hit=0;
96 Int_t koefhits[110];
94249139 97 Int_t trmChainHeader = 0x00000000;
98 Int_t trmChainTrailer = 0x10000000;
807a797f 99
f16935f7 100 Int_t filler = 0x70000000;
807a797f 101 Bool_t correct=kTRUE;
102 Int_t header;
4a6b40d0 103
f8bea420 104 Int_t fNTRM = fParam->GetNumberOfTRMs();
f8bea420 105 for ( Int_t k=0; k<110; k++) {
807a797f 106 koefhits[k]=0;
107 for ( Int_t jj=0; jj<5; jj++) {
108 fAllData[k][jj]=0;
f8bea420 109 }
110 }
e0bba6cc 111 do {
807a797f 112 if (!fRawReader->ReadNextData(fData)) return kFALSE;
113 } while (fRawReader->GetDataSize() == 0);
114
807a797f 115 fPosition = 0;
94249139 116 // cout.setf( ios_base::hex, ios_base::basefield );
807a797f 117
118 //DRM header
5325480c 119 for (Int_t i=0; i<6; i++) {
120 word = GetNextWord();
f16935f7 121 // cout<<" DRM header "<<word<<endl;
807a797f 122 header = AliBitPacking::UnpackWord(word,28,31);
123 if( header !=4 )
5325480c 124 {
29d3e0eb 125 AliWarning(Form(" !!!! wrong DRM header %x!!!!", word));
126 fRawReader->AddFatalErrorLog(kWrongDRMHeader,Form("w=%x",word));
5325480c 127 break;
807a797f 128 }
5325480c 129 }
94249139 130 for (Int_t ntrm=0; ntrm< fNTRM; ntrm++)
807a797f 131 {
132 //TRMheader
133 word = GetNextWord();
29d3e0eb 134 header = AliBitPacking::UnpackWord(word,28,31);
f16935f7 135 // cout<<" TRM header "<<word<<endl;
29d3e0eb 136 if ( header != 4 )
137 {
138 AliWarning(Form(" !!!! wrong TRM header %x!!!!", word));
139 fRawReader->AddMajorErrorLog(kWrongTRMHeader,Form("w=%x",word));
140 break;
141 }
807a797f 142 numberOfWordsInTRM=AliBitPacking::UnpackWord(word,4,16);
f16935f7 143 // cout<<" numberOfWordsInTRM "<<numberOfWordsInTRM<<endl;
807a797f 144 iTRM=AliBitPacking::UnpackWord(word,0,3);
807a797f 145 for( Int_t ichain=0; ichain<2; ichain++)
c41ceaac 146 {
807a797f 147 //chain header
148 word = GetNextWord();
f16935f7 149 // cout<<" chain header "<<word<<endl;
94249139 150 uu = word & trmChainHeader;
151 if(uu != trmChainHeader)
807a797f 152 {
29d3e0eb 153 AliWarning(Form(" !!!! wrong CHAIN 0 header %x!!!!", word));
154 fRawReader->AddMajorErrorLog(kWrongChain0Header,Form("w=%x",word));
807a797f 155 break;
156 }
157 word = GetNextWord();
d8079a1a 158// cout<<" next "<<word<<endl;
807a797f 159 tdcTime = AliBitPacking::UnpackWord(word,31,31);
f16935f7 160 while(tdcTime==1)
807a797f 161 {
f16935f7 162 // cout<<" packed "<<word<<endl;
807a797f 163 itdc=AliBitPacking::UnpackWord(word,24,27);
164 ichannel=AliBitPacking::UnpackWord(word,21,23);
165 time=AliBitPacking::UnpackWord(word,0,20);
166
167 koef = fParam->GetChannel(iTRM,itdc,ichain,ichannel);
f16935f7 168 if (koef != 0 )
169 // cout<<"RawReader>> "<<"koef "<<koef<<" trm "<<iTRM<<
170 // " tdc "<<itdc<<" chain "<<ichain<<
171 // " channel "<<ichannel<<" time "<<time<<endl;
807a797f 172 if (koef ==-1 ){
29d3e0eb 173 AliWarning(Form("Incorrect lookup table ! "));
174 fRawReader->AddMajorErrorLog(kIncorrectLUT);
807a797f 175 correct=kFALSE;
176 }
177 if(correct){
178 hit=koefhits[koef];
c1469fdf 179 if(hit>5) {
180 AliWarning(Form("Too many hits for %i channel ! ",koef));
181 break;
182 }
807a797f 183 fAllData[koef][hit]=time;
184 koefhits[koef]++;
185 }
f16935f7 186 word = GetNextWord();
187 // cout<<" next word in cycle "<<word<<endl;
188 tdcTime = AliBitPacking::UnpackWord(word,31,31);
807a797f 189
f16935f7 190 }
c41ceaac 191
f16935f7 192 // cout<<" chain trailer "<<word<<endl;
94249139 193 uu = word&trmChainTrailer;
194 if(uu != trmChainTrailer )
807a797f 195 {
29d3e0eb 196 AliWarning(Form(" !!!! wrong CHAIN 0 trailer %x !!!!", word));
f16935f7 197 fRawReader->AddMajorErrorLog(kWrongChain0Trailer,Form("w=%x",word));
807a797f 198 break;
199 }
200 }
201
202 word = GetNextWord(); //TRM trailer
f16935f7 203 // cout<<" TRM trailer "<<word<<endl;
807a797f 204 header = AliBitPacking::UnpackWord(word,28,31);
205 if( header !=5 )
206 {
29d3e0eb 207 AliWarning(Form(" !!!! wrong TRM GLOBAL trailer %x!!!!", word));
208 fRawReader->AddMajorErrorLog(kWrongTRMTrailer,Form("w=%x",word));
807a797f 209 break;
210 }
211 } //TRM loop
212 word = GetNextWord(); //
f16935f7 213 // cout<<" after TRM trailer "<<word<<endl;
214 if (word == filler ) word = GetNextWord();
21ab892d 215 header = AliBitPacking::UnpackWord(word,28,31);
216 if( header !=5 )
217 {
218 AliWarning(Form(" !!!! wrong DRM GLOBAL trailer %x!!!!", word));
219 fRawReader->AddFatalErrorLog(kWrongDRMTrailer,Form("w=%x",word));
807a797f 220 }
94249139 221 // cout.setf( ios_base::dec, ios_base::basefield );
222
21ab892d 223 return kTRUE;
dc7ca31d 224}
225//_____________________________________________________________________________
dc7ca31d 226Int_t AliT0RawReader::GetPosition()
227{
228 // Sets the position in the
229 // input stream
807a797f 230 if (((fRawReader->GetDataSize() * 8) % 32) != 0)
231 AliFatal(Form("Incorrect raw data size ! %d words are found !",fRawReader->GetDataSize()));
dc7ca31d 232 return (fRawReader->GetDataSize() * 8) / 32;
233}
234//_____________________________________________________________________________
235UInt_t AliT0RawReader::GetNextWord()
236{
237 // Read the next 32 bit word in backward direction
238 // The input stream access is given by fData and fPosition
239
240
241 // fPosition--;
242 Int_t iBit = fPosition * 32;
243 Int_t iByte = iBit / 8;
244
245 UInt_t word = 0;
246 word = fData[iByte+3]<<24;
247 word |= fData[iByte+2]<<16;
248 word |= fData[iByte+1]<<8;
249 word |= fData[iByte];
250 fPosition++;
251
252 return word;
253
254}
255