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