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