]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/ITSSPDPHYSda.cxx
Updated misalignment macros and AliITSMisalignMaker class (R. Grosso)
[u/mrichter/AliRoot.git] / ITS / ITSSPDPHYSda.cxx
CommitLineData
803e6db5 1/*
2Contact: henrik.tydesjo@cern.ch
3Link: tydes.home.cern.ch/tydes/doc/CalibrationOverview/CalibrationAlgorithms/
4Run Type: PHYSICS
5DA Type: MON
6Number of events needed: Depending on muliplicity per event
7Input Files: spd_physics_params , ./calibResults/DeadReferenceTmp/* , ./calibResults/DeadToFXS/*
8Output Files: ./calibResults/NoisyReference/* , ./calibResults/DeadReference/* , ./calibResults/NoisyToFXS/* , ./calibResults/DeadReferenceTmp/*,./calibResults/DeadToFXS/*
9Trigger types used: PHYSICS
10*/
11
12////////////////////////////////////////////////////////////////////////////////
13// This program can be compiled in two modes. //
14// //
15// 1. Online. With the DAQ DA framework. This is the default operating mode. //
16// //
17// 2. Offline. Without the DAQ DA framework. Define the SPD_DA_OFF //
18// environment var. Call this program with the name of the executable //
19// followed by the runNr and the data files to process. //
20// //
21////////////////////////////////////////////////////////////////////////////////
22
23#ifndef SPD_DA_OFF
24extern "C" {
25#include "daqDA.h"
26}
27#endif
28#include "event.h"
29#include "monitor.h"
30#include "AliRawReaderDate.h"
31#include "AliITSRawStreamSPD.h"
32#include "AliITSOnlineSPDphys.h"
33#include "AliITSOnlineSPDphysAnalyzer.h"
34#include "AliITSOnlineCalibrationSPDhandler.h"
35#include "AliLog.h"
36#include <iostream>
37#include <fstream>
478d804c 38//#include <time.h>
803e6db5 39#include <TROOT.h>
40#include <TPluginManager.h>
41#include <TObjArray.h>
478d804c 42#include <TObjString.h>
803e6db5 43#include <TString.h>
44
478d804c 45
803e6db5 46int main(int argc, char **argv) {
47 if (argc<2) {
f42c2e3b 48 printf("SPD DA ERROR: Wrong number of arguments\n");
803e6db5 49 return -1;
50 }
51
52 // directory structure, hard coded
53 char *saveDirDead = "./calibResults/Dead"; // may NOT delete content
54 char *saveDirDeadToFXS = "./calibResults/DeadToFXS"; // may delete content
55 char *saveDirDeadRef = "./calibResults/DeadReference"; // may delete content
56 char *saveDirDeadRefTmp = "./calibResults/DeadReferenceTmp"; // may NOT delete content
57 char *saveDirNoisyToFXS = "./calibResults/NoisyToFXS"; // may delete content
58 char *saveDirNoisyRef = "./calibResults/NoisyReference"; // may delete content
59 char *saveDirIdsToFXS = "./calibResults/IdsToFXS"; // may delete content
60 char *configFilesDir = "./configFiles"; // may delete content
61 // make sure the directory structure is put up correctly:
62 system("mkdir ./calibResults >& /dev/null");
63 system("mkdir ./calibResults/Dead >& /dev/null");
64 system("mkdir ./calibResults/DeadToFXS >& /dev/null");
65 system("mkdir ./calibResults/DeadReference >& /dev/null");
66 system("mkdir ./calibResults/DeadReferenceTmp >& /dev/null");
67 system("mkdir ./calibResults/NoisyToFXS >& /dev/null");
68 system("mkdir ./calibResults/NoisyReference >& /dev/null");
69 system("mkdir ./calibResults/IdsToFXS >& /dev/null");
70 system("mkdir ./configFiles >& /dev/null");
71 // parameters config file
72 TString paramsFileName = Form("%s/physics_params.txt",configFilesDir);
73
74 // This line is needed in case of a stand-alone application w/o
75 // $ROOTSYS/etc/system.rootrc file
76 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
77 "*",
78 "TStreamerInfo",
79 "RIO",
80 "TStreamerInfo()");
81
82 // turn off annoying warning messages
83 new AliLog;
84 AliLog::Instance()->SetGlobalDebugLevel(-20);
85
86
87 // ********* STEP 0: Get configuration files from db (if there are any) , then read parameters*********
88 UInt_t nrTuningParams = 0;
89 TObjArray paramNames; paramNames.SetOwner(kTRUE);
90 TObjArray paramVals; paramVals.SetOwner(kTRUE);
91
92 // tuning parameters:
93 Int_t par_status = 0;
94#ifndef SPD_DA_OFF
95 TString idp = "spd_physics_params";
96 par_status=daqDA_DB_getFile(idp.Data(),paramsFileName.Data());
97 if (par_status) {
f42c2e3b 98 printf("SPD DA: Failed to get config file %s: status=%d. Using default tuning parameters.\n",idp.Data(),par_status);
803e6db5 99 }
100#endif
101 if (par_status==0) {
102 ifstream paramsFile;
103 paramsFile.open(paramsFileName.Data(), ifstream::in);
104 if (paramsFile.fail()) {
f42c2e3b 105 printf("SPD DA: No config file (%s) present. Using default tuning parameters.\n",paramsFileName.Data());
803e6db5 106 }
107 else {
108 while(1) {
109 Char_t paramN[50];
110 Char_t paramV[50];
111 paramsFile >> paramN;
112 if (paramsFile.eof()) break;
113 paramsFile >> paramV;
478d804c 114 paramNames.AddAtAndExpand(new TObjString(paramN),nrTuningParams);
115 paramVals.AddAtAndExpand(new TObjString(paramV),nrTuningParams);
803e6db5 116 nrTuningParams++;
117 if (paramsFile.eof()) break;
118 }
119 paramsFile.close();
120 }
121 }
122 // for (UInt_t i=0; i<nrTuningParams; i++) {
478d804c 123 // // printf("Entry %d: N=%s , V=%s\n",i,((TString*)paramNames.At(i))->Data(),((TString*)paramVals.At(i))->Data());
124 // printf("Entry %d: N=%s , V=%s\n",i,((TObjString*)paramNames.At(i))->GetString().Data(),((TObjString*)paramVals.At(i))->GetString().Data());
803e6db5 125 // }
126
127
128
129
130
b696414b 131 // create calibration handler (needed already at step 1 in order to fill which eq,hs,chips are active
132 AliITSOnlineCalibrationSPDhandler* handler = new AliITSOnlineCalibrationSPDhandler();
f42c2e3b 133
b696414b 134 // Read silent=dead+inactive info from previous calibrations
f42c2e3b 135#ifndef SPD_DA_OFF
136 // remove previous files and read from DB instead
137 TString commandRemoveDead = Form("cd %s; rm -f *",saveDirDead);
138 system(commandRemoveDead.Data());
139 for (UInt_t eq=0; eq<20; eq++) {
140 Int_t getPreviousDead_status = 0;
141 TString idpd = Form("spd_previous_dead_%d",eq);
142 TString fileName = Form("%s/SPD_Dead_%d.root",saveDirDead,eq);
143 getPreviousDead_status = daqDA_DB_getFile(idpd.Data(),fileName.Data());
144 // printf("daqDA_DB_getFile(%s,%s)\n",idpd.Data(),fileName.Data());
145 if (par_status) {
146 printf("SPD DA: Failed to get dead file %s: status=%d. Dead search will start from zero for this eq.\n",idpd.Data(),getPreviousDead_status);
147 }
148 }
149#endif
b696414b 150 handler->SetFileLocation(saveDirDead);
151 handler->ReadSilentFromFiles();
f42c2e3b 152 printf("SPD DA: Number of single dead pixels from previous runs: %d\n",handler->GetNrDead());
b696414b 153
154
155
156
803e6db5 157 // ********* STEP 1: Produce phys container files (Reference Data). ***********************************
158
159#ifndef SPD_DA_OFF
160 if (getenv("DATE_RUN_NUMBER")==0) {
f42c2e3b 161 printf("SPD DA ERROR: DATE_RUN_NUMBER not properly set.\n");
803e6db5 162 return -1;
163 }
164 int runNr = atoi(getenv("DATE_RUN_NUMBER"));
165#else
166 int runNr = atoi(argv[1]);
167 int startSeg = 2;
168#endif
169
170
171 // container objects
172 AliITSOnlineSPDphys *physObj[20];
173 Bool_t bPhysInit[20];
478d804c 174 for (UInt_t eq=0; eq<20; eq++) {
175 physObj[eq]=NULL;
176 bPhysInit[eq]=kFALSE;
803e6db5 177 }
178
179
f42c2e3b 180 UInt_t eventNr=0;
181
803e6db5 182 // loop over run segments in case of offline mode
183#ifdef SPD_DA_OFF
184 for (int segNr=startSeg; segNr<argc; segNr++) {
185#endif
186
187 int status;
188
189 /* define data source : */
190#ifndef SPD_DA_OFF
191 status=monitorSetDataSource( argv[1] ); // should be "^SPD" in order to get full detector online
192#else
193 status=monitorSetDataSource( argv[segNr] );
194#endif
195 if (status!=0) {
f42c2e3b 196 printf("SPD DA ERROR: monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
803e6db5 197 return -1;
198 }
199 /* declare monitoring program */
200 status=monitorDeclareMp("ITS_SPD_PHYS");
201 if (status!=0) {
f42c2e3b 202 printf("SPD DA ERROR: monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
803e6db5 203 return -1;
204 }
205 /* define wait event timeout - 1s max */
206 monitorSetNowait();
207 monitorSetNoWaitNetworkTimeout(1000);
208
209
803e6db5 210 /* main loop (infinite) */
211 for(;;) {
212
213 struct eventHeaderStruct *event;
214 eventTypeType eventT;
215
216 /* check shutdown condition */
217#ifndef SPD_DA_OFF
218 if (daqDA_checkShutdown()) {break;}
219#endif
220
221 /* get next event (blocking call until timeout) */
222 status=monitorGetEventDynamic((void **)&event);
223 if (status==MON_ERR_EOF) {
f42c2e3b 224 printf ("SPD DA: End of File detected\n");
803e6db5 225 break; /* end of monitoring file has been reached */
226 }
227
228 if (status!=0) {
f42c2e3b 229 printf("SPD DA: monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
803e6db5 230 break;
231 }
232
233 /* retry if got no event */
234 if (event==NULL) {
235 continue;
236 }
237
238 eventT=event->eventType;
239 if (eventT == PHYSICS_EVENT){
240
803e6db5 241 // printf("eventNr %d\n",eventNr);
242
243 AliRawReader *reader = new AliRawReaderDate((void*)event);
244 AliITSRawStreamSPD *str = new AliITSRawStreamSPD(reader);
245
803e6db5 246 while (str->Next()) {
247
478d804c 248 Int_t eq = reader->GetDDLID();
b696414b 249 // check that this hs is active in handler object
478d804c 250 if (!(handler->IsActiveEq(eq))) {
f42c2e3b 251 printf("SPD DA: Found Eq (%d) , previously inactive\n",eq);
478d804c 252 handler->ActivateEq(eq);
b696414b 253 }
478d804c 254 if (eq>=0 && eq<20) {
255 if (!bPhysInit[eq]) { // this code is duplicated for the moment... (see also below)
256 TString fileName = Form("%s/SPDphys_run_%d_eq_%d.root",saveDirNoisyRef,runNr,eq);
257 physObj[eq] = new AliITSOnlineSPDphys(fileName.Data());
258 physObj[eq]->AddRunNr(runNr);
259 physObj[eq]->SetEqNr(eq);
260 bPhysInit[eq]=kTRUE;
803e6db5 261 }
b696414b 262
803e6db5 263 UInt_t hs = str->GetHalfStaveNr();
b696414b 264 // check that this hs is active in handler object
478d804c 265 if (!(handler->IsActiveHS(eq,hs))) {
f42c2e3b 266 printf("SPD DA: Found HS (%d,%d) , previously inactive\n",eq,hs);
478d804c 267 handler->ActivateHS(eq,hs);
b696414b 268 }
803e6db5 269 UInt_t chip = str->GetChipAddr();
b696414b 270 // check that this chip is active in handler object
478d804c 271 if (!(handler->IsActiveChip(eq,hs,chip))) {
f42c2e3b 272 printf("SPD DA: Found Chip (%d,%d,%d) , previously inactive\n",eq,hs,chip);
478d804c 273 handler->ActivateChip(eq,hs,chip);
b696414b 274 }
478d804c 275 physObj[eq]->IncrementHits(hs,chip,str->GetChipCol(),str->GetChipRow());
803e6db5 276
277 }
278 }
b696414b 279
280
478d804c 281 // check which eq and hs are active, for first event only
b696414b 282 if (eventNr==0) {
478d804c 283 for (UInt_t eq=0; eq<20; eq++) {
b696414b 284 // activate Eq and HSs in handler object
478d804c 285 if (str->IsActiveEq(eq)) {
286 handler->ActivateEq(eq);
b696414b 287 for (UInt_t hs=0; hs<6; hs++) {
478d804c 288 if (str->IsActiveHS(eq,hs)) {
289 handler->ActivateHS(eq,hs);
290 for (UInt_t chip=0; chip<10; chip++) {
291 if (str->IsActiveChip(eq,hs,chip)) {
292 handler->ActivateChip(eq,hs,chip);
293 }
294 else {
295 handler->ActivateChip(eq,hs,chip,kFALSE);
296 }
297 }
298 }
299 else {
300 handler->ActivateHS(eq,hs,kFALSE);
301 }
b696414b 302 }
478d804c 303 if (!bPhysInit[eq]) { // this code is duplicated for the moment... (see also above)
304 TString fileName = Form("%s/SPDphys_run_%d_eq_%d.root",saveDirNoisyRef,runNr,eq);
305 physObj[eq] = new AliITSOnlineSPDphys(fileName.Data());
306 physObj[eq]->AddRunNr(runNr);
307 physObj[eq]->SetEqNr(eq);
308 bPhysInit[eq]=kTRUE;
b696414b 309 }
310 }
311 else {
478d804c 312 handler->ActivateEq(eq,kFALSE);
b696414b 313 }
803e6db5 314 }
315 }
316
b696414b 317
318 for (UInt_t eq=0; eq<20; eq++) {
319 if (bPhysInit[eq]) {
320 physObj[eq]->IncrementNrEvents();
321 }
322 }
803e6db5 323
324 delete str;
325 delete reader;
326
b696414b 327 eventNr++;
328
803e6db5 329 }
330
331 /* free resources */
332 free(event);
333
334 }
335
336
337#ifdef SPD_DA_OFF
f42c2e3b 338 printf("SPD DA: progress: %d\n",(unsigned int)( ((Float_t)(segNr-startSeg+1))/(argc-startSeg)*50 ));
803e6db5 339 }
340#endif
f42c2e3b 341
803e6db5 342 // clean up phys objects (also saves them)
b696414b 343 for (UInt_t eq=0; eq<20; eq++) {
344 if (physObj[eq]!=NULL) delete physObj[eq];
803e6db5 345 }
346
f42c2e3b 347 printf("SPD DA: %d events collected for this run.\n",eventNr);
803e6db5 348
349
350
351
352 // ********* STEP 2: Analyze phys container files. ************************************************
353
478d804c 354 // time_t timeStamp = time(NULL);
355 // printf("*** Start step2 , %d\n",time(NULL) - timeStamp);
356
803e6db5 357 // clear noisyToFXS dir:
358 TString command;
359 command = Form("cd %s; rm -f *",saveDirNoisyToFXS);
360 system(command.Data());
361 // clear deadToFXS dir:
362 command = Form("cd %s; rm -f *",saveDirDeadToFXS);
363 system(command.Data());
364
365
803e6db5 366 UInt_t firstRunNrDead = runNr;
367
368
369 UInt_t nrEnoughStatNoisy = 0;
370 UInt_t nrEqActiveNoisy = 0;
371 Bool_t eqActiveNoisy[20];
372
373 // *** *** *** start loop over equipments (eq_id)
b696414b 374 for (UInt_t eq=0; eq<20; eq++) {
375 eqActiveNoisy[eq] = kFALSE;
803e6db5 376
377 // create analyzer for this eq
b696414b 378 TString fileName = Form("%s/SPDphys_run_%d_eq_%d.root",saveDirNoisyRef,runNr,eq);
803e6db5 379 AliITSOnlineSPDphysAnalyzer *noisyAnalyzer = new AliITSOnlineSPDphysAnalyzer(fileName.Data(),handler);
380
381 // check data in container
b696414b 382 if (noisyAnalyzer->GetEqNr() != eq) {
803e6db5 383 if (noisyAnalyzer->GetEqNr() != 999) {
f42c2e3b 384 printf("SPD DA ERROR: Mismatching EqId in Container data and filename (%d!=%d). Skipping eq.\n",
b696414b 385 noisyAnalyzer->GetEqNr(),eq);
803e6db5 386 }
387 delete noisyAnalyzer;
388 continue;
389 }
390
391 nrEqActiveNoisy++;
b696414b 392 eqActiveNoisy[eq] = kTRUE;
803e6db5 393
394 // configure analyzer with tuning parameters etc:
395 for (UInt_t i=0; i<nrTuningParams; i++) {
478d804c 396 noisyAnalyzer->SetParam(((TObjString*)paramNames.At(i))->GetString().Data(),((TObjString*)paramVals.At(i))->GetString().Data());
803e6db5 397 }
398
f42c2e3b 399 printf("SPD DA: SPD phys STEP 2: Noisy search for eq %d\n",eq);
803e6db5 400
401 // search for noisy pixels:
402 nrEnoughStatNoisy += noisyAnalyzer->ProcessNoisyPixels();
403
404 // copy this phys obj to temporary dead reference dir to process after noisy search
b696414b 405 TString fileNameDead = Form("%s/SPDphys_dead_run_0_0_eq_%d.root",saveDirDeadRefTmp,eq);
803e6db5 406 AliITSOnlineSPDphys* physObj = new AliITSOnlineSPDphys(fileNameDead.Data());
407 physObj->AddPhys(noisyAnalyzer->GetOnlinePhys());
408 if (physObj->GetNrRuns()>0) {
409 UInt_t firstRunNr = physObj->GetRunNr(0);
410 if (firstRunNrDead>firstRunNr) {
411 firstRunNrDead=firstRunNr;
412 }
413 }
414 // remove noisy pixels from dead hitmap
415 for (UInt_t hs=0; hs<6; hs++) {
416 for (UInt_t chip=0; chip<10; chip++) {
b696414b 417 for (UInt_t ind=0; ind<handler->GetNrNoisyC(eq,hs,chip); ind++) {
418 UInt_t col = handler->GetNoisyColAtC(eq,hs,chip,ind);
419 UInt_t row = handler->GetNoisyRowAtC(eq,hs,chip,ind);
803e6db5 420 physObj->AddHits(hs,chip,col,row,-noisyAnalyzer->GetOnlinePhys()->GetHits(hs,chip,col,row));
421 }
422 }
423 }
424
425 delete physObj;
426 delete noisyAnalyzer;
427
428#ifndef SPD_DA_OFF
b696414b 429 daqDA_progressReport((unsigned int)((eq+1)*2.5));
803e6db5 430#else
f42c2e3b 431 printf("SPD DA: progress: %d\n",(unsigned int)(50+(eq+1)*1.25));
803e6db5 432#endif
433 }
434 // *** *** *** end loop over equipments (eq_id)
435
f42c2e3b 436 printf("SPD DA: Noisy search finished. %d noisy pixels found. %d chips had enough statistics.\n",
478d804c 437 handler->GetNrNoisy(),nrEnoughStatNoisy);
803e6db5 438 handler->SetFileLocation(saveDirNoisyToFXS);
f42c2e3b 439 UInt_t nrNoisyFilesProduced = handler->WriteNoisyToFiles();
803e6db5 440
441
442
443
444
445
446
803e6db5 447 UInt_t nrEnoughStatChips = 0;
448 UInt_t nrDeadChips = 0;
449 UInt_t nrInefficientChips = 0;
450 UInt_t nrEqActiveDead = 0;
451 Bool_t eqActiveDead[20];
452
453 // *** *** *** start loop over equipments (eq_id)
b696414b 454 for (UInt_t eq=0; eq<20; eq++) {
455 eqActiveDead[eq] = kFALSE;
803e6db5 456
457 // setup analyzer for dead search
b696414b 458 TString fileNameDead = Form("%s/SPDphys_dead_run_0_0_eq_%d.root",saveDirDeadRefTmp,eq);
803e6db5 459 AliITSOnlineSPDphys* physObj = new AliITSOnlineSPDphys(fileNameDead.Data());
460 AliITSOnlineSPDphysAnalyzer* deadAnalyzer = new AliITSOnlineSPDphysAnalyzer(physObj,handler);
461 // check data in container
b696414b 462 if (deadAnalyzer->GetEqNr() != eq) {
803e6db5 463 if (deadAnalyzer->GetEqNr() != 999) {
f42c2e3b 464 printf("SPD DA ERROR: Mismatching EqId in Dead Container data and filename (%d!=%d). Skipping eq.\n",
b696414b 465 deadAnalyzer->GetEqNr(),eq);
803e6db5 466 }
467 delete deadAnalyzer;
478d804c 468 nrDeadChips+=60; // since this eq is inactive...
803e6db5 469 continue;
470 }
471
472 nrEqActiveDead++;
b696414b 473 eqActiveDead[eq] = kTRUE;
803e6db5 474
475 // configure analyzer with tuning parameters etc:
476 for (UInt_t i=0; i<nrTuningParams; i++) {
478d804c 477 deadAnalyzer->SetParam(((TObjString*)paramNames.At(i))->GetString().Data(),((TObjString*)paramVals.At(i))->GetString().Data());
803e6db5 478 }
479
f42c2e3b 480 printf("SPD DA: SPD phys STEP 2: Dead search for eq %d\n",eq);
803e6db5 481
482 // search for dead pixels:
483 nrEnoughStatChips += deadAnalyzer->ProcessDeadPixels();
484 nrDeadChips += deadAnalyzer->GetNrDeadChips();
485 nrInefficientChips += deadAnalyzer->GetNrInefficientChips();
486
487 delete deadAnalyzer;
488
478d804c 489
803e6db5 490#ifndef SPD_DA_OFF
b696414b 491 daqDA_progressReport((unsigned int)(50+(eq+1)*2.5));
803e6db5 492#else
f42c2e3b 493 printf("SPD DA: progress: %d\n",(unsigned int)(75+(eq+1)*1.25));
803e6db5 494#endif
495 }
f42c2e3b 496 // *** *** *** end loop over equipments (eq)
803e6db5 497
478d804c 498
499
803e6db5 500
f42c2e3b 501 printf("SPD DA: Dead search finished.\n");
502 printf("SPD DA: %d single dead pixels , %d dead or inactive pixels in total.\n",handler->GetNrDead(),handler->GetNrSilent());
503 printf("SPD DA: %d chips had enough statistics. %d chips are dead. %d chips are inefficient.\n",nrEnoughStatChips,nrDeadChips,nrInefficientChips);
803e6db5 504 handler->SetFileLocation(saveDirDead);
b696414b 505 handler->WriteSilentToFilesAlways();
803e6db5 506 handler->SetFileLocation(saveDirDeadToFXS);
b696414b 507 handler->WriteSilentToFilesAlways();
508
803e6db5 509
f42c2e3b 510 printf("SPD DA: Opening id list file\n");
803e6db5 511 TString idsFXSFileName = Form("%s/FXSids_run_%d.txt",saveDirIdsToFXS,runNr);
512 ofstream idsFXSfile;
513 idsFXSfile.open(idsFXSFileName.Data());
514
515
f42c2e3b 516 // store dead+inactive pixels in DB, used as starting point for later runs
517#ifndef SPD_DA_OFF
518 for (UInt_t eq=0; eq<20; eq++) {
519 Int_t storePreviousDead_status = 0;
520 TString idpd = Form("spd_previous_dead_%d",eq);
521 TString fileName = Form("%s/SPD_Dead_%d.root",saveDirDead,eq);
522 storePreviousDead_status = daqDA_DB_storeFile(fileName.Data(),idpd.Data());
523 // printf("daqDA_DB_storeFile(%s,%s)\n",fileName.Data(),idpd.Data());
469c929f 524 if (storePreviousDead_status) {
f42c2e3b 525 printf("SPD DA ERROR: Failed to store dead file %s in daqDetDB: status=%d.\n",idpd.Data(),storePreviousDead_status);
526 }
527 }
528#endif
529
530
b696414b 531 // send (dead) reference data for this run to FXS - only if there is no chip in category "needsMoreStat"
f42c2e3b 532 if (nrEnoughStatChips>0 && nrEnoughStatChips+nrDeadChips+nrInefficientChips == 1200) {
533 printf("SPD DA: Dead calibration is complete.\n");
534 printf("SPD DA: Preparing dead reference data\n");
803e6db5 535 // send reference data for dead pixels to FXS
536 TString tarFiles = "";
b696414b 537 for (UInt_t eq=0; eq<20; eq++) {
538 if (eqActiveDead[eq]) {
f42c2e3b 539 printf("SPD DA: Preparing dead pixels for eq %d\n",eq);
803e6db5 540 // move file to ref dir
b696414b 541 TString fileName = Form("%s/SPDphys_dead_run_0_0_eq_%d.root",saveDirDeadRefTmp,eq);
542 TString newFileName = Form("%s/SPDphys_dead_run_%d_%d_eq_%d.root",saveDirDeadRef,firstRunNrDead,runNr,eq);
803e6db5 543 TString command = Form("mv -f %s %s",fileName.Data(),newFileName.Data());
544 system(command.Data());
545
b696414b 546 tarFiles.Append(Form("SPDphys_dead_run_%d_%d_eq_%d.root ",firstRunNrDead,runNr,eq));
803e6db5 547 }
548 }
f42c2e3b 549 if (tarFiles.Length() > 0) { // make sure there are any files to send
550 TString send_command = Form("cd %s; tar -cf ref_phys_dead.tar %s",saveDirDeadRef,tarFiles.Data());
551 system(send_command.Data());
552 TString fileName = Form("%s/ref_phys_dead.tar",saveDirDeadRef);
553 TString id = "SPD_ref_phys_dead";
803e6db5 554#ifndef SPD_DA_OFF
f42c2e3b 555 status = daqDA_FES_storeFile(fileName.Data(),id.Data());
556 if (status!=0) {
557 printf("SPD DA ERROR: Failed to export file %s , status %d\n",fileName.Data(),status);
558 return -1;
559 }
803e6db5 560#endif
f42c2e3b 561 idsFXSfile << Form("%s\n",id.Data());
562 }
803e6db5 563 }
564
565
478d804c 566
b696414b 567 // send (noisy) reference data for this run to FXS
f42c2e3b 568 printf("SPD DA: Preparing noisy reference data\n");
803e6db5 569 TString tarFiles = "";
b696414b 570 for (UInt_t eq=0; eq<20; eq++) {
571 if (eqActiveNoisy[eq]) {
572 tarFiles.Append(Form("SPDphys_run_%d_eq_%d.root ",runNr,eq));
803e6db5 573 }
574 }
f42c2e3b 575 if (tarFiles.Length() > 0) { // make sure there are any files to send
576 TString send_command = Form("cd %s; tar -cf ref_phys.tar %s",saveDirNoisyRef,tarFiles.Data());
577 system(send_command.Data());
578 TString fileName = Form("%s/ref_phys.tar",saveDirNoisyRef);
579 TString id = "SPD_ref_phys";
803e6db5 580#ifndef SPD_DA_OFF
f42c2e3b 581 status = daqDA_FES_storeFile(fileName.Data(),id.Data());
582 if (status!=0) {
583 printf("SPD DA ERROR: Failed to export file %s , status %d\n",fileName.Data(),status);
584 return -1;
585 }
803e6db5 586#endif
f42c2e3b 587 idsFXSfile << Form("%s\n",id.Data());
588 }
803e6db5 589
478d804c 590
591
803e6db5 592 // send dead pixels to FXS
f42c2e3b 593 printf("SPD DA: Preparing dead files for FXS\n");
803e6db5 594 // send a tared file of all the dead files
f42c2e3b 595 TString send_command = Form("cd %s; tar -cf dead_phys.tar *",saveDirDeadToFXS);
803e6db5 596 // printf("\n\n%s\n\n",command.Data());
597 system(send_command.Data());
f42c2e3b 598 TString fileName = Form("%s/dead_phys.tar",saveDirDeadToFXS);
599 TString id = "SPD_phys_dead";
803e6db5 600#ifndef SPD_DA_OFF
601 Int_t send_status = daqDA_FES_storeFile(fileName.Data(),id.Data());
602 if (send_status!=0) {
f42c2e3b 603 printf("SPD DA ERROR: Failed to export file %s , status %d\n",fileName.Data(),send_status);
803e6db5 604 return -1;
605 }
606#endif
607 idsFXSfile << Form("%s\n",id.Data());
803e6db5 608
609
478d804c 610
803e6db5 611 // send noisy pixels to FXS
f42c2e3b 612 if (nrNoisyFilesProduced > 0) { // make sure there is at least one file created
613 printf("SPD DA: Preparing noisy files for FXS\n");
803e6db5 614 // send a tared file of all the noisy files
615 TString command = Form("cd %s; tar -cf noisy_phys.tar *",saveDirNoisyToFXS);
616 // printf("\n\n%s\n\n",command.Data());
617 system(command.Data());
618 TString fileName = Form("%s/noisy_phys.tar",saveDirNoisyToFXS);
619 TString id = "SPD_phys_noisy";
620#ifndef SPD_DA_OFF
621 status = daqDA_FES_storeFile(fileName.Data(),id.Data());
622 if (status!=0) {
f42c2e3b 623 printf("SPD DA ERROR: Failed to export file %s , status %d\n",fileName.Data(),status);
803e6db5 624 return -1;
625 }
626#endif
627 idsFXSfile << Form("%s\n",id.Data());
628 }
629
630
478d804c 631
803e6db5 632 // send ids file to FXS
633 idsFXSfile.close();
634 id = "SPD_id_list";
635#ifndef SPD_DA_OFF
636 status = daqDA_FES_storeFile(idsFXSFileName.Data(),id.Data());
637 if (status!=0) {
f42c2e3b 638 printf("SPD DA ERROR: Failed to export file %s , status %d\n",idsFXSFileName.Data(),status);
803e6db5 639 return -1;
640 }
641#endif
642
643
644
645
646 delete handler;
647
478d804c 648 // printf("*** End step2 , %d\n",time(NULL) - timeStamp);
649
803e6db5 650
651 return 0;
b696414b 652}