CMS 3D CMS Logo

SummaryTableOutputBranches.cc
Go to the documentation of this file.
2 
3 template <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  auto *br = tree.Branch(col.name.c_str(), (void *)nullptr, (col.name + "/" + rootType).c_str());
10  br->SetTitle(col.doc.c_str());
11  branches.emplace_back(col.name, br);
12  }
13 }
14 
15 template <typename Col>
16 void SummaryTableOutputBranches::makeVectorBranches(const std::vector<Col> &tabcols,
17  TTree &tree,
18  const std::string &rootType,
19  std::vector<NamedVectorBranchPtr> &branches) {
20  for (const auto &col : tabcols) {
21  auto *cbr = tree.Branch(("n" + col.name).c_str(), (void *)nullptr, ("n" + col.name + "/i").c_str());
22  auto *vbr = tree.Branch(col.name.c_str(), (void *)nullptr, (col.name + "[n" + col.name + "]/" + rootType).c_str());
23  cbr->SetTitle(("Number of entries in " + col.name).c_str());
24  vbr->SetTitle(col.doc.c_str());
25  branches.emplace_back(col.name, cbr, vbr);
26  }
27 }
28 
29 template <typename Col>
30 void SummaryTableOutputBranches::fillScalarBranches(const std::vector<Col> &tabcols,
31  std::vector<NamedBranchPtr> &branches) {
32  if (tabcols.size() != branches.size())
33  throw cms::Exception("LogicError", "Mismatch in table columns");
34  for (unsigned int i = 0, n = tabcols.size(); i < n; ++i) {
35  if (tabcols[i].name != branches[i].name)
36  throw cms::Exception("LogicError", "Mismatch in table columns");
37  branches[i].branch->SetAddress(const_cast<typename Col::value_type *>(&tabcols[i].value));
38  }
39 }
40 
41 template <typename Col>
42 void SummaryTableOutputBranches::fillVectorBranches(const std::vector<Col> &tabcols,
43  std::vector<NamedVectorBranchPtr> &branches) {
44  if (tabcols.size() != branches.size())
45  throw cms::Exception("LogicError", "Mismatch in table columns");
46  for (unsigned int i = 0, n = tabcols.size(); i < n; ++i) {
47  if (tabcols[i].name != branches[i].name)
48  throw cms::Exception("LogicError", "Mismatch in table columns");
49  branches[i].count = tabcols[i].values.size();
50  branches[i].branch->SetAddress(const_cast<typename Col::element_type *>(&tabcols[i].values.front()));
51  }
52 }
53 
59 
60  // now we go set the pointers for the counter branches
61  for (auto &vbp : m_vintBranches)
62  vbp.counterBranch->SetAddress(&vbp.count);
63  for (auto &vbp : m_vfloatBranches)
64  vbp.counterBranch->SetAddress(&vbp.count);
65 }
66 
69  iWhatever.getByToken(m_token, handle);
71 
72  if (!m_branchesBooked) {
74  m_branchesBooked = true;
75  }
80 }
void makeVectorBranches(const std::vector< Col > &tabcols, TTree &tree, const std::string &rootType, std::vector< NamedVectorBranchPtr > &branches)
const std::vector< VIntColumn > & vintCols() const
BasicHandle getByToken(EDGetToken token, TypeID const &typeID) const
void fillVectorBranches(const std::vector< Col > &tabcols, std::vector< NamedVectorBranchPtr > &branches)
std::vector< NamedVectorBranchPtr > m_vintBranches
const std::vector< IntColumn > & intCols() const
void makeScalarBranches(const std::vector< Col > &tabcols, TTree &tree, const std::string &rootType, std::vector< NamedBranchPtr > &branches)
const std::vector< FloatColumn > & floatCols() const
void defineBranchesFromFirstEvent(const nanoaod::MergeableCounterTable &tab, TTree &tree)
Definition: value.py:1
void fillScalarBranches(const std::vector< Col > &tabcols, std::vector< NamedBranchPtr > &branches)
std::vector< NamedVectorBranchPtr > m_vfloatBranches
const std::vector< VFloatColumn > & vfloatCols() const
col
Definition: cuy.py:1010
std::vector< NamedBranchPtr > m_intBranches
Definition: tree.py:1
std::vector< NamedBranchPtr > m_floatBranches
void fill(const edm::OccurrenceForOutput &iWhatever, TTree &tree)