CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/HLTrigger/HLTcore/src/TriggerExpressionHLTReader.cc

Go to the documentation of this file.
00001 #include <cassert>
00002 #include <sstream>
00003 #include <boost/foreach.hpp>
00004 
00005 #include "FWCore/Common/interface/TriggerNames.h"
00006 #include "FWCore/Utilities/interface/RegexMatch.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "DataFormats/Common/interface/TriggerResults.h"
00009 #include "HLTrigger/HLTcore/interface/TriggerExpressionHLTReader.h"
00010 #include "HLTrigger/HLTcore/interface/TriggerExpressionData.h"
00011 
00012 namespace triggerExpression {
00013 
00014 // define the result of the module from the HLT reults
00015 bool HLTReader::operator()(const Data & data) const {
00016   if (not data.hasHLT())
00017     return false;
00018 
00019   typedef std::pair<std::string, unsigned int> value_type;
00020   BOOST_FOREACH(const value_type & trigger, m_triggers)
00021     if (data.hltResults().accept(trigger.second))
00022       return true;
00023   
00024   return false;
00025 }
00026 
00027 void HLTReader::dump(std::ostream & out) const {
00028   if (m_triggers.size() == 0) {
00029     out << "FALSE";
00030   } else if (m_triggers.size() == 1) {
00031     out << m_triggers[0].first;
00032   } else {
00033     out << "(" << m_triggers[0].first;
00034     for (unsigned int i = 1; i < m_triggers.size(); ++i)
00035       out << " OR " << m_triggers[i].first;
00036     out << ")";
00037   }
00038 }
00039 
00040 // (re)initialize the module
00041 void HLTReader::init(const Data & data) {
00042   // clear the previous configuration
00043   m_triggers.clear();
00044 
00045   // check if the pattern has is a glob expression, or a single trigger name
00046   const edm::TriggerNames & hltMenu = data.hltMenu();
00047   if (not edm::is_glob(m_pattern)) {
00048     // no wildcard expression
00049     unsigned int index = hltMenu.triggerIndex(m_pattern);
00050     if (index < hltMenu.size())
00051       m_triggers.push_back( std::make_pair(m_pattern, index) );
00052     else {
00053       std::stringstream msg;
00054       msg << "requested HLT path \"" << m_pattern << "\" does not exist - known paths are:";
00055       if (hltMenu.triggerNames().empty())
00056         msg << " (none)";
00057       else
00058         BOOST_FOREACH(const std::string & p, hltMenu.triggerNames())
00059           msg << "\n\t" << p;
00060       if (data.shouldThrow())
00061         throw cms::Exception("Configuration") << msg.str();
00062       else
00063         edm::LogWarning("Configuration") << msg.str();
00064     }
00065   } else {
00066     // expand wildcards in the pattern
00067     const std::vector< std::vector<std::string>::const_iterator > & matches = edm::regexMatch(hltMenu.triggerNames(), m_pattern);
00068     if (matches.empty()) {
00069       // m_pattern does not match any trigger paths
00070       std::stringstream msg;
00071       msg << "requested pattern \"" << m_pattern <<  "\" does not match any HLT paths - known paths are:";
00072       if (hltMenu.triggerNames().empty())
00073         msg << " (none)";
00074       else
00075         BOOST_FOREACH(const std::string & p, hltMenu.triggerNames())
00076           msg << "\n\t" << p;
00077       if (data.shouldThrow())
00078         throw cms::Exception("Configuration") << msg.str();
00079       else
00080         edm::LogWarning("Configuration") << msg.str();
00081     } else {
00082       // store indices corresponding to the matching triggers
00083       BOOST_FOREACH(const std::vector<std::string>::const_iterator & match, matches) {
00084         unsigned int index = hltMenu.triggerIndex(*match);
00085         assert(index < hltMenu.size());
00086         m_triggers.push_back( std::make_pair(*match, index) );
00087       }
00088     }
00089   }
00090 }
00091 
00092 } // namespace triggerExpression