Commit de136480 authored by Jin Zhang's avatar Jin Zhang
Browse files

following suggetion to as to make a Detector::Factory wrapper rather than string comparison

parent 944a5b70
......@@ -77,6 +77,17 @@ Detector::Detector(const Configuration& config) : m_role(DetectorRole::NONE) {
}
}
std::shared_ptr<Detector> corryvreckan::Detector::Factory(const Configuration& config) {
// default coordinate is cartesian coordinate
std::string coordinates = config.get<std::string>("coordinates", "cartesian");
std::transform(coordinates.begin(), coordinates.end(), coordinates.begin(), ::tolower);
if(coordinates == "cartesian") {
return std::make_shared<PlanarDetector>(config);
} else {
throw InvalidValueError(config, "coordinates", "Coordiantes can only set to be cartesian now");
}
}
double Detector::getTimeResolution() const {
if(m_timeResolution > 0) {
return m_timeResolution;
......
......@@ -80,6 +80,13 @@ namespace corryvreckan {
*/
Detector(const Configuration& config);
/**
* @brief Factory to dynamically create detectors
* @param The name of the coordinates which should be used
* @return By param coordinates assigned detector to be used
*/
static std::shared_ptr<Detector> Factory(const Configuration& config);
/**
* @brief Get type of the detector
* @return Type of the detector model
......@@ -344,4 +351,5 @@ namespace corryvreckan {
};
} // namespace corryvreckan
#include "PlanarDetector.hpp"
#endif // CORRYVRECKAN_DETECTOR_H
......@@ -51,8 +51,8 @@ void ModuleManager::load_detectors() {
for(auto& detector_section : conf_manager_->getDetectorConfigurations()) {
std::string name = detector_section.getName();
std::string coordinate = detector_section.get<std::string>("coordinates", "cartesian");
std::transform(coordinate.begin(), coordinate.end(), coordinate.begin(), ::tolower);
// std::string coordinate = detector_section.get<std::string>("coordinates", "cartesian");
// std::transform(coordinate.begin(), coordinate.end(), coordinate.begin(), ::tolower);
// Check if we have a duplicate:
if(std::find_if(m_detectors.begin(), m_detectors.end(), [&name](std::shared_ptr<Detector> obj) {
......@@ -63,11 +63,9 @@ void ModuleManager::load_detectors() {
}
LOG_PROGRESS(STATUS, "DET_LOAD_LOOP") << "Loading detector " << name;
// the default coordinates is cartesian, any other type is forbidden now
// @to do: other detector types, e.g., ATLAS endcap strip detector
// default coordinate is cartesian coordinate
std::shared_ptr<Detector> detector;
if(coordinate == "cartesian")
detector = std::make_shared<PlanarDetector>(detector_section);
auto detector = Detector::Factory(detector_section);
// Check if we already found a reference plane:
if(m_reference != nullptr && detector->isReference()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment