ToyProducts.h
Go to the documentation of this file.
1 #ifndef art_test_TestObjects_ToyProducts_h
2 #define art_test_TestObjects_ToyProducts_h
3 
4 // ======================================================================
5 //
6 // EDProducts for testing purposes
7 //
8 // ======================================================================
9 
12 
13 #include <array>
14 #include <cstdint>
15 #include <memory>
16 #include <stdexcept>
17 #include <string>
18 #include <vector>
19 
20 namespace arttest {
21 
22  struct DummyProduct {
23  void
24  aggregate(DummyProduct const&) const
25  {}
26  };
27 
28  struct IntProduct {
29  IntProduct() = default;
30  explicit IntProduct(int i) : value(i) {}
31 
32  IntProduct&
34  {
35  value += other.value;
36  return *this;
37  }
38 
39  void
41  {
42  (void)operator+=(other);
43  }
44 
45  int value{};
46  };
47 
49  CompressedIntProduct() = default;
50  explicit CompressedIntProduct(int i) : value(i) {}
51 
54  {
55  value += other.value;
56  return *this;
57  }
58 
59  void
61  {
62  (void)operator+=(other);
63  }
64 
65  int value{};
66  };
67 
68  struct Int16_tProduct {
69  Int16_tProduct() = default;
70  explicit Int16_tProduct(int16_t i, uint16_t j) : value(i), uvalue(j) {}
71 
72  int16_t value{};
73  uint16_t uvalue{1};
74 
75  void
77  {
78  value += other.value;
79  uvalue += other.uvalue;
80  }
81  };
82 
83  struct DoubleProduct {
84  DoubleProduct() = default;
85  explicit DoubleProduct(double d) : value(d) {}
86 
87  void
89  {
90  value += d.value;
91  }
92 
93  double value{2.2};
94  };
95 
96  inline DoubleProduct
98  {
99  return DoubleProduct(left.value + right.value);
100  }
101 
102  inline DoubleProduct&
104  {
105  left.aggregate(right);
106  return left;
107  }
108 
109  inline DoubleProduct&
111  {
112  left.value += right;
113  return left;
114  }
115 
116  struct StringProduct {
117  StringProduct() = default;
118  explicit StringProduct(const std::string& s) : name_(s) {}
119  void
121  {}
122  std::string name_{};
123  };
124 
125  inline bool
127  {
128  return left.name_ == right.name_;
129  }
130 
131  inline std::ostream&
132  operator<<(std::ostream& os, StringProduct const& s)
133  {
134  return os << s.name_;
135  }
136 
137  struct Simple {
138  Simple() = default;
139 
140  virtual ~Simple() noexcept = default;
141  typedef int key_type;
142 
143  key_type key{};
144  double value{};
145 
146  key_type
147  id() const
148  {
149  return key;
150  }
151  virtual double
152  dummy() const
153  {
154  return -3.14;
155  }
156  virtual Simple*
157  clone() const
158  {
159  return new Simple(*this);
160  }
161  };
162 
163  inline bool
164  operator==(Simple const& a, Simple const& b)
165  {
166  return (a.key == b.key && a.value == b.value);
167  }
168 
169  inline bool
170  operator<(Simple const& a, Simple const& b)
171  {
172  return a.key < b.key;
173  }
174 
175  struct SimpleDerived : public Simple {
176  SimpleDerived() = default;
177 
179  : Simple(other), dummy_(other.dummy_)
180  {}
181 
182  double dummy_{16.25};
183  double
184  dummy() const override
185  {
186  return dummy_;
187  }
189  clone() const override
190  {
191  return new SimpleDerived(*this);
192  }
193  };
194 
195  struct Sortable {
196  int data{};
197  Sortable() = default;
198  explicit Sortable(int i) : data(i) {}
199  void
200  aggregate(Sortable const&) const
201  {}
202  };
203 
204  inline bool
205  operator==(Sortable const& a, Sortable const& b)
206  {
207  return (a.data == b.data);
208  }
209 
210  inline bool
211  operator<(Sortable const& a, Sortable const& b)
212  {
213  return a.data < b.data;
214  }
215 
216  using VSimpleProduct = std::vector<Simple>;
217 
218  struct Hit {
219  Hit() : id(-1) {}
220  Hit(size_t id) : id(id) {}
221  size_t id;
222  void
223  aggregate(Hit const&) const
224  {}
225  };
226 
227  struct Track {
228  Track() : id(-1) {}
229  Track(size_t id) : id(id) {}
230  size_t id;
231  void
232  aggregate(Track const&) const
233  {}
234  };
235 
236  template <std::size_t N>
237  struct IntArray {
238  IntArray() = default;
239  std::array<int, N> arr{{}};
240  void
242  {
243  for (std::size_t i{}; i < N; ++i) {
244  arr[i] += right.arr[i];
245  }
246  }
247  };
248 
249  // Test making a data product that has no default constructor and is
250  // marked persistent="false" in the selection XML file. We do not
251  // create a class that explicitly deletes the default constructor
252  // because ROOT's introspection mechanisms have a way of determining
253  // this at compile time.
254  struct NonPersistable {
255  explicit NonPersistable(std::string const& n) : name{n} {}
257  };
258 
259  // Create type that encapsulates a pointer to NonPersistable--this
260  // type *can* have a default constructor.
262 
263  explicit PtrToNonPersistable() = default;
265  : np{new NonPersistable{n}}
266  {}
267 
268  // Copying disabled
269  PtrToNonPersistable(PtrToNonPersistable const&) = delete;
270  PtrToNonPersistable& operator=(PtrToNonPersistable const&) = delete;
271 
272  // Move allowed
274  {
275  rhs.np = nullptr;
276  }
277 
280  {
281  np = rhs.np;
282  rhs.np = nullptr;
283  return *this;
284  }
285 
287  {
288  delete np;
289  np = nullptr;
290  }
291 
292  NonPersistable const* np{nullptr};
293  };
294 }
295 
296 // ======================================================================
297 
298 #endif /* art_test_TestObjects_ToyProducts_h */
299 
300 // Local Variables:
301 // mode: c++
302 // End:
static QCString name
Definition: declinfo.cpp:673
PtrToNonPersistable(std::string const &n)
Definition: ToyProducts.h:264
Int16_tProduct(int16_t i, uint16_t j)
Definition: ToyProducts.h:70
void aggregate(Int16_tProduct const &other)
Definition: ToyProducts.h:76
NonPersistable const * np
Definition: ToyProducts.h:292
double dummy() const override
Definition: ToyProducts.h:184
void aggregate(DoubleProduct const &d)
Definition: ToyProducts.h:88
Hit(size_t id)
Definition: ToyProducts.h:220
DoubleProduct & operator+=(DoubleProduct &left, DoubleProduct const &right)
Definition: ToyProducts.h:103
std::string string
Definition: nybbler.cc:12
Definition: types.h:35
void aggregate(DummyProduct const &) const
Definition: ToyProducts.h:24
NonPersistable(std::string const &n)
Definition: ToyProducts.h:255
CompressedIntProduct & operator+=(CompressedIntProduct const &other)
Definition: ToyProducts.h:53
void aggregate(StringProduct const &)
Definition: ToyProducts.h:120
void aggregate(CompressedIntProduct const &other)
Definition: ToyProducts.h:60
std::ostream & operator<<(std::ostream &os, StringProduct const &s)
Definition: ToyProducts.h:132
void aggregate(IntProduct const &other)
Definition: ToyProducts.h:40
std::vector< Simple > VSimpleProduct
Definition: ToyProducts.h:216
void aggregate(Hit const &) const
Definition: ToyProducts.h:223
SimpleDerived * clone() const override
Definition: ToyProducts.h:189
def key(type, name=None)
Definition: graph.py:13
std::void_t< T > n
const double a
void aggregate(IntArray const &right)
Definition: ToyProducts.h:241
virtual Simple * clone() const
Definition: ToyProducts.h:157
Track(size_t id)
Definition: ToyProducts.h:229
IntProduct & operator+=(IntProduct const &other)
Definition: ToyProducts.h:33
void aggregate(Sortable const &) const
Definition: ToyProducts.h:200
PtrToNonPersistable(PtrToNonPersistable &&rhs)
Definition: ToyProducts.h:273
key_type id() const
Definition: ToyProducts.h:147
DoubleProduct operator+(DoubleProduct const &left, DoubleProduct const right)
Definition: ToyProducts.h:97
std::array< int, N > arr
Definition: ToyProducts.h:239
virtual double dummy() const
Definition: ToyProducts.h:152
void aggregate(Track const &) const
Definition: ToyProducts.h:232
bool operator<(Simple const &a, Simple const &b)
Definition: ToyProducts.h:170
bool operator==(StringProduct const &left, StringProduct const &right)
Definition: ToyProducts.h:126
static bool * b
Definition: config.cpp:1043
StringProduct(const std::string &s)
Definition: ToyProducts.h:118
SimpleDerived(SimpleDerived const &other)
Definition: ToyProducts.h:178
PtrToNonPersistable & operator=(PtrToNonPersistable &&rhs)
Definition: ToyProducts.h:279
static QCString * s
Definition: config.cpp:1042