CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
33  UInt_t m_counter;
34  struct NamedBranchPtr {
36  TBranch *branch;
38  const std::string &atitle,
39  const std::string &rootType,
40  TBranch *branchptr = nullptr)
41  : name(aname), title(atitle), rootTypeCode(rootType), branch(branchptr) {}
42  };
43  TBranch *m_counterBranch;
44  std::vector<NamedBranchPtr> m_floatBranches;
45  std::vector<NamedBranchPtr> m_intBranches;
46  std::vector<NamedBranchPtr> m_uint8Branches;
47  std::vector<NamedBranchPtr> m_uint32Branches;
48  std::vector<NamedBranchPtr> m_doubleBranches;
50 
51  template <typename T>
52  void fillColumn(NamedBranchPtr &pair, const nanoaod::FlatTable &tab) {
53  int idx = tab.columnIndex(pair.name);
54  if (idx == -1)
55  throw cms::Exception("LogicError", "Missing column in input for " + m_baseName + "_" + pair.name);
56  pair.branch->SetAddress(const_cast<T *>(&tab.columnData<T>(idx).front())); // SetAddress should take a const * !
57  }
58 };
59 
60 #endif
std::vector< NamedBranchPtr > m_uint32Branches
int columnIndex(const std::string &name) const
Definition: FlatTable.cc:3
void defineBranchesFromFirstEvent(const nanoaod::FlatTable &tab)
auto columnData(unsigned int column) const
get a column by index (const)
Definition: FlatTable.h:72
std::vector< NamedBranchPtr > m_intBranches
std::string const & className() const
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)
enum TableOutputBranches::@894 m_extension
long double T
std::vector< NamedBranchPtr > m_floatBranches
void fillColumn(NamedBranchPtr &pair, const nanoaod::FlatTable &tab)
std::vector< NamedBranchPtr > m_doubleBranches