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