CMS 3D CMS Logo

TriggerExpressionPathReader.cc
Go to the documentation of this file.
1 #include <cassert>
2 #include <sstream>
3 
8 
9 namespace triggerExpression {
10 
11  // define the result of the module from the HLT reults
12  bool PathReader::operator()(const Data& data) const {
13  if (not data.hasHLT() && not data.usePathStatus())
14  return false;
15 
17 
18  for (auto const& trigger : triggers)
19  if (data.passHLT(trigger.second))
20  return true;
21 
22  return false;
23  }
24 
25  void PathReader::dump(std::ostream& out, bool const ignoreMasks) const {
26  if (not m_initialised) {
27  out << "Uninitialised_Path_Expression";
28  return;
29  }
30 
31  auto const& triggers = ignoreMasks or not masksEnabled() ? m_triggers : m_triggersAfterMasking;
32 
33  if (triggers.empty()) {
34  out << "FALSE";
35  } else if (triggers.size() == 1) {
36  out << triggers[0].first;
37  } else {
38  out << "(" << triggers[0].first;
39  for (unsigned int i = 1; i < triggers.size(); ++i)
40  out << " OR " << triggers[i].first;
41  out << ")";
42  }
43  }
44 
45  // (re)initialize the module
46  void PathReader::init(const Data& data) {
47  // clear the previous configuration
48  m_triggers.clear();
49 
50  // check if the pattern has is a glob expression, or a single trigger name
51  if (not edm::is_glob(m_pattern)) {
52  // no wildcard expression
53  auto index = data.triggerIndex(m_pattern);
54  if (index >= 0)
55  m_triggers.push_back(std::make_pair(m_pattern, index));
56  else {
57  std::stringstream msg;
58  msg << "requested HLT path \"" << m_pattern << "\" does not exist - known paths are:";
59  if (data.triggerNames().empty())
60  msg << " (none)";
61  else
62  for (auto const& p : data.triggerNames())
63  msg << "\n\t" << p;
64  if (data.shouldThrow())
65  throw cms::Exception("Configuration") << msg.str();
66  else
67  edm::LogWarning("Configuration") << msg.str();
68  }
69  } else {
70  // expand wildcards in the pattern
71  const std::vector<std::vector<std::string>::const_iterator>& matches =
72  edm::regexMatch(data.triggerNames(), m_pattern);
73  if (matches.empty()) {
74  // m_pattern does not match any trigger paths
75  std::stringstream msg;
76  msg << "requested pattern \"" << m_pattern << "\" does not match any HLT paths - known paths are:";
77  if (data.triggerNames().empty())
78  msg << " (none)";
79  else
80  for (auto const& p : data.triggerNames())
81  msg << "\n\t" << p;
82  if (data.shouldThrow())
83  throw cms::Exception("Configuration") << msg.str();
84  else
85  edm::LogWarning("Configuration") << msg.str();
86  } else {
87  // store indices corresponding to the matching triggers
88  for (auto const& match : matches) {
89  auto index = data.triggerIndex(*match);
90  assert(index >= 0);
91  m_triggers.push_back(std::make_pair(*match, index));
92  }
93  }
94  }
95 
97  m_initialised = true;
98  }
99 
100  void PathReader::mask(Evaluator const& eval) {
101  auto const& triggersToMask = eval.triggers();
102 
103  if (triggersToMask.empty()) {
104  edm::LogInfo("NoTriggersToMask") << "\tPathReader[\"" << *this << "\"]::mask(arg = \"" << eval << "\")"
105  << " failed: arg.triggers() is empty";
106  return;
107  }
108 
109  // patterns() is always empty for a L1uGTReader, and not empty for PathReader;
110  // here, L1uGTReader evaluators are skipped as they shouldn't be used to mask a PathReader
111  if (eval.patterns().empty()) {
112  edm::LogWarning("InvalidArgumentForMasking")
113  << "\tPathReader[\"" << *this << "\"]::mask(arg = \"" << eval << "\")"
114  << " failed: arg.patterns() is empty (arg is not a PathReader)";
115  return;
116  }
117 
118  enableMasks();
119 
120  // clang-format off
122  std::remove_if(
123  m_triggersAfterMasking.begin(),
125  [&triggersToMask](auto const& foo) {
126  return std::find(triggersToMask.begin(), triggersToMask.end(), foo) != triggersToMask.end();
127  }
128  ),
130  );
131  // clang-format on
132  }
133 
134 } // namespace triggerExpression
virtual std::vector< std::string > patterns() const
std::vector< std::pair< std::string, unsigned int > > triggers() const override
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:17
void dump(std::ostream &out, bool const ignoreMasks=false) const override
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
assert(be >=bs)
void mask(Evaluator const &eval) override
std::vector< std::pair< std::string, unsigned int > > m_triggersAfterMasking
bool operator()(const Data &data) const override
void init(const Data &data) override
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
Log< level::Info, false > LogInfo
tuple msg
Definition: mps_check.py:286
virtual std::vector< std::pair< std::string, unsigned int > > triggers() const
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, std::regex const &regexp)
Definition: RegexMatch.cc:26
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
Log< level::Warning, false > LogWarning
std::vector< std::pair< std::string, unsigned int > > m_triggers