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), m_processName(desc->processName())
17  {
18  if (desc->className() != "edm::TriggerResults") throw cms::Exception("Configuration", "NanoAODOutputModule/TriggerOutputBranches can only write out edm::TriggerResults objects");
19  }
20 
21  void updateTriggerNames(TTree &tree,const edm::TriggerNames & names, const edm::TriggerResults & ta);
22  void fill(const edm::EventForOutput &iEvent,TTree & tree) ;
24 
25  private:
26  edm::TriggerNames triggerNames(const edm::TriggerResults triggerResults); //FIXME: if we have to keep it local we may use PsetID check per event instead of run boundary
27 
31  UInt_t m_counter;
32  struct NamedBranchPtr {
34  int idx;
35  TBranch * branch;
36  uint8_t buffer;
37  NamedBranchPtr(const std::string & aname, const std::string & atitle, TBranch *branchptr = nullptr) :
38  name(aname), title(atitle), branch(branchptr), buffer(0) {}
39  };
40  std::vector<NamedBranchPtr> m_triggerBranches;
41  long m_lastRun;
42  unsigned long m_fills;
44  bool verifyBranchUniqueName(TTree &, std::string) const;
45 
46  template<typename T>
47  void fillColumn(NamedBranchPtr & nb, const edm::TriggerResults & triggers) {
48  nb.buffer = (nb.idx >= 0) ? triggers.accept(nb.idx) : 0;
49  nb.branch->SetAddress(&(nb.buffer)); // Can be improved: this is not reallt needed at each event
50  //but we should be sure that resize of vectors of TriggerOutputBranches do not mess up things
51  }
52 
53 };
54 
55 #endif
56 
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
bool verifyBranchUniqueName(TTree &, std::string) 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