Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-24 02:18:38

0001 // -*- C++ -*-
0002 //
0003 // Package:     FWCore/Common
0004 // Class  :     EventBase
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Thu Aug 27 11:20:06 CDT 2009
0011 //
0012 
0013 // system include files
0014 #include <vector>
0015 #include "oneapi/tbb/concurrent_unordered_map.h"
0016 
0017 // user include files
0018 #include "FWCore/Common/interface/EventBase.h"
0019 #include "FWCore/Common/interface/TriggerNames.h"
0020 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0021 #include "DataFormats/Common/interface/TriggerResults.h"
0022 #include "FWCore/Utilities/interface/Exception.h"
0023 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/ParameterSet/interface/Registry.h"
0026 
0027 namespace {
0028   struct key_hash {
0029     std::size_t operator()(edm::ParameterSetID const& iKey) const { return iKey.smallHash(); }
0030   };
0031   typedef oneapi::tbb::concurrent_unordered_map<edm::ParameterSetID, edm::TriggerNames, key_hash> TriggerNamesMap;
0032   CMS_THREAD_SAFE TriggerNamesMap triggerNamesMap;
0033 }  // namespace
0034 
0035 namespace edm {
0036 
0037   EventBase::EventBase() {}
0038 
0039   EventBase::~EventBase() {}
0040 
0041   edm::ParameterSet const* EventBase::parameterSetForID_(edm::ParameterSetID const& iPSID) {
0042     return edm::pset::Registry::instance()->getMapped(iPSID);
0043   }
0044 
0045   TriggerNames const* EventBase::triggerNames_(edm::TriggerResults const& triggerResults) {
0046     // If TriggerNames was already created and cached here in the map,
0047     // then look it up and return that one
0048     TriggerNamesMap::const_iterator iter = triggerNamesMap.find(triggerResults.parameterSetID());
0049     if (iter != triggerNamesMap.end()) {
0050       return &iter->second;
0051     }
0052 
0053     // Look for the parameter set containing the trigger names in the parameter
0054     // set registry using the ID from TriggerResults as the key used to find it.
0055     edm::pset::Registry* psetRegistry = edm::pset::Registry::instance();
0056     edm::ParameterSet const* pset = nullptr;
0057     if (nullptr != (pset = psetRegistry->getMapped(triggerResults.parameterSetID()))) {
0058       if (pset->existsAs<std::vector<std::string> >("@trigger_paths", true)) {
0059         TriggerNames triggerNames(*pset);
0060 
0061         // This should never happen
0062         if (triggerNames.size() != triggerResults.size()) {
0063           throw cms::Exception("LogicError") << "edm::EventBase::triggerNames_ Encountered vector\n"
0064                                                 "of trigger names and a TriggerResults object with\n"
0065                                                 "different sizes.  This should be impossible.\n"
0066                                                 "Please send information to reproduce this problem to\n"
0067                                                 "the edm developers.\n";
0068         }
0069 
0070         std::pair<TriggerNamesMap::iterator, bool> ret = triggerNamesMap.insert(
0071             std::pair<edm::ParameterSetID, edm::TriggerNames>(triggerResults.parameterSetID(), triggerNames));
0072         return &(ret.first->second);
0073       }
0074     }
0075     // For backward compatibility to very old data
0076     if (!triggerResults.getTriggerNames().empty()) {
0077       edm::ParameterSet fakePset;
0078       fakePset.addParameter<std::vector<std::string> >("@trigger_paths", triggerResults.getTriggerNames());
0079       fakePset.registerIt();
0080       TriggerNames triggerNames(fakePset);
0081 
0082       // This should never happen
0083       if (triggerNames.size() != triggerResults.size()) {
0084         throw cms::Exception("LogicError") << "edm::EventBase::triggerNames_ Encountered vector\n"
0085                                               "of trigger names and a TriggerResults object with\n"
0086                                               "different sizes.  This should be impossible.\n"
0087                                               "Please send information to reproduce this problem to\n"
0088                                               "the edm developers (2).\n";
0089       }
0090 
0091       std::pair<TriggerNamesMap::iterator, bool> ret =
0092           triggerNamesMap.insert(std::pair<edm::ParameterSetID, edm::TriggerNames>(fakePset.id(), triggerNames));
0093       return &(ret.first->second);
0094     }
0095     return nullptr;
0096   }
0097 }  // namespace edm