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