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