LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
Results.h
Go to the documentation of this file.
1 #ifndef art_Framework_Principal_Results_h
2 #define art_Framework_Principal_Results_h
3 
4 // ======================================================================
5 //
6 // Results: This is the primary interface for accessing results-level
7 // EDProducts and inserting new results-level EDProducts.
8 //
9 // For its usage, see "art/Framework/Principal/DataViewImpl.h"
10 //
11 // ======================================================================
12 
20 #include <memory>
21 #include <utility>
22 
23 namespace art {
24  class Consumer;
25  class Results;
26 }
27 
28 class art::Results final : private art::DataViewImpl {
29 public:
30  explicit Results(Principal const& p,
31  ModuleDescription const& md,
32  cet::exempt_ptr<Consumer> consumer);
33 
34  using Base = DataViewImpl;
35 
36  // Retrieve a product
37  using Base::get;
38  using Base::getByLabel;
39  using Base::getMany;
40  using Base::getManyByType;
43 
44  // Retrieve a view to a collection of products
45  using Base::getView;
46 
47  // Put a new product.
48  template <typename PROD>
49  art::ProductID put(std::unique_ptr<PROD>&& product);
50 
51  // Put a new product with a 'product instance name'
52  template <typename PROD>
53  art::ProductID put(std::unique_ptr<PROD>&& product,
54  std::string const& productInstanceName);
55 
56  // Expert-level
59 
60  EDProductGetter const* productGetter(ProductID const pid) const;
61 
62  // In principle, the principal (heh, heh) need not be a function
63  // argument since this class already keeps an internal reference to
64  // it. However, since the 'commit' function is public, requiring
65  // the principal as an argument prevents a commit from being called
66  // inappropriately.
67  void commit(ResultsPrincipal&);
68 
69  template <typename T>
70  using HandleT = Handle<T>;
71 
72 private:
74 };
75 
76 template <typename PROD>
78 art::Results::put(std::unique_ptr<PROD>&& product)
79 {
80  return put<PROD>(std::move(product), {});
81 }
82 
83 template <typename PROD>
85 art::Results::put(std::unique_ptr<PROD>&& product,
86  std::string const& productInstanceName)
87 {
88  TypeID const tid{typeid(PROD)};
89  if (!product) { // Null pointer is illegal.
91  << "Results::put: A null unique_ptr was passed to 'put'.\n"
92  << "The pointer is of type " << tid << ".\n"
93  << "The specified productInstanceName was '" << productInstanceName
94  << "'.\n";
95  }
96 
97  auto const& pd = getProductDescription(tid, productInstanceName);
98  auto wp = std::make_unique<Wrapper<PROD>>(std::move(product));
99 
100  auto result = putProducts().emplace(
101  TypeLabel{
102  tid, productInstanceName, SupportsView<PROD>::value, false /*not used*/},
103  PMValue{std::move(wp), pd, RangeSet::invalid()});
104  if (!result.second) {
106  << "Results::put: Attempt to put multiple products with the\n"
107  << " following description onto the Results.\n"
108  << " Products must be unique per Results.\n"
109  << "=================================\n"
110  << pd << "=================================\n";
111  }
112 
113  return pd.productID();
114 }
115 
116 #endif /* art_Framework_Principal_Results_h */
117 
118 // Local Variables:
119 // mode: c++
120 // End:
PROD const * getPointerByLabel(InputTag const &tag) const
Definition: DataViewImpl.h:396
void commit(ResultsPrincipal &)
Definition: Results.cc:18
ProcessHistory const & processHistory() const
Definition: DataViewImpl.cc:81
bool get(SelectorBase const &, Handle< PROD > &result) const
Definition: DataViewImpl.h:307
art::ProductID put(std::unique_ptr< PROD > &&product)
Definition: Results.h:78
Results(Principal const &p, ModuleDescription const &md, cet::exempt_ptr< Consumer > consumer)
Definition: Results.cc:5
BranchDescription const & getProductDescription(TypeID const &type, std::string const &productInstanceName) const
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::vector< ELEMENT const * > &result) const
Definition: DataViewImpl.h:474
void getMany(SelectorBase const &, std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:421
EDProductGetter const * productGetter(ProductID const pid) const
Definition: Results.cc:12
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: DataViewImpl.h:446
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
static RangeSet invalid()
Definition: RangeSet.cc:46
Principal const & principal_
Definition: Results.h:73
TypeLabelMap & putProducts()
Definition: DataViewImpl.h:183
HLT enums.
bool removeCachedProduct(Handle< PROD > &h) const
Definition: DataViewImpl.h:551
DataViewImpl(DataViewImpl const &)=delete
ValidHandle< PROD > getValidHandle(InputTag const &tag) const