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 TAcquireReturn = typename AcquireTypes::return_type;
113  using TProduceReturn = typename ProduceTypes::return_type;
114  using TRecord = typename ProduceTypes::argument_type;
115  using DecoratorType = eventsetup::CallbackSimpleDecorator<TRecord>;
116 
117  return setWhatAcquiredProducedWithLambda<TAcquireReturn, TProduceReturn, TRecord>(
118  std::forward<TAcquireFunc>(acquireFunc), std::forward<TProduceFunc>(produceFunc), DecoratorType(), iLabel);
119  }
120 
121  // In this template, TReturn and TRecord cannot be deduced. They must be explicitly provided when called.
122  // The previous 7 functions all end up calling this one (directly or indirectly).
123  template <typename TAcquireReturn,
124  typename TProduceReturn,
125  typename TRecord,
126  typename TAcquireFunc,
127  typename TProduceFunc,
128  typename TDecorator>
130  TProduceFunc&& produceFunc,
131  TDecorator&& iDec,
132  const es::Label& iLabel = {}) {
133  const auto id = consumesInfoSize();
134  using DecoratorType = std::decay_t<TDecorator>;
136  TAcquireFunc,
137  TAcquireReturn,
138  TProduceFunc,
139  TProduceReturn,
140  TRecord,
141  DecoratorType>;
142  unsigned int iovIndex = 0; // Start with 0, but later will cycle through all of them
143  auto temp = std::make_shared<CallbackType>(this,
144  std::forward<TAcquireFunc>(acquireFunc),
145  std::forward<TProduceFunc>(produceFunc),
146  id,
147  std::forward<TDecorator>(iDec));
148  auto callback =
149  std::make_shared<std::pair<unsigned int, std::shared_ptr<CallbackType>>>(iovIndex, std::move(temp));
151  static_cast<const typename eventsetup::produce::product_traits<TProduceReturn>::type*>(nullptr),
152  static_cast<const TRecord*>(nullptr),
153  iLabel);
155  }
156  };
157 } // namespace edm
158 #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:247
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:253
auto setWhatAcquiredProduced(T *iThis, const std::string &iLabel)
HLT enums.
unsigned int consumesInfoSize() const
Definition: ESProducer.h:245
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