LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
Group.h
Go to the documentation of this file.
1 #ifndef art_Framework_Principal_Group_h
2 #define art_Framework_Principal_Group_h
3 // vim: set sw=2:
4 
5 //
6 // A collection of information related to a single EDProduct.
7 //
8 
11 #include "art/Utilities/fwd.h"
20 #include "cetlib/container_algorithms.h"
21 #include "cetlib/exempt_ptr.h"
22 
23 #include <algorithm>
24 #include <iostream>
25 #include <memory>
26 #include <type_traits>
27 
28 namespace art {
29 
30  //
31  // Noncopyable through inheritance from EDProductGetter.
32  //
33 
34  class Group : public EDProductGetter {
35 
36  // The operative part of the GroupFactory system.
37  template <typename... ARGS>
38  friend std::unique_ptr<Group> gfactory::detail::make_group(
39  BranchDescription const&,
40  ARGS&&... args);
41 
42  public:
43  Group() = default;
44 
45  protected:
46  //
47  // Use GroupFactory to make.
48  //
50  ProductID const& pid,
51  RangeSet&& rs,
52  art::TypeID const& wrapper_type,
53  std::unique_ptr<EDProduct>&& edp = nullptr,
54  cet::exempt_ptr<Worker> productProducer = cet::exempt_ptr<Worker>{})
55  : wrapperType_{wrapper_type}
56  , product_{std::move(edp)}
57  , branchDescription_{&pd}
58  , pid_{pid}
59  , productProducer_{productProducer}
60  , rangeOfValidity_{std::move(rs)}
61  {}
62 
64  ProductID const& pid,
65  RangeSet&& rs,
66  cet::exempt_ptr<Worker> productProducer,
67  art::TypeID const& wrapper_type)
68  : Group{pd, pid, std::move(rs), wrapper_type, nullptr, productProducer}
69  {}
70 
72  ProductID const& pid,
73  RangeSet&& rs,
74  std::unique_ptr<EDProduct>&& edp,
75  art::TypeID const& wrapper_type)
76  : Group{pd, pid, std::move(rs), wrapper_type, std::move(edp)}
77  {}
78 
79  public:
80  // product is not available (dropped or never created)
81  bool productUnavailable() const;
82 
83  bool
84  isReady() const override
85  {
86  return true;
87  }
88 
89  EDProduct const*
90  getIt() const override
91  {
93  return product_.get();
94  }
95 
96  EDProduct const*
97  anyProduct() const override
98  {
99  return product_.get();
100  }
101 
102  EDProduct const*
103  uniqueProduct() const override
104  {
105  return product_.get();
106  }
107 
108  EDProduct const*
109  uniqueProduct(TypeID const&) const override
110  {
111  return product_.get();
112  }
113 
114  cet::exempt_ptr<ProductProvenance const> productProvenancePtr() const;
115 
116  BranchDescription const&
118  {
119  return *branchDescription_;
120  }
121 
122  std::string const&
123  moduleLabel() const
124  {
125  return branchDescription_->moduleLabel();
126  }
127 
128  std::string const&
130  {
131  return branchDescription_->productInstanceName();
132  }
133 
134  std::string const&
135  processName() const
136  {
137  return branchDescription_->processName();
138  }
139 
140  ProductStatus status() const;
141 
142  void
144  {
145  ppResolver_.reset(&bm);
146  productResolver_.reset(&dr);
147  }
148 
149  bool resolveProduct(TypeID const&) const override;
150 
151  bool resolveProductIfAvailable(TypeID const&) const override;
152 
153  void write(std::ostream& os) const;
154 
155  ProductID const&
156  productID() const
157  {
158  return pid_;
159  };
160 
161  TypeID const&
163  {
164  return wrapperType_;
165  }
166 
167  virtual void removeCachedProduct() const;
168 
169  RangeSet const&
171  {
172  return rangeOfValidity_;
173  }
174 
175  protected:
176  std::unique_ptr<EDProduct> obtainDesiredProduct(TypeID const&) const;
177 
178  void setProduct(std::unique_ptr<EDProduct>&& prod) const;
179 
180  [[noreturn]] void throwResolveLogicError(
181  TypeID const& wanted_wrapper_type) const;
182 
183  private:
184  bool dropped() const;
185 
186  private:
188  cet::exempt_ptr<BranchMapper const> ppResolver_{nullptr};
189  cet::exempt_ptr<DelayedReader const> productResolver_{nullptr};
190  mutable std::unique_ptr<EDProduct> product_{nullptr};
191  cet::exempt_ptr<BranchDescription const> branchDescription_{nullptr};
192  mutable ProductID pid_{};
193  cet::exempt_ptr<Worker> productProducer_{nullptr};
195  }; // Group
196 
197  inline std::ostream&
198  operator<<(std::ostream& os, Group const& g)
199  {
200  g.write(os);
201  return os;
202  }
203 
204 } // namespace art
205 
206 // Local Variables:
207 // mode: c++
208 // End:
209 #endif /* art_Framework_Principal_Group_h */
std::ostream & operator<<(std::ostream &os, EDAnalyzer::Table< T > const &t)
Definition: EDAnalyzer.h:184
RangeSet const & rangeOfValidity() const
Definition: Group.h:170
cet::exempt_ptr< BranchDescription const > branchDescription_
Definition: Group.h:191
Group(BranchDescription const &pd, ProductID const &pid, RangeSet &&rs, art::TypeID const &wrapper_type, std::unique_ptr< EDProduct > &&edp=nullptr, cet::exempt_ptr< Worker > productProducer=cet::exempt_ptr< Worker >{})
Definition: Group.h:49
bool productUnavailable() const
Definition: Group.cc:84
std::unique_ptr< Group > make_group(BranchDescription const &pd, ARGS &&...args)
ProductID pid_
Definition: Group.h:192
Group(BranchDescription const &pd, ProductID const &pid, RangeSet &&rs, std::unique_ptr< EDProduct > &&edp, art::TypeID const &wrapper_type)
Definition: Group.h:71
EDProduct const * uniqueProduct(TypeID const &) const override
Definition: Group.h:109
unsigned char ProductStatus
Definition: ProductStatus.h:12
EDProduct const * getIt() const override
Definition: Group.h:90
TypeID const & producedWrapperType() const
Definition: Group.h:162
cet::exempt_ptr< ProductProvenance const > productProvenancePtr() const
Definition: Group.cc:96
Group()=default
ProductID const & productID() const
Definition: Group.h:156
bool resolveProductIfAvailable(TypeID const &) const override
Definition: Group.cc:60
RangeSet rangeOfValidity_
Definition: Group.h:194
Group(BranchDescription const &pd, ProductID const &pid, RangeSet &&rs, cet::exempt_ptr< Worker > productProducer, art::TypeID const &wrapper_type)
Definition: Group.h:63
std::unique_ptr< EDProduct > product_
Definition: Group.h:190
virtual void removeCachedProduct() const
Definition: Group.cc:106
void write(std::ostream &os) const
Definition: Group.cc:139
TypeID wrapperType_
Definition: Group.h:187
cet::exempt_ptr< BranchMapper const > ppResolver_
Definition: Group.h:188
cet::exempt_ptr< Worker > productProducer_
Definition: Group.h:193
std::unique_ptr< EDProduct > obtainDesiredProduct(TypeID const &) const
Definition: Group.cc:76
bool isReady() const override
Definition: Group.h:84
std::string const & productInstanceName() const
Definition: Group.h:129
EDProduct const * uniqueProduct() const override
Definition: Group.h:103
static RangeSet invalid()
Definition: RangeSet.cc:46
std::string const & processName() const
Definition: Group.h:135
ProductStatus status() const
Definition: Group.cc:14
void setProduct(std::unique_ptr< EDProduct > &&prod) const
Definition: Group.cc:116
HLT enums.
void throwResolveLogicError(TypeID const &wanted_wrapper_type) const
Definition: Group.cc:123
std::string const & moduleLabel() const
Definition: Group.h:123
bool resolveProduct(TypeID const &) const override
Definition: Group.cc:45
cet::exempt_ptr< DelayedReader const > productResolver_
Definition: Group.h:189
EDProduct const * anyProduct() const override
Definition: Group.h:97
bool dropped() const
Definition: Group.cc:132
BranchDescription const & productDescription() const
Definition: Group.h:117
void setResolvers(BranchMapper const &bm, DelayedReader const &dr)
Definition: Group.h:143