CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TriggerExpressionPathReader.cc
Go to the documentation of this file.
1 #include <cassert>
2 #include <sstream>
3 #include <boost/foreach.hpp>
4 
11 
12 namespace triggerExpression {
13 
14 // define the result of the module from the HLT reults
15 bool PathReader::operator()(const Data & data) const {
16  if (not data.hasHLT())
17  return false;
18 
19  typedef std::pair<std::string, unsigned int> value_type;
20  BOOST_FOREACH(const value_type & trigger, m_triggers)
21  if (data.hltResults().accept(trigger.second))
22  return true;
23 
24  return false;
25 }
26 
27 void PathReader::dump(std::ostream & out) const {
28  if (m_triggers.size() == 0) {
29  out << "FALSE";
30  } else if (m_triggers.size() == 1) {
31  out << m_triggers[0].first;
32  } else {
33  out << "(" << m_triggers[0].first;
34  for (unsigned int i = 1; i < m_triggers.size(); ++i)
35  out << " OR " << m_triggers[i].first;
36  out << ")";
37  }
38 }
39 
40 // (re)initialize the module
41 void PathReader::init(const Data & data) {
42  // clear the previous configuration
43  m_triggers.clear();
44 
45  // check if the pattern has is a glob expression, or a single trigger name
46  const edm::TriggerNames & hltMenu = data.hltMenu();
47  if (not edm::is_glob(m_pattern)) {
48  // no wildcard expression
49  unsigned int index = hltMenu.triggerIndex(m_pattern);
50  if (index < hltMenu.size())
51  m_triggers.push_back( std::make_pair(m_pattern, index) );
52  else {
53  std::stringstream msg;
54  msg << "requested HLT path \"" << m_pattern << "\" does not exist - known paths are:";
55  if (hltMenu.triggerNames().empty())
56  msg << " (none)";
57  else
58  BOOST_FOREACH(const std::string & p, hltMenu.triggerNames())
59  msg << "\n\t" << p;
60  if (data.shouldThrow())
61  throw cms::Exception("Configuration") << msg.str();
62  else
63  edm::LogWarning("Configuration") << msg.str();
64  }
65  } else {
66  // expand wildcards in the pattern
67  const std::vector< std::vector<std::string>::const_iterator > & matches = edm::regexMatch(hltMenu.triggerNames(), m_pattern);
68  if (matches.empty()) {
69  // m_pattern does not match any trigger paths
70  std::stringstream msg;
71  msg << "requested pattern \"" << m_pattern << "\" does not match any HLT paths - known paths are:";
72  if (hltMenu.triggerNames().empty())
73  msg << " (none)";
74  else
75  BOOST_FOREACH(const std::string & p, hltMenu.triggerNames())
76  msg << "\n\t" << p;
77  if (data.shouldThrow())
78  throw cms::Exception("Configuration") << msg.str();
79  else
80  edm::LogWarning("Configuration") << msg.str();
81  } else {
82  // store indices corresponding to the matching triggers
83  BOOST_FOREACH(const std::vector<std::string>::const_iterator & match, matches) {
84  unsigned int index = hltMenu.triggerIndex(*match);
85  assert(index < hltMenu.size());
86  m_triggers.push_back( std::make_pair(*match, index) );
87  }
88  }
89  }
90 }
91 
92 } // namespace triggerExpression
int i
Definition: DBlmapReader.cc:9
bool accept() const
Has at least one path accepted the event?
assert(m_qm.get())
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:18
const edm::TriggerNames & hltMenu() const
Strings::size_type size() const
Definition: TriggerNames.cc:39
Strings const & triggerNames() const
Definition: TriggerNames.cc:24
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:32
bool operator()(const Data &data) const
const edm::TriggerResults & hltResults() const
Container::value_type value_type
tuple out
Definition: dbtoconf.py:99
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, std::regex const &regexp)
Definition: RegexMatch.cc:30
void dump(std::ostream &out) const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
std::vector< std::pair< std::string, unsigned int > > m_triggers