CMS 3D CMS Logo

TriggerExpressionL1uGTReader.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <boost/foreach.hpp>
3 #include <regex>
4 
12 
13 namespace triggerExpression {
14 
15 // define the result of the module from the L1 reults
16 bool L1uGTReader::operator()(const Data & data) const {
17  if (not data.hasL1T())
18  return false;
19 
20  std::vector<bool> const & word = data.l1tResults();
21  if (word.empty())
22  return false;
23 
24  for (auto const & trigger: m_triggers)
25  if (trigger.second < word.size() and word[trigger.second])
26  return true;
27 
28  return false;
29 }
30 
31 void L1uGTReader::dump(std::ostream & out) const {
32  if (m_triggers.size() == 0) {
33  out << "FALSE";
34  } else if (m_triggers.size() == 1) {
35  out << m_triggers[0].first;
36  } else {
37  out << "(" << m_triggers[0].first;
38  for (unsigned int i = 1; i < m_triggers.size(); ++i)
39  out << " OR " << m_triggers[i].first;
40  out << ")";
41  }
42 }
43 
44 void L1uGTReader::init(const Data & data) {
45  if (not data.hasL1T())
46  return;
47 
48  const L1TUtmTriggerMenu & menu = data.l1tMenu();
49 
50  // clear the previous configuration
51  m_triggers.clear();
52 
53  // check if the pattern has is a glob expression, or a single trigger name
54  auto const & triggerMap = menu.getAlgorithmMap();
55  if (not edm::is_glob(m_pattern)) {
56  // no wildcard expression
57  auto entry = triggerMap.find(m_pattern);
58  if (entry != triggerMap.end()) {
59  // single L1 bit
60  m_triggers.push_back( std::make_pair(m_pattern, entry->second.getIndex()) );
61  } else
62  // trigger not found in the current menu
63  if (data.shouldThrow())
64  throw cms::Exception("Configuration") << "requested L1 trigger \"" << m_pattern << "\" does not exist in the current L1 menu";
65  else
66  edm::LogWarning("Configuration") << "requested L1 trigger \"" << m_pattern << "\" does not exist in the current L1 menu";
67  } else {
68  // expand wildcards in the pattern
69  bool match = false;
70  std::regex re(edm::glob2reg(m_pattern));
71  for (auto const & entry: triggerMap)
72  if (std::regex_match(entry.first, re)) {
73  match = true;
74  m_triggers.push_back( std::make_pair(entry.first, entry.second.getIndex()) );
75  }
76 
77  if (not match) {
78  // m_pattern does not match any L1 bits
79  if (data.shouldThrow())
80  throw cms::Exception("Configuration") << "requested pattern \"" << m_pattern << "\" does not match any L1 trigger in the current menu";
81  else
82  edm::LogWarning("Configuration") << "requested pattern \"" << m_pattern << "\" does not match any L1 trigger in the current menu";
83  }
84  }
85 
86 }
87 
88 } // namespace triggerExpression
const L1TUtmTriggerMenu & l1tMenu() const
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:18
std::string glob2reg(std::string const &pattern)
Definition: RegexMatch.cc:22
void dump(std::ostream &out) const
std::vector< std::pair< std::string, unsigned int > > m_triggers
const std::vector< bool > & l1tResults() const
bool operator()(const Data &data) const
const std::map< std::string, L1TUtmAlgorithm > & getAlgorithmMap() 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