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 {
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
edm::EDProductGetter::getThinnedProduct
virtual std::optional< std::tuple< WrapperBase const *, unsigned int > > getThinnedProduct(ProductID const &, unsigned int key) const =0
edm::EDProductGetter::switchProductGetter
static EDProductGetter const * switchProductGetter(EDProductGetter const *)
These can only be used internally by the framework.
Definition: EDProductGetter.cc:78
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::EDProductGetter::getThinnedProducts
virtual void getThinnedProducts(ProductID const &pid, std::vector< WrapperBase const * > &foundContainers, std::vector< unsigned int > &keys) const =0
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
edm::EDProductGetter::getIt
virtual WrapperBase const * getIt(ProductID const &) const =0
detail
Definition: ConvertingESProducerWithDependenciesT.h:23
edm::EDProductGetter::getThinnedKeyFrom
virtual OptionalThinnedKey getThinnedKeyFrom(ProductID const &parent, unsigned int key, ProductID const &thinned) const =0
edm::mustBeNonZero
EDProductGetter const * mustBeNonZero(EDProductGetter const *prodGetter, std::string refType, ProductID const &productID)
Definition: EDProductGetter.cc:65
edm::EDProductGetter
Definition: EDProductGetter.h:41
edm::EDProductGetter::assignEDProductGetter
static void assignEDProductGetter(EDProductGetter const *&)
Definition: EDProductGetter.cc:84
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EDProductGetter
Exception
edm::EDProductGetter::transitionIndex_
virtual unsigned int transitionIndex_() const =0
edm::WrapperBase
Definition: WrapperBase.h:23
edm::OptionalThinnedKey
std::variant< unsigned int, detail::GetThinnedKeyFromExceptionFactory, std::monostate > OptionalThinnedKey
Definition: EDProductGetter.h:39
edm::EDProductGetter::~EDProductGetter
virtual ~EDProductGetter()
Definition: EDProductGetter.cc:39
Exception
Definition: hltDiff.cc:245
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
edm::EDProductGetter::operator=
EDProductGetter const & operator=(EDProductGetter const &)=delete
edm::detail::GetThinnedKeyFromExceptionFactory
std::function< edm::Exception()> GetThinnedKeyFromExceptionFactory
Definition: EDProductGetter.h:37
edm::EDProductGetter::transitionIndex
unsigned int transitionIndex() const
Definition: EDProductGetter.h:94
crabWrapper.key
key
Definition: crabWrapper.py:19
class-composition.parent
parent
Definition: class-composition.py:88
edm::ProductID
Definition: ProductID.h:27
edm::EDProductGetter::EDProductGetter
EDProductGetter()
Definition: EDProductGetter.cc:32