]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/VZEROTUNING2da.cxx
Added missing part in StepManager for handling V0A
[u/mrichter/AliRoot.git] / VZERO / VZEROTUNING2da.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_Tuning2.dat
11                 FXS file    V0_Tuning2.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 mean ADC responses ,  populates local  "./V0_Tuning2.dat"  file    * 
22 * 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 ADC_Mean[128];
65   for(Int_t i=0; i<128; i++) {
66       ADC_Mean[i] = 0.0;
67   } 
68       
69   /* log start of process */
70   printf("VZERO DA program started - Tuning FEE parameters\n");  
71
72   /* check that we got some arguments = list of files */
73   if (argc<2)   {
74       printf("Wrong number of arguments\n");
75       return -1;}
76                
77   /* open result file to be exported to FES */
78   FILE *fp=NULL;
79   fp=fopen("./V0_Tuning2.dat","a");
80   if (fp==NULL) {
81       printf("Failed to open result file\n");
82       return -1;}
83
84   /* open log file to inform user */
85   FILE *flog=NULL;
86   flog=fopen("./V00log.txt","a");
87   if (flog==NULL) {
88       printf("Failed to open log file\n");
89       return -1;  }
90     
91   /* report progress */
92   daqDA_progressReport(10);
93
94   /* init counters on events */
95   int nevents_physics=0;
96   int nevents_total=0;
97   int iteration;
98   sscanf(argv[1],"%d",&iteration);
99   
100   /* read the n data files */
101   for (int n=2; 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                     ADC_Mean[i]=ADC_Mean[i]+rawStream->GetADC(i);       // even integrator 
150                 }
151                 else 
152                 {                  
153                     ADC_Mean[i+64]=ADC_Mean[i+64]+rawStream->GetADC(i); // odd integrator
154                 }
155              }    
156              delete rawStream;
157              rawStream = 0x0;      
158              delete rawReader;
159              rawReader = 0x0;                                                                    
160         } // end of switch on event type 
161         
162         nevents_total++;
163         /* free resources */
164         free(event);
165
166     }    // end of loop over events
167   }      // end of loop over data files 
168
169 //________________________________________________________________________
170 //  Computes mean values, dumps them into the output text file
171         
172   for(Int_t i=0; i<128; i++) {
173       ADC_Mean[i]=ADC_Mean[i]/nevents_physics;
174       fprintf(fp," %d %d %f\n",iteration,i,ADC_Mean[i]);
175       fprintf(flog,"%d %d %f\n",iteration,i,ADC_Mean[i]);
176   } 
177   
178 //________________________________________________________________________
179    
180   /* write report */
181   fprintf(flog,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
182   printf("Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
183   
184   /* close result and log files */
185   fclose(fp);
186   fclose(flog); 
187   
188   /* report progress */
189   daqDA_progressReport(90);
190
191   /* export result file to FES */
192   status=daqDA_FES_storeFile("./V0_Tuning2.dat","V00da_results");
193   if (status)    {
194       printf("Failed to export file : %d\n",status);
195       return -1; }
196
197   /* report progress */
198   daqDA_progressReport(100);
199   
200   return status;
201 }