Loading src/core/geometry/GeometryManager.cpp +27 −35 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ * SPDX-License-Identifier: MIT */ #include <filesystem> #include <fstream> #include <memory> #include <string> Loading Loading @@ -381,48 +380,41 @@ void GeometryManager::load_models() { continue; } // Add the sub directory path to the reader LOG(TRACE) << "Reading model file " << sub_path; std::ifstream file(sub_path); // Check for ConfigParseError, might be an unrelated .conf file // For example, see https://gitlab.cern.ch/allpix-squared/allpix-squared/-/issues/277 try { ConfigReader reader(file, sub_path); readers.emplace_back(sub_path.stem(), reader); } catch(const ConfigParseError& e) { LOG(DEBUG) << "Skipping invalid model file " << sub_path << ":" << std::endl << e.what(); } // Read model file and add model to list read_model_file(std::move(sub_path)); } } else { // Always a file because paths are already checked LOG(TRACE) << "Reading model file " << path; std::ifstream file(path); // Do not check for ConfigParseError as above because explicit file was given ConfigReader reader(file, path); readers.emplace_back(std::filesystem::path(path).stem(), reader); read_model_file(std::filesystem::path(path)); } } } // Loop through all configurations and parse them LOG(TRACE) << "Parsing models"; for(auto& [name, reader] : readers) { if(hasModel(name)) { // Skip models that we already loaded earlier higher in the chain LOG(DEBUG) << "Skipping overwritten model " + name << " in path " << reader.getHeaderConfiguration().getFilePath(); continue; void GeometryManager::read_model_file(std::filesystem::path path) { auto model_name = path.stem(); LOG(TRACE) << "Reading model " << model_name << " in path " << path; // Check if we need to look at file at all if(hasModel(model_name)) { LOG(DEBUG) << "Skipping overwritten model " << model_name << " in path " << path; return; } if(!needsModel(name)) { // Also skip models that are not needed LOG(TRACE) << "Skipping not required model " + name << " in path " << reader.getHeaderConfiguration().getFilePath(); continue; if(!needsModel(model_name)) { LOG(TRACE) << "Skipping not required model " << model_name << " in path " << path; return; } try { // Try to parse as config file std::ifstream file(path); ConfigReader reader(file, path); // Parse configuration and add model to the config addModel(DetectorModel::factory(name, reader)); addModel(DetectorModel::factory(model_name, reader)); } catch(const ConfigParseError& e) { // Not a valid config file, see https://gitlab.cern.ch/allpix-squared/allpix-squared/-/issues/277 LOG(ERROR) << "Skipping invalid model file " << path << ":" << std::endl << e.what(); } } Loading src/core/geometry/GeometryManager.hpp +7 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ #ifndef ALLPIX_GEOMETRY_MANAGER_H #define ALLPIX_GEOMETRY_MANAGER_H #include <filesystem> #include <memory> #include <regex> #include <set> Loading Loading @@ -265,6 +266,12 @@ namespace allpix { */ void load_models(); /** * @brief Read a model file, check if the model is required and call \ref GeometryManager::addModel in that case * @param path Path to the model file */ void read_model_file(std::filesystem::path path); /** * @brief Get the orientation of an object * @param config Configuration that defines in the object Loading Loading
src/core/geometry/GeometryManager.cpp +27 −35 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ * SPDX-License-Identifier: MIT */ #include <filesystem> #include <fstream> #include <memory> #include <string> Loading Loading @@ -381,48 +380,41 @@ void GeometryManager::load_models() { continue; } // Add the sub directory path to the reader LOG(TRACE) << "Reading model file " << sub_path; std::ifstream file(sub_path); // Check for ConfigParseError, might be an unrelated .conf file // For example, see https://gitlab.cern.ch/allpix-squared/allpix-squared/-/issues/277 try { ConfigReader reader(file, sub_path); readers.emplace_back(sub_path.stem(), reader); } catch(const ConfigParseError& e) { LOG(DEBUG) << "Skipping invalid model file " << sub_path << ":" << std::endl << e.what(); } // Read model file and add model to list read_model_file(std::move(sub_path)); } } else { // Always a file because paths are already checked LOG(TRACE) << "Reading model file " << path; std::ifstream file(path); // Do not check for ConfigParseError as above because explicit file was given ConfigReader reader(file, path); readers.emplace_back(std::filesystem::path(path).stem(), reader); read_model_file(std::filesystem::path(path)); } } } // Loop through all configurations and parse them LOG(TRACE) << "Parsing models"; for(auto& [name, reader] : readers) { if(hasModel(name)) { // Skip models that we already loaded earlier higher in the chain LOG(DEBUG) << "Skipping overwritten model " + name << " in path " << reader.getHeaderConfiguration().getFilePath(); continue; void GeometryManager::read_model_file(std::filesystem::path path) { auto model_name = path.stem(); LOG(TRACE) << "Reading model " << model_name << " in path " << path; // Check if we need to look at file at all if(hasModel(model_name)) { LOG(DEBUG) << "Skipping overwritten model " << model_name << " in path " << path; return; } if(!needsModel(name)) { // Also skip models that are not needed LOG(TRACE) << "Skipping not required model " + name << " in path " << reader.getHeaderConfiguration().getFilePath(); continue; if(!needsModel(model_name)) { LOG(TRACE) << "Skipping not required model " << model_name << " in path " << path; return; } try { // Try to parse as config file std::ifstream file(path); ConfigReader reader(file, path); // Parse configuration and add model to the config addModel(DetectorModel::factory(name, reader)); addModel(DetectorModel::factory(model_name, reader)); } catch(const ConfigParseError& e) { // Not a valid config file, see https://gitlab.cern.ch/allpix-squared/allpix-squared/-/issues/277 LOG(ERROR) << "Skipping invalid model file " << path << ":" << std::endl << e.what(); } } Loading
src/core/geometry/GeometryManager.hpp +7 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ #ifndef ALLPIX_GEOMETRY_MANAGER_H #define ALLPIX_GEOMETRY_MANAGER_H #include <filesystem> #include <memory> #include <regex> #include <set> Loading Loading @@ -265,6 +266,12 @@ namespace allpix { */ void load_models(); /** * @brief Read a model file, check if the model is required and call \ref GeometryManager::addModel in that case * @param path Path to the model file */ void read_model_file(std::filesystem::path path); /** * @brief Get the orientation of an object * @param config Configuration that defines in the object Loading