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