]>
Commit | Line | Data |
---|---|---|
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> |
6f9dd32b | 7 | #include "AliL3RootTypes.h" |
8 | #include "AliL3Logger.h" | |
c2a88d53 | 9 | #include "AliL3MemHandler.h" |
10 | #include "AliL3AltroMemHandler.h" | |
11 | #include "AliL3DigitData.h" | |
2c7d4020 | 12 | #include "AliL3Transform.h" |
c2a88d53 | 13 | |
14 | /** | |
15 | Example program how to open and read a raw datafile. | |
a70f8e0b | 16 | In addition it shows, how to store (and read) the |
17 | digits in an Altro like data format. | |
c2a88d53 | 18 | */ |
19 | ||
20 | int main(int argc,char **argv) | |
21 | { | |
6f9dd32b | 22 | Int_t slice=0; |
23 | Int_t patch=0; | |
c2a88d53 | 24 | Bool_t altroout=kFALSE; |
25 | FILE *afile=0; | |
6f9dd32b | 26 | |
a70f8e0b | 27 | //AliL3Logger l; |
28 | //l.Set(AliL3Logger::kAll); | |
29 | //l.UseStdout(); | |
30 | //l.UseStream(); | |
2c7d4020 | 31 | |
c2a88d53 | 32 | if(argc<2) |
33 | { | |
6f9dd32b | 34 | cout<<"Usage: read datafile [slice] [patch] [altrodatfile]"<<endl; |
c2a88d53 | 35 | return -1; |
36 | } | |
37 | if (argc>2) { | |
6f9dd32b | 38 | slice=atoi(argv[2]); |
c2a88d53 | 39 | } |
40 | if (argc>3) { | |
6f9dd32b | 41 | patch=atoi(argv[3]); |
42 | } | |
43 | if (argc>4) { | |
c2a88d53 | 44 | altroout=kTRUE; |
6f9dd32b | 45 | afile=fopen(argv[4],"w"); |
c2a88d53 | 46 | } |
6f9dd32b | 47 | |
48 | //Loading all specific aliroot version quantities, needed. | |
49 | Char_t fname[1024]; | |
50 | strcpy(fname,argv[1]); | |
51 | AliL3Transform::Init(dirname(fname)); | |
52 | strcpy(fname,argv[1]); | |
c2a88d53 | 53 | |
54 | //Filehandler object: | |
55 | AliL3MemHandler file; | |
2c7d4020 | 56 | |
6f9dd32b | 57 | //Give slice and patch information (see filename convention) |
58 | if((patch>=0)&&(patch<6)) file.Init(slice,patch); | |
59 | else { | |
60 | Int_t srows[2]={0,175}; | |
a70f8e0b | 61 | patch=0; |
62 | file.Init(slice,patch,srows); | |
6f9dd32b | 63 | } |
64 | ||
c2a88d53 | 65 | //Open the data file: |
66 | if(!file.SetBinaryInput(argv[1])) | |
67 | { | |
68 | cerr<<"Error opening file "<<argv[1]<<endl; | |
69 | return -1; | |
70 | } | |
2c7d4020 | 71 | |
c2a88d53 | 72 | //Create an RowData object to access the data |
73 | AliL3DigitRowData *digits=0; | |
6f9dd32b | 74 | UInt_t nrows=0; |
c2a88d53 | 75 | |
76 | //Read the file, and store the data in memory. Return value is a pointer to the data. | |
6f9dd32b | 77 | digits = file.CompBinary2Memory(nrows); |
c2a88d53 | 78 | |
79 | //Create an ALtroMemHandler object | |
80 | AliL3AltroMemHandler altromem; | |
bbdff6bf | 81 | if(altroout) altroout=altromem.SetASCIIOutput(afile); |
82 | ||
c2a88d53 | 83 | UShort_t time,charge; |
84 | UChar_t pad; | |
6f9dd32b | 85 | Int_t row=file.GetRowMin()-1,crows=0,lrow=row; |
86 | ||
87 | for(UInt_t r=0; r<nrows; r++) //Loop over padrows | |
c2a88d53 | 88 | { |
89 | //Get the data on this padrow: | |
90 | AliL3DigitData *dataPt = (AliL3DigitData*)digits->fDigitData; | |
6f9dd32b | 91 | row++; |
8c594a58 | 92 | if(lrow+1==row) crows++; |
c2a88d53 | 93 | |
94 | //Loop over all digits on this padrow: | |
2c7d4020 | 95 | for(UInt_t ndig=0; ndig<digits->fNDigit; ndig++) |
c2a88d53 | 96 | { |
8c594a58 | 97 | lrow=row; |
c2a88d53 | 98 | pad = dataPt[ndig].fPad; |
99 | time = dataPt[ndig].fTime; | |
100 | charge = dataPt[ndig].fCharge; | |
101 | cout << "Padrow " << row << " pad " << (int)pad << " time " <<(int) time << " charge " << (int)charge << endl; | |
a70f8e0b | 102 | if(altroout) altromem.Write(row,pad,time,charge); |
c2a88d53 | 103 | } |
104 | ||
105 | //Move the pointer to the next padrow: | |
106 | file.UpdateRowPointer(digits); | |
107 | } | |
108 | ||
109 | if(afile) { | |
110 | altromem.WriteFinal(); | |
111 | fclose(afile); | |
a70f8e0b | 112 | |
113 | #if 0 | |
114 | //test Altro read | |
115 | UShort_t rrow=0,rtime=0,rcharge=0; | |
116 | UChar_t rpad=0; | |
117 | afile=fopen(argv[4],"r"); | |
118 | altromem.SetASCIIInput(afile); | |
119 | while(altromem.Read(rrow,rpad,rtime,rcharge)){ | |
120 | cout << "Padrow " << (int)rrow << " pad " << (int)rpad << " time " <<(int)rtime << " charge " << (int)rcharge << endl; | |
121 | } | |
122 | fclose(afile); | |
123 | #endif | |
124 | #if 0 | |
125 | //test Altro read sequence | |
126 | UShort_t rrow=0,rtime=0; | |
127 | UChar_t rpad=0,n=100,i=100; | |
128 | UShort_t *charges=new UShort_t[100]; | |
129 | afile=fopen(argv[4],"r"); | |
130 | altromem.SetASCIIInput(afile); | |
131 | while(altromem.ReadSequence(rrow,rpad,rtime,i,&charges)){ | |
132 | cout << "Padrow " << (int)rrow << " pad " << (int)rpad << " time " <<(int)rtime << " charges "; | |
133 | for(UChar_t ii=0;ii<i;ii++) cout << (int)charges[ii] << " "; | |
134 | cout << endl; | |
135 | i=n; | |
136 | } | |
137 | fclose(afile); | |
138 | #endif | |
c2a88d53 | 139 | } |
8c594a58 | 140 | |
6f9dd32b | 141 | //cerr << "Rows: " << (file.GetRowMax()-file.GetRowMin()+1) << " Consecutive: " << crows << endl; |
c2a88d53 | 142 | return 0; |
143 | } | |
6f9dd32b | 144 | |
145 |