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