]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/ITSSDDINJda.cxx
AliTPCkalmanFit.h AliTPCkalmanFit.cxx -
[u/mrichter/AliRoot.git] / ITS / ITSSDDINJda.cxx
1 /*
2 - Contact: - prino@to.infn.it
3 - Link: -
4 - Run Type: - PHYSICS
5 - DA Type: - LDC
6 - Number of events needed: 
7 - Input Files: - 
8 - Output Files: - SDDinj_ddl*c*_sid*.data
9 - Trigger types used: 
10 */
11
12
13 //////////////////////////////////////////////////////////////////////////////
14 // Detector Algorithm for analysis of SDD injector events.                  //
15 //                                                                          //
16 // Produces ASCII output files with:                                        //
17 // 1. event number                                                          //
18 // 2. event timestamp                                                       //
19 // 3. Fit parameters of drift vel. vs. anode                                //
20 // Tar Files are written to FXS                                             //
21 //                                                                          //
22 // Author: F. Prino (prino@to.infn.it)                                      //
23 //                                                                          //
24 //////////////////////////////////////////////////////////////////////////////
25
26
27
28 extern "C" {
29 #include "daqDA.h"
30 }
31
32 #include "event.h"
33 #include "monitor.h"
34
35 #include <stdio.h>
36 #include <stdlib.h>
37
38 // ROOT includes
39 #include <TFile.h>
40 #include <TH1F.h>
41 #include <TH2F.h>
42 #include <TSystem.h>
43 #include <TROOT.h>
44 #include <TPluginManager.h>
45
46
47 // AliRoot includes
48 #include "AliRawReaderDate.h"
49 #include "AliITSOnlineSDDInjectors.h"
50 #include "AliITSRawStreamSDD.h"
51 #include "AliITSRawStreamSDDCompressed.h"
52 /* Main routine
53       Arguments: list of DATE raw data files
54 */
55 int main(int argc, char **argv) {
56
57   int status = 0;
58
59
60   // line added to solve IO problems
61   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
62                                         "*",
63                                         "TStreamerInfo",
64                                         "RIO",
65                                         "TStreamerInfo()");
66
67   /* log start of process */
68   printf("ITS SDD INJ algorithm program started\n");  
69
70
71   /* check that we got some arguments = list of files */
72   if (argc<2) {
73     printf("Wrong number of arguments\n");
74     return -1;
75   }
76
77
78   Int_t maxNEvents=10; // maximum number of events to be analyzed
79   const Int_t kTotDDL=24;
80   const Int_t kModPerDDL=12;
81   const Int_t kSides=2;
82   Int_t adcSamplFreq=40;
83   Bool_t readfeeconf=kFALSE;
84   Int_t dataformat=1;
85   gSystem->Exec("rm -f SDDinj_ddl*.data");
86   if(gSystem->Getenv("DAQ_DETDB_LOCAL")!=NULL){
87     const char* dir=gSystem->Getenv("DAQ_DETDB_LOCAL");    
88     TString filnam=Form("%s/fee.conf",dir);    
89     FILE* feefil=fopen(filnam.Data(),"r"); 
90     if(feefil){
91       fscanf(feefil,"%d \n",&adcSamplFreq);
92       fscanf(feefil,"%d \n",&dataformat);
93       fclose(feefil);
94       readfeeconf=kTRUE;
95       printf("ADC sampling frequency = %d MHz dataformat code =%d \n",adcSamplFreq,dataformat);
96     }
97   }
98   if(!readfeeconf) printf("File fee.conf not found, sampling frequency set to 40 MHz and data format to 1\n");
99
100
101
102   AliITSOnlineSDDInjectors **injan=new AliITSOnlineSDDInjectors*[kTotDDL*kModPerDDL*kSides];
103   TH2F **histo=new TH2F*[kTotDDL*kModPerDDL*kSides];
104   Int_t nWrittenEv[kTotDDL*kModPerDDL*kSides];
105   Bool_t isFilled[kTotDDL*kModPerDDL*kSides];
106
107   Char_t hisnam[20];
108   for(Int_t iddl=0; iddl<kTotDDL;iddl++){
109     for(Int_t imod=0; imod<kModPerDDL;imod++){
110       for(Int_t isid=0;isid<kSides;isid++){
111         Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
112         injan[index]=new AliITSOnlineSDDInjectors(iddl,imod,isid);
113         if(adcSamplFreq==20) injan[index]->Set20MHzConfig();
114         else injan[index]->Set40MHzConfig();
115         sprintf(hisnam,"h%02dc%02ds%d",iddl,imod,isid);
116         histo[index]=new TH2F(hisnam,"",256,-0.5,255.5,256,-0.5,255.5);
117         nWrittenEv[index]=0;
118         isFilled[index]=0;
119       }
120     }
121   }
122   
123   /* report progress */
124   daqDA_progressReport(10);
125   Int_t iev=0;
126   Int_t ievInj=0;
127   /* read the data files */
128   int n;
129   for (n=1;n<argc;n++) {
130    
131     status=monitorSetDataSource( argv[n] );
132     if (status!=0) {
133       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
134       return -1;
135     }
136
137     /* report progress */
138     /* in this example, indexed on the number of files */
139     // Progress report inside the event loop as well?
140     daqDA_progressReport(10+80*n/argc);
141
142     /* read the file */
143     for(;;) {
144       struct eventHeaderStruct *event;
145       eventTypeType eventT;
146
147       /* get next event */
148       status=monitorGetEventDynamic((void **)&event);
149       if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
150       if (status!=0) {
151         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
152         return -1;
153       }
154       /* retry if got no event */
155       if (event==NULL) {
156         break;
157       }
158       iev++;
159
160       
161       /* use event - here, just write event id to result file */
162       eventT=event->eventType;
163       switch (event->eventType){
164         
165         /* START OF RUN */
166       case START_OF_RUN:
167         break;
168         
169         /* END OF RUN */
170       case END_OF_RUN:
171         break;
172         
173         //      case PHYSICS_EVENT:  // comment this line for test raw data
174         //      break;               // comment this line for test raw data
175
176       case CALIBRATION_EVENT:
177         break;  // uncomment this line for test raw data
178       case PHYSICS_EVENT: // uncomment this line for test raw data
179         printf(" event number = %i \n",iev);
180         ievInj++; 
181         AliRawReader *rawReader = new AliRawReaderDate((void*)event);
182
183         UInt_t timeSt=rawReader->GetTimestamp();
184
185         Int_t evtyp=0;
186         while(rawReader->ReadHeader()){
187           const UInt_t *subev = rawReader->GetSubEventAttributes();
188           if(subev[0]==0 && subev[1]==0 && subev[2]==0) evtyp=1; 
189         }
190
191         rawReader->Reset();
192         for(Int_t iddl=0; iddl<kTotDDL;iddl++){
193           for(Int_t imod=0; imod<kModPerDDL;imod++){
194             for(Int_t isid=0;isid<kSides;isid++){
195               Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
196               histo[index]->Reset();
197             }
198           }
199         }
200         AliITSRawStream* s;
201         if(dataformat==0){
202           s=new AliITSRawStreamSDD(rawReader);
203         }else{
204           s=new AliITSRawStreamSDDCompressed(rawReader);
205           if(dataformat==1) s->SetADCEncoded(kTRUE);
206         }
207         
208         while(s->Next()){
209           Int_t iDDL=rawReader->GetDDLID();
210           Int_t iCarlos=s->GetCarlosId();
211           if(s->IsCompletedModule()) continue;
212           if(s->IsCompletedDDL()) continue;
213           if(iDDL>=0 && iDDL<kTotDDL){ 
214             Int_t index=kSides*(kModPerDDL*iDDL+iCarlos)+s->GetChannel(); 
215             histo[index]->Fill(s->GetCoord2(),s->GetCoord1(),s->GetSignal());
216             isFilled[index]=1;
217           }
218         }
219         delete rawReader;
220         for(Int_t iddl=0; iddl<kTotDDL;iddl++){
221           for(Int_t imod=0; imod<kModPerDDL;imod++){
222             for(Int_t isid=0;isid<kSides;isid++){
223               Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
224               if(isFilled[index]){
225                 injan[index]->Reset();
226                 injan[index]->AnalyzeEvent(histo[index]);    
227                 injan[index]->WriteToASCII(iev,timeSt,nWrittenEv[index]);
228                 nWrittenEv[index]++;
229               }
230             }
231           }
232         }
233         /* free resources */
234         free(event);
235       }
236       if(ievInj>=maxNEvents) break;
237     }
238   }
239   /* write report */
240   printf("Run #%s, received %d injector events\n",getenv("DATE_RUN_NUMBER"),ievInj);
241
242   gSystem->Exec("rm -f  SDDinj_LDC.tar");
243   Char_t filnam[100],command[120];
244   for(Int_t iddl=0; iddl<kTotDDL;iddl++){
245     for(Int_t imod=0; imod<kModPerDDL;imod++){
246       for(Int_t isid=0;isid<kSides;isid++){
247         Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
248         if(nWrittenEv[index]>0){
249           sprintf(filnam,"SDDinj_ddl%02dc%02d_sid%d.data",iddl,imod,isid);
250           sprintf(command,"tar -rf SDDinj_LDC.tar %s",filnam);
251           gSystem->Exec(command);
252         }
253       }  
254     }
255   }
256
257
258   /* report progress */
259   daqDA_progressReport(90);
260
261
262   status=daqDA_FES_storeFile("./SDDinj_LDC.tar","SDD_Injec");
263
264   /* report progress */
265   daqDA_progressReport(100);
266
267
268
269   return status;
270 }