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