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