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