Logo coherent WaveBurst  
Library Reference Guide
Logo
cwb_inet.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 // interactive cwb pipeline (1G & 2G)
20 
21 {
23 
24  TB.checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
25  TB.checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
26  //TB.checkFile(gSystem->Getenv("CWB_UPARAMETERS_FILE"));
27  TB.checkFile(gSystem->Getenv("CWB_NETC_FILE"));
28 
29  TString cwb_batch="false";
30  if(gSystem->Getenv("CWB_BATCH")!=NULL) {
31  cwb_batch=TString(gSystem->Getenv("CWB_BATCH"));
32  }
33 
34  if(cwb_batch=="false") strcpy(nodedir,tmp_dir); // tmp_dir is used in interactive mode
35  strcpy(output_dir,data_dir); // default
36 
37  int cwb_jobid=0;
38  if(gSystem->Getenv("CWB_JOBID")==NULL) {
39  cout << "Error : environment CWB_JOBID is not defined!!!" << endl;exit(1);
40  } else {
41  if(TString(gSystem->Getenv("CWB_JOBID")).IsDigit()) {
42  cwb_jobid=TString(gSystem->Getenv("CWB_JOBID")).Atoi();
43  } else {
44  cout << "Error : environment CWB_JOBID is not defined!!!" << endl;exit(1);
45  }
46  }
47 
48  if(gSystem->Getenv("CWB_CED_DIR")!=NULL) {
49  TString cwb_ced_dir=TString(gSystem->Getenv("CWB_CED_DIR"));
50  if(cwb_ced_dir.Sizeof()>1) {
51  TB.checkFile(cwb_ced_dir);
52  strcpy(output_dir,cwb_ced_dir.Data()); // user defined
53  }
54  }
55 
56  TString cwb_inet_options=TString(gSystem->Getenv("CWB_INET_OPTIONS"));
57  if(cwb_inet_options.CompareTo("")!=0) {
58  TString inet_options = cwb_inet_options;
59  //inet_options.ToUpper();
60  if(!inet_options.Contains("--")) { // parameters are used only by cwb_inet
61 
62  TObjArray* token = TString(inet_options).Tokenize(TString(' '));
63  for(int j=0;j<token->GetEntries();j++){
64 
65  TObjString* tok = (TObjString*)token->At(j);
66  TString stok = tok->GetString();
67 
68  if(stok=="true") cedDump = true;
69  if(stok=="ced") cedDump = true;
70  if(stok=="false") cedDump = false;
71  if(stok=="root") cedDump = true;
72  if(stok.Contains("cedDump=")) {
73  TString cedDump_par=stok;
74  cedDump_par.Remove(0,cedDump_par.Last('=')+1);
75  if(cedDump_par=="true") cedDump=true;
76  if(cedDump_par=="false") cedDump=false;
77  }
78 
79  if(stok.Contains("gps=")) {
80  TString gps_par=stok;
81  gps_par.Remove(0,gps_par.Last('=')+1);
82  if(gps_par.IsFloat()) gSystem->Setenv("CWB_GPS_EVENT",gps_par);
83  }
84  if(stok.Contains("iwindow=")) {
85  TString iwindow_par=stok;
86  iwindow_par.Remove(0,iwindow_par.Last('=')+1);
87  if(iwindow_par.IsFloat()) gap=iwindow_par.Atof();
88  }
89  if(stok.Contains("netCC=")) {
90  TString netCC_par=stok;
91  netCC_par.Remove(0,netCC_par.Last('=')+1);
92  if(netCC_par.IsFloat()) netCC=netCC_par.Atof();
93  }
94  if(stok.Contains("Acore=")) {
95  TString Acore_par=stok;
96  Acore_par.Remove(0,Acore_par.Last('=')+1);
97  if(Acore_par.IsFloat()) Acore=Acore_par.Atof();
98  }
99  if(stok.Contains("dump=")) {
100  TString dump_par=stok;
101  dump_par.Remove(0,dump_par.Last('=')+1);
102  if(dump_par=="true") dump=true;
103  if(dump_par=="false") dump=false;
104  }
105  if(stok.Contains("plugin=")) {
106  TString plugin_par=stok;
107  plugin_par.Remove(0,plugin_par.Last('=')+1);
108  if(plugin_par.EndsWith(".C")) plugin=TMacro(plugin_par);
109  }
110  if(stok.Contains("search=")) {
111  TString search_par=stok;
112  search_par.Remove(0,search_par.Last('=')+1);
113  if(search_par=="r") SEARCH()='r';
114  if(search_par=="i") SEARCH()='i';
115  if(search_par=="p") SEARCH()='p';
116  if(search_par=="l") SEARCH()='l';
117  if(search_par=="c") SEARCH()='c';
118  if(search_par=="e") SEARCH()='e';
119  if(search_par=="s") SEARCH()='s';
120  if(search_par=="g") SEARCH()='g';
121  if(search_par=="b") SEARCH()='b';
122  }
123  if(stok.Contains("optim=")) {
124  TString optim_par=stok;
125  optim_par.Remove(0,optim_par.Last('=')+1);
126  if(optim_par=="true") optim=true;
127  if(optim_par=="false") optim=false;
128  }
129 
130  }
131 
132  } else { // parameters are used only by CWB_Plugin_cwb_inet.C
133 
134  // get CWB_Plugin_cwb_inet.C
135  TMacro cwb_inet_plugin = gSystem->ExpandPathName("$HOME_WAT/tools/cwb/plugins/CWB_Plugin_cwb_inet.C");
136  // creates a temporary file name
137  char fpluginName[1024];
138  unsigned int Pid = gSystem->GetPid(); // used to tag in a unique way the temporary files
139  sprintf(fpluginName,"%s/CWB_Plugin_cwb_inet_%s_%d_job%d.XXXXXX",
140  tmp_dir,data_label,Pid,cwb_jobid);
141  CWB::Toolbox::mksTemp(fpluginName); // create temporary file, must be deleted only at the end of run
142  // write plugin, if plugin is defined then we merge cwb_inet_plugin & plugin
143  ofstream out;
144  out.open(fpluginName,ios::out);
145  if(!out.good()) {cout << "cwb_inet.C - Error : Opening File : " << fpluginName << endl;gSystem->Exit(1);}
146  if(TString(plugin.GetName())!="") {
147  TList* fLines = plugin.GetListOfLines();
148  TObjString *obj;
149  TIter next(fLines);
150  out << "// --> BEGIN USER PLUGIN CODE" << endl;
151  while ((obj = (TObjString*) next())) {
152  TString line = obj->GetName();
153  line.ReplaceAll("CWB_Plugin(","CWB_UserPlugin("); // rename plugin name
154  out << line.Data() << endl;
155  }
156  out << "// --> END USER PLUGIN CODE" << endl << endl;
157  }
158  // write CWB_Plugin_cwb_inet.C code
159  TList* fLines = cwb_inet_plugin.GetListOfLines();
160  TObjString *obj;
161  TIter next(fLines);
162  out << "// --> BEGIN CWB_INET PLUGIN CODE" << endl;
163  while ((obj = (TObjString*) next())) {
164  TString line = obj->GetName();
165  out << line.Data() << endl;
166  // add CWB_PLUGIN (user plugin) call after the CWB_Plugin line
167  if((TString(plugin.GetName())!="")&&(line.Contains("CWB_Plugin("))) {
168  out << endl;
169  out << " CWB_UserPlugin(jfile, cfg, net, x, ifo, type); // CALL USER PLUGIN CODE" << endl;
170  out << endl;
171  }
172  }
173  out << "// --> END CWB_INET PLUGIN CODE" << endl;
174  out.close();
175 
176  if(cwb_inet_options.Contains("frdisplay")) plugin = fpluginName;
177  if(cwb_inet_options.Contains("psd")) plugin = fpluginName;
178  if(cwb_inet_options.Contains("inj")) plugin = fpluginName;
179  if(cwb_inet_options.Contains("wdm")) plugin = fpluginName;
180  if(cwb_inet_options.Contains("nrms")) plugin = fpluginName;
181  if(cwb_inet_options.Contains("emax")) plugin = fpluginName;
182  if(cwb_inet_options.Contains("sparse")) plugin = fpluginName;
183  if(cwb_inet_options.Contains("ced")) plugin = fpluginName;
184  plugin.SetName(fpluginName);
185  }
186  }
187 
188  int gps_event=0;
189  TString cwb_gps_event=TString(gSystem->Getenv("CWB_GPS_EVENT"));
190  if(cwb_gps_event.CompareTo("")!=0) {
191  if(!cwb_gps_event.IsFloat()) {cout<< "Error : CWB_GPS_EVENT is not a number" << endl;exit(1);}
192  if(cwb_gps_event.Atoi()>0) gps_event=cwb_gps_event.Atoi();
193  }
194 
195  network NET_CED; // network
196  detector* pD_CED[NIFO_MAX]; // pointers to detectors
197  for(int n=0;n<NIFO_MAX;n++) pD_CED[n]=NULL;
198 
199  segTHR=0; // remove the cat2 check
200  if(simulation) {
201  float mdc_factor=0;
202  TString cwb_mdc_factor=TString(gSystem->Getenv("CWB_MDC_FACTOR"));
203  if(cwb_mdc_factor.CompareTo("")!=0) {
204  if(!cwb_mdc_factor.IsFloat()) {cout<< "Error : CWB_MDC_FACTOR is not a number" << endl;exit(1);}
205  if(cwb_mdc_factor.Atof()>0) mdc_factor=cwb_mdc_factor.Atof();
206  }
207  if(mdc_factor!=0) {
208  nfactor=1;
209  factors[0]=mdc_factor;
210  }
211  } else {
212  int job_lag=-1; // if <0 all lags defined in user parameters are selected
213  TString cwb_job_lag=TString(gSystem->Getenv("CWB_JOB_LAG"));
214  if(cwb_job_lag.CompareTo("")!=0) {
215  if(!cwb_job_lag.IsFloat()) {cout<< "Error : CWB_JOB_LAG is not a number" << endl;exit(1);}
216  job_lag=cwb_job_lag.Atoi();
217  }
218 
219  // select only one lag
220  if(job_lag>=0) {
221  mlagStep= 0;
222  lagSize = 1; // number of lags (simulation=1)
223  lagOff = job_lag; // first lag id (lagOff=0 - include zero lag )
224  } else job_lag=0;
225 
226  for(int i=0; i<nIFO; i++) {
227  if(strlen(ifo[i])>0) pD_CED[i] = new detector(ifo[i]); // built in detector
228  else pD_CED[i] = new detector(detParms[i]); // user define detector
229  }
230 
231  for(int i=0; i<nIFO; i++) NET_CED.add(pD_CED[i]);
232 
233  // WARNING : segLen now is fixed, should be constrained by cat1 !!!
234 
235  wavearray<double> x(segLen*16384);
236  x.rate(16384.);
237  pD_CED[0]->TFmap=x;
238 
240  cout<<"lag step: "<<lagStep<<endl;
241  cout<<"number of time lags_ced : " << lags_ced << endl;
242 
243  // print selected lag
244  printf("%8s ","lag");
245  for(int n=0; n<nIFO; n++) printf("%12.12s%2s","ifo",NET_CED.getifo(n)->Name);
246  printf("\n");
247  printf("%8d ",job_lag);
248  for(int n=0; n<nIFO; n++) printf("%14.5f",pD_CED[n]->lagShift.data[0]);
249  printf("\n");
250 
251  pD_CED[0]->TFmap.resize(0);
252  }
253 
254  if(gps_event==0) return;
255 
256  // dq file list
257  // {ifo, dqcat_file, dqcat[0/1/2], shift[sec], inverse[false/true], 4columns[true/false]}
258 
259  if(gps_event>0) {
260  for(int n=0; n<nIFO; n++) {
261 
262  strcpy(DQF[nDQF].ifo, ifo[n]);
263  sprintf(DQF[nDQF].file, "%s/%s_%s.gps_%d",tmp_dir,ifo[n],data_label,int(gps_event));
264  DQF[nDQF].cat = CWB_CAT2;
265  DQF[nDQF].shift = 0.;
266  DQF[nDQF].invert = false;
267  DQF[nDQF].c4 = true;
268  nDQF++;
269 
270  cout << DQF[nDQF-1].file << endl;
271 
272  ofstream out;
273  out.open(DQF[nDQF-1].file,ios::out);
274  cout << "Write file : " << DQF[nDQF-1].file << endl;
275  if (!out.good()) {cout << "Error Opening File : " << DQF[nDQF-1].file << endl;exit(1);}
276  out.precision(14);
277  if(simulation) {
278  int istart = int(gps_event)-gap;
279  int istop = int(gps_event)+gap;
280  out << "1 " << istart << " " << istop << " " << 2*gap << endl;
281  } else {
282  int jobSegLen = 0;
283  if(slagSize>0) { // SLAG Segments
284  if(slagSize==1) {
285  if((slagMin!=0)||(slagMax!=0)||(slagOff!=0)||(slagFile!=NULL)) {
286  cout << "cwb_inet gps_event>1 is not implemented with : !!!" << endl;
287  cout << "if slagSize=1 -> slagMin=slagMax=slagOff=0, slagFile=NULL "<<endl;
288  exit(1);
289  }
290  } else {
291  cout << "cwb_inet gps_event>1 is not implemented with slagSize>1 !!!" << endl;
292  exit(1);
293  }
294  } else { // Standard Segments
296  vector<waveSegment> cat1List=TB.readSegList(nDQF, DQF, dqcat);
297  vector<waveSegment> jobList=TB.getJobList(cat1List, segLen, segMLS, segEdge); // get standard job list
298  if(jobList.size()==0) {
299  cout << endl << "cwb_inet standard job list size = 0 !!!" << endl << endl;
300  exit(1);
301  }
302  jobSegLen = jobList[cwb_jobid-1].stop-jobList[cwb_jobid-1].start;
303  }
304 
305  double tShift = pD_CED[n]->lagShift.data[0] - pD_CED[0]->lagShift.data[0];
306  if(tShift<0) tShift=jobSegLen-fabs(tShift);
307 
308  int istart = int(gps_event+tShift)-gap;
309  int istop = int(gps_event+tShift)+gap;
310  out << n+1 << " " << istart << " " << istop << " " << 2*gap << endl;
311  }
312  out.close();
313  }
314  }
315 
316  for(int n=0; n<nIFO; n++) if(pD_CED[n]!=NULL) delete pD_CED[n];
317 }
detector * getifo(size_t n)
param: detector index
Definition: network.hh:436
double segMLS
Definition: test_config1.C:47
virtual void resize(unsigned int)
Definition: wseries.cc:901
int slagSize
Definition: test_config1.C:65
double lagStep
Definition: test_config1.C:53
int slagOff
Definition: test_config1.C:68
size_t add(detector *)
param: detector structure return number of detectors in the network
Definition: network.cc:2559
virtual void rate(double r)
Definition: wavearray.hh:141
size_t * lagSite
Definition: test_config1.C:58
int n
Definition: cwb_net.C:28
bool invert
Definition: Toolbox.hh:88
TString("c")
ofstream out
Definition: cwb_merge.C:214
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<< "\ layers : "<< nLAYERS<< "\ dF(hz) : "<< dF<< "\ 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
bool c4
Definition: Toolbox.hh:89
bool optim
CWB_CAT dqcat
int slagMax
Definition: test_config1.C:67
CWB::Toolbox TB
static int mksTemp(char *fTemplate)
Definition: Toolbox.hh:341
CWB_CAT
Definition: Toolbox.hh:72
size_t lagOff
Definition: test_config1.C:54
double & gap
double segEdge
Definition: test_config1.C:49
int j
Definition: cwb_net.C:28
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:4670
double netCC
Definition: test_config1.C:33
char ifo[NIFO_MAX][8]
nDQF
Definition: cwb_eced.C:109
double Acore
Definition: test_config1.C:28
double segTHR
Definition: test_config1.C:48
#define nIFO
CWB_CAT cat
Definition: Toolbox.hh:86
char data_label[512]
Definition: test_config1.C:160
char file[1024]
Definition: Toolbox.hh:85
char tmp_dir[512]
Definition: test_config1.C:153
char lagMode[2]
Definition: test_config1.C:57
int cwb_jobid
Definition: cwb_frdisplay.C:26
TString cwb_job_lag
Definition: cwb_inet.C:213
vector< int > jobList
i() int(T_cor *100))
const int NIFO_MAX
Definition: wat.hh:22
dqfile DQF[12]
Definition: test_config1.C:171
TString cwb_batch
Definition: cwb_inet.C:29
printf("total live time: non-zero lags = %10.1f \, liveTot)
int mlagStep
TIter next(twave->GetListOfBranches())
segLen
Definition: cwb_eced.C:24
double shift
Definition: Toolbox.hh:87
char data_dir[512]
Definition: test_config1.C:152
vector< waveSegment > cat1List
TObjArray * token
wavearray< double > lagShift
Definition: detector.hh:369
static vector< waveSegment > getJobList(vector< waveSegment > ilist, double segLen=600., double segMLS=300., double segEdge=8.)
Definition: Toolbox.cc:646
WSeries< double > TFmap
Definition: detector.hh:354
static vector< waveSegment > readSegList(dqfile DQF)
Definition: Toolbox.cc:409
else job_lag
Definition: cwb_inet.C:224
char Name[16]
Definition: detector.hh:327
double fabs(const Complex &x)
Definition: numpy.cc:55
int gps_event
Definition: cwb_inet.C:188
char * lagFile
Definition: test_config1.C:56
strcpy(RunLabel, RUN_LABEL)
int nfactor
Definition: test_config1.C:83
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
TMacro plugin
bool dump
slagFile
Definition: cwb_tune_slag.C:25
DataType_t * data
Definition: wavearray.hh:319
network NET_CED
Definition: cwb_inet.C:195
char nodedir[1024]
Definition: test_config1.C:187
int slagMin
Definition: test_config1.C:66
TString cwb_gps_event
Definition: cwb_inet.C:189
char line[1024]
simulation
Definition: cwb_eced.C:26
detectorParams detParms[4]
factors[0]
Definition: cwb_eced.C:27
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:7321
char output_dir[512]
Definition: test_config1.C:146
#define SEARCH(TYPE)
Definition: xroot.hh:4
size_t lagMax
Definition: test_config1.C:55
bool cedDump
exit(0)
detector * pD_CED[NIFO_MAX]
Definition: cwb_inet.C:196
size_t lagSize
Definition: test_config1.C:52