Logo coherent WaveBurst  
Library Reference Guide
Logo
cwb_condor_xdag.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 // This macro is used to generate the dag file when CWB_Plugin_Periodic_Frames.C is used
20 // Selects jobs with range overlapping 2 periods -> do not work with CWB_Plugin_Periodic_Frames.C
21 // Read the standard *.dag file produced with cwb_condor create and produced a new dag file *.xdag
22 // Creates also *.idag which permits to run the selected jobs in interactive mode
23 
24 {
25  #include <vector>
26 
28 
29  TB.checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
30  TB.checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
31  TB.checkFile(gSystem->Getenv("CWB_UPARAMETERS_FILE"));
32 
33  if(slagSize != 1) {
34  cout << "cwb_condor_xdag.C - Error : This procedure do not works with segments with variable lenght (slagSize must be =1)!!!" << endl;exit(1);
35  }
36 
38  if(gSystem->Getenv("CWB_CONDOR_FSTART")==NULL) {
39  cout << "cwb_condor_xdag.C - Error : environment CWB_CONDOR_FSTART is not defined!!!" << endl;exit(1);
40  }
41  if(TString(gSystem->Getenv("CWB_CONDOR_FSTART")).IsDigit()) {
42  cwb_condor_fstart=TString(gSystem->Getenv("CWB_CONDOR_FSTART")).Atoi();
43  }
44  if(cwb_condor_fstart<=1) {
45  cout << "cwb_condor_xdag.C - Error : FRAME GPS START must be defined" << endl;
46  gSystem->Exit(1);
47  }
48  cout << cwb_condor_fstart << endl;
49 
50  int cwb_condor_flen=-1;
51  if(gSystem->Getenv("CWB_CONDOR_FLEN")==NULL) {
52  cout << "Error : environment CWB_CONDOR_FLEN is not defined!!!" << endl;exit(1);
53  }
54  if(TString(gSystem->Getenv("CWB_CONDOR_FLEN")).IsDigit()) {
55  cwb_condor_flen=TString(gSystem->Getenv("CWB_CONDOR_FLEN")).Atoi();
56  }
57  if(cwb_condor_flen<=1) {
58  cout << "cwb_condor_xdag.C - Error : FRAME LENGHT must be defined" << endl;
59  gSystem->Exit(1);
60  }
61  cout << cwb_condor_flen << endl;
62 
63  // get list start, stop for each job
64  double xtime;
65  char jobListFile[256];
66  sprintf(jobListFile,"%s/%s.sjob",dump_dir,data_label);
67  char dq1ListFile[256];
68  sprintf(dq1ListFile,"%s/%s.cat1",dump_dir,data_label);
69 
70  cout<<endl<<"-------------------------------------------------------------------------------------"<< endl<<endl;
71 
73  vector<waveSegment> dq1List=TB.readSegList(nDQF, DQF, dqcat);
74  TB.dumpSegList(dq1List,dq1ListFile, false);
75  cout << "Dump file : " << dq1ListFile << endl;
76  xtime=TB.getTimeSegList(dq1List);
77  cout << "cat1 livetime : " << int(xtime) << " sec "
78  << xtime/3600. << " h " << xtime/86400. << " day" << endl;
79 
80  cout<<endl<<"-------------------------------------------------------------------------------------"<< endl<<endl;
81 
82  // find jobs with range overlapping 2 periods -> do not work with CWB_Plugin_Strain_Frames.C
83  vector<waveSegment> jobSeg=TB.getSlagJobList(dq1List, segLen); // get slag job list
84  cout << "Dump file : " << jobListFile << endl;
85  cout << "nJob = " << jobSeg.size() << endl;
86  cout << endl;
87  vector<bool> jobSelected(jobSeg.size());
88  for(int i=0;i<jobSeg.size();i++) {
89  double frame_offset = fmod(cwb_condor_fstart, cwb_condor_flen);
90  double seg_offset = fmod(jobSeg[i].start-frame_offset, cwb_condor_flen);
91  double seg_len = jobSeg[i].stop-jobSeg[i].start;
92  //if(seg_offset<segEdge || (cwb_condor_flen-seg_offset)<seg_len+2*segEdge)
93  // cout << i+1 << " " << (int)seg_offset << " " << cwb_condor_flen-(int)seg_offset << endl;
94  if(seg_offset<segEdge || (cwb_condor_flen-seg_offset)<seg_len+2*segEdge) jobSelected[i]=false; else jobSelected[i]=true;
95  }
96 
97  // get condor dag
98  char full_condor_dir[1024];
99  sprintf(full_condor_dir,"%s/%s",work_dir,condor_dir);
100  TString cwb_condor_dag = TString::Format("%s/%s.dag",condor_dir,data_label);
101  TB.checkFile(cwb_condor_dag,false);
102  if(gSystem->Getenv("CWB_CONDOR_DAG")!=NULL) {
103  // user define condor tag
104  TString cwb_condor_dag=TString(gSystem->Getenv("CWB_CONDOR_DAG"));
105  }
106  if(!cwb_condor_dag.Contains(".dag")) {
107  cout << "cwb_condor_xdag.C - Error : dag file name must contains '.dag'" << endl;
108  gSystem->Exit(1);
109  }
110 
111  vector<int> jobList=TB.getCondorJobList(full_condor_dir, data_label);
112 
114  cwb_condor_xdag.ReplaceAll(".dag",".xdag");
115  cout << cwb_condor_xdag << endl;
116  //TB.checkFile(cwb_condor_xdag,false);
117 
118  // creates interactive job list
119  TString cwb_condor_idag = cwb_condor_dag;
120  cwb_condor_idag.ReplaceAll(".dag",".idag");
121  cout << cwb_condor_idag << endl;
122  //TB.checkFile(cwb_condor_idag,false);
123 
124  ofstream xout;
125  xout.open(cwb_condor_xdag.Data(),ios::out);
126  if (!xout.good()) {cout << "cwb_condor_xdag.C - Error Opening File : " << cwb_condor_xdag << endl;exit(1);}
127 
128  ofstream iout;
129  iout.open(cwb_condor_idag.Data(),ios::out);
130  if (!iout.good()) {cout << "cwb_condor_xdag.C - Error Opening File : " << cwb_condor_idag << endl;exit(1);}
131 
132  ifstream in;
133  in.open(cwb_condor_dag.Data(),ios::in);
134  if (!in.good()) {cout << "cwb_condor_dag.C - Error Opening File : " << cwb_condor_dag << endl;exit(1);}
135 
136  // copy dag to xdag
137  char istr[1024];
138  int njob=jobList.size()-1;
139  int nxjob=0; // index of selected jobs
140  int nlines=1;
141  while(true) {
142  in.getline(istr,1024);
143  if (!in.good()) break;
144  if(njob<=0) break;
145  int jobId = jobList[njob];
146  if(jobSelected[jobId-1]) xout << istr << endl;
147  if(jobSelected[jobId-1] && nlines%3==2) {
148  iout << "cwb_inet " << jobId << endl;
149  nxjob++;
150  }
151  if(nlines%3==0) njob--;
152  nlines++;
153  }
154  in.close();
155  xout.close();
156  iout.close();
157  cout << endl << "Created new xdag file : " << cwb_condor_xdag << endl << endl;
158  cout << endl << "Created new idag file : " << cwb_condor_idag << endl << endl;
159 
160  cout << "Number of job files : " << jobList.size() << endl;
161  cout << "Number of xjob files : " << nxjob << endl << endl;
162 
163  exit(0);
164 }
char full_condor_dir[1024]
int slagSize
Definition: test_config1.C:65
cout<< "Dump file : "<< jobListFile<< endl;cout<< "nJob = "<< jobSeg.size()<< endl;cout<< endl;vector< bool > jobSelected(jobSeg.size())
char dq1ListFile[256]
Definition: cwb_dump_dq.C:28
cout<< "Dump file : "<< dq1ListFile<< endl;xtime=TB.getTimeSegList(dq1List);cout<< "cat1 livetime : "<< int(xtime)<< " sec "<< xtime/3600.<< " h "<< xtime/86400.<< " day"<< endl;cout<< endl<<"-------------------------------------------------------------------------------------"<< endl<< endl;vector< waveSegment > jobSeg
vector< int > jobList
TString("c")
cout<< cwb_condor_flen<< endl;double xtime;char jobListFile[256];sprintf(jobListFile,"%s/%s.sjob", dump_dir, data_label);char dq1ListFile[256];sprintf(dq1ListFile,"%s/%s.cat1", dump_dir, data_label);cout<< endl<<"-------------------------------------------------------------------------------------"<< endl<< endl;CWB_CAT dqcat=CWB_CAT1;vector< waveSegment > dq1List
ofstream out
Definition: cwb_merge.C:214
CWB_CAT dqcat
CWB::Toolbox TB
CWB_CAT
Definition: Toolbox.hh:72
static double getTimeSegList(vector< waveSegment > list)
Definition: Toolbox.cc:611
double segEdge
Definition: test_config1.C:49
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:4670
TString cwb_condor_dag
nDQF
Definition: cwb_eced.C:109
char data_label[512]
Definition: test_config1.C:160
sprintf(full_condor_dir,"%s/%s", work_dir, condor_dir)
i() int(T_cor *100))
dqfile DQF[12]
Definition: test_config1.C:171
static int dumpSegList(vector< waveSegment > list, TString fName, bool c4=false)
Definition: Toolbox.cc:571
static vector< waveSegment > getSlagJobList(vector< waveSegment > ilist, int seglen=600)
Definition: Toolbox.cc:1791
segLen
Definition: cwb_eced.C:24
int cwb_condor_fstart
static vector< waveSegment > readSegList(dqfile DQF)
Definition: Toolbox.cc:409
static vector< int > getCondorJobList(TString condor_dir, TString label)
Definition: Toolbox.cc:1398
ifstream in
double xtime
Definition: cwb_dump_sjob.C:28
char dump_dir[512]
Definition: test_config1.C:156
char jobListFile[256]
Definition: cwb_dump_sjob.C:29
int jobId
char condor_dir[512]
Definition: test_config1.C:148
char work_dir[512]
Definition: test_config1.C:143
TString cwb_condor_xdag
exit(0)