Bayeux  3.4.1
Core Foundation library for SuperNEMO
signal_shape_builder.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Author(s) : Guillaume OliviĆ©ro <goliviero@lpccaen.in2p3.fr>
4  * Creation date : 2016-11-29
5  * Last modified : 2016-11-29
6  *
7  * Copyright (C) 2016 Francois Mauger <mauger@lpccaen.in2p3.fr>
8  * Copyright (C) 2016 Guillaume OliviĆ©ro <goliviero@lpccaen.in2p3.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or (at
13  * your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
23  * Boston, MA 02110-1301, USA.
24  *
25  * Description:
26  *
27  * A signal shape builder
28  *
29  */
30 
31 #ifndef MCTOOLS_SIGNAL_SIGNAL_SHAPE_BUILDER_H
32 #define MCTOOLS_SIGNAL_SIGNAL_SHAPE_BUILDER_H
33 
34 // Standard library:
35 #include <string>
36 #include <map>
37 
38 // Third party:
39 // - Boost:
40 #include <boost/noncopyable.hpp>
41 // - Bayeux/datatools:
42 #include <datatools/properties.h>
43 #include <datatools/factory.h>
44 #include <datatools/i_tree_dump.h>
45 // - Bayeux/mygsl:
46 #include <mygsl/i_unary_function.h>
47 // - Bayeux/geomtools:
48 #include <geomtools/base_hit.h>
49 
50 namespace datatools {
51  class service_manager;
52 } // end of namespace datatools
53 
54 namespace mctools {
55 
56  namespace signal {
57 
60  : private boost::noncopyable
62  {
63  public:
64 
66 
67  // Return the prefix for reference functor keys
68  static const std::string & reference_functor_prefix();
69 
72 
75 
78 
81 
83  bool has_category() const;
84 
86  void set_category(const std::string &);
87 
89  void reset_category();
90 
92  const std::string & get_category() const;
93 
95  void add_registered_shape_type_id(const std::string &);
96 
98  bool has_registered_shape_type_id(const std::string & )const;
99 
101  bool has_service_mgr() const;
102 
105 
108 
110  bool is_initialized() const;
111 
113  void initialize_simple();
114 
116  void initialize(const datatools::properties & config_);
117 
119  void reset();
120 
123  create_signal_shape(const std::string & key_,
124  const std::string & shape_type_id_,
125  const datatools::properties & shape_params_);
126 
128  bool has_functor_factory(const std::string & shape_type_id_) const;
129 
131  bool has_reference_functor(const std::string & key_) const;
132 
134  const mygsl::i_unary_function & get_reference_functor(const std::string & key_) const;
135 
137  void load_reference_functors_from_file(const std::string & filename_);
138 
140  void add_reference_functor(const std::string & key_,
141  const std::string & shape_type_id_,
142  const datatools::properties & shape_params_);
143 
145  bool has_functor(const std::string & key_) const;
146 
148  mygsl::i_unary_function & grab_functor(const std::string & key_);
149 
151  const mygsl::i_unary_function & get_functor(const std::string & key_) const;
152 
154  mygsl::const_unary_function_handle_type get_functor_handle(const std::string & key_) const;
155 
157  void clear_functor(const std::string & key_);
158 
160  void clear_functors();
161 
164 
166  void build_list_of_reference_functors(std::set<std::string> &) const;
167 
169  void build_list_of_functors(std::set<std::string> &) const;
170 
172  virtual void tree_dump(std::ostream & out_ = std::clog,
173  const std::string & title_ = "",
174  const std::string & indent_ = "",
175  bool inherit_ = false) const;
176 
177  private:
178 
179  void _init_(const datatools::properties * config_);
180 
181  void _init_reference_functors_();
182 
183  void _init_registration_();
184 
185  void _reset_();
186 
187  std::string _generate_functor_key();
188 
189  void _update_all_functors_();
190 
191  private:
192 
193  // Management:
194  bool _initialized_ = false;
195  datatools::logger::priority _logging_;
196 
197  // Configuration:
198  std::string _category_;
199  std::set<std::string> _registered_shape_type_ids_;
200  const datatools::service_manager * _service_mgr_ = nullptr;
201 
202  // Working data:
204  mygsl::unary_function_dict_type _reference_functors_;
206  mygsl::unary_function_dict_type _all_functors_;
207 
209  DR_CLASS_RTTI()
210 
211  };
212 
213  } // end of namespace signal
214 
215 } // end of namespace mctools
216 
217 // Activate reflection layer :
219 
220 #endif // MCTOOLS_SIGNAL_SIGNAL_SHAPE_BUILDER_H
221 
222 // Local Variables: --
223 // mode: c++ --
224 // c-file-style: "gnu" --
225 // tab-width: 2 --
226 // 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
bool has_functor_factory(const std::string &shape_type_id_) const
Check if a functor factory exists.
void build_list_of_reference_functors(std::set< std::string > &) const
Build the list of reference functors.
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
static const std::string & reference_functor_prefix()
Definition: base_step_hit.h:32
const mygsl::i_unary_function & get_functor(const std::string &key_) const
Return a const reference to an user functor.
bool has_reference_functor(const std::string &key_) const
Check if a reference functor with given key exists.
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
bool has_registered_shape_type_id(const std::string &) const
Check if a registered shape type identifier exists.
mygsl::i_unary_function & grab_functor(const std::string &key_)
Return a mutable reference to an user functor.
datatools::logger::priority get_logging_priority() const
Return the logging priority.
datatools::factory_register< mygsl::i_unary_function > freg_type
Definition: signal_shape_builder.h:65
const std::string & get_category() const
Return the category of signals.
void load_reference_functors_from_file(const std::string &filename_)
Load definition file for reference functors.
bool has_service_mgr() const
Check if the handle to an external service manager is set.
mygsl::const_unary_function_handle_type get_functor_handle(const std::string &key_) const
Return a handle to a const user functor.
signal_shape_builder()
Default constructor.
void set_service_mgr(const datatools::service_manager &)
Set the handle to an external service manager.
A signal shape builder/factory.
Definition: signal_shape_builder.h:59
void add_registered_shape_type_id(const std::string &)
Add registered shape type identifier.
void initialize_simple()
Initialize the signal builder.
void build_list_of_functors(std::set< std::string > &) const
Build the list of user functors.
bool has_category() const
Check if a category of signal is set.
bool has_functor(const std::string &key_) const
Check if an user functor with given key exists.
const mygsl::i_unary_function & create_signal_shape(const std::string &key_, const std::string &shape_type_id_, const datatools::properties &shape_params_)
Instantiate a functor.
Abstract interface for unary functions : R -> R.
Definition: i_unary_function.h:44
const mygsl::unary_function_dict_type & get_functors() const
Return the dictionnary of functors.
void clear_functors()
Remove all user functors.
void set_category(const std::string &)
Set the category of signals.
void reset_category()
Reset the category of signals.
void initialize(const datatools::properties &config_)
Initialize the signal builder from a set of configuration properties.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
std::map< std::string, unary_function_handle_type > unary_function_dict_type
Alias for dictionary of handles to unary function objects.
Definition: unary_function_utils.h:30
void add_reference_functor(const std::string &key_, const std::string &shape_type_id_, const datatools::properties &shape_params_)
Create a new reference functor.
#define DR_CLASS_RTTI()
Declare Camp RTTI within class declaration.
Definition: reflection_interface.h:46
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
void clear_functor(const std::string &key_)
Remove an user functor with given key.
bool is_initialized() const
Check initialization.
Service management class.
Definition: service_manager.h:57
const mygsl::i_unary_function & get_reference_functor(const std::string &key_) const
Return a const reference to a reference functor.
const datatools::service_manager & get_service_mgr() const
Return the handle to an external service manager.
void set_logging_priority(const datatools::logger::priority)
Set the logging priority.
A dictionary of arbitrary properties.
Definition: properties.h:125