]>
Commit | Line | Data |
---|---|---|
afd9bf7e | 1 | /* |
2 | Contact: annalisa.mastroserio@cern.ch | |
3 | Link: tydes.home.cern.ch/tydes/doc/CalibrationOverview/CalibrationAlgorithms/ | |
4 | Run Type: DAQ_FO_UNIF_SCAN | |
5 | DA Type: LDC | |
6 | Number of events needed: Depending on scan type | |
7 | Input Files: spd_focalib_params, raw data | |
8 | Output Files: ./calibResults/ScanDCSconfigToFXS/* | |
9 | Trigger types used: PHYSICS | |
10 | */ | |
11 | ||
286382a3 | 12 | //////////////////////////////////////////////////////////////////////////////// |
13 | // This program can be compiled in two modes. // | |
14 | // // | |
15 | // 1. With the DAQ DA framework on. This is the default operating mode. // | |
16 | // Call this program with the name of the executable followed by the // | |
17 | // data files to process. // | |
18 | // // | |
19 | // 2. Without the DAQ DA framework on. Define the SPD_DA_OFF environment var. // | |
20 | // Call this program with the name of the executable followed by the // | |
21 | // runNr and the data files to process. // | |
22 | // // | |
23 | //////////////////////////////////////////////////////////////////////////////// | |
24 | ||
25 | #ifndef SPD_DA_OFF | |
26 | extern "C" { | |
27 | #include <daqDA.h> | |
28 | } | |
29 | #endif | |
30 | #include "event.h" | |
31 | #include "monitor.h" | |
32 | #include "AliRawReaderDate.h" | |
33 | #include "AliITSRawStreamSPD.h" | |
34 | #include "AliITSOnlineSPDfoChip.h" | |
35 | #include "AliITSOnlineSPDfoInfo.h" | |
36 | #include "AliITSOnlineSPDfo.h" | |
37 | #include "AliITSOnlineSPDfoAnalyzer.h" | |
38 | #include "AliLog.h" | |
39 | #include <Riostream.h> | |
40 | #include <fstream> | |
41 | #include <TROOT.h> | |
42 | #include <TStopwatch.h> | |
43 | #include <TPluginManager.h> | |
44 | #include <TObjArray.h> | |
45 | #include <TClonesArray.h> | |
46 | #include <TObjString.h> | |
47 | #include <TString.h> | |
48 | #include <TFitter.h> | |
49 | #include <TFile.h> | |
50 | ||
51 | int main(int argc, char **argv) { | |
52 | if (argc<2) { | |
53 | printf("Wrong number of arguments\n"); | |
54 | return -1; | |
55 | } | |
56 | ||
57 | ||
58 | TStopwatch timer; | |
59 | timer.Start(); | |
60 | ||
61 | // directory structure, hard coded | |
286382a3 | 62 | char *saveDirDCSconfigToFXS= "./calibResults/ScanDCSconfigToFXS"; // may delete content |
63 | char *configFilesDir = "./configFiles"; // may delete content | |
64 | char *saveDirIdsToFXS = "./calibResults/IdsToFXS"; | |
afd9bf7e | 65 | |
66 | // make sure the directory structure is correct: | |
67 | system("mkdir ./calibResults >& /dev/null"); | |
68 | system("mkdir ./calibResults/ScanDCSconfigToFXS >& /dev/null"); | |
69 | system("mkdir ./calibResults/IdsToFXS >& /dev/null"); | |
70 | system("mkdir ./configFiles >& /dev/null"); | |
71 | ||
72 | ||
286382a3 | 73 | // parameters config files |
74 | TString thresholdsFileName = Form("%s/focalib_params.txt",configFilesDir); | |
75 | ||
76 | TFitter *fitter = new TFitter(3); | |
77 | TVirtualFitter::SetFitter(fitter); | |
78 | ||
79 | // This line is needed in case of a stand-alone application w/o | |
80 | // $ROOTSYS/etc/system.rootrc file | |
81 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", | |
82 | "*", | |
83 | "TStreamerInfo", | |
84 | "RIO", | |
85 | "TStreamerInfo()"); | |
86 | ||
87 | // turn off annoying warning messages | |
6d7793cf | 88 | // NB: Should not be handled here |
89 | AliLog logger = AliLog::GetRootLogger(); | |
90 | logger->SetGlobalDebugLevel(-20); | |
286382a3 | 91 | |
92 | // ********* STEP 0: Get configuration files from db (if there are any) , then read parameters********* | |
93 | ||
94 | //chip efficiency selection parameters (needed afterwards for the data analysis) | |
95 | Int_t status = 0; | |
96 | #ifndef SPD_DA_OFF | |
97 | TString idp = "spd_focalib_params"; | |
98 | status=daqDA_DB_getFile(idp.Data(),thresholdsFileName.Data()); | |
99 | if (status) { | |
100 | printf("Failed to get config file %s: status=%d. Using default tuning parameters.\n",idp.Data(),status); | |
101 | TString rmCmd = Form("rm -f %s",thresholdsFileName.Data()); | |
102 | system(rmCmd.Data()); | |
103 | } | |
104 | #endif | |
105 | ||
106 | ||
107 | ||
108 | // ********* STEP 1: Produce FO scan container files (Reference Data). *********************************** | |
109 | int startSeg = 1; | |
110 | ||
111 | #ifndef SPD_DA_OFF | |
112 | if (getenv("DATE_RUN_NUMBER")==0) { | |
113 | printf("DATE_RUN_NUMBER not properly set.\n"); | |
114 | return -1; | |
115 | } | |
116 | int runNr = atoi(getenv("DATE_RUN_NUMBER")); | |
117 | #else | |
118 | int runNr = atoi(argv[1]); | |
119 | startSeg = 2; | |
120 | #endif | |
121 | ||
122 | Int_t evType =-1; | |
123 | AliITSOnlineSPDfoInfo *info[20]; Int_t ntriggers[20]; Int_t vDB[20]; Bool_t iseq[20]; | |
286382a3 | 124 | AliITSOnlineSPDfo *fomanager[20]; |
125 | TString s = "focalib"; | |
126 | ||
127 | for(Int_t equip =0; equip < 20; equip++ ) { | |
128 | info[equip] = new AliITSOnlineSPDfoInfo(); | |
129 | info[equip]->SetRunNumber(runNr); | |
130 | info[equip]->SetRouter(equip); | |
131 | ntriggers[equip] = 0; | |
132 | vDB[equip] =0; | |
133 | iseq[equip]=kFALSE; | |
134 | fomanager[equip] = new AliITSOnlineSPDfo(s,runNr,equip); | |
135 | } | |
136 | ||
137 | ||
138 | // loop over run segments | |
139 | for (int segNr=startSeg; segNr<argc; segNr++) { | |
140 | ||
141 | int status; | |
142 | ||
143 | // define data source : this is argument 1 | |
144 | status=monitorSetDataSource( argv[segNr] ); | |
145 | if (status!=0) { | |
146 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
147 | return -1; | |
148 | } | |
149 | // declare monitoring program | |
150 | status=monitorDeclareMp("ITS_SPD_CAL"); | |
151 | if (status!=0) { | |
152 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
153 | return -1; | |
154 | } | |
155 | // define wait event timeout - 1s max | |
156 | monitorSetNowait(); | |
157 | monitorSetNoWaitNetworkTimeout(1000); | |
158 | ||
159 | Int_t eventType; | |
160 | UInt_t eventNr=0; | |
afd9bf7e | 161 | |
286382a3 | 162 | // main loop (infinite) |
163 | for(;;) { | |
164 | ||
165 | struct eventHeaderStruct *event; | |
166 | eventTypeType eventT; | |
167 | ||
168 | /* check shutdown condition */ | |
169 | #ifndef SPD_DA_OFF | |
170 | if (daqDA_checkShutdown()) {break;} | |
171 | #endif | |
172 | /* get next event (blocking call until timeout) */ | |
173 | status=monitorGetEventDynamic((void **)&event); | |
174 | if (status==MON_ERR_EOF) { | |
175 | printf ("End of File detected\n"); | |
176 | break; /* end of monitoring file has been reached */ | |
177 | } | |
178 | if (status!=0) { | |
179 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
180 | break; | |
181 | } | |
182 | /* retry if got no event */ | |
183 | if (event==NULL) { | |
184 | continue; | |
185 | } | |
186 | ||
187 | eventT=event->eventType; | |
188 | eventType = (Int_t) eventT; | |
189 | ||
190 | if (eventT == PHYSICS_EVENT) { | |
191 | ||
192 | eventNr++; | |
193 | //if(eventNr%5000 == 0 )printf(" eventNr %d\n",eventNr); | |
194 | ||
195 | AliRawReader *reader = new AliRawReaderDate((void*)event); | |
196 | AliITSRawStreamSPD *str = new AliITSRawStreamSPD(reader); | |
197 | ||
198 | for (UInt_t eqId=0; eqId<20; eqId++) { | |
199 | ||
200 | reader->Reset(); | |
201 | reader->Select("ITSSPD",eqId,eqId); | |
202 | ||
203 | if (str->ReadCalibHeader()>0) { | |
204 | ||
205 | if(evType<0) evType = str->GetFOHtype(); | |
206 | ||
207 | if(!iseq[eqId]){ // create output files | |
208 | fomanager[eqId]->CreateOutputFile(); | |
209 | fomanager[eqId]->SetFOscanParams(info[eqId]); | |
210 | iseq[eqId]=kTRUE; | |
211 | } | |
212 | ||
213 | if(info[eqId]->GetNumDACindex()<1) { | |
214 | Int_t ind =0; | |
215 | while(str->GetFOHdacIndex(ind)>0) { | |
216 | info[eqId]->AddDACindex(str->GetFOHdacIndex(ind)); | |
217 | ind++; | |
218 | } | |
219 | } | |
220 | ||
221 | if(!ntriggers[eqId]) { | |
222 | ntriggers[eqId] = str->GetFOHtriggers(); | |
223 | info[eqId]->SetNumTriggers(str->GetFOHtriggers()); | |
224 | } | |
225 | if(!vDB[eqId]) { | |
226 | vDB[eqId] = str->GetFOHglobalDBversion(); | |
227 | info[eqId]->SetDBversion(str->GetFOHglobalDBversion()); | |
228 | } | |
229 | ||
230 | if(!fomanager[eqId]->GetNdacs()) fomanager[eqId]->SetNdacs(str->GetFOHnumDacs()); | |
231 | ||
232 | TArrayS dacvalues(str->GetFOHnumDacs()); | |
afd9bf7e | 233 | for(Int_t n = 0; n<(Int_t)str->GetFOHnumDacs(); n++) dacvalues.AddAt(str->GetFOHdacValue(n),n); |
286382a3 | 234 | |
235 | TArrayS dacs = fomanager[eqId]->CreateDACArray(dacvalues, info[eqId]->GetDACIndexArray()); | |
236 | ||
237 | for(Int_t ihs =0; ihs < 6; ihs++) { // needed in the header to access the HS and ChipId info (in data it is different) | |
238 | for(Int_t ich =0; ich < 10; ich++){ | |
239 | if(!str->GetFOHchipPresent(ihs, ich)) continue; | |
14374702 | 240 | info[eqId]->SetActiveChipsAndHS(ihs,ich); |
286382a3 | 241 | Short_t measure[4] = {str->GetFOHMatrixID(),str->GetFOHpixelRow(), str->GetFOHpixelCol(), str->GetFOHchipCount(ihs,ich)}; |
242 | fomanager[eqId]->AddMeasurement(dacs,measure,ihs,ich); | |
243 | } // chip loop | |
244 | }// HS loop | |
245 | }// if str->ReadHeader()>0; | |
246 | }//if eqId | |
247 | delete str; | |
248 | delete reader; | |
249 | } | |
250 | ||
251 | // free resources | |
252 | free(event); | |
253 | }// infinite loop | |
254 | ||
255 | ||
256 | ||
257 | ||
258 | #ifndef SPD_DA_OFF | |
259 | daqDA_progressReport((unsigned int)( ((Float_t)(segNr-startSeg+1))/(argc-startSeg)*50 )); | |
260 | #else | |
261 | printf("progress: %d\n",(unsigned int)( ((Float_t)(segNr-startSeg+1))/(argc-startSeg)*50 )); | |
262 | #endif | |
263 | ||
264 | }// loop over run segments | |
265 | ||
266 | ||
267 | TString id[20], files[20]; | |
268 | for(Int_t ifile =0; ifile < 20; ifile++) { | |
269 | if(iseq[ifile]){ | |
270 | id[ifile] = Form("SPD_ref_fo%02i",ifile); | |
271 | files[ifile] = fomanager[ifile]->GetFile()->GetName(); | |
272 | fomanager[ifile]->WriteToFile(); | |
273 | } | |
274 | delete fomanager[ifile]; | |
275 | } | |
276 | ||
277 | ||
278 | // ANALYSIS part | |
279 | ||
280 | for(Int_t iff =0; iff<20 ; iff++){ | |
281 | if(!iseq[iff]) continue; | |
282 | ||
283 | AliITSOnlineSPDfoAnalyzer * analyzer = new AliITSOnlineSPDfoAnalyzer(Form("%i_%s%02i.root",runNr,s.Data(),iff)); | |
284 | analyzer->ReadParamsFromLocation(configFilesDir); | |
285 | analyzer->Process(); | |
286 | ||
287 | TString dcsConfigFileName = Form("%s/dcsConfig_run_%d_eq_%d.txt",saveDirDCSconfigToFXS,runNr,iff); | |
288 | ofstream dcsfile; | |
289 | dcsfile.open(dcsConfigFileName.Data()); | |
290 | dcsfile << "[SPD SCAN]\n"; | |
291 | dcsfile << "RunNumber=" << runNr << "\n"; | |
292 | dcsfile << "Type="<< evType <<"\n"; | |
293 | dcsfile << "Router=" << iff << "\n"; | |
294 | dcsfile << "ActualDetConfiguration=" << vDB[iff]<<"\n\n"; | |
295 | dcsfile << "[DACvalues]\n"; | |
296 | ||
297 | for(Int_t hs =0; hs<6; hs++){ | |
298 | for(Int_t ichip =0; ichip < 10; ichip++){ | |
299 | TArrayI dacs = analyzer->ChooseDACValues(hs,ichip); | |
300 | ||
301 | if(dacs.GetSize() == 0) continue; | |
302 | for(Int_t idac =0; idac < dacs.GetSize() - 1; idac++) { // -1 (the last one is the quality flag) | |
303 | if(dacs.At(idac) >=0 ) { | |
14374702 | 304 | |
286382a3 | 305 | dcsfile << ((analyzer->GetFOHandler())->GetFOscanInfo())->GetDACindex(idac) << ","; |
306 | dcsfile << iff << ","; | |
307 | dcsfile << hs << ","; | |
308 | dcsfile << ichip << "=" ; | |
309 | dcsfile << dacs.At(idac) << ","; | |
310 | dcsfile << dacs.At(dacs.GetSize() - 1) << "\n"; | |
311 | } | |
312 | } | |
313 | } | |
314 | } | |
315 | dcsfile.close(); | |
316 | } | |
317 | ||
318 | ||
319 | printf("Preparing DCS config files\n"); | |
320 | // send a tared file of all the dcsConfig text files | |
321 | TString command = Form("cd %s; tar -cf dcsConfig.tar *",saveDirDCSconfigToFXS); | |
322 | //printf("\n\n%s\n\n",command.Data()); | |
afd9bf7e | 323 | system(command.Data()); |
286382a3 | 324 | TString fileName = Form("%s/dcsConfig.tar",saveDirDCSconfigToFXS); |
325 | TString iddcs = "SPD_dcsConfig"; | |
326 | ||
327 | #ifndef SPD_DA_OFF | |
328 | status = daqDA_FES_storeFile(fileName.Data(),iddcs.Data()); | |
329 | if (status!=0) { | |
330 | printf("Failed to export file %s , status %d\n",fileName.Data(),status); | |
331 | return -1; | |
332 | } | |
333 | #endif | |
334 | ||
335 | ||
336 | printf("Opening id list file\n"); | |
337 | TString idsFXSFileName = Form("%s/FXSids_run_%d.txt",saveDirIdsToFXS,runNr); | |
338 | ofstream idsFXSfile; | |
339 | idsFXSfile.open(idsFXSFileName.Data()); | |
340 | ||
341 | // send reference data to FXS | |
342 | for (UInt_t eqId=0; eqId<20; eqId++) { | |
343 | if(!iseq[eqId]) continue; | |
344 | //printf("Preparing reference data for eq %d\n",eqId); | |
345 | ||
5e575679 | 346 | TString idf = Form("SPD_ref_fo_%d",eqId); |
286382a3 | 347 | #ifndef SPD_DA_OFF |
348 | status = daqDA_FES_storeFile(files[eqId].Data(),idf.Data()); | |
349 | if (status!=0) { | |
350 | printf("Failed to export file %s , status %d\n",files[eqId].Data(),status); | |
351 | return -1; | |
352 | } | |
353 | #endif | |
354 | idsFXSfile << Form("%s\n",idf.Data()); | |
355 | } | |
356 | ||
e737a317 | 357 | |
358 | ||
359 | printf("Preparing id list file\n"); | |
360 | idsFXSfile.close(); | |
361 | TString idlist = "SPD_id_list"; | |
362 | #ifndef SPD_DA_OFF | |
363 | status = daqDA_FES_storeFile(idsFXSFileName.Data(),idlist.Data()); | |
364 | if (status!=0) { | |
365 | printf("Failed to export file %s , status %d\n",idsFXSFileName.Data(),status); | |
366 | return -1; | |
367 | } | |
368 | #endif | |
369 | ||
370 | ||
371 | ||
286382a3 | 372 | timer.Stop(); |
373 | timer.Print(); | |
374 | printf("DA finished.\n"); | |
375 | return 0; | |
376 | } |