CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ComponentFactory.h
Go to the documentation of this file.
1 #ifndef Framework_ComponentFactory_h
2 #define Framework_ComponentFactory_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : ComponentFactory
7 //
16 //
17 // Author: Chris Jones
18 // Created: Wed May 25 15:21:05 EDT 2005
19 //
20 
21 // system include files
22 #include <string>
23 #include <map>
24 #include "boost/shared_ptr.hpp"
25 
26 // user include files
33 
34 // forward declarations
35 namespace edm {
36  namespace eventsetup {
37  class EventSetupProvider;
38 
39 template<typename T>
41 {
42 
43  public:
45  //~ComponentFactory();
46 
48  typedef std::map<std::string, boost::shared_ptr<Maker> > MakerMap;
49  typedef typename T::base_type base_type;
50  // ---------- const member functions ---------------------
51  boost::shared_ptr<base_type> addTo(EventSetupProvider& iProvider,
52  edm::ParameterSet const& iConfiguration,
53  std::string const& iProcessName,
54  ReleaseVersion const& iVersion,
55  PassID const& iPass) const
56  {
57  std::string modtype = iConfiguration.template getParameter<std::string>("@module_type");
58  //cerr << "Factory: module_type = " << modtype << endl;
59  typename MakerMap::iterator it = makers_.find(modtype);
60 
61  if(it == makers_.end())
62  {
63  boost::shared_ptr<Maker> wm(edmplugin::PluginFactory<ComponentMakerBase<T>* ()>::get()->create(modtype));
64 
65  if(wm.get() == 0) {
67  "UnknownModule",
68  T::name().c_str(),
69  " of type ",
70  modtype.c_str(),
71  " has not been registered.\n"
72  "Perhaps your module type is misspelled or is not a "
73  "framework plugin.\n"
74  "Try running EdmPluginDump to obtain a list of "
75  "available Plugins.");
76  }
77 
78  //cerr << "Factory: created the worker" << endl;
79 
80  std::pair<typename MakerMap::iterator,bool> ret =
81  makers_.insert(std::pair<std::string,boost::shared_ptr<Maker> >(modtype,wm));
82 
83  if(ret.second == false) {
84  Exception::throwThis(errors::Configuration,"Maker Factory map insert failed");
85  }
86 
87  it = ret.first;
88  }
89 
90  try {
91  return it->second->addTo(iProvider,iConfiguration,iProcessName,iVersion,iPass);
92  } catch(cms::Exception& iException) {
93  Exception toThrow(errors::Configuration,"Error occurred while creating ");
94  toThrow<<modtype<<"\n";
95  toThrow.append(iException);
96  toThrow.raise();
97  }
98  return boost::shared_ptr<base_type>();
99  }
100 
101  // ---------- static member functions --------------------
102  static ComponentFactory<T>* get();
103 
104  // ---------- member functions ---------------------------
105 
106  private:
107 
108  ComponentFactory(const ComponentFactory&); // stop default
109 
110  const ComponentFactory& operator=(const ComponentFactory&); // stop default
111 
112  // ---------- member data --------------------------------
113  mutable MakerMap makers_;
114 };
115 
116  }
117 }
118 #define COMPONENTFACTORY_GET(_type_) \
119 EDM_REGISTER_PLUGINFACTORY(edmplugin::PluginFactory<edm::eventsetup::ComponentMakerBase<_type_>* ()>,_type_::name()); \
120 static edm::eventsetup::ComponentFactory<_type_> s_dummyfactory; \
121 namespace edm { namespace eventsetup { \
122 template<> edm::eventsetup::ComponentFactory<_type_>* edm::eventsetup::ComponentFactory<_type_>::get() \
123 { return &s_dummyfactory; } \
124  } } \
125 typedef int componentfactory_get_needs_semicolon
126 
127 #endif
ComponentMakerBase< T > Maker
void append(Exception const &another)
Definition: Exception.cc:82
std::map< std::string, boost::shared_ptr< Maker > > MakerMap
void raise()
Definition: Exception.h:128
const ComponentFactory & operator=(const ComponentFactory &)
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:81
boost::shared_ptr< base_type > addTo(EventSetupProvider &iProvider, edm::ParameterSet const &iConfiguration, std::string const &iProcessName, ReleaseVersion const &iVersion, PassID const &iPass) const
std::string ReleaseVersion
Definition: ReleaseVersion.h:7
SurfaceDeformation * create(int type, const std::vector< double > &params)
std::string PassID
Definition: PassID.h:8