Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DataFormats_Common_EDProductGetter_h
0002 #define DataFormats_Common_EDProductGetter_h
0003 // -*- C++ -*-
0004 //
0005 // Class  :     EDProductGetter
0006 //
0007 /**\class EDProductGetter EDProductGetter.h DataFormats/Common/interface/EDProductGetter.h
0008 
0009  Description: Abstract base class used internally by the RefBase to obtain the EDProduct from the Event
0010 
0011  Usage:
0012     This is used internally by the edm::Ref classes.
0013 */
0014 //
0015 // Original Author:  Chris Jones
0016 //         Created:  Tue Nov  1 15:06:31 EST 2005
0017 //
0018 
0019 // user include files
0020 
0021 // system include files
0022 #include <functional>
0023 #include <optional>
0024 #include <string>
0025 #include <tuple>
0026 #include <variant>
0027 #include <vector>
0028 
0029 // forward declarations
0030 
0031 namespace edm {
0032 
0033   class Exception;
0034   class ProductID;
0035   class WrapperBase;
0036   namespace detail {
0037     using GetThinnedKeyFromExceptionFactory = std::function<edm::Exception()>;
0038   }
0039   using OptionalThinnedKey = std::variant<unsigned int, detail::GetThinnedKeyFromExceptionFactory, std::monostate>;
0040 
0041   class EDProductGetter {
0042   public:
0043     EDProductGetter();
0044     virtual ~EDProductGetter();
0045 
0046     EDProductGetter(EDProductGetter const&) = delete;  // stop default
0047 
0048     EDProductGetter const& operator=(EDProductGetter const&) = delete;  // stop default
0049 
0050     // ---------- const member functions ---------------------
0051     virtual WrapperBase const* getIt(ProductID const&) const = 0;
0052 
0053     // getThinnedProduct assumes getIt was already called and failed to find
0054     // the product. The input key is the index of the desired element in the
0055     // container identified by ProductID (which cannot be found).
0056     // If the return value is not null, then the desired element was
0057     // found in a thinned container. If the desired element is not
0058     // found, then an optional without a value is returned.
0059     virtual std::optional<std::tuple<WrapperBase const*, unsigned int>> getThinnedProduct(ProductID const&,
0060                                                                                           unsigned int key) const = 0;
0061 
0062     // getThinnedProducts assumes getIt was already called and failed to find
0063     // the product. The input keys are the indexes into the container identified
0064     // by ProductID (which cannot be found). On input the WrapperBase pointers
0065     // must all be set to nullptr (except when the function calls itself
0066     // recursively where non-null pointers mark already found elements).
0067     // Thinned containers derived from the product are searched to see
0068     // if they contain the desired elements. For each that is
0069     // found, the corresponding WrapperBase pointer is set and the key
0070     // is modified to be the key into the container where the element
0071     // was found. The WrapperBase pointers might or might not all point
0072     // to the same thinned container.
0073     virtual void getThinnedProducts(ProductID const& pid,
0074                                     std::vector<WrapperBase const*>& foundContainers,
0075                                     std::vector<unsigned int>& keys) const = 0;
0076 
0077     // This overload is allowed to be called also without getIt()
0078     // being called first, but the thinned ProductID must come from an
0079     // existing RefCore. The input key is the index of the desired
0080     // element in the container identified by the parent ProductID.
0081     // Returns an std::variant whose contents can be
0082     // - unsigned int for the index in the thinned collection if the
0083     //   desired element was found in the thinned collection
0084     // - function creating an edm::Exception if parent is not a parent
0085     //   of any thinned collection, thinned is not really a thinned
0086     //   collection, or parent and thinned have no thinning
0087     //   relationship
0088     // - std::monostate if thinned is thinned from parent, but the key
0089     //   is not found in the thinned collection
0090     virtual OptionalThinnedKey getThinnedKeyFrom(ProductID const& parent,
0091                                                  unsigned int key,
0092                                                  ProductID const& thinned) const = 0;
0093 
0094     unsigned int transitionIndex() const { return transitionIndex_(); }
0095 
0096     // ---------- member functions ---------------------------
0097 
0098     ///These can only be used internally by the framework
0099     static EDProductGetter const* switchProductGetter(EDProductGetter const*);
0100     static void assignEDProductGetter(EDProductGetter const*&);
0101 
0102   private:
0103     virtual unsigned int transitionIndex_() const = 0;
0104 
0105     // ---------- member data --------------------------------
0106   };
0107 
0108   EDProductGetter const* mustBeNonZero(EDProductGetter const* prodGetter,
0109                                        std::string refType,
0110                                        ProductID const& productID);
0111 }  // namespace edm
0112 #endif