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