Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:26

0001 #include <cassert>
0002 #include <sstream>
0003 
0004 #include "FWCore/Utilities/interface/RegexMatch.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "HLTrigger/HLTcore/interface/TriggerExpressionData.h"
0007 #include "HLTrigger/HLTcore/interface/TriggerExpressionPathReader.h"
0008 
0009 namespace triggerExpression {
0010 
0011   // define the result of the module from the HLT reults
0012   bool PathReader::operator()(const Data& data) const {
0013     if (not data.hasHLT() && not data.usePathStatus())
0014       return false;
0015 
0016     auto const& triggers = masksEnabled() ? m_triggersAfterMasking : m_triggers;
0017 
0018     for (auto const& trigger : triggers)
0019       if (data.passHLT(trigger.second))
0020         return true;
0021 
0022     return false;
0023   }
0024 
0025   void PathReader::dump(std::ostream& out, bool const ignoreMasks) const {
0026     if (not m_initialised) {
0027       out << "Uninitialised_Path_Expression";
0028       return;
0029     }
0030 
0031     auto const& triggers = ignoreMasks or not masksEnabled() ? m_triggers : m_triggersAfterMasking;
0032 
0033     if (triggers.empty()) {
0034       out << "FALSE";
0035     } else if (triggers.size() == 1) {
0036       out << triggers[0].first;
0037     } else {
0038       out << "(" << triggers[0].first;
0039       for (unsigned int i = 1; i < triggers.size(); ++i)
0040         out << " OR " << triggers[i].first;
0041       out << ")";
0042     }
0043   }
0044 
0045   // (re)initialize the module
0046   void PathReader::init(const Data& data) {
0047     // clear the previous configuration
0048     m_triggers.clear();
0049 
0050     // check if the pattern has is a glob expression, or a single trigger name
0051     if (not edm::is_glob(m_pattern)) {
0052       // no wildcard expression
0053       auto index = data.triggerIndex(m_pattern);
0054       if (index >= 0)
0055         m_triggers.push_back(std::make_pair(m_pattern, index));
0056       else {
0057         std::stringstream msg;
0058         msg << "requested HLT path \"" << m_pattern << "\" does not exist - known paths are:";
0059         if (data.triggerNames().empty())
0060           msg << " (none)";
0061         else
0062           for (auto const& p : data.triggerNames())
0063             msg << "\n\t" << p;
0064         if (data.shouldThrow())
0065           throw cms::Exception("Configuration") << msg.str();
0066         else
0067           edm::LogWarning("Configuration") << msg.str();
0068       }
0069     } else {
0070       // expand wildcards in the pattern
0071       const std::vector<std::vector<std::string>::const_iterator>& matches =
0072           edm::regexMatch(data.triggerNames(), m_pattern);
0073       if (matches.empty()) {
0074         // m_pattern does not match any trigger paths
0075         std::stringstream msg;
0076         msg << "requested pattern \"" << m_pattern << "\" does not match any HLT paths - known paths are:";
0077         if (data.triggerNames().empty())
0078           msg << " (none)";
0079         else
0080           for (auto const& p : data.triggerNames())
0081             msg << "\n\t" << p;
0082         if (data.shouldThrow())
0083           throw cms::Exception("Configuration") << msg.str();
0084         else
0085           edm::LogWarning("Configuration") << msg.str();
0086       } else {
0087         // store indices corresponding to the matching triggers
0088         for (auto const& match : matches) {
0089           auto index = data.triggerIndex(*match);
0090           assert(index >= 0);
0091           m_triggers.push_back(std::make_pair(*match, index));
0092         }
0093       }
0094     }
0095 
0096     m_triggersAfterMasking = m_triggers;
0097     m_initialised = true;
0098   }
0099 
0100   void PathReader::mask(Evaluator const& eval) {
0101     auto const& triggersToMask = eval.triggers();
0102 
0103     if (triggersToMask.empty()) {
0104       edm::LogInfo("NoTriggersToMask") << "\tPathReader[\"" << *this << "\"]::mask(arg = \"" << eval << "\")"
0105                                        << " failed: arg.triggers() is empty";
0106       return;
0107     }
0108 
0109     // patterns() is always empty for a L1uGTReader, and not empty for PathReader;
0110     // here, L1uGTReader evaluators are skipped as they shouldn't be used to mask a PathReader
0111     if (eval.patterns().empty()) {
0112       edm::LogWarning("InvalidArgumentForMasking")
0113           << "\tPathReader[\"" << *this << "\"]::mask(arg = \"" << eval << "\")"
0114           << " failed: arg.patterns() is empty (arg is not a PathReader)";
0115       return;
0116     }
0117 
0118     enableMasks();
0119 
0120     // clang-format off
0121     m_triggersAfterMasking.erase(
0122       std::remove_if(
0123         m_triggersAfterMasking.begin(),
0124         m_triggersAfterMasking.end(),
0125         [&triggersToMask](auto const& foo) {
0126           return std::find(triggersToMask.begin(), triggersToMask.end(), foo) != triggersToMask.end();
0127         }
0128       ),
0129       m_triggersAfterMasking.end()
0130     );
0131     // clang-format on
0132   }
0133 
0134 }  // namespace triggerExpression