CMS 3D CMS Logo

ESProducerExternalWork.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 #ifndef FWCore_Framework_ESProducerExternalWork_h
3 #define FWCore_Framework_ESProducerExternalWork_h
4 //
5 // Package: Framework
6 // Class : ESProducerExternalWork
7 //
17 //
18 // Author: W. David Dagenhart
19 // Created: 27 February 2023
20 
21 #include <memory>
22 #include <string>
23 #include <type_traits>
24 #include <utility>
25 #include <vector>
26 
34 
35 namespace edm {
36 
38  public:
40 
41  // These replicate the setWhatProduced functions but add a second functor for
42  // the acquire step. The acquire step is analogous to the acquire step for
43  // EDProducers with the ExternalWork ability.
44 
45  template <typename T>
46  auto setWhatAcquiredProduced(T* iThis, const es::Label& iLabel = {}) {
47  return setWhatAcquiredProduced(iThis, &T::acquire, &T::produce, iLabel);
48  }
49 
50  template <typename T>
51  auto setWhatAcquiredProduced(T* iThis, const char* iLabel) {
52  return setWhatAcquiredProduced(iThis, es::Label(iLabel));
53  }
54  template <typename T>
55  auto setWhatAcquiredProduced(T* iThis, const std::string& iLabel) {
56  return setWhatAcquiredProduced(iThis, es::Label(iLabel));
57  }
58 
59  // Note the Decorator pre and post functions are only run before
60  // and after the 'produce' function, but they are not run before
61  // and after the 'acquire' function.
62 
63  template <typename T, typename TDecorator>
64  auto setWhatAcquiredProduced(T* iThis, const TDecorator& iDec, const es::Label& iLabel = {}) {
65  return setWhatAcquiredProduced(iThis, &T::acquire, &T::produce, iDec, iLabel);
66  }
67 
75  template <typename T, typename TAcquireReturn, typename TProduceReturn, typename TRecord>
77  TAcquireReturn (T::*iAcquireMethod)(const TRecord&, WaitingTaskWithArenaHolder),
78  TProduceReturn (T::*iProduceMethod)(const TRecord&, TAcquireReturn),
79  const es::Label& iLabel = {}) {
81  iThis, iAcquireMethod, iProduceMethod, eventsetup::CallbackSimpleDecorator<TRecord>(), iLabel);
82  }
83 
84  template <typename T, typename TAcquireReturn, typename TProduceReturn, typename TRecord, typename TDecorator>
86  TAcquireReturn (T::*iAcquireMethod)(const TRecord&, WaitingTaskWithArenaHolder),
87  TProduceReturn (T ::*iProduceMethod)(const TRecord&, TAcquireReturn),
88  const TDecorator& iDec,
89  const es::Label& iLabel = {}) {
90  return setWhatAcquiredProducedWithLambda<TAcquireReturn, TProduceReturn, TRecord>(
91  [iThis, iAcquireMethod](TRecord const& iRecord, WaitingTaskWithArenaHolder iHolder) {
92  return (iThis->*iAcquireMethod)(iRecord, std::move(iHolder));
93  },
94  [iThis, iProduceMethod](TRecord const& iRecord, TAcquireReturn iAcquireReturn) {
95  return (iThis->*iProduceMethod)(iRecord, std::move(iAcquireReturn));
96  },
97  createDecoratorFrom(iThis, static_cast<const TRecord*>(nullptr), iDec),
98  iLabel);
99  }
100 
106  template <typename TAcquireFunc, typename TProduceFunc>
107  auto setWhatAcquiredProducedWithLambda(TAcquireFunc&& acquireFunc,
108  TProduceFunc&& produceFunc,
109  const es::Label& iLabel = {}) {
111  using TRecord = typename AcquireTypes::argument_type;
112  using TAcquireReturn = typename AcquireTypes::return_type;
113  using TProduceReturn = std::invoke_result_t<TProduceFunc, TRecord const&, TAcquireReturn>;
114  using DecoratorType = eventsetup::CallbackSimpleDecorator<TRecord>;
115 
116  return setWhatAcquiredProducedWithLambda<TAcquireReturn, TProduceReturn, TRecord>(
117  std::forward<TAcquireFunc>(acquireFunc), std::forward<TProduceFunc>(produceFunc), DecoratorType(), iLabel);
118  }
119 
120  // In this template, TReturn and TRecord cannot be deduced. They must be explicitly provided when called.
121  // The previous 7 functions all end up calling this one (directly or indirectly).
122  template <typename TAcquireReturn,
123  typename TProduceReturn,
124  typename TRecord,
125  typename TAcquireFunc,
126  typename TProduceFunc,
127  typename TDecorator>
129  TProduceFunc&& produceFunc,
130  TDecorator&& iDec,
131  const es::Label& iLabel = {}) {
132  const auto id = consumesInfoSize();
133  using DecoratorType = std::decay_t<TDecorator>;
135  TAcquireFunc,
136  TAcquireReturn,
137  TProduceFunc,
138  TProduceReturn,
139  TRecord,
140  DecoratorType>;
141  unsigned int iovIndex = 0; // Start with 0, but later will cycle through all of them
142  auto temp = std::make_shared<CallbackType>(this,
143  std::forward<TAcquireFunc>(acquireFunc),
144  std::forward<TProduceFunc>(produceFunc),
145  id,
146  std::forward<TDecorator>(iDec));
147  auto callback =
148  std::make_shared<std::pair<unsigned int, std::shared_ptr<CallbackType>>>(iovIndex, std::move(temp));
150  static_cast<const typename eventsetup::produce::product_traits<TProduceReturn>::type*>(nullptr),
151  static_cast<const TRecord*>(nullptr),
152  iLabel);
154  }
155  };
156 } // namespace edm
157 #endif
auto setWhatAcquiredProducedWithLambda(TAcquireFunc &&acquireFunc, TProduceFunc &&produceFunc, const es::Label &iLabel={})
auto setWhatAcquiredProduced(T *iThis, const char *iLabel)
auto setWhatAcquiredProduced(T *iThis, const TDecorator &iDec, const es::Label &iLabel={})
auto setWhatAcquiredProduced(T *iThis, const es::Label &iLabel={})
const TDecorator & createDecoratorFrom(T *, const TRecord *, const TDecorator &iDec)
Definition: ESProducer.h:99
ESConsumesInfo * consumesInfoPushBackNew()
Definition: ESProducer.h:248
auto setWhatAcquiredProduced(T *iThis, TAcquireReturn(T::*iAcquireMethod)(const TRecord &, WaitingTaskWithArenaHolder), TProduceReturn(T ::*iProduceMethod)(const TRecord &, TAcquireReturn), const TDecorator &iDec, const es::Label &iLabel={})
ESConsumesCollectorT< TRecord > setWhatAcquiredProducedWithLambda(TAcquireFunc &&acquireFunc, TProduceFunc &&produceFunc, TDecorator &&iDec, const es::Label &iLabel={})
void registerProducts(std::shared_ptr< std::pair< unsigned int, std::shared_ptr< CallbackT >>> iCallback, const TList *, const TRecord *iRecord, const es::Label &iLabel)
Definition: ESProducer.h:254
auto setWhatAcquiredProduced(T *iThis, const std::string &iLabel)
HLT enums.
unsigned int consumesInfoSize() const
Definition: ESProducer.h:246
long double T
auto setWhatAcquiredProduced(T *iThis, TAcquireReturn(T::*iAcquireMethod)(const TRecord &, WaitingTaskWithArenaHolder), TProduceReturn(T::*iProduceMethod)(const TRecord &, TAcquireReturn), const es::Label &iLabel={})
def move(src, dest)
Definition: eostools.py:511