3 HMPID DA for online calibration
5 Contact: Levente.Molnar@cern.ch, Giacomo.Volpe@ba.infn.it
6 Link: https://twiki.cern.ch/twiki/bin/view/ALICE/DAInstructions
7 Run Type: PEDESTAL -- but we select on the PHYSICS_EVENTS in the HMPIDda.cxx
10 Number of events needed: ~ 1000 events
11 Input Files: Raw pedestal file, EXTERNAL config files: HmpDaqDaConfig.txt, HmpDeadChannelMap.txt on all HMPID LDCs
12 Output Files: 2 x 14 txt files including pedestal and error values
13 Trigger types used: CALIBRATION RUN (but selecting on PHYSICS_EVENT)
24 #include <Riostream.h>
30 #include "AliHMPIDRawStream.h"
31 #include "AliHMPIDCalib.h"
32 #include "AliRawReaderDate.h"
33 #include "AliBitPacking.h"
41 #include "TPluginManager.h"
47 int main(int argc, char **argv){
50 const Char_t *hmpConfigFile = "HmpDaqDaConfig.txt";
51 const Char_t *hmpDeadChannelMapFile = "HmpDeadChannelMap.txt";
52 const Int_t ddlOffset = 1536;
57 /* log start of process */
58 printf("HMP PedestalDa: HMPID DA program started\n");
60 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo","*","TStreamerInfo","RIO","TStreamerInfo()");
62 /* check that we got some arguments = list of files */
64 printf("HMP PedestalDa: Wrong number of arguments\n");
68 /* copy locally a file from daq detector config db */
70 hmpIn=Form("./%s",hmpConfigFile);
71 status=daqDA_DB_getFile(hmpConfigFile,hmpIn.Data());
72 if (status) { printf("Failed to get HMPID config file status: %d\n",status);return -1; }
73 hmpIn2=Form("./%s",hmpDeadChannelMapFile);
74 status=daqDA_DB_getFile(hmpDeadChannelMapFile,hmpIn2.Data());
75 if (status) { printf("Failed to get HMPID dead channel file status: %d\n",status);return -1; }
79 daqDA_progressReport(10);
81 /* define wait event timeout - 1s max */
83 monitorSetNoWaitNetworkTimeout(1000);
85 /* set local storage of ped files for Fe2C */
88 /* init the pedestal calculation */
89 AliHMPIDCalib *pCal=new AliHMPIDCalib();
90 /* Set the number of sigma cuts inside the file HmpidSigmaCut.txt on all LDCs! */
91 /* If the file is NOT present then the default cut 3 will be used!*/
92 pCal->SetSigCutFromFile(hmpIn);
93 pCal->SetDeadChannelMapFromFile(hmpIn2);
95 /* init event counter */
97 Int_t iEvtNcal=firstEvt; //Start from 1 not 0!
102 for (n=1;n<argc;n++) {
104 status=monitorSetDataSource( argv[n] );
106 printf("HMP PedestalDa: monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
110 /* report progress */
111 /* in this example, indexed on the number of files */
112 daqDA_progressReport(10+80*n/argc);
114 for(;;) { // infinite loop
116 /* check shutdown condition */
117 if (daqDA_checkShutdown()) {break;}
119 struct eventHeaderStruct *event;
120 eventTypeType eventT;
123 status=monitorGetEventDynamic((void **)&event);
124 if (status==MON_ERR_EOF) /* end of monitoring file has been reached */
126 printf("HMP PedestalDa: End of monitoring file has been reached! \n");
130 printf("HMP PedestalDa: monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
134 /* retry if got no event */
140 /* use event - here, just write event id to result file */
141 eventT=event->eventType;
143 if (eventT==PHYSICS_EVENT || eventT==CALIBRATION_EVENT ) { //updated: 18/02/2008 based on http://alice-ecs.web.cern.ch/alice-ecs/runtypes_3.16.html
144 runNum=(unsigned long)event->eventRunNb; //assuming that only one run is processed at a time
145 ldcId=(unsigned long)event->eventLdcId;
148 AliRawReader *reader = new AliRawReaderDate((void*)event);
149 AliHMPIDRawStream stream(reader);stream.SetTurbo(kTRUE); //raw data decoding without error checks SetTurbo(kTRUE)
152 for(Int_t iPad=0;iPad<stream.GetNPads();iPad++) {
153 pCal->FillPedestal(stream.GetPadArray()[iPad],stream.GetChargeArray()[iPad]);
155 }//while -- loop on det load in one event
157 for(Int_t iddl=0;iddl<stream.GetNDDL();iddl++){
158 pCal->FillDDLCnt(iddl,stream.GetnDDLInStream()[iddl],stream.GetnDDLOutStream()[iddl]);
159 for(Int_t ierr=0; ierr < stream.GetNErrors(); ierr++) {
160 pCal->FillErrors(iddl,ierr,stream.GetErrors(iddl,ierr));
164 pCal->SetRunParams(runNum,stream.GetTimeStamp(),stream.GetLDCNumber()); //Get the last TimeStam read and the LDC ID
166 }// if CALIBRATION_EVENT
168 /* exit when last event received, no need to wait for TERM signal */
169 if (eventT==END_OF_RUN) {
170 printf("HMP PedestalDa: EOR event detected\n");
181 printf("HMP PedestalDa: HMPID DA processed RUN #%s on LDC#%d, with %d calibration events\n",getenv("DATE_RUN_NUMBER"),ldcId,iEvtNcal);
184 printf("HMP PedestalDa: No calibration events have been read. Exiting\n");
188 /* report progress */
189 daqDA_progressReport(90);
190 /* send pedestal and error files to DAQ FXS */
191 for(Int_t nDDL=0; nDDL < AliHMPIDRawStream::kNDDL; nDDL++) {
192 feeIn=Form("thr%d.dat",ddlOffset+nDDL);
193 /* Calculate pedestal for the given ddl, if there is no ddl go t next */
194 if(pCal->CalcPedestal(nDDL,Form("HmpidPedDdl%02i.txt",nDDL),Form("%s",feeIn.Data()),iEvtNcal)) {
195 status=daqDA_DB_storeFile(feeIn.Data(),feeIn.Data()); //store a single threshold file for a DDL in DAQ DB
196 if (status) { printf("HMP PedestalDa: Failed to store file %s in DAQ DB, status: %d\n",feeIn.Data(),status); }
197 status=daqDA_FES_storeFile(Form("HmpidPedDdl%02i.txt",nDDL),Form("HmpidPedDdl%02i.txt",nDDL)); //store a single pedestal file for a DDL
198 if (status) { printf("HMP PedestalDa: Failed to export file on FES: %d\n",status); }
199 }//pedestals and thresholds
200 if(pCal->WriteErrors(nDDL,Form("HmpidErrorsDdl%02i.txt",nDDL),iEvtNcal)) {
201 status=daqDA_FES_storeFile(Form("HmpidErrorsDdl%02i.txt",nDDL),Form("HmpidErrorsDdl%02i.txt",nDDL));
202 if (status) { printf("HMP PedestalDa: Failed to export file : %d\n",status); }
206 /* send files to AMORE DB */
207 daqDA_progressReport(95);
208 Int_t statusAmoreDA=0;
209 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
210 for(Int_t iCh=0; iCh < AliHMPIDParam::kMaxCh; iCh++) {
211 statusAmoreDA+=amoreDA.Send(Form("fPedMeanMap%d",iCh), pCal->GetPedMeanMap(iCh));
212 statusAmoreDA+=amoreDA.Send(Form("fPedSigMap%d",iCh), pCal->GetPedSigMap(iCh));
214 for(Int_t iCh=0;iCh<=AliHMPIDParam::kMaxCh;iCh++)
216 for(Int_t iFee=0;iFee<6;iFee++)
218 statusAmoreDA+=amoreDA.Send(Form("f1DPedMean_Ch%d_FEE_%d",iCh,iFee),pCal->GetPedMean(6*iCh+iFee));
219 statusAmoreDA+=amoreDA.Send(Form("f1DPedSigma_Ch%d_FEE_%d",iCh,iFee),pCal->GetPedSigma(6*iCh+iFee));
223 printf("HMP PedestalDa: num. masked pads: %d, num of currently dead pads: %d.\n",pCal->GetNumMaskedPads(),pCal->GetNumDeadPads());
226 if(status) return -1;
227 if(statusAmoreDA) return -1;
229 /* report progress */
230 daqDA_progressReport(100);