ProductToken.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Provenance_ProductToken_h
2 #define canvas_Persistency_Provenance_ProductToken_h
3 
4 //==============================================================
5 // ProductToken and ViewToken are used to enable efficient product
6 // lookup via a consumes statement given in a module's constructor
7 // (e.g.):
8 //
9 // ProductToken<int> nPotsToken_{consumes<int>(inputTag_)};
10 // ...
11 // auto const& nPotsH = e.getValidHandle(nPotsToken_); => ValidHandle<int>
12 //
13 // The ProductToken and ViewToken classes have only private members:
14 // access is granted via friendship. The intention is that these
15 // classes should be entirely opaque to the user.
16 // ==============================================================
17 
19 
20 #include <string>
21 
22 namespace gallery {
23  class Event;
24 }
25 
26 namespace art {
27 
28  template <typename T>
29  class ProductToken;
30  template <typename T>
31  class ViewToken;
32 
33  // Forward declarations needed for granting friendship
34  class DataViewImpl;
35  class ConsumesCollector;
36 
37  namespace detail {
38  template <typename ProdA, typename ProdB, typename Data>
39  struct safe_input_tag;
40  }
41 
42  template <typename T>
43  class ProductToken {
44  public:
45  using product_type = T;
46 
47  private:
48  static ProductToken<T>
50  {
51  return ProductToken<T>{};
52  }
53  explicit ProductToken() = default;
54  explicit ProductToken(InputTag const& t) : inputTag_{t} {}
55 
56  friend class DataViewImpl;
57  friend class ConsumesCollector;
58  friend class gallery::Event;
59  template <typename ProdA, typename ProdB, typename Data>
60  friend struct detail::safe_input_tag;
61 
62  // For now, the representation is just an InputTag. For an
63  // input-tag that includes a specified process name, the
64  // representation could be a ProductID allowing efficient access
65  // to the appropriate data. However, until a mechanism can be
66  // determined for combining the needs of specifying a process name
67  // vs. not, we will use the InputTag.
68 
69  InputTag inputTag_{};
70  };
71 
72  template <typename Element>
73  class ViewToken {
74  public:
75  using element_type = Element;
76 
77  private:
78  static ViewToken<Element>
80  {
81  return ViewToken<Element>{};
82  }
83  explicit ViewToken() = default;
84  explicit ViewToken(InputTag const& t) : inputTag_{t} {}
85 
86  friend class DataViewImpl;
87  friend class ConsumesCollector;
88 
89  // See notes in ProductToken re. the representation.
90  InputTag inputTag_{};
91  };
92 }
93 
94 #endif /* canvas_Persistency_Provenance_ProductToken_h */
95 
96 // Local Variables:
97 // mode: c++
98 // End:
ProductToken(InputTag const &t)
Definition: ProductToken.h:54
static ProductToken< T > invalid()
Definition: ProductToken.h:49
ViewToken(InputTag const &t)
Definition: ProductToken.h:84
std::vector< sim::OpDetBacktrackerRecord > product_type
Definition: ProductToken.h:45
Element element_type
Definition: ProductToken.h:75
static ViewToken< Element > invalid()
Definition: ProductToken.h:79