Logo coherent WaveBurst  
Library Reference Guide
Logo
cwb_jnet.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 // obsolete
20 
21 void
22 cwb_jnet(TString jName="", TString uName="") {
23 
24  bool jshell = jName!="" ? true : false;
25 
26  // if jName!="" jfile is opened from disk otherwise it is opened within TBrowser
27  TFile* jfile = jName=="" ? gROOT->GetFile() : jfile = new TFile(jName);
28  if(jfile==NULL) {
29  cout << "cwb_jnet - Error opening root file : " << jName << endl;
30  if(jshell) exit(1); else return;
31  }
32  jfile->ls();
33 
34  // read config object
35  CWB::config* cfg = (CWB::config*)jfile->Get("config");
36  if(cfg==NULL) {
37  cout << "cwb_jnet - config is not present in : " << jName << endl;
38  if(jshell) exit(1); else return;
39  }
40  // export config to cint
41  cfg->Export();
42  // set auxiliary configuration
43  if(uName!="") cfg.Import(uName); // auxiliary config file
44  //cfg->Print();
45 
46  // get analysis setup
47  TString ANALYSYS = cfg->analysis;
48 
49  // get jName ...
50  if(jName=="") {
51  jName = jfile->GetPath();
52  jName.ReplaceAll(":/","");
53  cout << jName.Data() << endl;
54  }
55 
56  jfile->Close();
57 
58  // create working directory jdir
59  TObjArray* token = TString(jName).Tokenize(TString('/'));
60  TObjString* stoken =(TObjString*)token->At(token->GetEntries()-1);
61  int jobID=TString(stoken->GetString().ReplaceAll("job","").ReplaceAll(".root","")).Atoi();
62  TString jdir = stoken->GetString().ReplaceAll(".root","");
63 
64  // -------------------------------------------------------------------------
65  // Check if output file already exists and asks if you want to overwrite it
66  // -------------------------------------------------------------------------
67  bool overwrite=true;
68  Long_t id,size=0,flags,mt;
69  int estat = gSystem->GetPathInfo(jdir.Data(),&id,&size,&flags,&mt);
70  if (estat==0) {
71  char answer[256];
72  strcpy(answer,"");
73  do {
74  cout << "Dir " << jdir.Data() << " already exist" << endl;
75  cout << "Do you want to overwrite it ? (y/n) ";
76  cin >> answer;
77  cout << endl << endl;
78  } while ((strcmp(answer,"y")!=0)&&(strcmp(answer,"n")!=0));
79  if (strcmp(answer,"n")==0) overwrite=false;
80  }
81  if(overwrite) {
82  // clean working directories
83  gSystem->Exec(TString("rm -rf ")+jdir+"/"+config_dir+"/*");
84  gSystem->Exec(TString("rm -rf ")+jdir+"/"+data_dir+"/*");
85  gSystem->Exec(TString("rm -rf ")+jdir+"/"+tmp_dir+"/*");
86  } else return;
87 
88  gSystem->Exec(TString("mkdir -p ")+jdir+"/"+config_dir);
89  gSystem->Exec(TString("mkdir -p ")+jdir+"/"+data_dir);
90  gSystem->Exec(TString("mkdir -p ")+jdir+"/"+tmp_dir);
91  TString juser_parameters = "config/juser_parameters.C";
92  if(uName!="") gSystem->Exec(TString("cp ")+uName+" "+jdir+"/"+juser_parameters);
93  gSystem->cd(jdir);
94 // else juser_parameters="";
95 // else gSystem->Exec(TString("touch ")+jdir+"/"+juser_parameters);
96  if(uName=="") {
97  gSystem->Exec(TString("echo \"{\n\" >> ")+juser_parameters);
98  gSystem->Exec(TString("echo \"jobfOptions=CWB_JOBF_SAVE_ALL;\n\" >> ")+juser_parameters);
99  gSystem->Exec(TString("echo \"}\n\" >> ")+juser_parameters);
100  }
101 // gSystem->Exec(TString("echo \"strcpy(config_dir,\"config\");\n\" >> ")+juser_parameters);
102  jName="../"+jName;
103 
104  // delete temp cfg
105  delete cfg;
106 
107  int runID=1;
108  if(ANALYSYS=="1G") {
109  cwb1G CWB(jName,juser_parameters);
110  CWB.run(runID);
111  } else
112  if(ANALYSYS=="2G") {
113  cwb2G CWB(jName,juser_parameters);
114  CWB.run(runID);
115  } else {
116  cout << "cwb_jnet - Error : analysis must be 1G or 2G" << endl;
117  if(jshell) exit(1); else return;
118  }
119 
120  jshell ? exit(0) : return;
121 }
CWB::config * cfg
char analysis[8]
Definition: config.hh:117
void Export(TString fname="")
Definition: config.cc:406
void cwb_jnet(TString jName="", TString uName="")
Definition: cwb_jnet.C:22
TString("c")
Long_t flags
Long_t size
void Import(TString umacro="")
Definition: config.cc:352
int jobID
Definition: cwb_net.C:195
Definition: cwb2G.hh:33
jfile
Definition: cwb_job_obj.C:43
char tmp_dir[512]
Definition: test_config1.C:153
virtual void run(int runID=0)
Definition: cwb.cc:281
char data_dir[512]
Definition: test_config1.C:152
TObjArray * token
char config_dir[512]
Definition: test_config1.C:144
char answer[256]
Definition: cwb1G.hh:31
int estat
strcpy(RunLabel, RUN_LABEL)
Long_t mt
bool overwrite
Definition: cwb_dump_inj.C:100
Long_t id
exit(0)