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