Logo coherent WaveBurst  
Library Reference Guide
Logo
cwb_condor_mtpe.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 
20 {
21 
22  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
23  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
24  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_UPARAMETERS_FILE"));
25 
26  if(TString(condor_tag)=="") {
27  cout << endl;
28  cout << "cwb_condor_mtpe.C : Error - the accounting_group is not defined !!!" << endl;
29  cout << "The accounting_group must be defined in the user_parameters.C file" << endl;
30  cout << "See the following link:" << endl;
31  cout <<" https://ldas-gridmon.ligo.caltech.edu/accounting/condor_groups/determine_condor_account_group.html" << endl;
32  cout << "Examples : " << endl;
33  cout << "strcpy(condor_tag,\"ligo.dev.o2.burst.allsky.cwboffline\");" << endl;
34  cout << "strcpy(condor_tag,\"ligo.prod.o2.burst.allsky.cwboffline\");" << endl;
35  cout << "If you don't need it set : strcpy(condor_tag,\"disabled\");" << endl << endl;
36  exit(1);
37  }
38  if(TString(condor_tag)=="disabled") strcpy(condor_tag,"");
39 
40  if(!(simulation==4) && !(simulation==0)) {
41  cout << endl << "cwb_condor_mtpe Error : allowed only with simulation=0/4 !!!" << endl << endl;
42  gSystem->Exit(1);
43  }
44 
45  bool singleDetector=false;
46  if(nIFO==1) { // Single Detector Mode
48  config.Import();
49  config.SetSingleDetectorMode();
50  config.Export();
51  singleDetector=true;
52  }
53  if(nIFO==2) { // 2 detectors with the same name "same detector -> nIFO=1"
54  if(TString(ifo[0])==TString(ifo[1])) singleDetector=true;
55  }
56 
57  // get PE jobid
59  if(gSystem->Getenv("CWB_CONDOR_MTPE_JOBID")==NULL) {
60  cout << endl << "cwb_condor_mtpe Error : environment CWB_CONDOR_MTPE_JOBID is not defined!!!" << endl << endl;
61  gSystem->Exit(1);
62  } else {
63  if(TString(gSystem->Getenv("CWB_CONDOR_MTPE_JOBID")).IsDigit()) {
64  cwb_condor_mtpe_jobid=TString(gSystem->Getenv("CWB_CONDOR_MTPE_JOBID")).Atoi();
65  } else {
66  cout << endl << "cwb_condor_mtpe Error : environment CWB_CONDOR_MTPE_JOBID is not an integer number!!!" << endl << endl;
67  gSystem->Exit(1);
68  }
69  }
70  if(cwb_condor_mtpe_jobid<1) {
71  cout << endl << "cwb_condor_mtpe Error : environment CWB_CONDOR_MTPE_JOBID is not an integer number >0 !!!" << endl << endl;
72  gSystem->Exit(1);
73  }
74 
75  // get PE trials
76  int cwb_condor_mtpe_trials=-1;
78 
79  // for simulation=4 the trials are defined in the nfactor, factors parameters
80  if(simulation==4 && nfactor>1) {
81  cwb_condor_mtpe_trials = factors[0]+nfactor-1;
82  cwb_condor_mtpe_offset = factors[0];
83  if(cwb_condor_mtpe_trials<1) {
84  cout << endl << "cwb_condor_mtpe Error : (simulation=4) nfactor is not an integer number >0 !!!" << endl << endl;
85  gSystem->Exit(1);
86  }
87  if(cwb_condor_mtpe_offset<1) {
88  cout << endl << "cwb_condor_mtpe Error : (simulation=4) factors[0] is not an integer number >0 !!!" << endl << endl;
89  gSystem->Exit(1);
90  }
91  }
92 
93  // for simulation=0 the trials are defined in the PE parPlugin
94  if((simulation==0)||(simulation==4 && nfactor==1)) {
95  bool multitask=false;
96  TString pe_options = parPlugin;
97  if(pe_options.CompareTo("")!=0) {
98  cout << pe_options << endl;
99  if(!pe_options.Contains("--")) {
100 
101  TObjArray* token = TString(pe_options).Tokenize(TString(' '));
102 
103  for(int j=0;j<token->GetEntries();j++) {
104 
105  TObjString* tok = (TObjString*)token->At(j);
106  TString stok = tok->GetString();
107 
108  if(stok.Contains("pe_multitask=")) {
109  TString pe_multitask=stok;
110  pe_multitask.Remove(0,pe_multitask.Last('=')+1);
111  if(pe_multitask=="true") multitask=true;
112  if(pe_multitask=="false") multitask=false;
113  }
114 
115  if(stok.Contains("pe_trials=") || stok.Contains("pe_retry=")) {
116  TString pe_trials=stok;
117  pe_trials.Remove(0,pe_trials.Last('=')+1);
118  if(pe_trials.IsDigit()) cwb_condor_mtpe_trials=pe_trials.Atoi();
119  }
120  }
121  }
122  }
123  if(!multitask) {
124  cout << endl << "cwb_condor_mtpe Error : (simulation=0) pe_multitask must be enabled !!!" << endl << endl;
125  gSystem->Exit(1);
126  }
127  if(cwb_condor_mtpe_trials<1 || cwb_condor_mtpe_trials>99) {
128  cout << endl << "cwb_condor_mtpe Error : (simulation=0) pe_trials in PE parPlugin is not an integer number >0 && <100 !!!" << endl << endl;
129  gSystem->Exit(1);
130  }
131  }
132 
133  char condor_label[1024];
134  sprintf(condor_label,"%s.mtpe",data_label);
135 
136  // create condor sub file
137 
138  char ofile_condor_sub[1024];
139  sprintf(ofile_condor_sub,"%s/%s.sub",condor_dir,condor_label);
140 
141  FILE *fP=NULL;
142  if((fP = fopen(ofile_condor_sub, "w")) == NULL) {
143  cout << endl << "cwb_condor_mtpe.C : Error - cannot open file " << ofile_condor_sub << endl << endl;
144  exit(1);
145  }
146  cout << endl << ofile_condor_sub << endl;
147 
148  char full_condor_dir[1024];
149  char full_condor_out_dir[1024];
150  char full_condor_err_dir[1024];
151 
152  sprintf(full_condor_dir,"%s/%s",work_dir,condor_dir);
153  sprintf(full_condor_out_dir,"%s/%s",work_dir,log_dir);
154  sprintf(full_condor_err_dir,"%s/%s",work_dir,log_dir);
155 
156  fprintf(fP,"universe = vanilla\n");
157  fprintf(fP,"getenv = true\n");
158  fprintf(fP,"priority = $(PRI)\n");
159  fprintf(fP,"on_exit_hold = ( ExitCode != 0 )\n");
160  fprintf(fP,"request_memory = 2000\n");
161  fprintf(fP,"executable = loudest.sh\n");
162  fprintf(fP,"job_machine_attrs = Machine\n");
163  fprintf(fP,"job_machine_attrs_history_length = 5\n");
164  fprintf(fP,"requirements = target.machine =!= MachineAttrMachine1 && target.machine =!= MachineAttrMachine2 && target.machine =!= MachineAttrMachine3 && target.machine =!= MachineAttrMachine4 && target.machine =!= MachineAttrMachine5\n");
165  fprintf(fP,"environment = CWB_JOBID=$(PID);CWB_UFILE=$(CWB_UFILE);CWB_STAGE=$(CWB_STAGE);CWB_MDC_FACTOR=$(CWB_MDC_FACTOR);CWB_CED_DIR=$(CWB_CED_DIR)\n");
166  if(TString(condor_tag)!="") fprintf(fP,"accounting_group = %s\n",condor_tag);
167  fprintf(fP,"output = %s/$(PID)_$(CWB_MDC_FACTOR)_%s.out\n",full_condor_out_dir,condor_label);
168  fprintf(fP,"error = %s/$(PID)_$(CWB_MDC_FACTOR)_%s.err\n",full_condor_err_dir,condor_label);
169  fprintf(fP,"log = %s/%s.log\n",condor_log,condor_label);
170  fprintf(fP,"notification = never\n");
171  fprintf(fP,"rank=memory\n");
172  fprintf(fP,"queue\n");
173 
174  fclose(fP);
175 
176  // create condor dag file
177 
178  char ofile_condor_dag[1024];
179  sprintf(ofile_condor_dag,"%s/%s.dag",condor_dir,condor_label);
180 
181  ofstream out;
182  out.open(ofile_condor_dag,ios::out);
183  if (!out.good()) {cout << endl << "cwb_condor_mtpe Error Opening File : " << ofile_condor_dag << endl << endl;exit(1);}
184  cout << ofile_condor_dag << endl << endl;
185 
186  TString cwb_uparameters_file=TString(gSystem->Getenv("CWB_UPARAMETERS_FILE"));
187 
188  for(int n=cwb_condor_mtpe_offset; n<=cwb_condor_mtpe_trials; n++) {
189  char ostring[1024*16];
190  sprintf(ostring,"JOB A%i_%d %s/%s.sub",cwb_condor_mtpe_jobid,n,full_condor_dir,condor_label);
191  out << ostring << endl;
192  sprintf(ostring,"VARS A%i_%d PID=\"%i\" CWB_UFILE=\"%s\" CWB_STAGE=\"CWB_STAGE_FULL\" CWB_MDC_FACTOR=\"%d\" CWB_CED_DIR=\"output\"",
193  cwb_condor_mtpe_jobid,n,cwb_condor_mtpe_jobid,cwb_uparameters_file.Data(),n);
194  out << ostring << endl;
195  sprintf(ostring,"RETRY A%i_%d 3000",cwb_condor_mtpe_jobid,n);
196  out << ostring << endl;
197  }
198 
199  if((simulation==0)||(simulation==4 && nfactor==1)) {
200  char ostring[1024*16];
201  out << "PARENT ";
202  for(int n=1; n<cwb_condor_mtpe_trials; n++) {
203  sprintf(ostring,"A%i_%d ",cwb_condor_mtpe_jobid,n);
204  out << ostring;
205  }
206  sprintf(ostring,"CHILD A%i_%d",cwb_condor_mtpe_jobid,cwb_condor_mtpe_trials);
207  out << ostring << endl;
208  out.close();
209  }
210 
211  exit(0);
212 }
213 
void Export(TString fname="")
Definition: config.cc:406
char parPlugin[1024]
int n
Definition: cwb_net.C:28
char ofile_condor_sub[1024]
TString("c")
ofstream out
Definition: cwb_merge.C:214
char full_condor_dir[1024]
char condor_label[1024]
FILE * fP
int j
Definition: cwb_net.C:28
void Import(TString umacro="")
Definition: config.cc:352
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:4670
int cwb_condor_mtpe_jobid
char ifo[NIFO_MAX][8]
fprintf(stdout,"start=%f duration=%f rate=%f\, x.start(), x.size()/x.rate(), x.rate())
bool singleDetector
#define nIFO
char full_condor_out_dir[1024]
char data_label[512]
Definition: test_config1.C:160
TObjArray * token
char log_dir[512]
Definition: test_config1.C:151
char full_condor_err_dir[1024]
int cwb_condor_mtpe_offset
sprintf(condor_label,"%s.mtpe", data_label)
strcpy(RunLabel, RUN_LABEL)
int nfactor
Definition: test_config1.C:83
char condor_log[512]
Definition: test_config1.C:163
TString cwb_uparameters_file
char condor_dir[512]
Definition: test_config1.C:148
char work_dir[512]
Definition: test_config1.C:143
simulation
Definition: cwb_eced.C:26
fclose(ftrig)
TString config
factors[0]
Definition: cwb_eced.C:27
void SetSingleDetectorMode()
Definition: config.cc:1352
exit(0)