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