CMS 3D CMS Logo

TriggerOutputBranches.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_NanoAOD_TriggerOutputBranches_h
2 #define PhysicsTools_NanoAOD_TriggerOutputBranches_h
3 
4 #include <string>
5 #include <vector>
6 #include <TTree.h>
12 
14 public:
16  : m_token(token), m_lastRun(-1), m_fills(0) {
17  if (desc->className() != "edm::TriggerResults")
18  throw cms::Exception("Configuration",
19  "NanoAODOutputModule/TriggerOutputBranches can only write out edm::TriggerResults objects");
20  }
21 
22  void updateTriggerNames(TTree &tree, const edm::TriggerNames &names, const edm::TriggerResults &ta);
23  void fill(const edm::EventForOutput &iEvent, TTree &tree);
24 
25 private:
28  triggerResults); //FIXME: if we have to keep it local we may use PsetID check per event instead of run boundary
29 
33  UInt_t m_counter;
34  struct NamedBranchPtr {
36  int idx;
37  TBranch *branch;
38  uint8_t buffer;
39  NamedBranchPtr(const std::string &aname, const std::string &atitle, TBranch *branchptr = nullptr)
40  : name(aname), title(atitle), branch(branchptr), buffer(-1) {}
41  };
42  std::vector<NamedBranchPtr> m_triggerBranches;
43  long m_lastRun;
44  unsigned long m_fills;
45 
46  template <typename T>
47  void fillColumn(NamedBranchPtr &nb, const edm::TriggerResults &triggers) {
48  if (nb.idx >= 0)
49  nb.buffer = triggers.accept(nb.idx);
50  nb.branch->SetAddress(&(nb.buffer)); // Can be improved: this is not reallt needed at each event
51  //but we should be sure that resize of vectors of TriggerOutputBranches do not mess up things
52  }
53 };
54 
55 #endif
NamedBranchPtr(const std::string &aname, const std::string &atitle, TBranch *branchptr=0)
void fillColumn(NamedBranchPtr &nb, const edm::TriggerResults &triggers)
bool accept() const
Has at least one path accepted the event?
const std::string names[nVars_]
int iEvent
Definition: GenABIO.cc:224
TriggerOutputBranches(const edm::BranchDescription *desc, const edm::EDGetToken &token)
std::string const & className() const
static std::string const triggerResults
Definition: EdmProvDump.cc:45
edm::TriggerNames triggerNames(const edm::TriggerResults triggerResults)
Definition: tree.py:1
void fill(const edm::EventForOutput &iEvent, TTree &tree)
void updateTriggerNames(TTree &tree, const edm::TriggerNames &names, const edm::TriggerResults &ta)
std::vector< NamedBranchPtr > m_triggerBranches