Bayeux  3.4.1
Core Foundation library for SuperNEMO
manager.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date : 2013-02-24
4  * Last modified :
5  *
6  * Copyright (C) 2011-2013 Francois Mauger <mauger@lpccaen.in2p3.fr>
7  * Copyright (C) 2012 Ben Morgan <Ben.Morgan@warwick.ac.uk>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or (at
12  * your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  *
24  *
25  * Description:
26  *
27  * A particle generator manager.
28  *
29  * History:
30  *
31  */
32 #ifndef GENBB_HELP_MANAGER_H
33 #define GENBB_HELP_MANAGER_H 1
34 
35 // Standard Library
36 #include <string>
37 #include <sstream>
38 #include <typeinfo>
39 #include <stdexcept>
40 
41 // Third Party
42 // - Boost
43 #include <boost/cstdint.hpp>
44 
45 // Datatools
46 #include <datatools/i_tree_dump.h>
47 #include <datatools/bit_mask.h>
48 #include <datatools/logger.h>
49 
50 // Mygsl
51 #include <mygsl/rng.h> // Pseudo random number generator
52 
53 // genbb_help
55 #include <genbb_help/i_genbb.h>
56 
57 namespace datatools {
58  class properties;
59  class multi_properties;
60  class service_manager;
61 }
62 
64 namespace genbb {
65 
69  class manager
71  {
72  public:
73  enum flag_type {
74  BLANK = 0,
77  };
78 
79  public:
80 
81  bool has_service_manager() const;
82 
84 
85  void reset_service();
86 
89 
91  ~manager();
92 
94  bool is_debug() const;
95 
97  void set_debug(bool debug_ = true);
98 
100  bool has_external_prng() const;
101 
104 
106  void reset_external_prng();
107 
110 
112  const mygsl::rng & get_external_prng() const;
113 
116 
118  const mygsl::rng & get_embedded_prng() const;
119 
121  void set_embedded_prng_seed(int seed_);
122 
124  mygsl::rng & grab_prng();
125 
127  const mygsl::rng & get_prng() const;
128 
130  bool has_default_generator() const;
131 
133  void set_default_generator(const std::string &);
134 
136  const std::string & get_default_generator() const;
137 
139  bool is_initialized() const;
140 
142  void initialize(const datatools::properties & config_);
143 
145  void reset();
146 
148  bool has_pg_type(const std::string & id_) const;
149 
151  template <class PgClass>
152  void register_pg_type(const std::string & id_);
153 
155  void unregister_pg_type(const std::string & id_);
156 
160  bool has(const std::string & name_) const;
161 
165  bool is_initialized(const std::string & name_) const;
166 
170  bool can_drop(const std::string & name_) const;
171 
174  void drop(const std::string & name_);
175 
178  void reset(const std::string & name_);
179 
183  const std::string & get_id(const std::string & name_) const;
184 
188  const i_genbb & get(const std::string & name_) const;
189 
193  i_genbb & grab(const std::string & name_);
194 
195  void load(const std::string & name_,
196  const std::string & id_,
197  const datatools::properties & config_);
198 
199  void load(const datatools::multi_properties & config_);
200 
201  void dump_particle_generators(std::ostream & out_ = std::clog,
202  const std::string & title_ = "",
203  const std::string & indent_ = "") const;
204 
205  void print_particle_generators(std::ostream & out_ = std::clog,
206  const std::string & title_ = "",
207  const std::string & indent_ = "",
208  const std::string & mode_ = "") const;
209 
211  virtual void tree_dump(std::ostream & out_ = std::clog,
212  const std::string & title_ = "",
213  const std::string & indent_ = "",
214  bool inherit_ = false) const;
215 
217 
219 
221 
223 
224  protected:
225 
226  // Note: move to private ASAP
227 
228  void _load_pg(const std::string & name_,
229  const std::string & id_,
230  const datatools::properties & config_);
231 
232  void _preload_global_dict();
233 
234  void _create_pg(detail::pg_entry_type & entry_);
235 
236  void _initialize_pg(detail::pg_entry_type & entry_);
237 
238  void _reset_pg(detail::pg_entry_type & entry_);
239 
240  private:
241 
243  void _set_preload_(bool preload_);
244 
245  private:
246 
247  datatools::service_manager * _service_mgr_ = nullptr;
248 
249  bool _initialized_;
250  datatools::logger::priority _logging_priority_;
251  bool _preload_;
252  bool _force_initialization_at_load_;
253  std::string _default_generator_;
254 
255  mygsl::rng * _external_prng_;
256  int _embedded_prng_seed_;
257  mygsl::rng _embedded_prng_;
258 
259  datatools::factory_register<i_genbb> _factory_register_;
260  detail::pg_dict_type _particle_generators_;
261 
262  };
263 
264 
265  template <class PgClass>
266  void manager::register_pg_type(const std::string & id_)
267  {
268  _factory_register_.registration(id_, boost::factory<PgClass*>());
269  }
270 
271 } // end of namespace genbb
272 
273 /***************
274  * OCD support *
275  ***************/
276 #include <datatools/ocd_macros.h>
278 
279 #endif // GENBB_HELP_MANAGER_H
280 
281 // Local Variables: --
282 // mode: c++ --
283 // End: --
bool has_pg_type(const std::string &id_) const
Check if the factory has a given type.
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
bool has(const std::string &name_) const
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
A container of mapped properties objects.
Definition: multi_properties.h:99
Definition: manager.h:75
void load(const std::string &name_, const std::string &id_, const datatools::properties &config_)
const mygsl::rng & get_embedded_prng() const
Return a non-mutable reference to the embedded PRNG.
void drop(const std::string &name_)
void set_embedded_prng_seed(int seed_)
Set the seed of the embedded PRNG.
bool can_drop(const std::string &name_) const
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
GENBB particle generator abstract base class.
Definition: i_genbb.h:59
static const uint32_t bit01
Definition: bit_mask.h:28
void dump_particle_generators(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="") const
const mygsl::rng & get_external_prng() const
Return a non-mutable reference to the external PRNG.
const mygsl::rng & get_prng() const
Return a non-mutable reference to the active PRNG.
void _load_pg(const std::string &name_, const std::string &id_, const datatools::properties &config_)
~manager()
Destructor.
flag_type
Definition: manager.h:73
const std::string & get_id(const std::string &name_) const
const i_genbb & get(const std::string &name_) const
void _preload_global_dict()
void _initialize_pg(detail::pg_entry_type &entry_)
void register_pg_type(const std::string &id_)
Register a given type in the factory.
Definition: manager.h:266
bool is_debug() const
Check the debug flag.
mygsl::rng & grab_prng()
Return a mutable reference to the active PRNG.
Template factory registration class.
Definition: factory.h:51
void _reset_pg(detail::pg_entry_type &entry_)
i_genbb & grab(const std::string &name_)
datatools::logger::priority get_logging_priority() const
DOCD_CLASS_DECLARATION(my::algo)
Declaration of the OCD support for the my::algo class.
void initialize(const datatools::properties &config_)
Initialize the manager from a container of properties.
const std::string & get_default_generator() const
Return the default generator name.
void reset()
Reset the manager.
Definition: pg_tools.h:46
Definition: manager.h:74
mygsl::rng & grab_external_prng()
Return a mutable reference to the external PRNG.
bool has_external_prng() const
Check the use of some external PRNG.
void reset_external_prng()
Reset the external PRNG.
void set_debug(bool debug_=true)
Set the debug flag.
Top-level namespace of the Bayeux/genbb_help module library.
Definition: alpha_decay.h:51
void set_external_prng(mygsl::rng &)
Set the external PRNG.
const datatools::factory_register< i_genbb > & get_factory_register() const
bool is_initialized() const
Check the initialization flag.
void print_particle_generators(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", const std::string &mode_="") const
bool has_default_generator() const
Check is a default generator is set.
datatools::factory_register< i_genbb > & grab_factory_register()
void _create_pg(detail::pg_entry_type &entry_)
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
Utilities for logging information.
mygsl::rng & grab_embedded_prng()
Return a mutable reference to the embedded PRNG.
void set_service_manager(datatools::service_manager &service_mgr_)
A warning. An operation completed with an unexpected result.
Definition: logger.h:88
void set_logging_priority(datatools::logger::priority p_)
static const uint32_t bit00
Definition: bit_mask.h:27
void set_default_generator(const std::string &)
Set the default generator name.
bool has_service_manager() const
manager(datatools::logger::priority p_=datatools::logger::PRIO_WARNING, int flags_=0)
Constructor.
std::map< std::string, pg_entry_type > pg_dict_type
Definition: pg_tools.h:134
void unregister_pg_type(const std::string &id_)
Unregister a given type from the factory.
GENBB particle manager management class.
Definition: manager.h:69
Service management class.
Definition: service_manager.h:57
Pseudo random number generator.
Definition: rng.h:53
void reset_service()
A dictionary of arbitrary properties.
Definition: properties.h:125