]>
Commit | Line | Data |
---|---|---|
1fd93b67 | 1 | //////////////////////////////////////////////////////////////////////////////// |
2 | // This program can be run in two modes. // | |
3 | // // | |
4 | // 1. With the DAQ DA framework on. This is the default operating mode. // | |
5 | // Call this program with the name of the executable followed by the // | |
6 | // data files to process. // | |
7 | // // | |
8 | // 2. Without the DAQ DA framework on. Define the SPD_DA_OFF environment var. // | |
9 | // Call this program with the name of the executable followed by the // | |
10 | // runNr and the data files to process. // | |
11 | // // | |
12 | //////////////////////////////////////////////////////////////////////////////// | |
3ec5024c | 13 | |
14 | extern "C" { | |
15 | #include "daqDA.h" | |
16 | } | |
17 | #include "event.h" | |
18 | #include "monitor.h" | |
19 | #include "AliRawReaderDate.h" | |
20 | #include "AliITSRawStreamSPD.h" | |
21 | #include "AliITSOnlineSPDscan.h" | |
22 | #include "AliITSOnlineSPDscanSingle.h" | |
23 | #include "AliITSOnlineSPDscanMultiple.h" | |
24 | #include "AliITSOnlineSPDscanMeanTh.h" | |
25 | #include "AliITSOnlineSPDscanAnalyzer.h" | |
53ae21ce | 26 | #include "AliITSOnlineCalibrationSPDhandler.h" |
3ec5024c | 27 | #include "AliLog.h" |
28 | #include <iostream> | |
29 | #include <fstream> | |
30 | #include <TROOT.h> | |
31 | #include <TPluginManager.h> | |
53ae21ce | 32 | #include <TObjArray.h> |
33 | #include <TString.h> | |
3ec5024c | 34 | |
35 | int main(int argc, char **argv) { | |
36 | if (argc<2) { | |
37 | printf("Wrong number of arguments\n"); | |
38 | return -1; | |
39 | } | |
40 | ||
1fd93b67 | 41 | // make directory structure (if not here already): |
42 | system("mkdir ./calibResults >& /dev/null"); | |
43 | system("mkdir ./calibResults/Noisy >& /dev/null"); | |
44 | system("mkdir ./calibResults/NoisyToFXS >& /dev/null"); | |
53ae21ce | 45 | system("mkdir ./calibResults/DCSconfigToFXS >& /dev/null"); |
1fd93b67 | 46 | system("mkdir ./calibResults/Parameters >& /dev/null"); |
47 | system("mkdir ./calibResults/Reference >& /dev/null"); | |
48 | char *saveDirNoisy = "./calibResults/Noisy"; | |
1fd93b67 | 49 | char *saveDirNoisyToFXS = "./calibResults/NoisyToFXS"; |
53ae21ce | 50 | char *saveDirDCSconfigToFXS= "./calibResults/DCSconfigToFXS"; |
1fd93b67 | 51 | char *saveDirParameters = "./calibResults/Parameters"; |
52 | char *saveDirRef = "./calibResults/Reference"; | |
3ec5024c | 53 | |
53ae21ce | 54 | char *paramsFileName = "./standal_params.txt"; |
55 | char *permNoisyFileName = "./perm_noisy.txt"; | |
56 | ||
3ec5024c | 57 | // This line is needed in case of a stand-alone application w/o |
58 | // $ROOTSYS/etc/system.rootrc file | |
59 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", | |
60 | "*", | |
61 | "TStreamerInfo", | |
62 | "RIO", | |
63 | "TStreamerInfo()"); | |
64 | ||
65 | // turn off annoying warning messages | |
66 | new AliLog; | |
1fd93b67 | 67 | AliLog::Instance()->SetGlobalDebugLevel(-20); |
3ec5024c | 68 | |
69 | // calib scan types | |
70 | enum calib_types{MINTH,MEANTH,DAC,UNIMA,NOISE,DELAY}; | |
71 | ||
72 | ||
4ee23d3d | 73 | // ********* STEP 0: Get configuration files from db (if there are any) , then read parameters********* |
53ae21ce | 74 | UInt_t nrTuningParams = 0; |
75 | TObjArray paramNames; paramNames.SetOwner(kTRUE); | |
76 | TObjArray paramVals; paramVals.SetOwner(kTRUE); | |
77 | ||
78 | // tuning parameters: | |
79 | Int_t status = 0; | |
80 | #ifndef SPD_DA_OFF | |
81 | TString idp = "spd_standal_params"; | |
82 | status=daqDA_DB_getFile(idp.Data(),paramsFileName); | |
83 | if (status) { | |
84 | printf("Failed to get config file %s: status=%d. Using default tuning parameters.\n",idp.Data(),status); | |
85 | } | |
86 | #endif | |
87 | if (status==0) { | |
88 | ifstream paramsFile; | |
89 | paramsFile.open(paramsFileName, ifstream::in); | |
90 | if (paramsFile.fail()) { | |
91 | printf("No config file (%s) present. Using default tuning parameters.\n",paramsFileName); | |
92 | } | |
93 | else { | |
94 | while(1) { | |
95 | Char_t paramN[50]; | |
96 | Char_t paramV[50]; | |
97 | paramsFile >> paramN; | |
98 | if (paramsFile.eof()) break; | |
99 | paramsFile >> paramV; | |
100 | TString* paramNS = new TString(paramN); | |
101 | TString* paramVS = new TString(paramV); | |
102 | paramNames.AddAtAndExpand((TObject*)paramNS,nrTuningParams); | |
103 | paramVals.AddAtAndExpand((TObject*)paramVS,nrTuningParams); | |
104 | nrTuningParams++; | |
105 | if (paramsFile.eof()) break; | |
106 | } | |
107 | paramsFile.close(); | |
108 | } | |
109 | } | |
110 | // for (UInt_t i=0; i<nrTuningParams; i++) { | |
111 | // printf("Entry %d: N=%s , V=%s\n",i,((TString*)paramNames.At(i))->Data(),((TString*)paramVals.At(i))->Data()); | |
112 | // } | |
113 | ||
114 | // perm noisy list: | |
115 | Int_t permstatus = 0; | |
116 | #ifndef SPD_DA_OFF | |
117 | TString idn = "spd_perm_noisy"; | |
118 | permstatus=daqDA_DB_getFile(idn.Data(),permNoisyFileName); | |
119 | if (permstatus) { | |
120 | printf("Failed to get config file %s: status=%d. No additional noisy pixels added.\n",idn.Data(),permstatus); | |
121 | } | |
122 | #endif | |
123 | ||
124 | ||
125 | ||
126 | ||
127 | // ********* STEP 1: Produce scan container files (Reference Data). *********************************** | |
3ec5024c | 128 | int startSeg = 1; |
129 | ||
1fd93b67 | 130 | #ifndef SPD_DA_OFF |
3ec5024c | 131 | int runNr = atoi(getenv("DATE_RUN_NUMBER")); |
132 | #else | |
133 | int runNr = atoi(argv[1]); | |
134 | startSeg = 2; | |
135 | #endif | |
136 | ||
137 | // container objects | |
138 | AliITSOnlineSPDscan *scanObj[20]; | |
139 | Bool_t bScanInit[20]; | |
140 | for (UInt_t eqId=0; eqId<20; eqId++) { | |
141 | scanObj[eqId]=NULL; | |
142 | bScanInit[eqId]=kFALSE; | |
143 | } | |
144 | // header data variables | |
145 | UInt_t routerNr[20]; | |
146 | Bool_t halfStaveScanned[20][6]; | |
147 | UInt_t type[20]; | |
148 | Bool_t dataFormat[20]; | |
149 | UInt_t triggers[20]; | |
150 | Bool_t chipPresent[20][6][10]; | |
151 | UInt_t dacStart[20]; | |
152 | UInt_t dacEnd[20]; | |
153 | UInt_t dacStep[20]; | |
154 | UInt_t dacId[20]; | |
155 | UInt_t rowStart[20]; | |
156 | UInt_t rowEnd[20]; | |
157 | UInt_t rowValue[20]; | |
158 | UInt_t dacValue[20]; | |
159 | UInt_t dacHigh[20][6]; | |
160 | UInt_t dacLow[20][6]; | |
161 | UInt_t TPAmp[20][6]; | |
1fd93b67 | 162 | Bool_t minTHchipPresent[20][10]; |
3ec5024c | 163 | // current scan step flag |
164 | Int_t currentStep[20]; | |
165 | for (UInt_t eqId=0; eqId<20; eqId++) currentStep[eqId] = 9999; | |
166 | ||
167 | // loop over run segments | |
168 | for (int segNr=startSeg; segNr<argc; segNr++) { | |
169 | ||
170 | ||
171 | int status; | |
172 | ||
173 | /* define data source : this is argument 1 */ | |
174 | status=monitorSetDataSource( argv[segNr] ); | |
175 | if (status!=0) { | |
176 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
177 | return -1; | |
178 | } | |
179 | /* declare monitoring program */ | |
180 | status=monitorDeclareMp("ITS_SPD_CAL"); | |
181 | if (status!=0) { | |
182 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
183 | return -1; | |
184 | } | |
185 | /* define wait event timeout - 1s max */ | |
186 | monitorSetNowait(); | |
187 | monitorSetNoWaitNetworkTimeout(1000); | |
188 | ||
189 | ||
190 | struct eventHeaderStruct *event; | |
191 | eventTypeType eventT; | |
192 | UInt_t eventNr=0; | |
193 | ||
194 | ||
195 | /* main loop (infinite) */ | |
196 | for(;;) { | |
197 | ||
198 | /* check shutdown condition */ | |
1fd93b67 | 199 | #ifndef SPD_DA_OFF |
3ec5024c | 200 | if (daqDA_checkShutdown()) {break;} |
1fd93b67 | 201 | #endif |
3ec5024c | 202 | /* get next event (blocking call until timeout) */ |
203 | status=monitorGetEventDynamic((void **)&event); | |
204 | if (status==MON_ERR_EOF) { | |
205 | printf ("End of File detected\n"); | |
206 | break; /* end of monitoring file has been reached */ | |
207 | } | |
208 | if (status!=0) { | |
209 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
210 | break; | |
211 | } | |
212 | /* retry if got no event */ | |
213 | if (event==NULL) { | |
214 | printf("event==NULL\n"); | |
215 | continue; | |
216 | } | |
217 | ||
218 | eventT=event->eventType; | |
1fd93b67 | 219 | if (eventT == PHYSICS_EVENT){ |
3ec5024c | 220 | |
221 | ||
222 | eventNr++; | |
1fd93b67 | 223 | // printf("eventNr %d\n",eventNr); |
3ec5024c | 224 | |
225 | AliRawReader *reader = new AliRawReaderDate((void*)event); | |
226 | AliITSRawStreamSPD *str = new AliITSRawStreamSPD(reader); | |
227 | ||
228 | ||
229 | for (UInt_t eqId=0; eqId<20; eqId++) { | |
230 | ||
231 | reader->Reset(); | |
232 | reader->Select("ITSSPD",eqId,eqId); | |
233 | ||
234 | // Hit Event flags, specific for one event | |
235 | Bool_t hitEventHSIncremented[6]; | |
236 | Bool_t hitEventChipIncremented[6][10]; | |
237 | for (UInt_t hs=0; hs<6; hs++) { | |
238 | hitEventHSIncremented[hs] = kFALSE; | |
239 | for (UInt_t chip=0; chip<10; chip++) { | |
240 | hitEventChipIncremented[hs][chip] = kFALSE; | |
241 | } | |
242 | } | |
243 | ||
244 | if (str->ReadCalibHeader()) { | |
245 | // first check the type: | |
246 | if (bScanInit[eqId] && type[eqId]!=str->GetHtype()) { | |
247 | printf("Calib header problem. Type changed (%d -> %d)!\n",type[eqId],str->GetHtype()); | |
248 | } | |
249 | ||
250 | // read calib values | |
1fd93b67 | 251 | routerNr[eqId] = str->GetHrouterNr(); |
252 | type[eqId] = str->GetHtype(); | |
253 | dataFormat[eqId] = str->GetHdataFormat(); | |
254 | triggers[eqId] = str->GetHtriggers(); | |
255 | dacStart[eqId] = str->GetHdacStart(); | |
256 | dacEnd[eqId] = str->GetHdacEnd(); | |
257 | dacStep[eqId] = str->GetHdacStep(); | |
258 | dacId[eqId] = str->GetHdacId(); | |
259 | rowStart[eqId] = str->GetHrowStart(); | |
260 | rowEnd[eqId] = str->GetHrowEnd(); | |
261 | rowValue[eqId] = str->GetHrowValue(); | |
262 | dacValue[eqId] = str->GetHdacValue(); | |
3ec5024c | 263 | for (UInt_t hs=0; hs<6; hs++) { |
1fd93b67 | 264 | halfStaveScanned[eqId][hs] = str->GetHhalfStaveScanned(hs); |
265 | dacHigh[eqId][hs] = str->GetHdacHigh(hs); | |
266 | dacLow[eqId][hs] = str->GetHdacLow(hs); | |
267 | TPAmp[eqId][hs] = str->GetHTPAmp(hs); | |
3ec5024c | 268 | for (UInt_t chip=0; chip<10; chip++) { |
1fd93b67 | 269 | chipPresent[eqId][hs][chip] = str->GetHchipPresent(hs,chip); |
3ec5024c | 270 | } |
271 | } | |
1fd93b67 | 272 | for (UInt_t chip=0; chip<10; chip++) { |
273 | minTHchipPresent[eqId][chip] = str->GetHminTHchipPresent(chip); | |
274 | } | |
3ec5024c | 275 | |
276 | currentStep[eqId] = (dacValue[eqId]-dacStart[eqId])/dacStep[eqId]; | |
277 | if (type[eqId]==DELAY) { | |
278 | currentStep[eqId]=currentStep[eqId]*2; | |
279 | dacValue[eqId]=dacValue[eqId]*2; | |
280 | if (dacHigh[eqId][0]==128) { // misc_ctrl value | |
281 | currentStep[eqId]=currentStep[eqId]+1; | |
282 | dacValue[eqId]=dacValue[eqId]+1; | |
283 | } | |
284 | } | |
285 | ||
286 | // router nr check: | |
287 | if (routerNr[eqId]!=eqId) { | |
288 | printf("Router nr problem? Router nr %d != EqID %d\n",routerNr[eqId],eqId); | |
289 | } | |
290 | ||
291 | if (!bScanInit[eqId]) { | |
292 | // initialize container object | |
53ae21ce | 293 | TString fileName = Form("%s/SPDcal_run_%d_eq_%d.root",saveDirRef,runNr,eqId); |
3ec5024c | 294 | switch (type[eqId]) { |
295 | case NOISE: | |
296 | case UNIMA: | |
53ae21ce | 297 | scanObj[eqId] = new AliITSOnlineSPDscanSingle(fileName.Data()); |
3ec5024c | 298 | ((AliITSOnlineSPDscanSingle*)scanObj[eqId])->ClearThis(); |
299 | bScanInit[eqId]=kTRUE; | |
300 | break; | |
301 | case MINTH: | |
302 | case DAC: | |
303 | case DELAY: | |
53ae21ce | 304 | scanObj[eqId] = new AliITSOnlineSPDscanMultiple(fileName.Data()); |
3ec5024c | 305 | scanObj[eqId]->ClearThis(); |
306 | bScanInit[eqId]=kTRUE; | |
307 | break; | |
308 | case MEANTH: | |
53ae21ce | 309 | scanObj[eqId] = new AliITSOnlineSPDscanMeanTh(fileName.Data()); |
3ec5024c | 310 | scanObj[eqId]->ClearThis(); |
311 | bScanInit[eqId]=kTRUE; | |
312 | break; | |
313 | default: | |
314 | printf("Unknown scan type: %d.\n",type[eqId]); | |
315 | } | |
316 | // some multiple scan data | |
317 | if (type[eqId]==MINTH || type[eqId]==MEANTH || type[eqId]==DAC || type[eqId]==DELAY) { | |
318 | ((AliITSOnlineSPDscanMultiple*)scanObj[eqId])->SetDacId(dacId[eqId]); | |
319 | } | |
320 | // some common data | |
321 | scanObj[eqId]->SetRunNr((UInt_t)runNr); | |
322 | scanObj[eqId]->SetRouterNr(routerNr[eqId]); | |
323 | for (UInt_t hs=0; hs<6; hs++) { | |
324 | scanObj[eqId]->SetHalfStaveScanned(hs,halfStaveScanned[eqId][hs]); | |
325 | } | |
326 | scanObj[eqId]->SetType(type[eqId]); | |
327 | scanObj[eqId]->SetDataFormat(dataFormat[eqId]); | |
328 | for (Int_t hs=0; hs<6; hs++) { | |
329 | ||
330 | // remove later when the chip present is set correctly !!!!!!!!!!!!!!!!!!!!!!!!!!! | |
331 | Bool_t halfStavePresent = str->GetHalfStavePresent(hs); | |
332 | // remove later when the chip present is set correctly !!!!!!!!!!!!!!!!!!!!!!!!!!! | |
333 | ||
334 | for (UInt_t chip=0; chip<10; chip++) { | |
335 | scanObj[eqId]->SetChipPresent(hs,chip,chipPresent[eqId][hs][chip]); | |
336 | ||
337 | // remove later when the chip present is set correctly !!!!!!!!!!!!!!!!!!!!!!!!!!! | |
338 | if (halfStavePresent) scanObj[eqId]->SetChipPresent(hs,chip,kTRUE); | |
339 | // remove later when the chip present is set correctly !!!!!!!!!!!!!!!!!!!!!!!!!!! | |
340 | ||
341 | } | |
342 | } | |
343 | scanObj[eqId]->SetRowStart(rowStart[eqId]); | |
344 | scanObj[eqId]->SetRowEnd(rowEnd[eqId]); | |
345 | scanObj[eqId]->SetDacStart(dacStart[eqId]); | |
346 | scanObj[eqId]->SetDacEnd(dacEnd[eqId]); | |
347 | scanObj[eqId]->SetDacStep(dacStep[eqId]); | |
348 | } | |
349 | ||
350 | if (type[eqId]==MINTH) { | |
351 | scanObj[eqId]->SetTriggers(currentStep[eqId],triggers[eqId]); | |
352 | } | |
353 | if (type[eqId]==UNIMA || type[eqId]==NOISE) { | |
354 | if (currentStep[eqId]==9999) printf("SPDcalibratorStep1 (eq %d): single step\n",eqId); | |
355 | currentStep[eqId]=0; | |
356 | } | |
357 | if (type[eqId]==MINTH || type[eqId]==MEANTH || type[eqId]==DAC || type[eqId]==DELAY) { | |
358 | ((AliITSOnlineSPDscanMultiple*)scanObj[eqId])->SetDacValue(currentStep[eqId],dacValue[eqId]); | |
359 | if (type[eqId]==DELAY) { | |
360 | printf("SPDcalibratorStep1 (eq %d): DAC %d/%d , step %d\n",eqId,dacValue[eqId]/2,dacHigh[eqId][0],currentStep[eqId]); | |
361 | } | |
362 | else { | |
363 | printf("SPDcalibratorStep1 (eq %d): DAC %d , step %d\n",eqId,dacValue[eqId],currentStep[eqId]); | |
364 | } | |
365 | } | |
366 | if (type[eqId]==MEANTH) { | |
367 | for (Int_t hs=0; hs<6; hs++) { | |
368 | ((AliITSOnlineSPDscanMeanTh*)scanObj[eqId])->SetDacLow(currentStep[eqId],hs,dacLow[eqId][hs]); | |
369 | ((AliITSOnlineSPDscanMeanTh*)scanObj[eqId])->SetDacHigh(currentStep[eqId],hs,dacHigh[eqId][hs]); | |
370 | ((AliITSOnlineSPDscanMeanTh*)scanObj[eqId])->SetTPAmp(currentStep[eqId],hs,TPAmp[eqId][hs]); | |
371 | } | |
372 | } | |
373 | ||
374 | ||
375 | } | |
53ae21ce | 376 | |
3ec5024c | 377 | if (bScanInit[eqId]) { |
378 | while (str->Next()) { | |
379 | UInt_t hs = str->GetHalfStaveNr(); | |
380 | UInt_t chip = str->GetChipAddr(); | |
53ae21ce | 381 | //***remove last condition when minthpresent put correctly in calib header? |
1fd93b67 | 382 | #ifndef SPD_DA_OFF |
53ae21ce | 383 | if (type[eqId]!=MINTH || minTHchipPresent[eqId][chip] || runNr<=416900) { |
1fd93b67 | 384 | #else |
53ae21ce | 385 | if (type[eqId]!=MINTH || minTHchipPresent[eqId][chip] || runNr<=416900) { |
1fd93b67 | 386 | #endif |
53ae21ce | 387 | //************************************************************************* |
3ec5024c | 388 | scanObj[eqId]->IncrementHits(currentStep[eqId],hs,chip,str->GetChipCol(),str->GetChipRow()); |
53ae21ce | 389 | |
3ec5024c | 390 | if (!hitEventHSIncremented[hs]) { |
391 | scanObj[eqId]->IncrementHitEventsTot(currentStep[eqId],hs); | |
392 | hitEventHSIncremented[hs]=kTRUE; | |
393 | } | |
394 | ||
395 | if (!hitEventChipIncremented[hs][chip]) { | |
396 | scanObj[eqId]->IncrementHitEvents(currentStep[eqId],hs,chip); | |
397 | hitEventChipIncremented[hs][chip]=kTRUE; | |
398 | } | |
399 | } | |
400 | ||
401 | } | |
402 | ||
403 | if (type[eqId]!=MINTH) { // for minth, triggers are set from header info | |
404 | scanObj[eqId]->IncrementTriggers(currentStep[eqId]); | |
405 | } | |
406 | ||
407 | } | |
408 | ||
409 | } | |
410 | ||
411 | delete str; | |
412 | delete reader; | |
413 | ||
414 | } | |
415 | ||
416 | /* free resources */ | |
417 | free(event); | |
418 | ||
419 | } | |
420 | ||
421 | status = monitorLogout(); | |
422 | if (status != 0) { | |
423 | printf("monitorLogout() failed : %s\n",monitorDecodeError(status)); | |
424 | return -1; | |
425 | } | |
426 | ||
1fd93b67 | 427 | #ifndef SPD_DA_OFF |
3ec5024c | 428 | daqDA_progressReport((unsigned int)( ((Float_t)(segNr-startSeg+1))/(argc-startSeg)*50 )); |
429 | #else | |
430 | printf("progress: %d\n",(unsigned int)( ((Float_t)(segNr-startSeg+1))/(argc-startSeg)*50 )); | |
431 | #endif | |
432 | ||
433 | } | |
434 | ||
435 | // clean up scan objects | |
436 | for (UInt_t eqId=0; eqId<20; eqId++) { | |
437 | if (scanObj[eqId]!=NULL) delete scanObj[eqId]; | |
438 | } | |
439 | ||
440 | ||
441 | ||
442 | ||
443 | ||
53ae21ce | 444 | // ********* STEP 2: Analyze scan container files. ************************************************ |
445 | ||
446 | // clear noisyToFXS and DCSconfigToFXS dirs: | |
447 | TString command = Form("cd %s; rm -f *",saveDirNoisyToFXS); | |
448 | system(command.Data()); | |
449 | TString command2 = Form("cd %s; rm -f *",saveDirDCSconfigToFXS); | |
450 | system(command2.Data()); | |
451 | UInt_t nrNoisyFilesProduced=0; | |
452 | UInt_t nrDCSconfigFilesProduced=0; | |
3ec5024c | 453 | |
454 | AliITSOnlineSPDscanAnalyzer *analyzer; | |
455 | ||
456 | // *** *** *** start loop over equipments (eq_id) | |
457 | for (int eqId=0; eqId<20; eqId++) { | |
458 | ||
53ae21ce | 459 | // create analyzer for this eq |
460 | TString fileName = Form("%s/SPDcal_run_%d_eq_%d.root",saveDirRef,runNr,eqId); | |
461 | analyzer = new AliITSOnlineSPDscanAnalyzer(fileName.Data()); | |
462 | ||
463 | // configure analyzer with tuning parameters etc: | |
464 | for (UInt_t i=0; i<nrTuningParams; i++) { | |
465 | analyzer->SetParam(((TString*)paramNames.At(i))->Data(),((TString*)paramVals.At(i))->Data()); | |
466 | } | |
3ec5024c | 467 | |
4ee23d3d | 468 | UInt_t type = analyzer->GetType(); |
469 | UInt_t dacId = analyzer->GetDacId(); | |
470 | UInt_t routerNr = analyzer->GetRouterNr(); | |
3ec5024c | 471 | if (type!=99) { |
472 | if (type==DAC) { | |
473 | printf("SPD calibrator Step2: eqId %d, type %d, dacId %d\n",eqId,type,dacId); | |
474 | } | |
475 | else printf("SPD calibrator Step2: eqId %d type %d\n",eqId,type); | |
476 | } | |
4ee23d3d | 477 | |
478 | ||
3ec5024c | 479 | |
53ae21ce | 480 | // algorithms for the different types of scans: |
3ec5024c | 481 | |
482 | if (type==UNIMA) { | |
53ae21ce | 483 | |
3ec5024c | 484 | } |
53ae21ce | 485 | |
3ec5024c | 486 | else if (type==NOISE) { |
487 | if (analyzer->ProcessNoisyPixels(saveDirNoisy)) { | |
53ae21ce | 488 | // init dcs config text file |
489 | TString dcsConfigFileName = Form("%s/dcsConfig_run_%d_eq_%d.txt",saveDirDCSconfigToFXS,runNr,eqId); | |
490 | ofstream dcsfile; | |
491 | dcsfile.open(dcsConfigFileName.Data()); | |
492 | dcsfile << "[SPD SCAN]\n"; | |
493 | dcsfile << "RunNumber=" << runNr << "\n"; | |
494 | dcsfile << "Type=" << type << "\n"; | |
4ee23d3d | 495 | dcsfile << "Router=" << routerNr << "\n"; |
53ae21ce | 496 | dcsfile << "ActualDetCoonfiguration=" << "0,-1,-1\n"; // dummy values for now |
497 | dcsfile << "[NOISY]\n"; | |
498 | nrDCSconfigFilesProduced++; | |
499 | for (UInt_t iModule=0; iModule<12; iModule++) { | |
500 | UInt_t module = AliITSRawStreamSPD::GetModuleNumber(eqId,iModule); | |
501 | AliITSOnlineCalibrationSPDhandler *handler = analyzer->GetOnlineCalibrationHandler(module); | |
502 | if (permstatus==0) { // add permanent noisy list | |
503 | UInt_t newNoisy = handler->ReadNoisyFromText(permNoisyFileName); | |
504 | if (newNoisy>0) { | |
505 | printf("%d additional noisy pixels added from permanent list.\n",newNoisy); | |
506 | } | |
507 | } | |
3ec5024c | 508 | if (analyzer->SaveDeadNoisyPixels(module,saveDirNoisy)) { |
53ae21ce | 509 | UInt_t nrNoisy = handler->GetNrNoisy(module); |
510 | UInt_t headkey=20*10*6; | |
511 | for (UInt_t ind=0; ind<nrNoisy; ind++) { | |
512 | UInt_t newkey = handler->GetNoisyEqIdAt(module,ind)*10*6 + | |
513 | handler->GetNoisyHSAt(module,ind)*10 + | |
514 | handler->GetNoisyChipAt(module,ind); | |
515 | if (newkey!=headkey) { // print eqId,hs,chip_header | |
516 | headkey = newkey; | |
517 | dcsfile << "-" << newkey/(6*10) << "," << (newkey%(6*10))/10 << "," << (newkey%(6*10))%10 << "\n"; | |
518 | } | |
519 | dcsfile << handler->GetNoisyColAt(module,ind) << "," << handler->GetNoisyRowAt(module,ind) << "\n"; | |
520 | } | |
1fd93b67 | 521 | nrNoisyFilesProduced++; |
53ae21ce | 522 | TString command = Form("cp %s/SPD_DeadNoisy_%d.root %s/.",saveDirNoisy,module,saveDirNoisyToFXS); |
523 | system(command.Data()); | |
3ec5024c | 524 | } |
525 | } | |
53ae21ce | 526 | dcsfile.close(); |
3ec5024c | 527 | } |
528 | } | |
53ae21ce | 529 | |
3ec5024c | 530 | else if (type==MINTH || (type==DAC && dacId==39)) { |
53ae21ce | 531 | // init dcs config text file |
532 | TString dcsConfigFileName = Form("%s/dcsConfig_run_%d_eq_%d.txt",saveDirDCSconfigToFXS,runNr,eqId); | |
533 | ofstream dcsfile; | |
534 | dcsfile.open(dcsConfigFileName.Data()); | |
535 | dcsfile << "[SPD SCAN]\n"; | |
536 | dcsfile << "RunNumber=" << runNr << "\n"; | |
537 | dcsfile << "Type=" << type << "\n"; | |
4ee23d3d | 538 | dcsfile << "Router=" << routerNr << "\n"; |
53ae21ce | 539 | dcsfile << "ActualDetCoonfiguration=" << "0,-1,-1\n"; // dummy values for now |
540 | dcsfile << "[DACvalues]\n"; | |
541 | nrDCSconfigFilesProduced++; | |
542 | TString ofileName = Form("%s/minth_eq_%d.txt",saveDirParameters,eqId); | |
3ec5024c | 543 | ofstream ofile; |
53ae21ce | 544 | ofile.open (ofileName.Data()); |
3ec5024c | 545 | for (UInt_t hs=0; hs<6; hs++) { |
546 | for (UInt_t chipNr=0; chipNr<10; chipNr++) { | |
53ae21ce | 547 | Int_t minTh = -1; |
548 | if (analyzer->GetOnlineScan()->GetChipPresent(hs,chipNr)) { | |
549 | minTh = analyzer->GetMinTh(hs,chipNr); | |
550 | if (minTh!=-1) { | |
551 | dcsfile << "39," << eqId << "," << hs << "," << chipNr << "=" << minTh << "\n"; | |
552 | } | |
553 | else { | |
554 | printf("MinTh failed for Eq %d , HS %d , Chip %d\n",eqId,hs,chipNr); | |
555 | } | |
556 | } | |
557 | ofile << minTh; | |
3ec5024c | 558 | ofile << "\t"; |
559 | } | |
560 | ofile << "\n"; | |
561 | } | |
562 | ofile.close(); | |
53ae21ce | 563 | dcsfile.close(); |
3ec5024c | 564 | } |
53ae21ce | 565 | |
3ec5024c | 566 | else if (type==DELAY) { |
53ae21ce | 567 | // init dcs config text file |
568 | TString dcsConfigFileName = Form("%s/dcsConfig_run_%d_eq_%d.txt",saveDirDCSconfigToFXS,runNr,eqId); | |
569 | ofstream dcsfile; | |
570 | dcsfile.open(dcsConfigFileName.Data()); | |
571 | dcsfile << "[SPD SCAN]\n"; | |
572 | dcsfile << "RunNumber=" << runNr << "\n"; | |
573 | dcsfile << "Type=" << type << "\n"; | |
4ee23d3d | 574 | dcsfile << "Router=" << routerNr << "\n"; |
53ae21ce | 575 | dcsfile << "ActualDetCoonfiguration=" << "0,-1,-1\n"; // dummy values for now |
576 | dcsfile << "[DACvalues]\n"; | |
577 | nrDCSconfigFilesProduced++; | |
578 | TString ofileName = Form("%s/delay_eq_%d.txt",saveDirParameters,eqId); | |
3ec5024c | 579 | ofstream ofile; |
53ae21ce | 580 | ofile.open (ofileName.Data()); |
3ec5024c | 581 | for (UInt_t hs=0; hs<6; hs++) { |
582 | for (UInt_t chipNr=0; chipNr<10; chipNr++) { | |
53ae21ce | 583 | Int_t clockCycle = -1; |
584 | Int_t delayCtrl = -1; | |
585 | Int_t miscCtrl = -1; | |
586 | if (analyzer->GetOnlineScan()->GetChipPresent(hs,chipNr)) { | |
587 | clockCycle = analyzer->GetDelay(hs,chipNr); | |
588 | delayCtrl = clockCycle/2; | |
589 | miscCtrl = 192; | |
590 | if (clockCycle!=-1) { | |
591 | if (clockCycle%2==1) miscCtrl = 128; | |
592 | dcsfile << "42," << eqId << "," << hs << "," << chipNr << "=" << delayCtrl << "\n"; | |
593 | dcsfile << "43," << eqId << "," << hs << "," << chipNr << "=" << miscCtrl << "\n"; | |
594 | } | |
595 | else { | |
596 | printf("Delay failed for Eq %d , HS %d , Chip %d\n",eqId,hs,chipNr); | |
597 | } | |
598 | } | |
3ec5024c | 599 | ofile << delayCtrl << "/" << miscCtrl; |
600 | ofile << "\t"; | |
601 | } | |
602 | ofile << "\n"; | |
603 | } | |
604 | ofile.close(); | |
53ae21ce | 605 | dcsfile.close(); |
3ec5024c | 606 | } |
607 | ||
3ec5024c | 608 | delete analyzer; |
609 | ||
1fd93b67 | 610 | #ifndef SPD_DA_OFF |
3ec5024c | 611 | daqDA_progressReport((unsigned int)(50+(eqId+1)*2.5)); |
612 | #else | |
613 | printf("progress: %d\n",(unsigned int)(50+(eqId+1)*2.5)); | |
614 | #endif | |
615 | ||
616 | } | |
617 | // *** *** *** end loop over equipments (eq_id) | |
618 | ||
619 | ||
1fd93b67 | 620 | if (nrNoisyFilesProduced>0) { |
621 | // send a tared file of all new noisy maps | |
53ae21ce | 622 | TString command = Form("cd %s; tar -cf noisy.tar *",saveDirNoisyToFXS); |
623 | printf("\n\n%s\n\n",command.Data()); | |
624 | system(command.Data()); | |
625 | #ifndef SPD_DA_OFF | |
626 | TString fileName = Form("%s/noisy.tar",saveDirNoisyToFXS); | |
627 | TString id = "SPD_noisy"; | |
628 | Int_t status = daqDA_FES_storeFile(fileName.Data(),id.Data()); | |
1fd93b67 | 629 | if (status!=0) { |
53ae21ce | 630 | printf("Failed to export file %s , status %d\n",fileName.Data(),status); |
1fd93b67 | 631 | return -1; |
632 | } | |
53ae21ce | 633 | #endif |
3ec5024c | 634 | } |
53ae21ce | 635 | |
636 | if (nrDCSconfigFilesProduced>0) { | |
637 | // send a tared file of all the dcsConfig text files | |
638 | TString command = Form("cd %s; tar -cf dcsConfig.tar *",saveDirDCSconfigToFXS); | |
639 | // printf("\n\n%s\n\n",command.Data()); | |
640 | system(command.Data()); | |
641 | #ifndef SPD_DA_OFF | |
642 | TString fileName = Form("%s/dcsConfig.tar",saveDirDCSconfigToFXS); | |
643 | TString id = "SPD_dcsConfig"; | |
644 | Int_t status = daqDA_FES_storeFile(fileName.Data(),id.Data()); | |
645 | if (status!=0) { | |
646 | printf("Failed to export file %s , status %d\n",fileName.Data(),status); | |
647 | return -1; | |
648 | } | |
3ec5024c | 649 | #endif |
53ae21ce | 650 | } |
651 | ||
3ec5024c | 652 | |
653 | ||
654 | return 0; | |
655 | } |