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 
16 #include "art/Utilities/Globals.h"
43 #include "cetlib/HorizontalRule.h"
45 #include "cetlib/exempt_ptr.h"
46 #include "cetlib_except/exception.h"
47 #include "fhiclcpp/ParameterSet.h"
48 #include "hep_concurrency/tsan.h"
49 
50 #include <algorithm>
51 #include <cassert>
52 #include <cstddef>
53 #include <cstdlib>
54 #include <map>
55 #include <memory>
56 #include <mutex>
57 #include <ostream>
58 #include <set>
59 #include <string>
60 #include <utility>
61 #include <vector>
62 
63 namespace art {
64 
65  class EDProductGetter;
66  class ResultsProducer;
67 
68  namespace detail {
69  class Analyzer;
70  class Filter;
71  class Producer;
72  }
73 
74  class DataViewImpl {
75 
76  // Give access to movePutProductsToPrincipal(...).
77  friend class detail::Analyzer;
78  friend class detail::Filter;
79  friend class detail::Producer;
80  friend class ResultsProducer;
81  friend class ProducingService;
82 
83  // TYPES
84  public:
85  struct PMValue {
86 
87  PMValue(std::unique_ptr<EDProduct>&& p,
88  BranchDescription const& b,
89  RangeSet const& r)
90  : prod_{std::move(p)}, bd_{b}, rs_{r}
91  {}
92  std::unique_ptr<EDProduct> prod_;
95  };
96 
97  // MEMBER FUNCTIONS -- Special Member Functions
98  public:
99  ~DataViewImpl();
100  explicit DataViewImpl(BranchType bt,
101  Principal const& p,
102  ModuleContext const& mc,
103  bool recordParents,
104  RangeSet const& rs = RangeSet::invalid());
105  DataViewImpl(DataViewImpl const&) = delete;
106  DataViewImpl(DataViewImpl&&) = delete;
107  DataViewImpl& operator=(DataViewImpl const&) = delete;
108  DataViewImpl& operator=(DataViewImpl&) = delete;
109 
110  // MEMBER FUNCTIONS -- User-facing API - misc
111  public:
112  RunID runID() const;
113  SubRunID subRunID() const;
114  EventID eventID() const;
115  RunNumber_t run() const;
116  SubRunNumber_t subRun() const;
117  EventNumber_t event() const;
118  Timestamp const& beginTime() const;
119  Timestamp const& endTime() const;
120  Timestamp time() const;
121  bool isRealData() const;
122  EventAuxiliary::ExperimentType experimentType() const;
123  History const& history() const;
124  ProcessHistoryID const& processHistoryID() const;
125  ProcessHistory const& processHistory() const;
126  template <typename PROD>
127  bool removeCachedProduct(Handle<PROD>&) const;
128  EDProductGetter const* productGetter(ProductID const pid) const;
129  bool getProcessParameterSet(std::string const& process,
130  fhicl::ParameterSet&) const;
131 
132  // MEMBER FUNCTIONS -- User-facing API -- get*
133  public:
134  template <typename PROD>
135  bool get(SelectorBase const&, Handle<PROD>& result) const;
136  template <typename PROD>
137  bool get(ProductID const pid, Handle<PROD>& result) const;
138  template <typename PROD>
139  bool getByLabel(std::string const& label,
140  std::string const& instance,
141  Handle<PROD>& result) const;
142  template <typename PROD>
143  bool getByLabel(std::string const& label,
144  std::string const& instance,
145  std::string const& process,
146  Handle<PROD>& result) const;
147 
148  // MEMBER FUNCTIONS -- User-facing API -- get*, using InputTag
149  public:
150  template <typename PROD>
151  PROD const& getByLabel(InputTag const& tag) const;
152  template <typename PROD>
153  bool getByLabel(InputTag const& tag, Handle<PROD>& result) const;
154  template <typename PROD>
155  PROD const* getPointerByLabel(InputTag const& tag) const;
156  template <typename PROD>
157  ValidHandle<PROD> getValidHandle(InputTag const& tag) const;
158 
159  // MEMBER FUNCTIONS -- User-facing API -- get*, using ProductToken
160  public:
161  template <typename PROD>
162  bool getByToken(ProductToken<PROD> const&, Handle<PROD>& result) const;
163  template <typename PROD>
164  ValidHandle<PROD> getValidHandle(ProductToken<PROD> const&) const;
165 
166  // MEMBER FUNCTIONS -- User-facing API -- getProductTokens/getMany*
167  public:
168  template <typename PROD>
169  std::vector<InputTag> getInputTags(
170  SelectorBase const& selector = MatchAllSelector{}) const;
171  template <typename PROD>
172  std::vector<ProductToken<PROD>> getProductTokens(
173  SelectorBase const& selector = MatchAllSelector{}) const;
174  template <typename PROD>
175  std::vector<Handle<PROD>> getMany(
176  SelectorBase const& selector = MatchAllSelector{}) const;
177  template <typename PROD>
178  void getMany(SelectorBase const&, std::vector<Handle<PROD>>& results) const;
179  template <typename PROD>
180  void getManyByType(std::vector<Handle<PROD>>& results) const;
181 
182  // MEMBER FUNCTIONS -- User-facing API -- getView
183  public:
184  template <typename ELEMENT>
185  std::size_t getView(std::string const& moduleLabel,
186  std::string const& productInstanceName,
187  std::string const& processName,
188  std::vector<ELEMENT const*>& result) const;
189  template <typename ELEMENT>
190  std::size_t getView(std::string const& moduleLabel,
191  std::string const& productInstanceName,
192  std::vector<ELEMENT const*>& result) const;
193  template <typename ELEMENT>
194  std::size_t getView(InputTag const&,
195  std::vector<ELEMENT const*>& result) const;
196  template <typename ELEMENT>
197  std::size_t getView(ViewToken<ELEMENT> const&,
198  std::vector<ELEMENT const*>& result) const;
199  template <typename ELEMENT>
200  bool getView(std::string const& moduleLabel,
201  std::string const& productInstanceName,
202  std::string const& processName,
203  View<ELEMENT>& result) const;
204  template <typename ELEMENT>
205  bool getView(std::string const& moduleLabel,
206  std::string const& productInstanceName,
207  View<ELEMENT>& result) const;
208  template <typename ELEMENT>
209  bool getView(InputTag const&, View<ELEMENT>& result) const;
210  template <typename ELEMENT>
211  bool getView(ViewToken<ELEMENT> const&, View<ELEMENT>& result) const;
212 
213  // MEMBER FUNCTIONS -- User-facing API -- getPtrVector
214  public:
215  template <typename ELEMENT>
216  void getPtrVector(std::string const& moduleLabel,
217  std::string const& productInstanceName,
218  std::string const& processName,
219  PtrVector<ELEMENT>& result) const;
220  template <typename ELEMENT>
221  void getPtrVector(std::string const& moduleLabel,
222  std::string const& productInstanceName,
223  PtrVector<ELEMENT>& result) const;
224  template <typename ELEMENT>
225  void getPtrVector(InputTag const&, PtrVector<ELEMENT>& result) const;
226  template <typename ELEMENT>
227  void getPtrVector(ViewToken<ELEMENT> const&,
228  PtrVector<ELEMENT>& result) const;
229 
230  // MEMBER FUNCTIONS -- User-facing API -- getProductID
231  public:
232  template <typename T>
233  ProductID getProductID(std::string const& instance_name = "") const;
234 
235  cet::exempt_ptr<BranchDescription const> getProductDescription(
236  ProductID) const;
237 
238  // MEMBER FUNCTIONS -- User-facing API -- put*, Run product
239  public:
240  template <typename PROD>
241  ProductID put(std::unique_ptr<PROD>&& edp,
242  FullSemantic<Level::Run> const semantic);
243  template <typename PROD>
244  ProductID put(std::unique_ptr<PROD>&& edp,
245  FragmentSemantic<Level::Run> const semantic);
246  template <typename PROD>
247  ProductID put(std::unique_ptr<PROD>&& edp,
249  template <typename PROD>
250  ProductID put(std::unique_ptr<PROD>&& edp,
251  std::string const& instance,
253  template <typename PROD>
254  ProductID put(std::unique_ptr<PROD>&& edp,
255  std::string const& instance,
257  template <typename PROD>
258  ProductID put(std::unique_ptr<PROD>&& edp,
259  std::string const& instance,
261 
262  // MEMBER FUNCTIONS -- User-facing API -- put*, SubRun product
263  public:
264  template <typename PROD>
265  ProductID put(std::unique_ptr<PROD>&& edp,
266  FullSemantic<Level::SubRun> const semantic);
267  template <typename PROD>
268  ProductID put(std::unique_ptr<PROD>&& edp,
269  FragmentSemantic<Level::SubRun> const semantic);
270  template <typename PROD>
271  ProductID put(std::unique_ptr<PROD>&& edp,
273  template <typename PROD>
274  ProductID put(std::unique_ptr<PROD>&& edp,
275  std::string const& instance,
277  template <typename PROD>
278  ProductID put(std::unique_ptr<PROD>&& edp,
279  std::string const& instance,
281  template <typename PROD>
282  ProductID put(std::unique_ptr<PROD>&& edp,
283  std::string const& instance,
285 
286  // MEMBER FUNCTIONS -- User-facing API -- put*, Event product
287  public:
288  template <typename PROD>
289  ProductID put(std::unique_ptr<PROD>&& edp);
290  template <typename PROD>
291  ProductID put(std::unique_ptr<PROD>&& edp, std::string const& instance);
292  template <typename PROD>
293  ProductID put(std::unique_ptr<PROD>&& edp,
294  std::string const& instance,
295  RangeSet const& rs);
296 
297  void movePutProductsToPrincipal(Principal& principal);
298  void movePutProductsToPrincipal(
299  Principal& principal,
300  bool const checkProducts,
301  std::map<TypeLabel, BranchDescription> const* expectedProducts);
302 
303  // MEMBER FUNCTIONS -- implementation details
304  private:
305  std::string const& getProcessName_(std::string const&) const;
306  BranchDescription const& getProductDescription_(
307  TypeID const& type,
308  std::string const& instance,
309  bool const alwaysEnableLookupOfProducedProducts = false) const;
310  void recordAsParent_(cet::exempt_ptr<Group const> grp) const;
311  cet::exempt_ptr<Group const> getContainerForView_(
312  TypeID const&,
313  std::string const& moduleLabel,
314  std::string const& productInstanceName,
315  ProcessTag const& processTag) const;
316 
317  // MEMBER DATA
318  private:
319  // Protects use of retrievedProducts_,
320  // putProducts_, and rangeSet_.
321  mutable std::recursive_mutex mutex_{};
322 
323  // Is this an Event, a Run, a SubRun, or a Results.
325 
326  // The principal we are operating on.
328 
329  // The context of the currently processing module.
331 
332  // The module we were created for.
334 
335  // If we are constructed as a non-const Event, then we
336  // can be used to put products into the Principal, so
337  // we need to record retrieved products into
338  // retrievedProducts_ to track parentage of any
339  // products we put.
340  bool const recordParents_;
341 
342  // The RangeSet to be used by any products put by the user.
343  // Cannot be const because we call collapse() on it.
345 
346  // The set of products retrieved from the principal.
347  // We use this to track parentage of any products
348  // we put.
349  mutable std::set<ProductID> retrievedProducts_{};
350 
351  // The set of products which have been put by the user.
352  // We own them.
353  std::map<TypeLabel, PMValue> putProducts_{};
354  };
355 
356  template <typename PROD>
357  ProductID
358  DataViewImpl::getProductID(std::string const& instance /* = "" */) const
359  {
360  std::lock_guard lock{mutex_};
361  TypeID const type{typeid(PROD)};
362  auto const& product_name = canonicalProductName(
363  type.friendlyClassName(), md_.moduleLabel(), instance, md_.processName());
364  ProductID const pid{product_name};
365  auto desc = principal_.getProductDescription(pid);
366  if (!desc) {
368  "DataViewImpl::getProductID: error while trying to "
369  "retrieve product description:\n")
370  << "No product is registered for\n"
371  << " process name: '" << md_.processName() << "'\n"
372  << " module label: '" << md_.moduleLabel() << "'\n"
373  << " product friendly class name: '" << type.friendlyClassName()
374  << "'\n"
375  << " product instance name: '" << instance << "'\n"
376  << " branch type: '" << branchType_ << "'\n";
377  }
378  // The description object is owned by either the source or the
379  // event processor, whose lifetimes exceed that of the
380  // DataViewImpl object. It is therefore safe to dereference.
381  return desc->productID();
382  }
383 
384  template <typename PROD>
385  bool
386  DataViewImpl::get(SelectorBase const& sel, Handle<PROD>& result) const
387  {
388  std::lock_guard lock{mutex_};
389  result.clear();
390  // We do *not* track whether consumes was called for a SelectorBase.
391  ProcessTag const processTag{"", md_.processName()};
392  auto qr = principal_.getBySelector(
393  mc_, WrappedTypeID::make<PROD>(), sel, processTag);
394  result = Handle<PROD>{qr};
395  bool const ok = qr.succeeded() && !qr.failed();
396  if (recordParents_ && ok) {
397  recordAsParent_(qr.result());
398  }
399  return ok;
400  }
401 
402  template <typename PROD>
403  bool
405  {
406  std::lock_guard lock{mutex_};
407  result.clear();
408  auto qr = principal_.getByProductID(pid);
409  result = Handle<PROD>{qr};
410  bool const ok = qr.succeeded() && !qr.failed();
411  if (recordParents_ && ok) {
412  recordAsParent_(qr.result());
413  }
414  return ok;
415  }
416 
417  template <typename PROD>
418  bool
420  std::string const& productInstanceName,
421  std::string const& processName,
422  Handle<PROD>& result) const
423  {
424  std::lock_guard lock{mutex_};
425  result.clear();
426  auto const wrapped = WrappedTypeID::make<PROD>();
427  ProcessTag const processTag{processName, md_.processName()};
429  wrapped.product_type,
430  moduleLabel,
431  productInstanceName,
432  processTag};
433  ConsumesInfo::instance()->validateConsumedProduct(branchType_, md_, pinfo);
434  GroupQueryResult qr = principal_.getByLabel(
435  mc_, wrapped, moduleLabel, productInstanceName, processTag);
436  result = Handle<PROD>{qr};
437  bool const ok = qr.succeeded() && !qr.failed();
438  if (recordParents_ && ok) {
439  recordAsParent_(qr.result());
440  }
441  return ok;
442  }
443 
444  template <typename PROD>
445  bool
447  std::string const& instance,
448  Handle<PROD>& result) const
449  {
450  return getByLabel<PROD>(moduleLabel, instance, {}, result);
451  }
452 
453  template <typename PROD>
454  bool
456  {
457  return getByLabel<PROD>(tag.label(), tag.instance(), tag.process(), result);
458  }
459 
460  template <typename PROD>
461  bool
463  Handle<PROD>& result) const
464  {
465  return getByLabel<PROD>(token.inputTag_.label(),
466  token.inputTag_.instance(),
467  token.inputTag_.process(),
468  result);
469  }
470 
471  template <typename PROD>
472  PROD const&
474  {
475  Handle<PROD> h;
476  getByLabel(tag, h);
477  return *h;
478  }
479 
480  template <typename PROD>
481  PROD const*
483  {
484  Handle<PROD> h;
485  getByLabel(tag, h);
486  return h.product();
487  }
488 
489  template <typename PROD>
492  {
493  Handle<PROD> h;
494  getByLabel(tag, h);
495  return ValidHandle{h.product(), *h.provenance()};
496  }
497 
498  template <typename PROD>
501  {
502  return getValidHandle<PROD>(token.inputTag_);
503  }
504 
505  template <typename PROD>
506  std::vector<InputTag>
507  DataViewImpl::getInputTags(SelectorBase const& selector) const
508  {
509  auto const wrapped = WrappedTypeID::make<PROD>();
510  ProcessTag const processTag{"", md_.processName()};
511  return principal_.getInputTags(mc_, wrapped, selector, processTag);
512  }
513 
514  template <typename PROD>
515  std::vector<ProductToken<PROD>>
516  DataViewImpl::getProductTokens(SelectorBase const& selector) const
517  {
518  auto const tags = getInputTags<PROD>(selector);
519  std::vector<ProductToken<PROD>> tokens;
520  tokens.reserve(tags.size());
521  cet::transform_all(tags, back_inserter(tokens), [](auto const& tag) {
522  return ProductToken<PROD>{tag};
523  });
524  return tokens;
525  }
526 
527  template <typename PROD>
528  std::vector<Handle<PROD>>
529  DataViewImpl::getMany(SelectorBase const& sel) const
530  {
531  std::lock_guard lock{mutex_};
532  auto const wrapped = WrappedTypeID::make<PROD>();
534  branchType_,
535  md_,
536  ProductInfo{ProductInfo::ConsumableType::Many, wrapped.product_type});
537  ProcessTag const processTag{"", md_.processName()};
538  std::vector<Handle<PROD>> products;
539  for (auto const& qr : principal_.getMany(mc_, wrapped, sel, processTag)) {
540  products.emplace_back(qr);
541  if (recordParents_) {
542  recordAsParent_(qr.result());
543  }
544  }
545  return products;
546  }
547 
548  template <typename PROD>
549  void
550  DataViewImpl::getMany(SelectorBase const& sel,
551  std::vector<Handle<PROD>>& results) const
552  {
553  results = getMany<PROD>(sel);
554  }
555 
556  template <typename PROD>
557  void
559  {
560  results = getMany<PROD>();
561  }
562 
563  template <typename ELEMENT>
564  std::size_t
565  DataViewImpl::getView(std::string const& moduleLabel,
566  std::string const& productInstanceName,
567  std::string const& processName,
568  std::vector<ELEMENT const*>& result) const
569  {
570  std::lock_guard lock{mutex_};
571  std::size_t const orig_size = result.size();
572  auto grp = getContainerForView_(TypeID{typeid(ELEMENT)},
573  moduleLabel,
574  productInstanceName,
575  ProcessTag{processName, md_.processName()});
576  if (recordParents_) {
577  recordAsParent_(grp);
578  }
579  std::vector<void const*> view;
580  grp->uniqueProduct()->fillView(view);
581  std::vector<ELEMENT const*> castedView;
582  for (auto p : view) {
583  castedView.push_back(static_cast<ELEMENT const*>(p));
584  }
585  result = std::move(castedView);
586  return result.size() - orig_size;
587  }
588 
589  template <typename ELEMENT>
590  std::size_t
591  DataViewImpl::getView(std::string const& moduleLabel,
592  std::string const& productInstanceName,
593  std::vector<ELEMENT const*>& result) const
594  {
595  return getView(moduleLabel, productInstanceName, {}, result);
596  }
597 
598  template <typename ELEMENT>
599  std::size_t
601  std::vector<ELEMENT const*>& result) const
602  {
603  return getView(tag.label(), tag.instance(), tag.process(), result);
604  }
605 
606  template <typename ELEMENT>
607  std::size_t
609  std::vector<ELEMENT const*>& result) const
610  {
611  return getView(token.inputTag_.label(),
612  token.inputTag_.instance(),
613  token.inputTag_.process(),
614  result);
615  }
616 
617  template <typename ELEMENT>
618  bool
619  DataViewImpl::getView(std::string const& moduleLabel,
620  std::string const& productInstanceName,
621  std::string const& processName,
622  View<ELEMENT>& result) const
623  {
624  std::lock_guard lock{mutex_};
625  auto grp = getContainerForView_(TypeID{typeid(ELEMENT)},
626  moduleLabel,
627  productInstanceName,
628  ProcessTag{processName, md_.processName()});
629  if (recordParents_) {
630  recordAsParent_(grp);
631  }
632  std::vector<void const*> view;
633  grp->uniqueProduct()->fillView(view);
634  std::vector<ELEMENT const*> castedView;
635  for (auto p : view) {
636  castedView.push_back(static_cast<ELEMENT const*>(p));
637  }
638  result = View{castedView, grp->productID(), grp->uniqueProduct()};
639  return true;
640  }
641 
642  template <typename ELEMENT>
643  bool
644  DataViewImpl::getView(std::string const& moduleLabel,
645  std::string const& productInstanceName,
646  View<ELEMENT>& result) const
647  {
648  return getView(moduleLabel, productInstanceName, {}, result);
649  }
650 
651  template <typename ELEMENT>
652  bool
654  {
655  return getView(tag.label(), tag.instance(), tag.process(), result);
656  }
657 
658  template <typename ELEMENT>
659  bool
661  View<ELEMENT>& result) const
662  {
663  return getView(token.inputTag_.label(),
664  token.inputTag_.instance(),
665  token.inputTag_.process(),
666  result);
667  }
668 
669  template <typename ELEMENT>
670  void
672  std::string const& productInstanceName,
673  std::string const& processName,
674  PtrVector<ELEMENT>& result) const
675  {
676  std::lock_guard lock{mutex_};
677  auto grp = getContainerForView_(TypeID{typeid(ELEMENT)},
678  moduleLabel,
679  productInstanceName,
680  ProcessTag{processName, md_.processName()});
681  if (recordParents_) {
682  recordAsParent_(grp);
683  }
684  std::vector<void const*> view;
685  grp->uniqueProduct()->fillView(view);
686  std::size_t i{0};
687  for (auto p : view) {
688  result.emplace_back(
689  grp->productID(), static_cast<ELEMENT const*>(p), i++);
690  }
691  }
692 
693  template <typename ELEMENT>
694  void
696  std::string const& productInstanceName,
697  PtrVector<ELEMENT>& result) const
698  {
699  getPtrVector(moduleLabel, productInstanceName, {}, result);
700  }
701 
702  template <typename ELEMENT>
703  void
705  PtrVector<ELEMENT>& result) const
706  {
707  getPtrVector(tag.label(), tag.instance(), tag.process(), result);
708  }
709 
710  template <typename ELEMENT>
711  void
713  PtrVector<ELEMENT>& result) const
714  {
715  getPtrVector(token.inputTag_.label(),
716  token.inputTag_.instance(),
717  token.inputTag_.process(),
718  result);
719  }
720 
721  template <typename PROD>
722  ProductID
723  DataViewImpl::put(std::unique_ptr<PROD>&& edp)
724  {
725  return put(move(edp), "");
726  }
727 
728  template <typename PROD>
729  ProductID
730  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
731  FullSemantic<Level::Run> const semantic)
732  {
733  return put(move(edp), "", semantic);
734  }
735 
736  template <typename PROD>
737  ProductID
738  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
739  FragmentSemantic<Level::Run> const semantic)
740  {
741  return put(move(edp), "", semantic);
742  }
743 
744  template <typename PROD>
745  ProductID
746  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
748  {
749  return put(move(edp), "", std::move(semantic));
750  }
751 
752  template <typename PROD>
753  ProductID
754  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
755  std::string const& instance,
757  {
758  return put(move(edp), instance, RangeSet::forRun(runID()));
759  }
760 
761  template <typename PROD>
762  ProductID
763  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
764  std::string const& instance,
766  {
767  std::lock_guard lock{mutex_};
768  static_assert(
770  "\n\n"
771  "art error: A Run product put with the semantic 'RunFragment'\n"
772  " must be able to be aggregated. Please add the appropriate\n"
773  " void aggregate(T const&)\n"
774  " function to your class, or contact artists@fnal.gov.\n");
775  if (rangeSet_.collapse().is_full_run()) {
776  throw art::Exception{errors::ProductPutFailure, "Run::put"}
777  << "\nCannot put a product corresponding to a full Run using\n"
778  << "art::runFragment(). This can happen if you attempted to\n"
779  << "put a product at beginRun using art::runFragment().\n"
780  << "Please use either:\n"
781  << " art::fullRun(), or\n"
782  << " art::runFragment(art::RangeSet const&)\n"
783  << "or contact artists@fnal.gov for assistance.\n";
784  }
785  return put(move(edp), instance, rangeSet_);
786  }
787 
788  template <typename PROD>
789  ProductID
790  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
791  std::string const& instance,
793  {
794  std::lock_guard lock{mutex_};
795  static_assert(
797  "\n\n"
798  "art error: A Run product put with the semantic 'RunFragment'\n"
799  " must be able to be aggregated. Please add the appropriate\n"
800  " void aggregate(T const&)\n"
801  " function to your class, or contact artists@fnal.gov.\n");
802  if (semantic.rs.collapse().is_full_run()) {
803  throw art::Exception{errors::ProductPutFailure, "Run::put"}
804  << "\nCannot put a product corresponding to a full Run using\n"
805  << "art::runFragment(art::RangeSet&). Please use:\n"
806  << " art::fullRun()\n"
807  << "or contact artists@fnal.gov for assistance.\n";
808  }
809  return put(move(edp), instance, semantic.rs);
810  }
811 
812  template <typename PROD>
813  ProductID
814  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
815  FullSemantic<Level::SubRun> const semantic)
816  {
817  return put(move(edp), "", semantic);
818  }
819 
820  template <typename PROD>
821  ProductID
822  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
823  FragmentSemantic<Level::SubRun> const semantic)
824  {
825  return put(move(edp), "", semantic);
826  }
827 
828  template <typename PROD>
829  ProductID
830  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
832  {
833  return put(move(edp), "", std::move(semantic));
834  }
835 
836  template <typename PROD>
837  ProductID
838  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
839  std::string const& instance,
841  {
842  return put(move(edp), instance, RangeSet::forSubRun(subRunID()));
843  }
844 
845  template <typename PROD>
846  ProductID
847  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
848  std::string const& instance,
850  {
851  std::lock_guard lock{mutex_};
852  static_assert(
854  "\n\n"
855  "art error: A SubRun product put with the semantic 'SubRunFragment'\n"
856  " must be able to be aggregated. Please add the appropriate\n"
857  " void aggregate(T const&)\n"
858  " function to your class, or contact artists@fnal.gov.\n");
859  if (rangeSet_.collapse().is_full_subRun()) {
860  throw art::Exception(errors::ProductPutFailure, "SubRun::put")
861  << "\nCannot put a product corresponding to a full SubRun using\n"
862  << "art::subRunFragment(). This can happen if you attempted to\n"
863  << "put a product at beginSubRun using art::subRunFragment().\n"
864  << "Please use either:\n"
865  << " art::fullSubRun(), or\n"
866  << " art::subRunFragment(art::RangeSet const&)\n"
867  << "or contact artists@fnal.gov for assistance.\n";
868  }
869  return put(move(edp), instance, rangeSet_);
870  }
871 
872  template <typename PROD>
873  ProductID
874  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
875  std::string const& instance,
877  {
878  std::lock_guard lock{mutex_};
879  static_assert(
881  "\n\n"
882  "art error: A SubRun product put with the semantic 'SubRunFragment'\n"
883  " must be able to be aggregated. Please add the appropriate\n"
884  " void aggregate(T const&)\n"
885  " function to your class, or contact artists@fnal.gov.\n");
886  if (semantic.rs.collapse().is_full_subRun()) {
887  throw art::Exception{errors::ProductPutFailure, "Run::put"}
888  << "\nCannot put a product corresponding to a full SubRun using\n"
889  << "art::subRunFragment(art::RangeSet&). Please use:\n"
890  << " art::fullSubRun()\n"
891  << "or contact artists@fnal.gov for assistance.\n";
892  }
893  return put(move(edp), instance, semantic.rs);
894  }
895 
896  template <typename PROD>
897  ProductID
898  DataViewImpl::put(std::unique_ptr<PROD>&& edp, std::string const& instance)
899  {
900  std::lock_guard lock{mutex_};
901  TypeID const tid{typeid(PROD)};
902  if (edp.get() == nullptr) {
904  << "Event::put: A null unique_ptr was passed to 'put'.\n"
905  << "The pointer is of type " << tid << ".\n"
906  << "The specified productInstanceName was '" << instance << "'.\n";
907  }
908  auto const& bd = getProductDescription_(tid, instance, true);
909  assert(bd.productID() != ProductID::invalid());
910  auto const typeLabel =
912  auto wp = std::make_unique<Wrapper<PROD>>(move(edp));
913  auto const& rs = detail::range_sets_supported(branchType_) ?
914  rangeSet_.collapse() :
916  bool const result =
917  putProducts_.try_emplace(typeLabel, PMValue{std::move(wp), bd, rs})
918  .second;
919  if (!result) {
920  cet::HorizontalRule rule{30};
922  << "Event::put: Attempt to put multiple products with the\n"
923  << " following description onto the Event.\n"
924  << " Products must be unique per Event.\n"
925  << rule('=') << '\n'
926  << bd << rule('=') << '\n';
927  }
928  return bd.productID();
929  }
930 
931  template <typename PROD>
932  ProductID
933  DataViewImpl::put(std::unique_ptr<PROD>&& edp,
934  std::string const& instance,
935  RangeSet const& rs)
936  {
937  std::lock_guard lock{mutex_};
938  TypeID const tid{typeid(PROD)};
939  if (edp.get() == nullptr) {
941  << "Event::put: A null unique_ptr was passed to 'put'.\n"
942  << "The pointer is of type " << tid << ".\n"
943  << "The specified productInstanceName was '" << instance << "'.\n";
944  }
945  if (!rs.is_valid()) {
946  throw art::Exception{errors::ProductPutFailure, "SubRun::put"}
947  << "\nCannot put a product with an invalid RangeSet.\n"
948  << "Please contact artists@fnal.gov.\n";
949  }
950  auto const& bd = getProductDescription_(tid, instance, true);
951  assert(bd.productID() != ProductID::invalid());
952  auto const typeLabel =
954  auto wp = std::make_unique<Wrapper<PROD>>(move(edp));
955  auto result =
956  putProducts_.try_emplace(typeLabel, PMValue{move(wp), bd, rs}).second;
957  if (!result) {
958  constexpr cet::HorizontalRule rule{30};
960  << "Event::put: Attempt to put multiple products with the\n"
961  << " following description onto the Event.\n"
962  << " Products must be unique per Event.\n"
963  << rule('=') << '\n'
964  << bd << rule('=') << '\n';
965  }
966  return bd.productID();
967  }
968 
969  template <typename PROD>
970  bool
972  {
973  std::lock_guard lock{mutex_};
974  bool result{false};
975  if (h.isValid() && !h.provenance()->produced()) {
976  principal_.removeCachedProduct(h.id());
977  h.clear();
978  result = true;
979  }
980  return result;
981  }
982 
983  template <typename PROD>
984  std::ostream&
985  operator<<(std::ostream& os, Handle<PROD> const& h)
986  {
987  os << h.product() << " " << h.provenance() << " " << h.id();
988  return os;
989  }
990 
991 } // namespace art
992 
993 #endif /* art_Framework_Principal_DataViewImpl_h */
994 
995 // Local Variables:
996 // mode: c++
997 // End:
def history()
Definition: g4zmq.py:84
Principal const & principal_
Definition: DataViewImpl.h:327
static RangeSet forSubRun(SubRunID)
bool getByToken(ProductToken< PROD > const &, Handle< PROD > &result) const
Definition: DataViewImpl.h:462
PROD const * getPointerByLabel(InputTag const &tag) const
Definition: DataViewImpl.h:482
ProductID getProductID(std::string const &instance_name="") const
Definition: DataViewImpl.h:358
const char * p
Definition: xmltok.h:285
void getPtrVector(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, PtrVector< ELEMENT > &result) const
Definition: DataViewImpl.h:671
TypeLabel type_label_for(TypeID const typeID, std::string const &instance, bool const supportsView, ModuleDescription const &md)
bool get(SelectorBase const &, Handle< PROD > &result) const
Definition: DataViewImpl.h:386
Int_t eventID
Definition: plot.C:81
void emplace_back(Args &&...args)
Definition: PtrVector.h:448
bool is_valid() const
::xsd::cxx::tree::time< char, simple_type > time
Definition: Database.h:194
BranchType const branchType_
Definition: DataViewImpl.h:324
static RangeSet forRun(RunID)
const char * label
std::vector< InputTag > getInputTags(SelectorBase const &selector=MatchAllSelector{}) const
Definition: DataViewImpl.h:507
PMValue(std::unique_ptr< EDProduct > &&p, BranchDescription const &b, RangeSet const &r)
Definition: DataViewImpl.h:87
std::vector< ProductToken< PROD > > getProductTokens(SelectorBase const &selector=MatchAllSelector{}) const
Definition: DataViewImpl.h:516
bool isValid() const
Definition: Handle.h:183
std::unique_ptr< EDProduct > prod_
Definition: DataViewImpl.h:92
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:446
std::string const & process() const noexcept
static RangeSet invalid()
T const * product() const
Definition: Handle.h:161
Provenance const * provenance() const
Definition: Handle.h:197
InputTag inputTag_
Definition: ProductToken.h:85
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
Definition: DataViewImpl.h:529
std::string const & instance() const noexcept
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:491
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:119
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:558
ModuleDescription const & md_
Definition: DataViewImpl.h:333
Definition: fwd.h:43
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:971
void validateConsumedProduct(BranchType const, ModuleDescription const &, ProductInfo const &productInfo)
InputTag inputTag_
Definition: ProductToken.h:64
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
BranchDescription const & bd_
Definition: DataViewImpl.h:93
void clear()
Definition: Handle.h:230
static constexpr ProductID invalid() noexcept
Definition: ProductID.h:27
cet::exempt_ptr< Group const > result() const
const hit & b
Definition: hits.cxx:21
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
BranchType
Definition: BranchType.h:18
assert(nhit_max >=nhit_nbins)
TRandom3 r(0)
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
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:565
ModuleContext const & mc_
Definition: DataViewImpl.h:330
::xsd::cxx::tree::token< char, normalized_string > token
Definition: Database.h:156
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:730
ProductID id() const
Definition: Handle.h:204
constexpr bool range_sets_supported(BranchType const bt)
static ConsumesInfo * instance()
std::string const & label() const noexcept
bool const recordParents_
Definition: DataViewImpl.h:340
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120
enum BeamMode string