CMS 3D CMS Logo

LumiOutputBranches.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_NanoAOD_LumiOutputBranches_h
2 #define PhysicsTools_NanoAOD_LumiOutputBranches_h
3 
4 #include <string>
5 #include <vector>
6 #include <TTree.h>
11 
13 public:
15  : m_token(token),
18  m_counter(0),
19  m_counterBranch(nullptr),
21  if (desc->className() != "nanoaod::FlatTable")
22  throw cms::Exception("Configuration", "NanoAODOutputModule can only write out nanoaod::FlatTable objects");
23  }
24 
26  void branch(TTree &tree);
27 
30  void fill(const edm::LuminosityBlockForOutput &iLumi, TTree &tree, bool extensions);
31 
32 private:
38  typedef Int_t CounterType;
40  struct NamedBranchPtr {
42  TBranch *branch;
44  const std::string &atitle,
45  const std::string &rootType,
46  TBranch *branchptr = nullptr)
47  : name(aname), title(atitle), rootTypeCode(rootType), branch(branchptr) {}
48  };
49  TBranch *m_counterBranch;
50  std::vector<NamedBranchPtr> m_floatBranches;
51  std::vector<NamedBranchPtr> m_intBranches;
52  std::vector<NamedBranchPtr> m_uint8Branches;
54 
55  template <typename T>
56  void fillColumn(NamedBranchPtr &pair, const nanoaod::FlatTable &tab) {
57  int idx = tab.columnIndex(pair.name);
58  if (idx == -1)
59  throw cms::Exception("LogicError", "Missing column in input for " + m_baseName + "_" + pair.name);
60  pair.branch->SetAddress(const_cast<T *>(&tab.columnData<T>(idx).front())); // SetAddress should take a const * !
61  }
62 };
63 
64 #endif
void fillColumn(NamedBranchPtr &pair, const nanoaod::FlatTable &tab)
void defineBranchesFromFirstEvent(const nanoaod::FlatTable &tab)
LumiOutputBranches(const edm::BranchDescription *desc, const edm::EDGetToken &token)
std::vector< NamedBranchPtr > m_floatBranches
std::vector< NamedBranchPtr > m_uint8Branches
std::vector< NamedBranchPtr > m_intBranches
int columnIndex(const std::string &name) const
Definition: FlatTable.cc:3
auto columnData(unsigned int column) const
get a column by index (const)
Definition: FlatTable.h:75
NamedBranchPtr(const std::string &aname, const std::string &atitle, const std::string &rootType, TBranch *branchptr=nullptr)
edm::EDGetToken m_token
enum LumiOutputBranches::@883 m_extension
void branch(TTree &tree)
void fill(const edm::LuminosityBlockForOutput &iLumi, TTree &tree, bool extensions)
Definition: tree.py:1
long double T