]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - T0/AliT0RawReader.cxx
improve libgfortran detection (like is done for ROOT now).
[u/mrichter/AliRoot.git] / T0 / AliT0RawReader.cxx
... / ...
CommitLineData
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
34ClassImp(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
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
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 // cout<<" DRM header "<<word<<endl;
122 header = AliBitPacking::UnpackWord(word,28,31);
123 if( header !=4 )
124 {
125 AliWarning(Form(" !!!! wrong DRM header %x!!!!", word));
126 fRawReader->AddFatalErrorLog(kWrongDRMHeader,Form("w=%x",word));
127 break;
128 }
129 }
130 for (Int_t ntrm=0; ntrm< fNTRM; ntrm++)
131 {
132 //TRMheader
133 word = GetNextWord();
134 header = AliBitPacking::UnpackWord(word,28,31);
135 // cout<<" TRM header "<<word<<endl;
136 if ( header != 4 )
137 {
138 AliWarning(Form(" !!!! wrong TRM header %x!!!!", word));
139 fRawReader->AddMajorErrorLog(kWrongTRMHeader,Form("w=%x",word));
140 break;
141 }
142 numberOfWordsInTRM=AliBitPacking::UnpackWord(word,4,16);
143 // cout<<" numberOfWordsInTRM "<<numberOfWordsInTRM<<endl;
144 iTRM=AliBitPacking::UnpackWord(word,0,3);
145 for( Int_t ichain=0; ichain<2; ichain++)
146 {
147 //chain header
148 word = GetNextWord();
149 // cout<<" chain header "<<word<<endl;
150 uu = word & trmChainHeader;
151 if(uu != trmChainHeader)
152 {
153 AliWarning(Form(" !!!! wrong CHAIN 0 header %x!!!!", word));
154 fRawReader->AddMajorErrorLog(kWrongChain0Header,Form("w=%x",word));
155 break;
156 }
157 word = GetNextWord();
158// cout<<" next "<<word<<endl;
159 tdcTime = AliBitPacking::UnpackWord(word,31,31);
160 while(tdcTime==1)
161 {
162 // cout<<" packed "<<word<<endl;
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);
168 if (koef != 0 )
169 // cout<<"RawReader>> "<<"koef "<<koef<<" trm "<<iTRM<<
170 // " tdc "<<itdc<<" chain "<<ichain<<
171 // " channel "<<ichannel<<" time "<<time<<endl;
172 if (koef ==-1 ){
173 AliWarning(Form("Incorrect lookup table ! "));
174 fRawReader->AddMajorErrorLog(kIncorrectLUT);
175 correct=kFALSE;
176 }
177 if(correct){
178 hit=koefhits[koef];
179 if(hit>5) {
180 AliWarning(Form("Too many hits for %i channel ! ",koef));
181 break;
182 }
183 fAllData[koef][hit]=time;
184 koefhits[koef]++;
185 }
186 word = GetNextWord();
187 // cout<<" next word in cycle "<<word<<endl;
188 tdcTime = AliBitPacking::UnpackWord(word,31,31);
189
190 }
191
192 // cout<<" chain trailer "<<word<<endl;
193 uu = word&trmChainTrailer;
194 if(uu != trmChainTrailer )
195 {
196 AliWarning(Form(" !!!! wrong CHAIN 0 trailer %x !!!!", word));
197 fRawReader->AddMajorErrorLog(kWrongChain0Trailer,Form("w=%x",word));
198 break;
199 }
200 }
201
202 word = GetNextWord(); //TRM trailer
203 // cout<<" TRM trailer "<<word<<endl;
204 header = AliBitPacking::UnpackWord(word,28,31);
205 if( header !=5 )
206 {
207 AliWarning(Form(" !!!! wrong TRM GLOBAL trailer %x!!!!", word));
208 fRawReader->AddMajorErrorLog(kWrongTRMTrailer,Form("w=%x",word));
209 break;
210 }
211 } //TRM loop
212 word = GetNextWord(); //
213 // cout<<" after TRM trailer "<<word<<endl;
214 if (word == filler ) word = GetNextWord();
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));
220 }
221 // cout.setf( ios_base::dec, ios_base::basefield );
222
223 return kTRUE;
224}
225//_____________________________________________________________________________
226Int_t AliT0RawReader::GetPosition()
227{
228 // Sets the position in the
229 // input stream
230 if (((fRawReader->GetDataSize() * 8) % 32) != 0)
231 AliFatal(Form("Incorrect raw data size ! %d words are found !",fRawReader->GetDataSize()));
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