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