Logo coherent WaveBurst  
Library Reference Guide
Logo
cwb_mkdir.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 // creates cwb working directory and subdirectories
20 
21 //#define SYMBOLIC_CONDOR_LOG_DIR // used in ATLAS cluster to fix issue with HSM
22 
23 {
25 
26  TB.checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
27  TB.checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
28 
29  bool cwb_mkdir_batch=false;
30  if(TString(gSystem->Getenv("CWB_MKDIR_OPTION")).CompareTo("batch")==0) cwb_mkdir_batch=true;
31  TString cwb_mkdir_wrkdir="";;
32  if(gSystem->Getenv("CWB_MKDIR_WRKDIR")!=NULL) {
33  // get working dir
34  // if cwb_mkdir_wrkdir="" : the working dir is the current
35  // if cwb_mkdir_wrkdir!="" : the working dir is created
36  cwb_mkdir_wrkdir=TString(gSystem->Getenv("CWB_MKDIR_WRKDIR"));
37  if(cwb_mkdir_wrkdir!="") {
38  // if present then strip last '/'
39  if(cwb_mkdir_wrkdir[cwb_mkdir_wrkdir.Sizeof()-2]=='/') {
40  cwb_mkdir_wrkdir.Resize(cwb_mkdir_wrkdir.Sizeof()-2);
41  }
42  }
43  }
44 
45  // check if wrkdir name is valid
46  if(cwb_mkdir_wrkdir.Contains(".M")) {
47  cout << "cwb_mkdir - Error : working directory name is not a valid name ..." << endl;
48  cout << "\"" << cwb_mkdir_wrkdir << "\"" << endl;
49  cout << "'.M' can not be used : it is used to label the merge data" << endl;
50  cout << "cwb_mkdir aborted" << endl << endl;
51  gSystem->Exit(1);
52  }
53  if(cwb_mkdir_wrkdir.Contains(".V")) {
54  cout << "cwb_mkdir - Error : working directory name is not a valid name ..." << endl;
55  cout << "\"" << cwb_mkdir_wrkdir << "\"" << endl;
56  cout << "'.V' can not be used : it is used to label the vetoed data" << endl;
57  cout << "cwb_mkdir aborted" << endl << endl;
58  gSystem->Exit(1);
59  }
60  if(cwb_mkdir_wrkdir.Contains(".C")) {
61  cout << "cwb_mkdir - Error : working directory name is not a valid name ..." << endl;
62  cout << "\"" << cwb_mkdir_wrkdir << "\"" << endl;
63  cout << "'.C' can not be used : it is used to label the cutted data" << endl;
64  cout << "cwb_mkdir aborted" << endl << endl;
65  gSystem->Exit(1);
66  }
67 
68  // get cluster site
70  if(gSystem->Getenv("SITE_CLUSTER")!=NULL) {
71  site_cluster = TString(gSystem->Getenv("SITE_CLUSTER"));
72  }
73 
74  #define NDIR 20
75 
77  int nDIR=0;
78  if(cwb_mkdir_wrkdir!="") {
79  dir_name[nDIR++] = cwb_mkdir_wrkdir;
80  cout << endl;
81  bool overwrite=TB.checkFile(cwb_mkdir_wrkdir,true,"working dir already exist !!!");
82  if(!overwrite) {cout << "cwb_mkdir aborted" << endl << endl; gSystem->Exit(1);}
83  }
84  dir_name[nDIR++] = tmp_dir;
85  dir_name[nDIR++] = data_dir;
86  dir_name[nDIR++] = config_dir;
87  dir_name[nDIR++] = input_dir;
88  dir_name[nDIR++] = output_dir;
89  dir_name[nDIR++] = macro_dir;
90  dir_name[nDIR++] = report_dir;
91  dir_name[nDIR++] = condor_log;
92 #ifdef SYMBOLIC_CONDOR_LOG_DIR
93  if(site_cluster=="ATLAS") {
94  // used in ATLAS cluster to fix issue with HSM
95  // condor log dir is in the local header nodes
96  if(cwb_mkdir_wrkdir!="") {
97  dir_name[nDIR++] = TString(condor_log_dir)+TString("/")+gSystem->BaseName(cwb_mkdir_wrkdir);
98  } else {
99  dir_name[nDIR++] = TString(condor_log_dir)+TString("/")++TString(data_label);
100  }
101  Long_t id,size=0,flags,mt;
102  int estat = gSystem->GetPathInfo(dir_name[nDIR-1].Data(),&id,&size,&flags,&mt);
103  if(estat==0) {
104  cout << endl;
105  cout << "cwb_mkdir - Error : condor log directory ..." << endl;
106  cout << "\"" << dir_name[nDIR-1] << "\"" << endl;
107  cout << "already exist, select a unique name for the working directory" << endl;
108  cout << "cwb_mkdir aborted" << endl << endl;
109  gSystem->Exit(1);
110  }
111  } else {
112  dir_name[nDIR++] = log_dir;
113  }
114 #else
115  dir_name[nDIR++] = log_dir;
116 #endif
117  dir_name[nDIR++] = condor_dir;
118  dir_name[nDIR++] = merge_dir;
119  dir_name[nDIR++] = ced_dir;
120  dir_name[nDIR++] = pp_dir;
121  dir_name[nDIR++] = dump_dir;
122  // www report dir is created only if the env WWW_PUBLIC_DIR != ""
123  if(TString(www_dir)!="") {
124  if(cwb_mkdir_wrkdir!="") dir_name[nDIR] = TString(www_dir)+TString("/")+gSystem->BaseName(cwb_mkdir_wrkdir);
125  else dir_name[nDIR] = TString(www_dir)+TString("/")+TString(data_label);
126  dir_name[nDIR].ReplaceAll(report_dir+TString("/"),"");
127  // check if www dir exist, must be unique !!!
128  cout << endl;
129  bool overwrite=TB.checkFile(dir_name[nDIR],true,"www report directory must be unique !!!");
130  if(!overwrite) {cout << "cwb_mkdir aborted" << endl << endl; gSystem->Exit(1);}
131  nDIR++;
132  }
133 /*
134  dir_name[nDIR] = TString(www_dir)+TString("/")+TString(data_label)+TString("/")+TString(pp_dir);
135  dir_name[nDIR].ReplaceAll(report_dir+TString("/"),"");
136  nDIR++;
137  dir_name[nDIR] = TString(www_dir)+TString("/")+TString(data_label)+TString("/")+TString(ced_dir);
138  dir_name[nDIR].ReplaceAll(report_dir+TString("/"),"");
139  nDIR++;
140  dir_name[nDIR] = TString(www_dir)+TString("/")+TString(data_label)+TString("/")+TString(dump_dir);
141  dir_name[nDIR].ReplaceAll(report_dir+TString("/"),"");
142  nDIR++;
143 */
144 
145  char cmd[1024];
146  char ldir[1024];
147  for(int i=0;i<nDIR;i++) {
148 
149  if(dir_name[i]=="") continue;
150 
151  sprintf(ldir,"%s",dir_name[i].Data());
152 
153  // ----------------------------------------------------------------
154  // Check if dir lists exist
155  // ----------------------------------------------------------------
156  Long_t id,size,flags,mt;
157  int estat = gSystem->GetPathInfo(ldir,&id,&size,&flags,&mt);
158  if (estat==0) {
159  char answer[256];
160  strcpy(answer,"");
161  do {
162  cout << endl;
163  cout << "dir \"" << ldir << "\" already exist" << endl;
164  cout << "Do you want to remove the files ? (y/n) ";
165  if(cwb_mkdir_batch) strcpy(answer,"y"); else cin >> answer;
166  cout << endl;
167  } while ((strcmp(answer,"y")!=0)&&(strcmp(answer,"n")!=0));
168  if (strcmp(answer,"y")==0) {
169  sprintf(cmd,"mkdir -p %s",ldir);
170  cout << cmd << endl;
171  gSystem->Exec(cmd);
172  }
173  } else {
174  sprintf(cmd,"mkdir -p %s",ldir);
175  cout << cmd << endl;
176  gSystem->Exec(cmd);
177 // sprintf(cmd,"rm %s/*",ldir);
178 // cout << cmd << endl;
179 // gSystem->Exec(cmd);
180  }
181 
182  // if working dir is created then cd to wrkdir
183  if(i==0 && cwb_mkdir_wrkdir!="") gSystem->ChangeDirectory(cwb_mkdir_wrkdir.Data());
184  }
185 
186 #ifdef SYMBOLIC_CONDOR_LOG_DIR
187  if(site_cluster=="ATLAS") {
188  // used in ATLAS cluster to fix issue with HSM
189  // condor log dir is in the local header nodes
190  if(cwb_mkdir_wrkdir!="") {
191  sprintf(cmd,"ln -sf %s/%s %s",condor_log_dir.Data(),
192  gSystem->BaseName(cwb_mkdir_wrkdir),log_dir);
193  } else {
194  sprintf(cmd,"ln -sf %s/%s %s",condor_log_dir.Data(),data_label,log_dir);
195  }
196  cout << cmd << endl;
197  gSystem->Exec(cmd);
198  }
199 #endif
200 
201  TString cwb_rootlogon_file = TString(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
202  sprintf(cmd,"ln -sf %s rootlogon.C",cwb_rootlogon_file.Data());
203  //cout << cmd << endl;
204  //gSystem->Exec(cmd);
205 
206  TString cwb_dir_name = TString(gSystem->Getenv("CWB_MACROS"));
207  sprintf(cmd,"ln -sf %s/README.cwb",cwb_dir_name.Data());
208  //cout << cmd << endl;
209  //gSystem->Exec(cmd);
210 
211  TString cwb_scripts = TString(gSystem->Getenv("CWB_SCRIPTS"));
212  TString cwb_nets_name = TString(gSystem->Getenv("CWB_NETS_FILE"));
213  if(gSystem->Getenv("_USE_PEGASUS")!=NULL) {
214  // symbolic links for pegasus scripts
215  sprintf(cmd,"ln -sf %s %s/cwb.sh",cwb_nets_name.Data(),condor_dir);
216  cout << cmd << endl;
217  gSystem->Exec(cmd);
218  } else {
219  // symbolic links for condor scripts
220  sprintf(cmd,"ln -sf %s/cwb_loudest.sh %s/loudest.sh",cwb_scripts.Data(),condor_dir);
221  cout << cmd << endl;
222  gSystem->Exec(cmd);
223 
224  sprintf(cmd,"ln -sf %s/cwb_ced.sh %s/ced.sh",cwb_scripts.Data(),condor_dir);
225  cout << cmd << endl;
226  gSystem->Exec(cmd);
227 
228  sprintf(cmd,"ln -sf %s %s/cwb.sh",cwb_nets_name.Data(),condor_dir);
229  cout << cmd << endl;
230  gSystem->Exec(cmd);
231  }
232 
233  // www report links are created only if the env WWW_PUBLIC_DIR != ""
234  if(TString(www_dir)!="") {
235  // data label
236  char www_label[1024];
237  TObjArray* token = TString(work_dir).Tokenize(TString("/"));
238  sprintf(www_label,"%s",((TObjString*)token->At(token->GetEntries()-1))->GetString().Data());
239  if(cwb_mkdir_wrkdir!="") {
240  TObjArray* token2 = TString(cwb_mkdir_wrkdir).Tokenize(TString("/"));
241  sprintf(www_label,"%s",((TObjString*)token2->At(token2->GetEntries()-1))->GetString().Data());
242  }
243 
244  TString cwb_dir = cwb_mkdir_wrkdir.BeginsWith("/") ? cwb_mkdir_wrkdir : TString(work_dir)+"/"+cwb_mkdir_wrkdir;
245 
246  sprintf(cmd,"ln -sf %s/%s %s/%s",cwb_dir.Data(),pp_dir,www_dir,www_label);
247  cout << cmd << endl;
248  gSystem->Exec(cmd);
249 
250  sprintf(cmd,"ln -sf %s/%s %s/%s",cwb_dir.Data(),ced_dir,www_dir,www_label);
251  cout << cmd << endl;
252  gSystem->Exec(cmd);
253 
254  sprintf(cmd,"ln -sf %s/%s %s/%s",cwb_dir.Data(),dump_dir,www_dir,www_label);
255  cout << cmd << endl;
256  gSystem->Exec(cmd);
257  }
258 
259  exit(0);
260 }
TString cwb_nets_name
Definition: cwb_mkdir.C:212
TString cwb_dir_name
Definition: cwb_mkdir.C:206
TString site_cluster
Definition: cwb_mkdir.C:69
TString condor_log_dir
char www_label[512]
TString("c")
char www_dir[512]
Definition: test_config1.C:157
CWB::Toolbox TB
Long_t flags
Long_t size
#define NDIR
Definition: cwb_mkdir.C:74
char macro_dir[512]
Definition: test_config1.C:150
char report_dir[512]
Definition: test_config1.C:149
sprintf(cmd,"ln -sf %s rootlogon.C", cwb_rootlogon_file.Data())
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:4670
char ced_dir[512]
Definition: test_config1.C:154
char data_label[512]
Definition: test_config1.C:160
char input_dir[512]
Definition: test_config1.C:145
char ldir[1024]
Definition: cwb_mkdir.C:146
char tmp_dir[512]
Definition: test_config1.C:153
bool cwb_mkdir_batch
Definition: cwb_mkdir.C:29
char cmd[1024]
Definition: cwb_mkdir.C:145
char merge_dir[512]
Definition: test_config1.C:147
TString cwb_scripts
Definition: cwb_mkdir.C:211
char data_dir[512]
Definition: test_config1.C:152
TObjArray * token
char log_dir[512]
Definition: test_config1.C:151
char config_dir[512]
Definition: test_config1.C:144
exit(0)
TString cwb_rootlogon_file
Definition: cwb_mkdir.C:201
char answer[256]
TString dir_name[NDIR]
Definition: cwb_mkdir.C:76
char dump_dir[512]
Definition: test_config1.C:156
char pp_dir[512]
Definition: test_config1.C:155
int estat
strcpy(RunLabel, RUN_LABEL)
Long_t mt
char condor_log[512]
Definition: test_config1.C:163
bool overwrite
Definition: cwb_dump_inj.C:100
Long_t id
char condor_dir[512]
Definition: test_config1.C:148
char work_dir[512]
Definition: test_config1.C:143
char output_dir[512]
Definition: test_config1.C:146
int nDIR
Definition: cwb_mkdir.C:77