1 #ifndef art_Framework_Principal_DataViewImpl_h 2 #define art_Framework_Principal_DataViewImpl_h 40 #include "cetlib_except/exception.h" 56 class EDProductGetter;
95 bool isRealData()
const;
100 template <
typename PROD>
107 template <
typename PROD>
109 template <
typename PROD>
113 template <
typename PROD>
115 template <
typename PROD>
117 template <
typename PROD>
119 template <
typename PROD>
123 template <
typename PROD>
125 template <
typename PROD>
129 template <
typename PROD>
130 std::vector<InputTag> getInputTags(
132 template <
typename PROD>
133 std::vector<ProductToken<PROD>> getProductTokens(
135 template <
typename PROD>
136 std::vector<Handle<PROD>> getMany(
140 template <
typename PROD>
142 template <
typename PROD>
144 template <
typename PROD>
148 template <
typename PROD>
153 template <
typename PROD>
157 template <
typename PROD>
159 "\n\nart warning: Please use getHandle<T>(token) instead.\n\n")]]
bool 161 template <
typename PROD>
162 [[deprecated(
"\n\nart warning: Please use getHandle<T>(tag).product() " 163 "instead.\n\n")]] PROD
const*
165 template <
typename PROD>
167 "\n\nart warning: Please use getMany<T>(selector) instead.\n\n")]]
void 169 template <
typename PROD>
170 [[deprecated(
"\n\nart warning: Please use getMany<T>() instead.\n\n")]]
void 174 template <
typename ELEMENT>
175 std::size_t getView(
std::string const& moduleLabel,
178 std::vector<ELEMENT const*>&
result)
const;
179 template <
typename ELEMENT>
180 std::size_t getView(
std::string const& moduleLabel,
182 std::vector<ELEMENT const*>&
result)
const;
183 template <
typename ELEMENT>
184 std::size_t getView(
InputTag const&,
185 std::vector<ELEMENT const*>&
result)
const;
186 template <
typename ELEMENT>
188 std::vector<ELEMENT const*>&
result)
const;
189 template <
typename ELEMENT>
194 template <
typename ELEMENT>
198 template <
typename ELEMENT>
200 template <
typename ELEMENT>
204 template <
typename T>
211 template <
typename PROD>
212 ProductID put(std::unique_ptr<PROD>&& edp,
216 template <
typename PROD>
217 ProductID put(std::unique_ptr<PROD>&& edp,
222 template <
typename PROD>
223 ProductID put(std::unique_ptr<PROD>&& edp,
225 template <
typename PROD>
226 ProductID put(std::unique_ptr<PROD>&& edp,
228 template <
typename PROD>
229 ProductID put(std::unique_ptr<PROD>&& edp,
231 template <
typename PROD>
232 ProductID put(std::unique_ptr<PROD>&& edp,
235 template <
typename PROD>
236 ProductID put(std::unique_ptr<PROD>&& edp,
239 template <
typename PROD>
240 ProductID put(std::unique_ptr<PROD>&& edp,
245 template <
typename PROD>
246 ProductID put(std::unique_ptr<PROD>&& edp,
248 template <
typename PROD>
249 ProductID put(std::unique_ptr<PROD>&& edp,
251 template <
typename PROD>
252 ProductID put(std::unique_ptr<PROD>&& edp,
254 template <
typename PROD>
255 ProductID put(std::unique_ptr<PROD>&& edp,
258 template <
typename PROD>
259 ProductID put(std::unique_ptr<PROD>&& edp,
262 template <
typename PROD>
263 ProductID put(std::unique_ptr<PROD>&& edp,
267 void movePutProductsToPrincipal(
Principal& principal);
268 void movePutProductsToPrincipal(
270 bool const checkProducts,
271 std::map<TypeLabel, BranchDescription>
const* expectedProducts);
289 bool const alwaysEnableLookupOfProducedProducts =
false)
const;
301 mutable std::recursive_mutex mutex_{};
329 mutable std::set<ProductID> retrievedProducts_{};
333 std::map<TypeLabel, PMValue> putProducts_{};
336 template <
typename PROD>
340 std::lock_guard lock{mutex_};
343 type.friendlyClassName(), md_.moduleLabel(),
instance, md_.processName());
345 auto desc = principal_.getProductDescription(pid);
348 "DataViewImpl::getProductID: error while trying to " 349 "retrieve product description:\n")
350 <<
"No product is registered for\n" 351 <<
" process name: '" << md_.processName() <<
"'\n" 352 <<
" module label: '" << md_.moduleLabel() <<
"'\n" 353 <<
" product friendly class name: '" <<
type.friendlyClassName()
355 <<
" product instance name: '" << instance <<
"'\n" 356 <<
" branch type: '" << branchType_ <<
"'\n";
361 return desc->productID();
365 template <
typename PROD>
369 return *getValidHandle<PROD>(tag);
372 template <
typename PROD>
376 return *getValidHandle(token);
380 template <
typename PROD>
384 std::lock_guard lock{mutex_};
386 ProcessTag const processTag{
"", md_.processName()};
387 auto qr = principal_.getBySelector(
388 mc_, WrappedTypeID::make<PROD>(), sel, processTag);
389 bool const ok = qr.succeeded() && !qr.failed();
390 if (recordParents_ && ok) {
391 recordAsParent_(qr.result());
396 template <
typename PROD>
400 std::lock_guard lock{mutex_};
401 auto qr = principal_.getByProductID(pid);
402 bool const ok = qr.succeeded() && !qr.failed();
403 if (recordParents_ && ok) {
404 recordAsParent_(qr.result());
409 template <
typename PROD>
413 std::lock_guard lock{mutex_};
414 auto const wrapped = WrappedTypeID::make<PROD>();
417 wrapped.product_type,
425 if (recordParents_ && ok) {
426 recordAsParent_(qr.
result());
431 template <
typename PROD>
439 template <
typename PROD>
448 template <
typename PROD>
452 return getValidHandle<PROD>(token.
inputTag_);
455 template <
typename PROD>
456 std::vector<InputTag>
459 auto const wrapped = WrappedTypeID::make<PROD>();
460 ProcessTag const processTag{
"", md_.processName()};
461 return principal_.getInputTags(mc_, wrapped, selector, processTag);
464 template <
typename PROD>
465 std::vector<ProductToken<PROD>>
468 auto const tags = getInputTags<PROD>(selector);
469 std::vector<ProductToken<PROD>> tokens;
470 tokens.reserve(tags.size());
477 template <
typename PROD>
478 std::vector<Handle<PROD>>
481 std::lock_guard lock{mutex_};
482 auto const wrapped = WrappedTypeID::make<PROD>();
487 ProcessTag const processTag{
"", md_.processName()};
488 std::vector<Handle<PROD>> products;
489 for (
auto const& qr : principal_.getMany(mc_, wrapped, sel, processTag)) {
490 products.emplace_back(qr);
491 if (recordParents_) {
492 recordAsParent_(qr.result());
498 template <
typename ELEMENT>
503 std::vector<ELEMENT const*>&
result)
const 505 std::lock_guard lock{mutex_};
506 std::size_t
const orig_size = result.size();
507 auto grp = getContainerForView_(
TypeID{
typeid(ELEMENT)},
511 if (recordParents_) {
512 recordAsParent_(grp);
514 auto const view = grp->uniqueProduct()->getView();
515 std::vector<ELEMENT const*> castedView;
516 for (
auto p : view) {
517 castedView.push_back(static_cast<ELEMENT const*>(p));
520 return result.size() - orig_size;
523 template <
typename ELEMENT>
527 std::vector<ELEMENT const*>&
result)
const 529 return getView(moduleLabel, productInstanceName, {},
result);
532 template <
typename ELEMENT>
535 std::vector<ELEMENT const*>&
result)
const 540 template <
typename ELEMENT>
543 std::vector<ELEMENT const*>&
result)
const 551 template <
typename ELEMENT>
558 std::lock_guard lock{mutex_};
559 auto grp = getContainerForView_(
TypeID{
typeid(ELEMENT)},
563 if (recordParents_) {
564 recordAsParent_(grp);
566 auto const view = grp->uniqueProduct()->getView();
567 std::vector<ELEMENT const*> castedView;
568 for (
auto p : view) {
569 castedView.push_back(static_cast<ELEMENT const*>(p));
571 result =
View{
move(castedView), grp->productID(), grp->uniqueProduct()};
575 template <
typename ELEMENT>
581 return getView(moduleLabel, productInstanceName, {},
result);
584 template <
typename ELEMENT>
591 template <
typename ELEMENT>
604 template <
typename PROD>
608 result = getHandle<PROD>(sel);
609 return static_cast<bool>(
result);
612 template <
typename PROD>
616 result = getHandle<PROD>(pid);
617 return static_cast<bool>(
result);
620 template <
typename PROD>
627 result = getHandle<PROD>({moduleLabel, productInstanceName, processName});
628 return static_cast<bool>(
result);
631 template <
typename PROD>
637 result = getHandle<PROD>({moduleLabel, instance});
638 return static_cast<bool>(
result);
641 template <
typename PROD>
645 result = getHandle<PROD>(tag);
646 return static_cast<bool>(
result);
649 template <
typename PROD>
658 template <
typename PROD>
663 result = getHandle(token);
664 return static_cast<bool>(
result);
667 template <
typename PROD>
672 results = getMany<PROD>(sel);
675 template <
typename PROD>
679 results = getMany<PROD>();
684 template <
typename PROD>
688 std::lock_guard lock{mutex_};
689 TypeID const tid{
typeid(PROD)};
690 if (edp.get() ==
nullptr) {
692 <<
"Event::put: A null unique_ptr was passed to 'put'.\n" 693 <<
"The pointer is of type " << tid <<
".\n" 694 <<
"The specified productInstanceName was '" << instance <<
"'.\n";
696 auto const& bd = getProductDescription_(tid, instance,
true);
698 auto const typeLabel =
700 auto wp = std::make_unique<Wrapper<PROD>>(
move(edp));
702 rangeSet_.collapse() :
710 <<
"Event::put: Attempt to put multiple products with the\n" 711 <<
" following description onto the Event.\n" 712 <<
" Products must be unique per Event.\n" 714 << bd << rule(
'=') <<
'\n';
716 return bd.productID();
719 template <
typename PROD>
724 return put(
move(edp),
"", semantic);
727 template <
typename PROD>
732 return put(
move(edp),
"", semantic);
735 template <
typename PROD>
743 template <
typename PROD>
752 template <
typename PROD>
758 std::lock_guard lock{mutex_};
762 "art error: A Run product put with the semantic 'RunFragment'\n" 763 " must be able to be aggregated. Please add the appropriate\n" 764 " void aggregate(T const&)\n" 765 " function to your class, or contact artists@fnal.gov.\n");
766 if (rangeSet_.collapse().is_full_run()) {
768 <<
"\nCannot put a product corresponding to a full Run using\n" 769 <<
"art::runFragment(). This can happen if you attempted to\n" 770 <<
"put a product at beginRun using art::runFragment().\n" 771 <<
"Please use either:\n" 772 <<
" art::fullRun(), or\n" 773 <<
" art::runFragment(art::RangeSet const&)\n" 774 <<
"or contact artists@fnal.gov for assistance.\n";
776 return put(
move(edp), instance, rangeSet_);
779 template <
typename PROD>
785 std::lock_guard lock{mutex_};
789 "art error: A Run product put with the semantic 'RunFragment'\n" 790 " must be able to be aggregated. Please add the appropriate\n" 791 " void aggregate(T const&)\n" 792 " function to your class, or contact artists@fnal.gov.\n");
793 if (semantic.
rs.collapse().is_full_run()) {
795 <<
"\nCannot put a product corresponding to a full Run using\n" 796 <<
"art::runFragment(art::RangeSet&). Please use:\n" 797 <<
" art::fullRun()\n" 798 <<
"or contact artists@fnal.gov for assistance.\n";
800 return put(
move(edp), instance, semantic.
rs);
803 template <
typename PROD>
808 return put(
move(edp),
"", semantic);
811 template <
typename PROD>
816 return put(
move(edp),
"", semantic);
819 template <
typename PROD>
827 template <
typename PROD>
836 template <
typename PROD>
842 std::lock_guard lock{mutex_};
846 "art error: A SubRun product put with the semantic 'SubRunFragment'\n" 847 " must be able to be aggregated. Please add the appropriate\n" 848 " void aggregate(T const&)\n" 849 " function to your class, or contact artists@fnal.gov.\n");
850 if (rangeSet_.collapse().is_full_subRun()) {
852 <<
"\nCannot put a product corresponding to a full SubRun using\n" 853 <<
"art::subRunFragment(). This can happen if you attempted to\n" 854 <<
"put a product at beginSubRun using art::subRunFragment().\n" 855 <<
"Please use either:\n" 856 <<
" art::fullSubRun(), or\n" 857 <<
" art::subRunFragment(art::RangeSet const&)\n" 858 <<
"or contact artists@fnal.gov for assistance.\n";
860 return put(
move(edp), instance, rangeSet_);
863 template <
typename PROD>
869 std::lock_guard lock{mutex_};
873 "art error: A SubRun product put with the semantic 'SubRunFragment'\n" 874 " must be able to be aggregated. Please add the appropriate\n" 875 " void aggregate(T const&)\n" 876 " function to your class, or contact artists@fnal.gov.\n");
877 if (semantic.
rs.collapse().is_full_subRun()) {
879 <<
"\nCannot put a product corresponding to a full SubRun using\n" 880 <<
"art::subRunFragment(art::RangeSet&). Please use:\n" 881 <<
" art::fullSubRun()\n" 882 <<
"or contact artists@fnal.gov for assistance.\n";
884 return put(
move(edp), instance, semantic.
rs);
887 template <
typename PROD>
893 std::lock_guard lock{mutex_};
894 TypeID const tid{
typeid(PROD)};
895 if (edp.get() ==
nullptr) {
897 <<
"Event::put: A null unique_ptr was passed to 'put'.\n" 898 <<
"The pointer is of type " << tid <<
".\n" 899 <<
"The specified productInstanceName was '" << instance <<
"'.\n";
903 <<
"\nCannot put a product with an invalid RangeSet.\n" 904 <<
"Please contact artists@fnal.gov.\n";
906 auto const& bd = getProductDescription_(tid, instance,
true);
908 auto const typeLabel =
910 auto wp = std::make_unique<Wrapper<PROD>>(
move(edp));
916 <<
"Event::put: Attempt to put multiple products with the\n" 917 <<
" following description onto the Event.\n" 918 <<
" Products must be unique per Event.\n" 920 << bd << rule(
'=') <<
'\n';
922 return bd.productID();
925 template <
typename PROD>
929 std::lock_guard lock{mutex_};
932 principal_.removeCachedProduct(h.
id());
939 template <
typename PROD>
941 operator<<(std::ostream& os, Handle<PROD>
const&
h)
943 os <<
h.product() <<
" " <<
h.provenance() <<
" " <<
h.id();
Principal const & principal_
PROD const * getPointerByLabel(InputTag const &tag) const
ProductID getProductID(std::string const &instance_name="") const
static ConsumesInfo * instance()
Handle< PROD > getHandle(SelectorBase const &) const
TypeLabel type_label_for(TypeID const typeID, std::string const &instance, bool const supportsView, ModuleDescription const &md)
const std::string instance
bool get(SelectorBase const &, Handle< PROD > &result) const
BranchType const branchType_
std::vector< InputTag > getInputTags(SelectorBase const &selector=MatchAllSelector{}) const
bool isValid() const noexcept
PMValue(std::unique_ptr< EDProduct > &&p, BranchDescription const &b, RangeSet const &r)
std::vector< ProductToken< PROD > > getProductTokens(SelectorBase const &selector=MatchAllSelector{}) const
std::unique_ptr< EDProduct > prod_
static RangeSet forSubRun(SubRunID)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
T const * product() const
Provenance const * provenance() const
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
IDNumber_t< Level::SubRun > SubRunNumber_t
void getManyByType(std::vector< Handle< PROD >> &results) const
ModuleDescription const & md_
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
std::string canonicalProductName(std::string const &friendlyClassName, std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName)
auto transform_all(Container &, OutputIt, UnaryOp)
bool removeCachedProduct(Handle< PROD > &) const
void validateConsumedProduct(BranchType const, ModuleDescription const &, ProductInfo const &productInfo)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
BranchDescription const & bd_
static constexpr ProductID invalid() noexcept
cet::exempt_ptr< Group const > result() const
static RangeSet invalid()
IDNumber_t< Level::Event > EventNumber_t
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
ModuleContext const & mc_
bool getByToken(ProductToken< PROD > const &token, Handle< PROD > &result) const
PROD const & getProduct(InputTag const &tag) const
second_as<> second
Type of time stored in seconds, in double precision.
constexpr bool range_sets_supported(BranchType const bt)
static RangeSet forRun(RunID)
bool const recordParents_
IDNumber_t< Level::Run > RunNumber_t