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