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

Merge branch 'backport_meshconv' into 'v2.1-stable'

[v2.1-stable] MeshConverter: Allow Parsing LogLevel from Config

See merge request allpix-squared/allpix-squared!614
parents 0946a945 69008557
Loading
Loading
Loading
Loading
+22 −9
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ int main(int argc, char** argv) {
        std::string log_file_name;

        std::string conf_file_name;
        allpix::LogLevel log_level = allpix::LogLevel::INFO;
        allpix::LogLevel log_level = allpix::LogLevel::NONE;

        for(int i = 1; i < argc; i++) {
            if(strcmp(argv[i], "-h") == 0) {
@@ -109,9 +109,6 @@ int main(int argc, char** argv) {
            }
        }

        // Set log level:
        allpix::Log::setReportingLevel(log_level);

        if(file_prefix.empty()) {
            print_help = true;
            return_code = 1;
@@ -143,6 +140,25 @@ int main(int argc, char** argv) {
            return return_code;
        }

        std::ifstream file(conf_file_name);
        allpix::ConfigReader reader(file, conf_file_name);
        allpix::Configuration config = reader.getHeaderConfiguration();

        if(log_level == allpix::LogLevel::NONE) {
            auto log_level_string = config.get<std::string>("log_level", "INFO");
            std::transform(log_level_string.begin(), log_level_string.end(), log_level_string.begin(), ::toupper);
            try {
                log_level = allpix::Log::getLevelFromString(log_level_string);
            } catch(std::invalid_argument& e) {
                LOG(ERROR) << "Log level \"" << log_level_string
                           << "\" specified in the configuration is invalid, defaulting to INFO instead";
                log_level = allpix::LogLevel::INFO;
            }
        }

        // Set log level:
        allpix::Log::setReportingLevel(log_level);

        // NOTE: this stream should be available for the duration of the logging
        std::ofstream log_file;
        if(!log_file_name.empty()) {
@@ -157,9 +173,6 @@ int main(int argc, char** argv) {

        LOG(STATUS) << "Welcome to the Mesh Converter Tool of Allpix^2 " << ALLPIX_PROJECT_VERSION;
        LOG(STATUS) << "Using " << conf_file_name << " configuration file";
        std::ifstream file(conf_file_name);
        allpix::ConfigReader reader(file, conf_file_name);
        allpix::Configuration config = reader.getHeaderConfiguration();

        // Output file format:
        auto format = config.get<std::string>("model", "apf");
@@ -404,8 +417,8 @@ int main(int argc, char** argv) {
            }

            mesh_points_done += divisions.z();
            LOG_PROGRESS(INFO, "m") << "Interpolating new mesh: " << mesh_points_done << " of " << mesh_points_total << ", "
                                    << (mesh_points_done / (mesh_points_total / 100)) << "%";
            LOG_PROGRESS(STATUS, "m") << "Interpolating new mesh: " << mesh_points_done << " of " << mesh_points_total
                                      << ", " << (mesh_points_done / (mesh_points_total / 100)) << "%";

            return new_mesh;
        };
+1 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ It should be noted that the Mesh Converter depends on the core utilities of the
* `xyz`: Array to replace the system coordinates of the mesh. A detailed description of how to use this parameter is given below.
* `workers`: Number of worker threads to be used for the interpolation. Defaults to the available number of cores on the machine (hardware concurrency).
* `vector_field`: Select if the observable is a vector field or scalar field (Defaults to `true` matching the default observable `ElectricField`).
* `log_level`: Specifies the lowest log level which should be reported. Possible values are the same as for the Allpix Squared framework.

### Usage
To run the program, the following command should be executed from the installation folder:
+4 −4
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ MeshMap DFISEParser::read_meshes(const std::string& file_name) {

        // Log the parsing progress:
        if(num_lines > 0 && num_lines_parsed % 1000 == 0) {
            LOG_PROGRESS(INFO, "gridlines") << "Parsing grid file: " << (100 * num_lines_parsed / num_lines) << "%";
            LOG_PROGRESS(STATUS, "gridlines") << "Parsing grid file: " << (100 * num_lines_parsed / num_lines) << "%";
        }
        num_lines_parsed++;

@@ -352,7 +352,7 @@ MeshMap DFISEParser::read_meshes(const std::string& file_name) {
            break;
        }
    }
    LOG_PROGRESS(INFO, "gridlines") << "Parsing grid file: done.";
    LOG_PROGRESS(STATUS, "gridlines") << "Parsing grid file: done.";

    std::map<std::string, std::vector<Point>> ret_map;
    for(auto& name_region_vertices : regions_vertices) {
@@ -406,7 +406,7 @@ FieldMap DFISEParser::read_fields(const std::string& file_name) {

        // Log the parsing progress:
        if(num_lines > 0 && num_lines_parsed % 1000 == 0) {
            LOG_PROGRESS(INFO, "fieldlines") << "Parsing field data file: " << (100 * num_lines_parsed / num_lines) << "%";
            LOG_PROGRESS(STATUS, "fieldlines") << "Parsing field data file: " << (100 * num_lines_parsed / num_lines) << "%";
        }
        num_lines_parsed++;

@@ -678,7 +678,7 @@ FieldMap DFISEParser::read_fields(const std::string& file_name) {
            }
        }
    }
    LOG_PROGRESS(INFO, "fieldlines") << "Parsing field data file: done.";
    LOG_PROGRESS(STATUS, "fieldlines") << "Parsing field data file: done.";

    return region_electric_field_map;
}