Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:57

0001 #ifndef DataFormats_Common_SimpleEDProductGetter_h
0002 #define DataFormats_Common_SimpleEDProductGetter_h
0003 
0004 #include "DataFormats/Common/interface/EDProductGetter.h"
0005 #include "DataFormats/Common/interface/Wrapper.h"
0006 #include "FWCore/Utilities/interface/propagate_const.h"
0007 
0008 #include <map>
0009 #include <memory>
0010 
0011 class SimpleEDProductGetter : public edm::EDProductGetter {
0012 public:
0013   typedef std::map<edm::ProductID, edm::propagate_const<std::shared_ptr<edm::WrapperBase>>> map_t;
0014 
0015   template <typename T>
0016   void addProduct(edm::ProductID const& id, std::unique_ptr<T> p) {
0017     typedef edm::Wrapper<T> wrapper_t;
0018     std::shared_ptr<wrapper_t> product = std::make_shared<wrapper_t>(std::move(p));
0019     database[id] = product;
0020   }
0021 
0022   size_t size() const { return database.size(); }
0023 
0024   edm::WrapperBase const* getIt(edm::ProductID const& id) const override {
0025     map_t::const_iterator i = database.find(id);
0026     if (i == database.end()) {
0027       edm::Exception e(edm::errors::ProductNotFound, "InvalidID");
0028       e << "No product with ProductID " << id << " is available from this EDProductGetter\n";
0029       throw e;
0030     }
0031     return i->second.get();
0032   }
0033 
0034   std::optional<std::tuple<edm::WrapperBase const*, unsigned int>> getThinnedProduct(edm::ProductID const&,
0035                                                                                      unsigned int) const override {
0036     return std::nullopt;
0037   }
0038 
0039   void getThinnedProducts(edm::ProductID const& pid,
0040                           std::vector<edm::WrapperBase const*>& wrappers,
0041                           std::vector<unsigned int>& keys) const override {}
0042 
0043   edm::OptionalThinnedKey getThinnedKeyFrom(edm::ProductID const&, unsigned int, edm::ProductID const&) const override {
0044     return std::monostate{};
0045   }
0046 
0047 private:
0048   unsigned int transitionIndex_() const override { return 0U; }
0049 
0050   map_t database;
0051 };
0052 #endif