Little bugfixes for new alitroot version.
[u/mrichter/AliRoot.git] / HLT / programs / ali2raw.cxx
1 /* $Id$ 
2    Author: Constantin Loizides <loizides@ikf.physik.uni-frankfurt.de>
3 */
4
5 #ifndef use_aliroot
6 BOMB THE COMPILE: USEPACKAGE=ALIROOT
7 #endif
8
9 #include <stream.h>
10 #include "AliL3RootTypes.h"
11 #include "AliL3MemHandler.h"
12 #include "AliL3FileHandler.h"
13 #include "AliL3DigitData.h"
14 #include "AliL3Transform.h"
15
16 /**
17    Converts from AliRoot Digits to L3-RawDigits
18  */
19 int Make_Init(char *file, char *tofile=NULL);
20
21 int main (int argc, char** argv)
22 {
23   int first=0;
24   int last=0;
25
26   if(argc<3)
27   {
28     cout<<"Usage: ali2raw datafile path [firstsector] [lastsector]"<<endl;
29     return -1;
30   }
31   if(argc<4) first=atoi(argv[3]);
32   if(argc<5) first=atoi(argv[4]);
33
34   char transname[1000];
35   const Int_t npatch = 6;
36   Int_t row[npatch][2] = {{0,31},{32,63},{64,91},{92,119},{120,143},{144,175}};
37   
38   strcpy(transname,argv[1]);
39   strcat(transname,"/.transform.config");
40   if(Make_Init(argv[1],transname)<0) exit(1);
41
42
43   /*
44   AliL3FileHandler *fFileHandler = new AliL3FileHandler(); 
45   fFileHandler->SetAliInput(in);
46   AliL3Transform *fTransformer = new AliL3Transform(path);
47
48
49   fFileHandler->Init(fTransformer);
50   for(int slice=first; slice<=last; slice++){
51     for(int patch=0;patch<npatch;patch++){
52       cerr<<"reading slice: "<<slice<<" patch: "<<patch;
53       fFileHandler->Free();
54       fFileHandler->Init(slice,patch,row[patch]);      
55       sprintf(name,"%sdigits_%d_%d.raw",path,slice,patch);
56       fFileHandler->SetBinaryOutput(name);
57       fFileHandler->AliDigits2CompBinary();
58       fFileHandler->CloseBinaryOutput();      
59       cerr<<" done"<<endl;
60     }      
61   }
62   fFileHandler->CloseAliInput();
63   */
64 }
65
66 int Make_Init(char *file, char *tofile=NULL){
67
68   TFile *rootf = new TFile(file,"READ");
69
70   if(!rootf->IsOpen()){
71     cerr<<"could not open file: "<<file<<endl;
72     return -1;
73   }
74
75   AliTPCParam* par = (AliTPCParam*)rootf->Get("75x40_100x60");
76
77   if(!par){
78     cerr<<"no AliTPCParam 75x40_100x60 in file: "<<file<<endl;
79     return -2;
80   }
81
82   int fNTimeBins = par->GetMaxTBin()+1;
83   int fNRowLow = par->GetNRowLow();
84   int fNRowUp  = par->GetNRowUp();
85   int fNRow= fNRowLow + fNRowUp;
86   int fNSectorLow = par->GetNInnerSector();
87   int fNSectorUp = par->GetNOuterSector();
88   int fNSector = fNSectorLow + fNSectorUp;
89   //  int fNSlice = fNSectorLow;
90
91   char tofilename[1000];
92   if(tofile){
93     strcpy(tofilename,tofile);
94     strcat(tofilename,".transform-config");
95   } else strcpy(tofilename,file);
96
97   FILE *f = fopen(tofilename,"w");
98   fprintf(f,"void AliL3Transform::Init(){\n");
99
100   fprintf(f,"  //sector:\n");
101   fprintf(f,"  fNTimeBins = %d ;\n",fNTimeBins);
102   fprintf(f,"  fNRowLow = %d ;\n",fNRowLow);
103   fprintf(f,"  fNRowUp = %d ;\n",fNRowUp);
104   fprintf(f,"  fNSectorLow = %d ;\n",fNSectorLow);
105   fprintf(f,"  fNSectorUp = %d ;\n",fNSectorUp);
106   fprintf(f,"  fNSector = %d ;\n",fNSector);
107   fprintf(f,"  fPadPitchWidthLow = %f ;\n",par->GetPadPitchWidth(0));
108   fprintf(f,"  fPadPitchWidthUp = %f ;\n",par->GetPadPitchWidth(fNSectorLow));
109   fprintf(f,"  fZWidth = %.20f ;\n",par->GetZWidth());
110   fprintf(f,"  fZSigma = %.20f ;\n",par->GetZSigma());
111
112   fprintf(f,"\n  //slices:\n");
113   fprintf(f,"  fNSlice = %d ;\n",fNSectorLow);
114   fprintf(f,"  fNRow = %d ;\n",fNRow);
115
116   //rotation shift put in by hand -> Constantin 
117   fprintf(f,"  fNRotShift = 0.5 ;\n");
118
119   fprintf(f,"  fPi = %.15f ;\n",TMath::Pi());
120   fprintf(f,"  for(Int_t i=0;i<36;i++){\n");
121   fprintf(f,"    fCos[i] = cos(2*fPi/9*(i+0.5));\n");
122   fprintf(f,"    fSin[i] = sin(2*fPi/9*(i+0.5));\n");
123   fprintf(f,"  }\n\n");
124
125   for(Int_t i=0;i<fNRow;i++){
126     int sec,row;
127     if( i < fNRowLow){sec =0;row =i;}
128     else{sec = fNSectorLow;row =i-fNRowLow;}
129     fprintf(f,"  fX[%d] = %3.15f ;\n",i,par->GetPadRowRadii(sec,row));
130   }
131   for(Int_t i=0;i<fNRow;i++){
132     int sec,row;
133     if( i < fNRowLow){sec =0;row =i;}
134     else{sec = fNSectorLow;row =i-fNRowLow;}
135     fprintf(f,"  fNPads[%d] = %d ;\n",i,par->GetNPads(sec,row));
136   }
137
138   fprintf(f,"}\n");
139   fclose(f);
140   return 0;
141 }
142
143
144
145 #if 0
146 void singlepatch(char* in,int first, int last,char *path="",int event=0)
147 {
148   AliL3Logger l;
149   //l.UnSet(AliL3Logger::kDebug);
150   //l.UnSet(AliL3Logger::kAll);
151   //l.Set(AliL3Logger::kInformational);
152   //l.UseStdout();
153   l.UseStream();
154   
155   char fname[100];
156   sprintf(fname,"%sevent_%d/",path,event);
157   char name[256];
158   AliL3FileHandler *fFileHandler = new AliL3FileHandler(); 
159   fFileHandler->SetAliInput(in);
160   Int_t srow[2] = {0,175};
161   int patch=0;
162   for(int slice=first; slice<=last; slice++)
163     {
164       cerr<<"reading slice: "<<slice;
165       fFileHandler->Free();
166       fFileHandler->Init(slice,patch,srow);
167       sprintf(name,"%sdigits_%d_%d.raw",fname,slice,patch);
168       fFileHandler->SetBinaryOutput(name);
169       fFileHandler->AliDigits2CompBinary(event);
170       fFileHandler->CloseBinaryOutput();      
171       cerr<<" done"<<endl;
172     }
173   fFileHandler->CloseAliInput();
174   
175 }
176 #endif
177
178
179
180
181
182
183