Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:44

0001 #include <iostream>
0002 #include <regex>
0003 
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "FWCore/Utilities/interface/RegexMatch.h"
0006 #include "CondFormats/L1TObjects/interface/L1GtTriggerMask.h"
0007 #include "CondFormats/L1TObjects/interface/L1TUtmTriggerMenu.h"
0008 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0009 #include "HLTrigger/HLTcore/interface/TriggerExpressionData.h"
0010 #include "HLTrigger/HLTcore/interface/TriggerExpressionL1uGTReader.h"
0011 
0012 namespace triggerExpression {
0013 
0014   // define the result of the module from the L1 reults
0015   bool L1uGTReader::operator()(const Data& data) const {
0016     if (not data.hasL1T())
0017       return false;
0018 
0019     std::vector<bool> const& word = data.l1tResults();
0020     if (word.empty())
0021       return false;
0022 
0023     for (auto const& trigger : m_triggers)
0024       if (trigger.second < word.size() and word[trigger.second])
0025         return true;
0026 
0027     return false;
0028   }
0029 
0030   void L1uGTReader::dump(std::ostream& out) const {
0031     if (m_triggers.empty()) {
0032       out << "FALSE";
0033     } else if (m_triggers.size() == 1) {
0034       out << m_triggers[0].first;
0035     } else {
0036       out << "(" << m_triggers[0].first;
0037       for (unsigned int i = 1; i < m_triggers.size(); ++i)
0038         out << " OR " << m_triggers[i].first;
0039       out << ")";
0040     }
0041   }
0042 
0043   void L1uGTReader::init(const Data& data) {
0044     if (not data.hasL1T())
0045       return;
0046 
0047     const L1TUtmTriggerMenu& menu = data.l1tMenu();
0048 
0049     // clear the previous configuration
0050     m_triggers.clear();
0051 
0052     // check if the pattern has is a glob expression, or a single trigger name
0053     auto const& triggerMap = menu.getAlgorithmMap();
0054     if (not edm::is_glob(m_pattern)) {
0055       // no wildcard expression
0056       auto entry = triggerMap.find(m_pattern);
0057       if (entry != triggerMap.end()) {
0058         // single L1 bit
0059         m_triggers.push_back(std::make_pair(m_pattern, entry->second.getIndex()));
0060       } else
0061           // trigger not found in the current menu
0062           if (data.shouldThrow())
0063         throw cms::Exception("Configuration")
0064             << "requested L1 trigger \"" << m_pattern << "\" does not exist in the current L1 menu";
0065       else
0066         edm::LogWarning("Configuration") << "requested L1 trigger \"" << m_pattern
0067                                          << "\" does not exist in the current L1 menu";
0068     } else {
0069       // expand wildcards in the pattern
0070       bool match = false;
0071       std::regex re(edm::glob2reg(m_pattern));
0072       for (auto const& entry : triggerMap)
0073         if (std::regex_match(entry.first, re)) {
0074           match = true;
0075           m_triggers.push_back(std::make_pair(entry.first, entry.second.getIndex()));
0076         }
0077 
0078       if (not match) {
0079         // m_pattern does not match any L1 bits
0080         if (data.shouldThrow())
0081           throw cms::Exception("Configuration")
0082               << "requested pattern \"" << m_pattern << "\" does not match any L1 trigger in the current menu";
0083         else
0084           edm::LogWarning("Configuration")
0085               << "requested pattern \"" << m_pattern << "\" does not match any L1 trigger in the current menu";
0086       }
0087     }
0088   }
0089 
0090 }  // namespace triggerExpression