Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-08 23:05:17

0001 #ifndef HLTrigger_HLTcore_TriggerExpressionData_h
0002 #define HLTrigger_HLTcore_TriggerExpressionData_h
0003 
0004 #include "FWCore/Framework/interface/ConsumesCollector.h"
0005 #include "FWCore/Utilities/interface/InputTag.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/Common/interface/TriggerNames.h"
0008 #include "CondFormats/DataRecord/interface/L1TUtmTriggerMenuRcd.h"
0009 #include "CondFormats/L1TObjects/interface/L1TUtmTriggerMenu.h"
0010 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0011 #include "DataFormats/Provenance/interface/EventID.h"
0012 #include "DataFormats/Common/interface/TriggerResults.h"
0013 #include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
0014 
0015 namespace edm {
0016   class Event;
0017   class EventSetup;
0018   class TriggerNames;
0019 }  // namespace edm
0020 
0021 namespace triggerExpression {
0022 
0023   class Data {
0024   public:
0025     // default c'tor
0026     Data()
0027         :  // configuration
0028           m_usePathStatus(false),
0029           m_pathStatusTokens(),
0030           m_hltResultsTag(""),
0031           m_hltResultsToken(),
0032           m_l1tResultsTag(""),
0033           m_l1tResultsToken(),
0034           m_l1tUtmTriggerMenuToken(),
0035           m_l1tIgnoreMaskAndPrescale(false),
0036           m_throw(true),
0037           // l1 values and status
0038           m_l1tResults(nullptr),
0039           m_l1tMenu(nullptr),
0040           m_l1tCacheID(),
0041           m_l1tUpdated(false),
0042           // hlt values and status
0043           m_pathStatus(),
0044           m_triggerNames(),
0045           m_hltResults(nullptr),
0046           m_hltMenu(nullptr),
0047           m_hltCacheID(),
0048           m_hltUpdated(false),
0049           // event values
0050           m_eventNumber() {}
0051 
0052     // explicit c'tor from a ParameterSet
0053     explicit Data(const edm::ParameterSet& config, edm::ConsumesCollector&& iC)
0054         :  // configuration
0055           m_usePathStatus(config.getParameter<bool>("usePathStatus")),
0056           m_pathStatusTokens(),
0057           m_hltResultsTag(config.getParameter<edm::InputTag>("hltResults")),
0058           m_hltResultsToken(),
0059           m_l1tResultsTag(config.getParameter<edm::InputTag>("l1tResults")),
0060           m_l1tResultsToken(),
0061           m_l1tUtmTriggerMenuToken(iC.esConsumes()),
0062           m_l1tIgnoreMaskAndPrescale(config.getParameter<bool>("l1tIgnoreMaskAndPrescale")),
0063           m_throw(config.getParameter<bool>("throw")),
0064           // l1 values and status
0065           m_l1tResults(nullptr),
0066           m_l1tMenu(nullptr),
0067           m_l1tCacheID(),
0068           m_l1tUpdated(false),
0069           // hlt values and status
0070           m_pathStatus(),
0071           m_triggerNames(),
0072           m_hltResults(nullptr),
0073           m_hltMenu(nullptr),
0074           m_hltCacheID(),
0075           m_hltUpdated(false),
0076           // event values
0077           m_eventNumber() {
0078       if (not m_hltResultsTag.label().empty() and not m_usePathStatus)
0079         m_hltResultsToken = iC.consumes<edm::TriggerResults>(m_hltResultsTag);
0080       if (not m_l1tResultsTag.label().empty())
0081         m_l1tResultsToken = iC.consumes<GlobalAlgBlkBxCollection>(m_l1tResultsTag);
0082     }
0083 
0084     // explicit c'tor from single arguments
0085     Data(bool const& usePathStatus,
0086          edm::InputTag const& hltResultsTag,
0087          edm::InputTag const& l1tResultsTag,
0088          bool l1tIgnoreMaskAndPrescale,
0089          bool doThrow,
0090          edm::ConsumesCollector&& iC)
0091         :  // configuration
0092           m_usePathStatus(usePathStatus),
0093           m_pathStatusTokens(),
0094           m_hltResultsTag(hltResultsTag),
0095           m_hltResultsToken(),
0096           m_l1tResultsTag(l1tResultsTag),
0097           m_l1tResultsToken(),
0098           m_l1tUtmTriggerMenuToken(iC.esConsumes()),
0099           m_l1tIgnoreMaskAndPrescale(l1tIgnoreMaskAndPrescale),
0100           m_throw(doThrow),
0101           // l1 values and status
0102           m_l1tResults(nullptr),
0103           m_l1tMenu(nullptr),
0104           m_l1tCacheID(),
0105           m_l1tUpdated(false),
0106           // hlt values and status
0107           m_pathStatus(),
0108           m_triggerNames(),
0109           m_hltResults(nullptr),
0110           m_hltMenu(nullptr),
0111           m_hltCacheID(),
0112           m_hltUpdated(false),
0113           // event values
0114           m_eventNumber() {
0115       if (not m_hltResultsTag.label().empty() and not m_usePathStatus)
0116         m_hltResultsToken = iC.consumes<edm::TriggerResults>(m_hltResultsTag);
0117       if (not m_l1tResultsTag.label().empty())
0118         m_l1tResultsToken = iC.consumes<GlobalAlgBlkBxCollection>(m_l1tResultsTag);
0119     }
0120 
0121     // set path status token
0122     void setPathStatusToken(edm::BranchDescription const& branch, edm::ConsumesCollector&& iC);
0123 
0124     // set the new event
0125     bool setEvent(const edm::Event& event, const edm::EventSetup& setup);
0126 
0127     // re-configuration accessors
0128 
0129     void setHltResultsTag(edm::InputTag const& tag) { m_hltResultsTag = tag; }
0130 
0131     void setL1tResultsTag(edm::InputTag const& tag) { m_l1tResultsTag = tag; }
0132 
0133     void setL1tIgnoreMaskAndPrescale(bool l1tIgnoreMaskAndPrescale) {
0134       m_l1tIgnoreMaskAndPrescale = l1tIgnoreMaskAndPrescale;
0135     }
0136 
0137     void setThrow(bool doThrow) { m_throw = doThrow; }
0138 
0139     // read-only accessors
0140 
0141     bool usePathStatus() const { return m_usePathStatus; }
0142 
0143     bool hasL1T() const { return not m_l1tResultsTag.label().empty(); }
0144 
0145     bool hasHLT() const { return not m_hltResultsTag.label().empty(); }
0146 
0147     const edm::TriggerResults& hltResults() const { return *m_hltResults; }
0148 
0149     const edm::TriggerNames& hltMenu() const { return *m_hltMenu; }
0150 
0151     const std::vector<bool>& l1tResults() const { return *m_l1tResults; }
0152 
0153     const L1TUtmTriggerMenu& l1tMenu() const { return *m_l1tMenu; }
0154 
0155     bool hltConfigurationUpdated() const { return m_hltUpdated; }
0156 
0157     bool l1tConfigurationUpdated() const { return m_l1tUpdated; }
0158 
0159     bool configurationUpdated() const { return m_hltUpdated or m_l1tUpdated; }
0160 
0161     edm::EventNumber_t eventNumber() const { return m_eventNumber; }
0162 
0163     bool shouldThrow() const { return m_throw; }
0164 
0165     bool ignoreL1MaskAndPrescale() const { return m_l1tIgnoreMaskAndPrescale; }
0166 
0167     const std::vector<std::string>& triggerNames() const {
0168       if (m_hltMenu)
0169         return m_hltMenu->triggerNames();
0170       return m_triggerNames;
0171     }
0172 
0173     bool passHLT(unsigned int const& index) const {
0174       if (usePathStatus())
0175         return m_pathStatus[index];
0176       return m_hltResults && m_hltResults->accept(index);
0177     }
0178 
0179     int triggerIndex(std::string const& p) const {
0180       if (usePathStatus()) {
0181         auto it = std::find(m_triggerNames.begin(), m_triggerNames.end(), p);
0182         if (it != m_triggerNames.end())
0183           return it - m_triggerNames.begin();
0184       } else if (m_hltMenu) {
0185         auto index = m_hltMenu->triggerIndex(p);
0186         if (index < m_hltMenu->size())
0187           return index;
0188       }
0189       return -1;
0190     }
0191 
0192     // configuration
0193     bool m_usePathStatus;
0194     std::map<std::string, edm::EDGetTokenT<edm::HLTPathStatus> > m_pathStatusTokens;
0195     edm::InputTag m_hltResultsTag;
0196     edm::EDGetTokenT<edm::TriggerResults> m_hltResultsToken;
0197     edm::InputTag m_l1tResultsTag;
0198     edm::EDGetTokenT<GlobalAlgBlkBxCollection> m_l1tResultsToken;
0199     edm::ESGetToken<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd> const m_l1tUtmTriggerMenuToken;
0200     bool m_l1tIgnoreMaskAndPrescale;
0201     bool m_throw;
0202 
0203     // l1 values and status
0204     const std::vector<bool>* m_l1tResults;
0205     const L1TUtmTriggerMenu* m_l1tMenu;
0206     unsigned long long m_l1tCacheID;
0207     bool m_l1tUpdated;
0208 
0209     // hlt values and status
0210     std::vector<bool> m_pathStatus;
0211     std::vector<std::string> m_triggerNames;
0212     const edm::TriggerResults* m_hltResults;
0213     const edm::TriggerNames* m_hltMenu;
0214     edm::ParameterSetID m_hltCacheID;
0215     bool m_hltUpdated;
0216 
0217     // event values
0218     edm::EventNumber_t m_eventNumber;
0219   };
0220 
0221 }  // namespace triggerExpression
0222 
0223 #endif  // HLTrigger_HLTcore_TriggerExpressionData_h