Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cwb.cc
Go to the documentation of this file.
1 #include "cwb.hh"
2 #include "mdc.hh"
3 #include "time.hh"
4 #include "Math/Polar3D.h"
5 #include "TMD5.h"
6 
7 #define EXIT(ERR) gSystem->Exit(ERR) // better exit handling for ROOT stuff
8 
9 using namespace ROOT::Math;
10 
11 ClassImp(cwb)
12 
13 cwb::cwb(CWB_STAGE jstage) {
14 //
15 // Default Constructor
16 //
17 // used only for cwb class streaming
18 //
19 
20  this->istage=CWB_STAGE_FULL;
21  this->jstage=jstage;
22  this->runID=0;
23  this->singleDetector=false;
24  this->lagBuffer.Set(0);
25  SetupStage(jstage);
26  Init();
27 }
28 
30 //
31 // Constructor
32 //
33 // In this method the cwb configuration is loaded
34 // The default configuration is defined in the $CWB_PARAMETERS_FILE file
35 // The user can provide a customized configuration using the fName or xName parameters
36 //
37 // fName : if fName ends with *.C the parameter is used as cwb user configuration file name
38 // The custom config must contains only the parameters which differ from the defaults
39 // and must not be declared with types (Ex : fLow=64; instead of double fLow=64;)
40 // if fName="" only the default cwb configuration file is used ($CWB_PARAMETERS_FILE)
41 // if fName ends with *.root the parameter is used as job file name
42 // the configuration is read from the job file (the previous processed stage)
43 // istage is initialized with the previous processed stage
44 // xName : this parameter is used as auxiliary cwb configuration file when fName ends with *.root
45 // the xName file is used to change the configuration stored in the job file
46 //
47 // jstage : is the final stage to be processed
48 //
49 
50  this->runID=0;
51  this->singleDetector=false;
52  this->lagBuffer.Set(0);
53  this->istage=CWB_STAGE_FULL;
54  if(fName.EndsWith(".root")) {
55  TFile* ifile = new TFile(fName);
56  if(!ifile->IsOpen()) {
57  cout << "cwb::cwb - Error opening root file : " << fName.Data() << endl;
58  EXIT(1);
59  }
60  // read config object
61  if(ifile->Get("config")!=NULL) {
62  // read config object
63  CWB::config* pcfg = (CWB::config*)ifile->Get("config");
64  cfg = *pcfg;
65  // read cwb object
66  cwb* CWB = (cwb*)ifile->Get("cwb");
67  if(CWB==NULL) {
68  cout << "cwb::cwb - Error : cwb is not contained in root file " << fName.Data() << endl;
69  EXIT(1);
70  }
71  // read runID
72  this->runID = CWB->runID;
73  // read singleDetector
74  this->singleDetector = CWB->singleDetector;
75  // read initial stage
76  this->istage = CWB->jstage;
77  if(jstage<=istage) {
78  cout << "cwb::cwb - Error : the stage(job file) " << GetStageString(istage).Data() << " >= "
79  << " input stage " << GetStageString(jstage).Data() << endl;EXIT(1);
80  EXIT(1);
81  }
82  // read frame structures
83  for(int i=0;i<2*NIFO_MAX;i++) {
84  this->nfrFiles[i] = CWB->nfrFiles[i];
85  this->fr[i] = CWB->fr[i];
86  this->FRF[i] = CWB->FRF[i];
87  }
88  // restore lag setting
89  lagBuffer = CWB->lagBuffer;
90  lagBuffer.Set(lagBuffer.GetSize()+1);
91  lagBuffer[lagBuffer.GetSize()-1]=0; // set end of string
92  lagMode[0]=CWB->lagMode[0];lagMode[1]=0; // restore lagMode
93  // restore detSegs
94  detSegs = CWB->detSegs;
95 
96  delete CWB;
97  // set local environment
98  if(gSystem->Getenv("HOME_WAT_FILTERS")==NULL) {
99  cout << "cwb::cwb - Error : environment HOME_WAT_FILTERS is not defined!!!" << endl;EXIT(1);
100  } else {
101  strcpy(cfg.filter_dir,TString(gSystem->Getenv("HOME_WAT_FILTERS")).Data());
102  }
103  // export config to cint
104  cfg.Export();
105  // set auxiliary configuration
106  if(xName!="") {
107  CWB::config icfg = cfg; // cfg from input job file
108  cfg.Import(xName); // cfg from input job file + auxiliary configuration
109  if(cfg.simulation==4) { // initialize array factors
110  if(int(cfg.factors[0])<=0) cfg.factors[0]=1; // set 1 if <=0
111  int ioffset = int(cfg.factors[0]); // extract offset
112  for(int i=ioffset;i<ioffset+cfg.nfactor;i++) cfg.factors[i]=i; // assign integer values
113  }
114  // check if auxiliary parameters are compatible with the previous stage config
115  if(cfg.simulation!=icfg.simulation) { // simulation
116  cout << "cwb::cwb - Error : aux simulation " << cfg.simulation
117  << " != in cfg simulation " << icfg.simulation << endl; EXIT(1);}
118  if(cfg.nfactor!=icfg.nfactor) { // nfactor
119  cout << "cwb::cwb - Error : aux nfactor " << cfg.nfactor
120  << " != in cfg nfactor " << icfg.nfactor << endl; EXIT(1);
121  } else { // factors
122  for(int i=0;i<=cfg.nfactor;i++) if(cfg.factors[i]!=icfg.factors[i]) {
123  cout << "cwb::cwb - Error : aux factors["<<i<<"]="<<cfg.factors[i]
124  << " != in cfg factors["<<i<<"]=="<<icfg.factors[i]<<endl;EXIT(1);}
125  }
126  if(cfg.l_low!=icfg.l_low) { // l_low
127  cout << "cwb::cwb - Error : aux l_low " << cfg.l_low
128  << " != in cfg l_low " << icfg.l_low << endl; EXIT(1);}
129  if(cfg.l_high!=icfg.l_high) { // l_high
130  cout << "cwb::cwb - Error : aux l_high " << cfg.l_high
131  << " != in cfg l_high " << icfg.l_high << endl; EXIT(1);}
132  if(cfg.fLow!=icfg.fLow) { // fLow
133  cout << "cwb::cwb - Error : aux fLow " << cfg.fLow
134  << " != in cfg fLow " << icfg.fLow << endl; EXIT(1);}
135  if(cfg.fHigh!=icfg.fHigh) { // fHigh
136  cout << "cwb::cwb - Error : aux fHigh " << cfg.fHigh
137  << " != in cfg fHigh " << icfg.fHigh << endl; EXIT(1);}
138  if(cfg.healpix!=icfg.healpix) { // healpix
139  cout << "cwb::cwb - Error : aux healpix " << cfg.healpix
140  << " != in cfg healpix " << icfg.healpix << endl; EXIT(1);}
141  }
142  } else {
143  cout << "cwb::cwb - Error : config is not contained in root file " << fName.Data() << endl;
144  EXIT(1);
145  }
146  ifile->Close();
147  iname=fName;
148  } else if(fName.EndsWith(".C")) {
149  if(gSystem->Getenv("CWB_PARAMETERS_FILE")==NULL) {
150  cout << "cwb::cwb - Error : environment CWB_PARAMETERS_FILE is not defined!!!" << endl;
151  EXIT(1);
152  } else {
153  // load default configuration $CWB_PARAMETERS_FILE
154  cfg.Import("$CWB_PARAMETERS_FILE");
155  }
156  cfg.Import(fName);
157  iname="";
158  } else if(fName=="") {
159  if(gSystem->Getenv("CWB_PARAMETERS_FILE")==NULL) {
160  cout << "cwb::cwb - Error : environment CWB_PARAMETERS_FILE is not defined!!!" << endl;
161  EXIT(1);
162  } else {
163  // load default configuration $CWB_PARAMETERS_FILE
164  cfg.Import("$CWB_PARAMETERS_FILE");
165  }
166  iname="";
167  } else {
168  cout << "cwb::cwb - Error : bad input file extension [.C, .root] " << fName.Data() << endl;
169  EXIT(1);
170  }
171  this->jstage=jstage;
172  SetupStage(jstage);
173  Init();
174  if(fName!="") cfg.Check(); // check parameter's consistency
175 }
176 
178 //
179 // Constructor
180 //
181 // use the config object as configuration
182 //
183 // jstage : is the final stage to be processed
184 //
185 
186  this->cfg = cfg;
187  this->istage=CWB_STAGE_FULL;
188  this->jstage=jstage;
189  this->runID=0;
190  this->singleDetector=false;
191  this->lagBuffer.Set(0);
192  SetupStage(jstage);
193  Init();
194  cfg.Check(); // check parameter's consistency
195 }
196 
198 //
199 // Destructor
200 //
201 
202  if(mdc!=NULL) delete mdc;
203  //if(netburst!=NULL) delete netburst; // commented because is already deleted by "delete froot"
204  if(history!=NULL) delete history;
205  if(jfile!=NULL) delete jfile;
206  if(froot!=NULL) delete froot;
207  if(singleDetector && pD[1]!=NULL) {pD[1]->IWFP.clear();pD[1]->RWFP.clear();}
208  for(int n=0;n<NIFO_MAX;n++) if(pD[n]!=NULL) delete pD[n];
209 }
210 
211 void
213 //
214 // Reset/Initialize the pipeline parameters
215 //
216 
217  // There is a bug in ROOT > 5.32.04 & < 5.34.00
218  // GarbageCollector don't remove the deleted objects from root file
219  // Tree saved to root in the Coherence stage could be corrupted
220 #ifdef _USE_ROOT6
221  cout << "cwb::Init - Warning !!! : This is a testing version for ROOT6" << endl;
222 #else
223  if(gROOT->GetVersionInt()>53204 && gROOT->GetVersionInt()<53400) {
224  cout << "cwb::Init - Error : cWB analysis don't works with ROOT version > 5.32.04 && version < 5.34.00" << endl;
225  cout << "You are running version : ROOT " << gROOT->GetVersion() << endl << endl;
226  EXIT(1);
227  }
228 #endif
229  if((cfg.simulation==4)&&(jstage==CWB_STAGE_STRAIN)&&(cfg.nfactor>1)) {
230  // NOTE : in the ReadData it is necessary to save MDC data for each factor
231  cout << "cwb::Init - Error : stage STRAIN not implemented with simulation=4" << endl;
232  EXIT(1);
233  }
234 
236  cout<<"cwb::Init - Error : jobfOptions=CWB_JOBF_SAVE_TRGFILE is allowed only with CWB_STAGE_FULL!!!"<<endl;
237  EXIT(1);
238  }
239 
240  if(cfg.fResample>0) { // RESAMPLING
242  } else {
244  }
245 
246  // check if rate is an integer at resolution level = l_high
247  if(rateANA-(1<<cfg.l_high)*(rateANA/(1<<cfg.l_high))!=0) {
248  cout << "cwb::Init - Error : data rate : " << rateANA
249  << " is not a multiple of 2^l_high : " << (1<<cfg.l_high) << endl;
250  EXIT(1);
251  }
252 
253  froot=NULL;
254  jfile=NULL;
255  mdc=NULL;
256  netburst=NULL;
257  history=NULL;
258  for(int n=0;n<NIFO_MAX;n++) pD[n]=NULL;
259  return;
260 }
261 
262 void
263 cwb::run(int runID) {
264 //
265 // The method used to start the analysis
266 //
267 // runID : is the job ID number, this is used in InitJob method to identify the
268 // the time range to be analyzed
269 //
270 // These are the main actions performed by this method
271 //
272 // - LoadPlugin
273 // - InitNetwork
274 // - InitHistory
275 // - InitJob
276 // - Loop over Factors
277 // - ReadData
278 // - DataConditioning
279 // - Coherence
280 // - SuperCluster
281 // - Likelihood
282 // - Save Recontructed Parameters
283 // - Save Job File (only for multi stage analysis)
284 //
285 
286  lags = 0;
287  double factor = 1.0; // strain factor
288  int ioffset = 0; // ifactor offset
289  watchJob.Start(); // start job benchmark
290  watchStage.Start(); // start stage benchmark
291 
292  bplugin = (TString(cfg.plugin.GetName())!="") ? true : false; // user plugin
293 
294  unsigned int Pid = gSystem->GetPid(); // used to tag in a unique way the temporary files
295 
296  double DATA_RATE = 0.;
297 
298  char tmpFile[1024];
299  char outFile[1024];
300  char endFile[1024];
301  char outDump[1024];
302  char endDump[1024];
303  char out_CED[1024];
304  char end_CED[1024];
305  char command[1024];
306  int ecommand=0;
307  FileStat_t fstemp;
308  char cmd[1024];
309 
310  if(cfg.nIFO==0) {cout << "cwb::cwb - Error : no detector is presents in the configuration" << endl;EXIT(1);}
311 
312  this->nIFO=cfg.nIFO;
313  for(int n=0;n<nIFO;n++) {
314  if(strlen(cfg.ifo[n])>0) strcpy(this->ifo[n],cfg.ifo[n]); // built in detector
315  else strcpy(this->ifo[n],cfg.detParms[n].name); // user define detector
316  }
317 
318  if(this->runID==0) { // this->runID>0 for multistage analysis
319  if(runID>0) {
320  this->runID=runID;
321  } else {
322  TString srunID = TString(gSystem->Getenv("CWB_JOBID"));
323  this->runID = srunID.Atoi();
324  }
325  }
326 
327  sprintf(cfg.work_dir,gSystem->WorkingDirectory());
328  sprintf(cfg.data_label,gSystem->BaseName(cfg.work_dir));
329 
330  cout<<"job ID : "<<this->runID<<endl;
331  cout<<"output : "<<cfg.output_dir<<endl;
332  cout<<"label : "<<cfg.data_label<<endl;
333  cout<<"nodedir : "<<cfg.nodedir<<endl;
334  cout<<"Pid : "<<Pid<<endl;
335 
336  // create log, nodedir & output directories
337  // Note : this step is necessary in multi stage analysis when pipeline
338  // start from an intermediate stage from a non structured working dir
339  sprintf(cmd,"mkdir -p %s",cfg.log_dir); gSystem->Exec(cmd);
340  sprintf(cmd,"mkdir -p %s",cfg.nodedir); gSystem->Exec(cmd);
341  sprintf(cmd,"mkdir -p %s",cfg.output_dir); gSystem->Exec(cmd);
342 
343  // export to CINT istage,jstage (used by plugins)
344  sprintf(cmd,"gISTAGE = (CWB_STAGE)%d;",istage); EXPORT(CWB_STAGE,gISTAGE,cmd)
345  sprintf(cmd,"gJSTAGE = (CWB_STAGE)%d;",jstage); EXPORT(CWB_STAGE,gJSTAGE,cmd)
346  // export to CINT ifactor (used by plugins)
347  sprintf(cmd,"gIFACTOR = -1;"); EXPORT(int,gIFACTOR,cmd) // init to gIFACTOR=-1
348 
349  // compile & load user plugin
350  if(bplugin) LoadPlugin(cfg.plugin,cfg.configPlugin);
351 
352  if(bplugin) {CWB_Plugin(NULL,&cfg,&NET,NULL,"",CWB_PLUGIN_CONFIG);SetupStage(jstage);}
353 
354  // ---------------------------------------
355  // init network
356  // ---------------------------------------
357 
358  iname=="" ? InitNetwork() : InitNetwork(iname);
359 
360  PrintAnalysis();
361 
362  // ---------------------------------------
363  // init history
364  // ---------------------------------------
365 
366  InitHistory();
367 
368  // ---------------------------------------
369  // init job
370  // ---------------------------------------
371 
372  double mdcShift = iname=="" ? InitJob() : InitJob(iname);
373 
374  // temporary job file
375  sprintf(jname,"%s/job_%d_%s_%d_%d.root",cfg.nodedir,int(Tb),cfg.data_label,this->runID,Pid);
376  cout<<"temporary job file : " << jname<<endl;
377 
378  if(jstage==CWB_STAGE_INIT) goto JOB_END;
379 
380  // ---------------------------------------
381  // read data (simulation!=4)
382  // ---------------------------------------
383 
384  if(cfg.simulation!=4) {
385  DATA_RATE = ReadData(mdcShift,0);
386  if(jstage==CWB_STAGE_STRAIN) goto JOB_END;
387  }
388 
389  // ---------------------------------------
390  // if simulation!=0, loop on the injection strain factors
391  // ---------------------------------------
392 
393  if(!cfg.simulation) cfg.nfactor = 1;
394 
395  ioffset = (cfg.simulation==4) ? int(cfg.factors[0]) : 0; // ifactor offset
396 
397  for(int ifactor=ioffset; ifactor<ioffset+cfg.nfactor; ifactor++) {
398 
399  int ceddir = 0; // flag if ced directory exists
400 
401  // export to CINT ifactor (used by plugins)
402  sprintf(cmd,"gIFACTOR = %d;",ifactor); EXPORT(int,gIFACTOR,cmd)
403 
404  // ---------------------------------------
405  // declaration of output files
406  // ---------------------------------------
407 
408  if(cfg.simulation) {
409  factor=cfg.factors[ifactor];
410  cout<<endl<< "---> Start processing factor["<<ifactor<< "]="<<factor<<endl<< endl;
411  char sfactor[32];
412  if(cfg.simulation==3) {
413  if(factor<0) sprintf(sfactor,"n%g",fabs(factor));
414  if(factor==0) sprintf(sfactor,"z%g",factor);
415  if(factor>0) sprintf(sfactor,"p%g",factor);
416  } else sprintf(sfactor,"%g",factor);
417  char sim_label[512];
418  sprintf(sim_label,"%d_%d_%s_%s_job%d",int(Tb),int(dT),cfg.data_label,sfactor,this->runID);
419 
420  sprintf(outFile,"%s/wave_%s_%d.root",cfg.nodedir,sim_label,Pid);
421  sprintf(endFile,"%s/wave_%s.root",cfg.output_dir,sim_label);
422  sprintf(tmpFile,"%s/wave_%s_%d.root.tmp",cfg.nodedir,sim_label,Pid);
423  sprintf(outDump,"%s/wave_%s_%d.txt",cfg.nodedir,sim_label,Pid);
424  sprintf(endDump,"%s/wave_%s.txt",cfg.output_dir,sim_label);
425  sprintf(out_CED,"%s/ced_%s_%d",cfg.nodedir,sim_label,Pid);
426  sprintf(end_CED,"%s/ced_%s",cfg.output_dir,sim_label);
427 
428  if(!gSystem->GetPathInfo(endFile,fstemp)) {
429  printf("The file %s already exists - skip\n",endFile);
430  fflush(stdout);
431  TFile rf(endFile);
432  if(!rf.IsZombie()) continue;
433  }
434  }
435  else {
436  char prod_label[512];
437  sprintf(prod_label,"%d_%d_%s_slag%d_lag%lu_%lu_job%d",
438  int(Tb),int(dT),cfg.data_label,slagID,cfg.lagOff,cfg.lagSize,this->runID);
439 
440  sprintf(outFile,"%s/wave_%s_%d.root",cfg.nodedir,prod_label,Pid);
441  sprintf(endFile,"%s/wave_%s.root",cfg.output_dir,prod_label);
442  sprintf(tmpFile,"%s/wave_%s_%d.root.tmp",cfg.nodedir,prod_label,Pid);
443  sprintf(outDump,"%s/wave_%s_%d.txt",cfg.nodedir,prod_label,Pid);
444  sprintf(endDump,"%s/wave_%s.txt",cfg.output_dir,prod_label);
445  sprintf(out_CED,"%s/ced_%s_%d",cfg.nodedir,prod_label,Pid);
446  sprintf(end_CED,"%s/ced_%s",cfg.output_dir,prod_label);
447  }
448 
449  // check if out_CED & end_CED already exist
450  if(cfg.cedDump) {
451  Long_t id,size=0,flags,mt;
452  if (!gSystem->GetPathInfo(out_CED,&id,&size,&flags,&mt)) {
453  cout << "cwb::run - Warning !!! - Dir \"" << out_CED << "\" already exist" << endl;
454  EXIT(0);
455  }
456  if (!gSystem->GetPathInfo(end_CED,&id,&size,&flags,&mt)) {
457  cout << "cwb::run - Warning !!! - Dir \"" << end_CED << "\" already exist" << endl;
458  EXIT(0);
459  }
460  }
461 
462  // remove outDump file
463  Long_t xid,xsize,xflags,xmt;
464  int xestat = gSystem->GetPathInfo(outDump,&xid,&xsize,&xflags,&xmt);
465  if (xestat==0) {
466  sprintf(command,"/bin/rm %s",outDump);
467  ecommand=gSystem->Exec(command);
468  if(ecommand) {cout << "cwb::cwb - Warning -> " << command << endl;}
469  }
470 
471  cout<<"output file on the node : "<<outFile<<endl;
472  cout<<"final output file name : "<<endFile<<endl;
473  cout<<"temporary output file : "<<tmpFile<<endl;
474 
475  // ---------------------------------------
476  // read mdc (simulation==4)
477  // ---------------------------------------
478 
479  if(cfg.simulation==4) {
480  DATA_RATE = ReadData(mdcShift,ifactor);
481  if(TString(cfg.analysis)=="2G" && jstage==CWB_STAGE_STRAIN) continue;
482  }
483 
484  // ---------------------------------------
485  // data conditioning
486  // ---------------------------------------
487 
488  DataConditioning(ifactor);
489  if(TString(cfg.analysis)=="2G" && jstage==CWB_STAGE_CSTRAIN) continue;
490 
491  // ---------------------------------------
492  // create output root file
493  // initialization of tree structures
494  // create prod/sim/lag directories
495  // ---------------------------------------
496 
497  froot = new TFile(tmpFile, "RECREATE");
498  if(froot==NULL) {cout << "cwb::cwb - Error opening root file : " << tmpFile << endl;EXIT(1);}
499  TTree* net_tree = !cfg.outPlugin ? netburst->setTree() : NULL; // outPlugin=true -> out tree is disabled
500  TTree* live_tree= live.setTree();
501  TTree* mdc_tree=NULL;
502  TTree* var_tree=NULL;
503  TTree* noise_tree=NULL;
504 
505  if(cfg.simulation) {
506  mdc_tree = mdc->setTree();
507  } else {
508  var_tree = wavevar.setTree();
509  noise_tree = noiserms.setTree();
510  }
511 
512  // ---------------------------------------
513  // start of the coherent search
514  // ---------------------------------------
515 
516  size_t mlagSize=cfg.lagOff+cfg.lagSize;
517  size_t mlagOff=cfg.lagOff;
518  size_t mlagStep=cfg.mlagStep;
519 
520  if(mlagStep==0) mlagStep=cfg.lagSize; // if mlagStep=0 -> standard lag analysis
521 
522  for(size_t mlag=mlagOff;mlag<mlagSize;mlag+=mlagStep) { // multilag loop
523 
524  cfg.lagOff = mlag;
525  cfg.lagSize = cfg.lagOff+mlagStep<=mlagSize ? mlagStep : mlagSize-cfg.lagOff;
526  if(cfg.lagSize==0) continue;
527 
528  cout << "lagSize : " << cfg.lagSize << " lagOff : " << cfg.lagOff << endl;
529 
530  std::vector<double> livTime;
531  if(iname!="") livTime=NET.livTime; // save livTime
532  if(!cfg.simulation) { // setup lags
534  lagBuffer.GetArray(),lagMode,cfg.lagSite);
535  cout<<"lag step: "<<cfg.lagStep<<endl;
536  cout<<"number of time lags: "<<lags<<endl;
537  }
538  else if(!lags) lags = NET.setTimeShifts();
539  if(iname!="") NET.livTime=livTime; // restore livTime
540 
541  // ---------------------------------------
542  // coherence analysis
543  // ---------------------------------------
544 
545  Coherence(ifactor);
546  if(TString(cfg.analysis)=="2G" && jstage==CWB_STAGE_COHERENCE) continue;
547 
548  // ---------------------------------------
549  // supercluster analysis
550  // ---------------------------------------
551 
552  SuperCluster(ifactor);
553  cout<<endl;
554  if(TString(cfg.analysis)=="1G") cout<<"events in the buffer: "<<NET.events()<<"\n";
555  if(TString(cfg.analysis)=="2G" && jstage==CWB_STAGE_SUPERCLUSTER) continue;
556 
557  // ---------------------------------------
558  // likelihood
559  // ---------------------------------------
560 
561  ceddir=Likelihood(ifactor, out_CED, netburst, net_tree, outDump);
562  cout<<"\nSearch done\n";
563  if(!cfg.cedDump) cout<<"reconstructed events: "<<NET.events()<<"\n";
564  if(cfg.simulation) NET.printwc(0);
565 
566  // ---------------------------------------
567  // save data into root file
568  // ---------------------------------------
569 
570  PrintStageInfo(CWB_STAGE_SAVE,"Data Save");
571  froot->cd();
572 
573  live.output(live_tree,&NET,slagShift,detSegs);
574 
575  if(cfg.simulation) {
576  double ofactor=0;
577  if(cfg.simulation==4) ofactor=-factor;
578  else if(cfg.simulation==3) ofactor=-ifactor;
579  else ofactor=factor;
580  if(TString(cfg.analysis)=="1G") {
581  if(cfg.dump) netburst->dopen(outDump,const_cast<char*>("w"));
582  netburst->output(net_tree,&NET,ofactor);
583  if(cfg.dump) netburst->dclose();
584  }
585  mdc->output(mdc_tree,&NET,ofactor);
586  } else {
587  if(TString(cfg.analysis)=="1G") {
588  if(cfg.dump) netburst->dopen(outDump,const_cast<char*>("w"));
589  netburst->output(net_tree,&NET);
590  if(cfg.dump) netburst->dclose();
591  }
592  for(int i=0; i<nIFO; i++) {
593  if(cfg.outfOptions&CWB_OUTF_SAVE_VAR) // write var tree
594  wavevar.output(var_tree,&v[i],i+1,cfg.segEdge);
595  if(cfg.outfOptions&CWB_OUTF_SAVE_NOISE) // write noise tree
596  noiserms.output(noise_tree,&pD[i]->nRMS,i+1,DATA_RATE/2);
597  }
598  }
599 
600  // save log info to final output root file
601  PrintStageInfo(CWB_STAGE_FINISH,"Job Finished",false,true,endFile);
602  history->AddLog( const_cast<char*>("FULL"), const_cast<char*>("STOP JOB"));
603  history->Write("history");
604 
605  froot->Write();
606 
607  } // end mlag loop
608 
609  froot->Close();
610 
611  // ---------------------------------
612  // move output files to end dirs
613  // ---------------------------------
614 
615  if((TString(cfg.analysis)=="2G") && (jstage!=CWB_STAGE_FULL && jstage!=CWB_STAGE_LIKELIHOOD)) {
616  // delete temporary output file
617  sprintf(command,"/bin/rm %s", tmpFile);
618  ecommand=gSystem->Exec(command);
619  if(ecommand) {cout << "cwb::cwb - Warning -> " << command << endl;}
620  continue;
621  }
622  sprintf(command,"/bin/mv %s %s", tmpFile, outFile);
623  if(!cfg.cedDump || (cfg.cedDump && cfg.online)) Exec(command);
624  if(cfg.cedDump && !cfg.online) sprintf(command,"/bin/rm %s",tmpFile);
625  else sprintf(command,"/bin/mv %s %s",outFile,endFile);
626  Exec(command);
627  if(cfg.cedDump && !cfg.online) sprintf(command,"/bin/rm %s",outDump);
628  else sprintf(command,"/bin/mv %s %s",outDump,endDump);
629  if(cfg.dump) {
630  // if file outDump exists then it is moved to endDump
631  if(!gSystem->GetPathInfo(outDump,&xid,&xsize,&xflags,&xmt)) Exec(command);
632  }
633  xestat = gSystem->GetPathInfo(end_CED,&xid,&xsize,&xflags,&xmt);
634  if (xestat==0) {
635  sprintf(command,"/bin/mv %s/* %s/.",out_CED,end_CED);
636  } else {
637  sprintf(command,"/bin/mv %s %s",out_CED,end_CED);
638  }
639  if(cfg.cedDump && ceddir && !(jobfOptions&CWB_JOBF_SAVE_CED)) Exec(command);
640  }
641 
642  JOB_END:
643 
644  sprintf(cmd,"gIFACTOR = -1;"); EXPORT(int,gIFACTOR,cmd) // set gIFACTOR=-1
645 
646  // -------------------------------------------------------------------
647  // write cwb, history, config, network objects into temporary job file
648  // -------------------------------------------------------------------
649 
651  // set options to save trigger file when full stage is used
653  //this->cwb::jobfOptions = CWB_JOBF_SAVE_DISABLE;
655  // clear network skymap filled in Likelihood stage (save space)
656  NET. nSensitivity=0; NET. nAlignment=0; NET. nCorrelation=0;
657  NET. nLikelihood=0; NET. nNullEnergy=0; NET. nPenalty=0;
658  NET. nCorrEnergy=0; NET. nNetIndex=0; NET. nDisbalance=0;
659  NET. nSkyStat=0; NET. nEllipticity=0; NET. nPolarisation=0;
660  NET. nProbability=0;
661  }
662 
663  jfile = new TFile(jname,"UPDATE");
664  if(jfile==NULL||!jfile->IsOpen())
665  {cout << "cwb::cwb - Error opening root file : " << jname << endl;EXIT(1);}
666  jfile->cd();
667  if(jobfOptions&CWB_JOBF_SAVE_CONFIG) { // write config object
668  TString tempName = cfg.configPlugin.GetName(); // save temporary macro name
669  TString tempTitle = cfg.configPlugin.GetTitle(); // save temporary macro title
670  // get original macro name
671  TObjString* objn = cfg.configPlugin.GetLineWith("//#?CONFIG_PLUGIN_NAME ");
672  TString origName = objn ? objn->GetString() : "";
673  cfg.configPlugin.SetName(origName.ReplaceAll("//#?CONFIG_PLUGIN_NAME ",""));
674  // get original macro title
675  TObjString* objt = cfg.configPlugin.GetLineWith("//#?CONFIG_PLUGIN_TITLE ");
676  TString origTitle = objt ? objt->GetString() : "";
677  cfg.configPlugin.SetTitle(origTitle.ReplaceAll("//#?CONFIG_PLUGIN_TITLE ",""));
678  cfg.Write("config");
679  cfg.configPlugin.SetName(tempName); // restore temporary macro name
680  cfg.configPlugin.SetTitle(tempTitle); // restore temporary macro title
681  }
683  // in 2G analysis the network::getNetworkPixels do "pixeLHood = *pTF;"
684  // the Forwad operation after WDM::setTDFilter include in pTF the TD structures
685  // since WDM and SymmObjArray streamers are incomplete because of its pointers
686  // the read/save to/from root jfile is not a safe operation
687  // a workaround is to set to 0 the TD structures
688  ((WDM<double>*)NET.pixeLHood.pWavelet)->T0.Resize(0);
689  ((WDM<double>*)NET.pixeLHood.pWavelet)->Tx.Resize(0);
690  }
691  if(jobfOptions&CWB_JOBF_SAVE_NETWORK) NET.Write("network"); // write network object
692  if(jobfOptions&CWB_JOBF_SAVE_JNET_MACRO) { // write cwb_jnet macro
693  // check if cwb_jnet.C macro exists
694  TString cwb_jnet_name = gSystem->ExpandPathName("$CWB_MACROS/cwb_jnet.C");
695  TB.checkFile(cwb_jnet_name);
696  TMacro cwb_jnet(cwb_jnet_name);
697  cwb_jnet.Write("cwb_jnet");
698  }
699  PrintStageInfo(CWB_STAGE_FINISH,"Job Finished",false,true);
700  history->AddLog( const_cast<char*>("FULL"), const_cast<char*>("STOP JOB"));
701  if(jobfOptions&CWB_JOBF_SAVE_HISTORY) history->Write("history");
702  if(jobfOptions&CWB_JOBF_SAVE_CWB) this->cwb::Write("cwb");
703  if(bplugin) {
704  wavearray<double> x; // temporary time series
705  for(int i=0; i<nIFO; i++) {
706  x.rate(cfg.inRate); x.start(FRF[i].start); x.resize(int(x.rate()*(FRF[i].stop-FRF[i].start)));
708  }
709  x.resize(0);
710  }
711  jfile->Close();
712 
713  // ---------------------------------
714  // clean-up temporary job file
715  // ---------------------------------
716 
717  if(jobfOptions) {
718  // get rid of duplicated trees created by TFileMergers
719  TFile *f = TFile::Open(jname,"UPDATE");
720  TDirectory* d;
721  for(int ifactor=0; ifactor<cfg.nfactor; ifactor++) {
722  for(int j=0; j<(int)NET.nLag; j++) {
723  netcluster* pwc = NET.getwc(j);
724  if(pwc==NULL) continue;
725  int cycle = cfg.simulation ? ifactor : Long_t(pwc->shift);
726  char trName[64];sprintf(trName,"clusters-cycle:%d;2",cycle);
727  d = (TDirectory*)f->Get("coherence;1");
728  if(d!=NULL) if(d->Get(trName)!=NULL) d->Delete(trName);
729  d = (TDirectory*)f->Get("supercluster;1");
730  if(d!=NULL) if(d->Get(trName)!=NULL) d->Delete(trName);
731  d = (TDirectory*)f->Get("likelihood;1");
732  if(d!=NULL) if(d->Get(trName)!=NULL) d->Delete(trName);
733  }
734  }
735  f->Close();
736 
737  // assign final file name according to the stage name
738  char jlabel[512]; sprintf(jlabel,"%d_%d_%s",int(Tb),int(dT),cfg.data_label);
739  char wlabel[512]; sprintf(wlabel,"wave_%s",jlabel);
740  TString jLABEL=jlabel;
741  if((jstage!=CWB_STAGE_FULL)&&(jstage!=CWB_STAGE_LIKELIHOOD))
742  sprintf(endFile,"%s/wave_%s_job%d.root",cfg.output_dir,jlabel,this->runID);
743  TString ojname = endFile;
744  if(TString(cfg.analysis)=="1G") ojname.ReplaceAll(wlabel,TString("job_")+jLABEL);
745  else { // 2G
746  if(jstage==CWB_STAGE_FULL) ojname.ReplaceAll(wlabel,TString("job_")+jLABEL);
747  if(jstage==CWB_STAGE_INIT) ojname.ReplaceAll(wlabel,TString("init_")+jLABEL);
748  if(jstage==CWB_STAGE_STRAIN) ojname.ReplaceAll(wlabel,TString("strain_")+jLABEL);
749  if(jstage==CWB_STAGE_CSTRAIN) ojname.ReplaceAll(wlabel,TString("cstrain_")+jLABEL);
750  if(jstage==CWB_STAGE_COHERENCE) ojname.ReplaceAll(wlabel,TString("coherence_")+jLABEL);
751  if(jstage==CWB_STAGE_SUPERCLUSTER) ojname.ReplaceAll(wlabel,TString("supercluster_")+jLABEL);
752  if(jstage==CWB_STAGE_LIKELIHOOD) ojname.ReplaceAll(wlabel,TString("job_")+jLABEL);
753  }
754 
755  // if CWB_JOBF_SAVE_NODE then 2G to store the intermediate stage job files to nodedir
756  // and creates a symbolic link to the final working dir output file name
758  TString olname = ojname; // symbolic link path destination
759  ojname.ReplaceAll(TString(cfg.output_dir)+TString("/"),TString(cfg.nodedir)+TString("/"));
760  // symbolic link path origin
761  if(ojname.BeginsWith("/")) {
762  sprintf(command,"/bin/ln -sf %s %s",ojname.Data(),olname.Data());
763  } else {
764  sprintf(command,"/bin/ln -sf ../%s %s",ojname.Data(),olname.Data());
765  }
766  cout << command << endl;
767  ecommand=gSystem->Exec(command);
768  if(ecommand) {cout << "cwb::cwb - Warning -> " << command << endl;}
769  }
770 
771  sprintf(endFile,"%s",ojname.Data()); // used by PrintStageInfo
772 
773  // move temporary job file to final position
774  sprintf(command,"/bin/mv %s %s",jname,ojname.Data());
775  ecommand=gSystem->Exec(command);
776  if(ecommand) {cout << "cwb::cwb - Warning -> " << command << endl;}
777 
778  } else {
779 
780  // remove temporary job file
781  sprintf(command,"/bin/rm %s",jname);
782  ecommand=gSystem->Exec(command);
783  if(ecommand) {cout << "cwb::cwb - Warning -> " << command << endl;}
784  }
785 
786  // remove temporary configPlugin file
787  if(TString(cfg.configPlugin.GetTitle())!="")
788  gSystem->Exec(TString("rm ")+cfg.configPlugin.GetTitle());
789 
790  // ---------------------------------
791  // print final infos
792  // ---------------------------------
793 
794  cout << endl << endl;
795  PrintStageInfo(CWB_STAGE_FINISH,"Job Finished",true,false,endFile);
796  int job_data_size_sec = dT;
797  double job_speed_factor = double(job_data_size_sec)/double(watchJob.RealTime());
798  cout << endl;
799  printf("Job Speed Factor - %2.2fX\n",job_speed_factor);
800  cout << endl;
801 
802  watchJob.Stop();watchJob.Reset();
803 
804  // ONLINE : create empty file "finished" in the output directory
805  if(cfg.online) {
806  sprintf(command,"touch %s/finished",cfg.output_dir);
807  gSystem->Exec(command);
808  }
809 
810  return;
811 }
812 
813 void
815 //
816 // Init the Network object : set detectors and network parameters
817 //
818 // read the network object from the job file (the previous processed stage)
819 //
820 
821  PrintStageInfo(CWB_STAGE_INIT,"cwb::InitNetwork from file");
822 
823  // read network object from job file
824  TFile* ifile = new TFile(fName);
825  if(ifile==NULL) {cout << "cwb::InitNetwork - Error opening root file : " << fName.Data() << endl;EXIT(1);}
826  network* pnet = (network*)ifile->Get("network");
827  if(pnet!=NULL) {
828  // copy network object into local NET object
829  NET = *pnet;
830  delete pnet;
831  } else {
832  cout << "cwb::InitNetwork - Error : net is not contained in root file " << fName.Data() << endl;
833  EXIT(1);
834  }
835  ifile->Close();
836  // save detector pointers into local structures pD
837  for(int n=0; n<nIFO; n++) pD[n] = NET.getifo(n);
838  // set the original sampling rate
839  for(int i=0; i<nIFO; i++) pD[i]->rate = cfg.fResample>0 ? cfg.fResample : cfg.inRate;
840 
841  // restore skymaps (to save space the network skymaps was not saved into job file)
842  if(cfg.healpix) NET.setSkyMaps(int(cfg.healpix));
844  NET.setAntenna();
845 
846  // restore network parameters
849  NET.Edge = cfg.segEdge;
850  NET.netCC = cfg.netCC;
851  NET.netRHO = cfg.netRHO;
852  NET.EFEC = cfg.EFEC;
854  NET.nSky = cfg.nSky;
856  NET.setRunID(runID);
858  NET.optim=cfg.optim;
860 
861  // restore sky mask
862  if(TString(cfg.analysis)=="1G") {
864  else if(cfg.mask<0 && strlen(cfg.skyMaskFile)>0)
865  SetSkyMask(&NET,&cfg,cfg.skyMaskFile,'e');
866  } else {
867  if(strlen(cfg.skyMaskFile)>0) SetSkyMask(&NET,&cfg,cfg.skyMaskFile,'e');
868  }
869  if(strlen(cfg.skyMaskCCFile)>0) SetSkyMask(&NET,&cfg,cfg.skyMaskCCFile,'c');
870 
871  // restore detector names defined in the network class
872  // there is a issue in network class (no TClass for char*)
873  // detectors names are not saved properly
874  NET.ifoName.clear();
875  for(int n=0; n<nIFO; n++) NET.ifoName.push_back(pD[n]->Name);
876 
877  // execute user plugin
878  if(bplugin) CWB_Plugin(NULL,&cfg,&NET,NULL,"",CWB_PLUGIN_NETWORK);
879 
880  // create injection (injected events) and netevent (reconstructed events) objects
881  mdc = new injection(nIFO);
882  netburst = new netevent(nIFO,cfg.Psave);
883 
884  // print system infos
885  gSystem->Exec("/bin/date");
886  gSystem->Exec("/bin/hostname");
887 
888  return;
889 }
890 
891 void
893 //
894 // Init the Network object :
895 //
896 // - create object & add detector objects to network
897 // - set network parameters : search type, regulators, thresholds, sky map grid resolution
898 // - set the user sky mask : enable/disable the sky map tiles (earth coordinates)
899 // - set the user celestial sky mask : enable/disable the sky map tiles (celestial coordinates)
900 //
901 
902  PrintStageInfo(CWB_STAGE_INIT,"cwb::InitNetwork");
903 
904  // ---------------------------------------
905  // Check single detector mode
906  // ---------------------------------------
907 
908  // if nIFO=1 the analysis is done as a network of 2 equal detectors
909  if(nIFO==1) {
910  // ------> cwb in Sigle Detector Mode !!!
912  nIFO = cfg.nIFO;
913  strcpy(ifo[1],ifo[0]);
914  singleDetector=true;
915  } else singleDetector=false;
916 
917  // ---------------------------------------
918  // init network
919  // ---------------------------------------
920 
921  // when ifo!="" check if user detectors defined in detParams has been initialized
922  for(int i=0; i<nIFO; i++) {
923  if(strlen(cfg.ifo[i])==0 && strlen(cfg.detParms[i].name)==0) {
924  cout << "cwb::InitNetwork - Error : user detector name at position "
925  << i << " is not defined (detParms)" << endl;
926  EXIT(1);
927  }
928  }
929 
930  // create detector objects
931  for(int i=0; i<nIFO; i++) {
932  if(strlen(cfg.ifo[i])>0) pD[i] = new detector(cfg.ifo[i]); // built in detector
933  else pD[i] = new detector(cfg.detParms[i]); // user define detector
934  }
935  // set the original sampling rate
936  for(int i=0; i<nIFO; i++) pD[i]->rate = cfg.fResample>0 ? cfg.fResample : cfg.inRate;
937  // add detector object to network
938  for(int i=0; i<nIFO; i++) NET.add(pD[i]);
939 
940  // set network skymaps
941  if(cfg.healpix) NET.setSkyMaps(int(cfg.healpix));
943  NET.setAntenna();
944 
945  // restore network parameters
948  NET.Edge = cfg.segEdge;
949  NET.netCC = cfg.netCC;
950  NET.netRHO = cfg.netRHO;
951  NET.EFEC = cfg.EFEC;
953  NET.nSky = cfg.nSky;
955  NET.setRunID(runID);
957  NET.optim=cfg.optim;
959 
960  // set sky mask
961  if(TString(cfg.analysis)=="1G") {
963  else if(cfg.mask<0 && strlen(cfg.skyMaskFile)>0)
964  SetSkyMask(&NET,&cfg,cfg.skyMaskFile,'e');
965  } else {
966  if(strlen(cfg.skyMaskFile)>0) SetSkyMask(&NET,&cfg,cfg.skyMaskFile,'e');
967  }
968  if(strlen(cfg.skyMaskCCFile)>0) SetSkyMask(&NET,&cfg,cfg.skyMaskCCFile,'c');
969 
970  // execute user plugin
971  if(bplugin) CWB_Plugin(NULL,&cfg,&NET,NULL,"",CWB_PLUGIN_NETWORK);
972 
973  // create injection (injected events) and netevent (reconstructed events) objects
974  mdc = new injection(nIFO);
975  netburst = new netevent(nIFO,cfg.Psave);
976 
977  // print system infos
978  gSystem->Exec("/bin/date");
979  gSystem->Exec("/bin/hostname");
980 
981  return;
982 }
983 
985 //
986 // Init History : it is used for bookkeping
987 //
988 // for each of these stages :
989 // (FULL,INIT,STRAIN,CSTRAIN,COHERENCE,SUPERCLUSTER,LIKELIHOOD)
990 // the following informations are saved
991 //
992 // CWB_ENV : cwb enviromental variable
993 // CWB_ENV_MD5 : the MD5 of the CWB_ENV string
994 // WATVERSION : WAT version
995 // XIFO : XIFO (max detectors's number)
996 // SVNVERSION : svn version
997 // SVNBRANCH : svn branch
998 // WORKDIR : working directory path
999 // FRLIBVERSION : framelib version
1000 // ROOTVERSION : ROOT version
1001 // LALVERSION : LAL version
1002 // DATALABEL : label used to tag the analysis
1003 // CMDLINE : command line used to start the job
1004 // ROOTLOGON : the cwb rootlogon.C
1005 // ROOTLOGON_MD5 : the MD5 of the ROOTLOGON_MD5 string
1006 // PARAMETERS : the user_parameters.C file
1007 // PARAMETERS_MD5 : the MD5 of the PARAMETERS_MD5 string
1008 // CWB_CONFIG_URL : cWB/config url
1009 // CWB_CONFIG_PATH : cWB/config path
1010 // CWB_CONFIG_BRANCH : cWB/config branch
1011 // CWB_CONFIG_TAG : cWB/config tag
1012 // CWB_CONFIG_HASH : cWB/config hash code
1013 // CWB_CONFIG_DIFF : cWB/config difference (modified)
1014 //
1015 
1016  PrintStageInfo(CWB_STAGE_INIT,"cwb::InitHistory");
1017 
1018  // check if configuration files exist
1019  TB.checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
1020 
1021  // declare stages
1022  const char* STAGE_NAMES[7] = {"FULL","INIT","STRAIN","CSTRAIN","COHERENCE","SUPERCLUSTER","LIKELIHOOD"};
1023  // declare types
1024  const char* TYPE_NAMES[22] = {"CWB_ENV","WATVERSION","XIFO","SVNVERSION","SVNBRANCH","WORKDIR",
1025  "FRLIBVERSION","ROOTVERSION","LALVERSION",
1026  "DATALABEL","CMDLINE","ROOTLOGON","PARAMETERS",
1027  "CWB_ENV_MD5","ROOTLOGON_MD5","PARAMETERS_MD5",
1028  "CWB_CONFIG_URL","CWB_CONFIG_PATH","CWB_CONFIG_BRANCH","CWB_CONFIG_TAG","CWB_CONFIG_HASH","CWB_CONFIG_DIFF"};
1029  // create history object
1030  history = new CWB::History(const_cast<char**>(STAGE_NAMES), 7, const_cast<char**>(TYPE_NAMES), 22);
1032 
1033  // If any, add history from previous processed stage
1034  if(iname!="") {
1035  TFile* ifile = new TFile(iname);
1036  if(ifile==NULL) {cout << "cwb::InitHistory - Error opening root file : " << iname.Data() << endl;EXIT(1);}
1037  // read network object
1038  if(ifile->Get("history")!=NULL) {
1039  // read history object
1040  CWB::History* hst = (CWB::History*)ifile->Get("history");
1041  TList* stageList = hst->GetStageNames();
1042  TList* typeList = hst->GetTypeNames();
1043  for(int i=0;i<stageList->GetSize();i++) {
1044  TObjString* stageString = (TObjString*)stageList->At(i);
1045  for(int j=0;j<typeList->GetSize();j++) {
1046  TObjString* typeString = (TObjString*)typeList->At(j);
1047  char* histData = hst->GetHistory(const_cast<char*>(stageString->GetString().Data()),
1048  const_cast<char*>(typeString->GetString().Data()));
1049  if(histData!=NULL) { // add previous history stage to current history
1050  history->AddHistory(const_cast<char*>(stageString->GetString().Data()),
1051  const_cast<char*>(typeString->GetString().Data()),histData);
1052  delete histData;
1053  }
1054  }
1055  }
1056  delete stageList;
1057  delete typeList;
1058  // read logs
1059  int log_size = hst->GetLogSize(const_cast<char*>("FULL"));
1060  for(int i=0;i<log_size;i++) {
1061  TString log = hst->GetLog(const_cast<char*>("FULL"),i);
1062  // Replace the final stage (STG:8) of the input job file with (STG:jstage)
1063  char stg_label[16];sprintf(stg_label,"STG:%d",jstage);
1064  if(log.Contains("STG:8")) log.ReplaceAll("STG:8",stg_label);
1065  // Add previous history logs to current history
1066  history->AddLog(const_cast<char*>("FULL"), const_cast<char*>(log.Data()));
1067  }
1068  delete hst;
1069  } else {
1070  cout << "cwb::InitHistory - Error : history is not contained in root file " << iname.Data() << endl;
1071  EXIT(1);
1072  }
1073  ifile->Close();
1074  }
1075 
1076  // add current history stage
1077  TString jStageString = GetStageString(jstage).ReplaceAll("CWB_STAGE_","");
1078  char jStage[256];sprintf(jStage,jStageString.Data());
1079 
1080  // get cwb enviromental variable and save to history
1081  char* cwbBuffer = TB.getEnvCWB();
1082  if(cwbBuffer!=NULL) {
1083  history->AddHistory(jStage, const_cast<char*>("CWB_ENV"), cwbBuffer);
1084  TMD5 md5;md5.Update((UChar_t*)cwbBuffer,strlen(cwbBuffer));md5.Final();
1085  history->AddHistory(jStage, const_cast<char*>("CWB_ENV_MD5"), const_cast<char*>(md5.AsString()));
1086  delete [] cwbBuffer;
1087  }
1088 
1089  // save library versions
1090  CWB::mdc MDC;
1091  char framelib_version[32]; sprintf(framelib_version,"%f",FRAMELIB_VERSION);
1092  history->AddHistory(jStage, const_cast<char*>("WATVERSION"), watversion('s'));
1093  history->AddHistory(jStage, const_cast<char*>("XIFO"), watversion('i'));
1094  history->AddHistory(jStage, const_cast<char*>("SVNVERSION"), watversion('r'));
1095  history->AddHistory(jStage, const_cast<char*>("SVNBRANCH"), watversion('b'));
1096  history->AddHistory(jStage, const_cast<char*>("FRLIBVERSION"), framelib_version);
1097  history->AddHistory(jStage, const_cast<char*>("ROOTVERSION"), const_cast<char*>(gROOT->GetVersion()));
1098  history->AddHistory(jStage, const_cast<char*>("LALVERSION"), const_cast<char*>(GetLALVersion().Data()));
1099 
1100  // save work directory and data label
1101  history->AddHistory(jStage, const_cast<char*>("WORKDIR"), cfg.work_dir);
1102  history->AddHistory(jStage, const_cast<char*>("DATALABEL"), cfg.data_label);
1103 
1104  // save command line used to start the application
1105  char cmd_line[2048]="";
1106  int cmd_line_len=0;
1107  for(int i=0;i<gApplication->Argc();i++) cmd_line_len+=strlen(gApplication->Argv(i));
1108  if(cmd_line_len>2047)
1109  {cout << "cwb::InitHistory - command line too long : " << cmd_line_len << endl;EXIT(1);}
1110  for(int i=0;i<gApplication->Argc();i++) sprintf(cmd_line,"%s %s",cmd_line,gApplication->Argv(i));
1111  history->AddHistory(jStage, const_cast<char*>("CMDLINE"), cmd_line);
1112 
1113  // save rootlogon script (ROOT initialization script)
1114  char* rootlogonBuffer = TB.readFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
1115  if(rootlogonBuffer!=NULL) {
1116  history->AddHistory(jStage, const_cast<char*>("ROOTLOGON"), rootlogonBuffer);
1117  TMD5 md5;md5.Update((UChar_t*)rootlogonBuffer,strlen(rootlogonBuffer));md5.Final();
1118  history->AddHistory(jStage, const_cast<char*>("ROOTLOGON_MD5"), const_cast<char*>(md5.AsString()));
1119  delete [] rootlogonBuffer;
1120  }
1121 
1122  // save git cWB/config infos
1123  history->AddHistory(jStage, const_cast<char*>("CWB_CONFIG_URL"), const_cast<char*>(GetGitInfos("url","$CWB_CONFIG").Data()));
1124  history->AddHistory(jStage, const_cast<char*>("CWB_CONFIG_PATH"), const_cast<char*>(GetGitInfos("path","$CWB_CONFIG").Data()));
1125  history->AddHistory(jStage, const_cast<char*>("CWB_CONFIG_BRANCH"), const_cast<char*>(GetGitInfos("branch","$CWB_CONFIG").Data()));
1126  history->AddHistory(jStage, const_cast<char*>("CWB_CONFIG_TAG"), const_cast<char*>(GetGitInfos("tag","$CWB_CONFIG").Data()));
1127  history->AddHistory(jStage, const_cast<char*>("CWB_CONFIG_HASH"), const_cast<char*>(GetGitInfos("hash","$CWB_CONFIG").Data()));
1128  history->AddHistory(jStage, const_cast<char*>("CWB_CONFIG_DIFF"), const_cast<char*>(GetGitInfos("diff","$CWB_CONFIG")!="" ? "M" : ""));
1129 
1130  // save configuration file
1131  char tmpFile[1024];
1132  unsigned int Pid = gSystem->GetPid(); // used to tag in a unique way the temporary files
1133  sprintf(tmpFile,"%s/CWB_Config_%s_%d_job%d.XXXXXX",cfg.nodedir,cfg.data_label,Pid,this->runID);
1134  if(mkstemp(tmpFile)==-1) { // create temporary file
1135  cout << "cwb::InitHistory - mkstemp error in creating tmp file : " << tmpFile << endl;
1136  EXIT(1);
1137  }
1138  char nodedir[1024];strcpy(nodedir,cfg.nodedir); // clean nodedir before dump to history
1139  strcpy(cfg.nodedir,""); // this makes config the same for all jobs
1140  TString tempTitle = cfg.configPlugin.GetTitle(); // save temporary macro title
1141  // get original macro title
1142  TObjString* objt = cfg.configPlugin.GetLineWith("//#?CONFIG_PLUGIN_TITLE ");
1143  TString origTitle = objt ? objt->GetString() : "";
1144  cfg.configPlugin.SetTitle(origTitle.ReplaceAll("//#?CONFIG_PLUGIN_TITLE ",""));
1145  cfg.Print(tmpFile); // write config to temporary file
1146  cfg.configPlugin.SetTitle(tempTitle); // restore temporary macro title
1147  strcpy(cfg.nodedir,nodedir); // restore nodedir
1148  char* parametersBuffer = TB.readFile(tmpFile); // read config from tmp file
1149  gSystem->Exec((TString("/bin/rm ")+TString(tmpFile)).Data()); // delete temporary file
1150  if(parametersBuffer!=NULL) {
1151  history->AddHistory(jStage, const_cast<char*>("PARAMETERS"), parametersBuffer);
1152  TMD5 md5;md5.Update((UChar_t*)parametersBuffer,strlen(parametersBuffer));md5.Final();
1153  history->AddHistory(jStage, const_cast<char*>("PARAMETERS_MD5"), const_cast<char*>(md5.AsString()));
1154  delete [] parametersBuffer;
1155  }
1156 
1157  // save START JOB to Log history
1158  history->AddLog(const_cast<char*>("FULL"), const_cast<char*>("START JOB"));
1159 
1160  return;
1161 }
1162 
1164 //
1165 // Init the Job
1166 //
1167 // read the Job configuration parameters from the job file (the previous processed stage)
1168 //
1169 
1170  PrintStageInfo(CWB_STAGE_INIT,"cwb::InitJob from file");
1171 
1172  double mdcShift=0.;
1173 
1174  // read cwb object from job file
1175  TFile* ifile = new TFile(fName);
1176  if(ifile==NULL||!ifile->IsOpen())
1177  {cout << "cwb::InitJob - Error opening root file : " << fName.Data() << endl;EXIT(1);}
1178  ifile->cd();
1179  cwb* CWB = (cwb*)ifile->Get("cwb");
1180  if(CWB==NULL) {
1181  cout << "cwb::InitJob - Error : cwb is not contained in root file " << fName.Data() << endl;
1182  EXIT(1);
1183  }
1184 
1185  // restore cwb segment parameters from saved cwb object
1186  jobID = CWB->jobID;
1187  Tb = CWB->Tb;
1188  dT = CWB->dT;
1189  Te = CWB->Te;
1190  slagID = CWB->slagID;
1191  for(int n=0;n<=(int)NET.ifoListSize();n++) segID[n]=CWB->segID[n]; // restore segID
1192  for(int n=0;n<=(int)NET.ifoListSize();n++) slagShift[n]=CWB->slagShift[n]; // restore slags
1193  netburst->setSLags(slagShift); // set slags into netevent
1194  ifile->Close();
1195 
1196  // restore TFmap start,rate (size=0) , needed by likelihood to get the initial segment time
1197  for(int n=0;n<(int)NET.ifoListSize();n++) {
1199  NET.getifo(n)->getTFmap()->rate(rateANA);
1200  }
1201 
1202  // set a fake TFmap for the first detector, needed to restore setTimeShifts
1203  if(TString(cfg.analysis)=="2G" && jstage==CWB_STAGE_LIKELIHOOD) {
1204  NET.getifo(0)->getTFmap()->resize(rateANA*(dT+2*cfg.segEdge));
1205  for(int n=0;n<NET.ifoListSize();n++) { // used for ced
1206  NET.getifo(n)->getTFmap()->setlow(cfg.fLow);
1208  }
1209  }
1210 
1211  // init simulation structures for simulation=4
1212  if(cfg.simulation==4) { // initialize array factors
1213  // for simulation=4 factors are used as tags for the output root files
1214  if(fmod(cfg.factors[0],1)) { // must be integer
1215  cout<<"cwb::InitJob : when simulation=4 factors[0] is the offset and must be integer>=0"<<endl;
1216  EXIT(1);
1217  }
1218  if(cfg.factors[0]<0) {
1219  cout<<"cwb::InitJob : when simulation=4 factors[0] is the offset and must be integer>=0"<<endl;
1220  EXIT(1);
1221  }
1222  if(int(cfg.factors[0])<=0) cfg.factors[0]=1; // set 1 if <=0
1223  int ioffset = int(cfg.factors[0]); // extract offset
1224  for(int i=ioffset;i<ioffset+cfg.nfactor;i++) cfg.factors[i]=i; // assign integer values
1225  }
1226 
1227  return mdcShift;
1228 }
1229 
1230 double cwb::InitJob() {
1231 //
1232 // Init the Job structures
1233 //
1234 // Selection of the period to be analyzed by this job (job segment)
1235 // - Read the data quality segment (DQ) files (CAT 0/1/2/4) : CWB::config::DFQ
1236 // CAT 0/1/4 are used to define where the data can be analyzed
1237 // CAT 2 are used to veto bad periods
1238 //
1239 // The job segment is computed according to the segment parameters : CWB::config::segXXX, CWB::config::slagXXX
1240 // Each job segment includes at beginning and at the end a scratch period which length is : CWB::config::segEdge
1241 // There are 2 types of procedures used to select the job segment :
1242 // - 1) the circular time-shifts (LAG) are performed within non shifted detector segments (same as 1G)
1243 // the length of the job segment is optimized to get the maximum livetime.
1244 // The minimum segment len is : CWB::config::segMLS , the maximum segment length is CWB::config::segLen
1245 // - 2) the circular time-shifts (LAG) are performed within shifted detector segments (SLAG)
1246 // all job segments have the same length : CWB::config::segLen
1247 //
1248 // Initialization of frame file structures
1249 // - Read noise/MDC frame lists
1250 // noise/MDC can be read from files or from the plugin (generated 'On The Fly')
1251 // - Read MDC log file (only for simulation)
1252 // Is the list of the injection parameters (inj time, hrss, source location, ...)
1253 //
1254 
1255  PrintStageInfo(CWB_STAGE_INIT,"cwb::InitJob");
1256 
1257  double mdcShift=0.;
1258 
1259  vector<TString> ifos(nIFO);
1260  for(int n=0;n<nIFO;n++) ifos[n]=ifo[n];
1261 
1262  if((cfg.simulation)&&((cfg.slagSize>1)||(cfg.lagSize!=1))) {
1263  cout << "Error : slagSize<=1 & lagSize==1 in simulation mode !!!" << endl;EXIT(1);
1264  }
1265 
1266  // -----------------------------------------------------------------------
1267  // init cat1 segments
1268  //
1269  // job segments are computed using as segEdge the value segEdge+segOverlap
1270  // NB! it is used only to compute the job segments
1271  //
1272  // |x| = segEdge : |+| = segOverlap : |-| = segLen
1273  //
1274  // |xxx|-------------------|++++++|xxx|
1275  // |xxx|-------------------|++++++|xxx|
1276  // -----------------------------------------------------------------------
1277 
1278  if(cfg.slagSize>0) { // SLAG Segments
1279 
1280  cout << endl << "START SLAG Init ..." << endl << endl;
1281 
1282  // Get zero lag merged dq cat0 & cat1 lists
1283  // The cat1List list is used only for slagSegs && slagJobList
1285 
1286  // Get number/list of available super lag jobs
1287  // Compute the available segments with length=segLen contained between the interval [min,max]
1288  // Where min,max are the minimum and macimum times in the cat1List list
1289  // The start time of each segment is forced to be a multiple of segLen
1290  vector<waveSegment> slagJobList=TB.getSlagJobList(cat1List, int(cfg.segLen));
1291  int slagSegs=slagJobList.size();
1292 
1293  // Get super lag list : slagList
1294  // Is the list of available segment shifts according to the slag configuration parameters
1295  vector<slag> slagList=TB.getSlagList(nIFO, cfg.slagSize, slagSegs, cfg.slagOff,
1297 
1298  // Extract SLAG from the the slagList according the input runID
1299  slag SLAG=TB.getSlag(slagList,runID);
1300  if(SLAG.jobId!=runID) {cout << "jobID " << runID << " not found in the slag list !!!" << endl;EXIT(1);}
1301  slagID = SLAG.slagId[0]; // slag identification number
1302  jobID = SLAG.jobId; // for slag -> jobID=runID
1303  for(int n=0; n<nIFO; n++) segID[n]=SLAG.segId[n]; // segment shifts
1304  cout << "SuperLag=" << slagID << " jobID=" << jobID;
1305  for(int n=0; n<nIFO; n++) cout << " segID[" << ifo[n] << "]=" << segID[n];cout << endl;
1306 
1307  // Apply slag shifts to the DQF structures (data quality)
1308  for(int n=0;n<nIFO;n++) ifos[n]=ifo[n];
1309  TB.setSlagShifts(SLAG, ifos, cfg.segLen, cfg.nDQF, cfg.DQF);
1310 
1311  // Get merged dq cat0 & cat1 lists after slag shifts
1313 
1314  // Extract ifo's slag segments ranges contained in the selected slag
1315  // Extract max length segment after the application of cat0+cat1
1316  // Final segment length must be gt [cfg.segMLS+2*(cfg.segEdge+cfg.segOverlap)] & gt [cfg.segMLS]
1318  cout << endl;
1319  cout << endl << "Segment type = SLAG" << endl;
1320 
1321  cout << endl << "END SLAG Init ..." << endl << endl;
1322 
1323  } else { // Segments are not shifted (standard shifts)
1324 
1325  jobID = runID;
1326  slagID = 0;
1327  for(int n=0;n<nIFO;n++) segID[n]=0;
1328 
1329  // Get merged dq cat0 & cat1 lists
1331 
1332  // Extract ifo's slag segments ranges
1333  // Extract max length segment after the application of cat0+cat1
1334  // Final segment length must be gt [cfg.segMLS+2*(cfg.segEdge+cfg.segOverlap)] & gt [cfg.segMLS]
1336  cout << endl;
1337  cout << "Segment type = LAG" << endl;
1338  }
1339  cout << "segLen = " << cfg.segLen << " sec" << endl;
1340  cout << "segMLS = " << cfg.segMLS << " sec" << endl;
1341  cout << "segOverlap = " << cfg.segOverlap << " sec" << endl;
1342  cout << endl;
1343 
1344  // set slags in to the netevent class
1345  for(int n=0; n<nIFO; n++) slagShift[n]=(segID[n]-segID[0])*cfg.segLen;
1346  slagShift[nIFO]=slagID;
1347  netburst->setSLags(slagShift);
1348 
1349  // Check if seg length is compatible with WDM parity (only for 2G)
1350  // This condition is necessary to avoid mixing between odd
1351  // and even pixels when circular buffer is used for lag shift
1352  // The MRAcatalog distinguish odd and even pixels
1353  // If not compatible then the length is modified according the requirements
1354  if(TString(cfg.analysis)=="2G") {
1355  int rate_min = rateANA>>cfg.l_high;
1356  for(int i=0;i<(int)detSegs.size();i++) {
1357  double length = detSegs[i].stop - detSegs[i].start;
1358  if(int(length*rate_min+0.001)&1) detSegs[i].stop-=1;
1359  }
1360  }
1361 
1362  // add segOverlap to the detector's segments stop for this job
1363  for(int i=0;i<nIFO;i++) detSegs[i].stop+=cfg.segOverlap;
1364  // print detector's segments for this job
1365  cout.precision(14);
1366  for(int i=0;i<nIFO;i++) {
1367  cout << "detSegs_dq1[" << ifo[i] << "] GPS range : "
1368  << detSegs[i].start << "-" << detSegs[i].stop << endl;
1369  }
1370  cout << endl;
1371  if(detSegs.size()==0) {cout << "no segments found for this job, job terminated !!!" << endl;EXIT(1);}
1372 
1373  // --------------------------------------------------------------------------
1374  // Fill Frame Files structures (FRF)
1375  // if (dataPlugin=false) noise data is read from frame files else from plugin
1376  // if (mdcPlugin=false) mdc data is read from frame files else from plugin
1377  // --------------------------------------------------------------------------
1378 
1379  // init FRF structures for noise data
1380  for(int n=0; n<nIFO; n++) {
1381  if(!cfg.dataPlugin) { // noise data from frames
1382  if(TString(cfg.frFiles[n])=="") {
1383  cout << "cwb::InitJob - Error : noise frame files list name is not defined" << endl;
1384  EXIT(1);
1385  }
1387  detSegs[n].stop -cfg.dataShift[n]+2*cfg.segEdge);
1388  fr[n].open(cfg.frFiles[n]); // read frame files list
1389  fr[n].setVerbose();
1391  fr[n].setSRIndex(TMath::Nint(TMath::Log2(cfg.inRate))); // force data to be resampled to inRate
1392  nfrFiles[n]=fr[n].getNfiles(); // number of frame files used for this job
1393  cout << ifo[n] << " -> nfrFiles : " << nfrFiles[n] << endl;
1394  FRF[n] = fr[n].getFrList(int(detSegs[n].start-cfg.dataShift[n]),
1395  int(detSegs[n].stop-cfg.dataShift[n]), int(cfg.segEdge));
1396  } else { // noise data from the user plugin
1399  FRF[n].length = FRF[n].stop-FRF[n].start;
1400  }
1401  }
1402 
1403  // init FRF structures for mdc data
1404  if(cfg.simulation) {
1405  for(int n=nIFO; n<2*nIFO; n++) {
1406  // mdc are declared in the array frFiles[nIFO,2*nIFO-1]
1407  // or within a single frame file frFiles[nIFO]
1408  // in such case the frFiles[nIFO+1,2*nIFO-1] are a copy of frFiles[nIFO]
1409  if(TString(cfg.frFiles[n])=="" && n>nIFO) {FRF[n]=FRF[nIFO];continue;}
1410  if(!cfg.mdcPlugin) { // mdc from frames
1411  // set frame file list
1412  if(TString(cfg.frFiles[n])=="") {
1413  cout << "cwb::InitJob - Error : MDC frame files list name is not defined" << endl;
1414  EXIT(1);
1415  }
1416  if(cfg.mdc_shift.startMDC>=0) { // cfg.mdc_shift.startMDC<0 -> automatically mdc time shift
1417  fr[n].setTimeRange(detSegs[n-nIFO].start-2*cfg.segEdge,detSegs[n-nIFO].stop+2*cfg.segEdge);
1418  }
1419  fr[n].open(cfg.frFiles[n]);
1420  fr[n].setVerbose();
1422  fr[n].setSRIndex(TMath::Nint(TMath::Log2(cfg.inRate))); // force data to be resampled to inRate
1423  nfrFiles[n]=fr[n].getNfiles();
1424  cout << "MDC " << " -> nfrFiles : " << nfrFiles[n] << endl;
1425  if(cfg.mdc_shift.startMDC<0) { // the mdc shift is automatically selected
1426  // read mdc range from mdc frl files
1427  waveSegment mdc_range = fr[n].getFrRange();
1428  cout << "mdc_range : " << mdc_range.start << " " << mdc_range.stop << endl;
1429  cfg.mdc_shift.startMDC=mdc_range.start;
1430  cfg.mdc_shift.stopMDC=mdc_range.stop;
1431  }
1432  mdcShift = TB.getMDCShift(cfg.mdc_shift, detSegs[n-nIFO].start);
1433  cout << "mdcShift : " << mdcShift << endl;
1434  FRF[n] = fr[n].getFrList(int(detSegs[n-nIFO].start-mdcShift),
1435  int(detSegs[n-nIFO].stop-mdcShift), int(cfg.segEdge));
1436  } else { // mdc from user plugin
1437  FRF[n]=FRF[n-nIFO];
1438  }
1439  }
1440 
1441  // init simulation structures for simulation=4
1442  if(cfg.simulation==4) { // initialize array factors
1443  // for simulation=4 factors are used as tags for the output root files
1444  if(fmod(cfg.factors[0],1)) { // must be integer
1445  cout<<"cwb::InitJob : when simulation=4 factors[0] is the offset and must be integer>=0"<<endl;
1446  EXIT(1);
1447  }
1448  if(cfg.factors[0]<0) {
1449  cout<<"cwb::InitJob : when simulation=4 factors[0] is the offset and must be integer>=0"<<endl;
1450  EXIT(1);
1451  }
1452  if(int(cfg.factors[0])<=0) cfg.factors[0]=1; // set 1 if <=0
1453  int ioffset = int(cfg.factors[0]); // extract offset
1454  for(int i=ioffset;i<ioffset+cfg.nfactor;i++) cfg.factors[i]=i; // assign integer values
1455  }
1456  }
1457 
1458  // ------------------------------
1459  // init cat2 segments
1460  // ------------------------------
1461 
1462  // get shifted merged dq cat0+cat1+cat2 list
1464  // store cat2List into network class
1466 
1467  // check if seg+cat2 data length is >= segTHR
1468  vector<waveSegment> detSegs_dq2;
1469  detSegs_dq2.push_back(detSegs[0]);
1470  detSegs_dq2 = TB.mergeSegLists(detSegs_dq2,cat2List);
1471  for(int i=0;i<(int)detSegs_dq2.size();i++) {
1472  cout << "detSegs_dq2[" << i << "] GPS range : "
1473  << detSegs_dq2[i].start << "-" << detSegs_dq2[i].stop << endl;
1474  }
1475  cout << endl;
1476  double detSegs_ctime = TB.getTimeSegList(detSegs_dq2);
1477  cout << "live time after cat 2 : " << detSegs_ctime << " sec" << endl;
1478  if(detSegs_ctime<cfg.segTHR) {
1479  cout << "cwb::InitJob : job segment live time after cat2 < segTHR="
1480  << cfg.segTHR << " sec, job terminated !!!" << endl;
1481  cout << endl << "To remove this check set segTHR=0 in the parameter file" << endl << endl;
1482  EXIT(1);
1483  }
1484 
1485  Tb=detSegs[0].start; // start seg time (excluded segEdge)
1486  Te=detSegs[0].stop; // stop seg time (excluded segEdge)
1487  dT = Te-Tb; // length seg time (excluded segEdge)
1488 
1489  // --------------------------------------------------------------------------------
1490  // read input mdc log file when data loaded from frame files (cfg.mdcPlugin==false)
1491  // --------------------------------------------------------------------------------
1492  if(cfg.simulation && !cfg.mdcPlugin) { // read MDC log file
1493  int i=NET.readMDClog(cfg.injectionList,double(long(Tb))-mdcShift);
1494  printf("GPS: %16.6f saved, injections: %d\n",double(long(Tb)),i);
1495  if(!cfg.mdcPlugin) TB.shiftBurstMDCLog(NET.mdcList, ifos, mdcShift);
1496  for(int i=0;i<(int)NET.mdcTime.size();i++) NET.mdcTime[i]+=mdcShift;
1497 
1498  // check if seg+cat2+inj data length is not zero
1499  vector<waveSegment> mdcSegs(NET.mdcTime.size());
1500  for(int k=0;k<(int)NET.mdcTime.size();k++) {
1501  mdcSegs[k].start=NET.mdcTime[k]-cfg.iwindow/2.;
1502  mdcSegs[k].stop=NET.mdcTime[k]+cfg.iwindow/2.;
1503  }
1504  vector<waveSegment> mdcSegs_dq2 = TB.mergeSegLists(detSegs_dq2,mdcSegs);
1505  double mdcSegs_ctime = TB.getTimeSegList(mdcSegs_dq2);
1506  cout << "live time in zero lag after cat2+inj : " << mdcSegs_ctime << endl;
1507  if(mdcSegs_ctime==0) {
1508  cout << "cwb::InitJob : job segment with zero cat2+inj "
1509  << "live time in zero lag, job terminated !!!" << endl;
1510  cout << "Warning : MDC data frames could be zero !!!" << endl;
1511  EXIT(1);
1512  }
1513  }
1514 
1515  // ------------------------------------------------------------
1516  // store the contents of the user lagFile to string (lagBuffer)
1517  // (used in multistages analysis to restore lags)
1518  // ------------------------------------------------------------
1519  lagBuffer.Set(0);
1520  lagMode[0]=cfg.lagMode[0];lagMode[1]=0;
1521  if(!cfg.simulation && cfg.lagFile!=NULL) {
1522  if(TString(cfg.lagMode)=="r") { // read lags from file
1523  ifstream in;
1524  in.open(cfg.lagFile, ios::in);
1525  if(!in.good()) {
1526  cout << "cwb::InitJob : Error Opening File : " << cfg.lagFile << endl;
1527  EXIT(1);
1528  }
1529  // get length of file:
1530  in.seekg (0, in.end);
1531  int len = in.tellg();
1532  in.seekg (0, in.beg);
1533  lagBuffer.Set(len);
1534  in.read(lagBuffer.GetArray(),len);// store the contents of the file into the lagBuffer
1535  lagMode[0]='s';lagMode[1]=0; // change lagMode : setTimeShifts read lags from string
1536  if(!in) {
1537  cout << "cwb::InitJob : Error Reading File : " << cfg.lagFile << endl;
1538  EXIT(1);
1539  }
1540  in.close();
1541  // set end of string
1542  lagBuffer.Set(lagBuffer.GetSize()+1);
1543  lagBuffer[lagBuffer.GetSize()-1]=0;
1544  } else { // write lags to file
1545  lagBuffer.Set(strlen(cfg.lagFile),cfg.lagFile);
1546  lagMode[0]='w';lagMode[1]=0;
1547  }
1548  }
1549 
1550  // execute user plugin
1551  if(bplugin) {
1552  wavearray<double> x; // temporary time series
1553  for(int i=0; i<nIFO; i++) {
1554  x.rate(cfg.inRate); x.start(FRF[i].start); x.resize(int(x.rate()*(FRF[i].stop-FRF[i].start)));
1556  }
1557  x.resize(0);
1558  }
1559 
1560  return mdcShift;
1561 }
1562 
1563 double
1565 //
1566 // Read unconditioned Noise/MDC from input job file (the previous processed stage)
1567 // Data are saved into current job file
1568 //
1569 
1570  PrintStageInfo(CWB_STAGE_STRAIN,"cwb::ReadData from file");
1571 
1572  // open in update mode the current job file (jfile)
1573  jfile = new TFile(jname,"UPDATE");
1574  if(jfile==NULL||!jfile->IsOpen())
1575  {cout << "cwb::ReadData - Error opening root file : " << jname << endl;EXIT(1);}
1576  TDirectory* cdstrain = (TDirectory*)jfile->Get("strain");
1577  if(cdstrain==NULL) cdstrain = jfile->mkdir("strain");
1578 
1579  // read unconditioned Noise/MDC from input job file (ifile)
1580  // write unconditioned Noise/MDC to current job file (jfile)
1581  TFile* ifile = new TFile(fName);
1582  if(ifile==NULL) {cout << "cwb::ReadData - Error opening root file : " << fName << endl;EXIT(1);}
1583 
1584  WSeries<double>* pws=NULL;
1585  for(int i=0; i<nIFO; i++) {
1586  ifile->cd();
1587  // read strain from ifile
1588  pws = (WSeries<double>*)ifile->Get(TString("strain/")+pD[i]->Name);
1589  if(pws==NULL)
1590  {cout << "cwb::ReadData - Error : data not present in file : " << fName << endl;EXIT(1);}
1591  // write strain to jfile
1592  pTF[i] = pD[i]->getTFmap();
1593  cdstrain->cd();pws->Write(ifo[i]);
1594  if(cfg.simulation) {
1595  ifile->cd();
1596  // read mdc from ifile
1597  pws = (WSeries<double>*)ifile->Get(TString("mdc/")+ifo[i]);
1598  if(pws==NULL)
1599  {cout << "cwb::ReadData - Error : mdc not present in file : " << fName << endl;EXIT(1);}
1600  // write mdc to jfile
1601  TDirectory* cdmdc = (TDirectory*)jfile->Get("mdc");
1602  if(cdmdc==NULL) cdmdc = jfile->mkdir("mdc");
1603  cdmdc->cd();pws->Write(ifo[i]);
1604  }
1605  if(singleDetector) break;
1606  }
1607 
1608  // close ifile/jfile
1609  ifile->Close();
1610  jfile->Close();
1611  return pws->rate();
1612 }
1613 
1614 void
1616 //
1617 // Read conditioned/whitened Noise/MDC from input job file (the previous processed stage)
1618 // Data are saved into current job file
1619 //
1620 
1621  PrintStageInfo(CWB_STAGE_CSTRAIN,"cwb::DataConditioning from file");
1622 
1623  char cdcstrain_name[32];sprintf(cdcstrain_name,"cstrain-f%d",ifactor);
1624 
1625  // open in update mode the current job file (jfile)
1626  jfile=NULL;
1627  TDirectory* jcdcstrain = NULL;
1629  jfile = new TFile(jname,"UPDATE");
1630  if(jfile==NULL||!jfile->IsOpen())
1631  {cout << "cwb::DataConditioning - Error opening root file : " << jname << endl;EXIT(1);}
1632  jcdcstrain=jfile->mkdir(cdcstrain_name);
1633  }
1634 
1635  // read conditioned data from input job file (ifile)
1636  // write conditioned data to current job file (jfile)
1637  TFile* ifile = new TFile(fName);
1638  if(ifile==NULL)
1639  {cout << "cwb::DataConditioning - Error opening root file : " << fName << endl;EXIT(1);}
1640 
1641  WSeries<double>* pws=NULL;
1642  for(int i=0; i<nIFO; i++) {
1643  ifile->cd();
1644  // read whitened data from ifile
1645  pws = (WSeries<double>*)ifile->Get(TString(cdcstrain_name)+TString("/")+pD[i]->Name);
1646  if(pws==NULL)
1647  {cout << "cwb::DataConditioning - Error : data not present, job terminated!!!" << endl;EXIT(1);}
1648  // write whitened data to jfile
1649  if(jfile!=NULL) {jfile->cd();jcdcstrain->cd();pws->Write(ifo[i]);}
1650  pTF[i] = pD[i]->getTFmap();
1651  *pTF[i]=*pws;
1652  delete pws;
1653  if(singleDetector) break;
1654  }
1655 
1656  // close ifile/jfile
1657  if(jfile!=NULL) jfile->Close();
1658  ifile->Close();
1659  return;
1660 }
1661 
1662 void
1664 //
1665 // Base class virtual Coherence method
1666 // It is implemented in cwb1G/cwb2G
1667 //
1668 
1669  PrintStageInfo(CWB_STAGE_COHERENCE,"cwb::Coherence from file");
1670 
1671  return;
1672 }
1673 
1674 void
1676 //
1677 // Base class virtual SuperCluster method
1678 // It is implemented in cwb1G/cwb2G
1679 //
1680 
1681  PrintStageInfo(CWB_STAGE_SUPERCLUSTER,"cwb::SuperCluster from file");
1682 
1683  return;
1684 }
1685 
1686 void
1687 cwb::PrintAnalysis(bool stageInfos) {
1688 //
1689 // Print Analysis Setup
1690 // input : stageInfos : if true stage infos are printed
1691 //
1692 // output format (Example) :
1693 //
1694 // jobID : 1
1695 //
1696 // Analysis : 2G
1697 // stage : CSTRAIN
1698 //
1699 // detectors : L1 H1 V1
1700 // search : un-modeled(r)-MRA-Standard
1701 // simulation : 2
1702 // maximum time delay between detectors : 0.0264483
1703 // maximum time delay difference : 0.0264483
1704 // HEALPix order : 7
1705 // levelR, rateANA, fLow, fHigh : 4, 1024, 32, 512
1706 // bpp, Acore : 0.001, 1.5
1707 // netRHO and netCC : 5, 0.5
1708 // clustering TFgap, Tgap, Fgap : 6.0, 0.0, 0.0
1709 // pattern : 0
1710 // subnetcut subnet, subcut : 0.6, 0.33
1711 // regulator delta, gamma : 0.05, 0.5
1712 // precision csize, order : 50, 5
1713 //
1714 
1715  if(stageInfos) PrintStageInfo(CWB_STAGE_INIT,"cwb::PrintAnalysis");
1716 
1717  cout << " jobID : " << runID << endl;
1718  cout << endl;
1719  cout << " Analysis : " << cfg.analysis << endl;
1720  cout << " stage : ";
1721  if(TString(cfg.analysis)=="1G") cout << "FULL" << endl;
1722  else { // 2G
1723  if(jstage==CWB_STAGE_FULL) cout << "FULL" << endl;
1724  if(jstage==CWB_STAGE_INIT) cout << "INIT" << endl;
1725  if(jstage==CWB_STAGE_STRAIN) cout << "STRAIN" << endl;
1726  if(jstage==CWB_STAGE_CSTRAIN) cout << "CSTRAIN" << endl;
1727  if(jstage==CWB_STAGE_COHERENCE) cout << "COHERENCE" << endl;
1728  if(jstage==CWB_STAGE_SUPERCLUSTER) cout << "SUPERCLUSTER" << endl;
1729  if(jstage==CWB_STAGE_LIKELIHOOD) cout << "LIKELIHOOD" << endl;
1730  }
1731 
1732  cout << "\n detectors : ";
1733  for(int i=0; i<cfg.nIFO; i++) cout<<ifo[i]<<" ";
1734  cout<<endl;
1735 
1736  cout << " search : ";
1737  if(TString(cfg.analysis)=="1G") {
1738  if(cfg.search=='E' || cfg.search=='E') cout<<"un-modeled (Energy)";
1739  if(cfg.search=='b' || cfg.search=='B') cout<<"un-modeled (single stream)";
1740  if(cfg.search=='r' || cfg.search=='R') cout<<"un-modeled (dual stream)";
1741  if(cfg.search=='i' || cfg.search=='I') cout<<"elliptical polarisation";
1742  if(cfg.search=='g' || cfg.search=='G') cout<<"circular polarisation";
1743  if(cfg.search=='s' || cfg.search=='S') cout<<"linear polarisation";
1744  cout << "(" << cfg.search << ")" << endl;
1745  } else if(TString(cfg.analysis)=="2G") {
1746  char _search = std::tolower(cfg.search);
1747  if(_search=='r') cout<<"un-modeled";
1748  if(_search=='i') cout<<"iota-wave";
1749  if(_search=='p') cout<<"psi-wave";
1750  if(_search=='l' || _search=='s') cout<<"linear polarisation";
1751  if(_search=='c' || _search=='g') cout<<"circular polarisation";
1752  if(_search=='e' || _search=='b') cout<<"elliptical polarisation";
1753  cout << "(" << cfg.search << ")";
1754  if(cfg.optim) cout<<"-SRA";
1755  else cout<<"-MRA";
1756  if(cfg.pattern==0) cout<<"-Standard";
1757  if((cfg.pattern!=0 && cfg.pattern<0)) cout<<"-Mixed";
1758  if((cfg.pattern!=0 && cfg.pattern>0)) cout<<"-Packet";
1759  cout << endl;
1760  } else {
1761  cout<<"\n unavailable analysis type !!!"<<endl;EXIT(1);
1762  }
1763  cout << " simulation : " << cfg.simulation << endl;;
1764 
1765  mTau=NET.getDelay(const_cast<char*>("MAX")); // maximum time delay
1766  dTau=NET.getDelay(const_cast<char*>("")); // time delay difference
1767  cout<<"maximum time delay between detectors : "<<mTau<<endl;
1768  cout<<" maximum time delay difference : "<<dTau<<endl;
1769  if(cfg.healpix) {
1770  cout<<" HEALPix order : "<<cfg.healpix<<endl;
1771  } else {
1772  cout<<" skymap angular resolution : "<<cfg.angle<<endl;
1773  cout<<" skymap size in polar angle : "<<cfg.Theta1<<", "<<cfg.Theta2<<endl;
1774  cout<<" skymap size in azimuthal angle : "<<cfg.Phi1<<", "<<cfg.Phi2<<endl;
1775  }
1776  cout<<" levelR, rateANA, fLow, fHigh : "<<cfg.levelR<<", "<<rateANA<<", "
1777  <<cfg.fLow<<", "<<cfg.fHigh<<endl;
1778  cout<<" bpp, Acore : "<<cfg.bpp<<", "<<cfg.Acore<<endl;
1779  cout<<" netRHO and netCC : "<<cfg.netRHO<<", "<<cfg.netCC<<endl;
1780  if(TString(cfg.analysis)=="1G") {
1781  cout<<" regulator delta, gamma : "<<cfg.delta<<", "<<NET.gamma<<endl;
1782  } else { // 2G
1783  cout<<" clustering TFgap, Tgap, Fgap : "<<cfg.TFgap<<", "<<cfg.Tgap<<", "<<cfg.Fgap<<endl;
1784 
1785  cout<<" pattern : "<<cfg.pattern<<" -> ";
1786  int pattern = abs(cfg.pattern);
1787  if(pattern== 0) cout<<"('*' single pixel standard)"<<endl;
1788  if(pattern== 1) cout<<"('3|' packet)"<<endl;
1789  if(pattern== 2) cout<<"('3-' packet)"<<endl;
1790  if(pattern== 3) cout<<"('3/' packet - chirp)"<<endl;
1791  if(pattern== 4) cout<<"('3\\' packet - ringdown)"<<endl;
1792  if(pattern== 5) cout<<"('5/' packet - chirp)"<<endl;
1793  if(pattern== 6) cout<<"('5\\' packet - ringdown)"<<endl;
1794  if(pattern== 7) cout<<"('3+' packet)"<<endl;
1795  if(pattern== 8) cout<<"('3x' cross packet)"<<endl;
1796  if(pattern== 9) cout<<"('9p' 9-pixel square packet)"<<endl;
1797  if(pattern > 9) cout<<"('*' single pixel packet)"<<endl;
1798 
1799  cout<<" regulator subnet, subcut : "<<cfg.subnet<<", "<<cfg.subcut<<endl;
1800  cout<<" regulator delta, gamma : "<<cfg.delta<<", "<<NET.gamma<<endl;
1801  }
1802  if(cfg.precision!=0) {
1803  int precision = int(fabs(cfg.precision));
1804  int csize = precision%65536; // get number of pixels threshold per level
1805  int order = (precision-csize)/65536; // get resampled order
1806  cout<<" precision csize, order : "<<csize<<", "<<order<<endl;
1807  }
1808  if((TString(cfg.analysis)=="1G")&&(cfg.mask>0.)) {
1809  cout<<" earth sky mask applied ; "<<cfg.skyMaskFile<<endl;
1810  cout<<" mask ; "<<cfg.mask<<endl;
1811  }
1812  if((TString(cfg.analysis)=="1G")&&(cfg.mask<0.)&&(strlen(cfg.skyMaskFile)>0))
1813  cout<<" earth sky mask applied ; "<<cfg.skyMaskFile<<endl;
1814  if((TString(cfg.analysis)=="2G")&&(strlen(cfg.skyMaskFile)>0))
1815  cout<<" earth sky mask applied ; "<<cfg.skyMaskFile<<endl;
1816  if(strlen(cfg.skyMaskCCFile)>0)
1817  cout<<" celestial sky mask applied ; "<<cfg.skyMaskCCFile<<endl;
1818  cout<<endl;
1819 
1820  // print ifo infos
1821  //cout << " nIFO : " << nIFO << endl;
1822  //NET.print();
1823  //for(int n=0; n<nIFO; n++) pD[n]->print();
1824 
1825  return;
1826 }
1827 
1828 size_t
1829 cwb::GetProcInfo(bool mvirtual) {
1830 //
1831 // Print to screen System Infos
1832 //
1833 // mvirtual : true/false -> {virtual memory)/(resident memory)
1834 //
1835 // output format (Example) :
1836 //
1837 // Mon Feb 3 17:34:12 UTC 2014
1838 // Memory - virtual : 596 (mb) rss : 315 (mb)
1839 //
1840 //
1841 
1842  ProcInfo_t info;
1843  gSystem->GetProcInfo(&info);
1844 
1845  cout << "Memory - virtual : " << info.fMemVirtual / 1024
1846  << " (mb) rss : " << info.fMemResident / 1024 << " (mb)" << endl;
1847  return mvirtual ? info.fMemVirtual/1024 : info.fMemResident/1024;
1848 }
1849 
1850 void
1852 //
1853 // Compile & load the plugin
1854 // Load the configPlugin
1855 //
1856 // plugin.GetName() : is the plugin macro name
1857 // plugin.GetTitle() : is the macro path
1858 // if ends with .C the plugin code is compiled
1859 // if ends with .so then it is used as path for the pre-compiled lib
1860 // configPlugin.GetName() : is the configPlugin macro name
1861 //
1862 
1863  if(TString(plugin.GetName())=="") return;
1864 
1865  unsigned int Pid = gSystem->GetPid(); // used to tag in a unique way the temporary files
1866 
1867  TString pluginPath = plugin.GetTitle();
1868 
1869  int error,check;
1870 
1871  // check if configPlugin exists and is readable
1872  if(TString(configPlugin.GetName())!="") {
1873  // save original name/title into the macro file, is used in the InitHistory
1874  configPlugin.AddLine(TString::Format("//#?CONFIG_PLUGIN_NAME %s",configPlugin.GetName()));
1875  configPlugin.AddLine(TString::Format("//#?CONFIG_PLUGIN_TITLE %s",configPlugin.GetTitle()));
1876 
1877  // set a unique name for macro, it is used by configPlugin.Exec() to create a temporary file
1878  // extract file name
1879 
1880  char configPluginName[1024];
1881  if((gROOT->GetVersionInt()>=53400)&&(gROOT->GetVersionInt()<=53407)) {
1882  // starting from ROOT 5.34.00 to 5.34.07 TMacro::Exec() creates the temporary macro file under /tmp
1883  // the temporary configPlugin name must be defined without the directory name
1884  sprintf(configPluginName,"CWB_Plugin_Config_%s_%d_job%d.XXXXXX",
1885  cfg.data_label,Pid,this->runID);
1886 
1887  } else {
1888  sprintf(configPluginName,"%s/CWB_Plugin_Config_%s_%d_job%d.XXXXXX",
1889  cfg.nodedir,cfg.data_label,Pid,this->runID);
1890  }
1891  if(mkstemp(configPluginName)==-1) { // create temporary file, must be deleted only at the end of run
1892  cout << "cwb::LoadPlugin - Error : mkstemp error in creating tmp file : " << configPluginName << endl;
1893  EXIT(1);
1894  }
1895  configPlugin.SetName("CWB_PluginConfig");
1896  configPlugin.SetTitle(configPluginName);
1897  }
1898 
1899  // if the plugin path extension ends with 'so' the pre-compiled plugin is used
1900  check=0;
1901  if(pluginPath.EndsWith(".so")) {
1902  // check if the plugin compilation date is up to date
1903  // the plugin compilation date must be > wat compilation date
1904  FileStat_t fStatus;
1905  int estat = gSystem->GetPathInfo(pluginPath.Data(),fStatus);
1906  if(!estat) {
1907  wat::Time plugin_comp_date(double(fStatus.fMtime)); // plugin compilation date (unix)
1908  plugin_comp_date.UnixToGps(); // plugin compilation date (gps)
1909  wat::Time wat_comp_date(watversion('T')); // wat compilation date
1910  if(plugin_comp_date.GetGPS()<wat_comp_date.GetGPS()) {
1911  TString pluginSrc = pluginPath;
1912  pluginSrc.ReplaceAll("_C.so",".C");
1913  cout << endl;
1914  cout << "cwb::LoadPlugin : The plugin compilation date is not up to date !!! " << endl;
1915  cout << " plugin compilation date : " << plugin_comp_date.GetDateString() << endl;
1916  cout << " wat compilation date : " << wat_comp_date.GetDateString() << endl;
1917  cout << endl;
1918  cout << "Recompile the plugin : " << endl;
1919  cout << "root -l -b -q " << pluginSrc << "++" << endl << endl;
1920  EXIT(1);
1921  }
1922  }
1923  cout << endl << "cwb::LoadPlugin - Load pre-compiled plugin ..." << endl << endl;
1924  check = gROOT->LoadMacro(pluginPath.Data(),&error);
1925  if(check==-1) {
1926  cout << "cwb::LoadPlugin : Load pre-compiled Plugin Failed !!! " << endl;
1927  cout << "cwb::LoadPlugin : The plugin is compiled 'On-The-Fly'!!! " << endl;
1928  }
1929  }
1930 
1931  // if the plugin path extension don't ends with 'so' or check!=0
1932  // then a copy is saved on tmp dir and the plugin is compiled 'On-The-Fly'
1933  if(!(pluginPath.EndsWith(".so"))||(check!=0)) {
1934  cout << endl << "cwb::LoadPlugin - compile and load plugin ..." << endl << endl;
1935  // create unique temporary file
1936  char tmpFile[1024]="";
1937  sprintf(tmpFile,"%s/CWB_Plugin_%s_%d_job%d.XXXXXX",cfg.nodedir,cfg.data_label,Pid,this->runID);
1938  if(mkstemp(tmpFile)==-1) { // create temporary file
1939  cout << "cwb::LoadPlugin - mkstemp error in creating tmp file : " << tmpFile << endl;
1940  EXIT(1);
1941  }
1942  char pluginSrc[1024]="";
1943  sprintf(pluginSrc,"%s.C",tmpFile); // must added .C to be compilable
1944  plugin.SaveSource(pluginSrc);
1945 
1946  // compile & load plugin
1947  int success = gSystem->CompileMacro(TString(pluginSrc).Data(),"f");
1948  gSystem->Exec(TString("/bin/rm ")+tmpFile); // remove temporary file
1949  if(!success) {
1950  cout << "cwb::LoadPlugin : Plugin Compilation Failed !!! " << endl;
1951  EXIT(1);
1952  }
1953 
1954  // check if the compiled filename exists and is readable
1955  TString pluginShr = pluginSrc;
1956  pluginShr.ReplaceAll(".C","_C.so");
1957  check = gROOT->LoadMacro(pluginShr.Data(),&error,true);
1958  if(check==-1) {
1959  cout << "cwb::LoadPlugin : Plugin Compilation Failed !!! " << endl;
1960  EXIT(1);
1961  }
1962 
1963  // removed temporary plugin files & shared object created by ACLiC
1964  TString pluginTmp = pluginSrc;
1965  char tmpStr[1024];
1966 
1967  sprintf(tmpStr, "/bin/rm -f %s", pluginTmp.Data());
1968  system(tmpStr);
1969  pluginTmp.ReplaceAll(".C","_C.so");
1970  sprintf(tmpStr, "/bin/rm -f %s", pluginTmp.Data());
1971  system(tmpStr);
1972  pluginTmp.ReplaceAll("_C.so","_C.d");
1973  sprintf(tmpStr, "/bin/rm -f %s", pluginTmp.Data());
1974  system(tmpStr);
1975  }
1976 
1977  return;
1978 }
1979 
1980 void
1982 //
1983 // convert job_elapsed_time to (hh:mm:ss) format and print it
1984 //
1985 // job_elapsed_time : time (seconds)
1986 //
1987 // info : info string added to (hh:mm:ss)
1988 //
1989 
1990  int job_elapsed_hour = int(job_elapsed_time/3600);
1991  int job_elapsed_min = int((job_elapsed_time-3600*job_elapsed_hour)/60);
1992  int job_elapsed_sec = int(job_elapsed_time-3600*job_elapsed_hour-60*job_elapsed_min);
1993  char buf[1024];
1994  sprintf(buf,"%s %02d:%02d:%02d (hh:mm:ss)\n",info.Data(),job_elapsed_hour,job_elapsed_min,job_elapsed_sec);
1995  cout << buf;
1996 
1997  return;
1998 }
1999 
2000 void
2002 //
2003 // Print stage infos to screen/history
2004 //
2005 // stage : stage
2006 // comment : comment
2007 // out : true -> print to standard output
2008 // log : true -> save to history
2009 // fname : fname : job/output file name
2010 //
2011 
2012  TString info = GetStageInfo(stage,comment,fname);
2013  // print to standard output
2014  if(out) cout << info.Data() << endl;
2015  // save to history
2016  if(log&&history) history->AddLog(const_cast<char*>("FULL"), const_cast<char*>(info.Data()));
2017 }
2018 
2019 TString
2021 //
2022 // return string filled using comment and internal analysis status parameters
2023 //
2024 // stage : stage
2025 // comment : comment
2026 // fname : fname : job/output file name
2027 //
2028 // The return string has this format (Example):
2029 //
2030 // --------------------------------------------------------------------
2031 // cwb::PrintAnalysis
2032 // --------------------------------------------------------------------
2033 // UTC - 2014-02-03 21:17:17 UTC Mon
2034 // Job Elapsed Time - 00:00:09 (hh:mm:ss)
2035 // Stage Elapsed Time - 00:00:01 (hh:mm:ss)
2036 // Memory - virtual : 472 (mb) rss : 187 (mb)
2037 // Job File Size - 0 (bytes) : 0 (kb) : 0 (mb)
2038 // --------------------------------------------------------------------
2039 // GPS:1075497453-JOB:1-STG:1-FCT:-1-JET:9-SET:1-MEM:472-JFS:0
2040 // --------------------------------------------------------------------
2041 //
2042 // where :
2043 //
2044 // GPS : gps time (sec)
2045 // JOB : job number
2046 // STG : stage number (defined in cwb.hh)
2047 // FCT : factors index array
2048 // JET : Job Elapsed Time (sec)
2049 // SET : Stage Elapsed Time (sec)
2050 // MEM : Memory usage (MB)
2051 // JFS : Job File Size - temporary file (bytes)
2052 //
2053 
2054  size_t GPS; // GPS Time
2055  size_t JOB=runID; // Job ID
2056  size_t STG=stage; // stage ID
2057  int FCT; // factor ID
2058  size_t JET; // Job Elapsed Time
2059  size_t SET; // Stage Elapsed Time
2060  size_t MEM; // Virtual Memory
2061  size_t JFS; // Job File Size
2062 
2063  // get ifactor
2064  int gIFACTOR; IMPORT(int,gIFACTOR)
2065  FCT = gIFACTOR;
2066 
2067  // redirect cout to buffer and return contents
2068  std::stringstream buffer;
2069  std::streambuf * old = std::cout.rdbuf(buffer.rdbuf());
2070 
2071  // get stage info
2072  cout << endl;
2073  cout << "--------------------------------------------------------------------" << endl;
2074  cout << comment.Data();
2075  if(cfg.simulation&&(FCT>=0)) {
2076  cout << " - factor[" << FCT << "]=" << cfg.factors[FCT] << endl;
2077  } else cout<<endl;
2078  cout << "--------------------------------------------------------------------" << endl;
2079  cout << "UTC - "; cout.flush();
2080  wat::Time date("now"); cout << date.GetDateString() << endl; GPS=date.GetGPS();
2081  watchJob.Stop();
2082  JET = watchJob.RealTime();
2083  PrintElapsedTime(watchJob.RealTime(),"Job Elapsed Time - ");
2084  watchJob.Continue();
2085  watchStage.Stop();
2086  SET = watchStage.RealTime();
2087  PrintElapsedTime(watchStage.RealTime(),"Stage Elapsed Time - ");
2088  watchStage.Reset();
2089  watchStage.Start();
2090  MEM=GetProcInfo();
2091  Long_t xid,xsize,xflags,xmt;
2092  TString xname = fname=="" ? jname : fname;
2093  int xestat = gSystem->GetPathInfo(xname.Data(),&xid,&xsize,&xflags,&xmt);
2094  if(xestat==0) JFS=xsize; else JFS=0;
2095  cout << "Job File Size - " << JFS << " (bytes) : "
2096  << int(JFS/1024.) << " (kb) : " << int(JFS/1024./1024) << " (mb)" << endl;
2097  cout << "--------------------------------------------------------------------" << endl;
2098  cout << "GPS:" << GPS << "-JOB:" << JOB << "-STG:" << STG << "-FCT:" << FCT
2099  << "-JET:" << JET << "-SET:" << SET << "-MEM:" << MEM << "-JFS:" << JFS << endl;
2100  cout << "--------------------------------------------------------------------" << endl;
2101  cout << endl;
2102 
2103  // restore cout
2104  std::cout.rdbuf(old);
2105 
2106  return buffer.str();
2107 }
2108 
2109 void
2111 //
2112 // Print to screen/history the comment string
2113 //
2114 // stage : stage
2115 // comment : comment to be showed/saved
2116 // info : extra user info
2117 // out : true -> print to standard output
2118 // log : true -> save to history
2119 //
2120 
2121  TString ainfo = GetAnalysisInfo(stage,comment,info);
2122  // print to standard output
2123  if(out) cout << ainfo.Data() << endl;
2124  // save to history
2125  if(log&&history) history->AddLog(const_cast<char*>("FULL"), const_cast<char*>(ainfo.Data()));
2126 }
2127 
2128 TString
2130 //
2131 // return string filled using comment/info and internal analysis status parameters
2132 //
2133 // stage : stage
2134 // comment : comment
2135 // info : extra user info
2136 //
2137 // The return string has this format (Example):
2138 //
2139 // --------------------------------------------------------------------
2140 // GPS:1075497453-JOB:1-STG:1-FCT:-1-JET:9-SET:1-MEM:472-JFS:0
2141 // --------------------------------------------------------------------
2142 //
2143 // where :
2144 //
2145 // GPS : gps time (sec)
2146 // JOB : job number
2147 // STG : stage number (defined in cwb.hh)
2148 // FCT : factors index array
2149 // JET : Job Elapsed Time (sec)
2150 // SET : Stage Elapsed Time (sec)
2151 // MEM : Memory usage (MB)
2152 // JFS : Job File Size - temporary file (bytes)
2153 //
2154 
2155  size_t GPS; // GPS Time
2156  size_t JOB=runID; // Job ID
2157  size_t STG=stage; // stage ID
2158  int FCT; // factor ID
2159 
2160  // get ifactor
2161  TGlobal* global = gROOT->GetGlobal("gIFACTOR",true);
2162  if(global!=NULL) FCT = *(int*)global->GetAddress(); else FCT=-1;
2163 
2164  // redirect cout to buffer and return contents
2165  std::stringstream buffer;
2166  std::streambuf * old = std::cout.rdbuf(buffer.rdbuf());
2167 
2168  // get stage info
2169  cout << endl;
2170  cout << "--------------------------------------------------------------------" << endl;
2171  cout << comment.Data();
2172  if(cfg.simulation&&(FCT>=0)) {
2173  cout << " - factor[" << FCT << "]=" << cfg.factors[FCT] << endl;
2174  } else cout<<endl;
2175  cout << "--------------------------------------------------------------------" << endl;
2176  cout << "GPS:" << GPS << "-JOB:" << JOB << "-STG:" << STG << "-FCT:" << FCT << info << endl;
2177  cout << "--------------------------------------------------------------------" << endl;
2178  cout << endl;
2179 
2180  // restore cout
2181  std::cout.rdbuf(old);
2182 
2183  return buffer.str();
2184 }
2185 
2186 TString
2188 //
2189 // return stage string format
2190 //
2191 // jstage : is the stage number defined the enum CWB_STAGE
2192 //
2193 
2194  switch(jstage) {
2195  case CWB_STAGE_FULL :
2196  return("CWB_STAGE_FULL");
2197  break;
2198  case CWB_STAGE_INIT :
2199  return("CWB_STAGE_INIT");
2200  break;
2201  case CWB_STAGE_STRAIN :
2202  return("CWB_STAGE_STRAIN");
2203  break;
2204  case CWB_STAGE_CSTRAIN :
2205  return("CWB_STAGE_CSTRAIN");
2206  break;
2207  case CWB_STAGE_COHERENCE :
2208  return("CWB_STAGE_COHERENCE");
2209  break;
2210  case CWB_STAGE_SUPERCLUSTER :
2211  return("CWB_STAGE_SUPERCLUSTER");
2212  break;
2213  case CWB_STAGE_LIKELIHOOD :
2214  return("CWB_STAGE_LIKELIHOOD");
2215  break;
2216  default :
2217  return("");
2218  break;
2219  }
2220 }
2221 
2222 void
2224 //
2225 // set save options for job file which is used to pass informations between stages
2226 //
2227 // jstage : is the stage number defined the enum CWB_STAGE
2228 //
2229 
2231 
2232  switch(jstage) {
2233  case CWB_STAGE_INIT :
2238  break;
2239  case CWB_STAGE_STRAIN :
2246  break;
2247  case CWB_STAGE_CSTRAIN :
2253  break;
2254  case CWB_STAGE_COHERENCE :
2261  break;
2262  case CWB_STAGE_SUPERCLUSTER :
2268  break;
2269  case CWB_STAGE_LIKELIHOOD :
2271  break;
2272  case CWB_STAGE_FULL :
2273  // if option CWB_JOBF_SAVE_TRGFILE and jstage=CWB_STAGE_FULL then
2274  // all necessary objects are saved in the trigger file
2275  if(!(jobfOptions&CWB_JOBF_SAVE_TRGFILE)) break;
2282  break;
2283  default :
2284  break;
2285  }
2286 
2287  return;
2288 }
2289 
2290 void
2291 cwb::Exec(char* command, int maxtry, bool verbose) {
2292 //
2293 // Execute System Command
2294 //
2295 // command : system command
2296 // maxtry : number of retry before to exit with error (default=3)
2297 // verbose : show the retry infos (default=true)
2298 //
2299 
2300  int ntry=0;
2301  int ecommand=1;
2302  while(ecommand&&(ntry<maxtry)) {
2303  ecommand=gSystem->Exec(command);
2304  if(ecommand) gSystem->Sleep(int(gRandom->Uniform(10000,30000))); // wait [10,30] sec
2305  ntry++;
2306  if(verbose) {
2307  if(ecommand) {
2308  cout << command << endl;
2309  cout << "cwb::Exec - NTRY " << ntry << endl;
2310  cout.flush();
2311  }
2312  }
2313  }
2314  if(ecommand) {cout << "cwb::Exec - Error -> " << command << endl;EXIT(1);}
2315  return;
2316 }
2317 
2318 void
2319 cwb::FileGarbageCollector(TString ifName, TString ofName, vector<TString> delObjList) {
2320 //
2321 // for ROOT < 5.34.05
2322 // the objects marked as deleted do not free the disk space
2323 // this method is used to free the deleted object space contained in the root file
2324 //
2325 // for ROOT >= 5.34.05
2326 // All objected contained in ifName and are not in the delObjList are copied to ofName
2327 // This method is used to cleanup the ROOT file ifName
2328 //
2329 // ifName : input file name
2330 // ofName : output file name (cleaned) - if ofName="" -> ofName=ifName
2331 // delObjList : list of object which must removed from the ifName (only for ROOT >= 5.34.05)
2332 //
2333 
2334  bool replace = false;
2335  if(ofName=="") {
2336  ofName = ifName;
2337  ofName.ReplaceAll(".root","_tmp.root");
2338  replace = true;
2339  }
2340 
2341  if(delObjList.size()==0) {
2342  if(!replace) {
2343  char command[1024];
2344  sprintf(command,"/bin/mv %s %s",ofName.Data(),ifName.Data());
2345  gSystem->Exec(command);
2346  } else return;
2347  }
2348 
2349  if(gROOT->GetVersionInt()<53405) {
2350  // delete the objects contained in the delObjList
2351  TFile* kfile = new TFile(ifName, "UPDATE");
2352  for(int i=0;i<delObjList.size();i++) kfile->Delete(delObjList[i]+";1");
2353  kfile->Close();
2354  }
2355 
2356  gErrorIgnoreLevel=kBreak; // disable root kInfo & kWarning & kError messages
2357  TFileMerger M(false);
2358  M.AddFile(ifName,false);
2359  M.OutputFile(ofName);
2360  if(gROOT->GetVersionInt()<53400) {
2361  // TFileMerger free the deleted object space
2362  if(!M.Merge()) {
2363  cout << "cwb::FileGarbageCollector : Error - Merge failed !!!" << endl;EXIT(1);
2364  }
2365  }
2366  if(gROOT->GetVersionInt()>=53400 && gROOT->GetVersionInt()<53405) {
2367  // starting from ROOT 5.34.00 TFileMerger::Merge() merge also the deleted object
2368  // The following is a workaround to fix this issue
2369  if(!M.PartialMerge(TFileMerger::kAllIncremental | TFileMerger::kRegular)) {
2370  cout << "cwb::FileGarbageCollector : Error - Merge failed !!!" << endl;EXIT(1);
2371  }
2372  }
2373 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,34,5)
2374  if(gROOT->GetVersionInt()>=53405) {
2375  // add files which must not be copied from ifName to ofName
2376  for(int i=0;i<delObjList.size();i++) M.AddObjectNames(delObjList[i]);
2377  // Must add new merging flag on top of the the default ones
2378  Int_t default_mode = TFileMerger::kAll | TFileMerger::kIncremental;
2379  Int_t mode = default_mode | TFileMerger::kSkipListed;
2380  if(!M.PartialMerge(mode)) {
2381  cout << "cwb::FileGarbageCollector : Error - Merge failed !!!" << endl;EXIT(1);
2382  }
2383  M.Reset();
2384  }
2385 #endif
2386  gErrorIgnoreLevel=kUnset; // re-enable root kInfo & kWarning messages
2387 
2388  if(replace) { // replace ifName with ofName
2389  char command[1024];
2390  sprintf(command,"/bin/mv %s %s",ofName.Data(),ifName.Data());
2391  gSystem->Exec(command);
2392  }
2393 
2394  return;
2395 }
2396 
2397 void
2398 cwb::MakeSkyMask(skymap& SkyMask, double theta, double phi, double radius) {
2399 //
2400 // make a sky mask
2401 // is used to define what are the sky locations that are analyzed
2402 //
2403 // theta,phi,radius : used to define the Celestial SkyMap
2404 // define a circle centered in (theta,phi) and radius=radius
2405 // theta : [-90,90], phi : [0,360], radius : degrees
2406 //
2407 // SkyMask : output sky celestial mask
2408 // inside the circle is filled with 1 otherwise with 0
2409 //
2410 
2411  int L = SkyMask.size();
2412  int healpix = SkyMask.getOrder();
2413  // check input parameters
2414  if(fabs(theta)>90 || (phi<0 || phi>360) || radius<=0 || L<=0) {
2415  cout << "cwb::MakeSkyMask : wrong input parameters !!! " << endl;
2416  if(fabs(theta)>90) cout << theta << " theta must be in the range [-90,90]" << endl;
2417  if(phi<0 || phi>360) cout << phi << " phi must be in the range [0,360]" << endl;
2418  if(radius<=0) cout << radius << " radius must be > 0" << endl;
2419  if(L<=0) cout << L << " SkyMask size must be > 0" << endl;
2420  EXIT(1);
2421  }
2422 
2423  if (!gROOT->GetClass("Polar3DVector")) gSystem->Load("libMathCore");
2424 
2425  // compute the minimun available radius
2426  // must be greater than the side of a pixel
2427  if(healpix) {
2428  int npix = 12*(int)pow(4.,(double)healpix);
2429  double sphere_solid_angle = 4*TMath::Pi()*pow(180./TMath::Pi(),2.);
2430  double skyres = sphere_solid_angle/npix;
2431  if(radius < sqrt(skyres)) radius = sqrt(skyres);
2432  } else {
2433  if(radius < SkyMask.sms) radius = SkyMask.sms;
2434  }
2435 
2436  double ph,th;
2437  GeographicToCwb(phi,theta,ph,th); // Geographic to CWB coordinates
2438 
2439  Polar3DVector ov1(1, th*TMath::Pi()/180, ph*TMath::Pi()/180);
2440 
2441  int nset=0;
2442  for (int l=0;l<L;l++) {
2443  double phi = SkyMask.getPhi(l);
2444  double theta = SkyMask.getTheta(l);
2445 
2446  Polar3DVector ov2(1, theta*TMath::Pi()/180, phi*TMath::Pi()/180 );
2447  double Dot = ov1.Dot(ov2);
2448  double dOmega = 180.*TMath::ACos(Dot)/TMath::Pi();
2449  //cout << "dOmega : " << dOmega << endl;
2450 
2451  if(dOmega<=radius) {SkyMask.set(l,1);nset++;} else SkyMask.set(l,0);
2452  }
2453 
2454  if(!nset) {
2455  cout << "cwb::MakeSkyMask : no sky positions setted !!! " << endl;
2456  cout << "check input mask parameters : theta = "
2457  << theta << " phi = " << phi << " radius : " << radius << endl << endl;
2458  EXIT(1);
2459  }
2460 
2461  return;
2462 }
2463 
2464 int
2465 cwb::SetSkyMask(network* net, CWB::config* cfg, char* options, char skycoord, double skyres) {
2466 //
2467 // set earth/celestial sky mask
2468 // is used to define what are the sky locations that are analyzed
2469 // by default all sky is used
2470 //
2471 // net : pointer to the network object
2472 // cfg : pointer to the cwb config object
2473 // options : used to define the earth/celestial SkyMap
2474 // option A :
2475 // skycoord='e'
2476 // --theta THETA --phi PHI --radius RADIUS
2477 // define a circle centered in (THETA,PHI) and radius=RADIUS
2478 // THETA : [-90,90], PHI : [0,360], RADIUS : degrees
2479 // skycoord='c'
2480 // --theta DEC --phi RA --radius RADIUS
2481 // define a circle centered in (DEC,RA) and radius=RADIUS
2482 // DEC : [-90,90], RA : [0,360], RADIUS : degrees
2483 // option B:
2484 // file name
2485 // format : two columns ascii file -> [sky_index value]
2486 // sky_index : is the sky grid index
2487 // value : if !=0 the index sky location is used for the analysis
2488 // skycoord : sky coordinates : 'e'=earth, 'c'=celestial
2489 // skyres : sky resolution : def=-1 -> use the value defined in parameters (angle,healpix)
2490 //
2491 // return 0 if successful
2492 
2493  if(skycoord!='e' && skycoord!='c') {
2494  cout << "cwb::SetSkyMask - Error : wrong input sky coordinates "
2495  << " must be 'e'/'c' earth/celestial" << endl;;
2496  EXIT(1);
2497  }
2498 
2499  if(strlen(options)>0) { // set SkyMask
2500  if(!TString(options).Contains("--")) { // input parameter is the skyMask file
2501  if(skyres>=0) return 1;
2502  int ret = net->setSkyMask(options,skycoord);
2503  if(ret==0) {
2504  cout << endl;
2505  cout << "cwb::SetSkyMask - Error : skyMask file"
2506  << " not exist or it has a wrong format" << endl;
2507  cout << endl;
2508  cout << " format : two columns ascii file -> [sky_index value]" << endl;
2509  cout << " sky_index : is the sky grid index" << endl;
2510  cout << " value : if !=0 the index sky location is used for the analysis" << endl;
2511  cout << endl;
2512  EXIT(1);
2513  }
2514  if(skycoord=='e') net->setIndexMode(0);
2515  return 0;
2516  }
2517 
2518  double theta=-1000;
2519  TString THETA = TB.getParameter(options,"--theta"); // get theta
2520  if(THETA.IsFloat()) theta=THETA.Atof();
2521  double phi=-1000;
2522  TString PHI = TB.getParameter(options,"--phi"); // get phi
2523  if(PHI.IsFloat()) phi=PHI.Atof();
2524  double radius=-1000;
2525  TString RADIUS = TB.getParameter(options,"--radius"); // get Radius
2526  if(RADIUS.IsFloat()) radius=RADIUS.Atof();
2527 
2528  if(theta==-1000 || phi==-1000 || radius==-1000) { // input parameter are the skyMask params
2529  cout << endl << "cwb::SetSkyMask - Error : wrong input skyMask params" << endl << endl;
2530  cout << "wrong input options : " << options << endl;
2531  if(skycoord=='e')
2532  cout<<"options must be : --theta THETA --phi PHI --radius RADIUS"<<endl<<endl;
2533  if(skycoord=='c')
2534  cout<<"options must be : --theta DEC --phi AR --radius RADIUS"<<endl<<endl;
2535  if(fabs(theta)>90) cout << theta << " theta must be in the range [-90,90]" << endl;
2536  if(phi<0 || phi>360) cout << phi << " phi must be in the range [0,360]" << endl;
2537  if(radius<=0) cout << radius << " radius must be > 0" << endl;
2538  cout << endl;
2539  EXIT(1);
2540  } else { // create & set SkyMask
2541  skymap* SkyMask=NULL;
2542  if(skyres<0) skyres = cfg->healpix ? cfg->healpix : cfg->angle;
2543  if(cfg->healpix) SkyMask = new skymap(int(skyres));
2544  else SkyMask = new skymap(skyres,cfg->Theta1,cfg->Theta2,cfg->Phi1,cfg->Phi2);
2545  MakeSkyMask(*SkyMask, theta, phi, radius);
2546  net->setSkyMask(*SkyMask,skycoord);
2547  if(skycoord=='e') net->setIndexMode(0);
2548  if(SkyMask!=NULL) delete SkyMask;
2549  }
2550  }
2551  return 0;
2552 }
2553 
2554 vector<frfile>
2556 //
2557 // return the FRF frame files list
2558 // input : ifoID : ifo iD , if ifoID=-1 then all ifo FRF are returned
2559 //
2560 
2561  vector<frfile> frlist;
2562 
2563  // fill frlist
2564  for(int i=0;i<2*nIFO;i++) {
2565  if((ifoID==-1)||(i==ifoID)||(i==(ifoID+nIFO))) frlist.push_back(FRF[i]);
2566  }
2567 
2568  return frlist;
2569 }
2570 
2571 vector<frfile>
2573 //
2574 // return the FRF frame files list
2575 // input : ifo : ifo name
2576 //
2577 
2578  // get ifo id
2579  int ifoID=-1;
2580  for(int n=0;n<nIFO;n++) if(ifo.CompareTo(this->ifo[n])==0) {ifoID=n;break;}
2581 
2582  if(ifoID==-1) {
2583  cout << "cwb::GetFrList - Error : requested ifo " << ifo
2584  << " not present !!!" << endl;;
2585  EXIT(1);
2586  }
2587 
2588  return GetFrList(ifoID);
2589 }
2590 
std::vector< char * > ifoName
Definition: network.hh:591
CWB_JOBF_OPTIONS jobfOptions
Definition: config.hh:273
void sethigh(double f)
Definition: wseries.hh:114
detector * getifo(size_t n)
param: detector index
Definition: network.hh:418
CWB::config * cfg
Definition: TestCWB_Plugin.C:5
char analysis[8]
Definition: config.hh:99
TString outDump
int jobID
category 2 data quality list
Definition: cwb.hh:279
double Te
Definition: cwb.hh:270
TString GetLALVersion(TString options="")
Definition: Toolfun.hh:892
double iwindow
Definition: config.hh:182
double netCC
Definition: network.hh:578
TString GetGitInfos(TString option="path", TString igit_path="$CWB_CONFIG")
Definition: Toolfun.hh:323
virtual void resize(unsigned int)
Definition: wseries.cc:883
CWB::frame fr[2 *NIFO_MAX]
Definition: cwb.hh:239
void PrintElapsedTime(int job_elapsed_time, TString info)
Definition: cwb.cc:1981
TString GetAnalysisInfo(CWB_STAGE stage, TString comment, TString info)
Definition: cwb.cc:2129
double startMDC
Definition: Toolbox.hh:88
cwb(CWB_STAGE jstage=CWB_STAGE_FULL)
Definition: cwb.cc:13
size_t nLag
Definition: network.hh:555
static size_t GetProcInfo(bool mvirtual=true)
Definition: cwb.cc:1829
double precision
Definition: config.hh:268
void printwc(size_t)
Definition: network.cc:2627
double start
Definition: network.hh:37
TString ofName
int job_elapsed_min
Definition: cwb_net.C:720
INT_4S GetGPS()
Definition: time.hh:107
TString GetDateString()
Definition: time.cc:443
WSeries< double > pixeLHood
Definition: network.hh:616
bool optim
Definition: config.hh:104
CWB::History * hst
void Export(TString fname="")
Definition: config.cc:388
void Init()
Definition: ChirpMass.C:280
void cwb_jnet(TString jName="", TString uName="")
Definition: cwb_jnet.C:4
void FileGarbageCollector(TString ifName, TString ofName="", vector< TString > delObjList=vector< TString >())
Definition: cwb.cc:2319
int stop
Definition: Toolbox.hh:76
void Print(Option_t *option="")
Definition: config.cc:719
size_t add(detector *)
param: detector structure return number of detectors in the network
Definition: network.cc:2528
tuple f
Definition: cwb_online.py:91
printf("total live time: non-zero lags = %10.1f \n", liveTot)
bool singleDetector
used for the stage stuff
Definition: cwb.hh:265
TString live
TMacro configPlugin
Definition: config.hh:344
char cmd[1024]
size_t readMDClog(char *, double=0., int=11, int=12)
param: MDC log file param: approximate gps time
Definition: network.cc:3339
void setAntenna(detector *)
param: detector (use theta, phi index array)
Definition: network.cc:2815
bool mdcPlugin
Definition: config.hh:347
Definition: ced.hh:24
int nfrFiles[2 *NIFO_MAX]
Definition: cwb.hh:240
virtual void rate(double r)
Definition: wavearray.hh:123
#define EXIT(ERR)
Definition: cwb.cc:7
char name[32]
Definition: detector.hh:32
char skyMaskFile[1024]
Definition: config.hh:290
WSeries< float > v[nIFO]
Definition: cwb_net.C:62
double job_speed_factor
Definition: cwb_net.C:723
bool dataPlugin
Definition: config.hh:346
int n
Definition: cwb_net.C:10
void Init()
Definition: cwb.cc:212
double dT
Definition: cwb.hh:271
void CWB_Plugin(TFile *jfile, CWB::config *, network *, WSeries< double > *, TString, int)
COHERENCE.
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
vector< frfile > GetFrList(int ifoID=-1)
Definition: cwb.cc:2555
char * watversion(char c='s')
Definition: watversion.hh:21
TString("c")
char comment[1024]
size_t setIndexMode(size_t=0)
Definition: network.cc:8072
int nset
Definition: cwb_mkeff.C:57
double Tb
Definition: cwb.hh:269
virtual double InitJob()
Definition: cwb.cc:1230
int start
Definition: Toolbox.hh:75
double stopMDC
Definition: Toolbox.hh:89
cout<< endl;cout<< "ts size = "<< ts.size()<< " ts rate = "<< ts.rate()<< endl;tf.Forward(ts, wdm);int levels=tf.getLevel();cout<< "tf size = "<< tf.size()<< endl;double dF=tf.resolution();double dT=1./(2 *dF);cout<< "rate(hz) : "<< RATE<< "\t layers : "<< nLAYERS<< "\t dF(hz) : "<< dF<< "\t dT(ms) : "<< dT *1000.<< endl;int itime=TIME_PIXEL_INDEX;int ifreq=FREQ_PIXEL_INDEX;int index=(levels+1)*itime+ifreq;double time=itime *dT;double freq=(ifreq >0)?ifreq *dF:dF/4;cout<< endl;cout<< "PIXEL TIME = "<< time<< " sec "<< endl;cout<< "PIXEL FREQ = "<< freq<< " Hz "<< endl;cout<< endl;wavearray< double > x
void Check()
Definition: config.cc:1393
std::vector< wavearray< double > * > RWFP
Definition: detector.hh:364
double fLow
Definition: config.hh:122
float theta
int pattern
Definition: config.hh:223
bool eDisbalance
Definition: network.hh:580
delete[] radius
netcluster * pwc
Definition: cwb_job_obj.C:20
TString mdc[4]
CWB::frame fr(FRLIST_NAME)
TH2F * ph
vector< int > segId
Definition: Toolbox.hh:84
CWB_STAGE jstage
Definition: cwb.hh:236
bool cedDump
Definition: config.hh:279
void setlow(double f)
Definition: wseries.hh:107
int slagID
Definition: cwb.hh:279
size_t setSkyMask(double f, char *fname)
Definition: network.cc:3182
Long_t flags
CWB_JOBF_OPTIONS jobfOptions
TString GetStageInfo(CWB_STAGE stage, TString comment, TString fname="")
Definition: cwb.cc:2020
virtual double ReadData(double mdcShift, int ifactor)
Definition: cwb.hh:189
dqfile DQF[DQF_MAX]
Definition: config.hh:331
CWB::mdc * MDC
size_t * slagSite
Definition: config.hh:167
double getTheta(size_t i)
Definition: skymap.hh:206
double Te
double netRHO
Definition: config.hh:129
CWB::History * history
char * lagFile
Definition: config.hh:154
Long_t size
#define M
Definition: UniqSLagsList.C:3
int slagMin
Definition: config.hh:164
static double getTimeSegList(vector< waveSegment > list)
Definition: Toolbox.cc:592
virtual void start(double s)
Definition: wavearray.hh:119
vector< waveSegment > detSegs_dq2
Definition: cwb_net.C:279
int j
Definition: cwb_net.C:10
i drho i
std::vector< double > mdcTime
Definition: network.hh:596
void Import(TString umacro="")
Definition: config.cc:334
char nodedir[1024]
Definition: config.hh:334
double segTHR
Definition: config.hh:145
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:3956
void setRunID(size_t n)
param: run
Definition: network.hh:437
double Phi1
Definition: config.hh:261
int jobID
Definition: cwb_net.C:177
bool outPlugin
Definition: config.hh:351
CWB::Toolbox TB
Definition: ComputeSNR.C:5
int jobId
Definition: Toolbox.hh:82
double segOverlap
Definition: config.hh:147
char ifo[NIFO_MAX][8]
double Edge
Definition: network.hh:560
int slagOff
Definition: config.hh:166
network ** net
NOISE_MDC_SIMULATION.
size_t ifoListSize()
Definition: network.hh:413
waveSegment getFrRange()
Definition: frame.hh:89
bool online
Definition: config.hh:100
static char * getEnvCWB()
Definition: Toolbox.cc:4599
double mdcShift
Definition: cwb_net.C:178
void constraint(double d=1., double g=0.0001)
param: constraint parameter, p=0 - no constraint
Definition: network.hh:445
char * rootlogonBuffer
Definition: cwb_net.C:140
int Psave
Definition: config.hh:175
vector< waveSegment > detSegs
time delay difference
Definition: cwb.hh:276
bool singleDetector
bool optim
Definition: network.hh:572
size_t mode
double segEdge
Definition: config.hh:146
#define nIFO
void UnixToGps()
Definition: time.hh:213
ofstream out
Definition: cwb_merge.C:196
virtual ~cwb()
Definition: cwb.cc:197
void setTimeRange(int xstart=0, int xstop=0)
Definition: frame.hh:130
float slagShift[20]
Definition: cwb.hh:280
detectorParams detParms[NIFO_MAX]
Definition: config.hh:110
double Theta2
Definition: config.hh:260
tlive_fix Write()
float phi
double precision
Definition: network.hh:575
double factor
size_t fResample
Definition: config.hh:124
TGlobal * global
Definition: config.cc:5
static char * readFile(TString ifName)
Definition: Toolbox.cc:2815
jfile
Definition: cwb_job_obj.C:25
char end_CED[1024]
Definition: cwb_job_obj.C:17
TTree * net_tree
char filter_dir[1024]
Definition: config.hh:287
double shift
Definition: netcluster.hh:364
size_t lagOff
Definition: config.hh:152
Definition: mdc.hh:216
char lagMode[2]
Definition: test_config1.C:57
std::vector< double > livTime
Definition: network.hh:593
static TString GetStageString(CWB_STAGE jstage)
Definition: cwb.cc:2187
int simulation
Definition: config.hh:181
int l_high
Definition: config.hh:138
int length
Definition: Toolbox.hh:77
int nDQF
Definition: config.hh:330
double Fgap
Definition: config.hh:118
int pattern
void PrintAnalysisInfo(CWB_STAGE stage, TString comment, TString info, bool out=true, bool log=true)
Definition: cwb.cc:2110
void SetupStage(CWB_STAGE jstage)
Definition: cwb.cc:2223
CWB_OUTF_OPTIONS outfOptions
Definition: config.hh:274
#define IMPORT(TYPE, VAR)
Definition: cwb.hh:51
int segID[20]
Definition: cwb.hh:279
char search
Definition: config.hh:103
size_t * lagSite
Definition: config.hh:156
vector< slag > slagList
char * GetLog(char *Stage, int index)
Definition: History.cc:286
i() int(T_cor *100))
int GetLogSize(char *Stage)
Definition: History.cc:280
char output_dir[1024]
Definition: config.hh:300
network NET
Definition: cwb_dump_inj.C:12
double Pi
int getOrder()
Definition: skymap.hh:296
virtual void run(int runID=0)
Definition: cwb.cc:263
std::vector< std::string > mdcList
Definition: network.hh:594
const int NIFO_MAX
Definition: wat.hh:4
bool log
Definition: WaveMDC.C:41
double getDelay(const char *c="")
Definition: network.cc:2787
char lagMode[1]
Definition: cwb.hh:282
int slagMax
Definition: config.hh:165
WSeries< double > pTF[nRES]
Definition: revMonster.cc:8
int gIFACTOR
static vector< waveSegment > getSlagJobList(vector< waveSegment > ilist, int seglen=600)
Definition: Toolbox.cc:1771
double delta
Definition: config.hh:234
int mlagStep
double sms
Definition: skymap.hh:302
char fname[1024]
bool eDisbalance
Definition: config.hh:252
double dataShift[NIFO_MAX]
Definition: config.hh:187
void setVerbose(bool verbose=true)
Definition: frame.hh:119
#define RADIUS
Definition: Wavelet.hh:31
double precision
int slagSize
Definition: config.hh:163
frfile FRF[nIFO+1]
Definition: cwb_net.C:251
double Acore
Definition: config.hh:125
void PrintStageInfo(CWB_STAGE stage, TString comment, bool out=true, bool log=true, TString fname="")
Definition: cwb.cc:2001
TList * GetStageNames()
Definition: History.cc:409
void Exec(char *command, int maxtry=3, bool verbose=true)
Definition: cwb.cc:2291
int k
CWB SetSkyMask(net, cfg, cfg->skyMaskCCFile,'c')
int frRetryTime
Definition: config.hh:326
int pattern
Definition: network.hh:583
int getNfiles()
Definition: frame.hh:92
std::vector< waveSegment > segList
Definition: network.hh:598
char log_dir[1024]
Definition: config.hh:305
int nfactor
Definition: config.hh:183
virtual void DataConditioning(int ifactor)
Definition: cwb.hh:193
std::vector< wavearray< double > * > IWFP
Definition: detector.hh:361
void PrintElapsedTime(int job_elapsed_time, double cpu_time, TString info)
size_t healpix
Definition: config.hh:264
char refIFO[4]
Definition: config.hh:107
int nfrFiles[nIFO+1]
Definition: cwb_net.C:174
vector< waveSegment > cat1List
size_t lagSize
Definition: config.hh:150
void setSRIndex(int srIndex)
Definition: frame.hh:96
void setDelay(const char *="L1")
Definition: network.cc:2736
Definition: skymap.hh:45
long nSky
Definition: config.hh:281
string command
Definition: cwb_online.py:382
cout<< endl;cout<< "Unfinished Jobs : "<< cnt<< "/"<< jobList.size()<< endl;cout<< endl;sprintf(dagfile,"%s/%s.dag.recovery.%d", condor_dir, data_label, iversion);cout<< "To submit condor recovered jobs, type :"<< endl;cout<< "cwb_condor submit "<< dagfile<< endl;}cout<< endl;if(gSystem->Getenv("_USE_LSF")!=NULL){TString cwb_stage_label="supercluster_";if(cwb_stage_input=="FULL") cwb_stage_label="wave_";if(cwb_stage_input=="INIT") cwb_stage_label="init_";if(cwb_stage_input=="STRAIN") cwb_stage_label="strain_";if(cwb_stage_input=="CSTRAIN") cwb_stage_label="cstrain_";if(cwb_stage_input=="COHERENCE") cwb_stage_label="coherence_";if(cwb_stage_input=="SUPERCLUSTER") cwb_stage_label="supercluster_";if(cwb_stage_input=="LIKELIHOOD") cwb_stage_label="wave_";TString exec_cmd=TString::Format("export file_n_st=""$(ls %s*_job%i.root)""", cwb_stage_label.Data(), jobID);gSystem-> Exec(exec_cmd)
TFile * ifile
frfile FRF[2 *NIFO_MAX]
Definition: cwb.hh:241
TList * GetTypeNames()
Definition: History.cc:422
char lagMode[2]
Definition: config.hh:155
size_t rateANA
Definition: test_config1.C:21
char injectionList[1024]
Definition: config.hh:289
double netCC
Definition: config.hh:130
bool EFEC
Definition: config.hh:256
TFile * froot
void setAcore(double a)
Definition: network.hh:383
int npix
static double getMDCShift(mdcshift mshift, double time)
Definition: Toolbox.cc:2276
double subnet
Definition: config.hh:229
mdcshift mdc_shift
Definition: config.hh:193
static slag getSlag(vector< slag > slagList, int jobid)
Definition: Toolbox.cc:1824
size_t events()
Definition: network.hh:311
static int shiftBurstMDCLog(std::vector< std::string > &mdcList, vector< TString > ifos, double mdc_shift)
Definition: Toolbox.cc:2154
vector< waveSegment > detSegs
Definition: cwb_net.C:175
static void setSlagShifts(slag SLAG, vector< TString > ifos, double segLen, int nDQF, dqfile *DQF)
Definition: Toolbox.cc:1997
int l_low
Definition: config.hh:137
char options[256]
#define EXPORT(TYPE, VAR, CMD)
Definition: config.cc:74
static vector< slag > getSlagList(size_t nIFO, size_t slagSize, int slagSegs, int slagOff, size_t slagMin, size_t slagMax, size_t *slagSite, char *slagFile=NULL)
Definition: Toolbox.cc:790
double getPhi(size_t i)
Definition: skymap.hh:146
static vector< waveSegment > readSegList(dqfile DQF)
Definition: Toolbox.cc:391
char cmd_line[512]
Definition: cwb_net.C:136
int job_elapsed_time
Definition: cwb_net.C:718
double Tb
static TString getParameter(TString options, TString param="")
Definition: Toolbox.cc:5943
ifstream in
char * slagFile
Definition: config.hh:168
double fHigh
Definition: config.hh:123
void PrintAnalysis(bool stageInfos=true)
Definition: cwb.cc:1687
int mlagStep
Definition: config.hh:160
WSeries< double > * getTFmap()
param: no parameters
Definition: detector.hh:161
static void MakeSkyMask(skymap &SkyMask, double theta, double phi, double radius)
Definition: cwb.cc:2398
char Name[16]
Definition: detector.hh:309
virtual void InitHistory()
Definition: cwb.cc:984
TMacro plugin
Definition: config.hh:343
char ifo[NIFO_MAX][8]
Definition: config.hh:106
vector< int > slagId
Definition: Toolbox.hh:83
double fabs(const Complex &x)
Definition: numpy.cc:37
char work_dir[1024]
Definition: config.hh:296
int job_data_size_sec
Definition: cwb_net.C:722
int ifactor
int SetSkyMask(network *net, CWB::config *cfg, char *options, char skycoord, double skyres=-1)
Definition: cwb.cc:2465
double gamma
Definition: network.hh:574
double segLen
Definition: config.hh:143
#define GPS
double mTau
int slagID
Definition: cwb_net.C:177
static vector< waveSegment > getSegList(int jobId, int nIFO, double segLen, double segMLS, double segEdge, vector< waveSegment > dqList)
Definition: Toolbox.cc:2779
int estat
void AddLog(char *Stage, char *Log, TDatime *Time=NULL)
Definition: History.cc:169
void LoadPlugin(TMacro &plugin, TMacro &configPlugin)
Definition: cwb.cc:1851
strcpy(RunLabel, RUN_LABEL)
Definition: Toolbox.hh:81
cout<< "total cat1 livetime : "<< int(cat1_time)<< " sec "<< cat1_time/3600.<< " h "<< cat1_time/86400.<< " day"<< endl;cout<< endl;vector< waveSegment > cat2List
Definition: cwb_dump_job.C:22
netcluster * getwc(size_t n)
param: delay index
Definition: network.hh:421
int l
Definition: cbc_plots.C:434
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
double subcut
Definition: config.hh:230
double Phi2
Definition: config.hh:262
Long_t mt
frfile getFrList(int istart, int istop, int segEdge)
Definition: frame.cc:509
TMacro plugin
void set(size_t i, double a)
param: sky index param: value to set
Definition: skymap.hh:104
static vector< waveSegment > mergeSegLists(vector< waveSegment > &ilist1, vector< waveSegment > &ilist2)
Definition: Toolbox.cc:332
char skyMaskCCFile[1024]
Definition: config.hh:291
int nIFO
Definition: config.hh:102
Definition: cwb.hh:119
double mask
Definition: config.hh:263
double Tgap
Definition: config.hh:116
char nodedir[1024]
Definition: test_config1.C:187
SortOrderType SetSortOrder(SortOrderType SortOrder)
Definition: History.cc:571
long nSky
Definition: network.hh:556
TString jname
Long_t id
double detSegs_ctime
Definition: cwb_net.C:285
enum WAVETYPE m_WaveType
Definition: Wavelet.hh:88
double factors[FACTORS_MAX]
Definition: config.hh:184
int job_elapsed_hour
Definition: cwb_net.C:719
TMacro configPlugin
int segID[20]
Definition: cwb_net.C:177
WaveDWT< DataType_t > * pWavelet
Definition: wseries.hh:438
double dT
Definition: testWDM_5.C:12
void GeographicToCwb(double ilongitude, double ilatitude, double &olongitude, double &olatitude)
Definition: skycoord.hh:403
size_t lagMax
Definition: config.hh:153
char * GetHistory(char *StageName, char *Type)
Definition: History.cc:255
TArrayC lagBuffer
Definition: cwb.hh:283
char data_label[1024]
Definition: config.hh:314
void setRetryTime(int frRetryTime=60)
Definition: frame.hh:123
cout<< fr.getNfiles()<< endl;std::vector< frfile > frlist
virtual void SuperCluster(int ifactor)
Definition: cwb.hh:201
void open(TString ioFile, TString chName="", Option_t *option="", bool onDisk=false, TString label=".gwf", unsigned int mode=0)
Definition: frame.cc:212
int runID
Definition: cwb.hh:234
double lagStep
Definition: config.hh:151
virtual void Coherence(int ifactor)
Definition: cwb.hh:197
size_t size()
Definition: skymap.hh:118
int job_elapsed_sec
Definition: cwb_net.C:721
char fName[256]
virtual void resize(unsigned int)
Definition: wavearray.cc:445
double TFgap
Definition: config.hh:120
double bpp
Definition: config.hh:115
int check
int setTimeShifts(size_t=1, double=1., size_t=0, size_t=0, const char *=NULL, const char *="w", size_t *=NULL)
param number of time lags param time shift step in seconds param first lag ID param maximum lag ID pa...
Definition: network.cc:7290
double length
Definition: TestBandPass.C:18
double Theta1
Definition: config.hh:259
double stop
Definition: network.hh:38
double netRHO
Definition: network.hh:579
size_t inRate
Definition: config.hh:114
double gamma
Definition: config.hh:240
void GetProcInfo(TString str="")
Definition: Toolfun.hh:219
double segMLS
Definition: config.hh:144
void AddHistory(char *Stage, char *Type, char *History, TDatime *Time=NULL)
Definition: History.cc:207
int levelR
Definition: config.hh:134
bool EFEC
Definition: network.hh:569
char frFiles[2 *NIFO_MAX][1024]
Definition: config.hh:324
detector ** pD
virtual void InitNetwork()
Definition: cwb.cc:892
CWB_STAGE
Definition: cwb.hh:102
void SetSingleDetectorMode()
Definition: config.cc:1334
TString ifos[60]
double angle
Definition: config.hh:258
void setSkyMaps(double, double=0., double=180., double=0., double=360.)
param: sky map granularity step, degrees param: theta begin, degrees param: theta end...
Definition: network.cc:2656
size_t healpix
bool dump
Definition: config.hh:277