CMS 3D CMS Logo

TriggerNames.cc

Go to the documentation of this file.
00001 
00002 // $Id: TriggerNames.cc,v 1.1 2007/06/15 18:41:47 wdd Exp $
00003 
00004 #include "FWCore/Framework/interface/TriggerNames.h"
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "FWCore/Framework/interface/TriggerNamesService.h"
00007 #include "DataFormats/Common/interface/TriggerResults.h"
00008 
00009 namespace edm {
00010 
00011   TriggerNames::TriggerNames() : psetID_valid_(false) { }
00012                                                                                
00013   TriggerNames::TriggerNames(TriggerResults const& triggerResults) :
00014       psetID_valid_(false)
00015   {
00016     init(triggerResults);
00017   }
00018 
00019   bool
00020   TriggerNames::init(TriggerResults const& triggerResults) {
00021 
00022     if ( psetID_valid_ && psetID_ == triggerResults.parameterSetID()) {
00023       return false;
00024     }
00025     edm::Service<edm::service::TriggerNamesService> tns;
00026     bool fromPSetRegistry;
00027     if (tns->getTrigPaths(triggerResults, triggerNames_, fromPSetRegistry)) {
00028 
00029       if (fromPSetRegistry) {
00030         psetID_ = triggerResults.parameterSetID();
00031         psetID_valid_ = true;
00032       }
00033       // Allows backward compatibility to old TriggerResults objects
00034       // which contain the names.
00035       else {
00036         psetID_valid_ = false;
00037       }
00038     }
00039     // This should never happen
00040     else {
00041       throw edm::Exception(edm::errors::Unknown)
00042         << "TriggerNames::init cannot find the trigger names for\n"
00043            "a TriggerResults object.  This should be impossible,\n"
00044            "please send information to reproduce this problem to\n"
00045            "the edm developers.  (Actually if you started with a\n"
00046            "Streamer file and the release used to read the streamer\n"
00047            "is older than the release used to create it, this may\n"
00048            "occur, but that is not supported and you should not do that)\n"; 
00049     }
00050 
00051     unsigned int index = 0;
00052     for (Strings::const_iterator iName = triggerNames_.begin(), 
00053          iEnd = triggerNames_.end();
00054          iName != iEnd;
00055          ++iName, ++index) {
00056       indexMap_[*iName] = index;
00057     }
00058     return true;
00059   }
00060 
00061   TriggerNames::Strings const&
00062   TriggerNames::triggerNames() const { return triggerNames_; }
00063 
00064   std::string const&
00065   TriggerNames::triggerName(unsigned int index) const {
00066     return triggerNames_.at(index);
00067   }
00068 
00069   unsigned int
00070   TriggerNames::triggerIndex(const std::string& name) const {
00071     IndexMap::const_iterator const pos = indexMap_.find(name);
00072     if (pos == indexMap_.end()) return indexMap_.size();
00073     return pos->second;
00074   }
00075 
00076   TriggerNames::Strings::size_type
00077   TriggerNames::size() const { return triggerNames_.size(); }
00078 }

Generated on Tue Jun 9 17:36:12 2009 for CMSSW by  doxygen 1.5.4