CMS 3D CMS Logo

SummaryTableOutputBranches.cc
Go to the documentation of this file.
2 
3 template<typename Col>
4 void
5 SummaryTableOutputBranches::makeScalarBranches(const std::vector<Col> & tabcols, TTree & tree, const std::string & rootType, std::vector<NamedBranchPtr> & branches ) {
6  for (const auto & col : tabcols) {
7  auto * br = tree.Branch(col.name.c_str(), (void*)nullptr, (col.name+"/"+rootType).c_str());
8  br->SetTitle(col.doc.c_str());
9  branches.emplace_back(col.name, br);
10  }
11 }
12 
13 template<typename Col>
14 void
15 SummaryTableOutputBranches::makeVectorBranches(const std::vector<Col> & tabcols, TTree & tree, const std::string & rootType, std::vector<NamedVectorBranchPtr> & branches ) {
16  for (const auto & col : tabcols) {
17  auto * cbr = tree.Branch(("n"+col.name).c_str(), (void*)nullptr, ("n"+col.name+"/i").c_str());
18  auto * vbr = tree.Branch(col.name.c_str(), (void*)nullptr, (col.name+"[n"+col.name+"]/"+rootType).c_str());
19  cbr->SetTitle(("Number of entries in "+col.name).c_str());
20  vbr->SetTitle(col.doc.c_str());
21  branches.emplace_back(col.name, cbr, vbr);
22  }
23 }
24 
25 template<typename Col>
26 void
27 SummaryTableOutputBranches::fillScalarBranches(const std::vector<Col> & tabcols, std::vector<NamedBranchPtr> & branches ) {
28  if (tabcols.size() != branches.size()) throw cms::Exception("LogicError", "Mismatch in table columns");
29  for (unsigned int i = 0, n = tabcols.size(); i < n; ++i) {
30  if (tabcols[i].name != branches[i].name) throw cms::Exception("LogicError", "Mismatch in table columns");
31  branches[i].branch->SetAddress( const_cast<typename Col::value_type *>(& tabcols[i].value) );
32  }
33 }
34 
35 template<typename Col>
36 void
37 SummaryTableOutputBranches::fillVectorBranches(const std::vector<Col> & tabcols, std::vector<NamedVectorBranchPtr> & branches ) {
38  if (tabcols.size() != branches.size()) throw cms::Exception("LogicError", "Mismatch in table columns");
39  for (unsigned int i = 0, n = tabcols.size(); i < n; ++i) {
40  if (tabcols[i].name != branches[i].name) throw cms::Exception("LogicError", "Mismatch in table columns");
41  branches[i].count = tabcols[i].values.size();
42  branches[i].branch->SetAddress( const_cast<typename Col::element_type *>(& tabcols[i].values.front()) );
43  }
44 }
45 
46 
47 
48 void
50 {
55 
56  // now we go set the pointers for the counter branches
57  for (auto & vbp : m_vintBranches) vbp.counterBranch->SetAddress( & vbp.count );
58  for (auto & vbp : m_vfloatBranches) vbp.counterBranch->SetAddress( & vbp.count );
59 }
60 
61 
63 {
65  iWhatever.getByToken(m_token, handle);
67 
68  if(!m_branchesBooked) {
69  defineBranchesFromFirstEvent(tab, tree);
70  m_branchesBooked=true;
71  }
76 }
77 
78 
void makeVectorBranches(const std::vector< Col > &tabcols, TTree &tree, const std::string &rootType, std::vector< NamedVectorBranchPtr > &branches)
const std::vector< VIntColumn > & vintCols() 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
bool getByToken(EDGetToken token, TypeID const &typeID, BasicHandle &result) 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)