1 #ifndef StringBasedNTupler_NTupler_H
2 #define StringBasedNTupler_NTupler_H
48 branchTitle_ = E +
" calculated on " +
C +
" object from " +
S.encode();
69 typedef std::unique_ptr<std::vector<float> >
value;
89 template <
typename Object>
96 const float defaultValue = 0.;
102 edm::LogError(
"StringBranchHelper") <<
"cannot open: " <<
B.src();
103 value_.reset(
new std::vector<float>(0));
108 value_.reset(
new std::vector<float>(1));
110 (*value_)[0] = (
expr)(*oH);
112 LogDebug(
"StringLeaveHelper") <<
"could not evaluate expression: " <<
B.expr()
113 <<
" on class: " <<
B.className();
114 (*value_)[0] = defaultValue;
123 template <
typename Object,
typename Collection = std::vector<Object> >
130 const float defaultValue = 0.;
134 iEvent.getByLabel(
B.src(), oH);
138 if (!(
iEvent.isRealData() &&
B.className() ==
"reco::GenParticle")) {
139 edm::LogError(
"StringBranchHelper") <<
"cannot open: " <<
B.src() <<
" " <<
B.className();
141 value_.reset(
new std::vector<float>());
146 value_.reset(
new std::vector<float>());
147 value_->reserve(oH->size());
150 if (!
B.selection().empty()) {
155 uint i_end = oH->size();
157 if (!
B.order().empty()) {
160 std::vector<const Object*> copyToSort(oH->size());
161 for (
uint i = 0;
i != i_end; ++
i)
162 copyToSort[
i] = &(*oH)[
i];
165 for (
uint i = 0;
i != i_end; ++
i) {
173 <<
"with sorting. could not evaluate expression: " <<
B.expr() <<
" on class: " <<
B.className();
174 value_->push_back(defaultValue);
179 for (
uint i = 0;
i != i_end; ++
i) {
187 <<
"could not evaluate expression: " <<
B.expr() <<
" on class: " <<
B.className();
188 value_->push_back(defaultValue);
205 std::vector<std::string> branches;
208 for (
uint b = 0;
b != branches.size(); ++
b) {
211 if (bPSet.
exists(
"class"))
218 if (bPSet.
exists(
"order"))
221 if (bPSet.
exists(
"selection"))
226 for (
uint l = 0;
l != leaves.size(); ++
l) {
235 if (leavesPSet.
exists(
"vars")) {
236 std::vector<std::string> leavesS = leavesPSet.
getParameter<std::vector<std::string> >(
"vars");
237 for (
uint l = 0;
l != leavesS.size(); ++
l) {
241 int space =
name.find(
" ");
242 while (space != -1 ) {
246 space =
name.find(
" ");
267 if (branchesPSet.
exists(
"useTFileService"))
273 if (branchesPSet.
exists(
"treeName")) {
297 tree_ = dynamic_cast<TTree*>(
object);
309 Branches::iterator iB =
branches_.begin();
310 Branches::iterator iB_end =
branches_.end();
311 uint indexOfIndexInDataHolder = 0;
312 for (; iB != iB_end; ++iB, ++indexOfIndexInDataHolder) {
314 tree_->Branch(iB->first.c_str(), &(
indexDataHolder_[indexOfIndexInDataHolder]), (iB->first +
"/i").c_str());
316 std::vector<TreeBranch>::iterator iL = iB->second.begin();
317 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
318 for (; iL != iL_end; ++iL) {
321 TBranch*
br =
tree_->Branch(
b.branchAlias().c_str(),
"std::vector<float>", iL->dataHolderPtrAdress());
322 br->SetTitle(
b.branchTitle().c_str());
329 tree_->Branch(
"event",
ev_,
"event/l");
339 Branches::iterator iB =
branches_.begin();
340 Branches::iterator iB_end =
branches_.end();
341 for (; iB != iB_end; ++iB) {
344 producesCollector.
produces<
uint>(iB->first).setBranchAlias(iB->first);
345 std::vector<TreeBranch>::iterator iL = iB->second.begin();
346 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
347 for (; iL != iL_end; ++iL) {
350 producesCollector.
produces<std::vector<float> >(
b.branchName()).setBranchAlias(
b.branchAlias());
364 Branches::iterator iB =
branches_.begin();
365 Branches::iterator iB_end =
branches_.end();
366 uint indexOfIndexInDataHolder = 0;
367 for (; iB != iB_end; ++iB, ++indexOfIndexInDataHolder) {
368 std::vector<TreeBranch>::iterator iL = iB->second.begin();
369 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
371 for (; iL != iL_end; ++iL) {
374 std::unique_ptr<std::vector<float> >
branch(
b.branch(
iEvent));
376 if (
branch->size() > maxS)
379 b.assignDataHolderPtr(
branch.release());
396 if (!
iEvent.isRealData()) {
398 iEvent.getByLabel(
"generator", wgeneventinfo);
402 typedef std::vector<std::string>::const_iterator comments_const_iterator;
407 if (
iEvent.getByLabel(
"source", product)) {
409 comments_const_iterator c_end = product->
comments_end();
411 for (comments_const_iterator cit = c_begin; cit != c_end; ++cit) {
412 size_t found = (*cit).find(
"model");
413 if (
found != std::string::npos) {
425 Branches::iterator iB =
branches_.begin();
426 Branches::iterator iB_end =
branches_.end();
427 for (; iB != iB_end; ++iB) {
428 std::vector<TreeBranch>::iterator iL = iB->second.begin();
429 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
431 for (; iL != iL_end; ++iL) {
433 std::unique_ptr<std::vector<float> >
branch(
b.branch(
iEvent));
434 if (
branch->size() > maxS)
439 iEvent.put(std::make_unique<uint>(maxS), iB->first);
446 Branches::iterator iB =
branches_.begin();
447 Branches::iterator iB_end =
branches_.end();
449 for (; iB != iB_end; ++iB) {
450 std::vector<TreeBranch>::iterator iL = iB->second.begin();
451 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
452 for (; iL != iL_end; ++iL) {
454 delete b.dataHolderPtr();
473 typedef std::map<std::string, std::vector<TreeBranch> >
Branches;