CMS 3D CMS Logo

TransformerBase.cc
Go to the documentation of this file.
9 
10 #include <optional>
11 
12 namespace edm {
14  ProducerBase& iBase, EDPutToken iToken, const TypeID& id, std::string instanceName, TransformFunction iFunc) {
15  auto transformPut = iBase.transforms(id, std::move(instanceName));
17  transformInfo_.emplace_back(iToken.index(), id, transformPut, std::move(ptf), std::move(iFunc));
18  }
19 
21  EDPutToken iToken,
22  const TypeID& id,
23  std::string instanceName,
24  PreTransformFunction iPreFunc,
25  TransformFunction iFunc) {
26  auto transformPut = iBase.transforms(id, std::move(instanceName));
27  transformInfo_.emplace_back(iToken.index(), id, transformPut, std::move(iPreFunc), std::move(iFunc));
28  }
29 
31  edm::BranchDescription const& iBranch) const {
32  auto const& list = iBase.typeLabelList();
33 
34  std::size_t index = 0;
35  bool found = false;
36  for (auto const& element : list) {
37  if (not element.isTransform_) {
38  continue;
39  }
40  if (element.typeID_ == iBranch.unwrappedTypeID() &&
41  element.productInstanceName_ == iBranch.productInstanceName()) {
42  found = true;
43  break;
44  }
45  ++index;
46  }
47  assert(found);
48  return index;
49  }
50 
52  ModuleDescription const& iModuleDesc,
53  ProductResolverIndexHelper const& iHelper) {
54  auto const& list = iBase.typeLabelList();
55 
56  for (auto it = transformInfo_.begin<0>(); it != transformInfo_.end<0>(); ++it) {
57  auto const& putInfo = list[*it];
58  *it = iHelper.index(PRODUCT_TYPE,
59  putInfo.typeID_,
60  iModuleDesc.moduleLabel().c_str(),
61  putInfo.productInstanceName_.c_str(),
62  iModuleDesc.processName().c_str());
63  }
64  }
65 
67  std::size_t iIndex,
68  ProducerBase const& iBase,
70  if (transformInfo_.get<kPreTransform>(iIndex)) {
71  std::optional<decltype(iEvent.get(transformInfo_.get<kType>(iIndex), transformInfo_.get<kResolverIndex>(iIndex)))>
72  handle;
73  CMS_SA_ALLOW try {
74  handle = iEvent.get(transformInfo_.get<kType>(iIndex), transformInfo_.get<kResolverIndex>(iIndex));
75  } catch (...) {
76  iHolder.doneWaiting(std::current_exception());
77  return;
78  }
79  if (handle->wrapper()) {
80  auto cache = std::make_shared<std::any>();
81  auto nextTask =
82  edm::make_waiting_task([holder = iHolder, cache, iIndex, this, &iBase, handle = *handle, iEvent](
83  std::exception_ptr const* iPtr) mutable {
84  if (iPtr) {
85  holder.doneWaiting(*iPtr);
86  } else {
88  transformInfo_.get<kTransform>(iIndex)(std::move(*cache)),
89  handle);
90  }
91  });
92  WaitingTaskWithArenaHolder wta(*iHolder.group(), nextTask);
93  CMS_SA_ALLOW try {
94  *cache = transformInfo_.get<kPreTransform>(iIndex)(*(handle->wrapper()), wta);
95  } catch (...) {
96  wta.doneWaiting(std::current_exception());
97  }
98  }
99  } else {
100  CMS_SA_ALLOW try {
101  auto handle = iEvent.get(transformInfo_.get<kType>(iIndex), transformInfo_.get<kResolverIndex>(iIndex));
102 
103  if (handle.wrapper()) {
104  std::any v = handle.wrapper();
106  transformInfo_.get<kTransform>(iIndex)(std::move(v)),
107  handle);
108  }
109  } catch (...) {
110  iHolder.doneWaiting(std::current_exception());
111  }
112  }
113  }
114 
115 } // namespace edm
void transformImpAsync(WaitingTaskHolder iTask, std::size_t iIndex, ProducerBase const &iBase, edm::EventForTransformer &) const
std::function< std::any(edm::WrapperBase const &, edm::WaitingTaskWithArenaHolder)> PreTransformFunction
#define CMS_SA_ALLOW
SoATuple< ProductResolverIndex, TypeID, EDPutToken, PreTransformFunction, TransformFunction > transformInfo_
bool any(const std::vector< T > &v, const T &what)
Definition: ECalSD.cc:37
TypeID unwrappedTypeID() const
EDPutToken transforms(const TypeID &id, std::string instanceName)
assert(be >=bs)
oneapi::tbb::task_group * group() const noexcept
int iEvent
Definition: GenABIO.cc:224
void doneWaiting(std::exception_ptr iExcept)
TypeLabelList const & typeLabelList() const
used by the fwk to register the list of products of this module
ProductResolverIndex index(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process=nullptr) const
void extendUpdateLookup(ProducerBase const &, ModuleDescription const &iModuleDesc, ProductResolverIndexHelper const &iHelper)
std::string const & productInstanceName() const
std::function< std::unique_ptr< edm::WrapperBase >(std::any)> TransformFunction
FunctorWaitingTask< F > * make_waiting_task(F f)
Definition: WaitingTask.h:92
optional
Definition: Types.py:239
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex() const
Definition: ProducerBase.h:101
constexpr value_type index() const noexcept
Definition: EDPutToken.h:50
void registerTransformAsyncImp(ProducerBase &, EDPutToken, const TypeID &id, std::string instanceName, PreTransformFunction, TransformFunction)
std::string const & processName() const
HLT enums.
def cache(function)
Definition: utilities.py:3
void registerTransformImp(ProducerBase &, EDPutToken, const TypeID &id, std::string instanceName, TransformFunction)
std::string const & moduleLabel() const
def move(src, dest)
Definition: eostools.py:511
std::size_t findMatchingIndex(ProducerBase const &iBase, edm::BranchDescription const &) const