2c7d4020 |
1 | /* $Id$ |
c2a88d53 |
2 | Author: Constantin Loizides <mailto: loizides@ikf.physik.uni-frankfurt.de |
3 | */ |
4 | |
5 | #include <stream.h> |
2c7d4020 |
6 | #include <libgen.h> |
c2a88d53 |
7 | #include "AliL3MemHandler.h" |
8 | #include "AliL3AltroMemHandler.h" |
9 | #include "AliL3DigitData.h" |
2c7d4020 |
10 | #include "AliL3Transform.h" |
c2a88d53 |
11 | |
12 | /** |
13 | Example program how to open and read a raw datafile. |
2c7d4020 |
14 | In addition it shows, how to store results in an Altro like |
15 | data format. |
c2a88d53 |
16 | */ |
17 | |
18 | int main(int argc,char **argv) |
19 | { |
20 | UInt_t nrows=175; |
21 | Bool_t altroout=kFALSE; |
22 | FILE *afile=0; |
2c7d4020 |
23 | |
c2a88d53 |
24 | if(argc<2) |
25 | { |
2c7d4020 |
26 | cout<<"Usage: read datafile [padrows] [altrodatfile]"<<endl; |
c2a88d53 |
27 | return -1; |
28 | } |
29 | if (argc>2) { |
30 | nrows=atoi(argv[2]); |
31 | } |
32 | if (argc>3) { |
33 | altroout=kTRUE; |
34 | afile=fopen(argv[3],"w"); |
35 | } |
36 | |
37 | //Filehandler object: |
38 | AliL3MemHandler file; |
2c7d4020 |
39 | |
c2a88d53 |
40 | //Open the data file: |
41 | if(!file.SetBinaryInput(argv[1])) |
42 | { |
43 | cerr<<"Error opening file "<<argv[1]<<endl; |
44 | return -1; |
45 | } |
46 | |
2c7d4020 |
47 | //Storing all detector-spesific quantities, needed. |
48 | AliL3Transform::Init(dirname(argv[1])); |
49 | |
c2a88d53 |
50 | //Create an RowData object to access the data |
51 | AliL3DigitRowData *digits=0; |
52 | UInt_t ndigits=0; |
53 | |
54 | //Read the file, and store the data in memory. Return value is a pointer to the data. |
55 | digits = file.CompBinary2Memory(ndigits); |
2c7d4020 |
56 | if(ndigits<nrows) nrows=ndigits; |
c2a88d53 |
57 | |
58 | //Create an ALtroMemHandler object |
59 | AliL3AltroMemHandler altromem; |
bbdff6bf |
60 | if(altroout) altroout=altromem.SetASCIIOutput(afile); |
61 | |
c2a88d53 |
62 | UShort_t time,charge; |
63 | UChar_t pad; |
64 | for(UInt_t row=0; row<nrows; row++) //Loop over padrows |
65 | { |
66 | //Get the data on this padrow: |
67 | AliL3DigitData *dataPt = (AliL3DigitData*)digits->fDigitData; |
68 | |
69 | //Loop over all digits on this padrow: |
2c7d4020 |
70 | for(UInt_t ndig=0; ndig<digits->fNDigit; ndig++) |
c2a88d53 |
71 | { |
72 | pad = dataPt[ndig].fPad; |
73 | time = dataPt[ndig].fTime; |
74 | charge = dataPt[ndig].fCharge; |
75 | cout << "Padrow " << row << " pad " << (int)pad << " time " <<(int) time << " charge " << (int)charge << endl; |
76 | if(altroout) altromem.Write(row,pad,charge,time); |
77 | } |
78 | |
79 | //Move the pointer to the next padrow: |
80 | file.UpdateRowPointer(digits); |
81 | } |
82 | |
83 | if(afile) { |
84 | altromem.WriteFinal(); |
85 | fclose(afile); |
86 | } |
87 | return 0; |
88 | } |