DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SegmentationFactory.cpp
Go to the documentation of this file.
1 /*
2  * SegmentationFactory.cpp
3  *
4  * Created on: Dec 15, 2013
5  * Author: Christian Grefe, CERN
6  */
7 
9 
10 namespace DD4hep {
11 namespace DDSegmentation {
12 
13 using std::map;
14 using std::vector;
15 
19 }
20 
23 
26  if (not _instance) {
27  _instance = new SegmentationFactory();
28  }
29  return _instance;
30 }
31 
33 Segmentation* SegmentationFactory::create(const std::string& name, const std::string& identifier) const {
34  map<std::string, SegmentationCreatorBase*>::const_iterator it;
35  it = _segmentations.find(name);
36  if (it != _segmentations.end()) {
37  return it->second->create(identifier);
38  }
39  return 0;
40 }
41 
43 vector<std::string> SegmentationFactory::registeredSegmentations() const {
44  vector<std::string> segmentationNames;
45  map<std::string, SegmentationCreatorBase*>::const_iterator it;
46  for (it = _segmentations.begin(); it != _segmentations.end(); ++ it) {
47  segmentationNames.push_back(it->first);
48  }
49  return segmentationNames;
50 }
51 
53 void SegmentationFactory::registerSegmentation(const std::string& name, SegmentationCreatorBase* creator) {
54  _segmentations[name] = creator;
55 }
56 
57 } /* namespace DDSegmentation */
58 } /* namespace DD4hep */
static SegmentationFactory * _instance
The global factory instance.
Segmentation * create(const std::string &name, const std::string &identifier="") const
Create a new segmentation object with the given type name. Returns NULL if type name is unknown...
Base class for the SegmentationCreator objects. Allows to use the factory without template...
SegmentationCreatorBase(const std::string &name)
Default constructor. Takes the class name as argument and takes care of registration with the factory...
Factory for creating segmentation objects by type name.
void registerSegmentation(const std::string &name, SegmentationCreatorBase *creator)
Registers a new SegmentationCreator with the factory.
Base class for all segmentations.
Definition: Segmentation.h:68
std::map< std::string, SegmentationCreatorBase * > _segmentations
Map to store SegmentationCreators by name.
std::vector< std::string > registeredSegmentations() const
Access to the list of registered segmentations.
static SegmentationFactory * instance()
Access to the global factory instance.