]>
Commit | Line | Data |
---|---|---|
e43e472f | 1 | /* |
2 | PMD DA for online calibration | |
3 | ||
4 | contact: basanta@phy.iitb.ac.in | |
d31b0352 | 5 | Link: |
53fa2405 | 6 | Reference run:/afs/cern.ch/user/s/sjena/public/run83496.raw |
e43e472f | 7 | Run Type: PHYSICS |
8 | DA Type: MON | |
9 | Number of events needed: 1 million for PB+PB, 200 milion for p+p | |
53fa2405 | 10 | Input Files: Run0_999999999_v0_s0.root,PMD_PED.root, PMD_GAIN_CONFIGFILE, pmd_gain_tempfile.dat |
d31b0352 | 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" | |
ee562d68 | 30 | #include "AliLog.h" |
31 | #include "AliCDBManager.h" | |
e43e472f | 32 | |
33 | //ROOT | |
34 | #include "TFile.h" | |
35 | #include "TH1F.h" | |
36 | #include "TBenchmark.h" | |
37 | #include "TTree.h" | |
38 | #include "TROOT.h" | |
39 | #include "TPluginManager.h" | |
ee562d68 | 40 | #include "TSystem.h" |
e43e472f | 41 | |
42 | ||
43 | /* Main routine | |
44 | Arguments: | |
45 | 1- monitoring data source | |
46 | */ | |
47 | int main(int argc, char **argv) { | |
48 | ||
49 | /* magic line from Rene */ | |
50 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", | |
51 | "*", | |
52 | "TStreamerInfo", | |
53 | "RIO", | |
54 | "TStreamerInfo()"); | |
55 | ||
d31b0352 | 56 | |
57 | int status = 0; | |
58 | ||
59 | ||
9d1486e3 | 60 | Int_t filestatus = -1, xvar = 5; |
61 | Int_t totevt = -1, maxevt = -1; | |
b2a5fcdc | 62 | Int_t hotevtsize = -1; |
63 | Bool_t hotfilestatus = false; | |
1da50520 | 64 | |
65 | // Reads the pedestal file and keep the values in memory for subtraction | |
66 | ||
b9007181 | 67 | AliPMDCalibGain *calibgain = new AliPMDCalibGain(); |
d31b0352 | 68 | |
69 | // Fetch the pedestal file - PMD_PED.root | |
9d1486e3 | 70 | |
d31b0352 | 71 | status = daqDA_DB_getFile("PMD_PED.root","PMD_PED.root"); |
72 | ||
73 | if(!status) | |
74 | { | |
75 | printf("*** Pedestal file retrieved from DB *** \n"); | |
76 | } | |
77 | else | |
78 | { | |
79 | printf("*** Pedestal file NOT retrieved from DB *** \n"); | |
80 | return -1; | |
81 | } | |
9d1486e3 | 82 | |
b9007181 | 83 | Int_t pstatus = calibgain->ExtractPedestal("PMD_PED.root"); |
1da50520 | 84 | |
85 | if(pstatus == -3) return -3; | |
e43e472f | 86 | |
9d1486e3 | 87 | TTree *ic = NULL; |
88 | TTree *meanc = NULL; | |
e43e472f | 89 | |
d31b0352 | 90 | // Retrieve the PMD_GAIN_CONFIGFILE |
91 | status = daqDA_DB_getFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE"); | |
92 | ||
1da50520 | 93 | FILE *fp1 = NULL; |
94 | ||
d31b0352 | 95 | fp1 = fopen("PMD_GAIN_CONFIGFILE","r"); |
1da50520 | 96 | |
97 | if (fp1 == NULL) | |
98 | { | |
d31b0352 | 99 | printf("*** PMD GAIN Configfile doesn't exist,Provide one ***\n"); |
100 | return -1; | |
1da50520 | 101 | } |
102 | else | |
103 | { | |
b2a5fcdc | 104 | fscanf(fp1,"%d %d %d %d %d\n",&filestatus, &xvar, &totevt, &maxevt, &hotevtsize); |
105 | //printf("%d %d %d %d %d\n",filestatus, xvar, totevt, maxevt, hotevtsize); | |
1da50520 | 106 | } |
107 | fclose(fp1); | |
9d1486e3 | 108 | |
e43e472f | 109 | |
1da50520 | 110 | if (filestatus == 1) |
111 | { | |
d31b0352 | 112 | // Retrieve the Temporray ascii file from DB |
113 | status = daqDA_DB_getFile("pmd_gain_tempfile.dat","pmd_gain_tempfile.dat"); | |
114 | if(!status) | |
115 | { | |
b9007181 | 116 | calibgain->ReadTempFile("pmd_gain_tempfile.dat"); |
d31b0352 | 117 | } |
118 | else | |
119 | { | |
120 | printf("--- pmd_gain_tempfile.dat: not retrieved from DB ---\n"); | |
121 | } | |
9d1486e3 | 122 | // Retrieve the hot cell file from DB - PMD_HOT.root |
123 | status = daqDA_DB_getFile("PMD_HOT.root","PMD_HOT.root"); | |
124 | if(!status) | |
125 | { | |
b9007181 | 126 | calibgain->ExtractHotChannel("PMD_HOT.root"); |
9d1486e3 | 127 | } |
128 | else | |
129 | { | |
130 | printf("--- pmd_gain_tempfile.dat: not retrieved from DB ---\n"); | |
131 | } | |
1da50520 | 132 | } |
133 | ||
9d1486e3 | 134 | |
e43e472f | 135 | // decoding the events |
136 | ||
e43e472f | 137 | |
138 | if (argc!=2) { | |
139 | printf("Wrong number of arguments\n"); | |
140 | return -1; | |
141 | } | |
142 | ||
e43e472f | 143 | |
144 | /* define data source : this is argument 1 */ | |
145 | status=monitorSetDataSource( argv[1] ); | |
146 | if (status!=0) { | |
147 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
148 | return -1; | |
149 | } | |
150 | ||
151 | /* declare monitoring program */ | |
152 | status=monitorDeclareMp( __FILE__ ); | |
153 | if (status!=0) { | |
154 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
155 | return -1; | |
156 | } | |
157 | ||
158 | /* define wait event timeout - 1s max */ | |
159 | monitorSetNowait(); | |
160 | monitorSetNoWaitNetworkTimeout(1000); | |
161 | ||
162 | /* log start of process */ | |
1da50520 | 163 | printf("PMD GAIN DA - strted generating the gain of a cell\n"); |
e43e472f | 164 | |
165 | /* init some counters */ | |
166 | int nevents_physics=0; | |
167 | int nevents_total=0; | |
168 | ||
169 | struct eventHeaderStruct *event; | |
338c285a | 170 | eventTypeType eventT = 0; |
171 | ||
e43e472f | 172 | Int_t iev=0; |
ee562d68 | 173 | |
174 | // Get run number | |
0073c15c | 175 | |
ee562d68 | 176 | if (getenv("DATE_RUN_NUMBER")==0) { |
177 | printf("DATE_RUN_NUMBER not properly set.\n"); | |
178 | return -1; | |
179 | } | |
180 | int runNr = atoi(getenv("DATE_RUN_NUMBER")); | |
ee562d68 | 181 | |
0073c15c | 182 | //int runNr = 0; |
ee562d68 | 183 | |
184 | if (gSystem->AccessPathName("localOCDB/PMD/Calib/Mapping",kFileExists)) | |
185 | { | |
186 | if (gSystem->mkdir("localOCDB/PMD/Calib/Mapping",kTRUE) != 0) | |
187 | { | |
188 | printf("Failed to create directory: localOCDB/PMD/Calib/Mapping"); | |
189 | return -1; | |
190 | } | |
191 | } | |
192 | status = daqDA_DB_getFile("PMD/Calib/Mapping","localOCDB/PMD/Calib/Mapping/Run0_999999999_v0_s0.root"); | |
193 | if (status) | |
194 | { | |
195 | printf("Failed to get PMD-Mapping file (PMD/Calib/Mapping) from DAQdetDB, status=%d\n", status); | |
196 | return -1; | |
197 | } | |
198 | ||
199 | // Global initializations | |
200 | AliLog::SetGlobalLogLevel(AliLog::kError); | |
201 | AliCDBManager *man = AliCDBManager::Instance(); | |
202 | man->SetDefaultStorage("local://localOCDB"); | |
203 | man->SetRun(runNr); | |
204 | ||
e43e472f | 205 | |
206 | /* main loop (infinite) */ | |
207 | for(;;) { | |
208 | ||
209 | /* check shutdown condition */ | |
210 | if (daqDA_checkShutdown()) {break;} | |
211 | ||
212 | /* get next event (blocking call until timeout) */ | |
213 | status=monitorGetEventDynamic((void **)&event); | |
214 | if (status==MON_ERR_EOF) { | |
215 | printf ("End of File detected\n"); | |
216 | break; /* end of monitoring file has been reached */ | |
217 | } | |
218 | ||
219 | if (status!=0) { | |
220 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
221 | break; | |
222 | } | |
223 | ||
224 | /* retry if got no event */ | |
225 | if (event==NULL) { | |
226 | continue; | |
227 | } | |
228 | ||
229 | iev++; | |
230 | ||
231 | /* use event - here, just write event id to result file */ | |
232 | nevents_total++; | |
233 | eventT=event->eventType; | |
234 | switch (event->eventType){ | |
235 | ||
236 | /* START OF RUN */ | |
237 | case START_OF_RUN: | |
238 | break; | |
239 | /* END START OF RUN */ | |
240 | ||
241 | /* END OF RUN */ | |
242 | case END_OF_RUN: | |
243 | break; | |
244 | ||
245 | case PHYSICS_EVENT: | |
246 | nevents_physics++; | |
b2a5fcdc | 247 | totevt++; |
1da50520 | 248 | //if(nevents_physics%100 == 0)printf("Physis Events = %d\n",nevents_physics); |
e43e472f | 249 | AliRawReader *rawReader = new AliRawReaderDate((void*)event); |
338c285a | 250 | TObjArray *pmdddlcont = new TObjArray(); |
b9007181 | 251 | calibgain->ProcessEvent(rawReader, pmdddlcont); |
e43e472f | 252 | |
b2a5fcdc | 253 | if (totevt%hotevtsize == 0) hotfilestatus = true; |
338c285a | 254 | delete pmdddlcont; |
255 | pmdddlcont = 0x0; | |
e43e472f | 256 | delete rawReader; |
257 | rawReader = 0x0; | |
258 | ||
259 | } | |
260 | ||
261 | /* free resources */ | |
262 | free(event); | |
263 | ||
338c285a | 264 | } |
265 | ||
266 | /* exit when last event received, no need to wait for TERM signal */ | |
40a42048 | 267 | |
9d1486e3 | 268 | |
269 | ic = new TTree("ic","PMD Gain tree"); | |
270 | meanc = new TTree("meanc","PMD Module mean tree"); | |
271 | ||
272 | if (filestatus == 0) | |
273 | { | |
274 | TFile *hotRun = new TFile ("PMD_HOT.root","RECREATE"); | |
275 | ||
276 | TTree *hot = new TTree("hot","PMD Hot cell tree"); | |
277 | ||
b9007181 | 278 | calibgain->FindHotCell(hot,xvar); |
9d1486e3 | 279 | |
280 | hot->Write(); | |
281 | hotRun->Close(); | |
282 | ||
283 | // store the hot cell root file in the DB | |
284 | ||
285 | status = daqDA_DB_storeFile("PMD_HOT.root","PMD_HOT.root"); | |
b2a5fcdc | 286 | |
287 | // store the hot cell root file in the file exchange server | |
288 | ||
289 | printf("root file for hot cell is created and getting exported\n"); | |
290 | status = daqDA_FES_storeFile("PMD_HOT.root","PMD_HOT.root"); | |
9d1486e3 | 291 | } |
292 | ||
b2a5fcdc | 293 | if (hotfilestatus) |
294 | { | |
295 | TFile *hotRun = new TFile ("PMD_HOT.root","RECREATE"); | |
296 | ||
297 | TTree *hot = new TTree("hot","PMD Hot cell tree"); | |
298 | ||
b9007181 | 299 | calibgain->FindHotCell(hot,xvar); |
b2a5fcdc | 300 | |
301 | hot->Write(); | |
302 | hotRun->Close(); | |
303 | ||
304 | // store the hot cell root file in the DB | |
305 | ||
306 | status = daqDA_DB_storeFile("PMD_HOT.root","PMD_HOT.root"); | |
307 | ||
308 | // store the hot cell root file in the file exchange server | |
309 | ||
310 | printf("root file for hot cell is created and getting exported\n"); | |
311 | status = daqDA_FES_storeFile("PMD_HOT.root","PMD_HOT.root"); | |
312 | } | |
e43e472f | 313 | |
1da50520 | 314 | |
d31b0352 | 315 | fp1 = fopen("PMD_GAIN_CONFIGFILE","w+"); |
1da50520 | 316 | |
317 | if (totevt < maxevt) | |
318 | { | |
d31b0352 | 319 | printf("-----------------------------------------------\n"); |
320 | printf("*** Required Number of Events not reached ***\n"); | |
321 | printf("*** Number of Events processed = %d ***\n",totevt); | |
322 | printf("*** Writing the intermediate ASCII file ***\n"); | |
323 | printf("-----------------------------------------------\n"); | |
324 | ||
b9007181 | 325 | calibgain->WriteTempFile("pmd_gain_tempfile.dat"); |
d31b0352 | 326 | |
327 | // Store the Intermediate ascii file in the DB | |
328 | status = daqDA_DB_storeFile("pmd_gain_tempfile.dat","pmd_gain_tempfile.dat"); | |
1da50520 | 329 | |
330 | filestatus = 1; | |
b2a5fcdc | 331 | fprintf(fp1,"%d %d %d %d %d\n",filestatus,xvar,totevt,maxevt,hotevtsize); |
9d1486e3 | 332 | fclose(fp1); |
d31b0352 | 333 | |
334 | // Store the configfile in the DB | |
335 | status = daqDA_DB_storeFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE"); | |
336 | ||
1da50520 | 337 | } |
338 | else if (totevt >= maxevt) | |
339 | { | |
d31b0352 | 340 | printf("-----------------------------------------------\n"); |
341 | printf("*** Required Number of Events reached = %d ***\n",totevt); | |
342 | printf("*** Writing the PMDGAINS.root file ***\n"); | |
343 | printf("-----------------------------------------------\n"); | |
344 | ||
b9007181 | 345 | calibgain->Analyse(ic, meanc); |
1da50520 | 346 | |
347 | TFile * gainRun = new TFile ("PMDGAINS.root","RECREATE"); | |
348 | ic->Write(); | |
349 | gainRun->Close(); | |
350 | ||
9d1486e3 | 351 | TFile * meanRun = new TFile ("PMD_MEAN_SM.root","RECREATE"); |
352 | meanc->Write(); | |
353 | meanRun->Close(); | |
354 | ||
355 | ||
1da50520 | 356 | filestatus = 0; |
357 | totevt = 0; | |
b2a5fcdc | 358 | fprintf(fp1,"%d %d %d %d %d\n",filestatus,xvar,totevt,maxevt,hotevtsize); |
9d1486e3 | 359 | fclose(fp1); |
d31b0352 | 360 | |
361 | // Store the configfile in the DB | |
362 | status = daqDA_DB_storeFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE"); | |
1da50520 | 363 | } |
e43e472f | 364 | |
338c285a | 365 | delete ic; |
366 | ic = 0; | |
9d1486e3 | 367 | |
368 | delete meanc; | |
369 | meanc = 0; | |
1da50520 | 370 | |
b9007181 | 371 | delete calibgain; |
1da50520 | 372 | |
373 | /* store the result file on FES */ | |
374 | ||
375 | if (filestatus == 0) | |
376 | { | |
9d1486e3 | 377 | printf("root file for cell gain is created and getting exported\n"); |
a5f36c63 | 378 | status = daqDA_FES_storeFile("PMDGAINS.root","PMDGAINS.root"); |
9d1486e3 | 379 | printf("root file for normalised means of different modules\n"); |
380 | status = daqDA_FES_storeFile("PMD_MEAN_SM.root","PMD_MEAN_SM.root"); | |
1da50520 | 381 | } |
b2a5fcdc | 382 | |
383 | if (hotfilestatus) | |
384 | { | |
385 | } | |
386 | ||
9d1486e3 | 387 | |
1da50520 | 388 | if (status) { |
389 | status = -2; | |
390 | } | |
338c285a | 391 | |
338c285a | 392 | |
9d1486e3 | 393 | |
e43e472f | 394 | return status; |
395 | } |