LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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 <ostream>
21 #include <string>
22 
23 namespace gallery {
24  class Event;
25 }
26 
27 namespace art {
28 
29  template <typename T>
30  class ProductToken;
31 
32  template <typename T>
33  class ViewToken;
34 
35  namespace detail {
36  template <typename ProdA, typename ProdB, typename Data>
37  struct safe_input_tag;
38  }
39 
40  template <typename T>
41  class ProductToken {
42  public:
43  using product_type = T;
44 
45  friend std::ostream&
46  operator<<(std::ostream& os, ProductToken const& tok)
47  {
48  os << tok.inputTag_;
49  return os;
50  }
51 
52  static ProductToken<T>
54  {
55  return ProductToken<T>{};
56  }
57  explicit ProductToken() = default;
58  explicit ProductToken(InputTag const& t) : inputTag_{t} {}
59 
60  InputTag const&
61  inputTag() const
62  {
63  return inputTag_;
64  }
65 
66  private:
67  template <typename ProdA, typename ProdB, typename Data>
68  friend struct detail::safe_input_tag;
69 
70  // For now, the representation is just an InputTag. For an
71  // input-tag that includes a specified process name, the
72  // representation could be a ProductID allowing efficient access
73  // to the appropriate data. However, until a mechanism can be
74  // determined for combining the needs of specifying a process name
75  // vs. not, we will use the InputTag.
76 
77  InputTag inputTag_{};
78  };
79 
80  template <typename Element>
81  class ViewToken {
82  public:
83  using element_type = Element;
84 
85  static ViewToken<Element>
87  {
88  return ViewToken<Element>{};
89  }
90  explicit ViewToken() = default;
91  explicit ViewToken(InputTag const& t) : inputTag_{t} {}
92 
93  InputTag const&
94  inputTag() const
95  {
96  return inputTag_;
97  }
98 
99  friend std::ostream&
100  operator<<(std::ostream& os, ViewToken const& tok)
101  {
102  os << tok.inputTag_;
103  return os;
104  }
105 
106  private:
107  // See notes in ProductToken re. the representation.
108  InputTag inputTag_{};
109  };
110 }
111 
112 #endif /* canvas_Persistency_Provenance_ProductToken_h */
113 
114 // Local Variables:
115 // mode: c++
116 // End:
ProductToken(InputTag const &t)
Definition: ProductToken.h:58
static ProductToken< T > invalid()
Definition: ProductToken.h:53
InputTag const & inputTag() const
Definition: ProductToken.h:94
ViewToken(InputTag const &t)
Definition: ProductToken.h:91
Element element_type
Definition: ProductToken.h:83
InputTag inputTag_
Definition: ProductToken.h:108
static ViewToken< Element > invalid()
Definition: ProductToken.h:86
InputTag inputTag_
Definition: ProductToken.h:77
Stream & operator<<(Stream &&out, CallInfo_t const &info)
Helper operator to insert a call information in a stream with default options.
Definition: DebugUtils.h:389
Definition: MVAAlg.h:12
InputTag const & inputTag() const
Definition: ProductToken.h:61