CMS 3D CMS Logo

TableOutputBranches.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_NanoAOD_TableOutputBranches_h
2 #define PhysicsTools_NanoAOD_TableOutputBranches_h
3 
4 #include <string>
5 #include <vector>
6 #include <TTree.h>
11 
13 public:
16  if (desc->className() != "nanoaod::FlatTable")
17  throw cms::Exception("Configuration", "NanoAODOutputModule can only write out nanoaod::FlatTable objects");
18  }
19 
21  void branch(TTree &tree);
22 
25  void fill(const edm::OccurrenceForOutput &iWhatever, TTree &tree, bool extensions);
26 
27 private:
30  bool m_singleton = false;
33  typedef Int_t CounterType;
35  struct NamedBranchPtr {
37  TBranch *branch;
39  const std::string &atitle,
40  const std::string &rootType,
41  TBranch *branchptr = nullptr)
42  : name(aname), title(atitle), rootTypeCode(rootType), branch(branchptr) {}
43  };
44  TBranch *m_counterBranch = nullptr;
45  std::vector<NamedBranchPtr> m_uint8Branches;
46  std::vector<NamedBranchPtr> m_int16Branches;
47  std::vector<NamedBranchPtr> m_uint16Branches;
48  std::vector<NamedBranchPtr> m_int32Branches;
49  std::vector<NamedBranchPtr> m_uint32Branches;
50  std::vector<NamedBranchPtr> m_floatBranches;
51  std::vector<NamedBranchPtr> m_doubleBranches;
53 
54  template <typename T>
55  void fillColumn(NamedBranchPtr &pair, const nanoaod::FlatTable &tab) {
56  int idx = tab.columnIndex(pair.name);
57  if (idx == -1)
58  throw cms::Exception("LogicError", "Missing column in input for " + m_baseName + "_" + pair.name);
59  pair.branch->SetAddress(
60  tab.size() == 0 ? static_cast<T *>(nullptr)
61  : const_cast<T *>(&tab.columnData<T>(idx).front())); // SetAddress should take a const * !
62  }
63 };
64 
65 #endif
std::vector< NamedBranchPtr > m_uint32Branches
void defineBranchesFromFirstEvent(const nanoaod::FlatTable &tab)
enum TableOutputBranches::@884 m_extension
int columnIndex(const std::string &name) const
Definition: FlatTable.cc:3
std::vector< NamedBranchPtr > m_int32Branches
std::vector< NamedBranchPtr > m_uint16Branches
auto columnData(unsigned int column) const
get a column by index (const)
Definition: FlatTable.h:75
std::vector< NamedBranchPtr > m_uint8Branches
TableOutputBranches(const edm::BranchDescription *desc, const edm::EDGetToken &token)
void fill(const edm::OccurrenceForOutput &iWhatever, TTree &tree, bool extensions)
void branch(TTree &tree)
edm::EDGetToken m_token
NamedBranchPtr(const std::string &aname, const std::string &atitle, const std::string &rootType, TBranch *branchptr=nullptr)
std::vector< NamedBranchPtr > m_int16Branches
Definition: tree.py:1
long double T
std::vector< NamedBranchPtr > m_floatBranches
unsigned int size() const
Definition: FlatTable.h:59
void fillColumn(NamedBranchPtr &pair, const nanoaod::FlatTable &tab)
std::vector< NamedBranchPtr > m_doubleBranches