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 expandtab :
4 
5 //
6 // A collection of information related to a single EDProduct.
7 //
8 
20 #include "cetlib/exempt_ptr.h"
21 
22 #include <atomic>
23 #include <memory>
24 #include <mutex>
25 #include <optional>
26 #include <vector>
27 
28 namespace art {
29 
30  class Group final : public EDProductGetter {
31  public:
32  ~Group();
33 
34  enum class grouptype { normal = 0, assns = 1, assnsWithData = 2 };
35 
37  BranchDescription const&,
38  std::unique_ptr<RangeSet>&&,
39  grouptype const gt,
40  std::unique_ptr<EDProduct>&& edp = nullptr);
41 
42  // EDProductGetter interface
43  EDProduct const* getIt_() const override;
44  EDProduct const* anyProduct() const;
45  EDProduct const* uniqueProduct() const;
46  EDProduct const* uniqueProduct(TypeID const&) const;
47  bool resolveProductIfAvailable(TypeID wanted_wrapper = TypeID{}) const;
48  bool tryToResolveProduct(TypeID const&);
49 
50  // Allows user module to remove a large fetched data product
51  // after copying it.
52  void removeCachedProduct();
53 
54  // Metadata
55  BranchDescription const& productDescription() const noexcept;
56  ProductID productID() const;
57  RangeSet const& rangeOfValidity() const;
58  bool productAvailable() const;
60 
61  // Setting internal product provenance and product pointers.
62 
63  // Called by Principal::ctor_read_provenance()
64  // Called by Principal::insert_pp
65  // Called by RootDelayedReader::getProduct_
66  void setProductProvenance(std::unique_ptr<ProductProvenance const>&&);
67 
68  // Called by Principal::put
69  void setProductAndProvenance(std::unique_ptr<ProductProvenance const>&&,
70  std::unique_ptr<EDProduct>&&,
71  std::unique_ptr<RangeSet>&&);
72 
73  private:
75 
76  // Back pointer to the delayed reader in the principal that owns
77  // us.
79  // Used to serialize access to productProvenance_, product_,
80  // rangeSet_, partnerProduct_, baseProduct_, and
81  // partnerBaseProduct_. This is recursive because sometimes we
82  // may need to replace the product provenance when merging run or
83  // subRun data products while checking if the product is
84  // available, which we may do while resolving a a product with
85  // this locked to make the updating of provenance and product
86  // pointers together one atomic transaction.
87  mutable std::recursive_mutex mutex_{};
88  // The product provenance for the data product.
89  // Note: Modified by setProductProvenance (called by Principal ctors and
90  // Principal::insert_pp (called by Principal::put).
91  std::atomic<ProductProvenance const*> productProvenance_{nullptr};
92  // The wrapped data product itself.
93  // Note: Modified by setProduct (called by Principal::put)
94  // Note: Modified by removeCachedProduct.
95  // Note: Modified by resolveProductIfAvailable.
96  mutable std::atomic<EDProduct*> product_;
97  // Note: Modified by setProduct (called by Principal put).
98  // Note: Modified by removeCachedProduct.
99  // Note: Modified by resolveProductIfAvailable.
100  mutable std::atomic<RangeSet*> rangeSet_;
101  // Are we normal, assns, or assnsWithData?
103  //
104  // AssnsGroup
105  //
106  // Note: Modified by setProduct (called by Principal put).
107  // Note: Modified by removeCachedProduct.
108  // Note: Modified by resolveProductIfAvailable.
109  mutable std::atomic<EDProduct*> partnerProduct_{nullptr};
110  //
111  // AssnsGroupWithData
112  //
113  // Note: Modified by setProduct.
114  // Note: Modified by removeCachedProduct.
115  // Note: Modified by resolveProductIfAvailable.
116  mutable std::atomic<EDProduct*> baseProduct_{nullptr};
117  // Note: Modified by setProduct.
118  // Note: Modified by removeCachedProduct.
119  // Note: Modified by resolveProductIfAvailable.
120  mutable std::atomic<EDProduct*> partnerBaseProduct_{nullptr};
121  };
122 
123  std::optional<GroupQueryResult> resolve_unique_product(
125  art::WrappedTypeID const& wrapped);
126 
127  std::vector<GroupQueryResult> resolve_products(
129  art::TypeID const& wrapped_type);
130 
131 } // namespace art
132 
133 // Local Variables:
134 // mode: c++
135 // End:
136 #endif /* art_Framework_Principal_Group_h */
bool tryToResolveProduct(TypeID const &)
Definition: Group.cc:377
ProductID productID() const
Definition: Group.cc:132
bool productAvailable() const
Definition: Group.cc:206
struct vector vector
std::optional< GroupQueryResult > resolve_unique_product(std::vector< cet::exempt_ptr< art::Group >> const &product_groups, art::WrappedTypeID const &wrapped)
Definition: Group.cc:387
std::atomic< ProductProvenance const * > productProvenance_
Definition: Group.h:91
std::atomic< RangeSet * > rangeSet_
Definition: Group.h:100
std::atomic< EDProduct * > baseProduct_
Definition: Group.h:116
void setProductAndProvenance(std::unique_ptr< ProductProvenance const > &&, std::unique_ptr< EDProduct > &&, std::unique_ptr< RangeSet > &&)
Definition: Group.cc:164
grouptype
Definition: Group.h:34
cet::exempt_ptr< ProductProvenance const > productProvenance() const
Definition: Group.cc:145
BranchDescription const & productDescription() const noexcept
Definition: Group.cc:126
~Group()
Definition: Group.cc:20
std::atomic< EDProduct * > product_
Definition: Group.h:96
EDProduct const * getIt_() const override
Definition: Group.cc:43
std::recursive_mutex mutex_
Definition: Group.h:87
EDProduct const * anyProduct() const
Definition: Group.cc:54
cet::exempt_ptr< DelayedReader const > const delayedReader_
Definition: Group.h:78
std::atomic< EDProduct * > partnerProduct_
Definition: Group.h:109
BranchDescription const & branchDescription_
Definition: Group.h:74
bool resolveProductIfAvailable(TypeID wanted_wrapper=TypeID{}) const
Definition: Group.cc:286
void removeCachedProduct()
Definition: Group.cc:178
std::atomic< EDProduct * > partnerBaseProduct_
Definition: Group.h:120
grouptype const grpType_
Definition: Group.h:102
EDProduct const * uniqueProduct() const
Definition: Group.cc:78
void setProductProvenance(std::unique_ptr< ProductProvenance const > &&)
Definition: Group.cc:155
RangeSet const & rangeOfValidity() const
Definition: Group.cc:138
Group(DelayedReader *, BranchDescription const &, std::unique_ptr< RangeSet > &&, grouptype const gt, std::unique_ptr< EDProduct > &&edp=nullptr)
Definition: Group.cc:30
std::vector< GroupQueryResult > resolve_products(std::vector< cet::exempt_ptr< art::Group >> const &groups, art::TypeID const &wrapped_type)
Definition: Group.cc:428