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  {
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) ;
23 
24  private:
25  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
26 
30  UInt_t m_counter;
31  struct NamedBranchPtr {
33  int idx;
34  TBranch * branch;
35  uint8_t buffer;
36  NamedBranchPtr(const std::string & aname, const std::string & atitle, TBranch *branchptr = nullptr) :
37  name(aname), title(atitle), branch(branchptr), buffer(-1) {}
38  };
39  std::vector<NamedBranchPtr> m_triggerBranches;
40  long m_lastRun;
41  unsigned long m_fills;
42 
43  template<typename T>
44  void fillColumn(NamedBranchPtr & nb, const edm::TriggerResults & triggers) {
45  if(nb.idx>=0) nb.buffer=triggers.accept(nb.idx);
46  nb.branch->SetAddress(&(nb.buffer)); // Can be improved: this is not reallt needed at each event
47  //but we should be sure that resize of vectors of TriggerOutputBranches do not mess up things
48  }
49 
50 };
51 
52 #endif
53 
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