File indexing completed on 2025-05-23 02:04:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <atomic>
0015
0016
0017 #include "DataFormats/Common/interface/EDProductGetter.h"
0018 #include "DataFormats/Provenance/interface/ProductID.h"
0019 #include "FWCore/Utilities/interface/EDMException.h"
0020 #include "FWCore/Utilities/interface/Likely.h"
0021
0022 namespace edm {
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 EDProductGetter::EDProductGetter() {}
0035
0036
0037
0038
0039
0040
0041 EDProductGetter::~EDProductGetter() {}
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 EDProductGetter const* mustBeNonZero(EDProductGetter const* prodGetter,
0068 std::string refType,
0069 ProductID const& productID) {
0070 if (prodGetter != nullptr)
0071 return prodGetter;
0072 throw Exception(errors::InvalidReference, refType)
0073 << "Attempt to construct a " << refType << " with ProductID " << productID << "\n"
0074 << "but with a null pointer to a product getter.\n"
0075 << "The product getter pointer passed to the constructor must refer\n"
0076 << "to a real getter, such as an EventPrincipal.\n";
0077 }
0078
0079 thread_local EDProductGetter const* s_productGetter = nullptr;
0080 static std::atomic<EDProductGetter const*> s_multiThreadProductGetter{nullptr};
0081 EDProductGetter const* EDProductGetter::switchProductGetter(EDProductGetter const* iNew) {
0082
0083 EDProductGetter const* old = s_productGetter;
0084 s_productGetter = iNew;
0085 return old;
0086 }
0087
0088 void EDProductGetter::setMultiThreadProductGetter(EDProductGetter const* prodGetter) {
0089 EDProductGetter const* expected = nullptr;
0090 while (not s_multiThreadProductGetter.compare_exchange_strong(expected, prodGetter, std::memory_order_acq_rel)) {
0091 expected = nullptr;
0092 };
0093 }
0094
0095 void EDProductGetter::unsetMultiThreadProductGetter() {
0096 s_multiThreadProductGetter.store(nullptr, std::memory_order_release);
0097 }
0098
0099 void EDProductGetter::assignEDProductGetter(EDProductGetter const*& iGetter) {
0100
0101 if LIKELY (s_productGetter != nullptr) {
0102 iGetter = s_productGetter;
0103 return;
0104 }
0105 iGetter = s_multiThreadProductGetter.load(std::memory_order_acquire);
0106 }
0107
0108 }