Bayeux  3.4.1
Core Foundation library for SuperNEMO
base_signal.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date : 2016-09-27
4  * Last modified : 2016-09-27
5  *
6  * Copyright (C) 2016 Francois Mauger <mauger@lpccaen.in2p3.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or (at
11  * your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  * Description:
24  *
25  * A base class representing an analog signal associated to a hit detector.
26  *
27  */
28 
29 #ifndef MCTOOLS_SIGNAL_BASE_SIGNAL_H
30 #define MCTOOLS_SIGNAL_BASE_SIGNAL_H
31 
32 // Third party:
33 // - Bayeux/datatools:
34 #include <datatools/logger.h>
35 #include <datatools/properties.h>
37 // - Bayeux/mygsl:
38 #include <mygsl/i_unary_function.h>
39 // - Bayeux/geomtools:
40 #include <geomtools/base_hit.h>
41 
42 namespace mctools {
43 
44  namespace signal {
45 
47 
56  {
57  public:
58 
59  static const std::string & shape_parameter_prefix();
60  static const std::string & allow_no_shape_builder_key();
61  static std::string build_shape_key(const int32_t);
62  static std::string build_private_shape_key(const int32_t, const std::size_t);
63 
65  base_signal();
66 
68  base_signal(const base_signal &);
69 
71  virtual ~base_signal();
72 
75 
77  virtual bool is_valid() const;
78 
80  void set_allow_no_shape_builder(bool a_);
81 
83  bool is_shape_builder_mandatory() const;
84 
87 
90 
92  bool has_time_ref() const;
93 
95  double get_time_ref() const;
96 
98  void set_time_ref(const double);
99 
101  void reset_time_ref();
102 
104  bool has_shape_builder() const;
105 
107  const signal_shape_builder & get_shape_builder() const;
108 
111 
114 
116  bool has_category() const;
117 
119  const std::string & get_category() const;
120 
122  void set_category(const std::string &);
123 
125  void reset_category();
126 
128  bool has_shape_type_id() const;
129 
131  const std::string & get_shape_type_id() const;
132 
134  void set_shape_type_id(const std::string &);
135 
137  void set_shape_parameters(const datatools::properties & params_);
138 
140  void reset_shape_parameters();
141 
143  void reset_shape_parameter(const std::string & key_);
144 
146  void set_shape_boolean_parameter(const std::string & key_,
147  const bool value_,
148  const std::string & desc_ = "");
149 
151  void set_shape_boolean_parameters(const std::string & key_,
152  const std::vector<bool> & values_,
153  const std::string & desc_ = "");
154 
156  void set_shape_integer_parameter(const std::string & key_,
157  const int value_,
158  const std::string & desc_ = "");
159 
161  void set_shape_integer_parameters(const std::string & key_,
162  const std::vector<int> & values_,
163  const std::string & desc_ = "");
164 
166  void set_shape_string_parameter(const std::string & key_,
167  const std::string & value_,
168  const std::string & desc_ = "");
169 
171  void set_shape_string_parameters(const std::string & key_,
172  const std::vector<std::string> & values_,
173  const std::string & desc_ = "");
174 
176  void set_shape_real_parameter(const std::string & key_,
177  const double value_,
178  const std::string & desc_ = "");
179 
181  void set_shape_real_parameters(const std::string & key_,
182  const std::vector<double> & values_,
183  const std::string & desc_ = "");
184 
186  void set_shape_real_parameter_with_explicit_unit(const std::string & key_,
187  const double value_,
188  const std::string & unit_symbol_,
189  const std::string & desc_ = "");
190 
192  void set_shape_real_parameters_with_explicit_unit(const std::string & key_,
193  const std::vector<double> & values_,
194  const std::string & unit_symbol_,
195  const std::string & desc_ = "");
196 
198  void add_private_shape(const std::string & key_,
199  const std::string & type_id_,
200  const datatools::properties & parameters_);
201 
203  std::string add_auto_private_shape(const std::string & type_id_,
204  const datatools::properties & parameters_);
205 
207  void remove_private_shape(const std::string & key_);
208 
210  void remove_private_shapes();
211 
213  bool is_shape_instantiated() const;
214 
216  const mygsl::i_unary_function & get_shape() const;
217 
219  void reset_shape();
220 
222  void set_shape(const mygsl::i_unary_function & shape_);
223 
225  void set_shape_owned(const mygsl::i_unary_function * shape_ptr_);
226 
228  void unlock();
229 
231  void relock();
232 
234  bool is_initialized() const;
235 
237  void initialize_simple();
238 
240  void initialize(const datatools::properties & config_);
241 
243  void reset();
244 
246  bool has_private_shapes_config() const;
247 
250 
252  virtual void tree_dump(std::ostream & out_ = std::clog,
253  const std::string & title_ = "",
254  const std::string & indent_ = "",
255  bool inherit_ = false) const;
256 
258  double compute_shape(double time_) const;
259 
261  static bool build_signal_shape(signal_shape_builder & builder_,
262  const std::string & key_,
263  base_signal & signal_,
265 
267  bool instantiate_signal_shape(signal_shape_builder & builder_, const std::string & key_ = "");
268 
269  private:
270 
272  const mygsl::i_unary_function & _get_shape_();
273 
275  void _copy_(const base_signal & sig_);
276 
278  void _reset_shape_();
279 
281  void _set_shape_(const mygsl::i_unary_function &, bool owned_);
282 
284  void _init_();
285 
287  void _reset_();
288 
290  void _base_construct_();
291 
292  private:
293 
294  // Management:
295  bool _initialized_ = false;
296  datatools::logger::priority _logging_;
297  signal_shape_builder * _shape_builder_ = nullptr;
298 
299  // Configuration:
300  std::string _category_;
301  double _time_ref_;
302  std::string _shape_type_id_;
303  datatools::multi_properties _private_shapes_config_;
304 
305  // Working data:
306  bool _owned_shape_ = false;
307  const mygsl::i_unary_function * _shape_ = nullptr;
308 
310 
311 
312  DR_CLASS_RTTI()
313 
314  };
315 
316  } // end of namespace signal
317 
318 } // end of namespace mctools
319 
320 // Activate reflection layer :
322 
323 #endif // MCTOOLS_SIGNAL_BASE_SIGNAL_H
324 
325 // Local Variables: --
326 // mode: c++ --
327 // c-file-style: "gnu" --
328 // tab-width: 2 --
329 // End: --
#define DR_CLASS_INIT(Introspectable)
Inform Camp that class Introspectable exists and trigger the automatic registration of dedicated refl...
Definition: reflection_interface.h:149
const signal_shape_builder & get_shape_builder() const
Return a handle to a shape builder.
Abstract base class representing an analog signal associated to a hit detector.
Definition: base_signal.h:55
signal_shape_builder & grab_shape_builder()
Return a handle to a shape builder.
void reset_shape()
Discard the embedded signal shape object.
void reset_shape_parameters()
Erase the full set of parameters for the shape object.
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
static std::string build_private_shape_key(const int32_t, const std::size_t)
A container of mapped properties objects.
Definition: multi_properties.h:99
void remove_private_shape(const std::string &key_)
Remove a private shape.
Definition: base_step_hit.h:32
std::string add_auto_private_shape(const std::string &type_id_, const datatools::properties &parameters_)
Add a private shape (only useful if a shape builder is associated to the base signal)
bool is_initialized() const
Check initialization.
static std::string build_shape_key(const int32_t)
void set_shape_owned(const mygsl::i_unary_function *shape_ptr_)
Set the embedded signal shape object with transfered ownership.
void set_shape_type_id(const std::string &)
Set the shape type identifier.
void set_shape_string_parameters(const std::string &key_, const std::vector< std::string > &values_, const std::string &desc_="")
Set a vector of string parameters for the shape object.
const std::string & get_category() const
Set the signal category.
datatools::logger::priority get_logging() const
Return the logging priority.
A fatal error. The application will most likely terminate. This is the highest priority.
Definition: logger.h:85
void initialize_simple()
Initialize the signal.
const std::string & get_shape_type_id() const
Return the shape type identifier.
bool has_private_shapes_config() const
Check if some private shapes are setup.
void set_shape_real_parameters(const std::string &key_, const std::vector< double > &values_, const std::string &desc_="")
Set a vector of real parameters for the shape object.
void set_shape_real_parameter_with_explicit_unit(const std::string &key_, const double value_, const std::string &unit_symbol_, const std::string &desc_="")
Set a real parameter for the shape object (with explicit unit)
const datatools::multi_properties & get_private_shapes_config() const
Return the configuration informations for private shapes.
double get_time_ref() const
Return the time reference.
void reset_time_ref()
Reset the time reference.
const mygsl::i_unary_function & get_shape() const
Return a const reference to the embedded signal shape.
void set_shape_boolean_parameters(const std::string &key_, const std::vector< bool > &values_, const std::string &desc_="")
Set a vector of boolean parameters for the shape object.
void set_shape_string_parameter(const std::string &key_, const std::string &value_, const std::string &desc_="")
Set a string parameter for the shape object.
void set_shape_boolean_parameter(const std::string &key_, const bool value_, const std::string &desc_="")
Set a boolean parameter for the shape object.
void set_allow_no_shape_builder(bool a_)
Allow no shape builder.
#define DATATOOLS_SERIALIZATION_DECLARATION()
Definition: i_serializable.h:266
void reset_category()
Reset the signal category.
A signal shape builder/factory.
Definition: signal_shape_builder.h:59
void set_category(const std::string &)
Set the signal category.
double compute_shape(double time_) const
Compute shape.
void reset()
Reset the signal.
bool is_shape_instantiated() const
Check if a shape is instantiated.
The base class for hit objects that locate events in a geometry model.
Definition: base_hit.h:38
bool is_shape_builder_mandatory() const
Check is a shape builder is mandatory to build the signal shape object.
void set_shape_integer_parameters(const std::string &key_, const std::vector< int > &values_, const std::string &desc_="")
Set a vector of integer parameters for the shape object.
bool has_time_ref() const
Check if time reference is set.
void set_shape_real_parameter(const std::string &key_, const double value_, const std::string &desc_="")
Set a real parameter for the shape object.
void reset_shape_parameter(const std::string &key_)
Erase one specific parameter for the shape object.
static const std::string & allow_no_shape_builder_key()
Abstract interface for unary functions : R -> R.
Definition: i_unary_function.h:44
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
void set_shape_builder(signal_shape_builder &)
Set a handle to a shape builder.
void set_shape(const mygsl::i_unary_function &shape_)
Set the embedded signal shape object without ownership.
virtual ~base_signal()
Destructor.
void set_time_ref(const double)
Set the time reference.
static bool build_signal_shape(signal_shape_builder &builder_, const std::string &key_, base_signal &signal_, const datatools::logger::priority logging_=datatools::logger::PRIO_FATAL)
Build the signal shape from a builder.
bool instantiate_signal_shape(signal_shape_builder &builder_, const std::string &key_="")
Instantiate the signal shape from a builder.
Utilities for logging information.
void set_shape_real_parameters_with_explicit_unit(const std::string &key_, const std::vector< double > &values_, const std::string &unit_symbol_, const std::string &desc_="")
Set a vector of real parameters for the shape object (with explicit unit)
void initialize(const datatools::properties &config_)
Initialize the signal.
void remove_private_shapes()
Remove all private shapes.
bool has_shape_type_id() const
Check the shape type identifier.
base_signal & operator=(const base_signal &)
Assignment operator.
bool has_shape_builder() const
Check if a shape builder is set.
void set_shape_integer_parameter(const std::string &key_, const int value_, const std::string &desc_="")
Set a integer parameter for the shape object.
#define DR_CLASS_RTTI()
Declare Camp RTTI within class declaration.
Definition: reflection_interface.h:46
void set_logging(const datatools::logger::priority)
Set the logging priority.
virtual bool is_valid() const
Check signal hit validity.
bool has_category() const
Check if the signal has category.
static const std::string & shape_parameter_prefix()
void add_private_shape(const std::string &key_, const std::string &type_id_, const datatools::properties &parameters_)
Add a private shape (only useful if a shape builder is associated to the base signal)
base_signal()
Default constructor.
void set_shape_parameters(const datatools::properties &params_)
Set the full set of parameters for the shape object.
A dictionary of arbitrary properties.
Definition: properties.h:125