Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cwb_condor_rescue.C
Go to the documentation of this file.
1 // used by the cwb_condor_rescue
2 
3 {
4  #include <vector>
5 
7 
8  TB.checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
9  TB.checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
10  TB.checkFile(gSystem->Getenv("CWB_UPARAMETERS_FILE"));
11 
12  char full_condor_dir[512];
13  sprintf(full_condor_dir,"%s/%s",work_dir,condor_dir);
14 
15  vector<int> jobList=TB.getCondorJobList(full_condor_dir, data_label);
16 
17  int max_jobs = jobList.size();
18 
19  int jobStart[max_jobs+1];
20  int jobStop[max_jobs+1];
21 
22  bool jobIdStatus[max_jobs+1];
23  for (int i=0;i<max_jobs+1;i++) jobIdStatus[i]=false;
24 
25  char tag[256];sprintf(tag,"%s.dag.rescue.",data_label);
26  vector<TString> fileList = TB.getFileListFromDir(condor_dir, tag, "", "_wave");
27  int iversion=0;
28  for(int i=0;i<fileList.size();i++) {
29  //cout << i << " " << fileList[i].Data() << endl;
30  TObjArray* token = TString(fileList[i]).Tokenize(TString("."));
31  TObjString* srescueID = (TObjString*)token->At(token->GetEntries()-1);
32  if(srescueID->GetString().IsDigit()) {
33  cout << i << " " << fileList[i].Data() << endl;
34  int rescueID = srescueID->GetString().Atoi();
35  if(iversion<rescueID) iversion=rescueID;
36  }
37  }
38  iversion++;
39 
40  char ofile[512];
41  sprintf(ofile,"%s/%s.dag.rescue.%d",condor_dir,data_label,iversion);
42 
43  // Check if file exist
44  Long_t id,size,flags,mt;
45  int estat = gSystem->GetPathInfo(ofile,&id,&size,&flags,&mt);
46  if (estat==0) {
47  char answer[256];
48  strcpy(answer,"");
49  do {
50  cout << "File \"" << ofile << "\" already exist" << endl;
51  cout << "Do you want to overwrite the file ? (y/n) ";
52  cin >> answer;
53  cout << endl << endl;
54  } while ((strcmp(answer,"y")!=0)&&(strcmp(answer,"n")!=0));
55  if (strcmp(answer,"n")==0) {
56  exit(0);
57  }
58  }
59 
60  int nrescue=0;
61  char ifile_name[512];
62  for (int i=1;i<=max_jobs;i++) {
63  sprintf(ifile_name,"%s/%s/%d_%s.err",work_dir,log_dir,jobList[i],data_label);
64  //cout << ifile_name << endl;
65  Long_t id,size,flags,mt;
66  int estat = gSystem->GetPathInfo(ifile_name,&id,&size,&flags,&mt);
67  if (estat==0) {
68  if (size>0) cout << ifile_name << endl;
69  //cout << size << endl;
70  if (size>0) {jobIdStatus[i]=true;nrescue++;}
71  }
72  }
73  if(nrescue==0) {
74  cout << "Unfinished Error Jobs : " << 0 << "/" << max_jobs << endl;
75  exit(0);
76  }
77  cout << endl;
78  cout << "New Rescue File " << endl;
79  cout << ofile << endl;
80 
81  char full_condor_dir[512];
82  sprintf(full_condor_dir,"%s/%s",work_dir,condor_dir);
83 
84  ofstream out;
85  out.open(ofile,ios::out);
86  int cnt = 0;
87  for (int i=0;i<=max_jobs;i++) {
88  if (jobIdStatus[i]) {
89  cnt++;
90  char ostring[256];
91  int jobID=jobList[i];
92  sprintf(ostring,"JOB A%i %s/%s.sub",jobID,full_condor_dir,data_label);
93  out << ostring << endl;
94  sprintf(ostring,"VARS A%i PID=\"%i\"",jobID,jobID);
95  out << ostring << endl;
96  sprintf(ostring,"RETRY A%i 3000",jobID);
97  out << ostring << endl;
98  }
99  }
100  out.close();
101 
102  cout << "Unfinished Error Jobs : " << cnt << "/" << max_jobs << endl;
103  cout << endl;
104  cout << "To submit condor rescued jobs type :" << endl;
105  cout << "cd " << condor_dir << endl;
106  sprintf(ofile,"%s.dag.rescue.%d",data_label,iversion);
107  cout << "condor_submit_dag " << ofile << endl;
108  cout << endl;
109 
110  exit(0);
111 }
static vector< TString > getFileListFromDir(TString dir_name, TString endString="", TString beginString="", TString containString="", bool fast=false)
Definition: Toolbox.cc:4333
char full_condor_dir[512]
TString("c")
vector< int > jobList
Long_t size
char ifile_name[512]
int estat
char ofile[512]
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:3956
int jobID
Definition: cwb_net.C:177
CWB::Toolbox TB
Definition: ComputeSNR.C:5
Long_t id
ofstream out
Definition: cwb_merge.C:196
char data_label[512]
Definition: test_config1.C:160
int max_jobs
int jobStop[max_jobs+1]
TObjArray * token
char log_dir[512]
Definition: test_config1.C:151
sprintf(full_condor_dir,"%s/%s", work_dir, condor_dir)
char tag[256]
Definition: cwb_merge.C:74
Long_t flags
int jobStart[max_jobs+1]
char answer[256]
static vector< int > getCondorJobList(TString condor_dir, TString label)
Definition: Toolbox.cc:1378
cout<< "Starting reading output directory ..."<< endl;vector< TString > fileList
iversion
strcpy(RunLabel, RUN_LABEL)
int cnt
int nrescue
char condor_dir[512]
Definition: test_config1.C:148
Long_t mt
char work_dir[512]
Definition: test_config1.C:143
bool jobIdStatus[max_jobs+1]
exit(0)