]>
Commit | Line | Data |
---|---|---|
a6c02c85 | 1 | // @(#) $Id$ |
2 | ||
3 | // Author: C. Loizides <loizides@ikf.uni-frankfurt.de> | |
4 | //*-- Copyright © ALICE HLT Group | |
5 | ||
6 | #include "AliHLTTPCStandardIncludes.h" | |
7 | ||
8 | #include "AliHLTTPCRootTypes.h" | |
9 | #include "AliHLTTPCLogging.h" | |
10 | #include "AliHLTTPCTransform.h" | |
11 | #include "AliHLTTPCMemHandler.h" | |
12 | #include "AliHLTTPCDigitData.h" | |
13 | #ifdef use_newio | |
14 | #include "AliRawReaderRoot.h" | |
15 | #include "AliRawReaderDate.h" | |
16 | #else | |
17 | #include "AliHLTTPCDDLTPCRawStream.h" | |
18 | #include "AliHLTTPCDDLRawReaderFile.h" | |
19 | #endif | |
20 | #include "AliHLTTPCDDLDataFileHandler.h" | |
21 | ||
22 | #if __GNUC__ == 3 | |
23 | using namespace std; | |
24 | #endif | |
25 | ||
26 | /** \class AliHLTTPCDDLDataFileHandler | |
27 | <pre> | |
28 | //_____________________________________________________________ | |
29 | // AliHLTTPCDDLDataFileHandler | |
30 | // | |
31 | // This class does converts from the DDL format of offline | |
32 | // into the memory I/O handling of the HLT binary files. | |
33 | // | |
34 | // Examples: see ddl2binary in exa and the general | |
35 | // AliHLTTPCMemHandler class description | |
36 | // | |
37 | </pre> | |
38 | */ | |
39 | ||
40 | ClassImp(AliHLTTPCDDLDataFileHandler) | |
41 | ||
42 | AliHLTTPCDDLDataFileHandler::AliHLTTPCDDLDataFileHandler() | |
43 | { | |
44 | // default constructor | |
45 | fReader=0; | |
46 | fTPCStream=0; | |
47 | } | |
48 | ||
49 | AliHLTTPCDDLDataFileHandler::~AliHLTTPCDDLDataFileHandler() | |
50 | { | |
51 | // destructor | |
52 | FreeAll(); | |
53 | } | |
54 | ||
55 | void AliHLTTPCDDLDataFileHandler::FreeAll() | |
56 | { | |
57 | // frees all heap memory | |
58 | if(fReader) delete fReader; | |
59 | fReader = 0; | |
60 | if(fTPCStream) delete fTPCStream; | |
61 | fTPCStream = 0; | |
62 | } | |
63 | ||
64 | ||
65 | #ifdef use_newio | |
66 | Bool_t AliHLTTPCDDLDataFileHandler::SetReaderInput(AliRawEvent *rawevent) | |
67 | { | |
68 | // sets the input of the reader | |
69 | fEvent=-1; | |
70 | fFilename=""; | |
71 | if(fReader) delete fReader; | |
72 | fReader=new AliRawReaderRoot(rawevent); | |
73 | if(fTPCStream) delete fTPCStream; | |
74 | fTPCStream=new AliTPCRawStream(fReader); | |
75 | ||
76 | return kTRUE; | |
77 | } | |
78 | ||
79 | Bool_t AliHLTTPCDDLDataFileHandler::SetReaderInput(Char_t *name,Int_t event) | |
80 | { | |
81 | // sets the input of the reader | |
82 | fEvent=event; | |
83 | if(fReader) delete fReader; | |
84 | if(fTPCStream) delete fTPCStream; | |
85 | if(event>=0){ | |
86 | fFilename=name; | |
87 | fReader=new AliRawReaderRoot(name,event); | |
88 | } else { | |
89 | fFilename=""; | |
90 | fReader=new AliRawReaderDate((void *)name); | |
91 | } | |
92 | fTPCStream=new AliTPCRawStream(fReader); | |
93 | ||
94 | return kTRUE; | |
95 | } | |
96 | #else | |
97 | Bool_t AliHLTTPCDDLDataFileHandler::SetReaderInput(Char_t *name, Bool_t add) | |
98 | { | |
99 | // sets the input of the reader | |
100 | if(fReader){ | |
101 | LOG(AliHLTTPCLog::kError,"AliHLTTPCDDLDataFileHandler::SetReaderInput","File Open") | |
102 | <<"Reader ptr is already in use"<<ENDLOG; | |
103 | return kFALSE; | |
104 | } | |
105 | ||
106 | fReader=new AliHLTTPCDDLRawReaderFile(name,add); | |
107 | fTPCStream=new AliHLTTPCDDLTPCRawStream(fReader); | |
108 | ||
109 | return kTRUE; | |
110 | } | |
111 | Bool_t AliHLTTPCDDLDataFileHandler::SetReaderInput(AliHLTTPCDDLRawReaderFile *rf) | |
112 | { | |
113 | // sets the input of the reader | |
114 | if(fReader){ | |
115 | LOG(AliHLTTPCLog::kError,"AliHLTTPCRawDataFileHandler::SetReaderInput","File Open") | |
116 | <<"Reader ptr is already in use, delete it first"<<ENDLOG; | |
117 | return kFALSE; | |
118 | } | |
119 | ||
120 | //Open the raw data file with given file. | |
121 | fReader = rf; | |
122 | fTPCStream=new AliHLTTPCDDLTPCRawStream(fReader); | |
123 | ||
124 | return kTRUE; | |
125 | } | |
126 | #endif | |
127 | ||
128 | void AliHLTTPCDDLDataFileHandler::CloseReaderInput() | |
129 | { | |
130 | // closes the input of the reader | |
131 | if(!fReader){ | |
132 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCRawDataFileHandler::CloseReaderInput","File Close") | |
133 | <<"Nothing to Close"<<ENDLOG; | |
134 | return; | |
135 | } | |
136 | ||
137 | delete fReader; | |
138 | delete fTPCStream; | |
139 | fReader = 0; | |
140 | fTPCStream = 0; | |
141 | } | |
142 | ||
143 | #ifdef use_newio | |
144 | Bool_t AliHLTTPCDDLDataFileHandler::IsDigit(Int_t /*i*/) const | |
145 | { | |
146 | // dummy | |
147 | return kTRUE; | |
148 | } | |
149 | #endif | |
150 | ||
151 | #ifndef fast_raw | |
152 | AliHLTTPCDigitRowData * AliHLTTPCDDLDataFileHandler::DDLData2Memory(UInt_t &nrow,Int_t event) | |
153 | { | |
154 | // transfers the DDL data to the memory | |
155 | #ifdef use_newio | |
156 | if((fEvent>=0)&&(event!=fEvent)){ | |
157 | fEvent=event; | |
158 | if(fReader) delete fReader; | |
159 | if(fTPCStream) delete fTPCStream; | |
160 | fReader=new AliRawReaderRoot(fFilename,event); | |
161 | fTPCStream=new AliTPCRawStream(fReader); | |
162 | } | |
163 | #endif | |
164 | AliHLTTPCDigitRowData *data = 0; | |
165 | nrow=0; | |
166 | ||
167 | if(!fReader){ | |
168 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCDDLDataFileHandler::DDLData2Memory","File") | |
169 | <<"No Input avalible: no object AliHLTTPCDDLRawReaderFile"<<ENDLOG; | |
170 | return 0; | |
171 | } | |
172 | ||
173 | Int_t nrows=fRowMax-fRowMin+1; | |
174 | Int_t ndigitcount=0; | |
175 | Int_t * ndigits = new Int_t[nrows]; | |
176 | UShort_t ***charges=new UShort_t**[nrows]; | |
177 | for(Int_t r=fRowMin;r<=fRowMax;r++){ | |
178 | Int_t lrow=r-fRowMin; | |
179 | charges[lrow]=new UShort_t*[AliHLTTPCTransform::GetNPads(r)]; | |
180 | for(Int_t k=0;k<AliHLTTPCTransform::GetNPads(r);k++){ | |
181 | charges[lrow][k]=new UShort_t[AliHLTTPCTransform::GetNTimeBins()]; | |
182 | for(Int_t j=0;j<AliHLTTPCTransform::GetNTimeBins();j++) charges[lrow][k][j]=0; | |
183 | } | |
184 | } | |
185 | ||
186 | Int_t ddlsToSearch=0; | |
187 | Int_t ddls[9]={-1,-1,-1,-1,-1,-1,-1,-1,-1}; | |
188 | Int_t ddlid=-1,lddlid=-1; | |
189 | for(Int_t r=fRowMin;r<=fRowMax;r++){ | |
190 | ndigits[r-fRowMin] = 0; //now digits on row | |
191 | ||
192 | Int_t patch=AliHLTTPCTransform::GetPatch(r); | |
193 | Int_t sector,row; | |
194 | AliHLTTPCTransform::Slice2Sector(fSlice,r,sector,row); | |
195 | ||
196 | if(sector<36) //taken from AliTPCBuffer160.cxx | |
197 | ddlid=sector*2+patch; | |
198 | else | |
199 | ddlid=70+(sector-36)*4+patch; | |
200 | ||
201 | if((lddlid!=ddlid-1)&&(r==30)){ //dont forget the split row on the last ddl | |
202 | ddls[ddlsToSearch++]=ddlid-1; | |
203 | lddlid=ddlid-1; | |
204 | } | |
205 | ||
206 | if((lddlid==-1)||(ddlid!=lddlid)){ | |
207 | ddls[ddlsToSearch++]=ddlid; | |
208 | lddlid=ddlid; | |
209 | } | |
210 | if((r==90)||(r==139)){ //dont forget the split row on the next ddl | |
211 | ddls[ddlsToSearch++]=ddlid+1; | |
212 | lddlid=ddlid+1; | |
213 | } | |
214 | } | |
215 | ||
216 | // for(Int_t i=0;i<ddlsToSearch;i++) cout << ddls[i] <<endl; | |
217 | ||
218 | if(ddls[0]>ddls[ddlsToSearch-1]) { | |
219 | Int_t tempddl = ddls[0]; | |
220 | ddls[0] = ddls[ddlsToSearch-1]; | |
221 | ddls[ddlsToSearch-1] = tempddl; | |
222 | } | |
223 | #ifdef use_newio | |
224 | fReader->Reset(); | |
225 | fReader->Select(0,ddls[0],ddls[ddlsToSearch-1]); | |
226 | fTPCStream->Reset(); | |
227 | #else | |
228 | fTPCStream->SetDDLID(ddls[i]); //ddl to read out | |
229 | #endif | |
230 | Int_t zerosup = AliHLTTPCTransform::GetZeroSup(); | |
231 | Int_t adcsat = AliHLTTPCTransform::GetADCSat(); | |
232 | Int_t slice,srow; | |
233 | Int_t lrow=-1; | |
234 | ||
235 | while (fTPCStream->Next()){ | |
236 | ||
237 | if(fTPCStream->IsNewSector() || fTPCStream->IsNewRow()) { | |
238 | Int_t sector=fTPCStream->GetSector(); | |
239 | Int_t row=fTPCStream->GetRow(); | |
240 | AliHLTTPCTransform::Sector2Slice(slice,srow,sector,row); | |
241 | if(slice!=fSlice){ | |
242 | LOG(AliHLTTPCLog::kError,"AliHLTTPCDDLDataFileHandler::DDLDigits2Memory","Slice") | |
243 | <<AliHLTTPCLog::kDec<<"Found slice "<<slice<<", expected "<<fSlice<<ENDLOG; | |
244 | continue; | |
245 | } | |
246 | lrow=srow-fRowMin; | |
247 | } | |
248 | ||
249 | //test row criteria (patch boundaries) | |
250 | if((srow<fRowMin)||(srow>fRowMax))continue; | |
251 | ||
252 | Int_t pad=fTPCStream->GetPad(); | |
253 | if(fTPCStream->IsNewPad()) { | |
254 | if((pad<0)||(pad>=AliHLTTPCTransform::GetNPads(srow))){ | |
255 | LOG(AliHLTTPCLog::kError,"AliHLTTPCDDLDataFileHandler::DDLDigits2Memory","Pad") | |
256 | <<AliHLTTPCLog::kDec<<"Pad value out of bounds "<<pad<<" " | |
257 | <<AliHLTTPCTransform::GetNPads(srow)<<ENDLOG; | |
258 | continue; | |
259 | } | |
260 | } | |
261 | ||
262 | Int_t time=fTPCStream->GetTime(); | |
263 | if((time<0)||(time>=AliHLTTPCTransform::GetNTimeBins())){ | |
264 | LOG(AliHLTTPCLog::kError,"AliHLTTPCDDLDataFileHandler::DDLDigits2Memory","Time") | |
265 | <<AliHLTTPCLog::kDec<<"Time out of bounds "<<time<<" " | |
266 | <<AliHLTTPCTransform::GetNTimeBins()<<ENDLOG; | |
267 | continue; | |
268 | } | |
269 | ||
270 | //store digit | |
271 | UShort_t dig=fTPCStream->GetSignal(); | |
272 | if(dig <= zerosup) continue; | |
273 | if(dig >= adcsat) dig = adcsat; | |
274 | ||
275 | ndigits[lrow]++; //for this row only | |
276 | ndigitcount++; //total number of digits to be published | |
277 | ||
278 | charges[lrow][pad][time]=dig; | |
279 | } | |
280 | ||
281 | Int_t size = sizeof(AliHLTTPCDigitData)*ndigitcount | |
282 | + nrows*sizeof(AliHLTTPCDigitRowData); | |
283 | ||
284 | LOG(AliHLTTPCLog::kDebug,"AliHLTTPCDDLDataFileHandler::DDLDigits2Memory","Digits") | |
285 | <<AliHLTTPCLog::kDec<<"Found "<<ndigitcount<<" Digits"<<ENDLOG; | |
286 | ||
287 | data=(AliHLTTPCDigitRowData*) Allocate(size); | |
288 | nrow = (UInt_t)nrows; | |
289 | AliHLTTPCDigitRowData *tempPt = data; | |
290 | ||
291 | for(Int_t r=fRowMin;r<=fRowMax;r++){ | |
292 | Int_t lrow=r-fRowMin; | |
293 | tempPt->fRow = r; | |
294 | tempPt->fNDigit = ndigits[lrow]; | |
295 | ||
296 | Int_t localcount=0; | |
297 | for(Int_t pad=0;pad<AliHLTTPCTransform::GetNPads(r);pad++){ | |
298 | for(Int_t time=0;time<AliHLTTPCTransform::GetNTimeBins();time++){ | |
299 | UShort_t dig=charges[lrow][pad][time]; | |
300 | if(!dig) continue; | |
301 | ||
302 | if(localcount >= ndigits[lrow]) | |
303 | LOG(AliHLTTPCLog::kFatal,"AliHLTTPCDDLDataFileHandler::DDLDigits2Binary","Memory") | |
304 | <<AliHLTTPCLog::kDec<<"Mismatch: localcount "<<localcount<<" ndigits " | |
305 | <<ndigits[lrow]<<ENDLOG; | |
306 | ||
307 | ||
308 | tempPt->fDigitData[localcount].fCharge=dig; | |
309 | tempPt->fDigitData[localcount].fPad=pad; | |
310 | tempPt->fDigitData[localcount].fTime=time; | |
311 | #ifdef do_mc | |
312 | tempPt->fDigitData[localcount].fTrackID[0] = 0; | |
313 | tempPt->fDigitData[localcount].fTrackID[1] = 0; | |
314 | tempPt->fDigitData[localcount].fTrackID[2] = 0; | |
315 | #endif | |
316 | localcount++; | |
317 | } | |
318 | } | |
319 | ||
320 | if(localcount != ndigits[lrow]) | |
321 | LOG(AliHLTTPCLog::kFatal,"AliHLTTPCDDLDataFileHandler::DDLDigits2Binary","Memory") | |
322 | <<AliHLTTPCLog::kDec<<"Mismatch: localcount "<<localcount<<" ndigits " | |
323 | <<ndigits[lrow]<<ENDLOG; | |
324 | ||
325 | ||
326 | Byte_t *tmp = (Byte_t*)tempPt; | |
327 | Int_t size = sizeof(AliHLTTPCDigitRowData) | |
328 | + ndigits[lrow]*sizeof(AliHLTTPCDigitData); | |
329 | tmp += size; | |
330 | tempPt = (AliHLTTPCDigitRowData*)tmp; | |
331 | } | |
332 | ||
333 | //delete charge array | |
334 | for(Int_t r=fRowMin;r<=fRowMax;r++){ | |
335 | Int_t lrow=r-fRowMin; | |
336 | for(Int_t k=0;k<AliHLTTPCTransform::GetNPads(r);k++) | |
337 | delete charges[lrow][k]; | |
338 | delete charges[lrow]; | |
339 | } | |
340 | delete charges; | |
341 | delete [] ndigits; | |
342 | ||
343 | return data; | |
344 | } | |
345 | #else | |
346 | AliHLTTPCDigitRowData * AliHLTTPCDDLDataFileHandler::DDLData2Memory(UInt_t &nrow,Int_t event) | |
347 | { | |
348 | // transfers the DDL data to the memory | |
349 | #ifdef use_newio | |
350 | if((fEvent>=0)&&(event!=fEvent)){ | |
351 | fEvent=event; | |
352 | if(fReader) delete fReader; | |
353 | if(fTPCStream) delete fTPCStream; | |
354 | fReader=new AliRawReaderRoot(fFilename,event); | |
355 | fTPCStream=new AliTPCRawStream(fReader); | |
356 | } | |
357 | #endif | |
358 | AliHLTTPCDigitRowData *data = 0; | |
359 | nrow=0; | |
360 | ||
361 | if(!fReader){ | |
362 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCDDLDataFileHandler::DDLData2Memory","File") | |
363 | <<"No Input avalible: no object AliHLTTPCDDLRawReaderFile"<<ENDLOG; | |
364 | return 0; | |
365 | } | |
366 | ||
367 | Int_t nrows=fRowMax-fRowMin+1; | |
368 | ||
369 | Int_t ddlsToSearch=0; | |
370 | Int_t ddls[9]={-1,-1,-1,-1,-1,-1,-1,-1,-1}; | |
371 | Int_t ddlid=-1,lddlid=-1; | |
372 | for(Int_t r=fRowMin;r<=fRowMax;r++){ | |
373 | ||
374 | Int_t patch=AliHLTTPCTransform::GetPatch(r); | |
375 | Int_t sector,row; | |
376 | AliHLTTPCTransform::Slice2Sector(fSlice,r,sector,row); | |
377 | ||
378 | if(sector<36) //taken from AliTPCBuffer160.cxx | |
379 | ddlid=sector*2+patch; | |
380 | else | |
381 | ddlid=70+(sector-36)*4+patch; | |
382 | ||
383 | if((lddlid==-1)||(ddlid!=lddlid)){ | |
384 | ddls[ddlsToSearch++]=ddlid; | |
385 | lddlid=ddlid; | |
386 | } | |
387 | } | |
388 | ||
389 | // for(Int_t i=0;i<ddlsToSearch;i++) cout << ddls[i] <<endl; | |
390 | ||
391 | #ifdef use_newio | |
392 | fReader->Reset(); | |
393 | fReader->Select(0,ddls[0],ddls[ddlsToSearch-1]); | |
394 | fTPCStream->Reset(); | |
395 | #else | |
396 | fTPCStream->SetDDLID(ddls[i]); //ddl to read out | |
397 | #endif | |
398 | ||
399 | nrow = (UInt_t)nrows; | |
400 | ||
401 | return data; | |
402 | } | |
403 | #endif | |
404 | ||
405 | Bool_t AliHLTTPCDDLDataFileHandler::DDLData2CompBinary(Int_t event) | |
406 | { | |
407 | // transfers the DDL data to the memory and converts it | |
408 | // to comp binary | |
409 | Bool_t out = kTRUE; | |
410 | UInt_t ndigits=0; | |
411 | AliHLTTPCDigitRowData *digits=0; | |
412 | digits = DDLData2Memory(ndigits,event); | |
413 | out = Memory2CompBinary(ndigits,digits); | |
414 | Free(); | |
415 | return out; | |
416 | } |