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::EventForOutput &iEvent, 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;
48 
49  template <typename T>
50  void fillColumn(NamedBranchPtr &pair, const nanoaod::FlatTable &tab) {
51  int idx = tab.columnIndex(pair.name);
52  if (idx == -1)
53  throw cms::Exception("LogicError", "Missing column in input for " + m_baseName + "_" + pair.name);
54  pair.branch->SetAddress(const_cast<T *>(&tab.columnData<T>(idx).front())); // SetAddress should take a const * !
55  }
56 };
57 
58 #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
TableOutputBranches::DontKnowYetIfMainOrExtension
Definition: TableOutputBranches.h:31
funct::false
false
Definition: Factorize.h:29
TableOutputBranches::defineBranchesFromFirstEvent
void defineBranchesFromFirstEvent(const nanoaod::FlatTable &tab)
Definition: TableOutputBranches.cc:11
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
TableOutputBranches::m_extension
enum TableOutputBranches::@863 m_extension
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
EventForOutput.h
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
TableOutputBranches::branch
void branch(TTree &tree)
Definition: TableOutputBranches.cc:34
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:70
TableOutputBranches::NamedBranchPtr::name
std::string name
Definition: TableOutputBranches.h:35
TableOutputBranches::fill
void fill(const edm::EventForOutput &iEvent, TTree &tree, bool extensions)
Definition: TableOutputBranches.cc:62
EDGetToken.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TableOutputBranches::m_counter
UInt_t m_counter
Definition: TableOutputBranches.h:33
TableOutputBranches::IsExtension
Definition: TableOutputBranches.h:31
nanoaod::FlatTable::columnIndex
int columnIndex(const std::string &name) const
Definition: FlatTable.cc:3
BranchDescription.h
TableOutputBranches
Definition: TableOutputBranches.h:12
iEvent
int iEvent
Definition: GenABIO.cc:224
TableOutputBranches::m_floatBranches
std::vector< NamedBranchPtr > m_floatBranches
Definition: TableOutputBranches.h:44
TableOutputBranches::IsMain
Definition: TableOutputBranches.h:31
edm::EDGetToken
Definition: EDGetToken.h:35
TableOutputBranches::m_intBranches
std::vector< NamedBranchPtr > m_intBranches
Definition: TableOutputBranches.h:45
FlatTable.h
edm::EventForOutput
Definition: EventForOutput.h:50
nanoaod::FlatTable
Definition: FlatTable.h:38
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
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:47
TableOutputBranches::NamedBranchPtr::title
std::string title
Definition: TableOutputBranches.h:35
TableOutputBranches::fillColumn
void fillColumn(NamedBranchPtr &pair, const nanoaod::FlatTable &tab)
Definition: TableOutputBranches.h:50
edm::BranchDescription
Definition: BranchDescription.h:32
cms::Exception
Definition: Exception.h:70
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