Logo coherent WaveBurst  
Config Reference Guide
Logo
cwb_mklinks.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 new merge label using symbolic links : used by the cwb_mklinks command
20 
21 {
22 
23  CWB::Toolbox TB;
24 
25  int estat;
26  Long_t id,size,flags,mt;
27  char cmd[1024];
28 
29  TString cwb_merge_label = TString(gSystem->Getenv("CWB_MERGE_LABEL"));
30  TString cwb_mklinks_options = TString(gSystem->Getenv("CWB_MKLINKS_OPTIONS"));
31 
32  // check if label has the correct format (M#) & extract merge number
34  if(cwb_merge_label[0]!='M') {
35  cout << "Error : label " << cwb_merge_label.Data() << " has bad format (M#)" << endl;exit(1);
36  } else {
37  TString lcheck=cwb_merge_label;
38  lcheck.Remove(0,1);
39  if(!lcheck.IsDigit()) {
40  cout << endl << "Error : label " << cwb_merge_label.Data() << " has bad format (M#)" << endl << endl;exit(1);
41  }
42  cwb_merge_number=lcheck.Atoi();
43  }
44 
45  // get file list with data_label tag
46  char tag[256];sprintf(tag,"wave_%s",data_label);
47  vector<TString> fileList = TB.getFileListFromDir(merge_dir, ".root", tag,"",true);
48 
49  // compute new version for label
50  int iversion=0;
51  for(int i=0;i<fileList.size();i++) {
52  //cout << i << " " << fileList[i].Data() << endl;
53  if(fileList[i].Contains(".root")) {
54  TObjArray* token = TString(fileList[i]).Tokenize(TString("."));
55  TString srescueID = ((TObjString*)token->At(token->GetEntries()-2))->GetString();
56  srescueID.ReplaceAll("M","");
57  if(srescueID.IsDigit()) {
58  //cout << i << " " << fileList[i].Data() << endl;
59  int rescueID = srescueID.Atoi();
60  if(iversion<rescueID) iversion=rescueID;
61  }
62  }
63  }
64  iversion++;
65 
66  if(cwb_merge_number==0 || cwb_merge_number>=iversion) { // iversion replaced with the input user merge version
68  } else {
69  cout << endl << "cwb_merge.C : Error - the input merge version (M" << cwb_merge_number
70  << ") must be greater of the most recent merge version (M" << iversion-1 << ")" << endl << endl;
71  gSystem->Exit(1);
72  }
73 
74  TString mdir = merge_dir;
75 
76  // check if cwb_mklinks_options contains '--' than cwb_mklinks_options
77  // is used to extract all setcuts parameters
78  TString cwb_ilabel = "";
79  if(cwb_mklinks_options.Contains("--")) {
80  TString option="";
81  // get the cwb_tcuts_tree
82  cwb_ilabel = TB.getParameter(cwb_mklinks_options,"--ilabel");
83  }
84 
85  // check if cwb_ilabel is defined
86  if(cwb_ilabel=="") {
87  cout << "cwb_mklikns.C : Error - ilabel not defined" << endl;
88  gSystem->Exit(1);
89  }
90 
91  char tmp[256]="";
92  char fTag[256]="";
93  TString cwb_imerge_label="";
94  wavearray<int> fIndex(fileList.size()); fIndex=0;
95  TObjArray* token = TString(cwb_ilabel).Tokenize(TString("."));
96  for(int i=0;i<token->GetEntries();i++) {
97  TString stoken = ((TObjString*)token->At(i))->GetString();
98  // get input merge label
99  if(i==0) cwb_imerge_label=stoken;
100  //cout << "TOKEN : " << i << " " << stoken << endl;
101  // check if file exist
102  bool exist=false;
103  sprintf(tmp,"%s",fTag);
104  sprintf(fTag,"%s.%s",tmp,stoken.Data());
105  char fName[1024];sprintf(fName,"%s/wave_%s%s.root",mdir.Data(),data_label,fTag);
106  for(int i=0;i<fileList.size();i++) {
107  //cout << i << " " << fileList[i].Data() << " " << fName << endl;
108  if(fileList[i]==fName) {exist=true;fIndex[i]=1;break;}
109  }
110  if(!exist) {
111  cout << endl << "cwb_mklikns.C : Error - file: " << fName << " not exist!!!" << endl << endl;
112  gSystem->Exit(1);
113  }
114  }
115 
116 /*
117  cout << endl;
118  for(int i=0;i<fileList.size();i++) {
119  if(fIndex[i]) cout << i << " " << fileList[i].Data() << endl;
120  }
121  cout << endl;
122 */
123 
124  cout << endl;
125  cout << "merge dir : " << mdir << endl;
126  cout << "cwb_ilabel : " << cwb_ilabel << endl;
127  cout << "cwb_imerge_label : " << cwb_imerge_label << endl;
128  cout << "cwb_merge_label : " << cwb_merge_label << endl;
129  cout << endl;
130 
131  for(int i=0;i<fileList.size();i++) {
132  if(fIndex[i]) {
133  //cout << i << " " << fileList[i].Data() << endl;
134 
135  TString iwfname = fileList[i];
136  iwfname.ReplaceAll(mdir+"/","");
137  TString owfname = iwfname;
138  owfname.ReplaceAll(cwb_imerge_label,cwb_merge_label);
139 
140  TString ilfname = iwfname;
141  ilfname.ReplaceAll("wave_","merge_");
142  ilfname.ReplaceAll(".root",".lst");
143  TString olfname = owfname;
144  olfname.ReplaceAll("wave_","merge_");
145  olfname.ReplaceAll(".root",".lst");
146 
147  TString imfname = iwfname;
148  if(simulation) imfname.ReplaceAll("wave_","mdc_"); else imfname.ReplaceAll("wave_","live_");
149  TString omfname = owfname;
150  if(simulation) omfname.ReplaceAll("wave_","mdc_"); else omfname.ReplaceAll("wave_","live_");
151 
152  //cout << endl;
153  //cout << "iwfname: " << iwfname << endl;
154  //cout << "owfname: " << owfname << endl;
155  //cout << "imfname: " << imfname << endl;
156  //cout << "omfname: " << omfname << endl;
157  //cout << endl;
158 
159 
160  estat = gSystem->GetPathInfo(mdir+"/"+iwfname,&id,&size,&flags,&mt);
161  if(estat==0) {
162  sprintf(cmd,"cd %s;ln -sf %s %s",mdir.Data(),iwfname.Data(),owfname.Data());
163  cout << cmd << endl;
164  gSystem->Exec(cmd);
165  }
166 
167  estat = gSystem->GetPathInfo(mdir+"/"+ilfname,&id,&size,&flags,&mt);
168  if(estat==0) {
169  sprintf(cmd,"cd %s;ln -sf %s %s",mdir.Data(),ilfname.Data(),olfname.Data());
170  cout << cmd << endl;
171  gSystem->Exec(cmd);
172  }
173 
174  estat = gSystem->GetPathInfo(mdir+"/"+imfname,&id,&size,&flags,&mt);
175  if(estat==0) {
176  sprintf(cmd,"cd %s;ln -sf %s %s",mdir.Data(),imfname.Data(),omfname.Data());
177  cout << cmd << endl;
178  gSystem->Exec(cmd);
179  }
180  }
181  }
182 
183  exit(0);
184 }
simulation