2 PMD DA for online calibration
4 contact: basanta@iitb.ac.in, Satyajit.Jena@cern.ch
5 Link: https://twiki.cern.ch/twiki/bin/view/ALICE/DA
6 Reference run:/afs/cern.ch/user/s/sjena/public/run83496.raw
9 Number of events needed: 1 million for PB+PB, 200 milion for p+p
10 Input Files: PMD/Calib/Mapping/Run0_999999999_v0_s0.root, PMD_PED.root, PMD_GAIN_CONFIGFILE, pmd_gain_tempfile.dat
11 Output Files: PMDGAINS.root, to be exported to the DAQ FES
12 Trigger types used: PHYSICS_EVENT
22 #include <Riostream.h>
27 #include "AliRawReaderDate.h"
28 #include "AliPMDCalibPedestal.h"
29 #include "AliPMDCalibGain.h"
31 #include "AliCDBManager.h"
36 #include "TBenchmark.h"
39 #include "TPluginManager.h"
45 1- monitoring data source
47 int main(int argc, char **argv) {
49 /* magic line from Rene */
50 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
60 Int_t filestatus = -1, xvar = 5;
61 Int_t totevt = -1, maxevt = -1;
62 Int_t hotevtsize = -1;
63 Bool_t hotfilestatus = false;
65 // Reads the pedestal file and keep the values in memory for subtraction
67 AliPMDCalibGain *calibgain = new AliPMDCalibGain();
69 // Fetch the pedestal file - PMD_PED.root
71 status = daqDA_DB_getFile("PMD_PED.root","PMD_PED.root");
75 printf("*** Pedestal file retrieved from DB *** \n");
79 printf("*** Pedestal file NOT retrieved from DB *** \n");
83 Int_t pstatus = calibgain->ExtractPedestal("PMD_PED.root");
85 if(pstatus == -3) return -3;
90 // Retrieve the PMD_GAIN_CONFIGFILE
91 status = daqDA_DB_getFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE");
95 fp1 = fopen("PMD_GAIN_CONFIGFILE","r");
99 printf("*** PMD GAIN Configfile doesn't exist,Provide one ***\n");
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);
112 // Retrieve the Temporray ascii file from DB
113 status = daqDA_DB_getFile("pmd_gain_tempfile.dat","pmd_gain_tempfile.dat");
116 calibgain->ReadTempFile("pmd_gain_tempfile.dat");
120 printf("--- pmd_gain_tempfile.dat: not retrieved from DB ---\n");
122 // Retrieve the hot cell file from DB - PMD_HOT.root
123 status = daqDA_DB_getFile("PMD_HOT.root","PMD_HOT.root");
126 calibgain->ExtractHotChannel("PMD_HOT.root");
130 printf("--- pmd_gain_tempfile.dat: not retrieved from DB ---\n");
135 // decoding the events
139 printf("Wrong number of arguments\n");
144 /* define data source : this is argument 1 */
145 status=monitorSetDataSource( argv[1] );
147 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
151 /* declare monitoring program */
152 status=monitorDeclareMp( __FILE__ );
154 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
158 /* define wait event timeout - 1s max */
160 monitorSetNoWaitNetworkTimeout(1000);
162 /* log start of process */
163 printf("PMD GAIN DA - strted generating the gain of a cell\n");
165 /* init some counters */
166 int nevents_physics=0;
169 struct eventHeaderStruct *event;
170 eventTypeType eventT = 0;
178 if (getenv("DATE_RUN_NUMBER")==0) {
179 printf("DATE_RUN_NUMBER not properly set.\n");
180 printf("Run Number set to Zero \n");
185 runNr = atoi(getenv("DATE_RUN_NUMBER"));
188 if (gSystem->AccessPathName("localOCDB/PMD/Calib/Mapping",kFileExists))
190 if (gSystem->mkdir("localOCDB/PMD/Calib/Mapping",kTRUE) != 0)
192 printf("Failed to create directory: localOCDB/PMD/Calib/Mapping");
196 status = daqDA_DB_getFile("PMD/Calib/Mapping/Run0_999999999_v0_s0.root","localOCDB/PMD/Calib/Mapping/Run0_999999999_v0_s0.root");
199 printf("Failed to get PMD-Mapping file (PMD/Calib/Mapping/Run0_999999999_v0_s0.root) from DAQdetDB, status=%d\n", status);
203 // Global initializations
204 AliLog::SetGlobalLogLevel(AliLog::kError);
205 AliCDBManager *man = AliCDBManager::Instance();
206 man->SetDefaultStorage("local://localOCDB");
210 /* main loop (infinite) */
213 /* check shutdown condition */
214 if (daqDA_checkShutdown()) {break;}
216 /* get next event (blocking call until timeout) */
217 status=monitorGetEventDynamic((void **)&event);
218 if (status==MON_ERR_EOF) {
219 printf ("End of File detected\n");
220 break; /* end of monitoring file has been reached */
224 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
228 /* retry if got no event */
235 /* use event - here, just write event id to result file */
237 eventT=event->eventType;
238 switch (event->eventType){
243 /* END START OF RUN */
252 //if(nevents_physics%100 == 0)printf("Physis Events = %d\n",nevents_physics);
253 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
254 TObjArray *pmdddlcont = new TObjArray();
255 calibgain->ProcessEvent(rawReader, pmdddlcont);
257 if (totevt%hotevtsize == 0) hotfilestatus = true;
270 /* exit when last event received, no need to wait for TERM signal */
273 ic = new TTree("ic","PMD Gain tree");
274 meanc = new TTree("meanc","PMD Module mean tree");
278 TFile *hotRun = new TFile ("PMD_HOT.root","RECREATE");
280 TTree *hot = new TTree("hot","PMD Hot cell tree");
282 calibgain->FindHotCell(hot,xvar);
287 // store the hot cell root file in the DB
289 status = daqDA_DB_storeFile("PMD_HOT.root","PMD_HOT.root");
291 // store the hot cell root file in the file exchange server
293 printf("root file for hot cell is created and getting exported\n");
294 status = daqDA_FES_storeFile("PMD_HOT.root","PMD_HOT.root");
299 TFile *hotRun = new TFile ("PMD_HOT.root","RECREATE");
301 TTree *hot = new TTree("hot","PMD Hot cell tree");
303 calibgain->FindHotCell(hot,xvar);
308 // store the hot cell root file in the DB
310 status = daqDA_DB_storeFile("PMD_HOT.root","PMD_HOT.root");
312 // store the hot cell root file in the file exchange server
314 printf("root file for hot cell is created and getting exported\n");
315 status = daqDA_FES_storeFile("PMD_HOT.root","PMD_HOT.root");
319 fp1 = fopen("PMD_GAIN_CONFIGFILE","w+");
323 printf("-----------------------------------------------\n");
324 printf("*** Required Number of Events not reached ***\n");
325 printf("*** Number of Events processed = %d ***\n",totevt);
326 printf("*** Writing the intermediate ASCII file ***\n");
327 printf("-----------------------------------------------\n");
329 calibgain->WriteTempFile("pmd_gain_tempfile.dat");
331 // Store the Intermediate ascii file in the DB
332 status = daqDA_DB_storeFile("pmd_gain_tempfile.dat","pmd_gain_tempfile.dat");
335 fprintf(fp1,"%d %d %d %d %d\n",filestatus,xvar,totevt,maxevt,hotevtsize);
338 // Store the configfile in the DB
339 status = daqDA_DB_storeFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE");
342 else if (totevt >= maxevt)
344 printf("-----------------------------------------------\n");
345 printf("*** Required Number of Events reached = %d ***\n",totevt);
346 printf("*** Writing the PMDGAINS.root file ***\n");
347 printf("-----------------------------------------------\n");
349 calibgain->Analyse(ic, meanc);
351 TFile * gainRun = new TFile ("PMDGAINS.root","RECREATE");
355 TFile * meanRun = new TFile ("PMD_MEAN_SM.root","RECREATE");
362 fprintf(fp1,"%d %d %d %d %d\n",filestatus,xvar,totevt,maxevt,hotevtsize);
365 // Store the configfile in the DB
366 status = daqDA_DB_storeFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE");
377 /* store the result file on FES */
381 printf("root file for cell gain is created and getting exported\n");
382 status = daqDA_FES_storeFile("PMDGAINS.root","PMDGAINS.root");
383 printf("root file for normalised means of different modules\n");
384 status = daqDA_FES_storeFile("PMD_MEAN_SM.root","PMD_MEAN_SM.root");