]>
Commit | Line | Data |
---|---|---|
6727e2db | 1 | /* |
803e6db5 | 2 | Contact: henrik.tydesjo@cern.ch |
3 | Link: tydes.home.cern.ch/tydes/doc/CalibrationOverview/CalibrationAlgorithms/ | |
64acb961 | 4 | Run Type: DAQ_MIN_TH_SCAN,DAQ_MEAN_TH_SCAN,DAQ_UNIFORMITY_SCAN,DAQ_NOISY_PIX_SCAN,DAQ_PIX_DELAY_SCAN |
803e6db5 | 5 | DA Type: LDC |
6 | Number of events needed: Depending on scan type | |
7 | Input Files: spd_standal_params,spd_perm_noisy , ./calibResults/ScanNoisy/* , raw data | |
8 | Output Files: ./calibResults/ScanReference/* , ./calibResults/ScanDCSconfigToFXS/* , ./calibResults/ScanNoisyToFXS/* , ./calibResults/ScanNoisy/* | |
9 | Trigger types used: PHYSICS | |
6727e2db | 10 | */ |
11 | ||
1fd93b67 | 12 | //////////////////////////////////////////////////////////////////////////////// |
6727e2db | 13 | // This program can be compiled in two modes. // |
1fd93b67 | 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 | //////////////////////////////////////////////////////////////////////////////// | |
3ec5024c | 24 | |
3f917533 | 25 | #ifndef SPD_DA_OFF |
3ec5024c | 26 | extern "C" { |
27 | #include "daqDA.h" | |
28 | } | |
3f917533 | 29 | #endif |
3ec5024c | 30 | #include "event.h" |
31 | #include "monitor.h" | |
32 | #include "AliRawReaderDate.h" | |
33 | #include "AliITSRawStreamSPD.h" | |
34 | #include "AliITSOnlineSPDscan.h" | |
35 | #include "AliITSOnlineSPDscanSingle.h" | |
36 | #include "AliITSOnlineSPDscanMultiple.h" | |
37 | #include "AliITSOnlineSPDscanMeanTh.h" | |
38 | #include "AliITSOnlineSPDscanAnalyzer.h" | |
53ae21ce | 39 | #include "AliITSOnlineCalibrationSPDhandler.h" |
3ec5024c | 40 | #include "AliLog.h" |
41 | #include <iostream> | |
42 | #include <fstream> | |
43 | #include <TROOT.h> | |
44 | #include <TPluginManager.h> | |
53ae21ce | 45 | #include <TObjArray.h> |
478d804c | 46 | #include <TObjString.h> |
53ae21ce | 47 | #include <TString.h> |
1c039f23 | 48 | #include <TFitter.h> |
3ec5024c | 49 | |
50 | int main(int argc, char **argv) { | |
51 | if (argc<2) { | |
52 | printf("Wrong number of arguments\n"); | |
53 | return -1; | |
54 | } | |
55 | ||
6727e2db | 56 | // directory structure, hard coded |
57 | char *saveDirNoisy = "./calibResults/ScanNoisy"; // may NOT delete content | |
58 | char *saveDirNoisyToFXS = "./calibResults/ScanNoisyToFXS"; // may delete content | |
59 | char *saveDirDCSconfigToFXS= "./calibResults/ScanDCSconfigToFXS"; // may delete content | |
60 | char *saveDirRef = "./calibResults/ScanReference"; // may delete content | |
4f88491f | 61 | char *saveDirIdsToFXS = "./calibResults/IdsToFXS"; // may delete content |
6727e2db | 62 | char *configFilesDir = "./configFiles"; // may delete content |
4f88491f | 63 | |
6727e2db | 64 | // make sure the directory structure is correct: |
1fd93b67 | 65 | system("mkdir ./calibResults >& /dev/null"); |
6727e2db | 66 | system("mkdir ./calibResults/ScanNoisy >& /dev/null"); |
67 | system("mkdir ./calibResults/ScanNoisyToFXS >& /dev/null"); | |
68 | system("mkdir ./calibResults/ScanDCSconfigToFXS >& /dev/null"); | |
69 | system("mkdir ./calibResults/ScanReference >& /dev/null"); | |
4f88491f | 70 | system("mkdir ./calibResults/IdsToFXS >& /dev/null"); |
6727e2db | 71 | system("mkdir ./configFiles >& /dev/null"); |
72 | // prameters config files | |
73 | TString paramsFileName = Form("%s/standal_params.txt",configFilesDir); | |
74 | TString permNoisyFileName = Form("%s/perm_noisy.txt",configFilesDir); | |
53ae21ce | 75 | |
1c039f23 | 76 | TFitter *fitter = new TFitter(3); |
77 | TVirtualFitter::SetFitter(fitter); | |
78 | ||
3ec5024c | 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 | |
88 | new AliLog; | |
1fd93b67 | 89 | AliLog::Instance()->SetGlobalDebugLevel(-20); |
3ec5024c | 90 | |
91 | // calib scan types | |
92 | enum calib_types{MINTH,MEANTH,DAC,UNIMA,NOISE,DELAY}; | |
93 | ||
94 | ||
4ee23d3d | 95 | // ********* STEP 0: Get configuration files from db (if there are any) , then read parameters********* |
53ae21ce | 96 | UInt_t nrTuningParams = 0; |
97 | TObjArray paramNames; paramNames.SetOwner(kTRUE); | |
98 | TObjArray paramVals; paramVals.SetOwner(kTRUE); | |
99 | ||
100 | // tuning parameters: | |
101 | Int_t status = 0; | |
102 | #ifndef SPD_DA_OFF | |
103 | TString idp = "spd_standal_params"; | |
6727e2db | 104 | status=daqDA_DB_getFile(idp.Data(),paramsFileName.Data()); |
53ae21ce | 105 | if (status) { |
106 | printf("Failed to get config file %s: status=%d. Using default tuning parameters.\n",idp.Data(),status); | |
7d25cc4b | 107 | TString rmCmd = Form("rm -f %s",paramsFileName.Data()); |
108 | system(rmCmd.Data()); | |
53ae21ce | 109 | } |
110 | #endif | |
111 | if (status==0) { | |
112 | ifstream paramsFile; | |
6727e2db | 113 | paramsFile.open(paramsFileName.Data(), ifstream::in); |
53ae21ce | 114 | if (paramsFile.fail()) { |
6727e2db | 115 | printf("No config file (%s) present. Using default tuning parameters.\n",paramsFileName.Data()); |
53ae21ce | 116 | } |
117 | else { | |
118 | while(1) { | |
119 | Char_t paramN[50]; | |
120 | Char_t paramV[50]; | |
121 | paramsFile >> paramN; | |
122 | if (paramsFile.eof()) break; | |
123 | paramsFile >> paramV; | |
478d804c | 124 | paramNames.AddAtAndExpand(new TObjString(paramN),nrTuningParams); |
125 | paramVals.AddAtAndExpand(new TObjString(paramV),nrTuningParams); | |
53ae21ce | 126 | nrTuningParams++; |
127 | if (paramsFile.eof()) break; | |
128 | } | |
129 | paramsFile.close(); | |
130 | } | |
131 | } | |
132 | // for (UInt_t i=0; i<nrTuningParams; i++) { | |
478d804c | 133 | // // printf("Entry %d: N=%s , V=%s\n",i,((TString*)paramNames.At(i))->Data(),((TString*)paramVals.At(i))->Data()); |
134 | // printf("Entry %d: N=%s , V=%s\n",i,((TObjString*)paramNames.At(i))->GetString().Data(),((TObjString*)paramVals.At(i))->GetString().Data()); | |
53ae21ce | 135 | // } |
136 | ||
137 | // perm noisy list: | |
138 | Int_t permstatus = 0; | |
139 | #ifndef SPD_DA_OFF | |
140 | TString idn = "spd_perm_noisy"; | |
6727e2db | 141 | permstatus=daqDA_DB_getFile(idn.Data(),permNoisyFileName.Data()); |
53ae21ce | 142 | if (permstatus) { |
6727e2db | 143 | printf("Failed to get config file %s: status=%d. No permanently noisy pixels will be added.\n",idn.Data(),permstatus); |
7d25cc4b | 144 | TString rmCmd = Form("rm -f %s",permNoisyFileName.Data()); |
145 | system(rmCmd.Data()); | |
53ae21ce | 146 | } |
147 | #endif | |
148 | ||
149 | ||
150 | ||
151 | ||
152 | // ********* STEP 1: Produce scan container files (Reference Data). *********************************** | |
3ec5024c | 153 | int startSeg = 1; |
154 | ||
1fd93b67 | 155 | #ifndef SPD_DA_OFF |
43cfb793 | 156 | if (getenv("DATE_RUN_NUMBER")==0) { |
157 | printf("DATE_RUN_NUMBER not properly set.\n"); | |
158 | return -1; | |
159 | } | |
3ec5024c | 160 | int runNr = atoi(getenv("DATE_RUN_NUMBER")); |
161 | #else | |
162 | int runNr = atoi(argv[1]); | |
163 | startSeg = 2; | |
164 | #endif | |
165 | ||
166 | // container objects | |
167 | AliITSOnlineSPDscan *scanObj[20]; | |
168 | Bool_t bScanInit[20]; | |
169 | for (UInt_t eqId=0; eqId<20; eqId++) { | |
170 | scanObj[eqId]=NULL; | |
171 | bScanInit[eqId]=kFALSE; | |
172 | } | |
173 | // header data variables | |
174 | UInt_t routerNr[20]; | |
175 | Bool_t halfStaveScanned[20][6]; | |
176 | UInt_t type[20]; | |
177 | Bool_t dataFormat[20]; | |
178 | UInt_t triggers[20]; | |
179 | Bool_t chipPresent[20][6][10]; | |
180 | UInt_t dacStart[20]; | |
181 | UInt_t dacEnd[20]; | |
182 | UInt_t dacStep[20]; | |
183 | UInt_t dacId[20]; | |
184 | UInt_t rowStart[20]; | |
185 | UInt_t rowEnd[20]; | |
186 | UInt_t rowValue[20]; | |
187 | UInt_t dacValue[20]; | |
188 | UInt_t dacHigh[20][6]; | |
189 | UInt_t dacLow[20][6]; | |
190 | UInt_t TPAmp[20][6]; | |
1fd93b67 | 191 | Bool_t minTHchipPresent[20][10]; |
3ec5024c | 192 | // current scan step flag |
193 | Int_t currentStep[20]; | |
194 | for (UInt_t eqId=0; eqId<20; eqId++) currentStep[eqId] = 9999; | |
195 | ||
196 | // loop over run segments | |
197 | for (int segNr=startSeg; segNr<argc; segNr++) { | |
198 | ||
3ec5024c | 199 | int status; |
200 | ||
201 | /* define data source : this is argument 1 */ | |
202 | status=monitorSetDataSource( argv[segNr] ); | |
203 | if (status!=0) { | |
204 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
205 | return -1; | |
206 | } | |
207 | /* declare monitoring program */ | |
208 | status=monitorDeclareMp("ITS_SPD_CAL"); | |
209 | if (status!=0) { | |
210 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
211 | return -1; | |
212 | } | |
213 | /* define wait event timeout - 1s max */ | |
214 | monitorSetNowait(); | |
215 | monitorSetNoWaitNetworkTimeout(1000); | |
6727e2db | 216 | |
217 | ||
3ec5024c | 218 | UInt_t eventNr=0; |
219 | ||
3ec5024c | 220 | /* main loop (infinite) */ |
221 | for(;;) { | |
6727e2db | 222 | |
223 | struct eventHeaderStruct *event; | |
224 | eventTypeType eventT; | |
225 | ||
3ec5024c | 226 | /* check shutdown condition */ |
1fd93b67 | 227 | #ifndef SPD_DA_OFF |
3ec5024c | 228 | if (daqDA_checkShutdown()) {break;} |
1fd93b67 | 229 | #endif |
3ec5024c | 230 | /* get next event (blocking call until timeout) */ |
231 | status=monitorGetEventDynamic((void **)&event); | |
232 | if (status==MON_ERR_EOF) { | |
233 | printf ("End of File detected\n"); | |
234 | break; /* end of monitoring file has been reached */ | |
235 | } | |
236 | if (status!=0) { | |
237 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
238 | break; | |
239 | } | |
240 | /* retry if got no event */ | |
241 | if (event==NULL) { | |
3ec5024c | 242 | continue; |
243 | } | |
244 | ||
245 | eventT=event->eventType; | |
6727e2db | 246 | if (eventT == PHYSICS_EVENT) { |
247 | ||
3ec5024c | 248 | eventNr++; |
1fd93b67 | 249 | // printf("eventNr %d\n",eventNr); |
6727e2db | 250 | |
3ec5024c | 251 | AliRawReader *reader = new AliRawReaderDate((void*)event); |
252 | AliITSRawStreamSPD *str = new AliITSRawStreamSPD(reader); | |
6727e2db | 253 | |
3ec5024c | 254 | for (UInt_t eqId=0; eqId<20; eqId++) { |
6727e2db | 255 | |
3ec5024c | 256 | reader->Reset(); |
257 | reader->Select("ITSSPD",eqId,eqId); | |
6727e2db | 258 | |
3ec5024c | 259 | // Hit Event flags, specific for one event |
260 | Bool_t hitEventHSIncremented[6]; | |
261 | Bool_t hitEventChipIncremented[6][10]; | |
262 | for (UInt_t hs=0; hs<6; hs++) { | |
263 | hitEventHSIncremented[hs] = kFALSE; | |
264 | for (UInt_t chip=0; chip<10; chip++) { | |
265 | hitEventChipIncremented[hs][chip] = kFALSE; | |
266 | } | |
267 | } | |
6727e2db | 268 | |
3f917533 | 269 | if (str->ReadCalibHeader()>0) { |
3ec5024c | 270 | // first check the type: |
271 | if (bScanInit[eqId] && type[eqId]!=str->GetHtype()) { | |
272 | printf("Calib header problem. Type changed (%d -> %d)!\n",type[eqId],str->GetHtype()); | |
273 | } | |
274 | ||
275 | // read calib values | |
1fd93b67 | 276 | routerNr[eqId] = str->GetHrouterNr(); |
277 | type[eqId] = str->GetHtype(); | |
278 | dataFormat[eqId] = str->GetHdataFormat(); | |
279 | triggers[eqId] = str->GetHtriggers(); | |
280 | dacStart[eqId] = str->GetHdacStart(); | |
281 | dacEnd[eqId] = str->GetHdacEnd(); | |
282 | dacStep[eqId] = str->GetHdacStep(); | |
283 | dacId[eqId] = str->GetHdacId(); | |
284 | rowStart[eqId] = str->GetHrowStart(); | |
285 | rowEnd[eqId] = str->GetHrowEnd(); | |
286 | rowValue[eqId] = str->GetHrowValue(); | |
64acb961 | 287 | dacValue[eqId] = str->GetHdacValue(); // this will change below for MEANTH scan |
288 | ||
3ec5024c | 289 | for (UInt_t hs=0; hs<6; hs++) { |
1fd93b67 | 290 | halfStaveScanned[eqId][hs] = str->GetHhalfStaveScanned(hs); |
291 | dacHigh[eqId][hs] = str->GetHdacHigh(hs); | |
292 | dacLow[eqId][hs] = str->GetHdacLow(hs); | |
293 | TPAmp[eqId][hs] = str->GetHTPAmp(hs); | |
3ec5024c | 294 | for (UInt_t chip=0; chip<10; chip++) { |
64acb961 | 295 | chipPresent[eqId][hs][chip] = str->GetHchipPresent(hs,chip); |
296 | if (type[eqId]==MEANTH && chipPresent[eqId][hs][chip]) dacValue[eqId] = str->GetHdacLow(hs); | |
3ec5024c | 297 | } |
298 | } | |
1fd93b67 | 299 | for (UInt_t chip=0; chip<10; chip++) { |
300 | minTHchipPresent[eqId][chip] = str->GetHminTHchipPresent(chip); | |
301 | } | |
3ec5024c | 302 | |
303 | currentStep[eqId] = (dacValue[eqId]-dacStart[eqId])/dacStep[eqId]; | |
304 | if (type[eqId]==DELAY) { | |
305 | currentStep[eqId]=currentStep[eqId]*2; | |
306 | dacValue[eqId]=dacValue[eqId]*2; | |
307 | if (dacHigh[eqId][0]==128) { // misc_ctrl value | |
308 | currentStep[eqId]=currentStep[eqId]+1; | |
309 | dacValue[eqId]=dacValue[eqId]+1; | |
310 | } | |
311 | } | |
312 | ||
313 | // router nr check: | |
314 | if (routerNr[eqId]!=eqId) { | |
315 | printf("Router nr problem? Router nr %d != EqID %d\n",routerNr[eqId],eqId); | |
316 | } | |
317 | ||
318 | if (!bScanInit[eqId]) { | |
319 | // initialize container object | |
53ae21ce | 320 | TString fileName = Form("%s/SPDcal_run_%d_eq_%d.root",saveDirRef,runNr,eqId); |
3ec5024c | 321 | switch (type[eqId]) { |
322 | case NOISE: | |
323 | case UNIMA: | |
53ae21ce | 324 | scanObj[eqId] = new AliITSOnlineSPDscanSingle(fileName.Data()); |
3ec5024c | 325 | ((AliITSOnlineSPDscanSingle*)scanObj[eqId])->ClearThis(); |
326 | bScanInit[eqId]=kTRUE; | |
327 | break; | |
328 | case MINTH: | |
329 | case DAC: | |
330 | case DELAY: | |
53ae21ce | 331 | scanObj[eqId] = new AliITSOnlineSPDscanMultiple(fileName.Data()); |
3ec5024c | 332 | scanObj[eqId]->ClearThis(); |
333 | bScanInit[eqId]=kTRUE; | |
334 | break; | |
335 | case MEANTH: | |
53ae21ce | 336 | scanObj[eqId] = new AliITSOnlineSPDscanMeanTh(fileName.Data()); |
3ec5024c | 337 | scanObj[eqId]->ClearThis(); |
338 | bScanInit[eqId]=kTRUE; | |
339 | break; | |
340 | default: | |
341 | printf("Unknown scan type: %d.\n",type[eqId]); | |
342 | } | |
343 | // some multiple scan data | |
344 | if (type[eqId]==MINTH || type[eqId]==MEANTH || type[eqId]==DAC || type[eqId]==DELAY) { | |
345 | ((AliITSOnlineSPDscanMultiple*)scanObj[eqId])->SetDacId(dacId[eqId]); | |
346 | } | |
347 | // some common data | |
348 | scanObj[eqId]->SetRunNr((UInt_t)runNr); | |
349 | scanObj[eqId]->SetRouterNr(routerNr[eqId]); | |
350 | for (UInt_t hs=0; hs<6; hs++) { | |
351 | scanObj[eqId]->SetHalfStaveScanned(hs,halfStaveScanned[eqId][hs]); | |
352 | } | |
353 | scanObj[eqId]->SetType(type[eqId]); | |
354 | scanObj[eqId]->SetDataFormat(dataFormat[eqId]); | |
64acb961 | 355 | for (Int_t hs=0; hs<6; hs++) { |
3ec5024c | 356 | for (UInt_t chip=0; chip<10; chip++) { |
357 | scanObj[eqId]->SetChipPresent(hs,chip,chipPresent[eqId][hs][chip]); | |
3ec5024c | 358 | } |
359 | } | |
360 | scanObj[eqId]->SetRowStart(rowStart[eqId]); | |
361 | scanObj[eqId]->SetRowEnd(rowEnd[eqId]); | |
362 | scanObj[eqId]->SetDacStart(dacStart[eqId]); | |
363 | scanObj[eqId]->SetDacEnd(dacEnd[eqId]); | |
364 | scanObj[eqId]->SetDacStep(dacStep[eqId]); | |
365 | } | |
366 | ||
367 | if (type[eqId]==MINTH) { | |
368 | scanObj[eqId]->SetTriggers(currentStep[eqId],triggers[eqId]); | |
369 | } | |
370 | if (type[eqId]==UNIMA || type[eqId]==NOISE) { | |
371 | if (currentStep[eqId]==9999) printf("SPDcalibratorStep1 (eq %d): single step\n",eqId); | |
372 | currentStep[eqId]=0; | |
373 | } | |
374 | if (type[eqId]==MINTH || type[eqId]==MEANTH || type[eqId]==DAC || type[eqId]==DELAY) { | |
375 | ((AliITSOnlineSPDscanMultiple*)scanObj[eqId])->SetDacValue(currentStep[eqId],dacValue[eqId]); | |
376 | if (type[eqId]==DELAY) { | |
377 | printf("SPDcalibratorStep1 (eq %d): DAC %d/%d , step %d\n",eqId,dacValue[eqId]/2,dacHigh[eqId][0],currentStep[eqId]); | |
378 | } | |
379 | else { | |
380 | printf("SPDcalibratorStep1 (eq %d): DAC %d , step %d\n",eqId,dacValue[eqId],currentStep[eqId]); | |
381 | } | |
382 | } | |
383 | if (type[eqId]==MEANTH) { | |
384 | for (Int_t hs=0; hs<6; hs++) { | |
385 | ((AliITSOnlineSPDscanMeanTh*)scanObj[eqId])->SetDacLow(currentStep[eqId],hs,dacLow[eqId][hs]); | |
386 | ((AliITSOnlineSPDscanMeanTh*)scanObj[eqId])->SetDacHigh(currentStep[eqId],hs,dacHigh[eqId][hs]); | |
387 | ((AliITSOnlineSPDscanMeanTh*)scanObj[eqId])->SetTPAmp(currentStep[eqId],hs,TPAmp[eqId][hs]); | |
388 | } | |
389 | } | |
390 | ||
391 | ||
392 | } | |
53ae21ce | 393 | |
3ec5024c | 394 | if (bScanInit[eqId]) { |
395 | while (str->Next()) { | |
396 | UInt_t hs = str->GetHalfStaveNr(); | |
397 | UInt_t chip = str->GetChipAddr(); | |
53ae21ce | 398 | //***remove last condition when minthpresent put correctly in calib header? |
1fd93b67 | 399 | #ifndef SPD_DA_OFF |
53ae21ce | 400 | if (type[eqId]!=MINTH || minTHchipPresent[eqId][chip] || runNr<=416900) { |
1fd93b67 | 401 | #else |
53ae21ce | 402 | if (type[eqId]!=MINTH || minTHchipPresent[eqId][chip] || runNr<=416900) { |
1fd93b67 | 403 | #endif |
6727e2db | 404 | //************************************************************************* |
3ec5024c | 405 | scanObj[eqId]->IncrementHits(currentStep[eqId],hs,chip,str->GetChipCol(),str->GetChipRow()); |
6727e2db | 406 | |
3ec5024c | 407 | if (!hitEventHSIncremented[hs]) { |
408 | scanObj[eqId]->IncrementHitEventsTot(currentStep[eqId],hs); | |
409 | hitEventHSIncremented[hs]=kTRUE; | |
410 | } | |
6727e2db | 411 | |
3ec5024c | 412 | if (!hitEventChipIncremented[hs][chip]) { |
413 | scanObj[eqId]->IncrementHitEvents(currentStep[eqId],hs,chip); | |
414 | hitEventChipIncremented[hs][chip]=kTRUE; | |
415 | } | |
416 | } | |
417 | ||
418 | } | |
419 | ||
420 | if (type[eqId]!=MINTH) { // for minth, triggers are set from header info | |
421 | scanObj[eqId]->IncrementTriggers(currentStep[eqId]); | |
422 | } | |
423 | ||
424 | } | |
425 | ||
426 | } | |
427 | ||
428 | delete str; | |
429 | delete reader; | |
430 | ||
431 | } | |
432 | ||
433 | /* free resources */ | |
434 | free(event); | |
435 | ||
436 | } | |
437 | ||
1fd93b67 | 438 | #ifndef SPD_DA_OFF |
3ec5024c | 439 | daqDA_progressReport((unsigned int)( ((Float_t)(segNr-startSeg+1))/(argc-startSeg)*50 )); |
440 | #else | |
441 | printf("progress: %d\n",(unsigned int)( ((Float_t)(segNr-startSeg+1))/(argc-startSeg)*50 )); | |
442 | #endif | |
443 | ||
444 | } | |
445 | ||
6727e2db | 446 | |
1c039f23 | 447 | // clean up scan objects (which also saves them) , check if something happened... |
448 | Bool_t somethingHappened = kFALSE; | |
3ec5024c | 449 | for (UInt_t eqId=0; eqId<20; eqId++) { |
1c039f23 | 450 | if (scanObj[eqId]!=NULL) { |
451 | delete scanObj[eqId]; | |
452 | somethingHappened = kTRUE; | |
453 | } | |
454 | } | |
455 | if (!somethingHappened) { | |
456 | printf("WARNING: No data processed. Are the calibration headers missing?\n"); | |
3ec5024c | 457 | } |
3ec5024c | 458 | |
459 | ||
460 | ||
461 | ||
53ae21ce | 462 | // ********* STEP 2: Analyze scan container files. ************************************************ |
463 | ||
464 | // clear noisyToFXS and DCSconfigToFXS dirs: | |
465 | TString command = Form("cd %s; rm -f *",saveDirNoisyToFXS); | |
466 | system(command.Data()); | |
467 | TString command2 = Form("cd %s; rm -f *",saveDirDCSconfigToFXS); | |
468 | system(command2.Data()); | |
469 | UInt_t nrNoisyFilesProduced=0; | |
470 | UInt_t nrDCSconfigFilesProduced=0; | |
3ec5024c | 471 | |
6727e2db | 472 | AliITSOnlineCalibrationSPDhandler* handler = new AliITSOnlineCalibrationSPDhandler(); |
473 | AliITSOnlineSPDscanAnalyzer *analyzer = NULL; | |
474 | AliITSOnlineCalibrationSPDhandler* handlerPermNoisy = NULL; | |
475 | // fill permanent noisy list to add later... | |
476 | if (permstatus==0) { | |
477 | handlerPermNoisy = new AliITSOnlineCalibrationSPDhandler(); | |
478 | UInt_t permNoisy = handlerPermNoisy->ReadNoisyFromText(permNoisyFileName.Data(),240); // 240 = read for all modules | |
479 | if (permNoisy>0) { | |
480 | printf("%d noisy pixels read from permanent list.\n",permNoisy); | |
481 | } | |
482 | } | |
483 | ||
4f88491f | 484 | Bool_t reset_made = kFALSE; |
3ec5024c | 485 | |
486 | // *** *** *** start loop over equipments (eq_id) | |
487 | for (int eqId=0; eqId<20; eqId++) { | |
488 | ||
53ae21ce | 489 | // create analyzer for this eq |
490 | TString fileName = Form("%s/SPDcal_run_%d_eq_%d.root",saveDirRef,runNr,eqId); | |
6727e2db | 491 | analyzer = new AliITSOnlineSPDscanAnalyzer(fileName.Data(),handler); |
53ae21ce | 492 | |
493 | // configure analyzer with tuning parameters etc: | |
494 | for (UInt_t i=0; i<nrTuningParams; i++) { | |
478d804c | 495 | analyzer->SetParam(((TObjString*)paramNames.At(i))->GetString().Data(),((TObjString*)paramVals.At(i))->GetString().Data()); |
53ae21ce | 496 | } |
3ec5024c | 497 | |
4ee23d3d | 498 | UInt_t type = analyzer->GetType(); |
499 | UInt_t dacId = analyzer->GetDacId(); | |
500 | UInt_t routerNr = analyzer->GetRouterNr(); | |
3ec5024c | 501 | if (type!=99) { |
502 | if (type==DAC) { | |
6727e2db | 503 | printf("SPD scan calibrator Step2: eqId %d, type %d, dacId %d\n",eqId,type,dacId); |
3ec5024c | 504 | } |
6727e2db | 505 | else printf("SPD scan calibrator Step2: eqId %d type %d\n",eqId,type); |
3ec5024c | 506 | } |
4ee23d3d | 507 | |
508 | ||
3ec5024c | 509 | |
53ae21ce | 510 | // algorithms for the different types of scans: |
3ec5024c | 511 | |
512 | if (type==UNIMA) { | |
53ae21ce | 513 | |
3ec5024c | 514 | } |
53ae21ce | 515 | |
3ec5024c | 516 | else if (type==NOISE) { |
4f88491f | 517 | // read previous noisy list (clear if overwriting) |
6727e2db | 518 | handler->SetFileLocation(saveDirNoisy); |
4f88491f | 519 | if (analyzer->IsOverWriteSet() && !reset_made) { |
520 | handler->ResetNoisy(); | |
521 | handler->WriteToFilesAlways(); | |
522 | reset_made=kTRUE; | |
523 | } | |
524 | else { | |
525 | handler->ReadFromFiles(); | |
526 | } | |
6727e2db | 527 | if (analyzer->ProcessNoisyPixels(/*saveDirNoisy*/)) { |
528 | if (permstatus==0) { | |
529 | handler->AddNoisyFrom(handlerPermNoisy); | |
530 | } | |
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"; |
6727e2db | 539 | dcsfile << "ActualDetConfiguration=" << "0,-1,-1\n"; // dummy values for now |
53ae21ce | 540 | dcsfile << "[NOISY]\n"; |
541 | nrDCSconfigFilesProduced++; | |
4f88491f | 542 | |
543 | for (UInt_t hs=0; hs<6; hs++) { | |
544 | for (UInt_t chip=0; chip<10; chip++) { | |
545 | if (analyzer->IsChipPresent(hs,chip) || analyzer->IsOverWriteSet()) { | |
546 | dcsfile << "-" << eqId << "," << hs << "," << chip << "\n"; | |
547 | UInt_t nrNoisy = handler->GetNrNoisyC(eqId,hs,chip); | |
548 | for (UInt_t ind=0; ind<nrNoisy; ind++) { | |
549 | UInt_t col = handler->GetNoisyColAtC(eqId,hs,chip,ind); | |
550 | UInt_t row = handler->GetNoisyRowAtC(eqId,hs,chip,ind); | |
551 | dcsfile << col << "," << row << "\n"; | |
53ae21ce | 552 | } |
53ae21ce | 553 | } |
3ec5024c | 554 | } |
555 | } | |
4f88491f | 556 | handler->SetFileLocation(saveDirNoisy); |
557 | handler->WriteNoisyToFile(eqId); | |
558 | handler->SetFileLocation(saveDirNoisyToFXS); | |
559 | handler->WriteNoisyToFile(eqId); | |
560 | nrNoisyFilesProduced++; | |
561 | ||
53ae21ce | 562 | dcsfile.close(); |
3ec5024c | 563 | } |
564 | } | |
53ae21ce | 565 | |
3ec5024c | 566 | else if (type==MINTH || (type==DAC && dacId==39)) { |
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"; |
4f88491f | 575 | dcsfile << "ActualDetConfiguration=" << "0,-1,-1\n"; // dummy values for now |
53ae21ce | 576 | dcsfile << "[DACvalues]\n"; |
577 | nrDCSconfigFilesProduced++; | |
3ec5024c | 578 | for (UInt_t hs=0; hs<6; hs++) { |
579 | for (UInt_t chipNr=0; chipNr<10; chipNr++) { | |
53ae21ce | 580 | Int_t minTh = -1; |
581 | if (analyzer->GetOnlineScan()->GetChipPresent(hs,chipNr)) { | |
582 | minTh = analyzer->GetMinTh(hs,chipNr); | |
583 | if (minTh!=-1) { | |
584 | dcsfile << "39," << eqId << "," << hs << "," << chipNr << "=" << minTh << "\n"; | |
585 | } | |
586 | else { | |
587 | printf("MinTh failed for Eq %d , HS %d , Chip %d\n",eqId,hs,chipNr); | |
588 | } | |
589 | } | |
3ec5024c | 590 | } |
3ec5024c | 591 | } |
53ae21ce | 592 | dcsfile.close(); |
3ec5024c | 593 | } |
53ae21ce | 594 | |
3ec5024c | 595 | else if (type==DELAY) { |
53ae21ce | 596 | // init dcs config text file |
597 | TString dcsConfigFileName = Form("%s/dcsConfig_run_%d_eq_%d.txt",saveDirDCSconfigToFXS,runNr,eqId); | |
598 | ofstream dcsfile; | |
599 | dcsfile.open(dcsConfigFileName.Data()); | |
600 | dcsfile << "[SPD SCAN]\n"; | |
601 | dcsfile << "RunNumber=" << runNr << "\n"; | |
602 | dcsfile << "Type=" << type << "\n"; | |
4ee23d3d | 603 | dcsfile << "Router=" << routerNr << "\n"; |
53ae21ce | 604 | dcsfile << "ActualDetCoonfiguration=" << "0,-1,-1\n"; // dummy values for now |
605 | dcsfile << "[DACvalues]\n"; | |
606 | nrDCSconfigFilesProduced++; | |
3ec5024c | 607 | for (UInt_t hs=0; hs<6; hs++) { |
608 | for (UInt_t chipNr=0; chipNr<10; chipNr++) { | |
53ae21ce | 609 | Int_t clockCycle = -1; |
610 | Int_t delayCtrl = -1; | |
611 | Int_t miscCtrl = -1; | |
612 | if (analyzer->GetOnlineScan()->GetChipPresent(hs,chipNr)) { | |
613 | clockCycle = analyzer->GetDelay(hs,chipNr); | |
614 | delayCtrl = clockCycle/2; | |
615 | miscCtrl = 192; | |
616 | if (clockCycle!=-1) { | |
617 | if (clockCycle%2==1) miscCtrl = 128; | |
618 | dcsfile << "42," << eqId << "," << hs << "," << chipNr << "=" << delayCtrl << "\n"; | |
619 | dcsfile << "43," << eqId << "," << hs << "," << chipNr << "=" << miscCtrl << "\n"; | |
620 | } | |
621 | else { | |
622 | printf("Delay failed for Eq %d , HS %d , Chip %d\n",eqId,hs,chipNr); | |
623 | } | |
624 | } | |
3ec5024c | 625 | } |
3ec5024c | 626 | } |
53ae21ce | 627 | dcsfile.close(); |
3ec5024c | 628 | } |
629 | ||
3ec5024c | 630 | delete analyzer; |
631 | ||
1fd93b67 | 632 | #ifndef SPD_DA_OFF |
3ec5024c | 633 | daqDA_progressReport((unsigned int)(50+(eqId+1)*2.5)); |
634 | #else | |
635 | printf("progress: %d\n",(unsigned int)(50+(eqId+1)*2.5)); | |
636 | #endif | |
637 | ||
638 | } | |
639 | // *** *** *** end loop over equipments (eq_id) | |
640 | ||
4f88491f | 641 | |
6727e2db | 642 | delete handler; |
643 | if (handlerPermNoisy!=NULL) { | |
644 | delete handlerPermNoisy; | |
645 | } | |
646 | ||
1c039f23 | 647 | printf("Opening id list file\n"); |
4f88491f | 648 | TString idsFXSFileName = Form("%s/FXSids_run_%d.txt",saveDirIdsToFXS,runNr); |
649 | ofstream idsFXSfile; | |
650 | idsFXSfile.open(idsFXSFileName.Data()); | |
651 | ||
3ec5024c | 652 | |
6727e2db | 653 | |
654 | // send noisy data to FXS | |
1fd93b67 | 655 | if (nrNoisyFilesProduced>0) { |
1c039f23 | 656 | printf("Preparing noisy files\n"); |
1fd93b67 | 657 | // send a tared file of all new noisy maps |
6727e2db | 658 | TString command = Form("cd %s; tar -cf noisy_scan.tar *",saveDirNoisyToFXS); |
659 | // printf("\n\n%s\n\n",command.Data()); | |
53ae21ce | 660 | system(command.Data()); |
6727e2db | 661 | TString fileName = Form("%s/noisy_scan.tar",saveDirNoisyToFXS); |
662 | TString id = "SPD_scan_noisy"; | |
4f88491f | 663 | #ifndef SPD_DA_OFF |
53ae21ce | 664 | Int_t status = daqDA_FES_storeFile(fileName.Data(),id.Data()); |
1fd93b67 | 665 | if (status!=0) { |
53ae21ce | 666 | printf("Failed to export file %s , status %d\n",fileName.Data(),status); |
1fd93b67 | 667 | return -1; |
668 | } | |
53ae21ce | 669 | #endif |
4f88491f | 670 | idsFXSfile << Form("%s\n",id.Data()); |
3ec5024c | 671 | } |
53ae21ce | 672 | |
6727e2db | 673 | // send dcs config files to FXS |
53ae21ce | 674 | if (nrDCSconfigFilesProduced>0) { |
1c039f23 | 675 | printf("Preparing DCS config files\n"); |
53ae21ce | 676 | // send a tared file of all the dcsConfig text files |
677 | TString command = Form("cd %s; tar -cf dcsConfig.tar *",saveDirDCSconfigToFXS); | |
678 | // printf("\n\n%s\n\n",command.Data()); | |
679 | system(command.Data()); | |
53ae21ce | 680 | TString fileName = Form("%s/dcsConfig.tar",saveDirDCSconfigToFXS); |
681 | TString id = "SPD_dcsConfig"; | |
4f88491f | 682 | #ifndef SPD_DA_OFF |
53ae21ce | 683 | Int_t status = daqDA_FES_storeFile(fileName.Data(),id.Data()); |
684 | if (status!=0) { | |
685 | printf("Failed to export file %s , status %d\n",fileName.Data(),status); | |
686 | return -1; | |
687 | } | |
3ec5024c | 688 | #endif |
4f88491f | 689 | //idsFXSfile << Form("%s\n",id.Data()); // do NOT write this id (this is not for preprocessor) |
53ae21ce | 690 | } |
691 | ||
6727e2db | 692 | // send reference data to FXS |
6727e2db | 693 | for (UInt_t eqId=0; eqId<20; eqId++) { |
694 | if (bScanInit[eqId]) { | |
1c039f23 | 695 | printf("Preparing reference data for eq %d\n",eqId); |
6727e2db | 696 | TString fileName = Form("%s/SPDcal_run_%d_eq_%d.root",saveDirRef,runNr,eqId); |
697 | TString id = Form("SPD_ref_scan_%d",eqId); | |
4f88491f | 698 | #ifndef SPD_DA_OFF |
6727e2db | 699 | Int_t status = daqDA_FES_storeFile(fileName.Data(),id.Data()); |
700 | if (status!=0) { | |
701 | printf("Failed to export file %s , status %d\n",fileName.Data(),status); | |
702 | return -1; | |
703 | } | |
4f88491f | 704 | #endif |
705 | idsFXSfile << Form("%s\n",id.Data()); | |
6727e2db | 706 | } |
707 | } | |
6727e2db | 708 | |
709 | ||
1c039f23 | 710 | printf("Preparing id list file\n"); |
4f88491f | 711 | idsFXSfile.close(); |
1c039f23 | 712 | TString id = "SPD_id_list"; |
713 | #ifndef SPD_DA_OFF | |
714 | status = daqDA_FES_storeFile(idsFXSFileName.Data(),id.Data()); | |
715 | if (status!=0) { | |
716 | printf("Failed to export file %s , status %d\n",idsFXSFileName.Data(),status); | |
717 | return -1; | |
718 | } | |
719 | #endif | |
6727e2db | 720 | |
3ec5024c | 721 | |
1c039f23 | 722 | printf("DA finished.\n"); |
3ec5024c | 723 | |
724 | return 0; | |
478d804c | 725 | } |