Commit 7bbb0752 authored by Håkan Wennlöf's avatar Håkan Wennlöf
Browse files

Updated passive material construction to give warnings when there are unused configuration keys

parent c37c01ea
Loading
Loading
Loading
Loading
+21 −22
Original line number Diff line number Diff line
@@ -60,9 +60,30 @@ void GeometryManager::load(ConfigManager* conf_manager, RandomNumberGenerator& s
                throw PassiveElementExistsError(geometry_section.getName());
            }

            // Calculate the orientations of passive elements
            passive_orientations_[geometry_section.getName()] = calculate_orientation(geometry_section);

            // Check for mandatory but hitherto unused keys:
            auto check_key = [&](const Configuration& cfg, const std::string& key) {
                if(!cfg.has(key)) {
                    throw MissingKeyError(key, cfg.getName());
                }
            };

            // Check type keyword
            check_key(geometry_section, "type");

            // Check material unless it's a GDML file placement
            auto type = geometry_section.get<std::string>("type");
            std::transform(type.begin(), type.end(), type.begin(), ::tolower);
            if(type != "gdml") {
                check_key(geometry_section, "material");
            }

            passive_elements_.push_back(geometry_section);
            LOG(DEBUG) << "Passive element " << geometry_section.getName() << ", putting aside";
            continue;

        } else if(role != "active") {
            throw InvalidValueError(geometry_section, "role", "unknown role");
        }
@@ -81,28 +102,6 @@ void GeometryManager::load(ConfigManager* conf_manager, RandomNumberGenerator& s
        nonresolved_models_[geometry_section.get<std::string>("type")].emplace_back(geometry_section, detector.get());
    }

    // Calculate the orientations of passive elements
    for(auto& passive_element : passive_elements_) {
        passive_orientations_[passive_element.getName()] = calculate_orientation(passive_element);

        // Check for mandatory but hitherto unused keys:
        auto check_key = [&](const Configuration& cfg, const std::string& key) {
            if(!cfg.has(key)) {
                throw MissingKeyError(key, cfg.getName());
            }
        };

        // Check type keyword
        check_key(passive_element, "type");

        // Check material unless it's a GDML file placement
        auto type = passive_element.get<std::string>("type");
        std::transform(type.begin(), type.end(), type.begin(), ::tolower);
        if(type != "gdml") {
            check_key(passive_element, "material");
        }
    }

    // Load the list of standard model paths
    Configuration& global_config = conf_manager->getGlobalConfiguration();
    if(global_config.has("model_paths")) {
+1 −2
Original line number Diff line number Diff line
@@ -22,8 +22,7 @@ void PassiveMaterialConstructionG4::registerVolumes() {
    LOG(TRACE) << "Registering " << passive_configs.size() << " passive material volume(s)";

    for(auto& passive_config : passive_configs) {
        std::shared_ptr<PassiveMaterialModel> model =
            PassiveMaterialModel::factory(passive_config.get<std::string>("type"), passive_config, geo_manager_);
        std::shared_ptr<PassiveMaterialModel> model = PassiveMaterialModel::factory(passive_config, geo_manager_);
        passive_volumes_.emplace_back(model);
    }

+15 −4
Original line number Diff line number Diff line
@@ -34,8 +34,9 @@
using namespace allpix;
using namespace ROOT::Math;

std::shared_ptr<PassiveMaterialModel>
allpix::PassiveMaterialModel::factory(const std::string& type, const Configuration& config, GeometryManager* geo_manager) {
std::shared_ptr<PassiveMaterialModel> allpix::PassiveMaterialModel::factory(Configuration& config,
                                                                            GeometryManager* geo_manager) {
    auto type = config.get<std::string>("type");
    if(type == "box") {
        return std::make_shared<BoxModel>(config, geo_manager);
    } else if(type == "cylinder") {
@@ -56,9 +57,8 @@ allpix::PassiveMaterialModel::factory(const std::string& type, const Configurati
    }
}

PassiveMaterialModel::PassiveMaterialModel(Configuration config, GeometryManager* geo_manager)
PassiveMaterialModel::PassiveMaterialModel(Configuration& config, GeometryManager* geo_manager)
    : config_(std::move(config)), geo_manager_(geo_manager) {

    name_ = config_.getName();
    mother_volume_ = config_.get<std::string>("mother_volume", "");

@@ -122,6 +122,17 @@ void PassiveMaterialModel::buildVolume(const std::shared_ptr<G4LogicalVolume>& w
    auto phys_volume = make_shared_no_delete<G4PVPlacement>(
        transform_phys, log_volume.get(), getName() + "_phys", mother_log_volume, false, 0, true);
    geo_manager_->setExternalObject(getName(), "passive_material_phys", phys_volume);

    auto unused_keys = config_.getUnusedKeys();
    if(!unused_keys.empty()) {
        std::stringstream st;
        st << "Unused configuration keys in passive material definition:";
        for(auto& key : unused_keys) {
            st << std::endl << key;
        }
        LOG(WARNING) << st.str();
    }

    LOG(TRACE) << " Constructed passive material " << getName() << " successfully";
}

+2 −3
Original line number Diff line number Diff line
@@ -45,15 +45,14 @@ namespace allpix {
         * @param geo_manager Pointer to the global geometry manager
         * @return By param trackModel assigned track model to be used
         */
        static std::shared_ptr<PassiveMaterialModel>
        factory(const std::string& type, const Configuration& config, GeometryManager* geo_manager);
        static std::shared_ptr<PassiveMaterialModel> factory(Configuration& config, GeometryManager* geo_manager);

        /**
         * @brief Constructs the base passive material model
         * @param config Configuration with description of the model
         * @param geo_manager Pointer to the global geometry manager
         */
        PassiveMaterialModel(Configuration config, GeometryManager* geo_manager);
        PassiveMaterialModel(Configuration& config, GeometryManager* geo_manager);

        /**
         * @brief Essential virtual destructor
+1 −2
Original line number Diff line number Diff line
@@ -34,8 +34,7 @@ namespace allpix {
         * @param config Configuration with description of the model
         * @param geo_manager Pointer to the global geometry manager
         */
        explicit BoxModel(const Configuration& config, GeometryManager* geo_manager)
            : PassiveMaterialModel(config, geo_manager) {
        explicit BoxModel(Configuration& config, GeometryManager* geo_manager) : PassiveMaterialModel(config, geo_manager) {

            // Set the box specifications
            setOuterSize(config_.get<ROOT::Math::XYZVector>("size"));
Loading