Commit 41b1d3d6 authored by Stephan Lachnit's avatar Stephan Lachnit
Browse files

Merge branch 'p-location-enum' into 'master'

SupportLayer: Make Location an enum class

See merge request allpix-squared/allpix-squared!1059
parents ee1af7c2 22109937
Loading
Loading
Loading
Loading
+5 −9
Original line number Diff line number Diff line
@@ -106,14 +106,10 @@ DetectorModel::DetectorModel(std::string type, std::shared_ptr<DetectorAssembly>
    for(auto& support_config : reader_.getConfigurations("support")) {
        auto thickness = support_config.get<double>("thickness");
        auto size = support_config.get<XYVector>("size");
        auto location = support_config.get<std::string>("location", "chip");
        std::transform(location.begin(), location.end(), location.begin(), ::tolower);
        if(location != "sensor" && location != "chip" && location != "absolute") {
            throw InvalidValueError(
                support_config, "location", "location of the support should be 'chip', 'sensor' or 'absolute'");
        }
        auto location = support_config.get<SupportLayer::Location>("location", SupportLayer::Location::CHIP);

        XYZVector offset;
        if(location == "absolute") {
        if(location == SupportLayer::Location::ABSOLUTE) {
            offset = support_config.get<XYZVector>("offset");
        } else {
            auto xy_offset = support_config.get<XYVector>("offset", {0, 0});
@@ -278,10 +274,10 @@ std::vector<SupportLayer> DetectorModel::getSupportLayers() const {
    auto chip_offset = getSensorSize().z() / 2.0 + getChipSize().z() + assembly_->getChipOffset().z();
    for(auto& layer : ret_layers) {
        ROOT::Math::XYZVector offset = layer.offset_;
        if(layer.location_ == "sensor") {
        if(layer.location_ == SupportLayer::Location::SENSOR) {
            offset.SetZ(sensor_offset - layer.size_.z() / 2.0);
            sensor_offset -= layer.size_.z();
        } else if(layer.location_ == "chip") {
        } else if(layer.location_ == SupportLayer::Location::CHIP) {
            offset.SetZ(chip_offset + layer.size_.z() / 2.0);
            chip_offset += layer.size_.z();
        }
+1 −2
Original line number Diff line number Diff line
@@ -552,13 +552,12 @@ namespace allpix {
         * @param hole_size Size of the optional hole in the support
         * @param hole_offset Offset of the hole from its default position
         */
        // FIXME: Location (and material) should probably be an enum instead
        void addSupportLayer(const ROOT::Math::XYVector& size,
                             double thickness,
                             ROOT::Math::XYZVector offset,
                             std::string material,
                             std::string type,
                             std::string location,
                             const SupportLayer::Location location,
                             const ROOT::Math::XYVector& hole_size,
                             ROOT::Math::XYVector hole_offset) {
            ROOT::Math::XYZVector full_size(size.x(), size.y(), thickness);
+9 −3
Original line number Diff line number Diff line
@@ -25,6 +25,12 @@ namespace allpix {
        friend class DetectorModel;

    public:
        enum class Location {
            SENSOR,  ///< Support layer is located on the sensor side of the assembly
            CHIP,    ///< Support layer is located on the chip side of the assembly
            ABSOLUTE ///< Support layer location provided as absolute position
        };

        /**
         * @brief Get the center of the support layer
         * @return Center of the support layer
@@ -67,7 +73,7 @@ namespace allpix {
        /**
         * @brief Get the location of the support layer
         */
        const std::string& getLocation() const { return location_; }
        const Location& getLocation() const { return location_; }

    private:
        /**
@@ -84,7 +90,7 @@ namespace allpix {
                     ROOT::Math::XYZVector offset,
                     std::string material,
                     std::string type,
                     std::string location,
                     const Location location,
                     ROOT::Math::XYZVector hole_size,
                     ROOT::Math::XYVector hole_offset)
            : size_(std::move(size)), material_(std::move(material)), type_(std::move(type)),
@@ -101,7 +107,7 @@ namespace allpix {
        // Internal parameters to calculate return parameters
        ROOT::Math::XYZVector offset_;
        ROOT::Math::XYVector hole_offset_;
        std::string location_;
        Location location_;
    };
} // namespace allpix