Logo coherent WaveBurst  
Library Reference Guide
Logo
cwb_condor_submit.C
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Gabriele Vedovato, Claudia Lazzaro
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 // submit condor jobs : used by the cwb_condor command
20 
21 {
23  char cmd[1024];
24 
25  TB.checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
26  TB.checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
27  TB.checkFile(gSystem->Getenv("CWB_UPARAMETERS_FILE"));
28 
29  // get condor dag
31  if(gSystem->Getenv("CWB_CONDOR_DAG")!=NULL) {
32  // user define condor tag
33  cwb_condor_dag=TString(gSystem->Getenv("CWB_CONDOR_DAG"));
34  //strip '/' from path
35  TObjArray* token = cwb_condor_dag.Tokenize(TString('/'));
36  TObjString* stoken =(TObjString*)token->At(token->GetEntries()-1);
37  cwb_condor_dag = stoken->GetString();
38  }
39 
40  // get pegasus site
42  if(gSystem->Getenv("CWB_PEGASUS_USITE")!=NULL) {
43  // user define pegasus site
44  TString cwb_pegasus_usite=TString(gSystem->Getenv("CWB_PEGASUS_USITE"));
45  }
46 
47  // get workflow file (used by pegasus)
49  cwb_condor_workflow.ReplaceAll(".","_"); // pegasus do not accept '.'
50  char workflowfile[1024];
51  sprintf(workflowfile,"%s/%s",condor_dir,cwb_condor_workflow.Data());
52 
53  // get job batch command
54  TString batch_cmd = "condor_submit_dag";
55  TString cwb_scripts = TString(gSystem->Getenv("CWB_SCRIPTS"));
56  if(gSystem->Getenv("_USE_PEGASUS")!=NULL) batch_cmd = cwb_scripts+"/cwb_pegasus_submit.sh";
57  if(gSystem->Getenv("_USE_LSF")!=NULL) batch_cmd = cwb_scripts+"/cwb_lsf_submit.sh";
58 
59  if(gSystem->Getenv("_USE_PEGASUS")!=NULL) {
60 
61  // Check if pagasus work file already exist
62  Long_t id,size,flags,mt;
63  int estat = gSystem->GetPathInfo(workflowfile,&id,&size,&flags,&mt);
64  if (estat==0) {
65  char answer[256];
66  strcpy(answer,"");
67  do {
68  cout << "File \"" << workflowfile << "\" already exist" << endl;
69  cout << "Do you want to submit again ? (y/n) ";
70  cin >> answer;
71  cout << endl << endl;
72  } while ((strcmp(answer,"y")!=0)&&(strcmp(answer,"n")!=0));
73  if (strcmp(answer,"n")==0) {
74  exit(0);
75  } else {
76  sprintf(cmd,"rm %s",workflowfile);
77  int ret=gSystem->Exec(cmd);
78  if(ret) {cout << "Error while executing " << cmd << " !!!" << endl;exit(1);}
79  }
80  }
81  }
82 
83  if(cwb_condor_dag=="") {
84  sprintf(cmd,"cd %s/%s;%s %s.dag %s",
85  work_dir,condor_dir,batch_cmd.Data(),data_label,cwb_pegasus_usite.Data());
86  } else {
87  sprintf(cmd,"cd %s/%s;%s %s %s",
88  work_dir,condor_dir,batch_cmd.Data(),cwb_condor_dag.Data(),cwb_pegasus_usite.Data());
89  }
90  cout << cmd << endl;
91  int ret=gSystem->Exec(cmd);
92  if(ret) {cout << "Error while executing " << batch_cmd << " !!!" << endl;exit(1);}
93 
94  if(gSystem->Getenv("_USE_LSF")!=NULL) {
95  cout << endl << endl;
96  cout << "Your LSF jobs has been submitted" << endl;
97  cout << "To monitor the jobs do : cwb_lsf status" << endl;
98  cout << "To monitor the queue : cwb_lsf queue" << endl;
99  cout << "To kill the all jobs do : cwb_lsf kill" << endl;
100  cout << "To resubmit paused jobs do : cwb_lsf resume" << endl;
101  cout << "To suspend all jobs do : cwb_lsf stop" << endl << endl;
102  }
103 
104  if(gSystem->Getenv("_USE_PEGASUS")!=NULL) {
105  sprintf(cmd, "cd %s;ls -1 -trd workflows/*/pegasus/cwb/* | tail -n 1 | awk 'BEGIN { OFS = \"\"; ORS = \"\" } ; {print $1}; {print \" %s\"}' | xargs ln -sf",condor_dir,data_label);
106  cout << cmd << endl;
107  int ret=gSystem->Exec(cmd);
108  if(ret) {cout << "Error while executing " << cmd << " !!!" << endl;exit(1);}
109  sprintf(cmd, "ln -sfn %s/%s pegasus",condor_dir,data_label);
110  cout << cmd << endl;
111  ret=gSystem->Exec(cmd);
112  cout << endl << endl;
113  cout << "Your workflow has been started and is running in the base directory: " << endl;
114  cout << workflowfile << endl << endl;
115  cout << "To monitor the workflow do : cwb_pstatus" << endl;
116  cout << "To remove the workflow do : cwb_premove" << endl;
117  cout << "To resubmit an aborted or failed workflow do : cwb_prun" << endl;
118  cout << "To analyze the workflow do : cwb_panalyzer" << endl << endl;
119  }
120 
121  gSystem->Exit(0);
122 }
TString cwb_scripts
TString("c")
CWB::Toolbox TB
char cmd[1024]
Long_t flags
Long_t size
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:4670
char workflowfile[1024]
char data_label[512]
Definition: test_config1.C:160
TString cwb_condor_dag
TObjArray * token
char answer[256]
TString cwb_condor_workflow
int estat
strcpy(RunLabel, RUN_LABEL)
sprintf(workflowfile,"%s/%s", condor_dir, cwb_condor_workflow.Data())
TString cwb_pegasus_usite
Long_t mt
Long_t id
char condor_dir[512]
Definition: test_config1.C:148
char work_dir[512]
Definition: test_config1.C:143
TString batch_cmd
exit(0)