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 }
SummaryTableOutputBranches::fill
void fill(const edm::OccurrenceForOutput &iWhatever, TTree &tree)
Definition: SummaryTableOutputBranches.cc:88
mps_fire.i
i
Definition: mps_fire.py:428
nanoaod::MergeableCounterTable::intCols
const std::vector< IntColumn > & intCols() const
Definition: MergeableCounterTable.h:109
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
nanoaod::MergeableCounterTable::vfloatWithNormCols
const std::vector< VFloatWithNormColumn > & vfloatWithNormCols() const
Definition: MergeableCounterTable.h:108
SummaryTableOutputBranches.h
patZpeak.handle
handle
Definition: patZpeak.py:23
tree
Definition: tree.py:1
cuy.col
col
Definition: cuy.py:1009
SummaryTableOutputBranches::fillVectorBranches
void fillVectorBranches(const std::vector< Col > &tabcols, std::vector< NamedVectorBranchPtr > &branches)
Definition: SummaryTableOutputBranches.cc:59
SummaryTableOutputBranches::makeScalarBranches
void makeScalarBranches(const std::vector< Col > &tabcols, TTree &tree, const std::string &rootType, std::vector< NamedBranchPtr > &branches)
Definition: SummaryTableOutputBranches.cc:4
SummaryTableOutputBranches::m_floatWithNormBranches
std::vector< NamedBranchPtr > m_floatWithNormBranches
Definition: SummaryTableOutputBranches.h:30
DDAxes::x
SummaryTableOutputBranches::m_vintBranches
std::vector< NamedVectorBranchPtr > m_vintBranches
Definition: SummaryTableOutputBranches.h:40
edm::Handle
Definition: AssociativeIterator.h:50
SummaryTableOutputBranches::m_fills
unsigned long m_fills
Definition: SummaryTableOutputBranches.h:42
nanoaod::MergeableCounterTable::vintCols
const std::vector< VIntColumn > & vintCols() const
Definition: MergeableCounterTable.h:110
edm::OccurrenceForOutput
Definition: OccurrenceForOutput.h:45
edm::OccurrenceForOutput::getByToken
BasicHandle getByToken(EDGetToken token, TypeID const &typeID) const
Definition: OccurrenceForOutput.cc:44
SummaryTableOutputBranches::updateBranches
void updateBranches(const nanoaod::MergeableCounterTable &tab, TTree &tree)
Definition: SummaryTableOutputBranches.cc:71
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
nanoaod::MergeableCounterTable
Definition: MergeableCounterTable.h:11
SummaryTableOutputBranches::m_token
edm::EDGetToken m_token
Definition: SummaryTableOutputBranches.h:23
SummaryTableOutputBranches::m_floatBranches
std::vector< NamedBranchPtr > m_floatBranches
Definition: SummaryTableOutputBranches.h:30
MainPageGenerator.tree
tree
Definition: MainPageGenerator.py:264
nanoaod::MergeableCounterTable::floatWithNormCols
const std::vector< FloatWithNormColumn > & floatWithNormCols() const
Definition: MergeableCounterTable.h:107
beamvalidation.br
br
Definition: beamvalidation.py:397
value
Definition: value.py:1
nanoaod::MergeableCounterTable::floatCols
const std::vector< FloatColumn > & floatCols() const
Definition: MergeableCounterTable.h:105
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SummaryTableOutputBranches::fillScalarBranches
void fillScalarBranches(const std::vector< Col > &tabcols, std::vector< NamedBranchPtr > &branches)
Definition: SummaryTableOutputBranches.cc:47
SummaryTableOutputBranches::NamedBranchPtr
Definition: SummaryTableOutputBranches.h:25
SummaryTableOutputBranches::m_vfloatBranches
std::vector< NamedVectorBranchPtr > m_vfloatBranches
Definition: SummaryTableOutputBranches.h:40
T
long double T
Definition: Basic3DVectorLD.h:48
Exception
Definition: hltDiff.cc:245
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
cms::Exception
Definition: Exception.h:70
nanoaod::MergeableCounterTable::vfloatCols
const std::vector< VFloatColumn > & vfloatCols() const
Definition: MergeableCounterTable.h:106
SummaryTableOutputBranches::m_intBranches
std::vector< NamedBranchPtr > m_intBranches
Definition: SummaryTableOutputBranches.h:30
SummaryTableOutputBranches::m_vfloatWithNormBranches
std::vector< NamedVectorBranchPtr > m_vfloatWithNormBranches
Definition: SummaryTableOutputBranches.h:40
SummaryTableOutputBranches::makeVectorBranches
void makeVectorBranches(const std::vector< Col > &tabcols, TTree &tree, const std::string &rootType, std::vector< NamedVectorBranchPtr > &branches)
Definition: SummaryTableOutputBranches.cc:23