1 #ifndef art_Framework_Principal_ProductRetriever_h 2 #define art_Framework_Principal_ProductRetriever_h 23 #include "cetlib/container_algorithms.h" 24 #include "cetlib/exempt_ptr.h" 25 #include "cetlib_except/exception.h" 41 class EDProductGetter;
62 template <
typename PROD>
63 PROD
const& getProduct(
InputTag const& tag)
const;
64 template <
typename PROD>
68 template <
typename PROD>
70 template <
typename PROD>
72 "\n\nart warning: The Event::getHandle<T>(id) interface is deprecated.\n" 73 " Please use a ProductPtr<T> instead, or retrieve a " 78 template <
typename PROD>
80 template <
typename PROD>
84 template <
typename PROD>
86 template <
typename PROD>
90 template <
typename PROD>
91 std::vector<InputTag> getInputTags(
93 template <
typename PROD>
94 std::vector<ProductToken<PROD>> getProductTokens(
96 template <
typename PROD>
97 std::vector<Handle<PROD>> getMany(
101 template <
typename PROD>
103 template <
typename PROD>
105 "\n\nart warning: The Event::get(id, handle) interface is deprecated.\n" 106 " Please use a ProductPtr<T> instead, or retrieve a " 109 "Ptr<T>::parentAs<Collection>().\n\n")]]
bool 111 template <
typename PROD>
112 bool getByLabel(std::string
const& label,
115 template <
typename PROD>
116 bool getByLabel(std::string
const& label,
117 std::string
const& instance,
118 std::string
const& process,
120 template <
typename PROD>
124 template <
typename ELEMENT>
125 std::size_t getView(std::string
const& moduleLabel,
126 std::string
const& productInstanceName,
127 std::string
const& processName,
128 std::vector<ELEMENT const*>& result)
const;
129 template <
typename ELEMENT>
130 std::size_t getView(std::string
const& moduleLabel,
131 std::string
const& productInstanceName,
132 std::vector<ELEMENT const*>& result)
const;
133 template <
typename ELEMENT>
134 std::size_t getView(
InputTag const&,
135 std::vector<ELEMENT const*>& result)
const;
136 template <
typename ELEMENT>
138 std::vector<ELEMENT const*>& result)
const;
139 template <
typename ELEMENT>
140 bool getView(std::string
const& moduleLabel,
141 std::string
const& productInstanceName,
142 std::string
const& processName,
144 template <
typename ELEMENT>
145 bool getView(std::string
const& moduleLabel,
146 std::string
const& productInstanceName,
148 template <
typename ELEMENT>
150 template <
typename ELEMENT>
153 std::vector<ProductID> retrievedPIDs()
const;
156 std::optional<Provenance const> getProductProvenance(
ProductID)
const;
157 std::optional<fhicl::ParameterSet const> getProcessParameterSet(
158 std::string
const& process)
const;
159 cet::exempt_ptr<BranchDescription const> getProductDescription(
163 template <
typename T>
164 ProductID getProductID(std::string
const& instance_name =
"")
const;
167 void recordAsParent_(cet::exempt_ptr<Group const> grp)
const;
168 cet::exempt_ptr<Group const> getContainerForView_(
170 std::string
const& moduleLabel,
171 std::string
const& productInstanceName,
174 std::string
const& instance)
const;
175 std::vector<InputTag> getInputTags_(
WrappedTypeID const& wrapped,
176 SelectorBase
const& selector)
const;
180 SelectorBase
const& selector)
const;
182 std::vector<GroupQueryResult> getMany_(
WrappedTypeID const& wrapped,
183 SelectorBase
const& sel)
const;
186 mutable std::recursive_mutex mutex_{};
208 mutable std::set<ProductID> retrievedProducts_{};
211 template <
typename PROD>
215 return getProductID_(
TypeID{
typeid(PROD)}, instance);
219 template <
typename PROD>
223 return *getValidHandle<PROD>(tag);
226 template <
typename PROD>
230 return *getValidHandle(token);
234 template <
typename PROD>
238 auto qr = getBySelector_(WrappedTypeID::make<PROD>(), sel);
242 template <
typename PROD>
246 auto qr = getByProductID_(pid);
250 template <
typename PROD>
254 auto qr = getByLabel_(WrappedTypeID::make<PROD>(), tag);
258 template <
typename PROD>
262 return getHandle<PROD>(token.
inputTag());
266 template <
typename PROD>
270 auto h = getHandle<PROD>(tag);
274 template <
typename PROD>
278 return getValidHandle<PROD>(token.
inputTag());
281 template <
typename PROD>
282 std::vector<InputTag>
285 return getInputTags_(WrappedTypeID::make<PROD>(), selector);
288 template <
typename PROD>
289 std::vector<ProductToken<PROD>>
292 auto const tags = getInputTags<PROD>(selector);
293 std::vector<ProductToken<PROD>> tokens;
294 tokens.reserve(tags.size());
295 cet::transform_all(tags, back_inserter(tokens), [](
auto const& tag) {
301 template <
typename PROD>
302 std::vector<Handle<PROD>>
305 auto const qrs = getMany_(WrappedTypeID::make<PROD>(), sel);
306 std::vector<Handle<PROD>> products;
307 products.reserve(qrs.size());
308 cet::transform_all(qrs, back_inserter(products), [](
auto const& qr) {
314 template <
typename ELEMENT>
317 std::string
const& productInstanceName,
318 std::string
const& processName,
319 std::vector<ELEMENT const*>& result)
const 321 std::lock_guard lock{mutex_};
322 std::size_t
const orig_size = result.size();
323 auto grp = getContainerForView_(
TypeID{
typeid(ELEMENT)},
327 if (recordParents_) {
328 recordAsParent_(grp);
330 auto const view = grp->uniqueProduct()->getView();
331 std::vector<ELEMENT const*> castedView;
332 for (
auto p : view) {
333 castedView.push_back(static_cast<ELEMENT const*>(p));
335 result = std::move(castedView);
336 return result.size() - orig_size;
339 template <
typename ELEMENT>
342 std::string
const& productInstanceName,
343 std::vector<ELEMENT const*>& result)
const 345 return getView(moduleLabel, productInstanceName, {}, result);
348 template <
typename ELEMENT>
351 std::vector<ELEMENT const*>& result)
const 356 template <
typename ELEMENT>
359 std::vector<ELEMENT const*>& result)
const 361 return getView(token.
inputTag(), result);
364 template <
typename ELEMENT>
367 std::string
const& productInstanceName,
368 std::string
const& processName,
371 std::lock_guard lock{mutex_};
372 auto grp = getContainerForView_(
TypeID{
typeid(ELEMENT)},
376 if (recordParents_) {
377 recordAsParent_(grp);
379 auto const view = grp->uniqueProduct()->getView();
380 std::vector<ELEMENT const*> castedView;
381 for (
auto p : view) {
382 castedView.push_back(static_cast<ELEMENT const*>(p));
385 View{std::move(castedView), grp->productID(), grp->uniqueProduct()};
389 template <
typename ELEMENT>
392 std::string
const& productInstanceName,
395 return getView(moduleLabel, productInstanceName, {}, result);
398 template <
typename ELEMENT>
405 template <
typename ELEMENT>
410 return getView(token.
inputTag(), result);
415 template <
typename PROD>
419 result = getHandle<PROD>(sel);
420 return static_cast<bool>(result);
423 template <
typename PROD>
427 result = getHandle<PROD>(pid);
428 return static_cast<bool>(result);
431 template <
typename PROD>
434 std::string
const& productInstanceName,
435 std::string
const& processName,
438 result = getHandle<PROD>({moduleLabel, productInstanceName, processName});
439 return static_cast<bool>(result);
442 template <
typename PROD>
448 result = getHandle<PROD>({moduleLabel, instance});
449 return static_cast<bool>(result);
452 template <
typename PROD>
456 result = getHandle<PROD>(tag);
457 return static_cast<bool>(result);
460 template <
typename PROD>
462 operator<<(std::ostream& os, Handle<PROD>
const& h)
464 os << h.
product() <<
" " << h.provenance() <<
" " << h.id();
bool get(SelectorBase const &, Handle< PROD > &result) const
ProductID getProductID(std::string const &instance_name="") const
ModuleContext const & mc_
const std::string instance
Principal const & principal_
bool const recordParents_
BranchType const branchType_
InputTag const & inputTag() const
T const * product() const
ModuleDescription const & md_
std::vector< ProductToken< PROD > > getProductTokens(SelectorBase const &selector=MatchAllSelector{}) const
T const * product() const
std::vector< InputTag > getInputTags(SelectorBase const &selector=MatchAllSelector{}) const
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Handle< PROD > getHandle(SelectorBase const &) const
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
InputTag const & inputTag() const
PROD const & getProduct(InputTag const &tag) const
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const