]>
Commit | Line | Data |
---|---|---|
6f14ad73 | 1 | /* |
a225d309 | 2 | |
3 | HMPID DA for online calibration | |
4 | ||
b065db45 | 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 | |
8 | DA Type: LDC | |
c91115b2 | 9 | Reference Run: 78734 |
b065db45 | 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) | |
a225d309 | 14 | |
6f14ad73 | 15 | */ |
a225d309 | 16 | |
6f14ad73 | 17 | extern "C" { |
18 | #include <daqDA.h> | |
19 | } | |
20 | ||
21 | #include "event.h" | |
22 | #include "monitor.h" | |
23 | ||
24 | #include <Riostream.h> | |
913dd690 | 25 | #include "fstream.h" |
6f14ad73 | 26 | #include <stdio.h> |
27 | #include <stdlib.h> | |
28 | ||
29 | //AliRoot | |
ef7257c6 | 30 | #include "AliHMPIDRawStream.h" |
21f61e25 | 31 | #include "AliHMPIDCalib.h" |
6f14ad73 | 32 | #include "AliRawReaderDate.h" |
33 | #include "AliBitPacking.h" | |
6f14ad73 | 34 | |
35 | //ROOT | |
3c8e86a0 | 36 | #include "TROOT.h" |
cdd8604a | 37 | #include "TFile.h" |
38 | #include "TSystem.h" | |
39 | #include "TString.h" | |
6f14ad73 | 40 | #include "TObject.h" |
77e40af5 | 41 | #include "TPluginManager.h" |
21f61e25 | 42 | |
2ac899f2 | 43 | //AMORE |
44 | #include <AmoreDA.h> | |
45 | ||
6f14ad73 | 46 | |
47 | int main(int argc, char **argv){ | |
48 | ||
b065db45 | 49 | int status=0; |
2ac899f2 | 50 | const Char_t *hmpConfigFile = "HmpDaqDaConfig.txt"; |
51 | const Char_t *hmpDeadChannelMapFile = "HmpDeadChannelMap.txt"; | |
4969a7fa | 52 | const Int_t ddlOffset = 1536; |
2ac899f2 | 53 | TString hmpIn,hmpIn2; |
4969a7fa | 54 | TString feeIn; |
6f14ad73 | 55 | |
4969a7fa | 56 | |
1e7f6589 | 57 | /* log start of process */ |
2a7784f8 | 58 | printf("HMP PedestalDa: HMPID DA program started\n"); |
77e40af5 | 59 | |
4969a7fa | 60 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo","*","TStreamerInfo","RIO","TStreamerInfo()"); |
77e40af5 | 61 | |
6f14ad73 | 62 | /* check that we got some arguments = list of files */ |
63 | if (argc<2) { | |
2a7784f8 | 64 | printf("HMP PedestalDa: Wrong number of arguments\n"); |
6f14ad73 | 65 | return -1; |
66 | } | |
67 | ||
4969a7fa | 68 | /* copy locally a file from daq detector config db */ |
2ac899f2 | 69 | |
2a7784f8 | 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; } | |
2ac899f2 | 76 | |
6f14ad73 | 77 | |
78 | /* report progress */ | |
79 | daqDA_progressReport(10); | |
2ac899f2 | 80 | |
a225d309 | 81 | /* define wait event timeout - 1s max */ |
82 | monitorSetNowait(); | |
83 | monitorSetNoWaitNetworkTimeout(1000); | |
6f14ad73 | 84 | |
cdd8604a | 85 | /* set local storage of ped files for Fe2C */ |
2ac899f2 | 86 | |
cdd8604a | 87 | |
21f61e25 | 88 | /* init the pedestal calculation */ |
89 | AliHMPIDCalib *pCal=new AliHMPIDCalib(); | |
2ac899f2 | 90 | /* Set the number of sigma cuts inside the file HmpidSigmaCut.txt on all LDCs! */ |
3c8e86a0 | 91 | /* If the file is NOT present then the default cut 3 will be used!*/ |
2a7784f8 | 92 | pCal->SetSigCutFromFile(hmpIn); |
93 | pCal->SetDeadChannelMapFromFile(hmpIn2); | |
77e40af5 | 94 | |
1e7f6589 | 95 | /* init event counter */ |
913dd690 | 96 | Int_t firstEvt=0; |
97 | Int_t iEvtNcal=firstEvt; //Start from 1 not 0! | |
a225d309 | 98 | ULong_t runNum=0; |
3c8e86a0 | 99 | ULong_t ldcId=0; |
100 | ||
1e7f6589 | 101 | int n; |
102 | for (n=1;n<argc;n++) { | |
6f14ad73 | 103 | |
104 | status=monitorSetDataSource( argv[n] ); | |
105 | if (status!=0) { | |
2a7784f8 | 106 | printf("HMP PedestalDa: monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); |
6f14ad73 | 107 | return -1; |
108 | } | |
109 | ||
110 | /* report progress */ | |
111 | /* in this example, indexed on the number of files */ | |
112 | daqDA_progressReport(10+80*n/argc); | |
113 | ||
1e7f6589 | 114 | for(;;) { // infinite loop |
a225d309 | 115 | |
116 | /* check shutdown condition */ | |
117 | if (daqDA_checkShutdown()) {break;} | |
118 | ||
6f14ad73 | 119 | struct eventHeaderStruct *event; |
120 | eventTypeType eventT; | |
121 | ||
122 | /* get next event */ | |
123 | status=monitorGetEventDynamic((void **)&event); | |
3e60bb92 | 124 | if (status==MON_ERR_EOF) /* end of monitoring file has been reached */ |
125 | { | |
2a7784f8 | 126 | printf("HMP PedestalDa: End of monitoring file has been reached! \n"); |
3e60bb92 | 127 | break; |
128 | } | |
6f14ad73 | 129 | if (status!=0) { |
2a7784f8 | 130 | printf("HMP PedestalDa: monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); |
ef7257c6 | 131 | return -1; |
6f14ad73 | 132 | } |
133 | ||
134 | /* retry if got no event */ | |
135 | if (event==NULL) { | |
3e60bb92 | 136 | //break; |
137 | continue; | |
6f14ad73 | 138 | } |
139 | ||
140 | /* use event - here, just write event id to result file */ | |
141 | eventT=event->eventType; | |
142 | ||
77e40af5 | 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 |
a225d309 | 144 | runNum=(unsigned long)event->eventRunNb; //assuming that only one run is processed at a time |
3c8e86a0 | 145 | ldcId=(unsigned long)event->eventLdcId; |
77e40af5 | 146 | |
913dd690 | 147 | iEvtNcal++; |
ef7257c6 | 148 | AliRawReader *reader = new AliRawReaderDate((void*)event); |
cb9b108e | 149 | AliHMPIDRawStream stream(reader);stream.SetTurbo(kTRUE); //raw data decoding without error checks SetTurbo(kTRUE) |
a225d309 | 150 | while(stream.Next()) |
151 | { | |
152 | for(Int_t iPad=0;iPad<stream.GetNPads();iPad++) { | |
153 | pCal->FillPedestal(stream.GetPadArray()[iPad],stream.GetChargeArray()[iPad]); | |
3c8e86a0 | 154 | } //pads |
913dd690 | 155 | }//while -- loop on det load in one event |
156 | ||
157 | for(Int_t iddl=0;iddl<stream.GetNDDL();iddl++){ | |
158 | pCal->FillDDLCnt(iddl,stream.GetnDDLInStream()[iddl],stream.GetnDDLOutStream()[iddl]); | |
3c8e86a0 | 159 | for(Int_t ierr=0; ierr < stream.GetNErrors(); ierr++) { |
160 | pCal->FillErrors(iddl,ierr,stream.GetErrors(iddl,ierr)); | |
a225d309 | 161 | } |
3c8e86a0 | 162 | }//err |
a225d309 | 163 | |
3c8e86a0 | 164 | pCal->SetRunParams(runNum,stream.GetTimeStamp(),stream.GetLDCNumber()); //Get the last TimeStam read and the LDC ID |
a225d309 | 165 | stream.Delete(); |
6f14ad73 | 166 | }// if CALIBRATION_EVENT |
167 | ||
168 | /* exit when last event received, no need to wait for TERM signal */ | |
169 | if (eventT==END_OF_RUN) { | |
2a7784f8 | 170 | printf("HMP PedestalDa: EOR event detected\n"); |
6f14ad73 | 171 | break; |
172 | ||
173 | } // events loop | |
174 | ||
1e7f6589 | 175 | free(event); |
176 | } | |
6f14ad73 | 177 | |
3e60bb92 | 178 | }//arg |
6f14ad73 | 179 | |
1e7f6589 | 180 | /* write report */ |
2a7784f8 | 181 | printf("HMP PedestalDa: HMPID DA processed RUN #%s on LDC#%d, with %d calibration events\n",getenv("DATE_RUN_NUMBER"),ldcId,iEvtNcal); |
1e7f6589 | 182 | |
183 | if (!iEvtNcal) { | |
2a7784f8 | 184 | printf("HMP PedestalDa: No calibration events have been read. Exiting\n"); |
6f14ad73 | 185 | return -1; |
186 | } | |
187 | ||
188 | /* report progress */ | |
1e7f6589 | 189 | daqDA_progressReport(90); |
2ac899f2 | 190 | /* send pedestal and error files to DAQ FXS */ |
4969a7fa | 191 | for(Int_t nDDL=0; nDDL < AliHMPIDRawStream::kNDDL; nDDL++) { |
192 | feeIn=Form("thr%d.dat",ddlOffset+nDDL); | |
21f61e25 | 193 | /* Calculate pedestal for the given ddl, if there is no ddl go t next */ |
4969a7fa | 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 | |
2a7784f8 | 196 | if (status) { printf("HMP PedestalDa: Failed to store file %s in DAQ DB, status: %d\n",feeIn.Data(),status); } |
4969a7fa | 197 | status=daqDA_FES_storeFile(Form("HmpidPedDdl%02i.txt",nDDL),Form("HmpidPedDdl%02i.txt",nDDL)); //store a single pedestal file for a DDL |
2a7784f8 | 198 | if (status) { printf("HMP PedestalDa: Failed to export file on FES: %d\n",status); } |
4969a7fa | 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)); | |
2a7784f8 | 202 | if (status) { printf("HMP PedestalDa: Failed to export file : %d\n",status); } |
4969a7fa | 203 | }//errors |
3e60bb92 | 204 | }//nDDL |
3c8e86a0 | 205 | |
2ac899f2 | 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)); | |
213 | } | |
214 | for(Int_t iCh=0;iCh<=AliHMPIDParam::kMaxCh;iCh++) | |
215 | { | |
216 | for(Int_t iFee=0;iFee<6;iFee++) | |
217 | { | |
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)); | |
220 | } | |
221 | } | |
2a7784f8 | 222 | |
223 | printf("HMP PedestalDa: num. masked pads: %d, num of currently dead pads: %d.\n",pCal->GetNumMaskedPads(),pCal->GetNumDeadPads()); | |
224 | ||
3c8e86a0 | 225 | delete pCal; |
2ac899f2 | 226 | if(status) return -1; |
227 | if(statusAmoreDA) return -1; | |
3e60bb92 | 228 | |
1e7f6589 | 229 | /* report progress */ |
230 | daqDA_progressReport(100); | |
a225d309 | 231 | |
3c8e86a0 | 232 | |
2a7784f8 | 233 | |
1e7f6589 | 234 | return status; |
6f14ad73 | 235 | } |
4969a7fa | 236 |