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: 2010-02-21
4  * Last modified: 2013-02-19
5  *
6  * License:
7  *
8  * Copyright 2007-2013 F. Mauger
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  * Geometry manager
28  *
29  * History:
30  *
31  */
32 
33 #ifndef GEOMTOOLS_MANAGER_H
34 #define GEOMTOOLS_MANAGER_H 1
35 
36 // Standard library:
37 #include <string>
38 #include <map>
39 
40 // Third party:
41 // - Boost:
42 #include <boost/scoped_ptr.hpp>
43 #include <boost/shared_ptr.hpp>
44 // - Bayeux/datatools:
45 #include <datatools/handle.h>
46 #include <datatools/properties.h>
50 #include <datatools/i_tree_dump.h>
51 #include <datatools/logger.h>
52 
53 // This project:
56 #include <geomtools/id_mgr.h>
57 #include <geomtools/mapping.h>
58 
59 namespace datatools {
60  // Forward declaration:
61  class version_id;
62 }
63 
64 namespace geomtools {
65 
71  {
72  public:
73 
74  // Forward declaration:
75  class plugin_entry;
76 
78  typedef std::map<std::string, plugin_entry> plugins_dict_type;
79 
82  {
83  public:
84 
86  base_plugin();
87 
89  virtual ~base_plugin();
90 
92  void set_geo_manager(manager & geo_mgr_);
93 
95  const manager & get_geo_manager() const;
96 
98  virtual int initialize_standalone(const datatools::properties& config);
99 
101  virtual int initialize_simple(const datatools::properties & config_,
102  const plugins_dict_type & plugins_);
103 
105  virtual int initialize(const datatools::properties & config_,
106  const plugins_dict_type & plugins_,
107  const datatools::service_dict_type & services_) = 0;
108 
110  virtual int reset() = 0;
111 
113  virtual bool is_initialized() const = 0;
114 
117 
120 
121  protected:
122 
124  void _basic_initialize(const datatools::properties & config_);
125 
128 
130  bool _has_geom_setup_requirement() const;
131 
133  void _check_geom_setup_requirement() const;
134 
136 
137  private:
138 
139  manager * _geo_mgr_;
140  std::vector<std::string> _geom_setup_requirements_;
141 
142  // Factory stuff :
144  };
145 
147 
150  {
151  public:
152 
154  enum status_type {
155  STATUS_BLANK = 0x0,
158  };
159 
161  void set_name(const std::string&);
162 
164  const std::string& get_name() const;
165 
167  const std::string& get_id() const;
168 
170  void set_description(const std::string&);
171 
173  bool has_description() const;
174 
176  const std::string& get_description() const;
177 
179  const datatools::properties & get_config() const;
180 
182  void set_config(const datatools::properties &);
183 
186 
188  bool is_created() const;
189 
191  bool is_initialized() const;
192 
194  bool can_be_dropped() const;
195 
197  plugin_entry();
198 
200  ~plugin_entry();
201 
203  base_plugin & grab();
204 
206  const base_plugin & get() const;
207 
209  virtual void tree_dump(std::ostream & out_ = std::clog,
210  const std::string & title_ = "",
211  const std::string & indent_ = "",
212  bool inherit_ = false) const;
213 
214  protected:
215 
217  void _set_status(uint32_t);
218 
219  public:
220 
221  std::string _name_;
222  std::string _id_;
223  std::string _description_;
225  uint32_t _status_;
227 
228  // friend class manager;
229  };
230 
232  bool is_debug() const;
233 
235  bool is_verbose() const;
236 
238  bool is_initialized() const;
239 
241  bool has_services() const;
242 
244  void set_services(datatools::service_dict_type & services_);
245 
247  void reset_services();
248 
250  void set_setup_label(const std::string &);
251 
253  const std::string & get_setup_label() const;
254 
256  void set_setup_version(const std::string &);
257 
259  const std::string & get_setup_version() const;
260 
262  void set_setup_description(const std::string &);
263 
265  const std::string & get_setup_description() const;
266 
269 
271  void set_mapping_requested(bool);
272 
274  bool is_mapping_requested() const;
275 
277  bool is_mapping_available() const;
278 
280  void set_world_name(const std::string &);
281 
283  const std::string & get_world_name() const;
284 
286  void build_mapping(const datatools::properties & config_);
287 
290 
293 
295  const geomtools::model_factory & get_factory() const;
296 
299 
301  const geomtools::id_mgr & get_id_mgr() const;
302 
305 
307  const geomtools::mapping & get_mapping(const std::string & mapping_name_ = "") const;
308 
309  /* Plugins management */
310 
311  bool can_drop_plugin(const std::string& plugin_name_);
312 
313  void drop_plugin(const std::string& plugin_name_);
314 
315  void load_plugin(const std::string& plugin_name_,
316  const std::string& plugin_id_,
317  const datatools::properties& plugin_config_,
318  bool only_lock_ = false);
319 
320  void load_plugins(const datatools::multi_properties& plugin_config_,
321  bool only_lock_ = false);
322 
323  const plugins_dict_type & get_plugins() const;
324 
326 
330  template<class T>
331  bool is_plugin_a(const std::string & a_plugin_name) const;
332 
336  template<class T>
337  T& grab_plugin(const std::string & a_plugin_name);
338 
342  template<class T>
343  const T& get_plugin(const std::string & a_plugin_name) const;
344 
348  bool has_plugin(const std::string & a_plugin_name) const;
349 
350  void print_plugins(std::ostream& out = std::clog,
351  const std::string& title = "",
352  const std::string& indent = "") const;
353 
355  void clear_plugins();
356 
358  bool has_plugin_type(const std::string& plugin_id) const;
359 
361  template <class PluginClass>
362  void register_plugin_type(const std::string& plugin_id);
363 
365  void unregister_plugin_type(const std::string& plugin_id);
366 
367  /* Main interface */
368 
370  manager();
371 
373  virtual ~manager();
374 
376  void init(const datatools::properties & config_);
377 
379  void initialize(const datatools::properties & config_);
380 
382  void reset();
383 
385  virtual void tree_dump(std::ostream & out_ = std::clog,
386  const std::string & title_ = "",
387  const std::string & indent_ = "",
388  bool inherit_ = false) const;
389 
391  const base_plugin::factory_register_type & get_plugins_factory_register();
392 
394  void set_logging_priority(datatools::logger::priority a_logging_priority);
395 
398 
400  static int print_list_of_gids(const geomtools::manager & mgr_,
401  const std::string & command_,
402  const std::string & rules_ = "",
403  std::ostream & out_ = std::clog);
404 
405  protected:
406 
407  virtual void _pre_init(const datatools::properties & config_);
408 
409  virtual void _post_init(const datatools::properties & config_);
410 
411  void _load_plugin(const std::string& name,
412  const std::string& id,
413  const datatools::properties& config);
414 
416 
417  void _create_plugin(plugin_entry& entry);
418 
419  void _initialize_plugin(plugin_entry& entry);
420 
421  void _reset_plugin(plugin_entry& entry);
422 
423  private:
424 
426  virtual void _at_init_(const datatools::properties & config_);
427 
429  void _init_plugins_(const datatools::properties & config_);
430 
431  protected:
432 
434 
435  private:
436 
437  bool _initialized_;
438  std::string _setup_label_;
439  std::string _setup_version_;
440  std::string _setup_description_;
441 
442  datatools::service_dict_type * _services_;
443 
444  geomtools::shape_factory _shape_factory_;
445  geomtools::model_factory _factory_;
446  geomtools::id_mgr _id_manager_;
447  bool _mapping_requested_;
448  geomtools::mapping _mapping_;
449  datatools::multi_properties _external_mapping_rules_;
450 
451  std::string _world_name_;
452 
453  bool _plugins_factory_preload_;
454  bool _plugins_force_initialization_at_load_;
455  base_plugin::factory_register_type _plugins_factory_register_;
456  plugins_dict_type _plugins_;
457 
458  };
459 
460 } // end of namespace geomtools
461 
462 /***************
463  * OCD support *
464  ***************/
465 #include <datatools/ocd_macros.h>
467 
468 #include <geomtools/detail/manager-inl.h>
469 
470 #endif // GEOMTOOLS_MANAGER_H
471 
472 /*
473 ** Local Variables: --
474 ** mode: c++ --
475 ** c-file-style: "gnu" --
476 ** tab-width: 2 --
477 ** End: --
478 */
void reset()
Reset the geometry manager.
datatools::logger::priority _logging
Logging priority threshold.
Definition: manager.h:433
Not created not initialized.
Definition: manager.h:155
const datatools::properties & get_config() const
Set the configuration.
void _load_plugin(const std::string &name, const std::string &id, const datatools::properties &config)
Internal record plugin handling.
Definition: manager.h:149
void fetch_setup_version_id(datatools::version_id &vid_) const
Construct the version id associated to the setup.
The geometry ID mapping.
Definition: mapping.h:43
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
void set_name(const std::string &)
Set the name of the plugin.
bool has_services() const
Check if manager has services.
const std::string & get_setup_description() const
Return the description of the setup.
The factory of shapes.
Definition: shape_factory.h:36
std::string _id_
The ID (type) of the plugin.
Definition: manager.h:222
T & grab_plugin(const std::string &a_plugin_name)
Definition: manager-inl.h:37
virtual void _pre_init(const datatools::properties &config_)
datatools::properties _config_
The configuration of the plugin.
Definition: manager.h:224
const geomtools::mapping & get_mapping(const std::string &mapping_name_="") const
Return a reference to the non mutable mapping with explicit name.
status_type
Status of a plugin entry.
Definition: manager.h:154
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
std::map< std::string, service_entry_ptr > service_dict_type
Type alias for a flat dictionary of service entries.
Definition: service_tools.h:196
const std::string & get_world_name() const
Return the name of the world volume.
bool is_initialized() const
Check if plugin is initialized.
const T & get_plugin(const std::string &a_plugin_name) const
Definition: manager-inl.h:61
void set_description(const std::string &)
Set the description of the plugin.
The geometry manager's plugin base class.
Definition: manager.h:81
const std::string & get_description() const
Get the description of the plugin.
void _set_status(uint32_t)
Modify the status of the plugin entry.
virtual int initialize(const datatools::properties &config_, const plugins_dict_type &plugins_, const datatools::service_dict_type &services_)=0
Main initialization method from a list of properties, a list of other plugins and a list of services.
const base_plugin::factory_register_type & get_plugins_factory_register()
Return a reference to the plugin factory register.
bool is_mapping_requested() const
Check if the build of the mapping has been requested.
void init(const datatools::properties &config_)
Initialize the geometry manager from a container of properties.
void unregister_plugin_type(const std::string &plugin_id)
Unregister a plugin type.
void drop_plugin(const std::string &plugin_name_)
virtual void _post_init(const datatools::properties &config_)
bool is_created() const
Check if plugin is created.
void _reset_plugin(plugin_entry &entry)
plugin_entry()
Default constructor.
datatools::logger::priority _logging
Definition: manager.h:135
const geomtools::shape_factory & get_shape_factory() const
Return a reference to the non mutable factory of shapes.
Created.
Definition: manager.h:156
void _initialize_plugin(plugin_entry &entry)
bool can_be_dropped() const
Check if plugin can be dropped by the manager.
std::string _name_
Name of the plugin.
Definition: manager.h:221
Initialized.
Definition: manager.h:157
virtual int reset()=0
Main reset method.
plugins_dict_type & grab_plugins()
const std::string & get_id() const
Get the ID of the plugin.
const geomtools::id_mgr & get_id_mgr() const
Return a reference to the non mutable geometry ID manager.
const std::string & get_name() const
Get the name of the plugin.
plugin_handle_type _handle_
Handle to the plugin.
Definition: manager.h:226
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
virtual int initialize_standalone(const datatools::properties &config)
Initialize the plugin using only a list of properties without the needs of other resources.
void register_plugin_type(const std::string &plugin_id)
Register a plugin type.
Definition: manager-inl.h:68
void set_mapping_requested(bool)
Request the build of the mapping.
datatools::logger::priority get_logging_priority() const
Get the logging priority threshold.
void set_logging_priority(datatools::logger::priority a_logging_priority)
Set the logging priority threshold.
manager()
Default constructor.
DOCD_CLASS_DECLARATION(my::algo)
Declaration of the OCD support for the my::algo class.
void clear_plugins()
Clear the plugins.
bool is_mapping_available() const
Check if the mapping is built.
base_plugin & grab()
Return a reference to the mutable plugin.
void _basic_initialize(const datatools::properties &config_)
Basic initialization.
const std::string & get_setup_label() const
Return the label of the setup.
Definition: id_mgr.h:37
static int print_list_of_gids(const geomtools::manager &mgr_, const std::string &command_, const std::string &rules_="", std::ostream &out_=std::clog)
Print the list of geometry identifiers (GIDs) from a manager and given specific rules.
bool is_plugin_a(const std::string &a_plugin_name) const
Definition: manager-inl.h:14
void set_config(const datatools::properties &)
Get the configuration.
void set_setup_version(const std::string &)
Set the version of the setup.
void set_world_name(const std::string &)
Set the name of the world volume.
std::map< std::string, plugin_entry > plugins_dict_type
Dictionary of plugin entries.
Definition: manager.h:75
const base_plugin & get() const
Return a reference to the non mutable plugin.
virtual bool is_initialized() const =0
Check if plugin is initialized.
const manager & get_geo_manager() const
Get a non-mutable reference to the geometry manager.
void _preload_plugins_global_dict()
void load_plugin(const std::string &plugin_name_, const std::string &plugin_id_, const datatools::properties &plugin_config_, bool only_lock_=false)
bool is_debug() const
Check the debug flag.
geomtools::shape_factory & grab_shape_factory()
Return a reference to the mutable factory of shapes.
void set_setup_description(const std::string &)
Set the description of the setup.
std::string _description_
Description of the plugin.
Definition: manager.h:223
bool _has_geom_setup_requirement() const
Check presence of geometry requirements.
void load_plugins(const datatools::multi_properties &plugin_config_, bool only_lock_=false)
void set_logging_priority(datatools::logger::priority)
Set the logging priority threshold.
void _create_plugin(plugin_entry &entry)
const plugins_dict_type & get_plugins() const
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
bool can_drop_plugin(const std::string &plugin_name_)
Utilities for logging information.
Geometry manager for virtual geometry modelling. Main geometry manager for the modelisation of variou...
Definition: manager.h:70
bool has_plugin_type(const std::string &plugin_id) const
Check if some plugin type is known.
void set_geo_manager(manager &geo_mgr_)
Set the reference to the geometry manager.
The factory of geometry models.
Definition: model_factory.h:40
void initialize(const datatools::properties &config_)
Initialize the geometry manager from a container of properties.
bool has_plugin(const std::string &a_plugin_name) const
datatools::properties & grab_config()
Grab the configuration.
geomtools::model_factory & grab_factory()
Return a reference to the mutable factory of geometry models.
~plugin_entry()
Destructor.
void _check_geom_setup_requirement() const
Check geometry requirement.
datatools::handle< base_plugin > plugin_handle_type
Definition: manager.h:146
bool is_initialized() const
Check the initialization flag.
void set_setup_label(const std::string &)
Set the label of the setup.
virtual ~manager()
Destructor.
virtual ~base_plugin()
Destructor.
void build_mapping(const datatools::properties &config_)
Build the mapping.
#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
geomtools::id_mgr & grab_id_mgr()
Return a reference to the mutable geometry ID manager.
datatools::logger::priority get_logging_priority() const
Return the logging priority threshold.
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
A class representing a version ID :
Definition: version_id.h:67
bool is_verbose() const
Check the verbose flag.
const geomtools::model_factory & get_factory() const
Return a reference to the non mutable factory of geometry models.
void set_services(datatools::service_dict_type &services_)
Set the dictionary of services.
uint32_t _status_
Status of the plugin.
Definition: manager.h:225
void reset_services()
Reset the dictionary of services.
const std::string & get_setup_version() const
Return the version of the setup.
virtual int initialize_simple(const datatools::properties &config_, const plugins_dict_type &plugins_)
Initialize the plugin using a list of properties and a list of other plugins.
void print_plugins(std::ostream &out=std::clog, const std::string &title="", const std::string &indent="") const
manager & _grab_geo_manager()
Get a mutable reference to the geometry manager.
bool has_description() const
Check is the description is not empty.
Top-level namespace of the Bayeux/geomtools module library.
Definition: electromagnetic_field_manager.h:39
A dictionary of arbitrary properties.
Definition: properties.h:125