Logo coherent WaveBurst  
Library Reference Guide
Logo
cwb_dump_inj.C
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Gabriele Vedovato
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 // dump the list of injections : used by the cwb_dump command
20 
21 {
22  #include <vector>
23 
25 
26  TB.checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
27  TB.checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
28  TB.checkFile(gSystem->Getenv("CWB_UPARAMETERS_FILE"));
29 
30  network NET; // network
31 
32  if(!simulation) {
33  cout << "cwb_dump_inj.C : dump injection type list works only in simulation mode !!!" << endl;
34  exit(1);
35  }
36 
37  if(TString(frFiles[nIFO])!="") { // MDC from frame files : read MDC list from MDC frames log file
38 
39  cout << "cwb_dump_inj.C : Opening MDC frame file ... " << frFiles[nIFO] << endl;
40  TB.checkFile(frFiles[nIFO]);
41  CWB::frame ifr(frFiles[nIFO]);
42  int nfrFiles=ifr.getNfiles();
43  cout << "MDC " << " -> nfrFiles : " << nfrFiles << endl;
44  waveSegment mdc_range = ifr.getFrRange();
45  cout << "mdc_range : " << mdc_range.start << " " << mdc_range.stop << endl;
46  double GPS = (mdc_range.stop+mdc_range.start)/2;
47  int nINJ = NET.readMDClog(injectionList,GPS);
48  printf("GPS: %16.6f saved, injections: %d\n",GPS,nINJ);
49  //for(int i=0;i<NET.mdcType.size();i++) cout << i << " " << NET.mdcType[i] << endl;
50  //for(int i=0;i<NET.mdcTime.size();i++) cout << i << " " << NET.mdcTime[i] << endl;
51 
52  } else { // MDC from cWB engine : read MDC list from configPlugin
53 
54  cout << "cwb_dump_inj.C : read MDC list from configPlugin ... " << configPlugin.GetTitle() << endl;
55  TB.checkFile(configPlugin.GetTitle());
56 
57  // export to CINT net,cfg
58  char cmd[128];
59  sprintf(cmd,"network* net = new network;");
60  gROOT->ProcessLine(cmd);
62  cfg->Import();
63  sprintf(cmd,"CWB::config* cfg = (CWB::config*)%p;",cfg);
64  gROOT->ProcessLine(cmd);
65  sprintf(cmd,"int gIFACTOR=1;");
66  gROOT->ProcessLine(cmd);
67  // exec config plugin
68  configPlugin.Exec();
69 // MDC.Print();
70 
71  // fill mdcType list
72  NET.mdcType.clear();
73  if(MDC.GetInspiral()!="") { // inspiral MDC type
74  NET.mdcType.push_back(MDC.GetInspName.Data());
75  } else { // burst MDC type
76  int size = MDC.wfList.size();
77  for(int i=0;i<size;i++) {
78  bool save=true;
79  for(int j=0; j<(int)NET.mdcType.size(); j++){
80  if(MDC.wfList[i].name.CompareTo(NET.mdcType[j])==0) {save = false; break;}
81  }
82  if(save) {
83  NET.mdcType.push_back(MDC.wfList[i].name.Data());
84  }
85  }
86  }
87  //cout.precision(14);
88  //for(int k=0;k<(int)NET.mdcType.size();k++) cout << k << " mdcType " << NET.mdcType[k] << endl;
89  }
90 
91  if(NET.mdcType.size()==0) {
92  cout << endl << "cwb_dump_inj.C - Error : injection types not found !!! " << endl << endl;
93  exit(1);
94  }
95 
96  // dump the inj list to file
97 
98  char mdc_inj_file[1024];
99  sprintf(mdc_inj_file,"%s/%s.inj",dump_dir,data_label);
100  bool overwrite=TB.checkFile(mdc_inj_file,true);
101  if(!overwrite) gSystem->Exit(1);
102 
103  FILE* fP;
104  if((fP = fopen(mdc_inj_file, "w")) == NULL) {
105  cout << "cwb_dump_inj.C : cannot open output file " << mdc_inj_file <<". \n";
106  exit(1);
107  };
108  cout << "Write output file : " << mdc_inj_file << endl << endl;
109  for(int i=0;i<NET.mdcType.size();i++) {
110  char ostr[256];
111  sprintf(ostr,"MDC_SET\t%4d\t%20s\t%6.0f\t%6.0f",i,NET.mdcType[i].data(),(fLow+fHigh)/2.,(fHigh-fLow)/2.);
112  cout << ostr << endl;
113  fprintf(fP,"%s\n",ostr);
114  }
115  fclose(fP);
116 
117  char cmd[256];
118  sprintf(cmd,"sort -k 3 -d %s > %s",mdc_inj_file,TString(mdc_inj_file).ReplaceAll(".inj",".inj.tmp").Data());
119  //cout << cmd << endl;
120  gSystem->Exec(cmd);
121  sprintf(cmd,"mv %s %s",TString(mdc_inj_file).ReplaceAll(".inj",".inj.tmp").Data(),mdc_inj_file);
122  //cout << cmd << endl;
123  gSystem->Exec(cmd);
124  cout << endl;
125  cout << "Output inj MDC file : " << mdc_inj_file << endl << endl;
126 
127  exit(0);
128 }
double start
Definition: network.hh:55
size_t readMDClog(char *, double=0., int=11, int=12)
param: MDC log file param: approximate gps time
Definition: network.cc:3370
double fHigh
TString("c")
CWB::config * cfg
Definition: cwb_dump_inj.C:61
char frFiles[NIFO_MAX+1][256]
Definition: test_config1.C:166
CWB::Toolbox TB
std::vector< std::string > mdcType
Definition: network.hh:613
CWB::mdc * MDC
Long_t size
int j
Definition: cwb_net.C:28
i drho i
void Import(TString umacro="")
Definition: config.cc:352
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:4670
FILE * fP
Definition: cwb_dump_inj.C:103
waveSegment getFrRange()
Definition: frame.hh:107
char injectionList[1024]
fprintf(stdout,"start=%f duration=%f rate=%f\, x.start(), x.size()/x.rate(), x.rate())
#define nIFO
char data_label[512]
Definition: test_config1.C:160
char mdc_inj_file[1024]
Definition: cwb_dump_inj.C:98
i() int(T_cor *100))
network NET
Definition: cwb_dump_inj.C:30
char cmd[128]
Definition: cwb_dump_inj.C:58
printf("total live time: non-zero lags = %10.1f \, liveTot)
int getNfiles()
Definition: frame.hh:110
int nfrFiles[nIFO+1]
Definition: cwb_net.C:192
vector< waveform > wfList
Definition: mdc.hh:387
condor_log_dir ReplaceAll("X_HOME", uhome.Data())
double fLow
char dump_dir[512]
Definition: test_config1.C:156
#define GPS
bool overwrite
Definition: cwb_dump_inj.C:100
TMacro configPlugin
bool save
simulation
Definition: cwb_eced.C:26
fclose(ftrig)
TString config
double stop
Definition: network.hh:56
sprintf(cmd,"network* net = new network;")
exit(0)