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:
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
TableOutputBranches::NamedBranchPtr::NamedBranchPtr
NamedBranchPtr(const std::string &aname, const std::string &atitle, const std::string &rootType, TBranch *branchptr=nullptr)
Definition: TableOutputBranches.h:37
TableOutputBranches::NamedBranchPtr
Definition: TableOutputBranches.h:34
TableOutputBranches::m_baseName
std::string m_baseName
Definition: TableOutputBranches.h:29
funct::false
false
Definition: Factorize.h:29
TableOutputBranches::defineBranchesFromFirstEvent
void defineBranchesFromFirstEvent(const nanoaod::FlatTable &tab)
Definition: TableOutputBranches.cc:11
TableOutputBranches::m_extension
enum TableOutputBranches::@882 m_extension
TableOutputBranches::m_uint8Branches
std::vector< NamedBranchPtr > m_uint8Branches
Definition: TableOutputBranches.h:46
TableOutputBranches::TableOutputBranches
TableOutputBranches(const edm::BranchDescription *desc, const edm::EDGetToken &token)
Definition: TableOutputBranches.h:14
tree
Definition: tree.py:1
TableOutputBranches::NamedBranchPtr::rootTypeCode
std::string rootTypeCode
Definition: TableOutputBranches.h:35
TableOutputBranches::m_singleton
bool m_singleton
Definition: TableOutputBranches.h:30
TableOutputBranches::IsMain
Definition: TableOutputBranches.h:31
edm::OccurrenceForOutput
Definition: OccurrenceForOutput.h:45
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
TableOutputBranches::fill
void fill(const edm::OccurrenceForOutput &iWhatever, TTree &tree, bool extensions)
Definition: TableOutputBranches.cc:69
TableOutputBranches::branch
void branch(TTree &tree)
Definition: TableOutputBranches.cc:40
TableOutputBranches::m_token
edm::EDGetToken m_token
Definition: TableOutputBranches.h:28
nanoaod::FlatTable::columnData
auto columnData(unsigned int column) const
get a column by index (const)
Definition: FlatTable.h:72
TableOutputBranches::NamedBranchPtr::name
std::string name
Definition: TableOutputBranches.h:35
EDGetToken.h
TableOutputBranches::m_counter
UInt_t m_counter
Definition: TableOutputBranches.h:33
TableOutputBranches::m_doubleBranches
std::vector< NamedBranchPtr > m_doubleBranches
Definition: TableOutputBranches.h:48
nanoaod::FlatTable::columnIndex
int columnIndex(const std::string &name) const
Definition: FlatTable.cc:3
BranchDescription.h
TableOutputBranches
Definition: TableOutputBranches.h:12
TableOutputBranches::DontKnowYetIfMainOrExtension
Definition: TableOutputBranches.h:31
TableOutputBranches::m_floatBranches
std::vector< NamedBranchPtr > m_floatBranches
Definition: TableOutputBranches.h:44
edm::EDGetToken
Definition: EDGetToken.h:35
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TableOutputBranches::m_intBranches
std::vector< NamedBranchPtr > m_intBranches
Definition: TableOutputBranches.h:45
FlatTable.h
nanoaod::FlatTable
Definition: FlatTable.h:38
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
TableOutputBranches::m_uint32Branches
std::vector< NamedBranchPtr > m_uint32Branches
Definition: TableOutputBranches.h:47
TableOutputBranches::IsExtension
Definition: TableOutputBranches.h:31
T
long double T
Definition: Basic3DVectorLD.h:48
TableOutputBranches::NamedBranchPtr::branch
TBranch * branch
Definition: TableOutputBranches.h:36
Exception
Definition: hltDiff.cc:245
TableOutputBranches::m_branchesBooked
bool m_branchesBooked
Definition: TableOutputBranches.h:49
TableOutputBranches::NamedBranchPtr::title
std::string title
Definition: TableOutputBranches.h:35
TableOutputBranches::fillColumn
void fillColumn(NamedBranchPtr &pair, const nanoaod::FlatTable &tab)
Definition: TableOutputBranches.h:52
edm::BranchDescription
Definition: BranchDescription.h:32
cms::Exception
Definition: Exception.h:70
OccurrenceForOutput.h
TableOutputBranches::m_doc
std::string m_doc
Definition: TableOutputBranches.h:32
TableOutputBranches::m_counterBranch
TBranch * m_counterBranch
Definition: TableOutputBranches.h:43
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316