]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/VZEROTUNING1da.cxx
Added loop on raw data files
[u/mrichter/AliRoot.git] / VZERO / VZEROTUNING1da.cxx
1 /*********************************************************************************
2 - Contact:    Brigitte Cheynis     b.cheynis@ipnl.in2p3.fr
3 - Link:       http
4 - Raw data test file : 
5 - Reference run number :              
6 - Run Type:   STANDALONE
7 - DA Type:    LDC
8 - Number of events needed: 500
9 - Input Files:  argument list
10 - Output Files: local file  V0_Tuning1.dat
11                 FXS file    V0_Tuning1.dat
12 - Trigger types used: PHYSICS_EVENT
13 **********************************************************************************/
14
15
16 /**********************************************************************************
17 *                                                                                 *
18 * VZERO Detector Algorithm used for tuning FEE parameters                         *
19 *                                                                                 *
20 * This program reads data on the LDC                                              *
21 * It cumulates fBB and fBG flags, populates local "./V0_Tuning1.dat"              *            
22 * file and exports it to the FES.                                                 *
23 * We have 128 channels instead of 64 as expected for V0 due to the two sets of    *
24 * charge integrators which are used by the FEE ...                                *
25 * The program reports about its processing progress.                              *
26 *                                                                                 *
27 ***********************************************************************************/
28
29 // DATE
30 #include "event.h"
31 #include "monitor.h"
32 #include "daqDA.h"
33
34 //AliRoot
35 #include <AliVZERORawStream.h>
36 #include <AliRawReaderDate.h>
37 #include <AliRawReader.h>
38 #include <AliDAQ.h>
39
40 // standard
41 #include <stdio.h>
42 #include <stdlib.h>
43
44 //ROOT
45 #include "TROOT.h"
46 #include "TPluginManager.h"
47 #include <TFile.h>
48 #include <TH1F.h>
49 #include <TMath.h>
50
51
52 /* Main routine --- Arguments: list of DATE raw data files */
53       
54 int main(int argc, char **argv) {
55
56 /* magic line from Cvetan */
57   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
58                     "*",
59                     "TStreamerInfo",
60                     "RIO",
61                     "TStreamerInfo()");
62   int status;
63
64   Float_t BBFlag[128];
65   Float_t BGFlag[128];
66   for(Int_t i=0; i<128; i++) {
67       BBFlag[i] = 0.0;
68       BGFlag[i] = 0.0;
69   } 
70       
71   /* log start of process */
72   printf("VZERO DA program started - Tuning FEE parameters\n");  
73
74   /* check that we got some arguments  */
75   if (argc<2)   {
76       printf("Wrong number of arguments\n");
77       return -1;}
78
79   /* open result file to be exported to FES */
80   FILE *fp=NULL;
81   fp=fopen("./V0_Tuning1.dat","a");
82   if (fp==NULL) {
83       printf("Failed to open result file\n");
84       return -1;}
85
86   /* open log file to inform user */
87   FILE *flog=NULL;
88   flog=fopen("./V00log.txt","a");
89   if (flog==NULL) {
90       printf("Failed to open log file\n");
91       return -1;  }
92     
93   /* report progress */
94   daqDA_progressReport(10);
95
96   /* init counters on events */
97   int nevents_physics=0;
98   int nevents_total=0;
99   
100   /* read the n data files */
101   for (int n=1; n<argc; n++) {
102   
103   /* read the data  */
104     status=monitorSetDataSource( argv[n] );
105     if (status!=0) {
106        printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
107        return -1; }
108
109   /* report progress */
110     daqDA_progressReport(10+50*n/argc);
111
112   /* read the data file */
113     for(;;) {
114         struct eventHeaderStruct *event;
115         eventTypeType eventT;
116
117         /* get next event */
118         status=monitorGetEventDynamic((void **)&event);
119         if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
120         if (status!=0) {
121             printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
122             return -1; }
123
124         /* retry if got no event */
125         if (event==NULL) break;
126         
127         /* decode event */
128         eventT=event->eventType;
129         
130         switch (event->eventType){
131       
132         case START_OF_RUN:
133              break;
134       
135         case END_OF_RUN:
136              printf("End Of Run detected\n");
137              break;
138       
139         case PHYSICS_EVENT:
140              nevents_physics++;
141
142              AliRawReader *rawReader = new AliRawReaderDate((void*)event);
143   
144              AliVZERORawStream* rawStream  = new AliVZERORawStream(rawReader); 
145              rawStream->Next(); 
146              for(Int_t i=0; i<64; i++) {
147                 if(!rawStream->GetIntegratorFlag(i,10))
148                 {
149                    if(rawStream->GetBBFlag(i,10)) BBFlag[i]++;       // even integrator - channel 0 to 63
150                    if(rawStream->GetBGFlag(i,10)) BGFlag[i]++;       // even integrator - channel 0 to 63
151                 } 
152                 else 
153                 {                  
154                    if(rawStream->GetBBFlag(i,10)) BBFlag[i+64]++;    // odd integrator  - channel 64 to 123
155                    if(rawStream->GetBGFlag(i,10)) BGFlag[i+64]++;    // odd integrator  - channel 64 to 123
156                 }
157              }    
158              delete rawStream;
159              rawStream = 0x0;      
160              delete rawReader;
161              rawReader = 0x0;                                                                    
162         } // end of switch on event type 
163         
164         nevents_total++;
165         /* free resources */
166         free(event);
167
168     }    // end of loop over events
169   }      // end of loop over data files 
170    
171 //________________________________________________________________________
172 //  Computes mean values, dumps them into the output text file
173         
174   for(Int_t i=0; i<128; i++) {
175       BBFlag[i] = BBFlag[i]/nevents_physics;
176       BGFlag[i] = BGFlag[i]/nevents_physics;
177       fprintf(fp," %d %f %f\n",i,BBFlag[i],BGFlag[i]);
178       fprintf(flog," %d %f %f\n",i,BBFlag[i],BGFlag[i]);
179   } 
180   fprintf(fp," End of current iteration \n");
181 //________________________________________________________________________
182    
183   /* write report */
184   fprintf(flog,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
185   printf("Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
186   
187   /* close result and log files */
188   fclose(fp);
189   fclose(flog); 
190   
191   /* report progress */
192   daqDA_progressReport(90);
193
194   /* export result file to FES */
195   status=daqDA_FES_storeFile("./V0_Tuning1.dat","V00da_results");
196   if (status)    {
197       printf("Failed to export file : %d\n",status);
198       return -1; }
199
200   /* report progress */
201   daqDA_progressReport(100);
202   
203   return status;
204 }