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  {
17  if (desc->className() != "nanoaod::FlatTable") 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::EventForOutput &iEvent, TTree & tree, bool extensions) ;
26 
27  private:
33  UInt_t m_counter;
34  struct NamedBranchPtr {
36  TBranch * branch;
37  NamedBranchPtr(const std::string & aname, const std::string & atitle, const std::string & rootType, TBranch *branchptr = nullptr) :
38  name(aname), title(atitle), rootTypeCode(rootType), branch(branchptr) {}
39  };
40  TBranch * m_counterBranch;
41  std::vector<NamedBranchPtr> m_floatBranches;
42  std::vector<NamedBranchPtr> m_intBranches;
43  std::vector<NamedBranchPtr> m_uint8Branches;
45 
46  template<typename T>
47  void fillColumn(NamedBranchPtr & pair, const nanoaod::FlatTable & tab) {
48  int idx = tab.columnIndex(pair.name);
49  if (idx == -1) throw cms::Exception("LogicError", "Missing column in input for "+m_baseName+"_"+pair.name);
50  pair.branch->SetAddress( const_cast<T *>(& tab.columnData<T>(idx).front() ) ); // SetAddress should take a const * !
51  }
52 
53 };
54 
55 #endif
56 
boost::sub_range< const std::vector< T > > columnData(unsigned int column) const
get a column by index (const)
Definition: FlatTable.h:53
int columnIndex(const std::string &name) const
Definition: FlatTable.cc:3
void defineBranchesFromFirstEvent(const nanoaod::FlatTable &tab)
void fill(const edm::EventForOutput &iEvent, TTree &tree, bool extensions)
NamedBranchPtr(const std::string &aname, const std::string &atitle, const std::string &rootType, TBranch *branchptr=0)
std::vector< NamedBranchPtr > m_intBranches
int iEvent
Definition: GenABIO.cc:230
std::string const & className() const
std::vector< NamedBranchPtr > m_uint8Branches
TableOutputBranches(const edm::BranchDescription *desc, const edm::EDGetToken &token)
void branch(TTree &tree)
edm::EDGetToken m_token
enum TableOutputBranches::@820 m_extension
Definition: tree.py:1
long double T
std::vector< NamedBranchPtr > m_floatBranches
void fillColumn(NamedBranchPtr &pair, const nanoaod::FlatTable &tab)