Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:36

0001 
0002 #include "FWCore/Common/interface/TriggerNames.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include <algorithm>
0005 
0006 namespace {
0007   struct PairSort {
0008     bool operator()(std::pair<std::string_view, unsigned int> const& iLHS,
0009                     std::pair<std::string_view, unsigned int> const& iRHS) const {
0010       return iLHS.first < iRHS.first;
0011     }
0012     bool operator()(std::string_view iLHS, std::pair<std::string_view, unsigned int> const& iRHS) const {
0013       return iLHS < iRHS.first;
0014     }
0015     bool operator()(std::pair<std::string_view, unsigned int> const& iLHS, std::string_view iRHS) const {
0016       return iLHS.first < iRHS;
0017     }
0018   };
0019 }  // namespace
0020 namespace edm {
0021 
0022   TriggerNames::TriggerNames(edm::ParameterSet const& pset)
0023       : psetID_{pset.id()}, triggerNames_{pset.getParameter<Strings>("@trigger_paths")} {
0024     initializeTriggerIndex();
0025   }
0026 
0027   TriggerNames::TriggerNames(TriggerNames const& iOther)
0028       : psetID_{iOther.psetID_}, triggerNames_{iOther.triggerNames_} {
0029     initializeTriggerIndex();
0030   }
0031 
0032   TriggerNames& TriggerNames::operator=(TriggerNames const& iOther) {
0033     TriggerNames temp(iOther);
0034     *this = std::move(temp);
0035     return *this;
0036   }
0037 
0038   void TriggerNames::initializeTriggerIndex() {
0039     unsigned int index = 0;
0040     indexMap_.reserve(triggerNames_.size());
0041     for (auto const& name : triggerNames_) {
0042       indexMap_.emplace_back(name, index);
0043       ++index;
0044     }
0045     std::sort(indexMap_.begin(), indexMap_.end(), PairSort());
0046   }
0047 
0048   TriggerNames::Strings const& TriggerNames::triggerNames() const { return triggerNames_; }
0049 
0050   std::string const& TriggerNames::triggerName(unsigned int index) const { return triggerNames_.at(index); }
0051 
0052   unsigned int TriggerNames::triggerIndex(std::string_view name) const {
0053     auto found = std::equal_range(indexMap_.begin(), indexMap_.end(), name, PairSort());
0054     if (found.first == found.second)
0055       return indexMap_.size();
0056     return found.first->second;
0057   }
0058 
0059   std::size_t TriggerNames::size() const { return triggerNames_.size(); }
0060 
0061   ParameterSetID const& TriggerNames::parameterSetID() const { return psetID_; }
0062 }  // namespace edm