]>
Commit | Line | Data |
---|---|---|
3e87ef69 | 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" | |
13 | ||
14 | #include "AliL3RawDataFileHandler.h" | |
15 | ||
16 | #if GCCVERSION == 3 | |
17 | using namespace std; | |
18 | #endif | |
19 | ||
20 | /** \class AliL3RawDataFileHandler | |
21 | <pre> | |
22 | //_____________________________________________________________ | |
23 | // AliL3RawDataFileHandler | |
24 | // | |
25 | </pre> | |
26 | */ | |
27 | ||
28 | ClassImp(AliL3RawDataFileHandler) | |
29 | ||
30 | AliL3RawDataFileHandler::AliL3RawDataFileHandler() | |
31 | { | |
32 | FreeAll(); | |
33 | ||
34 | if((sizeof(Int_t) != 4) || (sizeof(Short_t) != 2)){ | |
35 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::AliL3RawDataFileHandler","Constructor") | |
36 | <<"Check architecture to run the conversion on! Int_t should be 32 and Short_t should be 16 bit."<<ENDLOG; | |
37 | } | |
38 | } | |
39 | ||
40 | AliL3RawDataFileHandler::~AliL3RawDataFileHandler() | |
41 | { | |
42 | FreeAll(); | |
43 | } | |
44 | ||
45 | void AliL3RawDataFileHandler::FreeAll() | |
46 | { | |
47 | if(fInRaw) CloseRawInput(); | |
48 | if(fInRawPed) CloseRawPedestalsInput(); | |
49 | if(fMapping) CloseMappingFile(); | |
50 | if(fNChannels){ | |
51 | delete[] fRow; | |
52 | delete[] fPad; | |
53 | delete[] fRowPad; | |
54 | } | |
55 | if(fPedestals) delete[] fPedestals; | |
56 | if(fOutRaw) CloseRawOutput(); | |
57 | ||
58 | fConvert=kTRUE; | |
59 | fInRaw = 0; | |
60 | fInRawPed = 0; | |
61 | fOutRaw = 0; | |
62 | fMapping = 0; | |
63 | fNChannels=0; | |
64 | fRow=0; | |
65 | fPad=0; | |
66 | fRowPad=0; | |
67 | fRowMinUsed=AliL3Transform::GetNRows(); | |
68 | fRowMaxUsed=0; | |
69 | fPadMinUsed=255; | |
70 | fPadMaxUsed=0; | |
71 | fNTimeBins=0; | |
72 | for(Int_t i=0;i<AliL3Transform::GetNRows();i++) fNPads[i]=0; | |
73 | fPedVal=0; | |
74 | fPedestals=0; | |
75 | } | |
76 | ||
77 | Bool_t AliL3RawDataFileHandler::SetRawInput(Char_t *name) | |
78 | { | |
79 | if(fInRaw){ | |
80 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::SetRawInput","File Open") | |
81 | <<"File ptr is already in use, close file first"<<ENDLOG; | |
82 | return kFALSE; | |
83 | } | |
84 | ||
85 | //Open the raw data file with name. | |
86 | fInRaw = new ifstream(); | |
87 | fInRaw->open(name,fstream::binary); | |
88 | ||
89 | if(!fInRaw->is_open()){ | |
90 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::SetRawInput","File Open") | |
91 | <<"Pointer to ifstream = 0x0"<<ENDLOG; | |
92 | return kFALSE; | |
93 | } | |
94 | ||
95 | return kTRUE; | |
96 | } | |
97 | ||
98 | Bool_t AliL3RawDataFileHandler::SetRawInput(ifstream *file) | |
99 | { | |
100 | if(fInRaw){ | |
101 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::SetRawInput","File Open") | |
102 | <<"File ptr is already in use, close file first"<<ENDLOG; | |
103 | return kFALSE; | |
104 | } | |
105 | ||
106 | //Open the raw data file with given file. | |
107 | fInRaw = file; | |
108 | ||
109 | if(!fInRaw->is_open()){ | |
110 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::SetRawInput","File Open") | |
111 | <<"Pointer to ifstream = 0x0"<<ENDLOG; | |
112 | return kFALSE; | |
113 | } | |
114 | ||
115 | return kTRUE; | |
116 | } | |
117 | ||
118 | void AliL3RawDataFileHandler::CloseRawInput() | |
119 | { | |
120 | if(!fInRaw){ | |
121 | LOG(AliL3Log::kWarning,"AliL3RawDataFileHandler::CloseRawInput","File Close") | |
122 | <<"Nothing to Close"<<ENDLOG; | |
123 | return; | |
124 | } | |
125 | if(fInRaw->is_open()) fInRaw->close(); | |
126 | delete fInRaw; | |
127 | fInRaw = 0; | |
128 | } | |
129 | ||
130 | Bool_t AliL3RawDataFileHandler::SetRawOutput(Char_t *name) | |
131 | { | |
132 | if(fOutRaw){ | |
133 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::SetRawOutput","File Open") | |
134 | <<"File ptr is already in use, close file first"<<ENDLOG; | |
135 | return kFALSE; | |
136 | } | |
137 | ||
138 | fOutRaw = new ofstream(); | |
139 | fOutRaw->open(name,fstream::binary); | |
140 | ||
141 | if(!fOutRaw->is_open()){ | |
142 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::SetRawOutput","File Open") | |
143 | <<"Pointer to ofstream = 0x0"<<ENDLOG; | |
144 | return kFALSE; | |
145 | } | |
146 | ||
147 | return kTRUE; | |
148 | } | |
149 | ||
150 | Bool_t AliL3RawDataFileHandler::SetRawOutput(ofstream *file) | |
151 | { | |
152 | if(fOutRaw){ | |
153 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::SetRawOutput","File Open") | |
154 | <<"File ptr is already in use, close file first"<<ENDLOG; | |
155 | return kFALSE; | |
156 | } | |
157 | ||
158 | //Open the raw data file with given file. | |
159 | fOutRaw = file; | |
160 | ||
161 | if(!fOutRaw->is_open()){ | |
162 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::SetRawOutput","File Open") | |
163 | <<"Pointer to ofstream = 0x0"<<ENDLOG; | |
164 | return kFALSE; | |
165 | } | |
166 | ||
167 | return kTRUE; | |
168 | } | |
169 | ||
170 | void AliL3RawDataFileHandler::CloseRawOutput() | |
171 | { | |
172 | if(!fOutRaw){ | |
173 | LOG(AliL3Log::kWarning,"AliL3RawDataFileHandler::CloseRawOutput","File Close") | |
174 | <<"Nothing to Close"<<ENDLOG; | |
175 | return; | |
176 | } | |
177 | if(fOutRaw->is_open()) fOutRaw->close(); | |
178 | delete fOutRaw; | |
179 | fOutRaw = 0; | |
180 | } | |
181 | ||
182 | ||
183 | Bool_t AliL3RawDataFileHandler::SetRawPedestalsInput(Char_t *name) | |
184 | { | |
185 | if(fInRawPed){ | |
186 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::SetRawPedestalsInput","File Open") | |
187 | <<"File ptr is already in use, close file first"<<ENDLOG; | |
188 | return kFALSE; | |
189 | } | |
190 | ||
191 | //Open the raw data file with name. | |
192 | fInRawPed = new ifstream(); | |
193 | fInRawPed->open(name,fstream::binary); | |
194 | ||
195 | if(!fInRawPed->is_open()){ | |
196 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::SetRawPedestalsInput","File Open") | |
197 | <<"Pointer to ifstream = 0x0"<<ENDLOG; | |
198 | return kFALSE; | |
199 | } | |
200 | ||
201 | return kTRUE; | |
202 | } | |
203 | ||
204 | Bool_t AliL3RawDataFileHandler::SetRawPedestalsInput(ifstream *file) | |
205 | { | |
206 | if(fInRawPed){ | |
207 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::SetRawPedestalsInput","File Open") | |
208 | <<"File ptr is already in use, close file first"<<ENDLOG; | |
209 | return kFALSE; | |
210 | } | |
211 | ||
212 | //Open the raw data file with given file. | |
213 | fInRawPed = file; | |
214 | ||
215 | if(!fInRawPed->is_open()){ | |
216 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::SetRawPedestalsInput","File Open") | |
217 | <<"Pointer to ifstream = 0x0"<<ENDLOG; | |
218 | return kFALSE; | |
219 | } | |
220 | ||
221 | return kTRUE; | |
222 | } | |
223 | ||
224 | void AliL3RawDataFileHandler::CloseRawPedestalsInput() | |
225 | { | |
02f030e3 | 226 | if(!fInRawPed){ |
3e87ef69 | 227 | LOG(AliL3Log::kWarning,"AliL3RawDataFileHandler::CloseRawPedestalsInput","File Close") |
228 | <<"Nothing to Close"<<ENDLOG; | |
229 | return; | |
230 | } | |
02f030e3 | 231 | if(fInRawPed->is_open()) fInRawPed->close(); |
232 | delete fInRawPed; | |
3e87ef69 | 233 | fInRaw = 0; |
234 | } | |
235 | ||
236 | Bool_t AliL3RawDataFileHandler::SetMappingFile(Char_t *name) | |
237 | { | |
238 | if(fMapping){ | |
239 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::SetMapping","File Open") | |
240 | <<"File ptr is already in use, close file first"<<ENDLOG; | |
241 | return kFALSE; | |
242 | } | |
243 | ||
244 | fMapping = fopen(name,"r"); | |
245 | if(!fMapping){ | |
246 | LOG(AliL3Log::kWarning,"AliL3RawDataFileHandler::SetMappingFile","File Open") | |
247 | <<"Pointer to file = 0x0"<<ENDLOG; | |
248 | return kFALSE; | |
249 | } | |
250 | ||
251 | return kTRUE; | |
252 | } | |
253 | ||
254 | Bool_t AliL3RawDataFileHandler::SetMappingFile(FILE *file) | |
255 | { | |
256 | if(fMapping){ | |
257 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::SetMapping","File Open") | |
258 | <<"File ptr is already in use, close file first"<<ENDLOG; | |
259 | return kFALSE; | |
260 | } | |
261 | ||
262 | fMapping = file; | |
263 | if(!fMapping){ | |
264 | LOG(AliL3Log::kWarning,"AliL3RawDataFileHandler::SetMappingFile","File Open") | |
265 | <<"Pointer to file = 0x0"<<ENDLOG; | |
266 | return kFALSE; | |
267 | } | |
268 | ||
269 | return kTRUE; | |
270 | } | |
271 | ||
272 | void AliL3RawDataFileHandler::CloseMappingFile() | |
273 | { | |
274 | if(!fMapping){ | |
275 | LOG(AliL3Log::kWarning,"AliL3RawDataFileHandler::CloseMappingFile","File Close") | |
276 | <<"Nothing to Close"<<ENDLOG; | |
277 | return; | |
278 | } | |
279 | fclose(fMapping); | |
280 | fMapping = 0; | |
281 | } | |
282 | ||
283 | Int_t AliL3RawDataFileHandler::ReadMappingFile() | |
284 | { | |
285 | if(!fMapping){ | |
286 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::ReadMappingFile","File Open") | |
287 | <<"Pointer to file = 0x0"<<ENDLOG; | |
288 | return -1; | |
289 | } | |
290 | ||
291 | Char_t dummy[100]; | |
292 | fgets(dummy,80,fMapping); | |
293 | ||
294 | Int_t nboard,nadc; | |
295 | fscanf(fMapping,"%s %d %s %d",dummy,&nboard,dummy,&nadc); | |
296 | ||
297 | fNChannels=nboard*nadc; | |
298 | if(fNChannels<=0){ | |
299 | LOG(AliL3Log::kWarning,"AliL3RawDataFileHandler::ReadMappingFile","Data Inconsistency") | |
300 | <<"fNChannels must be greater than 0"<<ENDLOG; | |
301 | return -1; | |
302 | } | |
303 | ||
304 | fRow=new Byte_t[fNChannels]; | |
305 | fPad=new Byte_t[fNChannels]; | |
306 | fRowPad=new Short_t*[AliL3Transform::GetNRows()]; | |
307 | for(Int_t i=0; i < AliL3Transform::GetNRows(); i++){ | |
308 | fRowPad[i]=new Short_t[AliL3Transform::GetNPads(i)]; | |
309 | for(Int_t j=0; j < AliL3Transform::GetNPads(i); j++) fRowPad[i][j]=-1; | |
310 | } | |
311 | ||
312 | for(UInt_t i=0;i<fNChannels;i++){ | |
313 | Int_t board,adc,row,pad; | |
314 | if(fscanf(fMapping,"%d %d %d %d",&board,&adc,&row,&pad)!=4) break; | |
315 | //store the mapping | |
316 | fRow[i]=(Byte_t)row; | |
317 | fPad[i]=(Byte_t)pad; | |
318 | fRowPad[row][pad]=i; | |
319 | if(row>fRowMaxUsed) fRowMaxUsed=row; | |
320 | if(row<fRowMinUsed) fRowMinUsed=row; | |
321 | if(pad>fPadMaxUsed) fPadMaxUsed=pad; | |
322 | if(pad<fPadMinUsed) fPadMinUsed=pad; | |
323 | ||
324 | fNPads[row]++; | |
325 | //cout << i << " " << row << " " << pad << endl; | |
326 | } | |
327 | ||
328 | return fNChannels; | |
329 | } | |
330 | ||
331 | inline Int_t AliL3RawDataFileHandler::Convert4(Int_t i) | |
332 | { //BigEndian i0i1i2i3 -> LittleEndian i3i2i1i0 | |
333 | if(!fConvert) return i; | |
334 | Char_t *p=(Char_t*)&i; | |
335 | Char_t temp[4]; | |
336 | temp[0]=p[3]; | |
337 | temp[1]=p[2]; | |
338 | temp[2]=p[1]; | |
339 | temp[3]=p[0]; | |
340 | return (*(Int_t*)temp); | |
341 | } | |
342 | ||
343 | inline Short_t AliL3RawDataFileHandler::Convert2(Short_t s) | |
344 | { //BigEndian i0i1 -> LittleEndian i1i0 | |
345 | if(!fConvert) return s; | |
346 | Char_t *p=(Char_t*)&s; | |
347 | Char_t temp[2]; | |
348 | temp[0]=p[1]; | |
349 | temp[1]=p[0]; | |
350 | return (*(Short_t*)temp); | |
351 | } | |
352 | ||
353 | Int_t AliL3RawDataFileHandler::ReadRawInput() | |
354 | { | |
355 | //Read data from cosmics file into memory | |
356 | ||
357 | if(!fInRaw){ | |
358 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::ReadRawInput","File Open") | |
359 | <<"No Input avalible: no object ifstream"<<ENDLOG; | |
360 | return 0; | |
361 | } | |
362 | ||
363 | if(!fInRaw->is_open()){ | |
364 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::ReadRawInput","File Open") | |
365 | <<"No Input avalible: ifstream not opened"<<ENDLOG; | |
366 | return 0; | |
367 | } | |
368 | ||
369 | Int_t dummy4; | |
370 | Short_t dummy2; | |
371 | fInRaw->read((Char_t*)&dummy4,sizeof(dummy4)); | |
372 | if(dummy4==(Int_t)fNChannels) fConvert=kFALSE; | |
373 | else { | |
374 | Int_t knumofChannels = Convert4(dummy4); | |
375 | if(knumofChannels!=(Int_t)fNChannels){ | |
376 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::ReadRawInput","Data Inconsistency") | |
377 | <<"Number of Channels should be equal to fNChannels "<<knumofChannels<<" "<<fNChannels<<ENDLOG; | |
378 | return 0; | |
379 | } | |
380 | } | |
381 | ||
382 | //read used altrochannels (for the moment | |
383 | //this information is not really needed as | |
384 | //all channels per FEC are used | |
385 | for(UInt_t i = 0 ; i < fNChannels ; i++){ | |
386 | fInRaw->read((Char_t*)&dummy2,sizeof(dummy2)); | |
387 | UShort_t channel = Convert2(dummy2); | |
388 | if(channel>fNChannels){ | |
389 | LOG(AliL3Log::kWarning,"AliL3RawDataFileHandler::ReadRawInput","Data Inconsistency") | |
390 | <<AliL3Log::kDec<<"Channel number must be smaller then fNChannels "<<channel<<" "<<fNChannels<<ENDLOG; | |
391 | return 0; | |
392 | } | |
393 | } | |
394 | ||
395 | fInRaw->read((Char_t*)&dummy4,sizeof(dummy4)); | |
396 | Int_t numofChannelsTest = Convert4(dummy4); | |
397 | ||
398 | if (numofChannelsTest != (Int_t)fNChannels){ | |
399 | LOG(AliL3Log::kWarning,"AliL3RawDataFileHandler::ReadRawInput","Data Inconsistency") | |
400 | <<AliL3Log::kDec<<"Number of test channels should be equal to fNChannels "<<numofChannelsTest<<" "<<fNChannels<<ENDLOG; | |
401 | return 0; | |
402 | } | |
403 | ||
404 | //Timebins | |
405 | fInRaw->read((Char_t*)&dummy4,sizeof(dummy4)); | |
406 | fNTimeBins=Convert4(dummy4); | |
407 | ||
408 | if(fNTimeBins!=AliL3Transform::GetNTimeBins()){ | |
409 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::ReadRawInput","Data Inconsistency") | |
410 | <<AliL3Log::kDec<<"fNTimeBins does not match AliL3Transformer, check AliL3Transform::Init() "<<fNTimeBins<<" "<<AliL3Transform::GetNTimeBins()<<ENDLOG; | |
411 | } | |
412 | ||
413 | return fNChannels; | |
414 | } | |
415 | ||
416 | Short_t** AliL3RawDataFileHandler::GetRawData(Int_t &channels, Int_t &timebins) | |
417 | { | |
418 | Short_t **charges=0; | |
419 | channels=0; | |
420 | timebins=0; | |
421 | ||
422 | if(fNTimeBins==0){ | |
423 | LOG(AliL3Log::kWarning,"AliL3RawDataFileHandler::GetRawData","Data Inconsistency") | |
424 | <<"Call AliL3RawDataFileHandler::RawReadInput() first"<<ENDLOG; | |
425 | if(!ReadRawInput()){ | |
426 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::GetRawData","Data Inconsistency") | |
427 | <<"Something went wrong reading data header"<<ENDLOG; | |
428 | return 0; | |
429 | } | |
430 | } | |
431 | ||
432 | charges=new Short_t*[fNChannels]; | |
433 | for(UInt_t c=0;c<fNChannels;c++) charges[c]=new Short_t[fNTimeBins]; | |
434 | ||
435 | for(UInt_t channel = 0; channel < fNChannels; channel++){ | |
436 | for(Int_t timebin = 0 ; timebin < fNTimeBins ; timebin++){ | |
437 | Short_t dummy2; | |
438 | fInRaw->read((Char_t*)&dummy2,sizeof(dummy2)); | |
439 | Short_t charge = Convert2(dummy2); | |
440 | charges[channel][timebin]=charge; | |
441 | } | |
442 | } | |
443 | ||
444 | channels=fNChannels; | |
445 | timebins=fNTimeBins; | |
446 | ||
447 | return charges; | |
448 | } | |
449 | ||
450 | Int_t AliL3RawDataFileHandler::StoreRawData(Short_t **charges) | |
451 | { | |
452 | //store charges in the raw data format | |
453 | ||
454 | if(!fOutRaw){ | |
455 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::StoreRawData","File Open") | |
456 | <<"No Output avalible: no object ofstream"<<ENDLOG; | |
457 | return 0; | |
458 | } | |
459 | ||
460 | if(!fOutRaw->is_open()){ | |
461 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::StoreRawData","File Open") | |
462 | <<"No Output avalible: ofstream not opened"<<ENDLOG; | |
463 | return 0; | |
464 | } | |
465 | ||
466 | Int_t dummy4; | |
467 | Short_t dummy2; | |
468 | ||
469 | dummy4=Convert4(fNChannels); | |
470 | ||
471 | fOutRaw->write((Char_t*)&dummy4,sizeof(dummy4)); | |
472 | for(UInt_t i = 0 ; i < fNChannels ; i++){ | |
473 | dummy2 = Convert2(Short_t(i)); | |
474 | fOutRaw->write((Char_t*)&dummy2,sizeof(dummy2)); | |
475 | } | |
476 | ||
477 | dummy4=Convert4(fNChannels); | |
478 | fOutRaw->write((Char_t*)&dummy4,sizeof(dummy4)); | |
479 | ||
480 | //Timebins | |
481 | dummy4=Convert4(fNTimeBins); | |
482 | fOutRaw->write((Char_t*)&dummy4,sizeof(dummy4)); | |
483 | ||
484 | for(UInt_t channel = 0; channel < fNChannels; channel++){ | |
485 | for(Int_t timebin = 0 ; timebin < fNTimeBins ; timebin++){ | |
486 | Short_t charge=charges[channel][timebin]; | |
487 | dummy2 = Convert2(charge); | |
488 | fOutRaw->write((Char_t*)&dummy2,sizeof(dummy2)); | |
489 | } | |
490 | } | |
491 | ||
492 | return fNChannels; | |
493 | } | |
494 | ||
495 | Int_t AliL3RawDataFileHandler::ReadRawPedestalsInput() | |
496 | { | |
497 | if(!fInRawPed){ | |
498 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::ReadRawPedestalsInput","File Open") | |
499 | <<"No Input avalible: no object ifstream"<<ENDLOG; | |
500 | return 0; | |
501 | } | |
502 | ||
503 | if(!fInRawPed->is_open()){ | |
504 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::ReadRawPedestalsInput","File Open") | |
505 | <<"No Input avalible: ifstream not opened"<<ENDLOG; | |
506 | return 0; | |
507 | } | |
508 | ||
509 | Int_t dummy4; | |
510 | Short_t dummy2; | |
511 | fInRawPed->read((Char_t*)&dummy4,sizeof(dummy4)); | |
512 | if(dummy4==(Int_t)fNChannels) fConvert=kFALSE; | |
513 | else { | |
514 | Int_t knumofChannels = Convert4(dummy4); | |
515 | if(knumofChannels!=(Int_t)fNChannels){ | |
516 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::ReadRawPedestalsInput","Data Inconsistency") | |
517 | <<AliL3Log::kDec<<"Number of Channels should be equal to fNChannels "<<knumofChannels<<" "<<fNChannels<<ENDLOG; | |
518 | return 0; | |
519 | } | |
520 | } | |
521 | ||
522 | //read used altrochannels (for the moment | |
523 | for(UInt_t i = 0 ; i < fNChannels ; i++){ | |
524 | fInRawPed->read((Char_t*)&dummy2,sizeof(dummy2)); | |
525 | //UShort_t channel = Convert2(dummy2); | |
526 | } | |
527 | ||
528 | fInRawPed->read((Char_t*)&dummy4,sizeof(dummy4)); | |
529 | //Int_t numofChannelsTest = Convert4(dummy4); | |
530 | ||
531 | //Timebins | |
532 | fInRawPed->read((Char_t*)&dummy4,sizeof(dummy4)); | |
533 | fNTimeBins=Convert4(dummy4); | |
534 | ||
535 | if(fNTimeBins!=AliL3Transform::GetNTimeBins()){ | |
536 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::ReadRawPedestalsInput","Data Inconsistency") | |
537 | <<AliL3Log::kDec<<"fNTimeBins does not match AliL3Transformer, check AliL3Transform::Init() "<<fNTimeBins<<" "<<AliL3Transform::GetNTimeBins()<<ENDLOG; | |
538 | } | |
539 | ||
540 | //Read the data | |
541 | fPedestals=new Short_t*[fNChannels]; | |
542 | for(UInt_t c=0;c<fNChannels;c++) fPedestals[c]=new Short_t[fNTimeBins]; | |
543 | ||
544 | for(UInt_t channel = 0; channel < fNChannels; channel++){ | |
545 | for(Int_t timebin = 0 ; timebin < fNTimeBins ; timebin++){ | |
546 | Short_t dummy2; | |
547 | fInRawPed->read((Char_t*)&dummy2,sizeof(dummy2)); | |
548 | Short_t charge = Convert2(dummy2); | |
549 | fPedestals[channel][timebin]=charge; | |
550 | } | |
551 | } | |
552 | ||
553 | return fNChannels; | |
554 | } | |
555 | ||
556 | AliL3DigitRowData * AliL3RawDataFileHandler::RawData2Memory(UInt_t &nrow,Int_t event) | |
557 | { //event is not used | |
558 | AliL3DigitRowData *data = 0; | |
559 | nrow=0; | |
560 | ||
561 | if(fNTimeBins==0){ | |
562 | LOG(AliL3Log::kWarning,"AliL3RawDataFileHandler::RawData2Memory","Data Inconsistency") | |
563 | <<"Call AliL3RawDataFileHandler::RawReadInput() first"<<ENDLOG; | |
564 | if(!ReadRawInput()){ | |
565 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::RawData2Memory","Data Inconsistency") | |
566 | <<"Something went wrong reading data header"<<ENDLOG; | |
567 | return 0; | |
568 | } | |
569 | } | |
570 | ||
571 | //Read the data | |
572 | Short_t charges[fNChannels][fNTimeBins]; | |
573 | for(UInt_t channel = 0; channel < fNChannels; channel++){ | |
574 | for(Int_t timebin = 0 ; timebin < fNTimeBins ; timebin++){ | |
575 | Short_t dummy2; | |
576 | fInRaw->read((Char_t*)&dummy2,sizeof(dummy2)); | |
577 | Short_t charge = Convert2(dummy2); | |
578 | ||
579 | //Pedestal substraction | |
580 | if(fPedestals) charge-=fPedestals[channel][timebin]; | |
581 | else charge-=fPedVal; | |
582 | if(charge<0) charge=0; | |
583 | ||
584 | charges[channel][timebin]=charge; | |
585 | } | |
586 | } | |
587 | ||
588 | //get data size | |
589 | Int_t nrows=0; | |
590 | Int_t ndigitcount=0; | |
591 | Int_t ndigits[AliL3Transform::GetNRows()]; | |
592 | for(Int_t i=0;i<AliL3Transform::GetNRows();i++) ndigits[i]=0; | |
593 | ||
594 | //no need to search for slice/sector given by init | |
595 | //but check for row/patch boundaries | |
596 | //assume slice 0 | |
597 | for(Int_t slrow=0;slrow<AliL3Transform::GetNRows();slrow++){ | |
598 | ||
599 | if(slrow<fRowMin) continue; | |
600 | if(slrow>fRowMax) break; | |
601 | ||
602 | for(Int_t pad=0;pad<AliL3Transform::GetNPads(slrow);pad++){ | |
603 | Short_t channel=fRowPad[slrow][pad]; | |
604 | if(channel==-1) continue; //no data on that channel; | |
605 | ||
606 | for(Int_t timebin = 0 ; timebin < fNTimeBins ; timebin++){ | |
607 | Int_t dig=charges[channel][timebin]; | |
608 | ||
609 | if(dig <= AliL3Transform::GetZeroSup()) continue; | |
610 | if(dig >= AliL3Transform::GetADCSat()) | |
611 | dig = AliL3Transform::GetADCSat(); | |
612 | ||
613 | ndigits[slrow]++; //for this row only | |
614 | ndigitcount++; //total number of digits to be published | |
615 | } | |
616 | } | |
617 | ||
618 | //count number of rows | |
619 | nrows++; | |
620 | } | |
621 | ||
622 | //test data consistency | |
623 | Int_t ndigitcounttest=0; | |
624 | for(Int_t slrow=0;slrow<AliL3Transform::GetNRows();slrow++) | |
625 | ndigitcounttest+=ndigits[slrow]; | |
626 | if(ndigitcount!=ndigitcounttest) | |
627 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::RawData2Memory","Digits") | |
628 | <<AliL3Log::kDec<<"Found Inconsistency "<<ndigitcount<<" != "<<ndigitcounttest<<ENDLOG; | |
629 | ||
630 | Int_t size = sizeof(AliL3DigitData)*ndigitcount | |
631 | + nrows*sizeof(AliL3DigitRowData); | |
632 | LOG(AliL3Log::kDebug,"AliL3RawDataFileHandler::RawData2Memory","Digits") | |
633 | <<AliL3Log::kDec<<"Found "<<ndigitcount<<" Digits on "<<nrows<<" rows"<<ENDLOG; | |
634 | ||
635 | //now copy data | |
636 | data=(AliL3DigitRowData*) Allocate(size); | |
637 | nrow = (UInt_t)nrows; | |
638 | //memset(data,1,size); //for debugging | |
639 | ||
640 | Int_t ndigitcounttest2=0; | |
641 | AliL3DigitRowData *tempPt = data; | |
642 | for(Int_t slrow=0;slrow<AliL3Transform::GetNRows();slrow++){ | |
643 | ||
644 | if(slrow<fRowMin) continue; | |
645 | if(slrow>fRowMax) break; | |
646 | ||
647 | tempPt->fRow = slrow; | |
648 | tempPt->fNDigit = ndigits[slrow]; | |
649 | ||
650 | Int_t localcount=0; | |
651 | for(Int_t pad=0;pad<AliL3Transform::GetNPads(slrow);pad++){ | |
652 | Short_t channel=fRowPad[slrow][pad]; | |
653 | if(channel==-1) continue; //no data on that channel; | |
654 | ||
655 | for(Int_t timebin = 0 ; timebin < fNTimeBins ; timebin++){ | |
656 | Int_t dig=charges[channel][timebin]; | |
657 | ||
658 | if(dig <= AliL3Transform::GetZeroSup()) continue; | |
659 | if(dig >= AliL3Transform::GetADCSat()) | |
660 | dig = AliL3Transform::GetADCSat(); | |
661 | ||
662 | //Exclude data outside cone: | |
663 | //AliL3Transform::Raw2Local(xyz,sector,row,pad,time); | |
664 | //if(fParam->GetPadRowRadii(sector,row)<230./250.*fabs(xyz[2])) continue; | |
665 | ||
666 | tempPt->fDigitData[localcount].fCharge=(UShort_t)dig; | |
667 | tempPt->fDigitData[localcount].fPad=(UChar_t)pad; | |
668 | tempPt->fDigitData[localcount].fTime=(UShort_t)timebin; | |
669 | #ifdef do_mc | |
670 | tempPt->fDigitData[localcount].fTrackID[0] = 0; | |
671 | tempPt->fDigitData[localcount].fTrackID[1] = 0; | |
672 | tempPt->fDigitData[localcount].fTrackID[2] = 0; | |
673 | #endif | |
674 | localcount++; | |
675 | ndigitcounttest2++; | |
676 | } //time | |
677 | } //pad | |
678 | ||
679 | if(localcount != ndigits[slrow]) | |
680 | LOG(AliL3Log::kFatal,"AliL3RawDataFileHandler::RawData2Memory","Memory") | |
681 | <<AliL3Log::kDec<<"Mismatch: localcount "<<localcount<<" ndigits " | |
682 | <<ndigits[slrow]<<ENDLOG; | |
683 | ||
684 | Byte_t *tmp = (Byte_t*)tempPt; | |
685 | Int_t size = sizeof(AliL3DigitRowData) | |
686 | + ndigits[slrow]*sizeof(AliL3DigitData); | |
687 | tmp += size; | |
688 | tempPt = (AliL3DigitRowData*)tmp; | |
689 | }//row | |
690 | ||
691 | if(ndigitcount!=ndigitcounttest2) | |
692 | LOG(AliL3Log::kError,"AliL3RawDataFileHandler::RawData2Memory","Digits") | |
693 | <<AliL3Log::kDec<<"Found Inconsistency "<<ndigitcount<<" != "<<ndigitcounttest2<<ENDLOG; | |
694 | ||
695 | return data; | |
696 | } | |
240d63be | 697 | |
698 | Bool_t AliL3RawDataFileHandler::RawData2CompBinary(Int_t event) | |
699 | { | |
700 | Bool_t out = kTRUE; | |
701 | UInt_t ndigits=0; | |
702 | AliL3DigitRowData *digits=0; | |
703 | digits = RawData2Memory(ndigits,event); | |
704 | out = Memory2CompBinary(ndigits,digits); | |
705 | Free(); | |
706 | return out; | |
707 | } |