DataViewImpl.h
Go to the documentation of this file.
1 #ifndef art_Framework_Principal_DataViewImpl_h
2 #define art_Framework_Principal_DataViewImpl_h
3 // vim: set sw=2 expandtab :
4 
37 #include "cetlib/HorizontalRule.h"
39 #include "cetlib/exempt_ptr.h"
40 #include "cetlib_except/exception.h"
41 #include "fhiclcpp/fwd.h"
42 
43 #include <cassert>
44 #include <cstddef>
45 #include <map>
46 #include <memory>
47 #include <mutex>
48 #include <ostream>
49 #include <set>
50 #include <string>
51 #include <utility>
52 #include <vector>
53 
54 namespace art {
55 
56  class EDProductGetter;
57 
58  namespace detail {
59  class Analyzer;
60  class Filter;
61  class Producer;
62  }
63 
64  class DataViewImpl {
65 
66  // Give access to movePutProductsToPrincipal(...).
67  friend class detail::Analyzer;
68  friend class detail::Filter;
69  friend class detail::Producer;
70  friend class ResultsProducer;
71  friend class ProducingService;
72 
73  public:
74  ~DataViewImpl();
75  explicit DataViewImpl(BranchType bt,
76  Principal const& p,
77  ModuleContext const& mc,
78  bool recordParents,
79  RangeSet const& rs = RangeSet::invalid());
80  DataViewImpl(DataViewImpl const&) = delete;
81  DataViewImpl(DataViewImpl&&) = delete;
82  DataViewImpl& operator=(DataViewImpl const&) = delete;
83  DataViewImpl& operator=(DataViewImpl&) = delete;
84 
85  // Miscellaneous functionality
86  RunID runID() const;
87  SubRunID subRunID() const;
88  EventID eventID() const;
89  RunNumber_t run() const;
90  SubRunNumber_t subRun() const;
91  EventNumber_t event() const;
92  Timestamp const& beginTime() const;
93  Timestamp const& endTime() const;
94  Timestamp time() const;
95  bool isRealData() const;
96  EventAuxiliary::ExperimentType experimentType() const;
97  History const& history() const;
98  ProcessHistoryID const& processHistoryID() const;
99  ProcessHistory const& processHistory() const;
100  template <typename PROD>
101  bool removeCachedProduct(Handle<PROD>&) const;
102  EDProductGetter const* productGetter(ProductID const pid) const;
103  bool getProcessParameterSet(std::string const& process,
104  fhicl::ParameterSet&) const;
105 
106  // Product retrieval
107  template <typename PROD>
108  PROD const& getProduct(InputTag const& tag) const;
109  template <typename PROD>
110  PROD const& getProduct(ProductToken<PROD> const& token) const;
111 
112  // Product retrieval with provenance access
113  template <typename PROD>
114  Handle<PROD> getHandle(SelectorBase const&) const;
115  template <typename PROD>
116  Handle<PROD> getHandle(ProductID const pid) const;
117  template <typename PROD>
118  Handle<PROD> getHandle(InputTag const& tag) const;
119  template <typename PROD>
120  Handle<PROD> getHandle(ProductToken<PROD> const& token) const;
121 
122  // Product retrieval with provenance access (guaranteed valid handle)
123  template <typename PROD>
124  ValidHandle<PROD> getValidHandle(InputTag const& tag) const;
125  template <typename PROD>
126  ValidHandle<PROD> getValidHandle(ProductToken<PROD> const& token) const;
127 
128  // Multiple product retrievals
129  template <typename PROD>
130  std::vector<InputTag> getInputTags(
131  SelectorBase const& selector = MatchAllSelector{}) const;
132  template <typename PROD>
133  std::vector<ProductToken<PROD>> getProductTokens(
134  SelectorBase const& selector = MatchAllSelector{}) const;
135  template <typename PROD>
136  std::vector<Handle<PROD>> getMany(
137  SelectorBase const& selector = MatchAllSelector{}) const;
138 
139  // Obsolete product-retrieval (will be deprecated)
140  template <typename PROD>
141  bool get(SelectorBase const&, Handle<PROD>& result) const;
142  template <typename PROD>
143  bool get(ProductID const pid, Handle<PROD>& result) const;
144  template <typename PROD>
145  bool getByLabel(std::string const& label,
146  std::string const& instance,
147  Handle<PROD>& result) const;
148  template <typename PROD>
149  bool getByLabel(std::string const& label,
150  std::string const& instance,
151  std::string const& process,
152  Handle<PROD>& result) const;
153  template <typename PROD>
154  bool getByLabel(InputTag const& tag, Handle<PROD>& result) const;
155 
156  // Deprecated
157  template <typename PROD>
158  [[deprecated(
159  "\n\nart warning: Please use getHandle<T>(token) instead.\n\n")]] bool
160  getByToken(ProductToken<PROD> const& token, Handle<PROD>& result) const;
161  template <typename PROD>
162  [[deprecated("\n\nart warning: Please use getHandle<T>(tag).product() "
163  "instead.\n\n")]] PROD const*
164  getPointerByLabel(InputTag const& tag) const;
165  template <typename PROD>
166  [[deprecated(
167  "\n\nart warning: Please use getMany<T>(selector) instead.\n\n")]] void
168  getMany(SelectorBase const&, std::vector<Handle<PROD>>& results) const;
169  template <typename PROD>
170  [[deprecated("\n\nart warning: Please use getMany<T>() instead.\n\n")]] void
171  getManyByType(std::vector<Handle<PROD>>& results) const;
172 
173  // View retrieval
174  template <typename ELEMENT>
175  std::size_t getView(std::string const& moduleLabel,
176  std::string const& productInstanceName,
177  std::string const& processName,
178  std::vector<ELEMENT const*>& result) const;
179  template <typename ELEMENT>
180  std::size_t getView(std::string const& moduleLabel,
181  std::string const& productInstanceName,
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>
187  std::size_t getView(ViewToken<ELEMENT> const&,
188  std::vector<ELEMENT const*>& result) const;
189  template <typename ELEMENT>
190  bool getView(std::string const& moduleLabel,
191  std::string const& productInstanceName,
192  std::string const& processName,
193  View<ELEMENT>& result) const;
194  template <typename ELEMENT>
195  bool getView(std::string const& moduleLabel,
196  std::string const& productInstanceName,
197  View<ELEMENT>& result) const;
198  template <typename ELEMENT>
199  bool getView(InputTag const&, View<ELEMENT>& result) const;
200  template <typename ELEMENT>
201  bool getView(ViewToken<ELEMENT> const&, View<ELEMENT>& result) const;
202 
203  // Product ID and description
204  template <typename T>
205  ProductID getProductID(std::string const& instance_name = "") const;
206 
207  cet::exempt_ptr<BranchDescription const> getProductDescription(
208  ProductID) const;
209 
210  // Product insertion - all processing levels
211  template <typename PROD>
212  ProductID put(std::unique_ptr<PROD>&& edp,
213  std::string const& instance = {});
214 
215  // Product insertion -- run/subrun
216  template <typename PROD>
217  ProductID put(std::unique_ptr<PROD>&& edp,
218  std::string const& instance,
219  RangeSet const& rs);
220 
221  // Product insertion - run
222  template <typename PROD>
223  ProductID put(std::unique_ptr<PROD>&& edp,
224  FullSemantic<Level::Run> semantic);
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,
233  std::string const& instance,
235  template <typename PROD>
236  ProductID put(std::unique_ptr<PROD>&& edp,
237  std::string const& instance,
239  template <typename PROD>
240  ProductID put(std::unique_ptr<PROD>&& edp,
241  std::string const& instance,
243 
244  // Product insertion - subrun
245  template <typename PROD>
246  ProductID put(std::unique_ptr<PROD>&& edp,
247  FullSemantic<Level::SubRun> semantic);
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,
256  std::string const& instance,
258  template <typename PROD>
259  ProductID put(std::unique_ptr<PROD>&& edp,
260  std::string const& instance,
262  template <typename PROD>
263  ProductID put(std::unique_ptr<PROD>&& edp,
264  std::string const& instance,
266 
267  void movePutProductsToPrincipal(Principal& principal);
268  void movePutProductsToPrincipal(
269  Principal& principal,
270  bool const checkProducts,
271  std::map<TypeLabel, BranchDescription> const* expectedProducts);
272 
273  private:
274  struct PMValue {
275  PMValue(std::unique_ptr<EDProduct>&& p,
276  BranchDescription const& b,
277  RangeSet const& r)
278  : prod_{std::move(p)}, bd_{b}, rs_{r}
279  {}
280  std::unique_ptr<EDProduct> prod_;
283  };
284 
285  std::string const& getProcessName_(std::string const&) const;
286  BranchDescription const& getProductDescription_(
287  TypeID const& type,
288  std::string const& instance,
289  bool const alwaysEnableLookupOfProducedProducts = false) const;
290  void recordAsParent_(cet::exempt_ptr<Group const> grp) const;
291  cet::exempt_ptr<Group const> getContainerForView_(
292  TypeID const&,
293  std::string const& moduleLabel,
294  std::string const& productInstanceName,
295  ProcessTag const& processTag) const;
296 
297  // MEMBER DATA
298  private:
299  // Protects use of retrievedProducts_,
300  // putProducts_, and rangeSet_.
301  mutable std::recursive_mutex mutex_{};
302 
303  // Is this an Event, a Run, a SubRun, or a Results.
305 
306  // The principal we are operating on.
308 
309  // The context of the currently processing module.
311 
312  // The module we were created for.
314 
315  // If we are constructed as a non-const Event, then we
316  // can be used to put products into the Principal, so
317  // we need to record retrieved products into
318  // retrievedProducts_ to track parentage of any
319  // products we put.
320  bool const recordParents_;
321 
322  // The RangeSet to be used by any products put by the user.
323  // Cannot be const because we call collapse() on it.
325 
326  // The set of products retrieved from the principal.
327  // We use this to track parentage of any products
328  // we put.
329  mutable std::set<ProductID> retrievedProducts_{};
330 
331  // The set of products which have been put by the user.
332  // We own them.
333  std::map<TypeLabel, PMValue> putProducts_{};
334  };
335 
336  template <typename PROD>
337  ProductID
339  {
340  std::lock_guard lock{mutex_};
341  TypeID const type{typeid(PROD)};
342  auto const& product_name = canonicalProductName(
343  type.friendlyClassName(), md_.moduleLabel(), instance, md_.processName());
344  ProductID const pid{product_name};
345  auto desc = principal_.getProductDescription(pid);
346  if (!desc) {
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()
354  << "'\n"
355  << " product instance name: '" << instance << "'\n"
356  << " branch type: '" << branchType_ << "'\n";
357  }
358  // The description object is owned by either the source or the
359  // event processor, whose lifetimes exceed that of the
360  // DataViewImpl object. It is therefore safe to dereference.
361  return desc->productID();
362  }
363 
364  // =========================================================================
365  template <typename PROD>
366  PROD const&
368  {
369  return *getValidHandle<PROD>(tag);
370  }
371 
372  template <typename PROD>
373  PROD const&
375  {
376  return *getValidHandle(token);
377  }
378 
379  // =========================================================================
380  template <typename PROD>
382  DataViewImpl::getHandle(SelectorBase const& sel) const
383  {
384  std::lock_guard lock{mutex_};
385  // We do *not* track whether consumes was called for a SelectorBase.
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());
392  }
393  return Handle<PROD>{qr};
394  }
395 
396  template <typename PROD>
399  {
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());
405  }
406  return Handle<PROD>{qr};
407  }
408 
409  template <typename PROD>
412  {
413  std::lock_guard lock{mutex_};
414  auto const wrapped = WrappedTypeID::make<PROD>();
415  ProcessTag const processTag{tag.process(), md_.processName()};
417  wrapped.product_type,
418  tag.label(),
419  tag.instance(),
420  processTag};
421  ConsumesInfo::instance()->validateConsumedProduct(branchType_, md_, pinfo);
422  GroupQueryResult qr = principal_.getByLabel(
423  mc_, wrapped, tag.label(), tag.instance(), processTag);
424  bool const ok = qr.succeeded() && !qr.failed();
425  if (recordParents_ && ok) {
426  recordAsParent_(qr.result());
427  }
428  return Handle<PROD>{qr};
429  }
430 
431  template <typename PROD>
434  {
435  return getHandle<PROD>(token.inputTag_);
436  }
437 
438  // =========================================================================
439  template <typename PROD>
442  {
443  Handle<PROD> h;
444  getByLabel(tag, h);
445  return ValidHandle{h.product(), *h.provenance()};
446  }
447 
448  template <typename PROD>
451  {
452  return getValidHandle<PROD>(token.inputTag_);
453  }
454 
455  template <typename PROD>
456  std::vector<InputTag>
457  DataViewImpl::getInputTags(SelectorBase const& selector) const
458  {
459  auto const wrapped = WrappedTypeID::make<PROD>();
460  ProcessTag const processTag{"", md_.processName()};
461  return principal_.getInputTags(mc_, wrapped, selector, processTag);
462  }
463 
464  template <typename PROD>
465  std::vector<ProductToken<PROD>>
466  DataViewImpl::getProductTokens(SelectorBase const& selector) const
467  {
468  auto const tags = getInputTags<PROD>(selector);
469  std::vector<ProductToken<PROD>> tokens;
470  tokens.reserve(tags.size());
471  cet::transform_all(tags, back_inserter(tokens), [](auto const& tag) {
472  return ProductToken<PROD>{tag};
473  });
474  return tokens;
475  }
476 
477  template <typename PROD>
478  std::vector<Handle<PROD>>
479  DataViewImpl::getMany(SelectorBase const& sel) const
480  {
481  std::lock_guard lock{mutex_};
482  auto const wrapped = WrappedTypeID::make<PROD>();
484  branchType_,
485  md_,
486  ProductInfo{ProductInfo::ConsumableType::Many, wrapped.product_type});
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());
493  }
494  }
495  return products;
496  }
497 
498  template <typename ELEMENT>
499  std::size_t
500  DataViewImpl::getView(std::string const& moduleLabel,
501  std::string const& productInstanceName,
502  std::string const& processName,
503  std::vector<ELEMENT const*>& result) const
504  {
505  std::lock_guard lock{mutex_};
506  std::size_t const orig_size = result.size();
507  auto grp = getContainerForView_(TypeID{typeid(ELEMENT)},
508  moduleLabel,
509  productInstanceName,
510  ProcessTag{processName, md_.processName()});
511  if (recordParents_) {
512  recordAsParent_(grp);
513  }
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));
518  }
519  result = std::move(castedView);
520  return result.size() - orig_size;
521  }
522 
523  template <typename ELEMENT>
524  std::size_t
525  DataViewImpl::getView(std::string const& moduleLabel,
526  std::string const& productInstanceName,
527  std::vector<ELEMENT const*>& result) const
528  {
529  return getView(moduleLabel, productInstanceName, {}, result);
530  }
531 
532  template <typename ELEMENT>
533  std::size_t
535  std::vector<ELEMENT const*>& result) const
536  {
537  return getView(tag.label(), tag.instance(), tag.process(), result);
538  }
539 
540  template <typename ELEMENT>
541  std::size_t
543  std::vector<ELEMENT const*>& result) const
544  {
545  return getView(token.inputTag_.label(),
546  token.inputTag_.instance(),
547  token.inputTag_.process(),
548  result);
549  }
550 
551  template <typename ELEMENT>
552  bool
553  DataViewImpl::getView(std::string const& moduleLabel,
554  std::string const& productInstanceName,
555  std::string const& processName,
556  View<ELEMENT>& result) const
557  {
558  std::lock_guard lock{mutex_};
559  auto grp = getContainerForView_(TypeID{typeid(ELEMENT)},
560  moduleLabel,
561  productInstanceName,
562  ProcessTag{processName, md_.processName()});
563  if (recordParents_) {
564  recordAsParent_(grp);
565  }
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));
570  }
571  result = View{move(castedView), grp->productID(), grp->uniqueProduct()};
572  return true;
573  }
574 
575  template <typename ELEMENT>
576  bool
577  DataViewImpl::getView(std::string const& moduleLabel,
578  std::string const& productInstanceName,
579  View<ELEMENT>& result) const
580  {
581  return getView(moduleLabel, productInstanceName, {}, result);
582  }
583 
584  template <typename ELEMENT>
585  bool
587  {
588  return getView(tag.label(), tag.instance(), tag.process(), result);
589  }
590 
591  template <typename ELEMENT>
592  bool
594  View<ELEMENT>& result) const
595  {
596  return getView(token.inputTag_.label(),
597  token.inputTag_.instance(),
598  token.inputTag_.process(),
599  result);
600  }
601 
602  // =======================================================================
603  // Obsolete (will be deprecated)
604  template <typename PROD>
605  bool
606  DataViewImpl::get(SelectorBase const& sel, Handle<PROD>& result) const
607  {
608  result = getHandle<PROD>(sel);
609  return static_cast<bool>(result);
610  }
611 
612  template <typename PROD>
613  bool
615  {
616  result = getHandle<PROD>(pid);
617  return static_cast<bool>(result);
618  }
619 
620  template <typename PROD>
621  bool
623  std::string const& productInstanceName,
624  std::string const& processName,
625  Handle<PROD>& result) const
626  {
627  result = getHandle<PROD>({moduleLabel, productInstanceName, processName});
628  return static_cast<bool>(result);
629  }
630 
631  template <typename PROD>
632  bool
634  std::string const& instance,
635  Handle<PROD>& result) const
636  {
637  result = getHandle<PROD>({moduleLabel, instance});
638  return static_cast<bool>(result);
639  }
640 
641  template <typename PROD>
642  bool
644  {
645  result = getHandle<PROD>(tag);
646  return static_cast<bool>(result);
647  }
648 
649  template <typename PROD>
650  PROD const*
652  {
653  Handle<PROD> h;
654  getByLabel(tag, h);
655  return h.product();
656  }
657 
658  template <typename PROD>
659  bool
661  Handle<PROD>& result) const
662  {
663  result = getHandle(token);
664  return static_cast<bool>(result);
665  }
666 
667  template <typename PROD>
668  void
669  DataViewImpl::getMany(SelectorBase const& sel,
670  std::vector<Handle<PROD>>& results) const
671  {
672  results = getMany<PROD>(sel);
673  }
674 
675  template <typename PROD>
676  void
678  {
679  results = getMany<PROD>();
680  }
681 
682  // =======================================================================
683  // Product-insertion implementation
684  template <typename PROD>
685  ProductID
686  DataViewImpl::put(std::unique_ptr<PROD>&& edp, std::string const& instance)
687  {
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";
695  }
696  auto const& bd = getProductDescription_(tid, instance, true);
697  assert(bd.productID() != ProductID::invalid());
698  auto const typeLabel =
700  auto wp = std::make_unique<Wrapper<PROD>>(move(edp));
701  auto const& rs = detail::range_sets_supported(branchType_) ?
702  rangeSet_.collapse() :
704  bool const result =
705  putProducts_.try_emplace(typeLabel, PMValue{std::move(wp), bd, rs})
706  .second;
707  if (!result) {
708  cet::HorizontalRule rule{30};
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"
713  << rule('=') << '\n'
714  << bd << rule('=') << '\n';
715  }
716  return bd.productID();
717  }
718 
719  template <typename PROD>
720  ProductID
721  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
722  FullSemantic<Level::Run> const semantic)
723  {
724  return put(move(edp), "", semantic);
725  }
726 
727  template <typename PROD>
728  ProductID
729  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
730  FragmentSemantic<Level::Run> const semantic)
731  {
732  return put(move(edp), "", semantic);
733  }
734 
735  template <typename PROD>
736  ProductID
737  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
739  {
740  return put(move(edp), "", std::move(semantic));
741  }
742 
743  template <typename PROD>
744  ProductID
745  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
746  std::string const& instance,
748  {
749  return put(move(edp), instance, RangeSet::forRun(runID()));
750  }
751 
752  template <typename PROD>
753  ProductID
754  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
755  std::string const& instance,
757  {
758  std::lock_guard lock{mutex_};
759  static_assert(
761  "\n\n"
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()) {
767  throw art::Exception{errors::ProductPutFailure, "Run::put"}
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";
775  }
776  return put(move(edp), instance, rangeSet_);
777  }
778 
779  template <typename PROD>
780  ProductID
781  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
782  std::string const& instance,
784  {
785  std::lock_guard lock{mutex_};
786  static_assert(
788  "\n\n"
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()) {
794  throw art::Exception{errors::ProductPutFailure, "Run::put"}
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";
799  }
800  return put(move(edp), instance, semantic.rs);
801  }
802 
803  template <typename PROD>
804  ProductID
805  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
806  FullSemantic<Level::SubRun> const semantic)
807  {
808  return put(move(edp), "", semantic);
809  }
810 
811  template <typename PROD>
812  ProductID
813  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
814  FragmentSemantic<Level::SubRun> const semantic)
815  {
816  return put(move(edp), "", semantic);
817  }
818 
819  template <typename PROD>
820  ProductID
821  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
823  {
824  return put(move(edp), "", std::move(semantic));
825  }
826 
827  template <typename PROD>
828  ProductID
829  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
830  std::string const& instance,
832  {
833  return put(move(edp), instance, RangeSet::forSubRun(subRunID()));
834  }
835 
836  template <typename PROD>
837  ProductID
838  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
839  std::string const& instance,
841  {
842  std::lock_guard lock{mutex_};
843  static_assert(
845  "\n\n"
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()) {
851  throw art::Exception(errors::ProductPutFailure, "SubRun::put")
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";
859  }
860  return put(move(edp), instance, rangeSet_);
861  }
862 
863  template <typename PROD>
864  ProductID
865  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
866  std::string const& instance,
868  {
869  std::lock_guard lock{mutex_};
870  static_assert(
872  "\n\n"
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()) {
878  throw art::Exception{errors::ProductPutFailure, "Run::put"}
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";
883  }
884  return put(move(edp), instance, semantic.rs);
885  }
886 
887  template <typename PROD>
888  ProductID
889  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
890  std::string const& instance,
891  RangeSet const& rs)
892  {
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";
900  }
901  if (!rs.is_valid()) {
902  throw art::Exception{errors::ProductPutFailure, "SubRun::put"}
903  << "\nCannot put a product with an invalid RangeSet.\n"
904  << "Please contact artists@fnal.gov.\n";
905  }
906  auto const& bd = getProductDescription_(tid, instance, true);
907  assert(bd.productID() != ProductID::invalid());
908  auto const typeLabel =
910  auto wp = std::make_unique<Wrapper<PROD>>(move(edp));
911  auto result =
912  putProducts_.try_emplace(typeLabel, PMValue{move(wp), bd, rs}).second;
913  if (!result) {
914  constexpr cet::HorizontalRule rule{30};
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"
919  << rule('=') << '\n'
920  << bd << rule('=') << '\n';
921  }
922  return bd.productID();
923  }
924 
925  template <typename PROD>
926  bool
928  {
929  std::lock_guard lock{mutex_};
930  bool result{false};
931  if (h.isValid() && !h.provenance()->produced()) {
932  principal_.removeCachedProduct(h.id());
933  h.clear();
934  result = true;
935  }
936  return result;
937  }
938 
939  template <typename PROD>
940  std::ostream&
941  operator<<(std::ostream& os, Handle<PROD> const& h)
942  {
943  os << h.product() << " " << h.provenance() << " " << h.id();
944  return os;
945  }
946 
947 } // namespace art
948 
949 #endif /* art_Framework_Principal_DataViewImpl_h */
950 
951 // Local Variables:
952 // mode: c++
953 // End:
Principal const & principal_
Definition: DataViewImpl.h:307
PROD const * getPointerByLabel(InputTag const &tag) const
Definition: DataViewImpl.h:651
static QCString result
ProductID getProductID(std::string const &instance_name="") const
Definition: DataViewImpl.h:338
static ConsumesInfo * instance()
Definition: ConsumesInfo.cc:24
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
TypeLabel type_label_for(TypeID const typeID, std::string const &instance, bool const supportsView, ModuleDescription const &md)
struct vector vector
const std::string instance
bool get(SelectorBase const &, Handle< PROD > &result) const
Definition: DataViewImpl.h:606
std::string const & instance() const noexcept
Definition: InputTag.cc:85
bool is_valid() const
Definition: RangeSet.cc:117
std::string const & process() const noexcept
Definition: InputTag.cc:91
BranchType const branchType_
Definition: DataViewImpl.h:304
std::vector< InputTag > getInputTags(SelectorBase const &selector=MatchAllSelector{}) const
Definition: DataViewImpl.h:457
bool isValid() const noexcept
Definition: Handle.h:191
PMValue(std::unique_ptr< EDProduct > &&p, BranchDescription const &b, RangeSet const &r)
Definition: DataViewImpl.h:275
std::vector< ProductToken< PROD > > getProductTokens(SelectorBase const &selector=MatchAllSelector{}) const
Definition: DataViewImpl.h:466
std::string const & label() const noexcept
Definition: InputTag.cc:79
def process(f, kind)
Definition: search.py:254
std::unique_ptr< EDProduct > prod_
Definition: DataViewImpl.h:280
static RangeSet forSubRun(SubRunID)
Definition: RangeSet.cc:57
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
T const * product() const
Definition: Handle.h:163
bt
Definition: tracks.py:83
Provenance const * provenance() const
Definition: Handle.h:205
InputTag inputTag_
Definition: ProductToken.h:90
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
Definition: DataViewImpl.h:479
def move(depos, offset)
Definition: depos.py:107
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:119
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:677
p
Definition: test.py:223
ModuleDescription const & md_
Definition: DataViewImpl.h:313
Definition: fwd.h:46
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
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
Definition: DataViewImpl.h:927
void validateConsumedProduct(BranchType const, ModuleDescription const &, ProductInfo const &productInfo)
InputTag inputTag_
Definition: ProductToken.h:69
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
BranchDescription const & bd_
Definition: DataViewImpl.h:281
void clear()
Definition: Handle.h:236
static constexpr ProductID invalid() noexcept
Definition: ProductID.h:26
cet::exempt_ptr< Group const > result() const
static RangeSet invalid()
Definition: RangeSet.cc:45
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
BranchType
Definition: BranchType.h:20
static bool * b
Definition: config.cpp:1043
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
Definition: DataViewImpl.h:500
ModuleContext const & mc_
Definition: DataViewImpl.h:310
bool getByToken(ProductToken< PROD > const &token, Handle< PROD > &result) const
Definition: DataViewImpl.h:660
PROD const & getProduct(InputTag const &tag) const
Definition: DataViewImpl.h:367
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:85
ProductID id() const
Definition: Handle.h:212
constexpr bool range_sets_supported(BranchType const bt)
static RangeSet forRun(RunID)
Definition: RangeSet.cc:51
bool const recordParents_
Definition: DataViewImpl.h:320
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120