File indexing completed on 2024-04-06 12:11:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <vector>
0015 #include "oneapi/tbb/concurrent_unordered_map.h"
0016
0017
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 }
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
0047
0048 TriggerNamesMap::const_iterator iter = triggerNamesMap.find(triggerResults.parameterSetID());
0049 if (iter != triggerNamesMap.end()) {
0050 return &iter->second;
0051 }
0052
0053
0054
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
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
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
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 }