Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cwb_eced.C
Go to the documentation of this file.
1 // 1G easy ced : an interactive command to produce CED
2 
3 {
5  char cmd[1024];
6 
7  segLen=60;
8  cedRHO=0.0; // disable the cedRHO threshold
10  nfactor[0]=1;
11 
12  // variables where to save the user parameters definitions
13  int _nIFO=0;
18  dqfile _DQF[20];int _nDQF=0;
19 
20  char channelTypesRaw[NIFO_MAX][1024]; // detector data types - used only for cwb_eced by gw_data_find
21  for(int i=0;i<NIFO_MAX;i++) strcpy(channelTypesRaw[i],"");
22 
23  unsigned int Pid = gSystem->GetPid(); // used to tag in a unique way the temporary files
24  char tag[256];sprintf(tag,"%d",Pid);
25 
26  // get cluster site
28  if(gSystem->Getenv("SITE_CLUSTER")!=NULL) {
29  site_cluster=TString(gSystem->Getenv("SITE_CLUSTER"));
30  }
31 
32  // get env options
33  int gps_event=0;
34  TString cwb_eced_opts=TString(gSystem->Getenv("CWB_ECED_OPTS"));
36  if(cwb_eced_opts!="") {
37  if(cwb_eced_opts.IsFloat()) { // env CWB_ECED_OPTS contains only the gps_event
38  gps_event=cwb_eced_opts.Atoi();
39  cwb_eced_opts="";
40  } else { // more options
41  TString ECED_CFG = TB.getParameter(cwb_eced_opts,"--cfg");
42  if(ECED_CFG!="") {
43  TB.checkFile(gSystem->ExpandPathName(ECED_CFG.Data()));
44  gROOT->Macro(gSystem->ExpandPathName(ECED_CFG.Data())); // set cfg user define cwb parameters
45  eced_cfg=ECED_CFG;
46  }
47 
48  TString ECED_GPS = TB.getParameter(cwb_eced_opts,"--gps"); // set event gps time
49  if(ECED_GPS.IsFloat()) gps_event=ECED_GPS.Atoi();
50 
51  TString ECED_FACTOR = TB.getParameter(cwb_eced_opts,"--factor"); // set factor
52  if(ECED_FACTOR.IsFloat()) factor[0]=ECED_FACTOR.Atof();
53 
54  TString ECED_SEARCH = TB.getParameter(cwb_eced_opts,"--search"); // set search type
55  if(ECED_SEARCH.Sizeof()==2) SEARCH()=ECED_SEARCH[0];
56 
57  TString ECED_SIM = TB.getParameter(cwb_eced_opts,"--sim"); // set simulation mode
58  if(ECED_SIM.IsFloat()) {
59  int sim = ECED_SIM.Atoi();
60  if((sim<0)&&(sim>2)) {
61  cout << "Error : bad --sim value [0/1/2] !!!" << endl;
62  gSystem->Exit(1);
63  } else simulation=sim;
64  }
65 
66  TString ECED_TAG = TB.getParameter(cwb_eced_opts,"--tag"); // set directory user TAG
67  if(ECED_TAG!="") strcpy(tag,ECED_TAG.Data());
68  }
69  }
70  if(gps_event<=0) {
71  cout << "cwb_eced - Error : gps_event must be > 0, check config/user_parameters.C" << endl;
72  gSystem->Exit(1);
73  } else {
74  char sgps_event[16];sprintf(sgps_event,"%f",gps_event);
75  gSystem->Setenv("CWB_GPS_EVENT",sgps_event);
76  }
77 
78  // get evn ndet parameters
79  if(gSystem->Getenv("CWB_ECED_NDET")!=NULL) {
80  if(TString(gSystem->Getenv("CWB_ECED_NDET")).IsDigit()) {
81  nIFO=TString(gSystem->Getenv("CWB_ECED_NDET")).Atoi();
82  if(nIFO==0) {
83  cout << "cwb_eced - Error : ifos are not defined" << endl;
84  gSystem->Exit(1);
85  }
86  } else {
87  cout << "Error : environment CWB_ECED_NDET is not defined!!!" << endl;
88  gSystem->Exit(1);
89  }
90  }
91 
92  nDQF=0;
93  for(int n=0;n<nIFO;n++) {
94  TString ecedOptions;
95  char cwb_eced_det[64]; sprintf(cwb_eced_det,"CWB_ECED_DET%d",n+1);
96  if(gSystem->Getenv(cwb_eced_det)!=NULL) {
97  ecedOptions=TString(gSystem->Getenv(cwb_eced_det));
98 
99  // if ecedOptions = L1,H1,H2,V1,G1
100  if(ecedOptions.Sizeof()==3) {
101  strcpy(ifo[n],ecedOptions.Data());
102  ecedOptions="";
103  } else {
104  TString ECED_IFO = TB.getParameter(ecedOptions,"--ifo");
105  if(ECED_IFO!="") strcpy(ifo[n],ECED_IFO.Data());
106  else {cout << "Error : Inline param --ifo is not defined!!!" << endl;exit(1);}
107  }
108 
109  TString ECED_TYPE = TB.getParameter(ecedOptions,"--type");
110  if(ECED_TYPE!="") strcpy(channelTypesRaw[n],ECED_TYPE.Data());
111  else { // search the definitions in the user configuration file
112  for(int i=0;i<_nIFO;i++) if(_ifo[i]==ifo[n]) strcpy(channelTypesRaw[n],_frFiles[i].Data());
113  for(int i=0;i<_nIFO;i++) if(_ifo[i]==ifo[n]) strcpy(channelTypesRaw[n+nIFO],_frFiles[i+_nIFO].Data());
114  }
115 
116  TString ECED_CHRAW = TB.getParameter(ecedOptions,"--chraw");
117  if(ECED_CHRAW!="") strcpy(channelNamesRaw[n],ECED_CHRAW.Data());
118  else { // search the definitions in the user configuration file
119  for(int i=0;i<_nIFO;i++) if(_ifo[i]==ifo[n]) strcpy(channelNamesRaw[n],_channelNamesRaw[i].Data());
120  }
121 
122  TString ECED_CHMDC = TB.getParameter(ecedOptions,"--chmdc");
123  if(ECED_CHMDC!="") strcpy(channelNamesMDC[n],ECED_CHMDC.Data());
124  else { // search the definitions in the user configuration file
125  for(int i=0;i<_nIFO;i++) if(_ifo[i]==ifo[n]) strcpy(channelNamesMDC[n],_channelNamesMDC[i].Data());
126  }
127 
128  TString ECED_SHIFT = TB.getParameter(ecedOptions,"--shift");
129  if(ECED_SHIFT!="") {
130  if(ECED_SHIFT.IsFloat()) {
131  dataShift[n] = ECED_SHIFT.Atof();
132  if(fmod(dataShift[n],1)!=0)
133  {cout << "Error : shift parameter is not an integer number!!! " << ECED_SHIFT << endl;gSystem->Exit(1);}
134  for(int i=0;i<nDQF;i++) DQF[i].shift+=ECED_SHIFT.Atof();
135  } else {cout << "Error : shift parameter is not a number!!! " << ECED_SHIFT << endl;gSystem->Exit(1);}
136  } else { // search the definitions in the user configuration file
137  //for(int i=0;i<_nIFO;i++) if(_ifo[i]==ifo[n]) strcpy(dataShift[n],_channelNamesMDC[i].Data());
138  }
139 
140  // copy DQ definitions
141  for(int i=0;i<_nDQF;i++) if(TString(_DQF[i].ifo)==ifo[n]) DQF[nDQF++]=_DQF[i];
142 
143  cout << n << " ifo " << ifo[n] << " type " << channelTypesRaw[n]
144  << " chraw " << channelNamesRaw[n] << " chmdc " << channelNamesMDC[n] << endl;
145  }
146  }
147  for(int i=0;i<nDQF;i++) cout << "DQF : " << i << " " << DQF[i].ifo << " " << DQF[i].file << endl;
148 
149  // set reference ifo
150  strcpy(refIFO,ifo[0]);
151 
152  // select default job segment parameters
153  if(segLen<60) segLen=60;
154  segMLS = segLen;
155  segTHR = 0;
156 
157  // force nfactor=1
158  nfactor = 1;
159  // for background force nfactor[0]=1
160  if(simulation==0) nfactor[0]=1;
161 
162  // select a segment of 60 sec around the event gps time
163  int gps_start = int(gps_event)-(int(segLen/2.+1)+segEdge);
164  int gps_stop = int(gps_event)+(int(segLen/2.+1)+segEdge);
165 
166  // if not defined then set default Raw channel names & channel types
167  for(int n=0;n<nIFO;n++) {
168 
169  TString ECED_IFO = ifo[n];
170 
171  if(ECED_IFO=="L1") {
172  if(TString(channelNamesRaw[n])=="") sprintf(channelNamesRaw[n],"L1:LDAS-STRAIN");
173  if(TString(channelTypesRaw[n])=="") sprintf(channelTypesRaw[n],"L1_LDAS_C02_L2");
174  } else
175  if(ECED_IFO=="H1") {
176  if(TString(channelNamesRaw[n])=="") sprintf(channelNamesRaw[n],"H1:LDAS-STRAIN");
177  if(TString(channelTypesRaw[n])=="") sprintf(channelTypesRaw[n],"H1_LDAS_C02_L2");
178  } else
179  if(ECED_IFO=="H2") {
180  if(TString(channelNamesRaw[n])=="") sprintf(channelNamesRaw[n],"H2:LDAS-STRAIN");
181  if(TString(channelTypesRaw[n])=="") sprintf(channelTypesRaw[n],"H2_LDAS_C02_L2");
182  } else
183  if(ECED_IFO=="V1") {
184  if(TString(channelNamesRaw[n])=="") sprintf(channelNamesRaw[n],"V1:h_16384Hz");
185  if(TString(channelTypesRaw[n])=="") sprintf(channelTypesRaw[n],"HrecV2");
186  } else
187  if(ECED_IFO=="G1") {
188  if(TString(channelNamesRaw[n])=="") sprintf(channelNamesRaw[n],"G1:DER_DATA_H");
189  if(TString(channelTypesRaw[n])=="") sprintf(channelTypesRaw[n],"G1_RDS_C01_L3");
190  }
191  }
192 
193  TString cwb_inet_opts=TString(gSystem->Getenv("CWB_INET_OPTIONS"));
194  // define eced directory
195  char eced_dir[1024]="ECED_";
196  for(int n=0;n<nIFO;n++) sprintf(eced_dir,"%s%s",eced_dir,ifo[n]);
197  sprintf(eced_dir,"%s_TAG%s",eced_dir,tag);
198  if(cwb_inet_opts=="ced") {
199  sprintf(eced_dir,"%s_GPS%d",eced_dir,gps_event);
200  // Check if eced_dir exist
201  Long_t id,size,flags,mt;
202  int estat = gSystem->GetPathInfo(eced_dir,&id,&size,&flags,&mt);
203  if(estat==0) {
204  cout << "cwb_eced - Error : directory " << eced_dir << " already exist " << endl;
205  gSystem->Exit(1);
206  }
207  }
208  // redefine eced working directories
209  sprintf(tmp_dir, "%s/tmp",eced_dir);
210  sprintf(data_dir, "%s/tmp",eced_dir);
211  sprintf(config_dir,"%s/tmp",eced_dir);
212  sprintf(input_dir, "%s/tmp",eced_dir);
213  sprintf(output_dir,"%s/tmp",eced_dir);
214  sprintf(macro_dir, "%s/tmp",eced_dir);
215  sprintf(report_dir,"%s/tmp",eced_dir);
216  sprintf(log_dir, "%s/tmp",eced_dir);
217  sprintf(condor_dir,"%s/tmp",eced_dir);
218  sprintf(merge_dir, "%s/tmp",eced_dir);
219  sprintf(pp_dir, "%s/tmp",eced_dir);
220  sprintf(dump_dir, "%s/tmp",eced_dir);
221  if(cwb_inet_opts=="ced") {
222  sprintf(ced_dir, "%s/ced",eced_dir);
223  } else {
224  sprintf(ced_dir, "%s/output",eced_dir);
225  }
226 
227  // check if frame files are available with gw_data_find command
228  // fill ldf_command array to get frame files list for each detector
229  bool ldf_gcheck=true;
231  char ldf_command[NIFO_MAX][1024];
232  for(int i=0;i<NIFO_MAX;i++) {strcpy(ldf_command[i],"");ldf_check[i]=true;}
233  for(int n=0;n<nIFO;n++) {
234 
235  if(TString(channelTypesRaw[n]).Contains(".")) { // if type contains '.' then type is a frame files list
236  // set input frame file
237  strcpy(frFiles[n],channelTypesRaw[n]);
238  strcpy(frFiles[n+nIFO],channelTypesRaw[n+nIFO]);
239  continue;
240  }
241 
242  // check cluster
243  if((site_cluster!="CIT")&&(site_cluster!="ATLAS")) {
244  cout << "cwb_eced error : gw_data_find can be used only in CIT or ATLAS cluster" << endl;
245  gSystem->Exit(1);
246  }
247 
248  // eced is enabled only for L1,H1,H2,V1,G1 detectors
249  // gw_data_find is define only for such detectors
250  if(strcmp(ifo[n],"L1")&&strcmp(ifo[n],"H1")&&strcmp(ifo[n],"H2")&&strcmp(ifo[n],"V1")&&strcmp(ifo[n],"G1")) {
251  cout << "cwb_eced - Error : declared ifo " << ifo[n]
252  << " not enabled for eced (must be L1 or H1 or H2 or V1 or G1)" << endl;
253  gSystem->Exit(1);
254  }
255 
256  TString ECED_IFO = ifo[n];
257 
258  strcpy(ldf_command[n],"gw_data_find");
259 
260  // select the observatory
261  char observatory[4]="";
262  if(ECED_IFO=="L1") strcpy(observatory,"L");
263  if(ECED_IFO=="H1") strcpy(observatory,"H");
264  if(ECED_IFO=="H2") strcpy(observatory,"H");
265  if(ECED_IFO=="V1") strcpy(observatory,"V");
266  if(ECED_IFO=="G1") strcpy(observatory,"G");
267 
268  sprintf(ldf_command[n],"%s --observatory=%s",ldf_command[n],observatory);
269 
270  // select type
271  if(TString(channelNamesRaw[n])=="") {
272  cout << "cwb_eced - Error : strain channel name for ifo " << ifo[n]
273  << " not defined, check parameter channelNamesRaw[" << n << "] in config/user_parameters.C" << endl;
274  gSystem->Exit(1);
275  }
276 
277  // create temporary files to store gw_data_find output
278  FILE* fp = gSystem->TempFileName("eced");
279  TString tmpFile = TB.getFileName(fp);
280  fclose(fp);
281 
282  sprintf(ldf_command[n],"%s --type=%s",ldf_command[n],channelTypesRaw[n]);
283  sprintf(ldf_command[n],"%s --gps-start-time=%d --gps-end-time=%d",
284  ldf_command[n],gps_start-dataShift[n],gps_stop-dataShift[n]);
285  sprintf(cmd,"%s --url-type=file > %s",ldf_command[n],tmpFile.Data());
286  sprintf(frFiles[n],"%s/%s.frames",input_dir,ifo[n]); // set input frame file
287  sprintf(ldf_command[n],"%s --url-type=file > %s",ldf_command[n],frFiles[n]);
288 
289  // -------------------
290  // check if data exist
291  // -------------------
292 
293  // execute gw_data_find command
294  cout << cmd << endl;
295  int ret = gSystem->Exec(cmd);
296  if(ret) {
297  cout << "cwb_eced - gw_data_find error" << endl;
298  gSystem->Exit(1);
299  }
300 
301  // read size of frame file list
302  Long_t id, size, flags, modtime;
303  gSystem->GetPathInfo(tmpFile, &id, &size, &flags, &modtime);
304 
305  // delete temporary file
306  sprintf(cmd,"rm %s",tmpFile.Data());
307  gSystem->Exec(cmd);
308 
309  // check size of frame file list
310  if(size==0) {ldf_check[n]=false;ldf_gcheck=false;}
311  }
312  // check ligo_dta_find tests
313  cout << endl;
314  for(int n=0;n<nIFO;n++) {
315  if(!ldf_check[n]) cout << ifo[n] << " cwb_eced - no data found !!!" << endl;
316  else cout << ifo[n] << " cwb_eced - data found" << endl;
317  }
318  if(!ldf_gcheck) {
319  cout << endl << "check types : gw_data_find --show-types" << endl << endl;
320  gSystem->Exit(1);
321  }
322 
323  // create eced working directories
324  bool check = (cwb_inet_opts=="ced") ? true : false;
325  bool remove = (cwb_inet_opts=="ced") ? true : false;
326  TB.mkDir(eced_dir,check,remove);
327  TB.mkDir(tmp_dir,check,remove);
328  TB.mkDir(ced_dir,check,remove);
329 
330  // create frame files
331  for(int n=0;n<nIFO;n++) {
332  // execute gw_data_find command
333  cout << ldf_command[n] << endl;
334  int ret = gSystem->Exec(ldf_command[n]);
335  if(ret) {
336  cout << "cwb_eced - gw_data_find error" << endl;
337  gSystem->Exit(1);
338  }
339 
340  // extract unique frame file list
341  //TB.getUniqueFileList(frFiles[n],frFiles[n]);
342  }
343 
344  // check size of frame file list
345  for(int n=0;n<nIFO;n++) {
346  Long_t id, size, flags, modtime;
347  gSystem->GetPathInfo(frFiles[n], &id, &size, &flags, &modtime);
348  if(size==0) {
349  cout << "cwb_eced - Error : frame file list \"" << frFiles[n] << "\" with size=0" << endl;
350  gSystem->Exit(1);
351  }
352  }
353 
354  // create dummy user_parameters.C
355  char uparameter[1024];sprintf(uparameter,"%s/user_parameters.C",tmp_dir);
356  if(eced_cfg!="") {
357  // used only for book-keeping
358  gSystem->Exec(TString("cp ")+eced_cfg+TString(" ")+TString(uparameter));
359  } else {
360  // dummy user_parameters.C (only to avoid config::check error)
361  gSystem->Exec(TString("touch ")+TString(uparameter));
362  }
363  gSystem->Setenv("CWB_UPARAMETERS_FILE",uparameter);
364 
365  // set ced output dir to be ced_dir
366  gSystem->Setenv("CWB_CED_DIR",ced_dir);
367 
368  if(cwb_inet_opts=="ced") {
369  // create www symbolic link
370  sprintf(cmd,"mkdir -p %s/../ceds",www_dir);
371  cout << cmd << endl;
372  gSystem->Exec(cmd);
373  sprintf(cmd,"ln -s %s/%s %s/../ceds/%s",gSystem->WorkingDirectory(),ced_dir,www_dir,eced_dir);
374  cout << cmd << endl;
375  gSystem->Exec(cmd);
376  }
377 
378  // create cat1 file
379  for(int n=0;n<nIFO;n++) {
380 
381  ofstream out;
382  char cat1_file[1024];sprintf(cat1_file,"%s/%s_cat1.in",input_dir,ifo[n]);
383  out.open(cat1_file,ios::out);
384  if (!out.good()) {cout << "cwb_eced - Error : Error Opening File : " << cat1_file << endl;exit(1);}
385  out << gps_start << " " << gps_stop << endl;
386  out.close();
387 
388  strcpy(DQF[nDQF].ifo, ifo[n]);
389  sprintf(DQF[nDQF].file, "%s",cat1_file);
390  DQF[nDQF].cat = CWB_CAT1;
391  DQF[nDQF].shift = 0.;
392  DQF[nDQF].invert = false;
393  DQF[nDQF].c4 = false;
394  nDQF++;
395  }
396 }
double segMLS
Definition: test_config1.C:47
int _nIFO
Definition: cwb_eced.C:13
char cmd[1024]
Definition: cwb_eced.C:3
TString cwb_eced_opts
Definition: cwb_eced.C:34
TString site_cluster
Definition: cwb_mkdir.C:45
char uparameter[1024]
Definition: cwb_eced.C:355
char channelNamesMDC[NIFO_MAX][50]
char channelNamesRaw[NIFO_MAX][50]
TString _frFiles[2 *NIFO_MAX]
Definition: cwb_eced.C:17
int n
Definition: cwb_net.C:10
bool invert
Definition: Toolbox.hh:70
TString("c")
char www_dir[512]
Definition: test_config1.C:157
bool c4
Definition: Toolbox.hh:71
char frFiles[NIFO_MAX+1][256]
Definition: test_config1.C:166
TString cwb_inet_opts
Definition: cwb_eced.C:193
Long_t flags
Long_t size
char refIFO[4]
Definition: test_config1.C:14
char macro_dir[512]
Definition: test_config1.C:150
double segEdge
Definition: test_config1.C:49
char report_dir[512]
Definition: test_config1.C:149
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:3956
CWB::Toolbox TB
Definition: ComputeSNR.C:5
TString eced_cfg
Definition: cwb_eced.C:35
char ifo[NIFO_MAX][8]
char ced_dir[512]
Definition: test_config1.C:154
nDQF
Definition: cwb_eced.C:92
double segTHR
Definition: test_config1.C:48
TChain sim("waveburst")
#define nIFO
ofstream out
Definition: cwb_merge.C:196
CWB_CAT cat
Definition: Toolbox.hh:68
double factor
char input_dir[512]
Definition: test_config1.C:145
char channelTypesRaw[NIFO_MAX][1024]
Definition: cwb_eced.C:20
TString _channelNamesRaw[NIFO_MAX]
Definition: cwb_eced.C:15
char tmp_dir[512]
Definition: test_config1.C:153
TString _ifo[NIFO_MAX]
Definition: cwb_eced.C:14
sprintf(sgps_event,"%f", gps_event)
dqfile _DQF[20]
Definition: cwb_eced.C:18
i() int(T_cor *100))
const int NIFO_MAX
Definition: wat.hh:4
dqfile DQF[12]
Definition: test_config1.C:171
double dataShift[NIFO_MAX]
Definition: test_config1.C:87
int gps_event
Definition: cwb_eced.C:33
segLen
Definition: cwb_eced.C:7
double shift
Definition: Toolbox.hh:69
TString _channelNamesMDC[NIFO_MAX]
Definition: cwb_eced.C:16
char merge_dir[512]
Definition: test_config1.C:147
cedRHO
Definition: cwb_eced.C:8
char data_dir[512]
Definition: test_config1.C:152
int _nDQF
Definition: cwb_eced.C:18
char log_dir[512]
Definition: test_config1.C:151
char config_dir[512]
Definition: test_config1.C:144
char tag[256]
Definition: cwb_merge.C:74
char ldf_command[NIFO_MAX][1024]
Definition: cwb_eced.C:231
char eced_dir[1024]
Definition: cwb_eced.C:195
static TString getParameter(TString options, TString param="")
Definition: Toolbox.cc:5943
bool ldf_check[NIFO_MAX]
Definition: cwb_eced.C:230
char dump_dir[512]
Definition: test_config1.C:156
string file
Definition: cwb_online.py:385
char pp_dir[512]
Definition: test_config1.C:155
static void mkDir(TString dir, bool question=false, bool remove=true)
Definition: Toolbox.cc:4000
int estat
strcpy(RunLabel, RUN_LABEL)
nfactor[0]
Definition: cwb_eced.C:10
Long_t mt
static TString getFileName(FILE *fp)
Definition: Toolbox.cc:5996
Long_t id
char condor_dir[512]
Definition: test_config1.C:148
bool check
Definition: cwb_eced.C:324
bool ldf_gcheck
Definition: cwb_eced.C:229
simulation
Definition: cwb_eced.C:9
fclose(ftrig)
double shift[NIFO_MAX]
char output_dir[512]
Definition: test_config1.C:146
#define SEARCH(TYPE)
Definition: xroot.hh:4
exit(0)