]>
Commit | Line | Data |
---|---|---|
6f14ad73 | 1 | /* |
a225d309 | 2 | |
3 | HMPID DA for online calibration | |
4 | ||
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 | |
8 | DA Type: LDC | |
9 | Number of events needed: 1000 events | |
3c8e86a0 | 10 | Input Files: Raw pedestal file, EXTERNAL config file: HmpidSigmaCut.txt on both HMPID LDCs |
a225d309 | 11 | Output Files: 14 txt files including pedestal values |
12 | Trigger types used: PEDESTAL RUN (selecting on PHYSICS_EVENT) | |
13 | ||
6f14ad73 | 14 | */ |
a225d309 | 15 | |
6f14ad73 | 16 | extern "C" { |
17 | #include <daqDA.h> | |
18 | } | |
19 | ||
20 | #include "event.h" | |
21 | #include "monitor.h" | |
22 | ||
23 | #include <Riostream.h> | |
913dd690 | 24 | #include "fstream.h" |
6f14ad73 | 25 | #include <stdio.h> |
26 | #include <stdlib.h> | |
27 | ||
28 | //AliRoot | |
ef7257c6 | 29 | #include "AliHMPIDRawStream.h" |
21f61e25 | 30 | #include "AliHMPIDCalib.h" |
6f14ad73 | 31 | #include "AliRawReaderDate.h" |
32 | #include "AliBitPacking.h" | |
6f14ad73 | 33 | |
34 | //ROOT | |
3c8e86a0 | 35 | #include "TROOT.h" |
cdd8604a | 36 | #include "TFile.h" |
37 | #include "TSystem.h" | |
38 | #include "TString.h" | |
6f14ad73 | 39 | #include "TObject.h" |
77e40af5 | 40 | #include "TPluginManager.h" |
21f61e25 | 41 | |
6f14ad73 | 42 | |
43 | int main(int argc, char **argv){ | |
44 | ||
45 | int status; | |
46 | ||
1e7f6589 | 47 | /* log start of process */ |
48 | printf("HMPID DA program started\n"); | |
77e40af5 | 49 | |
3c8e86a0 | 50 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", |
51 | "*", | |
52 | "TStreamerInfo", | |
53 | "RIO", | |
54 | "TStreamerInfo()"); | |
77e40af5 | 55 | |
6f14ad73 | 56 | /* check that we got some arguments = list of files */ |
57 | if (argc<2) { | |
58 | printf("Wrong number of arguments\n"); | |
59 | return -1; | |
60 | } | |
61 | ||
1e7f6589 | 62 | /* copy locally a file from daq detector config db |
6f14ad73 | 63 | status=daqDA_DB_getFile("myconfig","./myconfig.txt"); |
64 | if (status) { | |
65 | printf("Failed to get config file : %d\n",status); | |
66 | return -1; | |
67 | } | |
1e7f6589 | 68 | and possibly use it */ |
6f14ad73 | 69 | |
70 | /* report progress */ | |
71 | daqDA_progressReport(10); | |
72 | ||
a225d309 | 73 | |
74 | ||
75 | /* define wait event timeout - 1s max */ | |
76 | monitorSetNowait(); | |
77 | monitorSetNoWaitNetworkTimeout(1000); | |
6f14ad73 | 78 | |
cdd8604a | 79 | /* set local storage of ped files for Fe2C */ |
80 | ||
81 | ||
21f61e25 | 82 | /* init the pedestal calculation */ |
83 | AliHMPIDCalib *pCal=new AliHMPIDCalib(); | |
3c8e86a0 | 84 | /* Set the number of sigma cuts inside the file HmpidSigmaCut.txt on BOTH LDCs! */ |
85 | /* If the file is NOT present then the default cut 3 will be used!*/ | |
cdd8604a | 86 | |
87 | //pCal->SetSigCutFromFile("HmpidSigmaCut.txt"); | |
88 | pCal->SetSigCutFromShell("HMPID_SIGMA_CUT"); //decision to make later: wether to use file or env variable... | |
89 | pCal->SetDaOutFromShell("HMPID_DA_OUT"); //decision to make later: wether to use file or env variable... | |
90 | pCal->SetFeeInFromShell("HMPID_FEE_IN"); //decision to make later: wether to use file or env variable... | |
91 | ||
92 | ||
3c8e86a0 | 93 | /* ONLY set this option to kTRUE if you want to create the ADC dsitributions for all 161280 pads!!!!*/ |
94 | /* kTRUE is not suggested for production mode b/c of the memory consumption! */ | |
913dd690 | 95 | pCal->SetWriteHistoPads(kFALSE); //use this option for default production useage!!! |
96 | //pCal->SetWriteHistoPads(kTRUE); //only for expert debug | |
97 | //pCal->SetWriteHistoPads(kTRUE,kTRUE,13); //DO NOT USE THIS OPTION! | |
21f61e25 | 98 | |
77e40af5 | 99 | |
1e7f6589 | 100 | /* init event counter */ |
913dd690 | 101 | Int_t firstEvt=0; |
102 | Int_t iEvtNcal=firstEvt; //Start from 1 not 0! | |
a225d309 | 103 | ULong_t runNum=0; |
3c8e86a0 | 104 | ULong_t ldcId=0; |
105 | ||
1e7f6589 | 106 | int n; |
107 | for (n=1;n<argc;n++) { | |
6f14ad73 | 108 | |
109 | status=monitorSetDataSource( argv[n] ); | |
110 | if (status!=0) { | |
111 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
112 | return -1; | |
113 | } | |
114 | ||
115 | /* report progress */ | |
116 | /* in this example, indexed on the number of files */ | |
117 | daqDA_progressReport(10+80*n/argc); | |
118 | ||
1e7f6589 | 119 | for(;;) { // infinite loop |
a225d309 | 120 | |
121 | /* check shutdown condition */ | |
122 | if (daqDA_checkShutdown()) {break;} | |
123 | ||
6f14ad73 | 124 | struct eventHeaderStruct *event; |
125 | eventTypeType eventT; | |
126 | ||
127 | /* get next event */ | |
128 | status=monitorGetEventDynamic((void **)&event); | |
3e60bb92 | 129 | if (status==MON_ERR_EOF) /* end of monitoring file has been reached */ |
130 | { | |
131 | printf("End of monitoring file has been reached! \n"); | |
132 | break; | |
133 | } | |
134 | ||
135 | ||
6f14ad73 | 136 | if (status!=0) { |
137 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
ef7257c6 | 138 | return -1; |
6f14ad73 | 139 | } |
140 | ||
141 | /* retry if got no event */ | |
142 | if (event==NULL) { | |
3e60bb92 | 143 | //break; |
144 | continue; | |
6f14ad73 | 145 | } |
146 | ||
147 | /* use event - here, just write event id to result file */ | |
148 | eventT=event->eventType; | |
149 | ||
77e40af5 | 150 | 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 | 151 | runNum=(unsigned long)event->eventRunNb; //assuming that only one run is processed at a time |
3c8e86a0 | 152 | ldcId=(unsigned long)event->eventLdcId; |
77e40af5 | 153 | if(iEvtNcal==firstEvt && pCal->GetWritePads()==kTRUE) |
154 | { | |
155 | if(pCal->GetLargePads()==kFALSE) pCal->InitFile((Int_t)ldcId); //The number for iEvtNcal should be the same as for the first value | |
156 | else pCal->InitFile((Int_t)runNum); //The number for iEvtNcal should be the same as for the first value | |
157 | } | |
158 | ||
913dd690 | 159 | iEvtNcal++; |
ef7257c6 | 160 | AliRawReader *reader = new AliRawReaderDate((void*)event); |
ef7257c6 | 161 | AliHMPIDRawStream stream(reader); |
a225d309 | 162 | while(stream.Next()) |
163 | { | |
164 | for(Int_t iPad=0;iPad<stream.GetNPads();iPad++) { | |
165 | pCal->FillPedestal(stream.GetPadArray()[iPad],stream.GetChargeArray()[iPad]); | |
3c8e86a0 | 166 | } //pads |
913dd690 | 167 | }//while -- loop on det load in one event |
168 | ||
169 | for(Int_t iddl=0;iddl<stream.GetNDDL();iddl++){ | |
170 | pCal->FillDDLCnt(iddl,stream.GetnDDLInStream()[iddl],stream.GetnDDLOutStream()[iddl]); | |
3c8e86a0 | 171 | for(Int_t ierr=0; ierr < stream.GetNErrors(); ierr++) { |
172 | pCal->FillErrors(iddl,ierr,stream.GetErrors(iddl,ierr)); | |
a225d309 | 173 | } |
3c8e86a0 | 174 | }//err |
a225d309 | 175 | |
3c8e86a0 | 176 | pCal->SetRunParams(runNum,stream.GetTimeStamp(),stream.GetLDCNumber()); //Get the last TimeStam read and the LDC ID |
a225d309 | 177 | stream.Delete(); |
6f14ad73 | 178 | }// if CALIBRATION_EVENT |
179 | ||
180 | /* exit when last event received, no need to wait for TERM signal */ | |
181 | if (eventT==END_OF_RUN) { | |
182 | printf("EOR event detected\n"); | |
183 | break; | |
184 | ||
185 | } // events loop | |
186 | ||
1e7f6589 | 187 | free(event); |
188 | } | |
6f14ad73 | 189 | |
3e60bb92 | 190 | }//arg |
6f14ad73 | 191 | |
1e7f6589 | 192 | /* write report */ |
3c8e86a0 | 193 | printf("HMPID DA processed RUN #%s on LDC#%d, with %d calibration events\n",getenv("DATE_RUN_NUMBER"),ldcId,iEvtNcal); |
1e7f6589 | 194 | |
195 | if (!iEvtNcal) { | |
196 | printf("No calibration events have been read. Exiting\n"); | |
6f14ad73 | 197 | return -1; |
198 | } | |
199 | ||
200 | /* report progress */ | |
1e7f6589 | 201 | daqDA_progressReport(90); |
cdd8604a | 202 | TString sDaOut=pCal->GetDaOutFromShell(); |
203 | ||
3c8e86a0 | 204 | for(Int_t nDDL=0; nDDL < AliHMPIDRawStream::kNDDL; nDDL++) { |
21f61e25 | 205 | |
206 | /* Calculate pedestal for the given ddl, if there is no ddl go t next */ | |
cdd8604a | 207 | if(!pCal->CalcPedestal(nDDL,Form("%sHmpidPedDdl%02i.txt",sDaOut.Data(),nDDL),iEvtNcal)) continue; |
208 | /* to create pedestal file as Paolo uncomment the line */ | |
209 | // if(!pCal->CalcPedestalPaolo(nDDL,Form("%sHmpidPedDdl%02i.txt",sDaOut.Data(),nDDL),iEvtNcal)) continue; | |
210 | if(!pCal->WriteErrors(nDDL,Form("%sHmpidErrorsDdl%02i.txt",sDaOut.Data(),nDDL),iEvtNcal)) continue; | |
21f61e25 | 211 | |
1e7f6589 | 212 | /* store the result file on FES */ |
3c8e86a0 | 213 | |
b7c14c1c | 214 | status=daqDA_FES_storeFile(Form("%sHmpidPedDdl%02i.txt",sDaOut.Data(),nDDL),Form("HmpidPedDdl%02i.txt",nDDL)); |
a225d309 | 215 | if (status) { printf("Failed to export file : %d\n",status); } |
b7c14c1c | 216 | status=daqDA_FES_storeFile(Form("%sHmpidErrorsDdl%02i.txt",sDaOut.Data(),nDDL),Form("HmpidErrorsDdl%02i.txt",nDDL)); |
a225d309 | 217 | if (status) { printf("Failed to export file : %d\n",status); } |
3e60bb92 | 218 | |
219 | }//nDDL | |
3c8e86a0 | 220 | |
77e40af5 | 221 | if(pCal->GetWritePads()==kTRUE) pCal->CloseFile(); |
3c8e86a0 | 222 | delete pCal; |
a225d309 | 223 | if (status) return -1; |
3e60bb92 | 224 | |
1e7f6589 | 225 | /* report progress */ |
226 | daqDA_progressReport(100); | |
a225d309 | 227 | |
3c8e86a0 | 228 | |
1e7f6589 | 229 | return status; |
6f14ad73 | 230 | } |