Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:43

0001 #ifndef PhysicsTools_NanoAOD_TriggerOutputBranches_h
0002 #define PhysicsTools_NanoAOD_TriggerOutputBranches_h
0003 
0004 #include <string>
0005 #include <vector>
0006 #include <TTree.h>
0007 #include "FWCore/Framework/interface/EventForOutput.h"
0008 #include "DataFormats/Common/interface/TriggerResults.h"
0009 #include "FWCore/Common/interface/TriggerNames.h"
0010 #include "DataFormats/Provenance/interface/BranchDescription.h"
0011 #include "FWCore/Utilities/interface/EDGetToken.h"
0012 
0013 class TriggerOutputBranches {
0014 public:
0015   TriggerOutputBranches(const edm::BranchDescription *desc, const edm::EDGetToken &token)
0016       : m_token(token), m_lastRun(-1), m_fills(0), m_processName(desc->processName()) {
0017     if (desc->className() != "edm::TriggerResults")
0018       throw cms::Exception("Configuration",
0019                            "NanoAODOutputModule/TriggerOutputBranches can only write out edm::TriggerResults objects");
0020   }
0021 
0022   void updateTriggerNames(TTree &tree, const edm::TriggerNames &names, const edm::TriggerResults &ta);
0023   void fill(const edm::EventForOutput &iEvent, TTree &tree);
0024   std::string processName() { return m_processName; }
0025 
0026 private:
0027   edm::TriggerNames triggerNames(
0028       const edm::TriggerResults
0029           triggerResults);  //FIXME: if we have to keep it local we may use PsetID check per event instead of run boundary
0030 
0031   edm::EDGetToken m_token;
0032   std::string m_baseName;
0033   UInt_t m_counter;
0034   struct NamedBranchPtr {
0035     std::string name, title;
0036     int idx;
0037     TBranch *branch;
0038     uint8_t buffer;
0039     NamedBranchPtr(const std::string &aname, const std::string &atitle, TBranch *branchptr = nullptr)
0040         : name(aname), title(atitle), branch(branchptr), buffer(0) {}
0041   };
0042   std::vector<NamedBranchPtr> m_triggerBranches;
0043   long m_lastRun;
0044   unsigned long m_fills;
0045   std::string m_processName;
0046   bool verifyBranchUniqueName(TTree &, std::string) const;
0047 
0048   template <typename T>
0049   void fillColumn(NamedBranchPtr &nb, const edm::TriggerResults &triggers) {
0050     nb.buffer = (nb.idx >= 0) ? triggers.accept(nb.idx) : 0;
0051     nb.branch->SetAddress(&(nb.buffer));  // Can be improved: this is not reallt needed at each event
0052         //but we should be sure that resize of vectors of TriggerOutputBranches do not mess up things
0053   }
0054 };
0055 
0056 #endif