CMS 3D CMS Logo

ComponentFactoryByName.h
Go to the documentation of this file.
1 #ifndef SimG4Core_ComponentFactoryByName_H
2 #define SimG4Core_ComponentFactoryByName_H
3 
5 
6 #include <string>
7 #include <map>
8 
9 template <class B>
11 {
12 public:
13  static B * getBuilder(const std::string & name)
14  {
15  if (myMap().size() == 0) {
16  throw cms::Exception("SimG4CoreNotification", " ComponentFactoryByName::getBuilder: No Builder registered to the Factory.");
17  }
18  if (myMap().find(name) == myMap().end()) {
19  throw cms::Exception("SimG4CoreNotification", " ComponentFactoryByName::getBuilder: The Component "+name+" is not registered to the Factory.");
20  }
21  return (myMap()[name]);
22  }
23  static void setBuilder(B * in , const std::string & name)
24  {
25  if (name.empty()) {
26  throw cms::Exception("SimG4CoreNotification", " ComponentFactoryByName::setBuilder: The registration of Components without name is not allowed.");
27  }
28  myMap()[name] = in;
29  }
30  typedef std::map<std::string,B *> BuilderMapType;
31 protected:
32  static BuilderMapType & myMap()
33  {
34  static BuilderMapType me_;
35  return me_;
36  }
37 };
38 
39 #endif
40 
41 
42 
size
Write out results.
static B * getBuilder(const std::string &name)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
static BuilderMapType & myMap()
#define end
Definition: vmac.h:39
static const std::string B
std::map< std::string, B * > BuilderMapType
static void setBuilder(B *in, const std::string &name)