CMS 3D CMS Logo

TriggerExpressionL1uGTReader.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <regex>
3 
9 
10 namespace triggerExpression {
11 
12  // define the result of the module from the L1 reults
13  bool L1uGTReader::operator()(const Data& data) const {
14  if (not data.hasL1T())
15  return false;
16 
17  std::vector<bool> const& word = data.l1tResults();
18  if (word.empty())
19  return false;
20 
22 
23  for (auto const& trigger : triggers)
24  if (trigger.second < word.size() and word[trigger.second])
25  return true;
26 
27  return false;
28  }
29 
30  void L1uGTReader::dump(std::ostream& out, bool const ignoreMasks) const {
31  if (not m_initialised) {
32  out << "Uninitialised_L1_Expression";
33  return;
34  }
35 
36  auto const& triggers = ignoreMasks or not masksEnabled() ? m_triggers : m_triggersAfterMasking;
37 
38  if (triggers.empty()) {
39  out << "FALSE";
40  } else if (triggers.size() == 1) {
41  out << triggers[0].first;
42  } else {
43  out << "(" << triggers[0].first;
44  for (unsigned int i = 1; i < triggers.size(); ++i)
45  out << " OR " << triggers[i].first;
46  out << ")";
47  }
48  }
49 
50  void L1uGTReader::init(const Data& data) {
51  if (not data.hasL1T())
52  return;
53 
54  const L1TUtmTriggerMenu& menu = data.l1tMenu();
55 
56  // clear the previous configuration
57  m_triggers.clear();
58 
59  // check if the pattern has is a glob expression, or a single trigger name
60  auto const& triggerMap = menu.getAlgorithmMap();
61  if (not edm::is_glob(m_pattern)) {
62  // no wildcard expression
63  auto entry = triggerMap.find(m_pattern);
64  if (entry != triggerMap.end()) {
65  // single L1 bit
66  m_triggers.push_back(std::make_pair(m_pattern, entry->second.getIndex()));
67  } else {
68  // trigger not found in the current menu
69  if (data.shouldThrow())
70  throw cms::Exception("Configuration")
71  << "requested L1 trigger \"" << m_pattern << "\" does not exist in the current L1 menu";
72  else
73  edm::LogWarning("Configuration")
74  << "requested L1 trigger \"" << m_pattern << "\" does not exist in the current L1 menu";
75  }
76  } else {
77  // expand wildcards in the pattern
78  bool match = false;
79  std::regex re(edm::glob2reg(m_pattern));
80  for (auto const& entry : triggerMap)
81  if (std::regex_match(entry.first, re)) {
82  match = true;
83  m_triggers.push_back(std::make_pair(entry.first, entry.second.getIndex()));
84  }
85 
86  if (not match) {
87  // m_pattern does not match any L1 bits
88  if (data.shouldThrow())
89  throw cms::Exception("Configuration")
90  << "requested pattern \"" << m_pattern << "\" does not match any L1 trigger in the current menu";
91  else
92  edm::LogWarning("Configuration")
93  << "requested pattern \"" << m_pattern << "\" does not match any L1 trigger in the current menu";
94  }
95  }
96 
98  m_initialised = true;
99  }
100 
101  void L1uGTReader::mask(Evaluator const& eval) {
102  auto const& triggersToMask = eval.triggers();
103 
104  if (triggersToMask.empty()) {
105  edm::LogInfo("NoTriggersToMask") << "\tL1uGTReader[\"" << *this << "\"]::mask(arg = \"" << eval << "\")"
106  << " failed: arg.triggers() is empty";
107  return;
108  }
109 
110  // patterns() is always empty for a L1uGTReader, and not empty for PathReader;
111  // here, PathReader evaluators are skipped as they shouldn't be used to mask a L1uGTReader
112  if (not eval.patterns().empty()) {
113  edm::LogWarning("InvalidArgumentForMasking")
114  << "\tL1uGTReader[\"" << *this << "\"]::mask(arg = \"" << eval << "\")"
115  << " failed: arg.patterns() is not empty (arg is not a L1uGTReader)";
116  return;
117  }
118 
119  enableMasks();
120 
121  // clang-format off
123  std::remove_if(
124  m_triggersAfterMasking.begin(),
126  [&triggersToMask](auto const& foo) {
127  return std::find(triggersToMask.begin(), triggersToMask.end(), foo) != triggersToMask.end();
128  }
129  ),
131  );
132  // clang-format on
133  }
134 
135 } // namespace triggerExpression
virtual std::vector< std::string > patterns() const
void dump(std::ostream &out, bool const ignoreMasks=false) const override
bool operator()(const Data &data) const override
void mask(Evaluator const &eval) override
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:17
std::string glob2reg(std::string const &pattern)
Definition: RegexMatch.cc:19
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
uint64_t word
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
std::vector< std::pair< std::string, unsigned int > > m_triggers
std::vector< std::pair< std::string, unsigned int > > m_triggersAfterMasking
void init(const Data &data) override
Log< level::Info, false > LogInfo
virtual std::vector< std::pair< std::string, unsigned int > > triggers() const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
Log< level::Warning, false > LogWarning
std::vector< std::pair< std::string, unsigned int > > triggers() const override