CMS 3D CMS Logo

EDProductGetter.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_EDProductGetter_h
2 #define DataFormats_Common_EDProductGetter_h
3 // -*- C++ -*-
4 //
5 // Class : EDProductGetter
6 //
14 //
15 // Original Author: Chris Jones
16 // Created: Tue Nov 1 15:06:31 EST 2005
17 //
18 
19 // user include files
20 
21 // system include files
22 #include <functional>
23 #include <optional>
24 #include <string>
25 #include <tuple>
26 #include <variant>
27 #include <vector>
28 
29 // forward declarations
30 
31 namespace edm {
32 
33  class Exception;
34  class ProductID;
35  class WrapperBase;
36  namespace detail {
37  using GetThinnedKeyFromExceptionFactory = std::function<edm::Exception()>;
38  }
39  using OptionalThinnedKey = std::variant<unsigned int, detail::GetThinnedKeyFromExceptionFactory, std::monostate>;
40 
42  public:
44  virtual ~EDProductGetter();
45 
46  EDProductGetter(EDProductGetter const&) = delete; // stop default
47 
48  EDProductGetter const& operator=(EDProductGetter const&) = delete; // stop default
49 
50  // ---------- const member functions ---------------------
51  virtual WrapperBase const* getIt(ProductID const&) const = 0;
52 
53  // getThinnedProduct assumes getIt was already called and failed to find
54  // the product. The input key is the index of the desired element in the
55  // container identified by ProductID (which cannot be found).
56  // If the return value is not null, then the desired element was
57  // found in a thinned container. If the desired element is not
58  // found, then an optional without a value is returned.
59  virtual std::optional<std::tuple<WrapperBase const*, unsigned int>> getThinnedProduct(ProductID const&,
60  unsigned int key) const = 0;
61 
62  // getThinnedProducts assumes getIt was already called and failed to find
63  // the product. The input keys are the indexes into the container identified
64  // by ProductID (which cannot be found). On input the WrapperBase pointers
65  // must all be set to nullptr (except when the function calls itself
66  // recursively where non-null pointers mark already found elements).
67  // Thinned containers derived from the product are searched to see
68  // if they contain the desired elements. For each that is
69  // found, the corresponding WrapperBase pointer is set and the key
70  // is modified to be the key into the container where the element
71  // was found. The WrapperBase pointers might or might not all point
72  // to the same thinned container.
73  virtual void getThinnedProducts(ProductID const& pid,
74  std::vector<WrapperBase const*>& foundContainers,
75  std::vector<unsigned int>& keys) const = 0;
76 
77  // This overload is allowed to be called also without getIt()
78  // being called first, but the thinned ProductID must come from an
79  // existing RefCore. The input key is the index of the desired
80  // element in the container identified by the parent ProductID.
81  // Returns an std::variant whose contents can be
82  // - unsigned int for the index in the thinned collection if the
83  // desired element was found in the thinned collection
84  // - function creating an edm::Exception if parent is not a parent
85  // of any thinned collection, thinned is not really a thinned
86  // collection, or parent and thinned have no thinning
87  // relationship
88  // - std::monostate if thinned is thinned from parent, but the key
89  // is not found in the thinned collection
91  unsigned int key,
92  ProductID const& thinned) const = 0;
93 
94  unsigned int transitionIndex() const { return transitionIndex_(); }
95 
96  // ---------- member functions ---------------------------
97 
100  static void assignEDProductGetter(EDProductGetter const*&);
101 
102  private:
103  virtual unsigned int transitionIndex_() const = 0;
104 
105  // ---------- member data --------------------------------
106  };
107 
108  EDProductGetter const* mustBeNonZero(EDProductGetter const* prodGetter,
109  std::string refType,
110  ProductID const& productID);
111 } // namespace edm
112 #endif
std::variant< unsigned int, detail::GetThinnedKeyFromExceptionFactory, std::monostate > OptionalThinnedKey
EDProductGetter const * mustBeNonZero(EDProductGetter const *prodGetter, std::string refType, ProductID const &productID)
static EDProductGetter const * switchProductGetter(EDProductGetter const *)
These can only be used internally by the framework.
unsigned int transitionIndex() const
virtual WrapperBase const * getIt(ProductID const &) const =0
EDProductGetter const & operator=(EDProductGetter const &)=delete
virtual void getThinnedProducts(ProductID const &pid, std::vector< WrapperBase const *> &foundContainers, std::vector< unsigned int > &keys) const =0
virtual std::optional< std::tuple< WrapperBase const *, unsigned int > > getThinnedProduct(ProductID const &, unsigned int key) const =0
virtual unsigned int transitionIndex_() const =0
static void assignEDProductGetter(EDProductGetter const *&)
HLT enums.
std::function< edm::Exception()> GetThinnedKeyFromExceptionFactory
virtual OptionalThinnedKey getThinnedKeyFrom(ProductID const &parent, unsigned int key, ProductID const &thinned) const =0