Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-21 02:12:15

0001 //
0002 // See header file for description
0003 //
0004 
0005 #include "CommonTools/TriggerUtils/interface/PrescaleWeightProvider.h"
0006 
0007 #include <sstream>
0008 
0009 #include "L1Trigger/GlobalTriggerAnalyzer/interface/L1GtUtils.h"
0010 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0011 #include "DataFormats/Common/interface/TriggerResults.h"
0012 #include "DataFormats/L1GlobalTrigger/interface/L1GtTriggerMenuLite.h"
0013 
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/Utilities/interface/BranchType.h"
0016 
0017 PrescaleWeightProvider::PrescaleWeightProvider(const edm::ParameterSet& config, edm::ConsumesCollector& iC)
0018     // default values
0019     : init_(false),
0020       verbosity_(0),
0021       triggerResultsTag_("TriggerResults::HLT"),
0022       triggerResultsToken_(iC.mayConsume<edm::TriggerResults>(triggerResultsTag_)),
0023       l1GtTriggerMenuLiteTag_("l1GtTriggerMenuLite"),
0024       l1GtTriggerMenuLiteToken_(iC.mayConsume<L1GtTriggerMenuLite, edm::InRun>(l1GtTriggerMenuLiteTag_)) {
0025   hltPaths_.clear();
0026   if (config.exists("prescaleWeightVerbosityLevel"))
0027     verbosity_ = config.getParameter<unsigned>("prescaleWeightVerbosityLevel");
0028   if (config.exists("prescaleWeightTriggerResults"))
0029     triggerResultsTag_ = config.getParameter<edm::InputTag>("prescaleWeightTriggerResults");
0030   if (config.exists("prescaleWeightL1GtTriggerMenuLite"))
0031     l1GtTriggerMenuLiteTag_ = config.getParameter<edm::InputTag>("prescaleWeightL1GtTriggerMenuLite");
0032   if (config.exists("prescaleWeightHltPaths"))
0033     hltPaths_ = config.getParameter<std::vector<std::string> >("prescaleWeightHltPaths");
0034 
0035   configured_ = true;
0036   if (triggerResultsTag_.process().empty()) {
0037     configured_ = false;
0038     if (verbosity_ > 0)
0039       edm::LogWarning("PrescaleWeightProvider") << "Process name not configured via TriggerResults InputTag";
0040   } else if (triggerResultsTag_.label().empty()) {
0041     configured_ = false;
0042     if (verbosity_ > 0)
0043       edm::LogWarning("PrescaleWeightProvider") << "TriggerResults label not configured";
0044   } else if (l1GtTriggerMenuLiteTag_.label().empty()) {
0045     configured_ = false;
0046     if (verbosity_ > 0)
0047       edm::LogWarning("PrescaleWeightProvider") << "L1GtTriggerMenuLite label not configured";
0048   } else if (hltPaths_.empty()) {
0049     configured_ = false;
0050     if (verbosity_ > 0)
0051       edm::LogError("PrescaleWeightProvider") << "HLT paths of interest not configured";
0052   }
0053   if (configured_) {
0054     triggerResultsToken_ = iC.mayConsume<edm::TriggerResults>(triggerResultsTag_);
0055     l1GtTriggerMenuLiteToken_ = iC.mayConsume<L1GtTriggerMenuLite, edm::InRun>(l1GtTriggerMenuLiteTag_);
0056   }
0057 }
0058 
0059 void PrescaleWeightProvider::initRun(const edm::Run& run, const edm::EventSetup& setup) {
0060   init_ = true;
0061 
0062   if (!configured_) {
0063     init_ = false;
0064     if (verbosity_ > 0)
0065       edm::LogWarning("PrescaleWeightProvider") << "Run initialisation failed due to failing configuration";
0066     return;
0067   }
0068 
0069   HLTConfigProvider const& hltConfig = hltPrescaleProvider_->hltConfigProvider();
0070   bool hltChanged(false);
0071   if (!hltPrescaleProvider_->init(run, setup, triggerResultsTag_.process(), hltChanged)) {
0072     if (verbosity_ > 0)
0073       edm::LogError("PrescaleWeightProvider")
0074           << "HLT config initialization error with process name \"" << triggerResultsTag_.process() << "\"";
0075     init_ = false;
0076   } else if (hltConfig.size() <= 0) {
0077     if (verbosity_ > 0)
0078       edm::LogError("PrescaleWeightProvider") << "HLT config size error";
0079     init_ = false;
0080   } else if (hltChanged) {
0081     if (verbosity_ > 0)
0082       edm::LogInfo("PrescaleWeightProvider") << "HLT configuration changed";
0083   }
0084   if (!init_)
0085     return;
0086 
0087   run.getByToken(l1GtTriggerMenuLiteToken_, triggerMenuLite_);
0088   if (!triggerMenuLite_.isValid()) {
0089     if (verbosity_ > 0)
0090       edm::LogError("PrescaleWeightProvider")
0091           << "L1GtTriggerMenuLite with label \"" << l1GtTriggerMenuLiteTag_.label() << "\" not found";
0092     init_ = false;
0093   }
0094 }
0095 
0096 void PrescaleWeightProvider::parseL1Seeds(const std::string& l1Seeds) {
0097   l1SeedPaths_.clear();
0098   std::stringstream ss(l1Seeds);
0099   std::string buf;
0100 
0101   while (ss.good() && !ss.eof()) {
0102     ss >> buf;
0103     if (buf[0] == '(' || buf[buf.size() - 1] == ')' || buf == "AND" || buf == "NOT") {
0104       l1SeedPaths_.clear();
0105       if (verbosity_ > 0)
0106         edm::LogWarning("PrescaleWeightProvider::parseL1Seeds") << "Only supported logical expression is OR";
0107       return;
0108     } else if (buf == "OR")
0109       continue;
0110     else
0111       l1SeedPaths_.push_back(buf);
0112   }
0113 }