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