]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/programs/read.cxx
Check consecutive rows.
[u/mrichter/AliRoot.git] / HLT / programs / read.cxx
1 /* $Id$
2 Author: Constantin Loizides <mailto: loizides@ikf.physik.uni-frankfurt.de
3 */
4
5 #include <stream.h>
6 #include <libgen.h>
7 #include "AliL3MemHandler.h"
8 #include "AliL3AltroMemHandler.h"
9 #include "AliL3DigitData.h"
10 #include "AliL3Transform.h"
11
12 /**
13 Example program how to open and read a raw datafile.
14 In addition it shows, how to store results in an Altro like 
15 data format. 
16 */
17
18 int main(int argc,char **argv)
19 {
20   Int_t nrows=175;
21   Bool_t altroout=kFALSE;
22   FILE *afile=0;
23
24   if(argc<2)
25     {
26       cout<<"Usage: read datafile [padrows] [altrodatfile]"<<endl;
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;
39
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   
47   //Storing all detector-spesific quantities, needed.
48   AliL3Transform::Init(dirname(argv[1])); 
49
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);
56   if((Int_t)ndigits<nrows) nrows=ndigits;
57
58   //Create an ALtroMemHandler object
59   AliL3AltroMemHandler altromem;
60   if(altroout) altroout=altromem.SetASCIIOutput(afile);
61
62   UShort_t time,charge;
63   UChar_t pad;
64   Int_t crows=0,lrow=-1;
65   for(Int_t row=0; row<nrows; row++) //Loop over padrows
66     {
67       //Get the data on this padrow:
68       AliL3DigitData *dataPt = (AliL3DigitData*)digits->fDigitData;
69       if(lrow+1==row) crows++;
70       
71       //Loop over all digits on this padrow:
72       for(UInt_t ndig=0; ndig<digits->fNDigit; ndig++)
73         //for(UInt_t ndig=digits->fNDigit;ndig>0;ndig--)
74         {
75           lrow=row;
76           pad = dataPt[ndig].fPad;
77           time = dataPt[ndig].fTime;
78           charge = dataPt[ndig].fCharge;
79           cout << "Padrow " << row << " pad " << (int)pad << " time " <<(int) time << " charge " << (int)charge << endl;
80           if(altroout) altromem.Write(row,pad,charge,time);
81         }
82       
83       //Move the pointer to the next padrow:
84       file.UpdateRowPointer(digits);
85     }
86   
87   if(afile) {
88     altromem.WriteFinal();
89     fclose(afile);
90   }
91
92   cerr << "Rows: " << nrows << " Consecutive: " << crows << endl;
93   return 0;
94 }