Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:36:22

0001 #ifndef FWCore_Framework_ESProducts_h
0002 #define FWCore_Framework_ESProducts_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Framework
0006 // Class  :     ESProducts
0007 //
0008 /**\class ESProducts ESProducts.h FWCore/Framework/interface/ESProducts.h
0009 
0010  Description: Container for multiple products created by an ESProducer
0011 
0012  Usage:
0013     This is used as a return type from the produce method of an ESProducer.  Users are not anticipated to ever need
0014  to directly use this class.  Instead, to create an instance of the class at method return time, they should call
0015  the helper function es::products.
0016 
0017 */
0018 //
0019 // Author:      Chris Jones
0020 // Created:     Sun Apr 17 17:30:46 EDT 2005
0021 //
0022 
0023 // system include files
0024 #include <memory>
0025 
0026 // user include files
0027 #include "FWCore/Framework/interface/produce_helpers.h"
0028 
0029 // forward declarations
0030 namespace edm {
0031   namespace eventsetup {
0032     namespace produce {
0033       template <typename T1, typename... TArgs>
0034       struct ProductHolder : public ProductHolder<TArgs...> {
0035         using parent_type = ProductHolder<TArgs...>;
0036 
0037         ProductHolder() : value() {}
0038         ProductHolder(ProductHolder<T1, TArgs...>&&) = default;
0039         ProductHolder(ProductHolder<T1, TArgs...> const&) = default;
0040         ProductHolder<T1, TArgs...>& operator=(ProductHolder<T1, TArgs...>&&) = default;
0041         ProductHolder<T1, TArgs...>& operator=(ProductHolder<T1, TArgs...> const&) = default;
0042 
0043         template <typename T>
0044         void setAllValues(T& iValuesFrom) {
0045           iValuesFrom.setFromRecursive(*this);
0046         }
0047         using parent_type::moveTo;
0048         void moveTo(T1& oValue) { oValue = std::move(value); }
0049 
0050         using parent_type::setFrom;
0051         void setFrom(T1& iValue) { value = iValue; }
0052         void setFrom(T1&& iValue) { value = std::move(iValue); }
0053 
0054         template <typename T>
0055         void setFromRecursive(T& iValuesTo) {
0056           iValuesTo.setFrom(value);
0057           parent_type::setFromRecursive(iValuesTo);
0058         }
0059 
0060         template <typename T>
0061         void moveToRecursive(T& iValuesTo) {
0062           iValuesTo.moveTo(value);
0063           parent_type::moveToRecursive(iValuesTo);
0064         }
0065         T1 value;
0066 
0067         using tail_type = T1;
0068         using head_type = parent_type;
0069       };
0070 
0071       template <typename T1>
0072       struct ProductHolder<T1> {
0073         ProductHolder() : value() {}
0074         ProductHolder(ProductHolder<T1>&&) = default;
0075         ProductHolder(ProductHolder<T1> const&) = default;
0076         ProductHolder<T1>& operator=(ProductHolder<T1>&&) = default;
0077         ProductHolder<T1>& operator=(ProductHolder<T1> const&) = default;
0078 
0079         template <typename T>
0080         void setAllValues(T& iValuesFrom) {
0081           iValuesFrom.moveToRecursive(*this);
0082         }
0083         void moveTo(T1& oValue) { oValue = std::move(value); }
0084         void setFrom(T1& iValue) { value = iValue; }
0085         void setFrom(T1&& iValue) { value = std::move(iValue); }
0086         template <typename T>
0087         void moveToRecursive(T& iValuesTo) {
0088           iValuesTo.moveTo(value);
0089         }
0090         template <typename T>
0091         void setFromRecursive(T& iValuesTo) {
0092           iValuesTo.setFrom(value);
0093         }
0094         T1 value;
0095 
0096         using tail_type = T1;
0097         using head_type = Null;
0098       };
0099 
0100     }  // namespace produce
0101   }  // namespace eventsetup
0102   struct ESFillDirectly {};
0103 
0104   template <typename... TArgs>
0105   struct ESProducts : public eventsetup::produce::ProductHolder<TArgs...> {
0106     typedef eventsetup::produce::ProductHolder<TArgs...> parent_type;
0107     template <typename... S>
0108     ESProducts(ESProducts<S...>&& iProducts) {
0109       parent_type::setAllValues(iProducts);
0110     }
0111     template <typename T>
0112     /*explicit*/ ESProducts(T&& iValues) {
0113       parent_type::setAllValues(iValues);
0114     }
0115     template <typename... Vars>
0116     ESProducts(ESFillDirectly, Vars&&... vars) {
0117       (this->setFrom(std::forward<Vars>(vars)), ...);
0118     }
0119 
0120     ESProducts(ESProducts<TArgs...> const&) = default;
0121     ESProducts(ESProducts<TArgs...>&&) = default;
0122     ESProducts<TArgs...>& operator=(ESProducts<TArgs...> const&) = default;
0123     ESProducts<TArgs...>& operator=(ESProducts<TArgs...>&&) = default;
0124   };
0125 
0126   namespace es {
0127     template <typename... TArgs>
0128     ESProducts<std::remove_reference_t<TArgs>...> products(TArgs&&... args) {
0129       return ESProducts<std::remove_reference_t<TArgs>...>(edm::ESFillDirectly{}, std::forward<TArgs>(args)...);
0130     }
0131   }  // namespace es
0132 
0133   template <typename... TArgs, typename ToT>
0134   void moveFromTo(ESProducts<TArgs...>& iFrom, ToT& iTo) {
0135     iFrom.moveTo(iTo);
0136   }
0137 }  // namespace edm
0138 
0139 #endif