3 HMPID DA for online calibration
5 Contact: Levente.Molnar@ba.infn.it, Giacomo.Volpe@ba.infn.it
6 Link: http://richpc1.ba.infn.it/~levente/Files4Public/ValidateHmpidDA/
7 Run Type: PEDESTAL -- but we select on the PHYSICS_EVENTS in th HMPIDda.cxx
9 Number of events needed: 1000 events
10 Input Files: Raw pedestal file, no external config file
11 Output Files: 14 txt files including pedestal values
12 Trigger types used: PEDESTAL RUN (selecting on PHYSICS_EVENT)
23 #include <Riostream.h>
28 #include "AliHMPIDRawStream.h"
29 #include "AliHMPIDCalib.h"
30 #include "AliRawReaderDate.h"
31 #include "AliBitPacking.h"
40 #include "TBenchmark.h"
45 int main(int argc, char **argv){
49 /* log start of process */
50 printf("HMPID DA program started\n");
52 /* check that we got some arguments = list of files */
54 printf("Wrong number of arguments\n");
58 /* copy locally a file from daq detector config db
59 status=daqDA_DB_getFile("myconfig","./myconfig.txt");
61 printf("Failed to get config file : %d\n",status);
64 and possibly use it */
67 daqDA_progressReport(10);
71 /* define wait event timeout - 1s max */
73 monitorSetNoWaitNetworkTimeout(1000);
75 /* init the pedestal calculation */
76 AliHMPIDCalib *pCal=new AliHMPIDCalib();
78 /* init event counter */
83 for (n=1;n<argc;n++) {
85 status=monitorSetDataSource( argv[n] );
87 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
92 /* in this example, indexed on the number of files */
93 daqDA_progressReport(10+80*n/argc);
95 for(;;) { // infinite loop
97 /* check shutdown condition */
98 if (daqDA_checkShutdown()) {break;}
100 struct eventHeaderStruct *event;
101 eventTypeType eventT;
104 status=monitorGetEventDynamic((void **)&event);
105 if (status==MON_ERR_EOF) /* end of monitoring file has been reached */
107 printf("End of monitoring file has been reached! \n");
113 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
117 /* retry if got no event */
123 /* use event - here, just write event id to result file */
124 eventT=event->eventType;
126 if (eventT==PHYSICS_EVENT) { //we use PHYSICS_EVENT for pedestal not CALIBRATION_EVENT
128 runNum=(unsigned long)event->eventRunNb; //assuming that only one run is processed at a time
132 AliRawReader *reader = new AliRawReaderDate((void*)event);
133 AliHMPIDRawStream stream(reader);
137 for(Int_t iPad=0;iPad<stream.GetNPads();iPad++) {
138 pCal->FillPedestal(stream.GetPadArray()[iPad],stream.GetChargeArray()[iPad]);
141 for(Int_t iddl=0;iddl<AliHMPIDRawStream::kNDDL;iddl++){
142 for(Int_t ierr=0; ierr < AliHMPIDRawStream::kSumErr; ierr++) {
143 pCal->FillErrors(iddl,ierr,stream.GetErrors(iddl,ierr));
150 }// if CALIBRATION_EVENT
152 /* exit when last event received, no need to wait for TERM signal */
153 if (eventT==END_OF_RUN) {
154 printf("EOR event detected\n");
165 printf("HMPID DA processed RUN #%s, with %d calibration events\n",getenv("DATE_RUN_NUMBER"),iEvtNcal);
168 printf("No calibration events have been read. Exiting\n");
172 /* report progress */
173 daqDA_progressReport(90);
176 for(Int_t nDDL=0; nDDL < AliHMPIDCalib::kNDDL; nDDL++) {
178 /* Calculate pedestal for the given ddl, if there is no ddl go t next */
179 if(!pCal->CalcPedestal(runNum,nDDL,Form("./HmpidPedDdl%02i.txt",nDDL),iEvtNcal)) continue;
180 if(!pCal->WriteErrors(runNum,nDDL,Form("./HmpidErrorsDdl%02i.txt",nDDL),iEvtNcal)) continue;
182 /* store the result file on FES */
184 status=daqDA_FES_storeFile(Form("./HmpidPedDdl%02i.txt",nDDL),Form("HMPID_DA_Pedestals_ddl=%02i",nDDL));
186 printf("Failed to export file : %d\n",status);
190 status=daqDA_FES_storeFile(Form("./HmpidPedDdl%02i.txt",nDDL),Form("HMPID_DA_Pedestals_ddl=%02i",nDDL));
191 if (status) { printf("Failed to export file : %d\n",status); }
192 status=daqDA_FES_storeFile(Form("./HmpidErrorsDdl%02i.txt",nDDL),Form("HMPID_DA_Errors_ddl=%02i",nDDL));
193 if (status) { printf("Failed to export file : %d\n",status); }
197 if (status) return -1;
199 /* report progress */
200 daqDA_progressReport(100);