CMS 3D CMS Logo

SummaryTableOutputBranches.cc
Go to the documentation of this file.
2 
3 template <typename T, typename Col>
4 void SummaryTableOutputBranches::makeScalarBranches(const std::vector<Col> &tabcols,
5  TTree &tree,
6  const std::string &rootType,
7  std::vector<NamedBranchPtr> &branches) {
8  for (const auto &col : tabcols) {
9  if (std::find_if(branches.begin(), branches.end(), [&col](const NamedBranchPtr &x) {
10  return x.name == col.name;
11  }) == branches.end()) {
12  T backFillValue = 0;
13  auto *br = tree.Branch(col.name.c_str(), &backFillValue, (col.name + "/" + rootType).c_str());
14  br->SetTitle(col.doc.c_str());
15  for (unsigned long i = 0; i < m_fills; i++)
16  br->Fill();
17  branches.emplace_back(col.name, br);
18  }
19  }
20 }
21 
22 template <typename Col>
23 void SummaryTableOutputBranches::makeVectorBranches(const std::vector<Col> &tabcols,
24  TTree &tree,
25  const std::string &rootType,
26  std::vector<NamedVectorBranchPtr> &branches) {
27  for (const auto &col : tabcols) {
28  if (std::find_if(branches.begin(), branches.end(), [&col](const NamedBranchPtr &x) {
29  return x.name == col.name;
30  }) == branches.end()) {
31  unsigned int backFillValue = 0;
32  auto *cbr = tree.Branch(("n" + col.name).c_str(), &backFillValue, ("n" + col.name + "/i").c_str());
33  auto *vbr =
34  tree.Branch(col.name.c_str(), (void *)nullptr, (col.name + "[n" + col.name + "]/" + rootType).c_str());
35  cbr->SetTitle(("Number of entries in " + col.name).c_str());
36  vbr->SetTitle(col.doc.c_str());
37  for (unsigned long i = 0; i < m_fills; i++) {
38  cbr->Fill();
39  vbr->Fill();
40  }
41  branches.emplace_back(col.name, cbr, vbr);
42  }
43  }
44 }
45 
46 template <typename Col>
47 void SummaryTableOutputBranches::fillScalarBranches(const std::vector<Col> &tabcols,
48  std::vector<NamedBranchPtr> &branches) {
49  if (tabcols.size() != branches.size())
50  throw cms::Exception("LogicError", "Mismatch in table columns");
51  for (unsigned int i = 0, n = tabcols.size(); i < n; ++i) {
52  if (tabcols[i].name != branches[i].name)
53  throw cms::Exception("LogicError", "Mismatch in table columns");
54  branches[i].branch->SetAddress(const_cast<typename Col::value_type *>(&tabcols[i].value));
55  }
56 }
57 
58 template <typename Col>
59 void SummaryTableOutputBranches::fillVectorBranches(const std::vector<Col> &tabcols,
60  std::vector<NamedVectorBranchPtr> &branches) {
61  if (tabcols.size() != branches.size())
62  throw cms::Exception("LogicError", "Mismatch in table columns");
63  for (unsigned int i = 0, n = tabcols.size(); i < n; ++i) {
64  if (tabcols[i].name != branches[i].name)
65  throw cms::Exception("LogicError", "Mismatch in table columns");
66  branches[i].count = tabcols[i].values.size();
67  branches[i].branch->SetAddress(const_cast<typename Col::element_type *>(&tabcols[i].values.front()));
68  }
69 }
70 
72  makeScalarBranches<Long64_t>(tab.intCols(), tree, "L", m_intBranches);
73  makeScalarBranches<Double_t>(tab.floatCols(), tree, "D", m_floatBranches);
74  makeScalarBranches<Double_t>(tab.floatWithNormCols(), tree, "D", m_floatWithNormBranches);
78 
79  // now we go set the pointers for the counter branches
80  for (auto &vbp : m_vintBranches)
81  vbp.counterBranch->SetAddress(&vbp.count);
82  for (auto &vbp : m_vfloatBranches)
83  vbp.counterBranch->SetAddress(&vbp.count);
84  for (auto &vbp : m_vfloatWithNormBranches)
85  vbp.counterBranch->SetAddress(&vbp.count);
86 }
87 
90  iWhatever.getByToken(m_token, handle);
92 
93  updateBranches(tab, tree);
94 
101  m_fills++;
102 }
void makeVectorBranches(const std::vector< Col > &tabcols, TTree &tree, const std::string &rootType, std::vector< NamedVectorBranchPtr > &branches)
std::vector< NamedVectorBranchPtr > m_vfloatWithNormBranches
const std::vector< FloatWithNormColumn > & floatWithNormCols() const
const std::vector< VIntColumn > & vintCols() const
void fillVectorBranches(const std::vector< Col > &tabcols, std::vector< NamedVectorBranchPtr > &branches)
std::vector< NamedBranchPtr > m_floatWithNormBranches
std::vector< NamedVectorBranchPtr > m_vintBranches
const std::vector< IntColumn > & intCols() const
void updateBranches(const nanoaod::MergeableCounterTable &tab, TTree &tree)
const std::vector< FloatColumn > & floatCols() const
bool getByToken(EDGetToken token, TypeID const &typeID, BasicHandle &result) const
void makeScalarBranches(const std::vector< Col > &tabcols, TTree &tree, const std::string &rootType, std::vector< NamedBranchPtr > &branches)
Definition: value.py:1
void fillScalarBranches(const std::vector< Col > &tabcols, std::vector< NamedBranchPtr > &branches)
const std::vector< VFloatWithNormColumn > & vfloatWithNormCols() const
std::vector< NamedVectorBranchPtr > m_vfloatBranches
const std::vector< VFloatColumn > & vfloatCols() const
col
Definition: cuy.py:1009
std::vector< NamedBranchPtr > m_intBranches
Definition: tree.py:1
std::vector< NamedBranchPtr > m_floatBranches
void fill(const edm::OccurrenceForOutput &iWhatever, TTree &tree)
long double T