]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/PMDGAINda.cxx
tree defined outside if loop
[u/mrichter/AliRoot.git] / PMD / PMDGAINda.cxx
1 /*
2 PMD DA for online calibration
3
4 contact: basanta@phy.iitb.ac.in
5 Link:http://www.veccal.ernet.in/~pmd/
6 Reference run:
7 Run Type: PHYSICS
8 DA Type: MON
9 Number of events needed: 1 million for PB+PB, 200 milion for p+p
10 Input Files: 
11 Output Files: pmd_calib.root, to be exported to the DAQ FXS
12 Trigger types used: PHYSICS_EVENT
13
14 */
15 extern "C" {
16 #include <daqDA.h>
17 }
18
19 #include "event.h"
20 #include "monitor.h"
21 //#include "daqDA.h"
22
23 #include <Riostream.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26
27 //AliRoot
28 #include "AliRawReaderDate.h"
29 #include "AliPMDCalibPedestal.h"
30 #include "AliPMDCalibGain.h"
31
32 //ROOT
33 #include "TFile.h"
34 #include "TH1F.h"
35 #include "TBenchmark.h"
36 #include "TTree.h"
37 #include "TROOT.h"
38 #include "TPluginManager.h"
39
40
41
42 /* Main routine
43       Arguments: 
44       1- monitoring data source
45 */
46 int main(int argc, char **argv) {
47   
48     /* magic line from Rene */
49     gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
50                                           "*",
51                                           "TStreamerInfo",
52                                           "RIO",
53                                           "TStreamerInfo()");
54
55     AliPMDCalibGain calibgain;
56
57     TTree *ic = NULL;
58
59     //TH1F::AddDirectory(0);
60   
61     
62     // decoding the events
63     
64     int status;
65
66     if (argc!=2) {
67         printf("Wrong number of arguments\n");
68         return -1;
69     }
70     
71     /* open result file */
72     FILE *fp=NULL;
73     fp=fopen("./result.txt","a");
74     if (fp==NULL) {
75         printf("Failed to open file\n");
76         return -1;
77     }
78     
79     /* define data source : this is argument 1 */  
80     status=monitorSetDataSource( argv[1] );
81     if (status!=0) {
82         printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
83         return -1;
84     }
85     
86     /* declare monitoring program */
87     status=monitorDeclareMp( __FILE__ );
88     if (status!=0) {
89         printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
90         return -1;
91     }
92     
93     /* define wait event timeout - 1s max */
94     monitorSetNowait();
95     monitorSetNoWaitNetworkTimeout(1000);
96     
97     /* log start of process */
98     printf("DA example case2 monitoring program started\n");  
99     
100     /* init some counters */
101     int nevents_physics=0;
102     int nevents_total=0;
103     
104     struct eventHeaderStruct *event;
105     eventTypeType eventT = 0;
106
107     Int_t iev=0;
108     
109     /* main loop (infinite) */
110     for(;;) {
111         
112         /* check shutdown condition */
113         if (daqDA_checkShutdown()) {break;}
114         
115         /* get next event (blocking call until timeout) */
116         status=monitorGetEventDynamic((void **)&event);
117         if (status==MON_ERR_EOF) {
118             printf ("End of File detected\n");
119             break; /* end of monitoring file has been reached */
120         }
121         
122         if (status!=0) {
123             printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
124             break;
125         }
126         
127         /* retry if got no event */
128         if (event==NULL) {
129             continue;
130         }
131         
132         iev++; 
133         
134         /* use event - here, just write event id to result file */
135         nevents_total++;
136         eventT=event->eventType;
137         switch (event->eventType){
138       
139             /* START OF RUN */
140             case START_OF_RUN:
141                 break;
142                 /* END START OF RUN */
143                 
144                 /* END OF RUN */
145             case END_OF_RUN:
146                 break;
147                 
148             case PHYSICS_EVENT:
149                 nevents_physics++;
150                 if(nevents_physics%100 == 0)printf("Physis Events = %d\n",nevents_physics);
151                 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
152                 TObjArray *pmdddlcont = new TObjArray();
153                 calibgain.ProcessEvent(rawReader, pmdddlcont);
154
155                 delete pmdddlcont;
156                 pmdddlcont = 0x0;
157                 delete rawReader;
158                 rawReader = 0x0;
159                 
160         }
161        
162         /* free resources */
163         free(event);
164         
165     }
166
167     /* exit when last event received, no need to wait for TERM signal */
168
169     ic = new TTree("ic","PMD Gain tree");
170     if (eventT==END_OF_RUN) {
171       printf("EOR event detected\n");
172       calibgain.Analyse(ic);
173     }
174     
175     //write the Run level file   
176     TFile * fileRun = new TFile ("outPMDdaRun.root","RECREATE"); 
177     TBenchmark *bench = new TBenchmark();
178     bench->Start("PMD");
179     bench->Stop("PMD");
180     bench->Print("PMD");
181     fileRun->Close();
182     
183     /* write report */
184     fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
185     
186
187     TFile * gainRun = new TFile ("PMDGAINS.root","RECREATE"); 
188     ic->Write();
189     gainRun->Close();
190     
191     delete ic;
192     ic = 0;
193
194     /* close result file */
195     fclose(fp);
196
197     return status;
198 }