19 |
|
#include "TString.h" |
20 |
|
#include "TFile.h" |
21 |
|
#include "TTree.h" |
22 |
+ |
#include "TSeqCollection.h" |
23 |
|
#include <iostream> |
24 |
|
#include <fstream> |
25 |
|
#include <set> |
34 |
|
ofstream implf; |
35 |
|
ofstream branchfile; |
36 |
|
|
37 |
< |
void makeHeaderFile(TFile *f, bool paranoid, string Classname); |
37 |
> |
void makeHeaderFile(TFile *f, std::string treeName, bool paranoid, string Classname); |
38 |
|
void makeSrcFile(std::string Classname, std::string branchNamesFile); |
39 |
|
void makeBranchFile(std::string branchNamesFile); |
40 |
|
void makeDriverFile(std::string fname); |
41 |
|
|
41 |
– |
struct hltcompare { |
42 |
– |
bool operator() (const TString& lhs, const TString& rhs) const { |
43 |
– |
string s_match = "hlt_bits"; |
44 |
– |
string s_lhs = (string) lhs; |
45 |
– |
string s_rhs = (string) rhs; |
46 |
– |
s_lhs = s_lhs.replace( s_lhs.find(s_match), s_match.length(), "" ); |
47 |
– |
s_rhs = s_rhs.replace( s_rhs.find(s_match), s_match.length(), "" ); |
48 |
– |
int i_lhs = atoi( s_lhs.c_str() ); |
49 |
– |
int i_rhs = atoi( s_rhs.c_str() ); |
50 |
– |
return i_lhs < i_rhs; |
51 |
– |
} |
52 |
– |
}; |
53 |
– |
|
54 |
– |
|
42 |
|
|
43 |
|
//------------------------------------------------------------------------------------------------- |
44 |
< |
void makeCMS2ClassFiles (std::string fname, bool paranoid = true, |
45 |
< |
std::string branchNamesFile="", std::string className = "CMS2") { |
44 |
> |
void makeCMS2ClassFiles (std::string fname, bool paranoid = true, std::string treeName="", |
45 |
> |
std::string branchNamesFile="", std::string className = "CMS2") { |
46 |
|
|
47 |
< |
using namespace std; |
47 |
> |
using namespace std; |
48 |
|
|
49 |
< |
TFile *f = TFile::Open( fname.c_str() ); |
49 |
> |
TFile *f = TFile::Open( fname.c_str() ); |
50 |
|
|
51 |
< |
if(f==NULL) { |
52 |
< |
cout << "File does not exist. Exiting program" << endl; |
53 |
< |
return; |
54 |
< |
} |
51 |
> |
if(f==NULL) { |
52 |
> |
cout << "File does not exist. Exiting program" << endl; |
53 |
> |
return; |
54 |
> |
} |
55 |
|
|
56 |
< |
if(f->IsZombie()) { |
57 |
< |
cout << "File is not a valid root file, or root file is corruped" << endl; |
58 |
< |
cout << "Exiting..." << endl; |
59 |
< |
return; |
60 |
< |
} |
56 |
> |
if(f->IsZombie()) { |
57 |
> |
cout << "File is not a valid root file, or root file is corruped" << endl; |
58 |
> |
cout << "Exiting..." << endl; |
59 |
> |
return; |
60 |
> |
} |
61 |
|
|
62 |
< |
//check if the branchNamesFile exists |
63 |
< |
if(branchNamesFile != "") { |
64 |
< |
struct stat results; |
65 |
< |
int intStat = stat(branchNamesFile.c_str(), &results); |
66 |
< |
if(intStat != 0) { |
67 |
< |
cout << "Cannot open " << branchNamesFile << endl; |
68 |
< |
cout << "Please make sure that the file exists" << endl; |
69 |
< |
return; |
62 |
> |
//check if the branchNamesFile exists |
63 |
> |
if(branchNamesFile != "") { |
64 |
> |
struct stat results; |
65 |
> |
int intStat = stat(branchNamesFile.c_str(), &results); |
66 |
> |
if(intStat != 0) { |
67 |
> |
cout << "Cannot open " << branchNamesFile << endl; |
68 |
> |
cout << "Please make sure that the file exists" << endl; |
69 |
> |
return; |
70 |
> |
} |
71 |
|
} |
84 |
– |
} |
72 |
|
|
73 |
|
|
74 |
< |
//class is CMS2 by default |
75 |
< |
//std::string Classname = className=="" ? "CMS2" : className; |
74 |
> |
//class is CMS2 by default |
75 |
> |
//std::string Classname = className=="" ? "CMS2" : className; |
76 |
|
|
77 |
< |
headerf.open((className+".h").c_str()); |
78 |
< |
implf.open((className+".cc").c_str()); |
79 |
< |
codef.open("ScanChain.C"); |
77 |
> |
headerf.open((className+".h").c_str()); |
78 |
> |
implf.open((className+".cc").c_str()); |
79 |
> |
codef.open("ScanChain.C"); |
80 |
|
|
81 |
< |
implf << "#include \"" << className+".h" << "\"\n" << className << " cms2;" << endl; |
82 |
< |
makeHeaderFile(f, paranoid, className); |
83 |
< |
makeSrcFile(className, branchNamesFile); |
84 |
< |
if(branchNamesFile!="") |
85 |
< |
makeBranchFile(branchNamesFile); |
86 |
< |
implf << "}" << endl; |
87 |
< |
implf.close(); |
88 |
< |
headerf << "}" << endl; |
89 |
< |
headerf << "#endif" << endl; |
90 |
< |
headerf.close(); |
81 |
> |
implf << "#include \"" << className+".h" << "\"\n" << className << " cms2;" << endl; |
82 |
> |
makeHeaderFile(f, treeName, paranoid, className); |
83 |
> |
makeSrcFile(className, branchNamesFile); |
84 |
> |
if(branchNamesFile!="") |
85 |
> |
makeBranchFile(branchNamesFile); |
86 |
> |
implf << "}" << endl; |
87 |
> |
implf.close(); |
88 |
> |
headerf << "}" << endl; |
89 |
> |
headerf << "#endif" << endl; |
90 |
> |
headerf.close(); |
91 |
|
|
92 |
|
|
93 |
< |
codef.close(); |
93 |
> |
codef.close(); |
94 |
|
|
95 |
< |
makeDriverFile(fname); |
95 |
> |
makeDriverFile(fname); |
96 |
|
|
97 |
< |
f->Close(); |
97 |
> |
f->Close(); |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
|
//------------------------------------------------------------------------------------------------- |
102 |
< |
void makeHeaderFile(TFile *f, bool paranoid, string Classname) { |
102 |
> |
void makeHeaderFile(TFile *f, std::string treeName, bool paranoid, string Classname) { |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
< |
headerf << "// -*- C++ -*-" << endl; |
107 |
< |
headerf << "#ifndef " << Classname << "_H" << endl; |
108 |
< |
headerf << "#define " << Classname << "_H" << endl; |
109 |
< |
headerf << "#include \"Math/LorentzVector.h\"" << endl; |
110 |
< |
headerf << "#include \"Math/Point3D.h\"" << endl; |
111 |
< |
headerf << "#include \"TMath.h\"" << endl; |
112 |
< |
headerf << "#include \"TBranch.h\"" << endl; |
113 |
< |
headerf << "#include \"TTree.h\"" << endl; |
114 |
< |
headerf << "#include \"TH1F.h\"" << endl; |
115 |
< |
headerf << "#include \"TFile.h\"" << endl; |
116 |
< |
headerf << "#include <vector> " << endl; |
117 |
< |
headerf << "typedef ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> > LorentzVector;" << endl << endl; |
118 |
< |
if (paranoid) |
119 |
< |
headerf << "#define PARANOIA" << endl << endl; |
120 |
< |
headerf << "using namespace std; " << endl; |
121 |
< |
headerf << "class " << Classname << " {" << endl; |
122 |
< |
headerf << "private: " << endl; |
123 |
< |
headerf << "protected: " << endl; |
124 |
< |
headerf << "\tunsigned int index;" << endl; |
125 |
< |
TTree *ev = (TTree*)f->Get("Events"); |
126 |
< |
TList *fullarray = ev->GetListOfAliases(); |
127 |
< |
TList *aliasarray = new TList(); |
106 |
> |
headerf << "// -*- C++ -*-" << endl; |
107 |
> |
headerf << "#ifndef " << Classname << "_H" << endl; |
108 |
> |
headerf << "#define " << Classname << "_H" << endl; |
109 |
> |
headerf << "#include \"Math/LorentzVector.h\"" << endl; |
110 |
> |
headerf << "#include \"Math/Point3D.h\"" << endl; |
111 |
> |
headerf << "#include \"TMath.h\"" << endl; |
112 |
> |
headerf << "#include \"TBranch.h\"" << endl; |
113 |
> |
headerf << "#include \"TTree.h\"" << endl; |
114 |
> |
headerf << "#include \"TH1F.h\"" << endl; |
115 |
> |
headerf << "#include \"TFile.h\"" << endl; |
116 |
> |
headerf << "#include \"TBits.h\"" << endl; |
117 |
> |
headerf << "#include <vector> " << endl; |
118 |
> |
headerf << "typedef ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> > LorentzVector;" << endl << endl; |
119 |
> |
if (paranoid) |
120 |
> |
headerf << "#define PARANOIA" << endl << endl; |
121 |
> |
headerf << "using namespace std; " << endl; |
122 |
> |
headerf << "class " << Classname << " {" << endl; |
123 |
> |
headerf << "private: " << endl; |
124 |
> |
headerf << "protected: " << endl; |
125 |
> |
headerf << "\tunsigned int index;" << endl; |
126 |
> |
// TTree *ev = (TTree*)f->Get("Events"); |
127 |
> |
TList* list_of_keys = f->GetListOfKeys(); |
128 |
> |
std::string tree_name = ""; |
129 |
> |
if (treeName.empty()) { |
130 |
> |
unsigned int ntrees = 0; |
131 |
> |
for (unsigned int idx = 0; idx < (unsigned int)list_of_keys->GetSize(); idx++) { |
132 |
> |
const char* obj_name = list_of_keys->At(idx)->GetName(); |
133 |
> |
TObject* obj = f->Get(obj_name); |
134 |
> |
if (obj->InheritsFrom("TTree")) { |
135 |
> |
++ntrees; |
136 |
> |
tree_name = obj_name; |
137 |
> |
} |
138 |
> |
} |
139 |
> |
if (ntrees == 0) { |
140 |
> |
std::cout << "Did not find a tree. Exiting." << std::endl; |
141 |
> |
return; |
142 |
> |
} |
143 |
> |
if (ntrees > 1) { |
144 |
> |
std::cout << "Found more than one tree. Please specify a tree to use." << std::endl; |
145 |
> |
return; |
146 |
> |
} |
147 |
> |
} |
148 |
> |
else |
149 |
> |
tree_name = treeName; |
150 |
> |
|
151 |
> |
TTree *ev = (TTree*)f->Get(tree_name.c_str()); |
152 |
> |
|
153 |
> |
TSeqCollection *fullarray = ev->GetListOfAliases(); |
154 |
> |
bool have_aliases = true; |
155 |
> |
if (!fullarray) { |
156 |
> |
have_aliases = false; |
157 |
> |
fullarray = ev->GetListOfBranches(); |
158 |
> |
} |
159 |
> |
|
160 |
> |
// if (have_aliases && fullarray->GetSize() != ev->GetListOfBranches()->GetSize()) { |
161 |
> |
// std::cout << "Tree has " << fullarray->GetSize() << " aliases and " << ev->GetListOfBranches()->GetSize() << " branches. Exiting." << std::endl; |
162 |
> |
// return; |
163 |
> |
// } |
164 |
> |
|
165 |
> |
TList *aliasarray = new TList(); |
166 |
|
|
167 |
< |
//for(Int_t i = 0; i < aliasarray->GetSize(); ++i) { |
168 |
< |
for(Int_t i = 0; i < fullarray->GetSize(); ++i) { |
169 |
< |
TString aliasname(fullarray->At(i)->GetName()); |
170 |
< |
TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
171 |
< |
TString branchname(branch->GetName()); |
172 |
< |
TString branchtitle(branch->GetTitle()); |
173 |
< |
if(!branchname.BeginsWith("int") && |
174 |
< |
!branchname.BeginsWith("uint") && |
175 |
< |
!branchname.BeginsWith("bool") && |
176 |
< |
!branchname.BeginsWith("float") && |
177 |
< |
!branchname.BeginsWith("double") && |
178 |
< |
!branchtitle.EndsWith("/F") && |
179 |
< |
!branchtitle.EndsWith("/I") && |
180 |
< |
!branchtitle.EndsWith("/i") && |
181 |
< |
!branchtitle.BeginsWith("TString")) |
182 |
< |
continue; |
183 |
< |
aliasarray->Add(fullarray->At(i)); |
184 |
< |
} |
167 |
> |
for(Int_t i = 0; i < fullarray->GetSize(); ++i) { |
168 |
> |
TString aliasname(fullarray->At(i)->GetName()); |
169 |
> |
// TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
170 |
> |
TBranch *branch = 0; |
171 |
> |
if (have_aliases) |
172 |
> |
branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
173 |
> |
else |
174 |
> |
branch = (TBranch*)fullarray->At(i); |
175 |
> |
|
176 |
> |
TString branchname(branch->GetName()); |
177 |
> |
TString branchtitle(branch->GetTitle()); |
178 |
> |
if(!branchname.BeginsWith("int") && |
179 |
> |
!branchname.BeginsWith("uint") && |
180 |
> |
!branchname.BeginsWith("bool") && |
181 |
> |
!branchname.BeginsWith("float") && |
182 |
> |
!branchname.BeginsWith("double") && |
183 |
> |
!branchtitle.EndsWith("/F") && |
184 |
> |
!branchtitle.EndsWith("/I") && |
185 |
> |
!branchtitle.EndsWith("/i") && |
186 |
> |
!branchtitle.EndsWith("/O") && |
187 |
> |
!branchtitle.BeginsWith("TString") && |
188 |
> |
!branchtitle.BeginsWith("TBits")) |
189 |
> |
continue; |
190 |
> |
aliasarray->Add(fullarray->At(i)); |
191 |
> |
} |
192 |
|
|
193 |
|
|
194 |
< |
for(Int_t i = 0; i< aliasarray->GetSize(); ++i) { |
194 |
> |
for(Int_t i = 0; i< aliasarray->GetSize(); ++i) { |
195 |
|
|
196 |
< |
//Class name is blank for a int of float |
197 |
< |
TString aliasname(aliasarray->At(i)->GetName()); |
198 |
< |
TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
196 |
> |
//Class name is blank for a int of float |
197 |
> |
TString aliasname(aliasarray->At(i)->GetName()); |
198 |
> |
// TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
199 |
> |
TBranch *branch = 0; |
200 |
> |
if (have_aliases) |
201 |
> |
branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
202 |
> |
else |
203 |
> |
branch = (TBranch*)aliasarray->At(i); |
204 |
|
|
205 |
< |
TString classname = branch->GetClassName(); |
206 |
< |
TString title = branch->GetTitle(); |
207 |
< |
if ( classname.Contains("vector") ) { |
208 |
< |
if(classname.Contains("edm::Wrapper<") ) { |
209 |
< |
classname = classname(0,classname.Length()-2); |
210 |
< |
classname.ReplaceAll("edm::Wrapper<",""); |
211 |
< |
headerf << "\t" << classname << " " << aliasname << "_;" << endl; |
212 |
< |
} else { |
213 |
< |
headerf << "\t" << classname << " *" << aliasname << "_;" << endl; |
214 |
< |
} |
215 |
< |
} else { |
205 |
> |
TString classname = branch->GetClassName(); |
206 |
> |
TString title = branch->GetTitle(); |
207 |
> |
if ( classname.Contains("vector") ) { |
208 |
> |
if(classname.Contains("edm::Wrapper<") ) { |
209 |
> |
classname = classname(0,classname.Length()-2); |
210 |
> |
classname.ReplaceAll("edm::Wrapper<",""); |
211 |
> |
headerf << "\t" << classname << " " << aliasname << "_;" << endl; |
212 |
> |
} else { |
213 |
> |
headerf << "\t" << classname << " *" << aliasname << "_;" << endl; |
214 |
> |
} |
215 |
> |
} else { |
216 |
|
|
217 |
< |
if(classname != "" ) { //LorentzVector |
218 |
< |
if(classname.Contains("edm::Wrapper<") ) { |
219 |
< |
classname = classname(0,classname.Length()-1); |
220 |
< |
classname.ReplaceAll("edm::Wrapper<",""); |
221 |
< |
headerf << "\t" << classname << " " << aliasname << "_;" << endl; |
222 |
< |
} else { |
223 |
< |
headerf << "\t" << classname << " *" << aliasname << "_;" << endl; |
224 |
< |
} |
225 |
< |
} else { |
226 |
< |
if(title.EndsWith("/i")) |
227 |
< |
headerf << "\tunsigned int" << "\t" << aliasname << "_;" << endl; |
228 |
< |
if(title.EndsWith("/F")) |
229 |
< |
headerf << "\tfloat" << "\t" << aliasname << "_;" << endl; |
230 |
< |
if(title.EndsWith("/I")) |
231 |
< |
headerf << "\tint" << "\t" << aliasname << "_;" << endl; |
232 |
< |
} |
233 |
< |
} |
234 |
< |
headerf << "\tTBranch *" << Form("%s_branch",aliasname.Data()) << ";" << endl; |
235 |
< |
headerf << "\tbool " << Form("%s_isLoaded",aliasname.Data()) << ";" << endl; |
236 |
< |
} |
217 |
> |
if(classname != "" ) { //LorentzVector |
218 |
> |
if(classname.Contains("edm::Wrapper<") ) { |
219 |
> |
classname = classname(0,classname.Length()-1); |
220 |
> |
classname.ReplaceAll("edm::Wrapper<",""); |
221 |
> |
headerf << "\t" << classname << " " << aliasname << "_;" << endl; |
222 |
> |
} else { |
223 |
> |
headerf << "\t" << classname << " *" << aliasname << "_;" << endl; |
224 |
> |
} |
225 |
> |
} else { |
226 |
> |
if(title.EndsWith("/i")) |
227 |
> |
headerf << "\tunsigned int" << "\t" << aliasname << "_;" << endl; |
228 |
> |
if(title.EndsWith("/F")) |
229 |
> |
headerf << "\tfloat" << "\t" << aliasname << "_;" << endl; |
230 |
> |
if(title.EndsWith("/I")) |
231 |
> |
headerf << "\tint" << "\t" << aliasname << "_;" << endl; |
232 |
> |
if(title.EndsWith("/O")) |
233 |
> |
headerf << "\tbool" << "\t" << aliasname << "_;" << endl; |
234 |
> |
} |
235 |
> |
} |
236 |
> |
headerf << "\tTBranch *" << Form("%s_branch",aliasname.Data()) << ";" << endl; |
237 |
> |
headerf << "\tbool " << Form("%s_isLoaded",aliasname.Data()) << ";" << endl; |
238 |
> |
} |
239 |
|
|
240 |
|
|
241 |
< |
headerf << "public: " << endl; |
242 |
< |
headerf << "void Init(TTree *tree) {" << endl; |
241 |
> |
headerf << "public: " << endl; |
242 |
> |
headerf << "void Init(TTree *tree) {" << endl; |
243 |
|
|
244 |
|
|
245 |
< |
// SetBranchAddresses for LorentzVectors |
246 |
< |
for(Int_t i = 0; i< aliasarray->GetSize(); i++) { |
247 |
< |
TString aliasname(aliasarray->At(i)->GetName()); |
248 |
< |
TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
249 |
< |
TString classname = branch->GetClassName(); |
250 |
< |
if ( !classname.Contains("vector<vector") ) { |
251 |
< |
if ( classname.Contains("Lorentz") || classname.Contains("PositionVector") ) { |
252 |
< |
headerf << "\t" << Form("%s_branch",aliasname.Data()) << " = 0;" << endl; |
253 |
< |
headerf << "\t" << "if (tree->GetAlias(\"" << aliasname << "\") != 0) {" << endl; |
254 |
< |
headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << " = tree->GetBranch(tree->GetAlias(\"" << aliasname << "\"));" << endl; |
255 |
< |
headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << "->SetAddress(&" << aliasname << "_);" << endl << "\t}" << endl; |
256 |
< |
} |
257 |
< |
} |
258 |
< |
} |
259 |
< |
|
260 |
< |
|
261 |
< |
// SetBranchAddresses for everything else |
262 |
< |
headerf << " tree->SetMakeClass(1);" << endl; |
263 |
< |
for(Int_t i = 0; i< aliasarray->GetSize(); i++) { |
264 |
< |
TString aliasname(aliasarray->At(i)->GetName()); |
265 |
< |
TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
266 |
< |
TString classname = branch->GetClassName(); |
267 |
< |
if ( ! (classname.Contains("Lorentz") || classname.Contains("PositionVector")) || classname.Contains("vector<vector") ) { |
268 |
< |
headerf << "\t" << Form("%s_branch",aliasname.Data()) << " = 0;" << endl; |
269 |
< |
headerf << "\t" << "if (tree->GetAlias(\"" << aliasname << "\") != 0) {" << endl; |
270 |
< |
headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << " = tree->GetBranch(tree->GetAlias(\"" << aliasname << "\"));" << endl; |
271 |
< |
headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << "->SetAddress(&" << aliasname << "_);" << endl << "\t}" << endl; |
272 |
< |
} |
273 |
< |
} |
274 |
< |
|
275 |
< |
headerf << " tree->SetMakeClass(0);" << endl; |
276 |
< |
headerf << "}" << endl; |
277 |
< |
|
278 |
< |
// GetEntry |
279 |
< |
headerf << "void GetEntry(unsigned int idx) " << endl; |
280 |
< |
headerf << "\t// this only marks branches as not loaded, saving a lot of time" << endl << "\t{" << endl; |
281 |
< |
headerf << "\t\tindex = idx;" << endl; |
282 |
< |
for(Int_t i = 0; i< aliasarray->GetSize(); i++) { |
283 |
< |
TString aliasname(aliasarray->At(i)->GetName()); |
284 |
< |
headerf << "\t\t" << Form("%s_isLoaded",aliasname.Data()) << " = false;" << endl; |
285 |
< |
} |
286 |
< |
headerf << "\t}" << endl << endl; |
287 |
< |
|
288 |
< |
// LoadAllBranches |
289 |
< |
headerf << "void LoadAllBranches() " << endl; |
290 |
< |
headerf << "\t// load all branches" << endl << "{" << endl; |
291 |
< |
for(Int_t i = 0; i< aliasarray->GetSize(); i++) { |
292 |
< |
TString aliasname(aliasarray->At(i)->GetName()); |
293 |
< |
headerf << "\t" << "if (" << aliasname.Data() << "_branch != 0) " << Form("%s();",aliasname.Data()) << endl; |
294 |
< |
} |
295 |
< |
headerf << "}" << endl << endl; |
296 |
< |
|
297 |
< |
// accessor functions |
298 |
< |
for (Int_t i = 0; i< aliasarray->GetSize(); i++) { |
299 |
< |
TString aliasname(aliasarray->At(i)->GetName()); |
300 |
< |
TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
301 |
< |
TString classname = branch->GetClassName(); |
302 |
< |
TString title = branch->GetTitle(); |
303 |
< |
bool isSkimmedNtuple = false; |
304 |
< |
if(!classname.Contains("edm::Wrapper<") && |
305 |
< |
(classname.Contains("vector") || classname.Contains("LorentzVector") ) ) |
306 |
< |
isSkimmedNtuple = true; |
307 |
< |
if ( classname.Contains("vector") ) { |
308 |
< |
if(classname.Contains("edm::Wrapper<") ) { |
309 |
< |
classname = classname(0,classname.Length()-2); |
310 |
< |
classname.ReplaceAll("edm::Wrapper<",""); |
311 |
< |
} |
312 |
< |
headerf << "\t" << classname << " &" << aliasname << "()" << endl; |
313 |
< |
} else { |
314 |
< |
if(classname.Contains("edm::Wrapper<") ) { |
315 |
< |
classname = classname(0,classname.Length()-1); |
316 |
< |
classname.ReplaceAll("edm::Wrapper<",""); |
317 |
< |
} |
318 |
< |
if(classname != "" ) { |
319 |
< |
headerf << "\t" << classname << " &" << aliasname << "()" << endl; |
320 |
< |
} else { |
321 |
< |
if(title.EndsWith("/i")) |
322 |
< |
headerf << "\tunsigned int &" << aliasname << "()" << endl; |
323 |
< |
if(title.EndsWith("/F")) |
324 |
< |
headerf << "\tfloat &" << aliasname << "()" << endl; |
325 |
< |
if(title.EndsWith("/I")) |
326 |
< |
headerf << "\tint &" << aliasname << "()" << endl; |
327 |
< |
} |
328 |
< |
} |
329 |
< |
aliasname = aliasarray->At(i)->GetName(); |
330 |
< |
headerf << "\t{" << endl; |
331 |
< |
headerf << "\t\t" << "if (not " << Form("%s_isLoaded) {",aliasname.Data()) << endl; |
332 |
< |
headerf << "\t\t\t" << "if (" << Form("%s_branch",aliasname.Data()) << " != 0) {" << endl; |
333 |
< |
headerf << "\t\t\t\t" << Form("%s_branch",aliasname.Data()) << "->GetEntry(index);" << endl; |
334 |
< |
if (paranoid) { |
335 |
< |
headerf << "\t\t\t\t#ifdef PARANOIA" << endl; |
336 |
< |
if (classname == "vector<vector<float> >") { |
337 |
< |
if(isSkimmedNtuple) { |
338 |
< |
headerf << "\t\t\t\t" << "for (vector<vector<float> >::const_iterator i = " |
339 |
< |
<< aliasname << "_->begin(); i != "<< aliasname << "_->end(); ++i) {" << endl; |
340 |
< |
} else { |
341 |
< |
headerf << "\t\t\t\t" << "for (vector<vector<float> >::const_iterator i = " |
342 |
< |
<< aliasname << "_.begin(); i != "<< aliasname << "_.end(); ++i) {" << endl; |
343 |
< |
} |
344 |
< |
headerf << "\t\t\t\t\t" << "for (vector<float>::const_iterator j = i->begin(); " |
345 |
< |
"j != i->end(); ++j) {" << endl; |
346 |
< |
headerf << "\t\t\t\t\t\t" << "if (not isfinite(*j)) {" << endl; |
347 |
< |
headerf << "\t\t\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) |
348 |
< |
<< " contains a bad float: %f\\n\", *j);" << endl << "\t\t\t\t\t\t\t" << "exit(1);" |
349 |
< |
<< endl; |
350 |
< |
headerf << "\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}" << endl; |
351 |
< |
} else if (classname == "vector<float>") { |
352 |
< |
if(isSkimmedNtuple) { |
353 |
< |
headerf << "\t\t\t\t" << "for (vector<float>::const_iterator i = " |
354 |
< |
<< aliasname << "_->begin(); i != "<< aliasname << "_->end(); ++i) {" << endl; |
355 |
< |
} else { |
356 |
< |
headerf << "\t\t\t\t" << "for (vector<float>::const_iterator i = " |
357 |
< |
<< aliasname << "_.begin(); i != "<< aliasname << "_.end(); ++i) {" << endl; |
358 |
< |
} |
359 |
< |
headerf << "\t\t\t\t\t" << "if (not isfinite(*i)) {" << endl; |
360 |
< |
headerf << "\t\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) |
361 |
< |
<< " contains a bad float: %f\\n\", *i);" << endl << "\t\t\t\t\t\t" << "exit(1);" |
362 |
< |
<< endl; |
363 |
< |
headerf << "\t\t\t\t\t}\n\t\t\t\t}" << endl; |
364 |
< |
} else if (classname == "float") { |
365 |
< |
headerf << "\t\t\t\t" << "if (not isfinite(" << aliasname << "_)) {" << endl; |
366 |
< |
headerf << "\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) |
367 |
< |
<< " contains a bad float: %f\\n\", " << aliasname << "_);" << endl |
368 |
< |
<< "\t\t\t\t\t" << "exit(1);" |
369 |
< |
<< endl; |
370 |
< |
headerf << "\t\t\t\t}" << endl; |
371 |
< |
} else if (classname.BeginsWith("vector<vector<ROOT::Math::LorentzVector")) { |
372 |
< |
if(isSkimmedNtuple) { |
373 |
< |
headerf << "\t\t\t\t" << "for (" << classname.Data() <<"::const_iterator i = " |
374 |
< |
<< aliasname << "_->begin(); i != "<< aliasname << "_->end(); ++i) {" << endl; |
375 |
< |
} else { |
376 |
< |
headerf << "\t\t\t\t" << "for (" << classname.Data() <<"::const_iterator i = " |
377 |
< |
<< aliasname << "_.begin(); i != "<< aliasname << "_.end(); ++i) {" << endl; |
378 |
< |
} |
379 |
< |
// this is a slightly hacky way to get rid of the outer vector< > ... |
380 |
< |
std::string str = classname.Data() + 7; |
381 |
< |
str[str.length() - 2] = 0; |
382 |
< |
headerf << "\t\t\t\t\t" << "for (" << str.c_str() << "::const_iterator j = i->begin(); " |
383 |
< |
"j != i->end(); ++j) {" << endl; |
384 |
< |
headerf << "\t\t\t\t\t\t" << "int e;" << endl; |
385 |
< |
headerf << "\t\t\t\t\t\t" << "frexp(j->pt(), &e);" << endl; |
386 |
< |
headerf << "\t\t\t\t\t\t" << "if (not isfinite(j->pt()) || e > 30) {" << endl; |
387 |
< |
headerf << "\t\t\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) |
388 |
< |
<< " contains a bad float: %f\\n\", j->pt());" << endl << "\t\t\t\t\t\t\t" << "exit(1);" |
389 |
< |
<< endl; |
390 |
< |
headerf << "\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}" << endl; |
391 |
< |
} else if (classname.BeginsWith("vector<ROOT::Math::LorentzVector")) { |
392 |
< |
if(isSkimmedNtuple) { |
393 |
< |
headerf << "\t\t\t\t" << "for (" << classname.Data() << "::const_iterator i = " |
394 |
< |
<< aliasname << "_->begin(); i != "<< aliasname << "_->end(); ++i) {" << endl; |
395 |
< |
} else { |
396 |
< |
headerf << "\t\t\t\t" << "for (" << classname.Data() << "::const_iterator i = " |
397 |
< |
<< aliasname << "_.begin(); i != "<< aliasname << "_.end(); ++i) {" << endl; |
398 |
< |
} |
399 |
< |
headerf << "\t\t\t\t\t" << "int e;" << endl; |
400 |
< |
headerf << "\t\t\t\t\t" << "frexp(i->pt(), &e);" << endl; |
401 |
< |
headerf << "\t\t\t\t\t" << "if (not isfinite(i->pt()) || e > 30) {" << endl; |
402 |
< |
headerf << "\t\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) |
403 |
< |
<< " contains a bad float: %f\\n\", i->pt());" << endl << "\t\t\t\t\t\t" << "exit(1);" |
404 |
< |
<< endl; |
405 |
< |
headerf << "\t\t\t\t\t}\n\t\t\t\t}" << endl; |
406 |
< |
} else if (classname.BeginsWith("ROOT::Math::LorentzVector")) { |
407 |
< |
headerf << "\t\t\t\t" << "int e;" << endl; |
408 |
< |
if(isSkimmedNtuple) { |
409 |
< |
headerf << "\t\t\t\t" << "frexp(" << aliasname << "_->pt(), &e);" << endl; |
410 |
< |
headerf << "\t\t\t\t" << "if (not isfinite(" << aliasname << "_->pt()) || e > 30) {" << endl; |
411 |
< |
headerf << "\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) |
412 |
< |
<< " contains a bad float: %f\\n\", " << aliasname << "_->pt());" << endl |
413 |
< |
<< "\t\t\t\t\t" << "exit(1);" |
414 |
< |
<< endl; |
415 |
< |
} else { |
416 |
< |
headerf << "\t\t\t\t" << "frexp(" << aliasname << "_.pt(), &e);" << endl; |
417 |
< |
headerf << "\t\t\t\t" << "if (not isfinite(" << aliasname << "_.pt()) || e > 30) {" << endl; |
418 |
< |
headerf << "\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) |
419 |
< |
<< " contains a bad float: %f\\n\", " << aliasname << "_.pt());" << endl |
420 |
< |
<< "\t\t\t\t\t" << "exit(1);" |
421 |
< |
<< endl; |
422 |
< |
} |
423 |
< |
headerf << "\t\t\t\t}" << endl; |
424 |
< |
} |
425 |
< |
headerf << "\t\t\t\t#endif // #ifdef PARANOIA" << endl; |
426 |
< |
} |
427 |
< |
headerf << "\t\t\t" << "} else { " << endl; |
428 |
< |
headerf << "\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) |
429 |
< |
<< " does not exist!\\n\");" << endl; |
430 |
< |
headerf << "\t\t\t\t" << "exit(1);" << endl << "\t\t\t}" << endl; |
431 |
< |
headerf << "\t\t\t" << Form("%s_isLoaded",aliasname.Data()) << " = true;" << endl; |
432 |
< |
headerf << "\t\t" << "}" << endl; |
433 |
< |
if(isSkimmedNtuple) { |
434 |
< |
headerf << "\t\t" << "return *" << aliasname << "_;" << endl << "\t}" << endl; |
435 |
< |
} |
436 |
< |
else { |
437 |
< |
headerf << "\t\t" << "return " << aliasname << "_;" << endl << "\t}" << endl; |
438 |
< |
} |
439 |
< |
} |
440 |
< |
|
441 |
< |
bool haveHLTInfo = false; |
442 |
< |
bool haveL1Info = false; |
443 |
< |
bool haveHLT8E29Info = false; |
444 |
< |
for(int i = 0; i < aliasarray->GetSize(); i++) { |
445 |
< |
TString aliasname(aliasarray->At(i)->GetName()); |
446 |
< |
if(aliasname=="hlt_trigNames") |
447 |
< |
haveHLTInfo = true; |
448 |
< |
if(aliasname=="l1_trigNames") |
449 |
< |
haveL1Info = true; |
450 |
< |
if(aliasname=="hlt8e29_trigNames") |
451 |
< |
haveHLT8E29Info = true; |
452 |
< |
} |
453 |
< |
|
454 |
< |
if(haveHLTInfo) { |
455 |
< |
//functions to return whether or not trigger fired - HLT |
456 |
< |
headerf << "\t" << "bool passHLTTrigger(TString trigName) {" << endl; |
457 |
< |
headerf << "\t\t" << "int trigIndx;" << endl; |
458 |
< |
headerf << "\t\t" << "vector<TString>::const_iterator begin_it = hlt_trigNames().begin();" << endl; |
459 |
< |
headerf << "\t\t" << "vector<TString>::const_iterator end_it = hlt_trigNames().end();" << endl; |
460 |
< |
headerf << "\t\t" << "vector<TString>::const_iterator found_it = find(begin_it, end_it, trigName);" << endl; |
461 |
< |
headerf << "\t\t" << "if(found_it != end_it)" << endl; |
462 |
< |
headerf << "\t\t\t" << "trigIndx = found_it - begin_it;" << endl; |
463 |
< |
headerf << "\t\t" << "else {" << endl; |
464 |
< |
headerf << "\t\t\t" << "cout << \"Cannot find Trigger \" << trigName << endl; " << endl; |
465 |
< |
headerf << "\t\t\t" << "return 0;" << endl; |
466 |
< |
headerf << "\t\t" << "}" << endl << endl; |
467 |
< |
//get the list of branches that hold the HLT bitmasks |
468 |
< |
//store in a set 'cause its automatically sorted |
469 |
< |
//set<TString> s_HLTbitmasks; |
470 |
< |
set<TString, hltcompare> s_HLTbitmasks; |
471 |
< |
set<TString> s_L1bitmasks; |
472 |
< |
for(int j = 0; j < aliasarray->GetSize(); j++) { |
473 |
< |
TString aliasname(aliasarray->At(j)->GetName()); |
474 |
< |
TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
475 |
< |
TString classname = branch->GetClassName(); |
476 |
< |
if(aliasname.Contains("hlt_bits") && classname.Contains("int")) { |
477 |
< |
s_HLTbitmasks.insert(aliasname); |
478 |
< |
} |
479 |
< |
} |
480 |
< |
int i = 0; |
481 |
< |
for( set<TString>::const_iterator s_it = s_HLTbitmasks.begin(); s_it != s_HLTbitmasks.end(); s_it++, i++ ) { |
482 |
< |
if(i==0) { |
483 |
< |
headerf << "\t\t" << "if(trigIndx <= 31) {" << endl; |
484 |
< |
headerf << "\t\t\t" << "unsigned int bitmask = 1;" << endl; |
485 |
< |
headerf << "\t\t\t" << "bitmask <<= trigIndx;" << endl; |
486 |
< |
headerf << "\t\t\t" << "return " << *s_it << "() & bitmask;" << endl; |
448 |
< |
headerf << "\t\t" << "}" << endl; |
449 |
< |
continue; |
450 |
< |
} |
451 |
< |
headerf << "\t\t" << "if(trigIndx >= " << Form("%d && trigIndx <= %d", 32*i, 32*i+31) << ") {" << endl; |
452 |
< |
headerf << "\t\t\t" << "unsigned int bitmask = 1;" << endl; |
453 |
< |
headerf << "\t\t\t" << "bitmask <<= (trigIndx - " << Form("%d",32*i) << "); " << endl; |
454 |
< |
headerf << "\t\t\t" << "return " << *s_it << "() & bitmask;" << endl; |
455 |
< |
headerf << "\t\t" << "}" << endl; |
456 |
< |
} |
457 |
< |
headerf << "\t" << "return 0;" << endl; |
458 |
< |
headerf << "\t" << "}" << endl; |
459 |
< |
}//if(haveHLTInfo) |
460 |
< |
|
461 |
< |
if(haveHLT8E29Info) { |
462 |
< |
//functions to return whether or not trigger fired - HLT |
463 |
< |
headerf << "\t" << "bool passHLT8E29Trigger(TString trigName) {" << endl; |
464 |
< |
headerf << "\t\t" << "int trigIndx;" << endl; |
465 |
< |
headerf << "\t\t" << "vector<TString>::const_iterator begin_it = hlt8e29_trigNames().begin();" << endl; |
466 |
< |
headerf << "\t\t" << "vector<TString>::const_iterator end_it = hlt8e29_trigNames().end();" << endl; |
467 |
< |
headerf << "\t\t" << "vector<TString>::const_iterator found_it = find(begin_it, end_it, trigName);" << endl; |
468 |
< |
headerf << "\t\t" << "if(found_it != end_it)" << endl; |
469 |
< |
headerf << "\t\t\t" << "trigIndx = found_it - begin_it;" << endl; |
470 |
< |
headerf << "\t\t" << "else {" << endl; |
471 |
< |
headerf << "\t\t\t" << "cout << \"Cannot find Trigger \" << trigName << endl; " << endl; |
472 |
< |
headerf << "\t\t\t" << "return 0;" << endl; |
473 |
< |
headerf << "\t\t" << "}" << endl << endl; |
474 |
< |
//get the list of branches that hold the HLT bitmasks |
475 |
< |
//store in a set 'cause its automatically sorted |
476 |
< |
set<TString> s_HLTbitmasks; |
477 |
< |
set<TString> s_L1bitmasks; |
478 |
< |
for(int j = 0; j < aliasarray->GetSize(); j++) { |
479 |
< |
TString aliasname(aliasarray->At(j)->GetName()); |
480 |
< |
TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
481 |
< |
TString classname = branch->GetClassName(); |
482 |
< |
if(aliasname.Contains("hlt8e29_bits") && classname.Contains("int")) { |
483 |
< |
s_HLTbitmasks.insert(aliasname); |
484 |
< |
} |
485 |
< |
|
245 |
> |
// SetBranchAddresses for LorentzVectors |
246 |
> |
// TBits also needs SetMakeClass(0)... |
247 |
> |
for(Int_t i = 0; i< aliasarray->GetSize(); i++) { |
248 |
> |
TString aliasname(aliasarray->At(i)->GetName()); |
249 |
> |
// TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
250 |
> |
TBranch *branch = 0; |
251 |
> |
if (have_aliases) |
252 |
> |
branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
253 |
> |
else |
254 |
> |
branch = (TBranch*)aliasarray->At(i); |
255 |
> |
|
256 |
> |
TString classname = branch->GetClassName(); |
257 |
> |
if ( !classname.Contains("vector<vector") ) { |
258 |
> |
if ( classname.Contains("Lorentz") || classname.Contains("PositionVector") || classname.Contains("TBits")) { |
259 |
> |
headerf << "\t" << Form("%s_branch",aliasname.Data()) << " = 0;" << endl; |
260 |
> |
if (have_aliases) { |
261 |
> |
headerf << "\t" << "if (tree->GetAlias(\"" << aliasname << "\") != 0) {" << endl; |
262 |
> |
headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << " = tree->GetBranch(tree->GetAlias(\"" << aliasname << "\"));" << endl; |
263 |
> |
headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << "->SetAddress(&" << aliasname << "_);" << endl << "\t}" << endl; |
264 |
> |
} |
265 |
> |
else { |
266 |
> |
headerf << "\t" << "if (tree->GetBranch(\"" << aliasname << "\") != 0) {" << endl; |
267 |
> |
headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << " = tree->GetBranch(\"" << aliasname << "\");" << endl; |
268 |
> |
headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << "->SetAddress(&" << aliasname << "_);" << endl << "\t}" << endl; |
269 |
> |
} |
270 |
> |
} |
271 |
> |
} |
272 |
> |
} |
273 |
> |
|
274 |
> |
|
275 |
> |
// SetBranchAddresses for everything else |
276 |
> |
headerf << " tree->SetMakeClass(1);" << endl; |
277 |
> |
for(Int_t i = 0; i< aliasarray->GetSize(); i++) { |
278 |
> |
TString aliasname(aliasarray->At(i)->GetName()); |
279 |
> |
// TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
280 |
> |
TBranch *branch = 0; |
281 |
> |
if (have_aliases) |
282 |
> |
branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
283 |
> |
else |
284 |
> |
branch = (TBranch*)aliasarray->At(i); |
285 |
> |
|
286 |
> |
TString classname = branch->GetClassName(); |
287 |
> |
if ( ! (classname.Contains("Lorentz") || classname.Contains("PositionVector") || classname.Contains("TBits")) || classname.Contains("vector<vector") ) { |
288 |
> |
headerf << "\t" << Form("%s_branch",aliasname.Data()) << " = 0;" << endl; |
289 |
> |
if (have_aliases) { |
290 |
> |
headerf << "\t" << "if (tree->GetAlias(\"" << aliasname << "\") != 0) {" << endl; |
291 |
> |
headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << " = tree->GetBranch(tree->GetAlias(\"" << aliasname << "\"));" << endl; |
292 |
> |
headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << "->SetAddress(&" << aliasname << "_);" << endl << "\t}" << endl; |
293 |
> |
} |
294 |
> |
else { |
295 |
> |
headerf << "\t" << "if (tree->GetBranch(\"" << aliasname << "\") != 0) {" << endl; |
296 |
> |
headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << " = tree->GetBranch(\"" << aliasname << "\");" << endl; |
297 |
> |
headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << "->SetAddress(&" << aliasname << "_);" << endl << "\t}" << endl; |
298 |
> |
} |
299 |
> |
} |
300 |
> |
} |
301 |
> |
|
302 |
> |
headerf << " tree->SetMakeClass(0);" << endl; |
303 |
> |
headerf << "}" << endl; |
304 |
> |
|
305 |
> |
// GetEntry |
306 |
> |
headerf << "void GetEntry(unsigned int idx) " << endl; |
307 |
> |
headerf << "\t// this only marks branches as not loaded, saving a lot of time" << endl << "\t{" << endl; |
308 |
> |
headerf << "\t\tindex = idx;" << endl; |
309 |
> |
for(Int_t i = 0; i< aliasarray->GetSize(); i++) { |
310 |
> |
TString aliasname(aliasarray->At(i)->GetName()); |
311 |
> |
headerf << "\t\t" << Form("%s_isLoaded",aliasname.Data()) << " = false;" << endl; |
312 |
> |
} |
313 |
> |
headerf << "\t}" << endl << endl; |
314 |
> |
|
315 |
> |
// LoadAllBranches |
316 |
> |
headerf << "void LoadAllBranches() " << endl; |
317 |
> |
headerf << "\t// load all branches" << endl << "{" << endl; |
318 |
> |
for(Int_t i = 0; i< aliasarray->GetSize(); i++) { |
319 |
> |
TString aliasname(aliasarray->At(i)->GetName()); |
320 |
> |
headerf << "\t" << "if (" << aliasname.Data() << "_branch != 0) " << Form("%s();",aliasname.Data()) << endl; |
321 |
> |
} |
322 |
> |
headerf << "}" << endl << endl; |
323 |
> |
|
324 |
> |
// accessor functions |
325 |
> |
for (Int_t i = 0; i< aliasarray->GetSize(); i++) { |
326 |
> |
TString aliasname(aliasarray->At(i)->GetName()); |
327 |
> |
// TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
328 |
> |
TBranch *branch = 0; |
329 |
> |
if (have_aliases) |
330 |
> |
branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
331 |
> |
else |
332 |
> |
branch = (TBranch*)aliasarray->At(i); |
333 |
> |
|
334 |
> |
TString classname = branch->GetClassName(); |
335 |
> |
TString title = branch->GetTitle(); |
336 |
> |
bool isSkimmedNtuple = false; |
337 |
> |
if(!classname.Contains("edm::Wrapper<") && |
338 |
> |
(classname.Contains("vector") || classname.Contains("LorentzVector") ) ) |
339 |
> |
isSkimmedNtuple = true; |
340 |
> |
if ( classname.Contains("vector") ) { |
341 |
> |
if(classname.Contains("edm::Wrapper<") ) { |
342 |
> |
classname = classname(0,classname.Length()-2); |
343 |
> |
classname.ReplaceAll("edm::Wrapper<",""); |
344 |
> |
} |
345 |
> |
headerf << "\t" << classname << " &" << aliasname << "()" << endl; |
346 |
> |
} else { |
347 |
> |
if(classname.Contains("edm::Wrapper<") ) { |
348 |
> |
classname = classname(0,classname.Length()-1); |
349 |
> |
classname.ReplaceAll("edm::Wrapper<",""); |
350 |
> |
} |
351 |
> |
if(classname != "" ) { |
352 |
> |
headerf << "\t" << classname << " &" << aliasname << "()" << endl; |
353 |
> |
} else { |
354 |
> |
if(title.EndsWith("/i")) |
355 |
> |
headerf << "\tunsigned int &" << aliasname << "()" << endl; |
356 |
> |
if(title.EndsWith("/F")) |
357 |
> |
headerf << "\tfloat &" << aliasname << "()" << endl; |
358 |
> |
if(title.EndsWith("/I")) |
359 |
> |
headerf << "\tint &" << aliasname << "()" << endl; |
360 |
> |
if(title.EndsWith("/O")) |
361 |
> |
headerf << "\tbool &" << "\t" << aliasname << "()" << endl; |
362 |
> |
} |
363 |
> |
} |
364 |
> |
aliasname = aliasarray->At(i)->GetName(); |
365 |
> |
headerf << "\t{" << endl; |
366 |
> |
headerf << "\t\t" << "if (not " << Form("%s_isLoaded) {",aliasname.Data()) << endl; |
367 |
> |
headerf << "\t\t\t" << "if (" << Form("%s_branch",aliasname.Data()) << " != 0) {" << endl; |
368 |
> |
headerf << "\t\t\t\t" << Form("%s_branch",aliasname.Data()) << "->GetEntry(index);" << endl; |
369 |
> |
if (paranoid) { |
370 |
> |
headerf << "\t\t\t\t#ifdef PARANOIA" << endl; |
371 |
> |
if (classname == "vector<vector<float> >") { |
372 |
> |
if(isSkimmedNtuple) { |
373 |
> |
headerf << "\t\t\t\t" << "for (vector<vector<float> >::const_iterator i = " |
374 |
> |
<< aliasname << "_->begin(); i != "<< aliasname << "_->end(); ++i) {" << endl; |
375 |
> |
} else { |
376 |
> |
headerf << "\t\t\t\t" << "for (vector<vector<float> >::const_iterator i = " |
377 |
> |
<< aliasname << "_.begin(); i != "<< aliasname << "_.end(); ++i) {" << endl; |
378 |
> |
} |
379 |
> |
headerf << "\t\t\t\t\t" << "for (vector<float>::const_iterator j = i->begin(); " |
380 |
> |
"j != i->end(); ++j) {" << endl; |
381 |
> |
headerf << "\t\t\t\t\t\t" << "if (not isfinite(*j)) {" << endl; |
382 |
> |
headerf << "\t\t\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) |
383 |
> |
<< " contains a bad float: %f\\n\", *j);" << endl << "\t\t\t\t\t\t\t" << "exit(1);" |
384 |
> |
<< endl; |
385 |
> |
headerf << "\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}" << endl; |
386 |
> |
} else if (classname == "vector<float>") { |
387 |
> |
if(isSkimmedNtuple) { |
388 |
> |
headerf << "\t\t\t\t" << "for (vector<float>::const_iterator i = " |
389 |
> |
<< aliasname << "_->begin(); i != "<< aliasname << "_->end(); ++i) {" << endl; |
390 |
> |
} else { |
391 |
> |
headerf << "\t\t\t\t" << "for (vector<float>::const_iterator i = " |
392 |
> |
<< aliasname << "_.begin(); i != "<< aliasname << "_.end(); ++i) {" << endl; |
393 |
> |
} |
394 |
> |
headerf << "\t\t\t\t\t" << "if (not isfinite(*i)) {" << endl; |
395 |
> |
headerf << "\t\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) |
396 |
> |
<< " contains a bad float: %f\\n\", *i);" << endl << "\t\t\t\t\t\t" << "exit(1);" |
397 |
> |
<< endl; |
398 |
> |
headerf << "\t\t\t\t\t}\n\t\t\t\t}" << endl; |
399 |
> |
} else if (classname == "float") { |
400 |
> |
headerf << "\t\t\t\t" << "if (not isfinite(" << aliasname << "_)) {" << endl; |
401 |
> |
headerf << "\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) |
402 |
> |
<< " contains a bad float: %f\\n\", " << aliasname << "_);" << endl |
403 |
> |
<< "\t\t\t\t\t" << "exit(1);" |
404 |
> |
<< endl; |
405 |
> |
headerf << "\t\t\t\t}" << endl; |
406 |
> |
} else if (classname.BeginsWith("vector<vector<ROOT::Math::LorentzVector")) { |
407 |
> |
if(isSkimmedNtuple) { |
408 |
> |
headerf << "\t\t\t\t" << "for (" << classname.Data() <<"::const_iterator i = " |
409 |
> |
<< aliasname << "_->begin(); i != "<< aliasname << "_->end(); ++i) {" << endl; |
410 |
> |
} else { |
411 |
> |
headerf << "\t\t\t\t" << "for (" << classname.Data() <<"::const_iterator i = " |
412 |
> |
<< aliasname << "_.begin(); i != "<< aliasname << "_.end(); ++i) {" << endl; |
413 |
> |
} |
414 |
> |
// this is a slightly hacky way to get rid of the outer vector< > ... |
415 |
> |
std::string str = classname.Data() + 7; |
416 |
> |
str[str.length() - 2] = 0; |
417 |
> |
headerf << "\t\t\t\t\t" << "for (" << str.c_str() << "::const_iterator j = i->begin(); " |
418 |
> |
"j != i->end(); ++j) {" << endl; |
419 |
> |
headerf << "\t\t\t\t\t\t" << "int e;" << endl; |
420 |
> |
headerf << "\t\t\t\t\t\t" << "frexp(j->pt(), &e);" << endl; |
421 |
> |
headerf << "\t\t\t\t\t\t" << "if (not isfinite(j->pt()) || e > 30) {" << endl; |
422 |
> |
headerf << "\t\t\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) |
423 |
> |
<< " contains a bad float: %f\\n\", j->pt());" << endl << "\t\t\t\t\t\t\t" << "exit(1);" |
424 |
> |
<< endl; |
425 |
> |
headerf << "\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}" << endl; |
426 |
> |
} else if (classname.BeginsWith("vector<ROOT::Math::LorentzVector")) { |
427 |
> |
if(isSkimmedNtuple) { |
428 |
> |
headerf << "\t\t\t\t" << "for (" << classname.Data() << "::const_iterator i = " |
429 |
> |
<< aliasname << "_->begin(); i != "<< aliasname << "_->end(); ++i) {" << endl; |
430 |
> |
} else { |
431 |
> |
headerf << "\t\t\t\t" << "for (" << classname.Data() << "::const_iterator i = " |
432 |
> |
<< aliasname << "_.begin(); i != "<< aliasname << "_.end(); ++i) {" << endl; |
433 |
> |
} |
434 |
> |
headerf << "\t\t\t\t\t" << "int e;" << endl; |
435 |
> |
headerf << "\t\t\t\t\t" << "frexp(i->pt(), &e);" << endl; |
436 |
> |
headerf << "\t\t\t\t\t" << "if (not isfinite(i->pt()) || e > 30) {" << endl; |
437 |
> |
headerf << "\t\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) |
438 |
> |
<< " contains a bad float: %f\\n\", i->pt());" << endl << "\t\t\t\t\t\t" << "exit(1);" |
439 |
> |
<< endl; |
440 |
> |
headerf << "\t\t\t\t\t}\n\t\t\t\t}" << endl; |
441 |
> |
} else if (classname.BeginsWith("ROOT::Math::LorentzVector")) { |
442 |
> |
headerf << "\t\t\t\t" << "int e;" << endl; |
443 |
> |
if(isSkimmedNtuple) { |
444 |
> |
headerf << "\t\t\t\t" << "frexp(" << aliasname << "_->pt(), &e);" << endl; |
445 |
> |
headerf << "\t\t\t\t" << "if (not isfinite(" << aliasname << "_->pt()) || e > 30) {" << endl; |
446 |
> |
headerf << "\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) |
447 |
> |
<< " contains a bad float: %f\\n\", " << aliasname << "_->pt());" << endl |
448 |
> |
<< "\t\t\t\t\t" << "exit(1);" |
449 |
> |
<< endl; |
450 |
> |
} else { |
451 |
> |
headerf << "\t\t\t\t" << "frexp(" << aliasname << "_.pt(), &e);" << endl; |
452 |
> |
headerf << "\t\t\t\t" << "if (not isfinite(" << aliasname << "_.pt()) || e > 30) {" << endl; |
453 |
> |
headerf << "\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) |
454 |
> |
<< " contains a bad float: %f\\n\", " << aliasname << "_.pt());" << endl |
455 |
> |
<< "\t\t\t\t\t" << "exit(1);" |
456 |
> |
<< endl; |
457 |
> |
} |
458 |
> |
headerf << "\t\t\t\t}" << endl; |
459 |
> |
} |
460 |
> |
headerf << "\t\t\t\t#endif // #ifdef PARANOIA" << endl; |
461 |
> |
} |
462 |
> |
headerf << "\t\t\t" << "} else { " << endl; |
463 |
> |
headerf << "\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) |
464 |
> |
<< " does not exist!\\n\");" << endl; |
465 |
> |
headerf << "\t\t\t\t" << "exit(1);" << endl << "\t\t\t}" << endl; |
466 |
> |
headerf << "\t\t\t" << Form("%s_isLoaded",aliasname.Data()) << " = true;" << endl; |
467 |
> |
headerf << "\t\t" << "}" << endl; |
468 |
> |
if(isSkimmedNtuple) { |
469 |
> |
headerf << "\t\t" << "return *" << aliasname << "_;" << endl << "\t}" << endl; |
470 |
> |
} |
471 |
> |
else { |
472 |
> |
headerf << "\t\t" << "return " << aliasname << "_;" << endl << "\t}" << endl; |
473 |
> |
} |
474 |
> |
} |
475 |
> |
|
476 |
> |
bool haveHLTInfo = false; |
477 |
> |
bool haveL1Info = false; |
478 |
> |
bool haveHLT8E29Info = false; |
479 |
> |
for(int i = 0; i < aliasarray->GetSize(); i++) { |
480 |
> |
TString aliasname(aliasarray->At(i)->GetName()); |
481 |
> |
if(aliasname=="hlt_trigNames") |
482 |
> |
haveHLTInfo = true; |
483 |
> |
if(aliasname=="l1_trigNames") |
484 |
> |
haveL1Info = true; |
485 |
> |
if(aliasname=="hlt8e29_trigNames") |
486 |
> |
haveHLT8E29Info = true; |
487 |
|
} |
488 |
< |
int i = 0; |
489 |
< |
for(set<TString>::const_iterator s_it = s_HLTbitmasks.begin(); |
490 |
< |
s_it != s_HLTbitmasks.end(); s_it++, i++) { |
491 |
< |
|
492 |
< |
if(i==0) { |
493 |
< |
headerf << "\t\t" << "if(trigIndx <= 31) {" << endl; |
494 |
< |
headerf << "\t\t\t" << "unsigned int bitmask = 1;" << endl; |
495 |
< |
headerf << "\t\t\t" << "bitmask <<= trigIndx;" << endl; |
496 |
< |
headerf << "\t\t\t" << "return " << *s_it << "() & bitmask;" << endl; |
497 |
< |
headerf << "\t\t" << "}" << endl; |
498 |
< |
continue; |
499 |
< |
} |
500 |
< |
headerf << "\t\t" << "if(trigIndx >= " << Form("%d && trigIndx <= %d", 32*i, 32*i+31) << ") {" << endl; |
501 |
< |
headerf << "\t\t\t" << "unsigned int bitmask = 1;" << endl; |
502 |
< |
headerf << "\t\t\t" << "bitmask <<= (trigIndx - " << Form("%d",32*i) << "); " << endl; |
503 |
< |
headerf << "\t\t\t" << "return " << *s_it << "() & bitmask;" << endl; |
504 |
< |
headerf << "\t\t" << "}" << endl; |
505 |
< |
} |
506 |
< |
headerf << "\t" << "return 0;" << endl; |
507 |
< |
headerf << "\t" << "}" << endl; |
508 |
< |
}//if(haveHLT8E29Info) |
509 |
< |
|
510 |
< |
|
511 |
< |
if(haveL1Info) { |
512 |
< |
//functions to return whether or not trigger fired - L1 |
513 |
< |
headerf << "\t" << "bool passL1Trigger(TString trigName) {" << endl; |
514 |
< |
headerf << "\t\t" << "int trigIndx;" << endl; |
515 |
< |
headerf << "\t\t" << "vector<TString>::const_iterator begin_it = l1_trigNames().begin();" << endl; |
516 |
< |
headerf << "\t\t" << "vector<TString>::const_iterator end_it = l1_trigNames().end();" << endl; |
517 |
< |
headerf << "\t\t" << "vector<TString>::const_iterator found_it = find(begin_it, end_it, trigName);" << endl; |
518 |
< |
headerf << "\t\t" << "if(found_it != end_it)" << endl; |
519 |
< |
headerf << "\t\t\t" << "trigIndx = found_it - begin_it;" << endl; |
520 |
< |
headerf << "\t\t" << "else {" << endl; |
521 |
< |
headerf << "\t\t\t" << "cout << \"Cannot find Trigger \" << trigName << endl; " << endl; |
522 |
< |
headerf << "\t\t\t" << "return 0;" << endl; |
523 |
< |
headerf << "\t\t" << "}" << endl << endl; |
524 |
< |
//get the list of branches that hold the L1 bitmasks |
525 |
< |
//store in a set 'cause its automatically sorted |
526 |
< |
set<TString> s_L1bitmasks; |
527 |
< |
for(int j = 0; j < aliasarray->GetSize(); j++) { |
528 |
< |
TString aliasname(aliasarray->At(j)->GetName()); |
529 |
< |
TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
530 |
< |
TString classname = branch->GetClassName(); |
531 |
< |
if(aliasname.Contains("l1_bits") && classname.Contains("int")) { |
532 |
< |
s_L1bitmasks.insert(aliasname); |
533 |
< |
} |
488 |
> |
|
489 |
> |
if(haveHLTInfo) { |
490 |
> |
//functions to return whether or not trigger fired - HLT |
491 |
> |
headerf << "\t" << "bool passHLTTrigger(TString trigName) {" << endl; |
492 |
> |
headerf << "\t\t" << "int trigIndx;" << endl; |
493 |
> |
headerf << "\t\t" << "vector<TString>::const_iterator begin_it = hlt_trigNames().begin();" << endl; |
494 |
> |
headerf << "\t\t" << "vector<TString>::const_iterator end_it = hlt_trigNames().end();" << endl; |
495 |
> |
headerf << "\t\t" << "vector<TString>::const_iterator found_it = find(begin_it, end_it, trigName);" << endl; |
496 |
> |
headerf << "\t\t" << "if(found_it != end_it)" << endl; |
497 |
> |
headerf << "\t\t\t" << "trigIndx = found_it - begin_it;" << endl; |
498 |
> |
headerf << "\t\t" << "else {" << endl; |
499 |
> |
headerf << "\t\t\t" << "cout << \"Cannot find Trigger \" << trigName << endl; " << endl; |
500 |
> |
headerf << "\t\t\t" << "return 0;" << endl; |
501 |
> |
headerf << "\t\t" << "}" << endl << endl; |
502 |
> |
headerf << "\t" << "return hlt_bits().TestBitNumber(trigIndx);" << endl; |
503 |
> |
headerf << "\t" << "}" << endl; |
504 |
> |
}//if(haveHLTInfo) |
505 |
> |
|
506 |
> |
if(haveHLT8E29Info) { |
507 |
> |
//functions to return whether or not trigger fired - HLT |
508 |
> |
headerf << "\t" << "bool passHLT8E29Trigger(TString trigName) {" << endl; |
509 |
> |
headerf << "\t\t" << "int trigIndx;" << endl; |
510 |
> |
headerf << "\t\t" << "vector<TString>::const_iterator begin_it = hlt8e29_trigNames().begin();" << endl; |
511 |
> |
headerf << "\t\t" << "vector<TString>::const_iterator end_it = hlt8e29_trigNames().end();" << endl; |
512 |
> |
headerf << "\t\t" << "vector<TString>::const_iterator found_it = find(begin_it, end_it, trigName);" << endl; |
513 |
> |
headerf << "\t\t" << "if(found_it != end_it)" << endl; |
514 |
> |
headerf << "\t\t\t" << "trigIndx = found_it - begin_it;" << endl; |
515 |
> |
headerf << "\t\t" << "else {" << endl; |
516 |
> |
headerf << "\t\t\t" << "cout << \"Cannot find Trigger \" << trigName << endl; " << endl; |
517 |
> |
headerf << "\t\t\t" << "return 0;" << endl; |
518 |
> |
headerf << "\t\t" << "}" << endl << endl; |
519 |
> |
headerf << "\t" << "return hlt8e29_bits().TestBitNumber(trigIndx);" << endl; |
520 |
> |
headerf << "\t" << "}" << endl; |
521 |
> |
}//if(haveHLT8E29Info) |
522 |
> |
|
523 |
> |
|
524 |
> |
if(haveL1Info) { |
525 |
> |
//functions to return whether or not trigger fired - L1 |
526 |
> |
headerf << "\t" << "bool passL1Trigger(TString trigName) {" << endl; |
527 |
> |
headerf << "\t\t" << "int trigIndx;" << endl; |
528 |
> |
headerf << "\t\t" << "vector<TString>::const_iterator begin_it = l1_trigNames().begin();" << endl; |
529 |
> |
headerf << "\t\t" << "vector<TString>::const_iterator end_it = l1_trigNames().end();" << endl; |
530 |
> |
headerf << "\t\t" << "vector<TString>::const_iterator found_it = find(begin_it, end_it, trigName);" << endl; |
531 |
> |
headerf << "\t\t" << "if(found_it != end_it)" << endl; |
532 |
> |
headerf << "\t\t\t" << "trigIndx = found_it - begin_it;" << endl; |
533 |
> |
headerf << "\t\t" << "else {" << endl; |
534 |
> |
headerf << "\t\t\t" << "cout << \"Cannot find Trigger \" << trigName << endl; " << endl; |
535 |
> |
headerf << "\t\t\t" << "return 0;" << endl; |
536 |
> |
headerf << "\t\t" << "}" << endl << endl; |
537 |
> |
//get the list of branches that hold the L1 bitmasks |
538 |
> |
//store in a set 'cause its automatically sorted |
539 |
> |
set<TString> s_L1bitmasks; |
540 |
> |
for(int j = 0; j < aliasarray->GetSize(); j++) { |
541 |
> |
TString aliasname(aliasarray->At(j)->GetName()); |
542 |
> |
// TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
543 |
> |
TBranch *branch = 0; |
544 |
> |
if (have_aliases) |
545 |
> |
branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
546 |
> |
else |
547 |
> |
branch = (TBranch*)aliasarray->At(j); |
548 |
> |
|
549 |
> |
TString classname = branch->GetClassName(); |
550 |
> |
if(aliasname.Contains("l1_bits") && classname.Contains("int")) { |
551 |
> |
s_L1bitmasks.insert(aliasname); |
552 |
> |
} |
553 |
|
|
554 |
< |
} |
555 |
< |
int i = 0; |
556 |
< |
for(set<TString>::const_iterator s_it = s_L1bitmasks.begin(); |
557 |
< |
s_it != s_L1bitmasks.end(); s_it++, i++) { |
554 |
> |
} |
555 |
> |
int i = 0; |
556 |
> |
for(set<TString>::const_iterator s_it = s_L1bitmasks.begin(); |
557 |
> |
s_it != s_L1bitmasks.end(); s_it++, i++) { |
558 |
|
|
559 |
< |
if(i==0) { |
560 |
< |
headerf << "\t\t" << "if(trigIndx <= 31) {" << endl; |
561 |
< |
headerf << "\t\t\t" << "unsigned int bitmask = 1;" << endl; |
562 |
< |
headerf << "\t\t\t" << "bitmask <<= trigIndx;" << endl; |
563 |
< |
headerf << "\t\t\t" << "return " << *s_it << "() & bitmask;" << endl; |
564 |
< |
headerf << "\t\t" << "}" << endl; |
565 |
< |
continue; |
566 |
< |
} |
567 |
< |
headerf << "\t\t" << "if(trigIndx >= " << Form("%d && trigIndx <= %d", 32*i, 32*i+31) << ") {" << endl; |
568 |
< |
headerf << "\t\t\t" << "unsigned int bitmask = 1;" << endl; |
569 |
< |
headerf << "\t\t\t" << "bitmask <<= (trigIndx - " << Form("%d",32*i) << "); " << endl; |
570 |
< |
headerf << "\t\t\t" << "return " << *s_it << "() & bitmask;" << endl; |
571 |
< |
headerf << "\t\t" << "}" << endl; |
572 |
< |
} |
573 |
< |
headerf << "\t" << "return 0;" << endl; |
574 |
< |
headerf << "\t" << "}" << endl; |
575 |
< |
}//if(haveL1Info) |
559 |
> |
if(i==0) { |
560 |
> |
headerf << "\t\t" << "if(trigIndx <= 31) {" << endl; |
561 |
> |
headerf << "\t\t\t" << "unsigned int bitmask = 1;" << endl; |
562 |
> |
headerf << "\t\t\t" << "bitmask <<= trigIndx;" << endl; |
563 |
> |
headerf << "\t\t\t" << "return " << *s_it << "() & bitmask;" << endl; |
564 |
> |
headerf << "\t\t" << "}" << endl; |
565 |
> |
continue; |
566 |
> |
} |
567 |
> |
headerf << "\t\t" << "if(trigIndx >= " << Form("%d && trigIndx <= %d", 32*i, 32*i+31) << ") {" << endl; |
568 |
> |
headerf << "\t\t\t" << "unsigned int bitmask = 1;" << endl; |
569 |
> |
headerf << "\t\t\t" << "bitmask <<= (trigIndx - " << Form("%d",32*i) << "); " << endl; |
570 |
> |
headerf << "\t\t\t" << "return " << *s_it << "() & bitmask;" << endl; |
571 |
> |
headerf << "\t\t" << "}" << endl; |
572 |
> |
} |
573 |
> |
headerf << "\t" << "return 0;" << endl; |
574 |
> |
headerf << "\t" << "}" << endl; |
575 |
> |
}//if(haveL1Info) |
576 |
|
|
577 |
< |
headerf << endl; |
578 |
< |
headerf << " static void progress( int nEventsTotal, int nEventsChain ){" << endl; |
579 |
< |
headerf << " int period = 1000;" << endl; |
580 |
< |
headerf << " if(nEventsTotal%1000 == 0) {" << endl; |
581 |
< |
headerf << " // xterm magic from L. Vacavant and A. Cerri" << endl; |
582 |
< |
headerf << " if (isatty(1)) {" << endl; |
583 |
< |
headerf << " if( ( nEventsChain - nEventsTotal ) > period ){" << endl; |
584 |
< |
headerf << " float frac = (float)nEventsTotal/(nEventsChain*0.01);" << endl; |
585 |
< |
headerf << " printf(\"\\015\\033[32m ---> \\033[1m\\033[31m%4.1f%%\"" << endl; |
586 |
< |
headerf << " \"\\033[0m\\033[32m <---\\033[0m\\015\", frac);" << endl; |
587 |
< |
headerf << " fflush(stdout);" << endl; |
588 |
< |
headerf << " }" << endl; |
589 |
< |
headerf << " else {" << endl; |
590 |
< |
headerf << " printf(\"\\015\\033[32m ---> \\033[1m\\033[31m%4.1f%%\"" << endl; |
591 |
< |
headerf << " \"\\033[0m\\033[32m <---\\033[0m\\015\", 100.);" << endl; |
592 |
< |
headerf << " cout << endl;" << endl; |
593 |
< |
headerf << " }" << endl; |
594 |
< |
headerf << " }" << endl; |
595 |
< |
headerf << " }" << endl; |
596 |
< |
headerf << " }" << endl; |
597 |
< |
headerf << " " << endl; |
577 |
> |
headerf << endl; |
578 |
> |
headerf << " static void progress( int nEventsTotal, int nEventsChain ){" << endl; |
579 |
> |
headerf << " int period = 1000;" << endl; |
580 |
> |
headerf << " if(nEventsTotal%1000 == 0) {" << endl; |
581 |
> |
headerf << " // xterm magic from L. Vacavant and A. Cerri" << endl; |
582 |
> |
headerf << " if (isatty(1)) {" << endl; |
583 |
> |
headerf << " if( ( nEventsChain - nEventsTotal ) > period ){" << endl; |
584 |
> |
headerf << " float frac = (float)nEventsTotal/(nEventsChain*0.01);" << endl; |
585 |
> |
headerf << " printf(\"\\015\\033[32m ---> \\033[1m\\033[31m%4.1f%%\"" << endl; |
586 |
> |
headerf << " \"\\033[0m\\033[32m <---\\033[0m\\015\", frac);" << endl; |
587 |
> |
headerf << " fflush(stdout);" << endl; |
588 |
> |
headerf << " }" << endl; |
589 |
> |
headerf << " else {" << endl; |
590 |
> |
headerf << " printf(\"\\015\\033[32m ---> \\033[1m\\033[31m%4.1f%%\"" << endl; |
591 |
> |
headerf << " \"\\033[0m\\033[32m <---\\033[0m\\015\", 100.);" << endl; |
592 |
> |
headerf << " cout << endl;" << endl; |
593 |
> |
headerf << " }" << endl; |
594 |
> |
headerf << " }" << endl; |
595 |
> |
headerf << " }" << endl; |
596 |
> |
headerf << " }" << endl; |
597 |
> |
headerf << " " << endl; |
598 |
|
|
599 |
< |
headerf << "};" << endl << endl; |
599 |
> |
headerf << "};" << endl << endl; |
600 |
|
|
601 |
< |
headerf << "#ifndef __CINT__" << endl; |
602 |
< |
headerf << "extern " << Classname << " cms2;" << endl; |
603 |
< |
headerf << "#endif" << endl << endl; |
604 |
< |
|
605 |
< |
// Create namespace that can be used to access the extern'd cms2 |
606 |
< |
// object methods without having to type cms2. everywhere. |
607 |
< |
// Does not include cms2.Init and cms2.GetEntry because I think |
608 |
< |
// it is healthy to leave those methods as they are |
609 |
< |
headerf << "namespace tas {" << endl; |
610 |
< |
implf << "namespace tas {" << endl; |
611 |
< |
for (Int_t i = 0; i< aliasarray->GetSize(); i++) { |
612 |
< |
TString aliasname(aliasarray->At(i)->GetName()); |
613 |
< |
TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
614 |
< |
TString classname = branch->GetClassName(); |
615 |
< |
TString title = branch->GetTitle(); |
616 |
< |
if ( classname.Contains("vector") ) { |
617 |
< |
if(classname.Contains("edm::Wrapper") ) { |
618 |
< |
classname = classname(0,classname.Length()-2); |
619 |
< |
classname.ReplaceAll("edm::Wrapper<",""); |
620 |
< |
} |
621 |
< |
headerf << "\t" << classname << " &" << aliasname << "()"; |
622 |
< |
implf << "\t" << classname << " &" << aliasname << "()"; |
623 |
< |
} else { |
624 |
< |
if(classname.Contains("edm::Wrapper<") ) { |
625 |
< |
classname = classname(0,classname.Length()-1); |
626 |
< |
classname.ReplaceAll("edm::Wrapper<",""); |
627 |
< |
} |
628 |
< |
if(classname != "" ) { |
629 |
< |
headerf << "\t" << classname << " &" << aliasname << "()"; |
630 |
< |
implf << "\t" << classname << " &" << aliasname << "()"; |
631 |
< |
} else { |
632 |
< |
if(title.EndsWith("/i")){ |
633 |
< |
headerf << "\tunsigned int &" << aliasname << "()"; |
634 |
< |
implf << "\tunsigned int &" << aliasname << "()"; |
635 |
< |
} |
636 |
< |
if(title.EndsWith("/F")){ |
637 |
< |
headerf << "\tfloat &" << aliasname << "()"; |
638 |
< |
implf << "\tfloat &" << aliasname << "()"; |
639 |
< |
} |
640 |
< |
if(title.EndsWith("/I")){ |
641 |
< |
headerf << "\tint &" << aliasname << "()"; |
642 |
< |
implf << "\tint &" << aliasname << "()"; |
643 |
< |
} |
644 |
< |
} |
645 |
< |
} |
646 |
< |
headerf << ";" << endl; |
647 |
< |
implf << " { return cms2." << aliasname << "(); }" << endl; |
648 |
< |
} |
649 |
< |
if(haveHLTInfo) { |
650 |
< |
//functions to return whether or not trigger fired - HLT |
651 |
< |
headerf << "\t" << "bool passHLTTrigger(TString trigName);" << endl; |
652 |
< |
implf << "\t" << "bool passHLTTrigger(TString trigName) { return cms2.passHLTTrigger(trigName); }" << endl; |
653 |
< |
}//if(haveHLTInfo) |
654 |
< |
if(haveHLT8E29Info) { |
655 |
< |
//functions to return whether or not trigger fired - HLT |
656 |
< |
headerf << "\t" << "bool passHLT8E29Trigger(TString trigName);" << endl; |
657 |
< |
implf << "\t" << "bool passHLT8E29Trigger(TString trigName) { return cms2.passHLT8E29Trigger(trigName); }" << endl; |
658 |
< |
}//if(haveHLT8E29Info) |
659 |
< |
if(haveL1Info) { |
660 |
< |
//functions to return whether or not trigger fired - L1 |
661 |
< |
headerf << "\t" << "bool passL1Trigger(TString trigName);" << endl; |
662 |
< |
implf << "\t" << "bool passL1Trigger(TString trigName) { return cms2.passL1Trigger(trigName); }" << endl; |
663 |
< |
}//if(haveL1Info) |
601 |
> |
headerf << "#ifndef __CINT__" << endl; |
602 |
> |
headerf << "extern " << Classname << " cms2;" << endl; |
603 |
> |
headerf << "#endif" << endl << endl; |
604 |
> |
|
605 |
> |
// Create namespace that can be used to access the extern'd cms2 |
606 |
> |
// object methods without having to type cms2. everywhere. |
607 |
> |
// Does not include cms2.Init and cms2.GetEntry because I think |
608 |
> |
// it is healthy to leave those methods as they are |
609 |
> |
headerf << "namespace tas {" << endl; |
610 |
> |
implf << "namespace tas {" << endl; |
611 |
> |
for (Int_t i = 0; i< aliasarray->GetSize(); i++) { |
612 |
> |
TString aliasname(aliasarray->At(i)->GetName()); |
613 |
> |
// TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
614 |
> |
TBranch *branch = 0; |
615 |
> |
if (have_aliases) |
616 |
> |
branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); |
617 |
> |
else |
618 |
> |
branch = (TBranch*)aliasarray->At(i); |
619 |
> |
|
620 |
> |
TString classname = branch->GetClassName(); |
621 |
> |
TString title = branch->GetTitle(); |
622 |
> |
if ( classname.Contains("vector") ) { |
623 |
> |
if(classname.Contains("edm::Wrapper") ) { |
624 |
> |
classname = classname(0,classname.Length()-2); |
625 |
> |
classname.ReplaceAll("edm::Wrapper<",""); |
626 |
> |
} |
627 |
> |
headerf << "\t" << classname << " &" << aliasname << "()"; |
628 |
> |
implf << "\t" << classname << " &" << aliasname << "()"; |
629 |
> |
} else { |
630 |
> |
if(classname.Contains("edm::Wrapper<") ) { |
631 |
> |
classname = classname(0,classname.Length()-1); |
632 |
> |
classname.ReplaceAll("edm::Wrapper<",""); |
633 |
> |
} |
634 |
> |
if(classname != "" ) { |
635 |
> |
headerf << "\t" << classname << " &" << aliasname << "()"; |
636 |
> |
implf << "\t" << classname << " &" << aliasname << "()"; |
637 |
> |
} else { |
638 |
> |
if(title.EndsWith("/i")){ |
639 |
> |
headerf << "\tunsigned int &" << aliasname << "()"; |
640 |
> |
implf << "\tunsigned int &" << aliasname << "()"; |
641 |
> |
} |
642 |
> |
if(title.EndsWith("/F")){ |
643 |
> |
headerf << "\tfloat &" << aliasname << "()"; |
644 |
> |
implf << "\tfloat &" << aliasname << "()"; |
645 |
> |
} |
646 |
> |
if(title.EndsWith("/I")){ |
647 |
> |
headerf << "\tint &" << aliasname << "()"; |
648 |
> |
implf << "\tint &" << aliasname << "()"; |
649 |
> |
} |
650 |
> |
if(title.EndsWith("/O")){ |
651 |
> |
headerf << "\tbool &" << aliasname << "()"; |
652 |
> |
implf << "\tbool &" << aliasname << "()"; |
653 |
> |
} |
654 |
> |
} |
655 |
> |
} |
656 |
> |
headerf << ";" << endl; |
657 |
> |
implf << " { return cms2." << aliasname << "(); }" << endl; |
658 |
> |
} |
659 |
> |
if(haveHLTInfo) { |
660 |
> |
//functions to return whether or not trigger fired - HLT |
661 |
> |
headerf << "\t" << "bool passHLTTrigger(TString trigName);" << endl; |
662 |
> |
implf << "\t" << "bool passHLTTrigger(TString trigName) { return cms2.passHLTTrigger(trigName); }" << endl; |
663 |
> |
}//if(haveHLTInfo) |
664 |
> |
if(haveHLT8E29Info) { |
665 |
> |
//functions to return whether or not trigger fired - HLT |
666 |
> |
headerf << "\t" << "bool passHLT8E29Trigger(TString trigName);" << endl; |
667 |
> |
implf << "\t" << "bool passHLT8E29Trigger(TString trigName) { return cms2.passHLT8E29Trigger(trigName); }" << endl; |
668 |
> |
}//if(haveHLT8E29Info) |
669 |
> |
if(haveL1Info) { |
670 |
> |
//functions to return whether or not trigger fired - L1 |
671 |
> |
headerf << "\t" << "bool passL1Trigger(TString trigName);" << endl; |
672 |
> |
implf << "\t" << "bool passL1Trigger(TString trigName) { return cms2.passL1Trigger(trigName); }" << endl; |
673 |
> |
}//if(haveL1Info) |
674 |
|
|
675 |
|
} |
676 |
|
|
677 |
|
//------------------------------------------------------------------------------------------------- |
678 |
|
void makeSrcFile(std::string Classname, std::string branchNamesFile) { |
679 |
|
|
680 |
< |
// TTree *ev = (TTree*)f->Get("Events"); |
680 |
> |
// TTree *ev = (TTree*)f->Get("Events"); |
681 |
|
|
682 |
< |
codef << "/* Usage:" << endl; |
683 |
< |
codef << " root [0] .L ScanChain.C++" << endl; |
684 |
< |
codef << " root [1] TChain *chain = new TChain(\"Events\")" << endl; |
685 |
< |
codef << " root [2] chain->Add(\"merged_ntuple.root\")" << endl; |
686 |
< |
codef << " root [3] ScanChain(chain)" << endl; |
687 |
< |
codef << "*/" << endl; |
688 |
< |
codef << "" << endl; |
689 |
< |
codef << "// C++" << endl; |
690 |
< |
codef << "#include <iostream>" << endl; |
691 |
< |
codef << "#include <vector>" << endl; |
692 |
< |
codef << "" << endl; |
693 |
< |
codef << "// ROOT" << endl; |
694 |
< |
codef << "#include \"TChain.h\"" << endl; |
695 |
< |
codef << "#include \"TFile.h\"" << endl; |
696 |
< |
codef << "#include \"TDirectory.h\"" << endl; |
697 |
< |
codef << "#include \"TROOT.h\"" << endl; |
698 |
< |
codef << "" << endl; |
699 |
< |
codef << "// CMS2" << endl; |
700 |
< |
codef << "#include \"" + Classname+".cc\"" << endl; |
701 |
< |
if(branchNamesFile!="") |
702 |
< |
codef << "#include \"branches.h\"" << endl; |
703 |
< |
codef << "using namespace tas;" << endl; |
704 |
< |
codef << endl; |
705 |
< |
codef << endl; |
706 |
< |
codef << "int ScanChain( TChain* chain, int nEvents = -1, std::string skimFilePrefix=\"\") {" << endl; |
707 |
< |
codef << "" << endl; |
708 |
< |
codef << " // Example Histograms" << endl; |
709 |
< |
codef << " TDirectory *rootdir = gDirectory->GetDirectory(\"Rint:\");" << endl; |
710 |
< |
codef << " TH1F *samplehisto = new TH1F(\"samplehisto\", \"Example histogram\", 200,0,200);" << endl; |
711 |
< |
codef << " samplehisto->SetDirectory(rootdir);" << endl; |
712 |
< |
codef << "" << endl; |
713 |
< |
codef << " // File Loop" << endl; |
714 |
< |
codef << " if( nEvents == -1 ) nEvents = chain->GetEntries();" << endl; |
715 |
< |
codef << " unsigned int nEventsChain = nEvents;" << endl; |
716 |
< |
codef << " unsigned int nEventsTotal = 0;" << endl; |
717 |
< |
if(branchNamesFile!="") |
718 |
< |
codef << " InitSkimmedTree(skimFilePrefix);" << endl; |
719 |
< |
codef << " TObjArray *listOfFiles = chain->GetListOfFiles();" << endl; |
720 |
< |
codef << " TIter fileIter(listOfFiles);" << endl; |
721 |
< |
codef << " TFile *currentFile = 0;" << endl; |
722 |
< |
codef << " while ( (currentFile = (TFile*)fileIter.Next()) ) {" << endl; |
723 |
< |
codef << " // Get File Content" << endl; |
724 |
< |
codef << " TFile f( currentFile->GetTitle() );" << endl; |
725 |
< |
codef << " TTree *tree = (TTree*)f.Get(\"Events\");" << endl; |
726 |
< |
codef << " cms2.Init(tree);" << endl; |
727 |
< |
codef << " " << endl; |
728 |
< |
codef << " // Event Loop" << endl; |
729 |
< |
codef << " unsigned int nEvents = tree->GetEntries();" << endl; |
730 |
< |
codef << " for( unsigned int event = 0; event < nEvents; ++event) {" << endl; |
731 |
< |
codef << " " << endl; |
732 |
< |
codef << " // Get Event Content" << endl; |
733 |
< |
codef << " cms2.GetEntry(event);" << endl; |
734 |
< |
codef << " ++nEventsTotal;" << endl; |
735 |
< |
codef << " " << endl; |
736 |
< |
codef << " // Progress" << endl; |
737 |
< |
codef << " CMS2::progress( nEventsTotal, nEventsChain );" << endl; |
738 |
< |
codef << " }" << endl; |
739 |
< |
codef << " " << endl; |
740 |
< |
codef << " delete tree;" << endl; |
741 |
< |
codef << " f.Close();" << endl; |
742 |
< |
codef << " }" << endl; |
743 |
< |
codef << " if ( nEventsChain != nEventsTotal ) {" << endl; |
744 |
< |
codef << " std::cout << \"ERROR: number of events from files is not equal to total number of events\" << std::endl;" << endl; |
745 |
< |
codef << " }" << endl; |
746 |
< |
codef << "" << endl; |
747 |
< |
if(branchNamesFile!="") { |
748 |
< |
codef << " outFile_->cd();" << endl; |
749 |
< |
codef << " outTree_->Write();" << endl; |
750 |
< |
codef << " outFile_->Close();" << endl; |
751 |
< |
} |
752 |
< |
codef << " " << endl; |
753 |
< |
codef << " // Example Histograms" << endl; |
754 |
< |
codef << " samplehisto->Draw();" << endl; |
755 |
< |
codef << " " << endl; |
756 |
< |
codef << " // return" << endl; |
757 |
< |
codef << " return 0;" << endl; |
758 |
< |
codef << "}" << endl; |
682 |
> |
codef << "// Usage:" << endl; |
683 |
> |
codef << "// > root -b doAll.C" << endl; |
684 |
> |
codef << "" << endl; |
685 |
> |
codef << "// C++" << endl; |
686 |
> |
codef << "#include <iostream>" << endl; |
687 |
> |
codef << "#include <vector>" << endl; |
688 |
> |
codef << "" << endl; |
689 |
> |
codef << "// ROOT" << endl; |
690 |
> |
codef << "#include \"TBenchmark.h\"" << endl; |
691 |
> |
codef << "#include \"TChain.h\"" << endl; |
692 |
> |
codef << "#include \"TDirectory.h\"" << endl; |
693 |
> |
codef << "#include \"TFile.h\"" << endl; |
694 |
> |
codef << "#include \"TROOT.h\"" << endl; |
695 |
> |
codef << "#include \"TTreeCache.h\"" << endl; |
696 |
> |
codef << "" << endl; |
697 |
> |
codef << "// CMS2" << endl; |
698 |
> |
codef << "#include \"" + Classname+".cc\"" << endl; |
699 |
> |
if(branchNamesFile!="") |
700 |
> |
codef << "#include \"branches.h\"" << endl; |
701 |
> |
codef << "" << endl; |
702 |
> |
codef << "using namespace std;" << endl; |
703 |
> |
codef << "using namespace tas;" << endl; |
704 |
> |
codef << endl; |
705 |
> |
codef << "int ScanChain( TChain* chain, bool fast = true, int nEvents = -1, string skimFilePrefix = \"test\") {" << endl; |
706 |
> |
codef << "" << endl; |
707 |
> |
codef << " // Benchmark" << endl; |
708 |
> |
codef << " TBenchmark *bmark = new TBenchmark();" << endl; |
709 |
> |
codef << " bmark->Start(\"benchmark\");" << endl; |
710 |
> |
codef << "" << endl; |
711 |
> |
codef << " // Example Histograms" << endl; |
712 |
> |
codef << " TDirectory *rootdir = gDirectory->GetDirectory(\"Rint:\");" << endl; |
713 |
> |
codef << " TH1F *samplehisto = new TH1F(\"samplehisto\", \"Example histogram\", 200,0,200);" << endl; |
714 |
> |
codef << " samplehisto->SetDirectory(rootdir);" << endl; |
715 |
> |
codef << "" << endl; |
716 |
> |
codef << " // Loop over events to Analyze" << endl; |
717 |
> |
codef << " unsigned int nEventsTotal = 0;" << endl; |
718 |
> |
codef << " unsigned int nEventsChain = chain->GetEntries();" << endl; |
719 |
> |
codef << " if( nEvents >= 0 ) nEventsChain = nEvents;" << endl; |
720 |
> |
if(branchNamesFile!="") |
721 |
> |
codef << " InitSkimmedTree(skimFilePrefix);" << endl; |
722 |
> |
codef << " TObjArray *listOfFiles = chain->GetListOfFiles();" << endl; |
723 |
> |
codef << " TIter fileIter(listOfFiles);" << endl; |
724 |
> |
codef << " TFile *currentFile = 0;" << endl; |
725 |
> |
codef << "" << endl; |
726 |
> |
codef << " // File Loop" << endl; |
727 |
> |
codef << " while ( (currentFile = (TFile*)fileIter.Next()) ) {" << endl; |
728 |
> |
codef << "" << endl; |
729 |
> |
codef << " // Get File Content" << endl; |
730 |
> |
codef << " TFile *file = new TFile( currentFile->GetTitle() );" << endl; |
731 |
> |
codef << " TTree *tree = (TTree*)file->Get(\"Events\");" << endl; |
732 |
> |
codef << " if(fast) TTreeCache::SetLearnEntries(10);" << endl; |
733 |
> |
codef << " if(fast) tree->SetCacheSize(128*1024*1024);" << endl; |
734 |
> |
codef << " cms2.Init(tree);" << endl; |
735 |
> |
codef << " " << endl; |
736 |
> |
codef << " // Loop over Events in current file" << endl; |
737 |
> |
codef << " if( nEventsTotal >= nEventsChain ) continue;" << endl; |
738 |
> |
codef << " unsigned int nEventsTree = tree->GetEntriesFast();" << endl; |
739 |
> |
codef << " for( unsigned int event = 0; event < nEventsTree; ++event) {" << endl; |
740 |
> |
codef << " " << endl; |
741 |
> |
codef << " // Get Event Content" << endl; |
742 |
> |
codef << " if( nEventsTotal >= nEventsChain ) continue;" << endl; |
743 |
> |
codef << " if(fast) tree->LoadTree(event);" << endl; |
744 |
> |
codef << " cms2.GetEntry(event);" << endl; |
745 |
> |
codef << " ++nEventsTotal;" << endl; |
746 |
> |
codef << " " << endl; |
747 |
> |
codef << " // Progress" << endl; |
748 |
> |
codef << " CMS2::progress( nEventsTotal, nEventsChain );" << endl << endl; |
749 |
> |
codef << " // Analysis Code" << endl << endl; |
750 |
> |
codef << " }" << endl; |
751 |
> |
codef << " " << endl; |
752 |
> |
codef << " // Clean Up" << endl; |
753 |
> |
codef << " delete tree;" << endl; |
754 |
> |
codef << " file->Close();" << endl; |
755 |
> |
codef << " delete file;" << endl; |
756 |
> |
codef << " }" << endl; |
757 |
> |
codef << " if ( nEventsChain != nEventsTotal ) {" << endl; |
758 |
> |
codef << " cout << Form( \"ERROR: number of events from files (\%d) is not equal to total number of events (\%d)\", nEventsChain, nEventsTotal ) << endl;" << endl; |
759 |
> |
codef << " }" << endl; |
760 |
> |
if(branchNamesFile!="") { |
761 |
> |
codef << " outFile_->cd();" << endl; |
762 |
> |
codef << " outTree_->Write();" << endl; |
763 |
> |
codef << " outFile_->Close();" << endl; |
764 |
> |
} |
765 |
> |
codef << " " << endl; |
766 |
> |
codef << " // Example Histograms" << endl; |
767 |
> |
codef << " samplehisto->Draw();" << endl; |
768 |
> |
codef << " " << endl; |
769 |
> |
codef << " // return" << endl; |
770 |
> |
codef << " bmark->Stop(\"benchmark\");" << endl; |
771 |
> |
codef << " cout << endl;" << endl; |
772 |
> |
codef << " cout << nEventsTotal << \" Events Processed\" << endl;" << endl; |
773 |
> |
codef << " cout << \"------------------------------\" << endl;" << endl; |
774 |
> |
codef << " cout << \"CPU Time:\t\" << Form( \"\%.01f\", bmark->GetCpuTime(\"benchmark\") ) << endl;" << endl; |
775 |
> |
codef << " cout << \"Real Time:\t\" << Form( \"\%.01f\", bmark->GetRealTime(\"benchmark\") ) << endl;" << endl; |
776 |
> |
codef << " cout << endl;" << endl; |
777 |
> |
codef << " delete bmark;" << endl; |
778 |
> |
codef << " return 0;" << endl; |
779 |
> |
codef << "}" << endl; |
780 |
|
|
781 |
|
} |
782 |
|
|
784 |
|
//------------------------------------------------------------------------------------------------- |
785 |
|
void makeBranchFile(std::string branchNamesFile) { |
786 |
|
|
787 |
< |
ifstream branchesF(branchNamesFile.c_str()); |
788 |
< |
vector<TString> v_datatypes; |
789 |
< |
vector<TString> v_varNames; |
790 |
< |
while(!branchesF.eof()) { |
791 |
< |
string temp; |
792 |
< |
getline(branchesF, temp); |
793 |
< |
TString line(temp); |
794 |
< |
// do not use commented lines |
795 |
< |
if(line.BeginsWith("//")) |
796 |
< |
continue; |
797 |
< |
vector<TString> v_line; |
798 |
< |
TIter objIt((TObjArray*)line.Tokenize(" ")); |
799 |
< |
while(TObject *obj = (TObject*)objIt.Next()) { |
800 |
< |
if(obj==NULL) |
801 |
< |
continue; |
802 |
< |
v_line.push_back(obj->GetName()); |
803 |
< |
} |
787 |
> |
ifstream branchesF(branchNamesFile.c_str()); |
788 |
> |
vector<TString> v_datatypes; |
789 |
> |
vector<TString> v_varNames; |
790 |
> |
while(!branchesF.eof()) { |
791 |
> |
string temp; |
792 |
> |
getline(branchesF, temp); |
793 |
> |
TString line(temp); |
794 |
> |
// do not use commented lines |
795 |
> |
if(line.BeginsWith("//")) |
796 |
> |
continue; |
797 |
> |
vector<TString> v_line; |
798 |
> |
TIter objIt((TObjArray*)line.Tokenize(" ")); |
799 |
> |
while(TObject *obj = (TObject*)objIt.Next()) { |
800 |
> |
if(obj==NULL) |
801 |
> |
continue; |
802 |
> |
v_line.push_back(obj->GetName()); |
803 |
> |
} |
804 |
|
|
805 |
< |
if(v_line.size() == 0) |
806 |
< |
continue; |
807 |
< |
TString varName; |
808 |
< |
//loop over v_line until you get to the first element thats not a space |
809 |
< |
for(vector<TString>::iterator it = v_line.begin(); |
810 |
< |
it != v_line.end(); it++) { |
811 |
< |
if( *it != " " ) { |
812 |
< |
varName = *it; |
813 |
< |
} |
814 |
< |
} |
805 |
> |
if(v_line.size() == 0) |
806 |
> |
continue; |
807 |
> |
TString varName; |
808 |
> |
//loop over v_line until you get to the first element thats not a space |
809 |
> |
for(vector<TString>::iterator it = v_line.begin(); |
810 |
> |
it != v_line.end(); it++) { |
811 |
> |
if( *it != " " ) { |
812 |
> |
varName = *it; |
813 |
> |
} |
814 |
> |
} |
815 |
|
|
816 |
< |
v_varNames.push_back(varName.Strip()); //paranoid....strips trailing spaces |
817 |
< |
TString datatype(""); |
818 |
< |
for(unsigned int i = 0; i < v_line.size()-1; i++) { |
819 |
< |
TString temp = v_line[i]; |
820 |
< |
if(temp.Contains("vector") && !temp.Contains("std::")) |
821 |
< |
temp.ReplaceAll("vector", "std::vector"); |
822 |
< |
if(temp.Contains("LorentzVector") && !temp.Contains("ROOT::Math::LorentzVector")) |
823 |
< |
temp.ReplaceAll("LorentzVector", "ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> >"); |
824 |
< |
temp.ReplaceAll(">>", "> >"); |
825 |
< |
temp.ReplaceAll(">>>", "> > >"); |
826 |
< |
if(i!=0) |
827 |
< |
datatype = datatype+" " + temp; |
777 |
< |
else |
778 |
< |
datatype = datatype+temp; |
779 |
< |
} |
780 |
< |
v_datatypes.push_back(datatype); |
816 |
> |
v_varNames.push_back(varName.Strip()); //paranoid....strips trailing spaces |
817 |
> |
TString datatype(""); |
818 |
> |
for(unsigned int i = 0; i < v_line.size()-1; i++) { |
819 |
> |
TString temp2 = v_line[i]; |
820 |
> |
if(temp2.Contains("vector") && !temp2.Contains("std::")) temp2.ReplaceAll("vector", "std::vector"); |
821 |
> |
if(temp2.Contains("LorentzVector") && !temp2.Contains("ROOT::Math::LorentzVector")) temp2.ReplaceAll("LorentzVector", "ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> >"); |
822 |
> |
temp2.ReplaceAll(">>", "> >"); |
823 |
> |
temp2.ReplaceAll(">>>", "> > >"); |
824 |
> |
if(i!=0) datatype = datatype+" " + temp2; |
825 |
> |
else datatype = datatype+temp2; |
826 |
> |
} |
827 |
> |
v_datatypes.push_back(datatype); |
828 |
|
|
829 |
< |
} |
830 |
< |
branchfile.open("branches.h"); |
831 |
< |
branchfile << "#ifndef BRANCHES_H" << endl << "#define BRANCHES_H" << endl; |
832 |
< |
branchfile << "#include <vector>" << endl; |
833 |
< |
branchfile << "#include \"TFile.h\"" << endl; |
834 |
< |
branchfile << "#include \"TTree.h\"" << endl << endl << endl << endl; |
835 |
< |
|
836 |
< |
for(unsigned int i = 0; i < v_datatypes.size(); i++) { |
837 |
< |
TString temp(v_varNames.at(i)); |
838 |
< |
if(v_datatypes.at(i).Contains("vector") || v_datatypes.at(i).Contains("LorentzVector")) { |
839 |
< |
branchfile << v_datatypes.at(i) << " *" |
840 |
< |
<< temp.ReplaceAll("_","")+"_;" << endl; |
841 |
< |
continue; |
842 |
< |
} |
843 |
< |
branchfile << v_datatypes.at(i) << " " |
844 |
< |
<< temp.ReplaceAll("_","")+"_;" << endl; |
845 |
< |
} |
846 |
< |
|
847 |
< |
|
848 |
< |
branchfile << "TFile *outFile_;" << endl; |
849 |
< |
branchfile << "TTree *outTree_;" << endl; |
850 |
< |
|
851 |
< |
//now declare the branches and set aliases in the InitSkimmedTree function |
852 |
< |
branchfile << "void InitSkimmedTree(std::string skimFilePrefix=\"\") {\n\n"; |
853 |
< |
branchfile << " if(skimFilePrefix != \"\")" << endl; |
854 |
< |
branchfile << " outFile_ = TFile::Open(string(skimFilePrefix + \"_skimmednTuple.root\").c_str(),\"RECREATE\");\n"; |
855 |
< |
branchfile << " else outFile_ = TFile::Open(\"skimmednTuple.root\", \"RECREATE\");\n"; |
856 |
< |
branchfile << " outFile_->cd();" << endl; |
857 |
< |
branchfile << " outTree_ = new TTree(\"Events\", \"\");\n\n"; |
858 |
< |
branchfile << " //book the branches\n"; |
859 |
< |
for(unsigned int i = 0; i < v_datatypes.size(); i++) { |
860 |
< |
TString varName = v_varNames[i]; |
861 |
< |
varName = varName.ReplaceAll("_", "") + "_"; |
862 |
< |
TString varType = v_datatypes[i]; |
863 |
< |
if(varType.BeginsWith("std::vector") |
864 |
< |
|| varType.BeginsWith("ROOT::Math") ) { |
865 |
< |
TString prefix = ""; |
866 |
< |
if(varType.BeginsWith("std::vector<float>") ) |
867 |
< |
prefix = "floats"; |
868 |
< |
if(varType.BeginsWith("std::vector<int>") ) |
869 |
< |
prefix = "ints"; |
870 |
< |
if(varType.BeginsWith("std::vector<unsigned int>") ) |
871 |
< |
prefix = "uints"; |
872 |
< |
if(varType.BeginsWith("ROOT::Math::LorentzVector<") ) |
873 |
< |
prefix = "floatROOTMathPxPyPzE4DROOTMathLorentzVector"; |
874 |
< |
if(varType.BeginsWith("std::vector<ROOT::Math::LorentzVector<") ) |
875 |
< |
prefix = "floatROOTMathPxPyPzE4DROOTMathLorentzVectors"; |
876 |
< |
if(varType.Contains("std::vector<std::vector<ROOT::Math::LorentzVector<") ) |
877 |
< |
prefix = "floatROOTMathPxPyPzE4DROOTMathLorentzVectorss"; |
878 |
< |
branchfile << " outTree_->Branch(\"" << prefix + "_" +varName << "\", \"" |
879 |
< |
<< varType << "\", &" << varName << ");" << endl; |
880 |
< |
branchfile << " outTree_->SetAlias(\"" << v_varNames[i] << "\", " |
881 |
< |
<< "\"" << prefix+"_"+varName << "\");" << endl; |
882 |
< |
continue; |
883 |
< |
} |
884 |
< |
if(varType=="float" || varType == "Float_t") { |
885 |
< |
branchfile << " outTree_->Branch(\"" << varName << "\", &" << varName; |
886 |
< |
branchfile << ", \"" << varName + "/F\");" << endl; |
887 |
< |
branchfile << " outTree_->SetAlias(\"" << v_varNames[i] << "\", " |
888 |
< |
<< "\"" << varName << "\");" << endl; |
889 |
< |
continue; |
890 |
< |
} |
891 |
< |
if(varType=="unsigned int" || varType == "UInt_t") { |
892 |
< |
branchfile << " outTree_->Branch(\"" << varName << "\", &" << varName; |
893 |
< |
branchfile << ", \"" << varName + "/i\");" << endl; |
894 |
< |
branchfile << " outTree_->SetAlias(\"" << v_varNames[i] << "\", " |
895 |
< |
<< "\"" << varName << "\");" << endl; |
896 |
< |
continue; |
897 |
< |
} |
898 |
< |
if(varType=="int" || varType == "Int_t") { |
899 |
< |
branchfile << " outTree_->Branch(\"" << varName << "\", &" << varName; |
900 |
< |
branchfile << ", \"" << varName + "/I\");" << endl; |
901 |
< |
branchfile << " outTree_->SetAlias(\"" << v_varNames[i] << "\", " |
902 |
< |
<< "\"" << varName << "\");" << endl; |
903 |
< |
continue; |
904 |
< |
} |
905 |
< |
} |
859 |
< |
branchfile << "} " << endl; |
860 |
< |
branchfile << "#endif" << endl; |
829 |
> |
} |
830 |
> |
branchfile.open("branches.h"); |
831 |
> |
branchfile << "#ifndef BRANCHES_H" << endl << "#define BRANCHES_H" << endl; |
832 |
> |
branchfile << "#include <vector>" << endl; |
833 |
> |
branchfile << "#include \"TFile.h\"" << endl; |
834 |
> |
branchfile << "#include \"TTree.h\"" << endl << endl << endl << endl; |
835 |
> |
|
836 |
> |
for(unsigned int i = 0; i < v_datatypes.size(); i++) { |
837 |
> |
TString temp2(v_varNames.at(i)); |
838 |
> |
if(v_datatypes.at(i).Contains("vector") || v_datatypes.at(i).Contains("LorentzVector")) { |
839 |
> |
branchfile << v_datatypes.at(i) << " *" << temp2.ReplaceAll("_","")+"_;" << endl; |
840 |
> |
continue; |
841 |
> |
} |
842 |
> |
branchfile << v_datatypes.at(i) << " " << temp2.ReplaceAll("_","")+"_;" << endl; |
843 |
> |
} |
844 |
> |
|
845 |
> |
|
846 |
> |
branchfile << "TFile *outFile_;" << endl; |
847 |
> |
branchfile << "TTree *outTree_;" << endl; |
848 |
> |
|
849 |
> |
//now declare the branches and set aliases in the InitSkimmedTree function |
850 |
> |
branchfile << "void InitSkimmedTree(std::string skimFilePrefix=\"\") {\n\n"; |
851 |
> |
branchfile << " if(skimFilePrefix != \"\")" << endl; |
852 |
> |
branchfile << " outFile_ = TFile::Open(string(skimFilePrefix + \"_skimmednTuple.root\").c_str(),\"RECREATE\");\n"; |
853 |
> |
branchfile << " else outFile_ = TFile::Open(\"skimmednTuple.root\", \"RECREATE\");\n"; |
854 |
> |
branchfile << " outFile_->cd();" << endl; |
855 |
> |
branchfile << " outTree_ = new TTree(\"Events\", \"\");\n\n"; |
856 |
> |
branchfile << " //book the branches\n"; |
857 |
> |
for(unsigned int i = 0; i < v_datatypes.size(); i++) { |
858 |
> |
TString varName = v_varNames[i]; |
859 |
> |
varName = varName.ReplaceAll("_", "") + "_"; |
860 |
> |
TString varType = v_datatypes[i]; |
861 |
> |
if(varType.BeginsWith("std::vector") |
862 |
> |
|| varType.BeginsWith("ROOT::Math") ) { |
863 |
> |
TString prefix = ""; |
864 |
> |
if(varType.BeginsWith("std::vector<float>") ) |
865 |
> |
prefix = "floats"; |
866 |
> |
if(varType.BeginsWith("std::vector<int>") ) |
867 |
> |
prefix = "ints"; |
868 |
> |
if(varType.BeginsWith("std::vector<unsigned int>") ) |
869 |
> |
prefix = "uints"; |
870 |
> |
if(varType.BeginsWith("ROOT::Math::LorentzVector<") ) |
871 |
> |
prefix = "floatROOTMathPxPyPzE4DROOTMathLorentzVector"; |
872 |
> |
if(varType.BeginsWith("std::vector<ROOT::Math::LorentzVector<") ) |
873 |
> |
prefix = "floatROOTMathPxPyPzE4DROOTMathLorentzVectors"; |
874 |
> |
if(varType.Contains("std::vector<std::vector<ROOT::Math::LorentzVector<") ) |
875 |
> |
prefix = "floatROOTMathPxPyPzE4DROOTMathLorentzVectorss"; |
876 |
> |
branchfile << " outTree_->Branch(\"" << prefix + "_" +varName << "\", \"" |
877 |
> |
<< varType << "\", &" << varName << ");" << endl; |
878 |
> |
branchfile << " outTree_->SetAlias(\"" << v_varNames[i] << "\", " |
879 |
> |
<< "\"" << prefix+"_"+varName << "\");" << endl; |
880 |
> |
continue; |
881 |
> |
} |
882 |
> |
if(varType=="float" || varType == "Float_t") { |
883 |
> |
branchfile << " outTree_->Branch(\"" << varName << "\", &" << varName; |
884 |
> |
branchfile << ", \"" << varName + "/F\");" << endl; |
885 |
> |
branchfile << " outTree_->SetAlias(\"" << v_varNames[i] << "\", " |
886 |
> |
<< "\"" << varName << "\");" << endl; |
887 |
> |
continue; |
888 |
> |
} |
889 |
> |
if(varType=="unsigned int" || varType == "UInt_t") { |
890 |
> |
branchfile << " outTree_->Branch(\"" << varName << "\", &" << varName; |
891 |
> |
branchfile << ", \"" << varName + "/i\");" << endl; |
892 |
> |
branchfile << " outTree_->SetAlias(\"" << v_varNames[i] << "\", " |
893 |
> |
<< "\"" << varName << "\");" << endl; |
894 |
> |
continue; |
895 |
> |
} |
896 |
> |
if(varType=="int" || varType == "Int_t") { |
897 |
> |
branchfile << " outTree_->Branch(\"" << varName << "\", &" << varName; |
898 |
> |
branchfile << ", \"" << varName + "/I\");" << endl; |
899 |
> |
branchfile << " outTree_->SetAlias(\"" << v_varNames[i] << "\", " |
900 |
> |
<< "\"" << varName << "\");" << endl; |
901 |
> |
continue; |
902 |
> |
} |
903 |
> |
} |
904 |
> |
branchfile << "} " << endl; |
905 |
> |
branchfile << "#endif" << endl; |
906 |
|
|
907 |
< |
branchfile.close(); |
907 |
> |
branchfile.close(); |
908 |
|
} |
909 |
|
|
910 |
|
|
911 |
|
void makeDriverFile(std::string fname) { |
912 |
|
|
913 |
< |
ofstream driverF; |
914 |
< |
driverF.open("doAll.C"); |
913 |
> |
ofstream driverF; |
914 |
> |
driverF.open("doAll.C"); |
915 |
|
|
916 |
< |
driverF << "{" << endl << endl; |
917 |
< |
driverF << " gROOT->ProcessLine(\".L ScanChain.C+\");" << endl << endl; |
918 |
< |
driverF << " TChain *ch = new TChain(\"Events\"); " << endl; |
919 |
< |
driverF << " ch->Add(\"" + fname + "\");" << endl; |
920 |
< |
driverF << " ScanChain(ch); " << endl; |
921 |
< |
driverF << "}"; |
922 |
< |
driverF.close(); |
916 |
> |
driverF << "{" << endl << endl; |
917 |
> |
driverF << " gROOT->ProcessLine(\".L ScanChain.C+\");" << endl << endl; |
918 |
> |
driverF << " TChain *ch = new TChain(\"Events\"); " << endl; |
919 |
> |
driverF << " ch->Add(\"" + fname + "\");" << endl; |
920 |
> |
driverF << " ScanChain(ch); " << endl; |
921 |
> |
driverF << "}"; |
922 |
> |
driverF.close(); |
923 |
|
|
924 |
|
|
925 |
|
} |