CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

HLTHighLevel Class Reference

#include <HLTHighLevel.h>

Inheritance diagram for HLTHighLevel:
edm::EDFilter edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

virtual bool filter (edm::Event &, const edm::EventSetup &)
 HLTHighLevel (const edm::ParameterSet &)
std::vector< std::string > pathsFromSetup (const std::string &key, const edm::EventSetup &iSetup) const
 get HLTPaths with key 'key' from EventSetup (AlCaRecoTriggerBitsRcd)
 ~HLTHighLevel ()

Private Member Functions

void init (const edm::TriggerResults &results, const edm::EventSetup &iSetup, const edm::TriggerNames &triggerNames)
 initialize the trigger conditions (call this if the trigger paths have changed)
std::string const & moduleLabel () const
std::string const & pathName () const
 stolen from HLTFilter

Private Attributes

bool andOr_
 false = and-mode (all requested triggers), true = or-mode (at least one)
const std::string eventSetupPathsKey_
 not empty => use read paths from AlCaRecoTriggerBitsRcd via this key
std::vector< unsigned int > HLTPathsByIndex_
 list of required HLT triggers by HLT index
std::vector< std::string > HLTPathsByName_
 list of required HLT triggers by HLT name
std::vector< std::string > HLTPatterns_
 input patterns that will be expanded into trigger names
edm::InputTag inputTag_
 HLT TriggerResults EDProduct.
bool throw_
 throw on any requested trigger being unknown
edm::ParameterSetID triggerNamesID_
 HLT trigger names.
edm::ESWatcher
< AlCaRecoTriggerBitsRcd > * 
watchAlCaRecoTriggerBitsRcd_
 Watcher to be created and used if 'eventSetupPathsKey_' non empty:

Detailed Description

This class is an HLTFilter (-> EDFilter) implementing filtering on HLT bits

Date:
2012/01/29 00:51:00
Revision:
1.10
Author:
Martin Grunewald

See header file for documentation

Date:
2012/01/29 00:51:01
Revision:
1.20
Author:
Martin Grunewald

Definition at line 40 of file HLTHighLevel.h.


Constructor & Destructor Documentation

HLTHighLevel::HLTHighLevel ( const edm::ParameterSet iConfig) [explicit]

Definition at line 36 of file HLTHighLevel.cc.

References eventSetupPathsKey_, Exception, edm::ParameterSet::getParameter(), HLTPatterns_, and watchAlCaRecoTriggerBitsRcd_.

                                                         :
  inputTag_     (iConfig.getParameter<edm::InputTag> ("TriggerResultsTag")),
  triggerNamesID_ (),
  andOr_        (iConfig.getParameter<bool> ("andOr")),
  throw_        (iConfig.getParameter<bool> ("throw")),
  eventSetupPathsKey_(iConfig.getParameter<std::string>("eventSetupPathsKey")),
  watchAlCaRecoTriggerBitsRcd_(0),
  HLTPatterns_  (iConfig.getParameter<std::vector<std::string> >("HLTPaths")),
  HLTPathsByName_(),
  HLTPathsByIndex_()
{
  // names and slot numbers are computed during the event loop, 
  // as they need to access the TriggerNames object via the TriggerResults

  if (eventSetupPathsKey_.size()) {
    // If paths come from eventsetup, we must watch for IOV changes.
    if (!HLTPatterns_.empty()) {
      // We do not want double trigger path setting, so throw!
      throw cms::Exception("Configuration")
        << " HLTHighLevel instance: "<< iConfig.getParameter<std::string>("@module_label")
        << "\n configured with " << HLTPatterns_.size() << " HLTPaths and\n"
        << " eventSetupPathsKey " << eventSetupPathsKey_ << ", choose either of them.";
    }
    watchAlCaRecoTriggerBitsRcd_ = new edm::ESWatcher<AlCaRecoTriggerBitsRcd>;
  }
}
HLTHighLevel::~HLTHighLevel ( )

Definition at line 63 of file HLTHighLevel.cc.

References watchAlCaRecoTriggerBitsRcd_.

{
  delete watchAlCaRecoTriggerBitsRcd_; // safe on null pointer...
}

Member Function Documentation

bool HLTHighLevel::filter ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDFilter.

Definition at line 187 of file HLTHighLevel.cc.

References accept(), andOr_, edm::ESWatcher< T >::check(), edm::InputTag::encode(), Exception, edm::Event::getByLabel(), HLTPathsByIndex_, HLTPathsByName_, i, init(), inputTag_, LogDebug, LogTrace, python::rootplot::argparse::message, moduleLabel(), n, pathName(), throw_, edm::Event::triggerNames(), triggerNamesID_, and watchAlCaRecoTriggerBitsRcd_.

{
  using namespace std;
  using namespace edm;

  // get hold of TriggerResults Object
  Handle<TriggerResults> trh;
  iEvent.getByLabel(inputTag_, trh);
  if (trh.isValid()) {
    LogDebug("HLTHighLevel") << "TriggerResults found, number of HLT paths: " << trh->size();
  } else {
    LogError("HLTHighLevel") << "TriggerResults product " << inputTag_.encode() << " not found - returning result=false!";
    return false;
  }

  // init the TriggerNames with the TriggerResults
  const edm::TriggerNames & triggerNames = iEvent.triggerNames(*trh);
  bool config_changed = false;
  if (triggerNamesID_ != triggerNames.parameterSetID()) {
    triggerNamesID_ = triggerNames.parameterSetID();
    config_changed = true;
  }

  // (re)run the initialization stuff if 
  // - this is the first event 
  // - or the HLT table has changed 
  // - or selected trigger bits come from AlCaRecoTriggerBitsRcd and these changed
  if (config_changed or (watchAlCaRecoTriggerBitsRcd_ and watchAlCaRecoTriggerBitsRcd_->check(iSetup))) {
    this->init(*trh, iSetup, triggerNames);  
  }
  unsigned int n     = HLTPathsByName_.size();
  unsigned int nbad  = 0;
  unsigned int fired = 0;

  // count invalid and fired triggers
  for (unsigned int i = 0; i < n; i++)
    if (HLTPathsByIndex_[i] == (unsigned int) -1)
      ++nbad;
    else if (trh->accept(HLTPathsByIndex_[i]))
      ++fired;

  if ((nbad > 0) and (config_changed or throw_)) {
    // only generate the error message if it's actually going to be used
    std::string message;

    for (unsigned int i = 0; i < n; i++)
      if (HLTPathsByIndex_[i] == (unsigned int) -1)
        message += HLTPathsByName_[i] + " ";

    if (config_changed) {
      LogTrace("HLTHighLevel")
        << " HLTHighLevel [instance: " << moduleLabel()
        << " - path: " << pathName()
        << "] configured with " << nbad
        << "/" << n
        << " unknown HLT path names: " << message;
    }

    if (throw_) {
      throw cms::Exception("Configuration")
        << " HLTHighLevel [instance: " << moduleLabel()
        << " - path: " << pathName()
        << "] configured with " << nbad
        << "/" << n
        << " unknown HLT path names: " << message;
    }
  }

  // Boolean filter result (always at least one trigger)
  const bool accept( (fired > 0) and ( andOr_ or (fired == n-nbad) ) );
  LogDebug("HLTHighLevel") << "Accept = " << std::boolalpha << accept;

  return accept;
}
void HLTHighLevel::init ( const edm::TriggerResults results,
const edm::EventSetup iSetup,
const edm::TriggerNames triggerNames 
) [private]

initialize the trigger conditions (call this if the trigger paths have changed)

Definition at line 76 of file HLTHighLevel.cc.

References andOr_, edm::InputTag::encode(), eventSetupPathsKey_, Exception, HLTPathsByIndex_, HLTPathsByName_, HLTPatterns_, i, inputTag_, edm::is_glob(), LogDebug, LogTrace, match(), n, pathsFromSetup(), listBenchmarks::pattern, edm::regexMatch(), edm::HLTGlobalStatus::size(), throw_, edm::TriggerNames::triggerIndex(), edm::TriggerNames::triggerName(), edm::TriggerNames::triggerNames(), and TrackValidation_HighPurity_cff::valid.

Referenced by filter().

{
  unsigned int n;

  // clean up old data
  HLTPathsByName_.clear();
  HLTPathsByIndex_.clear();

  // Overwrite paths from EventSetup via AlCaRecoTriggerBitsRcd if configured:
  if (eventSetupPathsKey_.size()) {
    HLTPatterns_ = this->pathsFromSetup(eventSetupPathsKey_, iSetup);
  }

  if (HLTPatterns_.empty()) {
    // for empty input vector, default to all HLT trigger paths
    n = result.size();
    HLTPathsByName_.resize(n);
    HLTPathsByIndex_.resize(n);
    for (unsigned int i = 0; i < n; ++i) {
      HLTPathsByName_[i] = triggerNames.triggerName(i);
      HLTPathsByIndex_[i] = i;
    }
  } else {
    // otherwise, expand wildcards in trigger names...
    BOOST_FOREACH(const std::string & pattern, HLTPatterns_) {
      if (edm::is_glob(pattern)) {
        // found a glob pattern, expand it
        std::vector< std::vector<std::string>::const_iterator > matches = edm::regexMatch(triggerNames.triggerNames(), pattern);
        if (matches.empty()) {
          // pattern does not match any trigger paths
          if (throw_)
            throw cms::Exception("Configuration") << "requested pattern \"" << pattern <<  "\" does not match any HLT paths";
          else
            edm::LogInfo("Configuration") << "requested pattern \"" << pattern <<  "\" does not match any HLT paths";
        } else {
          // store the matching patterns
          BOOST_FOREACH(std::vector<std::string>::const_iterator match, matches)
            HLTPathsByName_.push_back(*match);
        }
      } else {
        // found a trigger name, just copy it
        HLTPathsByName_.push_back(pattern);
      }
    }
    n = HLTPathsByName_.size();

    // ...and get hold of trigger indices
    bool valid = false;
    HLTPathsByIndex_.resize(n);
    for (unsigned int i = 0; i < HLTPathsByName_.size(); i++) {
      HLTPathsByIndex_[i] = triggerNames.triggerIndex(HLTPathsByName_[i]);
      if (HLTPathsByIndex_[i] < result.size()) {
        valid = true;
      } else {
        // trigger path not found
        HLTPathsByIndex_[i] = (unsigned int) -1;
        if (throw_)
          throw cms::Exception("Configuration") << "requested HLT path \"" << HLTPathsByName_[i] << "\" does not exist";
        else
          edm::LogInfo("Configuration") << "requested HLT path \"" << HLTPathsByName_[i] << "\" does not exist";
      }
    }
    
    if (not valid) {
      // no point in throwing - if requested, it should have already happened
      edm::LogWarning("Configuration") << "none of the requested paths and pattern match any HLT path - no events will be selected";
    }
    
  }

  // report on what is finally used
  LogDebug("HLTHighLevel") << "HLT trigger paths: " + inputTag_.encode()
    << " - Number of paths: " << n
    << " - andOr mode: " << andOr_
    << " - throw mode: " << throw_;

  LogTrace("HLTHighLevel") << "The HLT trigger paths (# index name):";
  for (unsigned int i = 0; i < n; ++i)
    if (HLTPathsByIndex_[i] == (unsigned int) -1)
      LogTrace("HLTHighLevel") << "    n/a   " << HLTPathsByName_[i];
    else
      LogTrace("HLTHighLevel") << "    " << std::setw(4) << HLTPathsByIndex_[i] << "  " << HLTPathsByName_[i];

}
std::string const & HLTHighLevel::moduleLabel ( ) const [private]
std::string const & HLTHighLevel::pathName ( ) const [private]

stolen from HLTFilter

Definition at line 263 of file HLTHighLevel.cc.

References edm::EDFilter::currentContext(), and edm::CurrentProcessingContext::pathName().

Referenced by filter(), and pathsFromSetup().

                                               {
  return * currentContext()->pathName();
}
std::vector< std::string > HLTHighLevel::pathsFromSetup ( const std::string &  key,
const edm::EventSetup iSetup 
) const

get HLTPaths with key 'key' from EventSetup (AlCaRecoTriggerBitsRcd)

Definition at line 165 of file HLTHighLevel.cc.

References Exception, edm::EventSetup::get(), moduleLabel(), and pathName().

Referenced by init().

{
  // Get map of strings to concatenated list of names of HLT paths from EventSetup:
  edm::ESHandle<AlCaRecoTriggerBits> triggerBits;
  iSetup.get<AlCaRecoTriggerBitsRcd>().get(triggerBits);
  typedef std::map<std::string, std::string> TriggerMap;
  const TriggerMap &triggerMap = triggerBits->m_alcarecoToTrig;

  TriggerMap::const_iterator listIter = triggerMap.find(key);
  if (listIter == triggerMap.end()) {
    throw cms::Exception("Configuration")
      << " HLTHighLevel [instance: " << moduleLabel() << " - path: " << pathName()
      << "]: No triggerList with key " << key << " in AlCaRecoTriggerBitsRcd";
  }

  // We must avoid a map<string,vector<string> > in DB for performance reason,
  // so the paths are mapped into one string that we have to decompose:
  return triggerBits->decompose(listIter->second);
}

Member Data Documentation

bool HLTHighLevel::andOr_ [private]

false = and-mode (all requested triggers), true = or-mode (at least one)

Definition at line 64 of file HLTHighLevel.h.

Referenced by filter(), and init().

const std::string HLTHighLevel::eventSetupPathsKey_ [private]

not empty => use read paths from AlCaRecoTriggerBitsRcd via this key

Definition at line 74 of file HLTHighLevel.h.

Referenced by HLTHighLevel(), and init().

std::vector<unsigned int> HLTHighLevel::HLTPathsByIndex_ [private]

list of required HLT triggers by HLT index

Definition at line 85 of file HLTHighLevel.h.

Referenced by filter(), and init().

std::vector<std::string> HLTHighLevel::HLTPathsByName_ [private]

list of required HLT triggers by HLT name

Definition at line 82 of file HLTHighLevel.h.

Referenced by filter(), and init().

std::vector<std::string> HLTHighLevel::HLTPatterns_ [private]

input patterns that will be expanded into trigger names

Definition at line 79 of file HLTHighLevel.h.

Referenced by HLTHighLevel(), and init().

HLT TriggerResults EDProduct.

Definition at line 58 of file HLTHighLevel.h.

Referenced by filter(), and init().

bool HLTHighLevel::throw_ [private]

throw on any requested trigger being unknown

Definition at line 67 of file HLTHighLevel.h.

Referenced by filter(), and init().

HLT trigger names.

Definition at line 61 of file HLTHighLevel.h.

Referenced by filter().

Watcher to be created and used if 'eventSetupPathsKey_' non empty:

Definition at line 76 of file HLTHighLevel.h.

Referenced by filter(), HLTHighLevel(), and ~HLTHighLevel().