12 if(gSystem->Getenv(
"CWB_CLONEDIR_CHECK")!=NULL) {
18 cwb_clonedir_options_output.ToUpper();
19 if(cwb_clonedir_options_output!=
"") {
21 if(cwb_clonedir_options_output==
"LINKS") check=
true;
22 if(cwb_clonedir_options_output==
"MERGE") check=
true;
24 cout << endl <<
"cwb_clonedir Error : --output available value are : links/merge!!!" << endl << endl;
32 cwb_clonedir_options_config.ToUpper();
33 if(cwb_clonedir_options_config!=
"") {
35 if(cwb_clonedir_options_config==
"CHECK") check=
true;
37 cout << endl <<
"cwb_clonedir Error : --check available values are : true/false!!!" << endl << endl;
45 cwb_clonedir_options_simulation.ToUpper();
46 if(cwb_clonedir_options_simulation!=
"") {
48 if(cwb_clonedir_options_simulation==
"TRUE") check=
true;
49 if(cwb_clonedir_options_simulation==
"FALSE") check=
true;
51 cout << endl <<
"cwb_clonedir Error : --simulation available values are : true/false!!!" << endl << endl;
59 if(cwb_clonedir_options_chunk!=
"") {
63 if(cwb_clonedir_options_label!=
"") {
64 cout << endl <<
"cwb_clonedir Error : --chunk option can not be used when --label option is used!!!" << endl << endl;
67 if(!cwb_clonedir_options_chunk.IsDigit()) {
68 cout << endl <<
"cwb_clonedir Error : ckunk option is not a positive integer number!!!" << endl << endl;
76 if(cwb_clonedir_options==
"") {
78 cout <<
"Destination directory already exist ..." << endl;
83 TB.
checkFile(gSystem->Getenv(
"CWB_ROOTLOGON_FILE"));
84 TB.
checkFile(gSystem->Getenv(
"CWB_PARAMETERS_FILE"));
85 TB.
checkFile(gSystem->Getenv(
"CWB_UPARAMETERS_FILE"));
89 if(gSystem->Getenv(
"CWB_CLONEDIR_PWD")!=NULL) {
90 cwb_clonedir_pwd=
TString(gSystem->Getenv(
"CWB_CLONEDIR_PWD"));
92 cout <<
"cwb_clonedir.C - Error : CWB_CLONEDIR_PWD not declared" << endl;
98 if(gSystem->Getenv(
"CWB_CLONEDIR_SRC")!=NULL) {
99 cwb_clonedir_src=
TString(gSystem->Getenv(
"CWB_CLONEDIR_SRC"));
100 if(!cwb_clonedir_src.BeginsWith(
"/")) {
104 cout <<
"cwb_clonedir.C - Error : CWB_CLONEDIR_SRC not declared" << endl;
111 if(gSystem->Getenv(
"CWB_CLONEDIR_DEST")!=NULL) {
112 cwb_clonedir_dest=
TString(gSystem->Getenv(
"CWB_CLONEDIR_DEST"));
114 cout <<
"cwb_clonedir.C - Error : CWB_CLONEDIR_DEST not declared" << endl;
121 cwb_clonedir_options_output.ToUpper();
126 cwb_clonedir_options_config.ToUpper();
131 cwb_clonedir_options_simulation.ToUpper();
144 cwb_clonedir_options_jstage.ToUpper();
147 if(cwb_clonedir_options_jstage==
"FULL") cwb_stage_label=
"wave_";
148 if(cwb_clonedir_options_jstage==
"INIT") cwb_stage_label=
"init_";
149 if(cwb_clonedir_options_jstage==
"STRAIN") cwb_stage_label=
"strain_";
150 if(cwb_clonedir_options_jstage==
"CSTRAIN") cwb_stage_label=
"cstrain_";
151 if(cwb_clonedir_options_jstage==
"COHERENCE") cwb_stage_label=
"coherence_";
152 if(cwb_clonedir_options_jstage==
"SUPERCLUSTER") cwb_stage_label=
"supercluster_";
153 if(cwb_clonedir_options_jstage==
"LIKELIHOOD") cwb_stage_label=
"wave_";
155 char src_output_dir[1024];
159 if(cwb_clonedir_src.EndsWith(
"/")) cwb_clonedir_src.Resize(cwb_clonedir_src.Sizeof()-2);
161 const char* src_data_label = gSystem->BaseName(cwb_clonedir_src.Data());
164 if(cwb_clonedir_options_config==
"CHECK") {
168 sprintf(fparms,
"%s/%s",cwb_clonedir_src.Data(),gSystem->ExpandPathName(
"$CWB_UPARAMETERS_FILE"));
173 cout <<
"fparms : " << fparms << endl;
176 sprintf(cmd,
"diff %s %s | less",fparms,gSystem->ExpandPathName(
"$CWB_UPARAMETERS_FILE"));
182 cout <<
"Are src & dest config files compatibles ? (y/n) " << endl;
184 cout << endl << endl;
185 }
while ((strcmp(answer,
"y")!=0)&&(strcmp(answer,
"n")!=0));
186 if (strcmp(answer,
"n")==0) gSystem->Exit(1);
191 if(cwb_clonedir_options_output==
"LINKS") {
193 cwb_stage_label, src_data_label);
194 cout <<
"cwb_clonedir : create symbolic links in output dir ..." << endl;
200 for(
int i=0;
i<fileList.size();
i++) {
201 if(
i%100==0) cout <<
i <<
"/" << fileList.size() << endl;
203 const char* file_name_base = gSystem->BaseName(fileList[
i].Data());
204 TString sfile_name_base = file_name_base;
205 sfile_name_base.ReplaceAll(src_data_label,
data_label);
208 estat = gSystem->GetPathInfo(filePath,&
id,&size,&flags,&mt);
212 gSystem->Symlink(fileList[
i].Data(),link_to);
215 cout <<
"Number of new links " << newlinks <<
"/" << fileList.size() << endl;
222 if(cwb_clonedir_options_output==
"MERGE") {
226 cout <<
"cwb_clonedir : merge src wave&live in output dir ..." << endl;
227 TRegexp reg1(
".*M[0-9]+.root");
230 for(
int i=0;
i<fileList.size();
i++) {
232 if(fileList[
i].Contains(reg1)) {
235 TString smergeID = ((TObjString*)token->At(token->GetEntries()-2))->GetString();
236 smergeID.ReplaceAll(
"M",
"");
237 if(smergeID.IsDigit()) {
238 int mergeID = smergeID.Atoi();
239 if(max_version<mergeID) max_version=mergeID;
245 TString chunk_label = cwb_clonedir_options_chunk!=
"" ?
TString(
".K_chunk")+cwb_clonedir_options_chunk :
"";
251 if(cwb_clonedir_options_label==
"") {
252 sprintf(fwave,
"%s/wave_%s.M%d%s.root",src_merge_dir,src_data_label,max_version,chunk_label.Data());
253 sprintf(flive,
"%s/live_%s.M%d%s.root",src_merge_dir,src_data_label,max_version,chunk_label.Data());
254 sprintf(fmerge,
"%s/wave_%s.M%d%s.root",
output_dir,src_data_label,max_version,chunk_label.Data());
255 sprintf(flist,
"%s/wave_%s.M%d%s.lst",
output_dir,src_data_label,max_version,chunk_label.Data());
256 sprintf(fmdc,
"%s/mdc_%s.M%d%s.root",src_merge_dir,src_data_label,max_version,chunk_label.Data());
258 sprintf(fwave,
"%s/wave_%s.%s.root",src_merge_dir,src_data_label,cwb_clonedir_options_label.Data());
259 sprintf(flive,
"%s/live_%s.%s.root",src_merge_dir,src_data_label,cwb_clonedir_options_label.Data());
260 sprintf(fmerge,
"%s/wave_%s.%s.root",
output_dir,src_data_label,cwb_clonedir_options_label.Data());
261 sprintf(flist,
"%s/wave_%s.%s.lst",
output_dir,src_data_label,cwb_clonedir_options_label.Data());
262 sprintf(fmdc,
"%s/mdc_%s.%s.root",src_merge_dir,src_data_label,cwb_clonedir_options_label.Data());
264 cout <<
"fwave : " << fwave << endl;
265 cout <<
"flive : " << flive << endl;
266 cout <<
"fmerge : " << fmerge << endl;
267 cout <<
"flist : " << flist << endl;
268 cout <<
"fmdc : " << fmdc << endl;
270 estat = gSystem->GetPathInfo(fwave,&
id,&size,&flags,&mt);
271 if (estat!=0) {cout <<
"cwb_clonedir.C : Error - wave not exist : " << fwave << endl;
exit(1);}
272 if(cwb_clonedir_options_simulation==
"TRUE") {
273 estat = gSystem->GetPathInfo(fmdc,&
id,&size,&flags,&mt);
274 if (estat!=0) {cout <<
"cwb_clonedir.C : Error - mdc not exist : " << fmdc << endl;
exit(1);}
276 estat = gSystem->GetPathInfo(flive,&
id,&size,&flags,&mt);
277 if (estat!=0) {cout <<
"cwb_clonedir.C : Error - live not exist : " << flive << endl;
exit(1);}
281 if(checkList.size()!=0) {
283 cout <<
"cwb_clonedir.C : Error - files with source label : " << src_data_label << endl;
284 cout <<
"already exist in the output directory : " << cwb_clonedir_dest <<
286 cout <<
"Before to apply cwb_clonedir.C the following files must be removed !!!" << endl << endl;
287 for(
int i=0;
i<checkList.size();
i++) {
288 cout <<
i <<
" " << checkList[
i].Data() << endl;
292 if(chunk_label!=
"") {
295 if(checkList.size()!=0) {
297 cout <<
"cwb_clonedir.C : Error - files with chunk label : " << chunk_label << endl;
298 cout <<
"already exist in the output directory : " << cwb_clonedir_dest <<
300 cout <<
"Before to apply cwb_clonedir.C the following files must be removed !!!" << endl << endl;
301 for(
int i=0;
i<checkList.size();
i++) {
302 cout <<
i <<
" " << checkList[
i].Data() << endl;
309 M.AddFile(fwave,
true);
310 if(cwb_clonedir_options_simulation==
"TRUE") {
311 M.AddFile(fmdc,
true);
313 M.AddFile(flive,
true);
315 M.OutputFile(fmerge);
321 cout <<
"cwb_clonedir.C : Error - Merge failed !!!" << endl;
325 vector<TString> mergeList(2);
327 if(cwb_clonedir_options_simulation==
"TRUE") {
TString cwb_clonedir_options_output
TString cwb_clonedir_options_chunk
TString cwb_clonedir_options
TString cwb_clonedir_dest
TString cwb_clonedir_options_jstage
cout<< "Starting reading output directory ..."<< endl;vector< TString > fileList
TString cwb_clonedir_options_config
strcpy(RunLabel, RUN_LABEL)
TString cwb_clonedir_options_simulation
sprintf(src_merge_dir,"%s/%s", cwb_clonedir_src.Data(), merge_dir)
TString cwb_clonedir_options_label