]>
Commit | Line | Data |
---|---|---|
e43e472f | 1 | /* |
2 | PMD DA for online calibration | |
3 | ||
4 | contact: basanta@phy.iitb.ac.in | |
338c285a | 5 | Link:http://www.veccal.ernet.in/~pmd/ |
6 | Reference run: | |
e43e472f | 7 | Run Type: PHYSICS |
8 | DA Type: MON | |
9 | Number of events needed: 1 million for PB+PB, 200 milion for p+p | |
338c285a | 10 | Input Files: |
e43e472f | 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 | ||
338c285a | 57 | TTree *ic = NULL; |
e43e472f | 58 | |
338c285a | 59 | //TH1F::AddDirectory(0); |
e43e472f | 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; | |
338c285a | 105 | eventTypeType eventT = 0; |
106 | ||
e43e472f | 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++; | |
338c285a | 150 | if(nevents_physics%100 == 0)printf("Physis Events = %d\n",nevents_physics); |
e43e472f | 151 | AliRawReader *rawReader = new AliRawReaderDate((void*)event); |
338c285a | 152 | TObjArray *pmdddlcont = new TObjArray(); |
153 | calibgain.ProcessEvent(rawReader, pmdddlcont); | |
e43e472f | 154 | |
338c285a | 155 | delete pmdddlcont; |
156 | pmdddlcont = 0x0; | |
e43e472f | 157 | delete rawReader; |
158 | rawReader = 0x0; | |
159 | ||
160 | } | |
161 | ||
162 | /* free resources */ | |
163 | free(event); | |
164 | ||
338c285a | 165 | } |
166 | ||
167 | /* exit when last event received, no need to wait for TERM signal */ | |
168 | if (eventT==END_OF_RUN) { | |
169 | printf("EOR event detected\n"); | |
170 | ||
171 | ic = new TTree("ic","PMD Gain tree"); | |
172 | calibgain.Analyse(ic); | |
173 | //break; | |
e43e472f | 174 | } |
175 | ||
176 | //write the Run level file | |
177 | TFile * fileRun = new TFile ("outPMDdaRun.root","RECREATE"); | |
178 | TBenchmark *bench = new TBenchmark(); | |
179 | bench->Start("PMD"); | |
180 | bench->Stop("PMD"); | |
181 | bench->Print("PMD"); | |
182 | fileRun->Close(); | |
183 | ||
184 | /* write report */ | |
185 | fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total); | |
186 | ||
e43e472f | 187 | |
338c285a | 188 | TFile * gainRun = new TFile ("PMDGAINS.root","RECREATE"); |
189 | ic->Write(); | |
e43e472f | 190 | gainRun->Close(); |
191 | ||
192 | ||
338c285a | 193 | delete ic; |
194 | ic = 0; | |
195 | ||
e43e472f | 196 | /* close result file */ |
197 | fclose(fp); | |
338c285a | 198 | |
e43e472f | 199 | return status; |
200 | } |