Bayeux  3.4.1
Core Foundation library for SuperNEMO
base_hit.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date: 2010-03-16
4  * Last modified: 2018-08-16
5  *
6  * License: GPL3
7  *
8  * Description:
9  *
10  * Base hit.
11  *
12  */
13 
14 #ifndef GEOMTOOLS_BASE_HIT_H
15 #define GEOMTOOLS_BASE_HIT_H 1
16 
17 // Third party:
18 // - Boost:
19 #include <boost/serialization/access.hpp>
20 #include <boost/cstdint.hpp>
21 // - Bayeux/datatools :
23 #include <datatools/i_tree_dump.h>
24 #include <datatools/i_clear.h>
25 #include <datatools/i_predicate.h>
26 #include <datatools/bit_mask.h>
27 #include <datatools/properties.h>
29 
30 // This project :
32 #include <geomtools/geom_id.h>
33 #include <datatools/properties.h>
34 
35 namespace geomtools {
36 
38  class base_hit :
41  public datatools::i_clear
42  {
43  public:
44 
53  };
54 
55  static const int32_t INVALID_HIT_ID = -1;
56 
65  bool has_hit_id () const;
66 
73  int32_t get_hit_id () const;
74 
76  void set_hit_id (int32_t);
77 
87  void invalidate_hit_id ();
88 
90  bool has_geom_id () const;
91 
93  const geomtools::geom_id & get_geom_id () const;
94 
97 
99  void set_geom_id (const geomtools::geom_id &);
100 
102  void invalidate_geom_id ();
103 
105  bool has_auxiliaries () const;
106 
108  const datatools::properties & get_auxiliaries () const;
109 
112 
114  void set_auxiliaries (const datatools::properties &);
115 
117  void invalidate_auxiliaries ();
118 
120  base_hit ();
121 
123  virtual ~base_hit ();
124 
126 
130  virtual bool is_valid () const;
131 
133  virtual void invalidate ();
134 
136  void reset ();
137 
139  virtual void clear ();
140 
141  /* measurement */
142 
145  {
146  public:
147 
149  virtual void do_measurement (base_hit &) = 0;
150 
153 
154  };
155 
158 
159  /* interface i_tree_dumpable */
160 
162  virtual void tree_dump (std::ostream & a_out = std::clog,
163  const std::string & a_title = "",
164  const std::string & a_indent = "",
165  bool a_inherit = false) const;
176  void print_tree(std::ostream & out_ = std::clog,
177  const boost::property_tree::ptree & options_ = datatools::i_tree_dumpable::empty_options()) const override;
178 
180  void dump() const;
181 
182  /* predicates */
183 
186  {
187  std::string flag_;
188 
189  public:
190 
192  explicit has_flag_predicate (const std::string & a_flag)
193  {
194  flag_ = a_flag;
195  return;
196  }
197 
199  bool operator () (const base_hit & a_hit) const
200  {
201  return (a_hit.get_auxiliaries ().has_flag (flag_));
202  }
203 
204  };
205 
207  class has_key_predicate : public datatools::i_predicate<base_hit>
208  {
209  std::string key_;
210 
211  public:
212 
214  explicit has_key_predicate (const std::string & a_key)
215  {
216  key_ = a_key;
217  return;
218  }
219 
221  bool operator () (const base_hit & a_hit) const
222  {
223  return (a_hit.get_auxiliaries ().has_key (key_));
224  }
225 
226  };
227 
230  {
231  std::string key_;
232  std::vector<std::string> values_;
233 
234  public:
235 
237  explicit has_string_property_predicate (const std::string & a_key,
238  const std::string & a_value)
239  {
240  key_ = a_key;
241  values_.push_back (a_value);
242  return;
243  }
244 
246  explicit has_string_property_predicate (const std::string & a_key,
247  const std::vector<std::string> & a_values)
248  {
249  key_ = a_key;
250  values_ = a_values;
251  return;
252  }
253 
255  bool operator () (const base_hit & a_hit) const
256  {
257  if (! a_hit.get_auxiliaries ().has_key (key_)) return false;
258  if (! a_hit.get_auxiliaries ().is_string (key_)) return false;
259  const std::string & str = a_hit.get_auxiliaries ().fetch_string (key_);
260  return (std::find (values_.begin (),
261  values_.end (),
262  str) != values_.end ());
263  }
264 
265  };
266 
269  {
270  public:
271 
273  explicit has_hit_id_predicate (int a_hid)
274  {
275  hid_ = a_hid;
276  return;
277  }
278 
280  bool operator () (const base_hit & a_hit) const
281  {
282  return (a_hit.has_hit_id () && a_hit.get_hit_id () == hid_);
283  }
284 
285  private:
286 
287  int hid_;
288 
289  };
290 
291 
294  {
295  public:
296 
298  explicit has_geom_id_predicate (const geomtools::geom_id & a_gid)
299  {
300  gid_ = a_gid;
301  return;
302  }
303 
305  bool operator () (const base_hit & a_hit) const
306  {
307  return (a_hit.has_geom_id () && a_hit.get_geom_id () == gid_);
308  }
309 
310  private:
311 
312  geomtools::geom_id gid_;
313 
314  };
315 
316 
318  class negates_predicate : public datatools::i_predicate<base_hit>
319  {
320  public:
321 
324  {
325  pred_ = &a_pred;
326  return;
327  }
328 
330  bool operator () (const base_hit & a_hit) const
331  {
332  return (! (*pred_)(a_hit));
333  }
334 
335  private:
336 
337  const datatools::i_predicate<base_hit> * pred_;
338 
339  };
340 
341  protected:
342 
344  void _store_set(uint32_t bit_mask_);
345 
347  void _store_unset(uint32_t bit_mask_);
348 
350  bool _store_check(uint32_t bit_mask_) const;
351 
361  uint32_t _store;
362 
363  private:
364 
365  int32_t _hit_id_;
366  geomtools::geom_id _geom_id_;
367  datatools::properties _auxiliaries_;
368 
370 
371 
372  DR_CLASS_RTTI()
373 
374  // Factory stuff :
376 
378 
379  };
380 
381 } // end of namespace geomtools
382 
383 #include <boost/serialization/export.hpp>
384 BOOST_CLASS_EXPORT_KEY2(geomtools::base_hit, "geomtools::base_hit")
385 
386 // Activate reflection layer for the geomtools::base_hit class :
388 
389 // Class version:
390 #include <boost/serialization/version.hpp>
391 BOOST_CLASS_VERSION(geomtools::base_hit, 1)
392 
393 #define GEOMTOOLS_HIT_REGISTRATION_INTERFACE(HitClassName) \
394  private: \
395  DATATOOLS_FACTORY_SYSTEM_AUTO_REGISTRATION_INTERFACE(::geomtools::base_hit,HitClassName) \
396 
397 
398 #define GEOMTOOLS_HIT_REGISTRATION_IMPLEMENT(HitClassName,HitClassId) \
399  DATATOOLS_FACTORY_SYSTEM_AUTO_REGISTRATION_IMPLEMENTATION(::geomtools::base_hit,HitClassName,HitClassId) \
400 
401 
402 #endif // GEOMTOOLS_BASE_HIT_H
403 
404 /*
405 ** Local Variables: --
406 ** mode: c++ --
407 ** c-file-style: "gnu" --
408 ** tab-width: 2 --
409 ** End: --
410 */
static const boost::property_tree::ptree & empty_options()
has_string_property_predicate(const std::string &a_key, const std::vector< std::string > &a_values)
Constructor.
Definition: base_hit.h:246
#define DR_CLASS_INIT(Introspectable)
Inform Camp that class Introspectable exists and trigger the automatic registration of dedicated refl...
Definition: reflection_interface.h:149
void _store_unset(uint32_t bit_mask_)
Unset the bits from a mask.
bool operator()(const base_hit &a_hit) const
Functor interface.
Definition: base_hit.h:221
Base abstract class of all serializable (and possibly introspectable) classes.
Definition: i_serializable.h:51
void set_geom_id(const geomtools::geom_id &)
Set the geometry ID.
static const int32_t INVALID_HIT_ID
Definition: base_hit.h:55
has_key_predicate(const std::string &a_key)
The property key to be checked.
Definition: base_hit.h:214
bool has_hit_id() const
Serialization mask for the auxiliary properties attribute.
Definition: base_hit.h:50
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
Serialization mask for the geometry ID attribute.
Definition: base_hit.h:49
Reserved bit (chained)
Definition: base_hit.h:52
void invalidate_geom_id()
Reset the geometry ID.
base_hit & operator()(base_hit &)
Functor interface.
static const uint32_t bit01
Definition: bit_mask.h:28
geomtools::geom_id & grab_geom_id()
Get a reference on the mutable geometry ID.
Reserved bit (lock)
Definition: base_hit.h:51
void print_tree(std::ostream &out_=std::clog, const boost::property_tree::ptree &options_=datatools::i_tree_dumpable::empty_options()) const override
virtual void clear()
Reset the internals of the hit, making it invalid.
has_geom_id_predicate(const geomtools::geom_id &a_gid)
Constructor.
Definition: base_hit.h:298
bool has_auxiliaries() const
Check if there are stored auxiliary properties.
bool is_string(const std::string &prop_key_) const
Check if data with name 'prop_key_' is string.
base_hit()
Default constructor.
negates_predicate(const datatools::i_predicate< base_hit > &a_pred)
Constructor.
Definition: base_hit.h:323
void set_hit_id(int32_t)
Set the hit ID integer value.
has_hit_id_predicate(int a_hid)
Constructor.
Definition: base_hit.h:273
bool operator()(const base_hit &a_hit) const
Functor interface.
Definition: base_hit.h:305
virtual void do_measurement(base_hit &)=0
Main virtual interface method that performs a measurement on a hit.
static const uint32_t bit31
Definition: bit_mask.h:58
#define DATATOOLS_FACTORY_SYSTEM_AUTO_REGISTRATION_INTERFACE(BaseType, DerivedType)
Interface macro of the automated registration for derived classes.
Definition: factory_macros.h:87
#define DATATOOLS_SERIALIZATION_DECLARATION()
Definition: i_serializable.h:266
const geomtools::geom_id & get_geom_id() const
Get a reference on the non-mutable geometry ID.
has_string_property_predicate(const std::string &a_key, const std::string &a_value)
The vector of accepted values.
Definition: base_hit.h:237
has_flag_predicate(const std::string &a_flag)
The flag to be checked.
Definition: base_hit.h:192
The base class for hit objects that locate events in a geometry model.
Definition: base_hit.h:38
virtual void tree_dump(std::ostream &a_out=std::clog, const std::string &a_title="", const std::string &a_indent="", bool a_inherit=false) const
virtual void invalidate()
Reset the internals of the hit, making it invalid.
bool operator()(const base_hit &a_hit) const
Functor interface.
Definition: base_hit.h:255
datatools::properties & grab_auxiliaries()
Get a mutable reference on the auxiliaries container.
Predicate that checks if the hit has some specific geometry ID.
Definition: base_hit.h:293
bool _store_check(uint32_t bit_mask_) const
Check the bits from a mask.
bool has_flag(const std::string &key_) const
Check if a boolean value with a given key/name exists with value 'true'.
void reset()
Reset the internals of the hit, making it invalid.
bool has_key(const std::string &prop_key_) const
Check if a property with given key/name exists.
int32_t get_hit_id() const
static const uint32_t bit02
Definition: bit_mask.h:29
Predicate that checks if the auxiliaries container stores some property with a specific key.
Definition: base_hit.h:207
bool has_geom_id() const
Check if the geometry ID is valid.
A template predicate abstract class.
Definition: i_predicate.h:12
A pure abstract class (interface) for inherited clearable classes.
Definition: i_clear.h:9
static const uint32_t bit30
Definition: bit_mask.h:57
void dump() const
Smart print (default behaviour)
Predicate that checks if the auxiliaries container stores some property with a specific key.
Definition: base_hit.h:229
virtual bool is_valid() const
Check if the hit is valid.
bool operator()(const base_hit &a_hit) const
Functor interface.
Definition: base_hit.h:330
void set_auxiliaries(const datatools::properties &)
Set the auxiliaries container.
Predicate that checks if the auxiliaries container stores some specific flag.
Definition: base_hit.h:185
virtual ~base_hit()
Destructor.
Definition: geom_id.h:41
uint32_t _store
Definition: base_hit.h:361
Serialization mask for the hit ID attribute.
Definition: base_hit.h:48
static const uint32_t bit00
Definition: bit_mask.h:27
bool operator()(const base_hit &a_hit) const
Functor interface.
Definition: base_hit.h:280
base_hit & measure(i_measurement &)
Apply a measurement on the current hit.
#define DR_CLASS_RTTI()
Declare Camp RTTI within class declaration.
Definition: reflection_interface.h:46
#define DATATOOLS_FACTORY_SYSTEM_REGISTER_INTERFACE(BaseType)
Declaration of a system (allocator/functor) factory register as a static member of a base class and s...
Definition: factory_macros.h:52
void invalidate_auxiliaries()
Reset the mutable auxiliaries container.
Definition: base_hit.h:47
Predicate that checks if the hit has some specific ID.
Definition: base_hit.h:268
void _store_set(uint32_t bit_mask_)
Set the bits from a mask.
const datatools::properties & get_auxiliaries() const
Get a non-mutable reference on the auxiliaries container.
store_mask_type
Masks to automatically tag the attributes to be stored.
Definition: base_hit.h:46
bool operator()(const base_hit &a_hit) const
Functor interface.
Definition: base_hit.h:199
Generic abstract interface for a measurement on a hit.
Definition: base_hit.h:144
Predicate that negates another predicate.
Definition: base_hit.h:318
Top-level namespace of the Bayeux/geomtools module library.
Definition: electromagnetic_field_manager.h:39
std::string fetch_string(const std::string &name_, int index_=0) const
Fetch the string value stored with a given key/name and index.
A dictionary of arbitrary properties.
Definition: properties.h:125