2 PMD DA for online calibration
4 contact: basanta@phy.iitb.ac.in
6 Reference run:/afs/cern.ch/user/b/bnandi/public/gaindata/pythia100evts.date
9 Number of events needed: 1 million for PB+PB, 200 milion for p+p
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
12 Trigger types used: PHYSICS_EVENT
23 #include <Riostream.h>
28 #include "AliRawReaderDate.h"
29 #include "AliPMDCalibPedestal.h"
30 #include "AliPMDCalibGain.h"
35 #include "TBenchmark.h"
38 #include "TPluginManager.h"
44 1- monitoring data source
46 int main(int argc, char **argv) {
48 /* magic line from Rene */
49 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
59 Int_t filestatus = -1, totevt = -1;
62 // Reads the pedestal file and keep the values in memory for subtraction
64 AliPMDCalibGain calibgain;
66 // Fetch the pedestal file - PMD_PED.root
67 status = daqDA_DB_getFile("PMD_PED.root","PMD_PED.root");
71 printf("*** Pedestal file retrieved from DB *** \n");
75 printf("*** Pedestal file NOT retrieved from DB *** \n");
79 Int_t pstatus = calibgain.ExtractPedestal("PMD_PED.root");
81 if(pstatus == -3) return -3;
85 // Retrieve the PMD_GAIN_CONFIGFILE
86 status = daqDA_DB_getFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE");
90 fp1 = fopen("PMD_GAIN_CONFIGFILE","r");
94 printf("*** PMD GAIN Configfile doesn't exist,Provide one ***\n");
99 fscanf(fp1,"%d %d %d\n",&filestatus, &totevt,&maxevt);
100 //printf("%d %d %d\n",filestatus, totevt, maxevt);
106 // Retrieve the Temporray ascii file from DB
107 status = daqDA_DB_getFile("pmd_gain_tempfile.dat","pmd_gain_tempfile.dat");
110 calibgain.ReadTempFile("pmd_gain_tempfile.dat");
114 printf("--- pmd_gain_tempfile.dat: not retrieved from DB ---\n");
118 // decoding the events
122 printf("Wrong number of arguments\n");
127 /* define data source : this is argument 1 */
128 status=monitorSetDataSource( argv[1] );
130 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
134 /* declare monitoring program */
135 status=monitorDeclareMp( __FILE__ );
137 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
141 /* define wait event timeout - 1s max */
143 monitorSetNoWaitNetworkTimeout(1000);
145 /* log start of process */
146 printf("PMD GAIN DA - strted generating the gain of a cell\n");
148 /* init some counters */
149 int nevents_physics=0;
152 struct eventHeaderStruct *event;
153 eventTypeType eventT = 0;
157 /* main loop (infinite) */
160 /* check shutdown condition */
161 if (daqDA_checkShutdown()) {break;}
163 /* get next event (blocking call until timeout) */
164 status=monitorGetEventDynamic((void **)&event);
165 if (status==MON_ERR_EOF) {
166 printf ("End of File detected\n");
167 break; /* end of monitoring file has been reached */
171 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
175 /* retry if got no event */
182 /* use event - here, just write event id to result file */
184 eventT=event->eventType;
185 switch (event->eventType){
190 /* END START OF RUN */
198 //if(nevents_physics%100 == 0)printf("Physis Events = %d\n",nevents_physics);
199 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
200 TObjArray *pmdddlcont = new TObjArray();
201 calibgain.ProcessEvent(rawReader, pmdddlcont);
215 /* exit when last event received, no need to wait for TERM signal */
217 ic = new TTree("ic","PMD Gain tree");
219 totevt += nevents_physics++;
221 fp1 = fopen("PMD_GAIN_CONFIGFILE","w+");
225 printf("-----------------------------------------------\n");
226 printf("*** Required Number of Events not reached ***\n");
227 printf("*** Number of Events processed = %d ***\n",totevt);
228 printf("*** Writing the intermediate ASCII file ***\n");
229 printf("-----------------------------------------------\n");
231 calibgain.WriteTempFile("pmd_gain_tempfile.dat");
233 // Store the Intermediate ascii file in the DB
234 status = daqDA_DB_storeFile("pmd_gain_tempfile.dat","pmd_gain_tempfile.dat");
237 fprintf(fp1,"%d %d %d\n",filestatus,totevt,maxevt);
239 // Store the configfile in the DB
240 status = daqDA_DB_storeFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE");
243 else if (totevt >= maxevt)
245 printf("-----------------------------------------------\n");
246 printf("*** Required Number of Events reached = %d ***\n",totevt);
247 printf("*** Writing the PMDGAINS.root file ***\n");
248 printf("-----------------------------------------------\n");
250 calibgain.Analyse(ic);
252 TFile * gainRun = new TFile ("PMDGAINS.root","RECREATE");
258 fprintf(fp1,"%d %d %d\n",filestatus,totevt,maxevt);
260 // Store the configfile in the DB
261 status = daqDA_DB_storeFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE");
270 /* store the result file on FES */
274 printf("root file is created and getting exported\n");
275 status = daqDA_FES_storeFile("PMDGAINS.root","gaincalib");