Logo coherent WaveBurst  
Library Reference Guide
Logo
cwb_condor_sdag.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 // read the standard *.dag file produced with cwb_condor create and produced a new dag file *.sdag
20 // The *.sdag permits to submit in each node N jobs in sequential mode
21 // This solution speedup the submission of jobs when the job execution time is too short
22 
23 {
24  #include <vector>
25 
27 
28  TB.checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
29  TB.checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
30  TB.checkFile(gSystem->Getenv("CWB_UPARAMETERS_FILE"));
31 
32  int cwb_condor_njobs=-1; // slag>0
33  if(gSystem->Getenv("CWB_CONDOR_NJOBS")==NULL) {
34  cout << "Error : environment CWB_CONDOR_NJOBS is not defined!!!" << endl;exit(1);
35  }
36  if(TString(gSystem->Getenv("CWB_CONDOR_NJOBS")).IsDigit()) {
37  cwb_condor_njobs=TString(gSystem->Getenv("CWB_CONDOR_NJOBS")).Atoi();
38  }
39  if(cwb_condor_njobs<=1) {
40  cout << "cwb_condor_sdag.C - Error : nJOBS must be >1" << endl;
41  gSystem->Exit(1);
42  }
43 
44  cout << cwb_condor_njobs << endl;
45 
46  // get condor dag
47  char full_condor_dir[1024];
48  sprintf(full_condor_dir,"%s/%s",work_dir,condor_dir);
49  TString cwb_condor_dag = TString::Format("%s/%s.dag",condor_dir,data_label);
50  TB.checkFile(cwb_condor_dag,false);
51  if(gSystem->Getenv("CWB_CONDOR_DAG")!=NULL) {
52  // user define condor tag
53  TString cwb_condor_dag=TString(gSystem->Getenv("CWB_CONDOR_DAG"));
54  }
55  if(!cwb_condor_dag.Contains(".dag")) {
56  cout << "cwb_condor_sdag.C - Error : dag file name must contains '.dag'" << endl;
57  gSystem->Exit(1);
58  }
59 
60  vector<int> jobList=TB.getCondorJobList(full_condor_dir, data_label);
61 
63  cwb_condor_sdag.ReplaceAll(".dag",".sdag");
64  cout << cwb_condor_sdag << endl;
65 
66  TB.checkFile(cwb_condor_sdag,true);
67 
68  ofstream out;
69  out.open(cwb_condor_sdag.Data(),ios::out);
70  if (!out.good()) {cout << "cwb_condor_sdag.C - Error Opening File : " << cwb_condor_sdag << endl;exit(1);}
71 
72  ifstream in;
73  in.open(cwb_condor_dag.Data(),ios::in);
74  if (!in.good()) {cout << "cwb_condor_dag.C - Error Opening File : " << cwb_condor_dag << endl;exit(1);}
75 
76  // copy dag to sdag
77  char istr[1024];
78  while(true) {
79  in.getline(istr,1024);
80  if (!in.good()) break;
81  out << istr << endl;
82  }
83  in.close();
84 
85  // add super jobs instructions to sdag file
86  out << endl;
87  int nsjob=0;
88  for(int i=0;i<jobList.size();i++) {
89  for(int j=1;j<cwb_condor_njobs && i<jobList.size()-1;j++) {
90  out << "PARENT A" << jobList[i] << " CHILD A" << jobList[i+1] << endl;
91  //cout << i << " " << j << " jobId : " << jobList[i] << endl;
92  i++;
93  }
94  out << endl;
95  nsjob++;
96  }
97 
98  out.close();
99 
100  cout << endl << "Created new sdag file : " << cwb_condor_sdag << endl << endl;
101 
102  cout << "Number of job files : " << jobList.size() << endl;
103  cout << "Number of sjob files : " << nsjob << endl << endl;
104 
105  exit(0);
106 }
TString("c")
ofstream out
Definition: cwb_merge.C:214
char full_condor_dir[1024]
CWB::Toolbox TB
int cwb_condor_njobs
int j
Definition: cwb_net.C:28
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:4670
char data_label[512]
Definition: test_config1.C:160
TString cwb_condor_dag
vector< int > jobList
TString cwb_condor_sdag
static vector< int > getCondorJobList(TString condor_dir, TString label)
Definition: Toolbox.cc:1398
ifstream in
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
char condor_dir[512]
Definition: test_config1.C:148
char work_dir[512]
Definition: test_config1.C:143
exit(0)