]>
Commit | Line | Data |
---|---|---|
e43e472f | 1 | /* |
2 | PMD DA for online calibration | |
3 | ||
4 | contact: basanta@phy.iitb.ac.in | |
d31b0352 | 5 | Link: |
6 | Reference run:/afs/cern.ch/user/b/bnandi/public/gaindata/pythia100evts.date | |
e43e472f | 7 | Run Type: PHYSICS |
8 | DA Type: MON | |
9 | Number of events needed: 1 million for PB+PB, 200 milion for p+p | |
d31b0352 | 10 | Input Files: PMD_PED.root, PMD_GAIN_CONFIGFILE, pmd_gain_tempfile.dat |
11 | Output Files: PMDGAINS.root, to be exported to the DAQ FES | |
e43e472f | 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" | |
e43e472f | 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 | ||
d31b0352 | 54 | |
55 | int status = 0; | |
56 | ||
57 | ||
9d1486e3 | 58 | Int_t filestatus = -1, xvar = 5; |
59 | Int_t totevt = -1, maxevt = -1; | |
1da50520 | 60 | |
61 | // Reads the pedestal file and keep the values in memory for subtraction | |
62 | ||
e43e472f | 63 | AliPMDCalibGain calibgain; |
d31b0352 | 64 | |
65 | // Fetch the pedestal file - PMD_PED.root | |
9d1486e3 | 66 | |
d31b0352 | 67 | status = daqDA_DB_getFile("PMD_PED.root","PMD_PED.root"); |
68 | ||
69 | if(!status) | |
70 | { | |
71 | printf("*** Pedestal file retrieved from DB *** \n"); | |
72 | } | |
73 | else | |
74 | { | |
75 | printf("*** Pedestal file NOT retrieved from DB *** \n"); | |
76 | return -1; | |
77 | } | |
9d1486e3 | 78 | |
d31b0352 | 79 | Int_t pstatus = calibgain.ExtractPedestal("PMD_PED.root"); |
1da50520 | 80 | |
81 | if(pstatus == -3) return -3; | |
e43e472f | 82 | |
9d1486e3 | 83 | TTree *ic = NULL; |
84 | TTree *meanc = NULL; | |
e43e472f | 85 | |
d31b0352 | 86 | // Retrieve the PMD_GAIN_CONFIGFILE |
87 | status = daqDA_DB_getFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE"); | |
88 | ||
1da50520 | 89 | FILE *fp1 = NULL; |
90 | ||
d31b0352 | 91 | fp1 = fopen("PMD_GAIN_CONFIGFILE","r"); |
1da50520 | 92 | |
93 | if (fp1 == NULL) | |
94 | { | |
d31b0352 | 95 | printf("*** PMD GAIN Configfile doesn't exist,Provide one ***\n"); |
96 | return -1; | |
1da50520 | 97 | } |
98 | else | |
99 | { | |
9d1486e3 | 100 | fscanf(fp1,"%d %d %d %d\n",&filestatus, &xvar, &totevt, &maxevt); |
101 | //printf("%d %d %d %d\n",filestatus, xvar, totevt, maxevt); | |
1da50520 | 102 | } |
103 | fclose(fp1); | |
9d1486e3 | 104 | |
e43e472f | 105 | |
1da50520 | 106 | if (filestatus == 1) |
107 | { | |
d31b0352 | 108 | // Retrieve the Temporray ascii file from DB |
109 | status = daqDA_DB_getFile("pmd_gain_tempfile.dat","pmd_gain_tempfile.dat"); | |
110 | if(!status) | |
111 | { | |
112 | calibgain.ReadTempFile("pmd_gain_tempfile.dat"); | |
113 | } | |
114 | else | |
115 | { | |
116 | printf("--- pmd_gain_tempfile.dat: not retrieved from DB ---\n"); | |
117 | } | |
9d1486e3 | 118 | // Retrieve the hot cell file from DB - PMD_HOT.root |
119 | status = daqDA_DB_getFile("PMD_HOT.root","PMD_HOT.root"); | |
120 | if(!status) | |
121 | { | |
122 | calibgain.ExtractHotChannel("PMD_HOT.root"); | |
123 | } | |
124 | else | |
125 | { | |
126 | printf("--- pmd_gain_tempfile.dat: not retrieved from DB ---\n"); | |
127 | } | |
1da50520 | 128 | } |
129 | ||
9d1486e3 | 130 | |
e43e472f | 131 | // decoding the events |
132 | ||
e43e472f | 133 | |
134 | if (argc!=2) { | |
135 | printf("Wrong number of arguments\n"); | |
136 | return -1; | |
137 | } | |
138 | ||
e43e472f | 139 | |
140 | /* define data source : this is argument 1 */ | |
141 | status=monitorSetDataSource( argv[1] ); | |
142 | if (status!=0) { | |
143 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
144 | return -1; | |
145 | } | |
146 | ||
147 | /* declare monitoring program */ | |
148 | status=monitorDeclareMp( __FILE__ ); | |
149 | if (status!=0) { | |
150 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
151 | return -1; | |
152 | } | |
153 | ||
154 | /* define wait event timeout - 1s max */ | |
155 | monitorSetNowait(); | |
156 | monitorSetNoWaitNetworkTimeout(1000); | |
157 | ||
158 | /* log start of process */ | |
1da50520 | 159 | printf("PMD GAIN DA - strted generating the gain of a cell\n"); |
e43e472f | 160 | |
161 | /* init some counters */ | |
162 | int nevents_physics=0; | |
163 | int nevents_total=0; | |
164 | ||
165 | struct eventHeaderStruct *event; | |
338c285a | 166 | eventTypeType eventT = 0; |
167 | ||
e43e472f | 168 | Int_t iev=0; |
169 | ||
170 | /* main loop (infinite) */ | |
171 | for(;;) { | |
172 | ||
173 | /* check shutdown condition */ | |
174 | if (daqDA_checkShutdown()) {break;} | |
175 | ||
176 | /* get next event (blocking call until timeout) */ | |
177 | status=monitorGetEventDynamic((void **)&event); | |
178 | if (status==MON_ERR_EOF) { | |
179 | printf ("End of File detected\n"); | |
180 | break; /* end of monitoring file has been reached */ | |
181 | } | |
182 | ||
183 | if (status!=0) { | |
184 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
185 | break; | |
186 | } | |
187 | ||
188 | /* retry if got no event */ | |
189 | if (event==NULL) { | |
190 | continue; | |
191 | } | |
192 | ||
193 | iev++; | |
194 | ||
195 | /* use event - here, just write event id to result file */ | |
196 | nevents_total++; | |
197 | eventT=event->eventType; | |
198 | switch (event->eventType){ | |
199 | ||
200 | /* START OF RUN */ | |
201 | case START_OF_RUN: | |
202 | break; | |
203 | /* END START OF RUN */ | |
204 | ||
205 | /* END OF RUN */ | |
206 | case END_OF_RUN: | |
207 | break; | |
208 | ||
209 | case PHYSICS_EVENT: | |
210 | nevents_physics++; | |
1da50520 | 211 | //if(nevents_physics%100 == 0)printf("Physis Events = %d\n",nevents_physics); |
e43e472f | 212 | AliRawReader *rawReader = new AliRawReaderDate((void*)event); |
338c285a | 213 | TObjArray *pmdddlcont = new TObjArray(); |
214 | calibgain.ProcessEvent(rawReader, pmdddlcont); | |
e43e472f | 215 | |
338c285a | 216 | delete pmdddlcont; |
217 | pmdddlcont = 0x0; | |
e43e472f | 218 | delete rawReader; |
219 | rawReader = 0x0; | |
220 | ||
221 | } | |
222 | ||
223 | /* free resources */ | |
224 | free(event); | |
225 | ||
338c285a | 226 | } |
227 | ||
228 | /* exit when last event received, no need to wait for TERM signal */ | |
40a42048 | 229 | |
9d1486e3 | 230 | |
231 | ic = new TTree("ic","PMD Gain tree"); | |
232 | meanc = new TTree("meanc","PMD Module mean tree"); | |
233 | ||
234 | if (filestatus == 0) | |
235 | { | |
236 | TFile *hotRun = new TFile ("PMD_HOT.root","RECREATE"); | |
237 | ||
238 | TTree *hot = new TTree("hot","PMD Hot cell tree"); | |
239 | ||
240 | calibgain.FindHotCell(hot,xvar); | |
241 | ||
242 | hot->Write(); | |
243 | hotRun->Close(); | |
244 | ||
245 | // store the hot cell root file in the DB | |
246 | ||
247 | status = daqDA_DB_storeFile("PMD_HOT.root","PMD_HOT.root"); | |
248 | } | |
249 | ||
e43e472f | 250 | |
1da50520 | 251 | totevt += nevents_physics++; |
252 | ||
d31b0352 | 253 | fp1 = fopen("PMD_GAIN_CONFIGFILE","w+"); |
1da50520 | 254 | |
255 | if (totevt < maxevt) | |
256 | { | |
d31b0352 | 257 | printf("-----------------------------------------------\n"); |
258 | printf("*** Required Number of Events not reached ***\n"); | |
259 | printf("*** Number of Events processed = %d ***\n",totevt); | |
260 | printf("*** Writing the intermediate ASCII file ***\n"); | |
261 | printf("-----------------------------------------------\n"); | |
262 | ||
263 | calibgain.WriteTempFile("pmd_gain_tempfile.dat"); | |
264 | ||
265 | // Store the Intermediate ascii file in the DB | |
266 | status = daqDA_DB_storeFile("pmd_gain_tempfile.dat","pmd_gain_tempfile.dat"); | |
1da50520 | 267 | |
268 | filestatus = 1; | |
9d1486e3 | 269 | fprintf(fp1,"%d %d %d %d\n",filestatus,xvar,totevt,maxevt); |
270 | fclose(fp1); | |
d31b0352 | 271 | |
272 | // Store the configfile in the DB | |
273 | status = daqDA_DB_storeFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE"); | |
274 | ||
1da50520 | 275 | } |
276 | else if (totevt >= maxevt) | |
277 | { | |
d31b0352 | 278 | printf("-----------------------------------------------\n"); |
279 | printf("*** Required Number of Events reached = %d ***\n",totevt); | |
280 | printf("*** Writing the PMDGAINS.root file ***\n"); | |
281 | printf("-----------------------------------------------\n"); | |
282 | ||
9d1486e3 | 283 | calibgain.Analyse(ic, meanc); |
1da50520 | 284 | |
285 | TFile * gainRun = new TFile ("PMDGAINS.root","RECREATE"); | |
286 | ic->Write(); | |
287 | gainRun->Close(); | |
288 | ||
9d1486e3 | 289 | TFile * meanRun = new TFile ("PMD_MEAN_SM.root","RECREATE"); |
290 | meanc->Write(); | |
291 | meanRun->Close(); | |
292 | ||
293 | ||
1da50520 | 294 | filestatus = 0; |
295 | totevt = 0; | |
9d1486e3 | 296 | fprintf(fp1,"%d %d %d %d\n",filestatus,xvar,totevt,maxevt); |
297 | fclose(fp1); | |
d31b0352 | 298 | |
299 | // Store the configfile in the DB | |
300 | status = daqDA_DB_storeFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE"); | |
1da50520 | 301 | } |
e43e472f | 302 | |
338c285a | 303 | delete ic; |
304 | ic = 0; | |
9d1486e3 | 305 | |
306 | delete meanc; | |
307 | meanc = 0; | |
1da50520 | 308 | |
309 | ||
310 | /* store the result file on FES */ | |
311 | ||
312 | if (filestatus == 0) | |
313 | { | |
9d1486e3 | 314 | printf("root file for cell gain is created and getting exported\n"); |
a5f36c63 | 315 | status = daqDA_FES_storeFile("PMDGAINS.root","PMDGAINS.root"); |
9d1486e3 | 316 | printf("root file for hot cell is created and getting exported\n"); |
317 | status = daqDA_FES_storeFile("PMD_HOT.root","PMD_HOT.root"); | |
318 | printf("root file for normalised means of different modules\n"); | |
319 | status = daqDA_FES_storeFile("PMD_MEAN_SM.root","PMD_MEAN_SM.root"); | |
1da50520 | 320 | } |
9d1486e3 | 321 | |
1da50520 | 322 | if (status) { |
323 | status = -2; | |
324 | } | |
338c285a | 325 | |
338c285a | 326 | |
9d1486e3 | 327 | |
e43e472f | 328 | return status; |
329 | } |