R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
SteerWriter.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3 * Copyright (C) 2019-2023 Members of R3B Collaboration *
4 * *
5 * This software is distributed under the terms of the *
6 * GNU General Public Licence (GPL) version 3, *
7 * copied verbatim in the file "LICENSE". *
8 * *
9 * In applying this license GSI does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 ******************************************************************************/
13
14#pragma once
15
16#include <cstdint>
17#include <fmt/core.h>
18#include <fmt/format.h>
19#include <fstream>
20#include <map>
21#include <string>
22#include <string_view>
23#include <unordered_map>
24#include <utility>
25#include <vector>
26
27constexpr auto DEFAULT_MILLEPEDE_PARAMETER_FILE = "parameters.txt";
28constexpr auto DEFAULT_STEER_FILENAME = "steer.txt";
29constexpr auto DEFAULT_DATA_FILENAME = "data.bin";
30
31namespace R3B
32{
34 {
35 public:
46
47 SteerWriter() = default;
48 void set_filepath(std::string_view filepath) { filepath_ = filepath; }
49 void set_data_filepath(std::string_view filepath) { data_filepath_ = filepath; }
50 void set_parameter_file(std::string_view filename) { parameter_file_ = filename; }
51
52 void add_parameter_default(int par_num, const std::pair<float, float>& values);
53 void add_method(Method method, const std::pair<float, float>& values);
54 void add_other_options(std::vector<std::string> options);
55
56 void write();
57
58 private:
59 std::map<Method, std::pair<float, float>> methods_;
63 std::unordered_map<int, std::pair<float, float>> parameter_defaults_;
64 std::vector<std::vector<std::string>> other_options_;
65
67 void write_data_file(std::ofstream& ofile);
68 void write_methods(std::ofstream& ofile);
69 void write_others(std::ofstream& ofile);
70 };
71
72} // namespace R3B
73
74template <>
75class fmt::formatter<R3B::SteerWriter::Method>
76{
77 public:
78 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
79 template <typename FmtContent>
80 constexpr auto format(const R3B::SteerWriter::Method& method, FmtContent& ctn) const
81 {
82 switch (method)
83 {
85 return format_to(ctn.out(), "{}", "inversion");
86 break;
88 return format_to(ctn.out(), "{}", "diagonalization");
89 break;
91 return format_to(ctn.out(), "{}", "fullGMRES");
92 break;
94 return format_to(ctn.out(), "{}", "sparseGMRES");
95 break;
97 return format_to(ctn.out(), "{}", "cholesky");
98 break;
100 return format_to(ctn.out(), "{}", "bandcholesky");
101 break;
103 return format_to(ctn.out(), "{}", "HIP");
104 break;
105 default:
106 return format_to(ctn.out(), "{}", "unrecognized");
107 break;
108 }
109 }
110};
constexpr auto DEFAULT_STEER_FILENAME
Definition SteerWriter.h:28
constexpr auto DEFAULT_MILLEPEDE_PARAMETER_FILE
Definition SteerWriter.h:27
constexpr auto DEFAULT_DATA_FILENAME
Definition SteerWriter.h:29
std::string data_filepath_
Definition SteerWriter.h:62
void set_data_filepath(std::string_view filepath)
Definition SteerWriter.h:49
std::vector< std::vector< std::string > > other_options_
Definition SteerWriter.h:64
std::string parameter_file_
Definition SteerWriter.h:61
void write_data_file(std::ofstream &ofile)
void add_method(Method method, const std::pair< float, float > &values)
void write_parameter_defaults()
std::map< Method, std::pair< float, float > > methods_
Definition SteerWriter.h:59
void set_parameter_file(std::string_view filename)
Definition SteerWriter.h:50
std::string filepath_
Definition SteerWriter.h:60
void add_other_options(std::vector< std::string > options)
void add_parameter_default(int par_num, const std::pair< float, float > &values)
SteerWriter()=default
std::unordered_map< int, std::pair< float, float > > parameter_defaults_
Definition SteerWriter.h:63
void write_methods(std::ofstream &ofile)
void set_filepath(std::string_view filepath)
Definition SteerWriter.h:48
void write_others(std::ofstream &ofile)
constexpr auto format(const R3B::SteerWriter::Method &method, FmtContent &ctn) const
Definition SteerWriter.h:80
static constexpr auto parse(format_parse_context &ctx)
Definition SteerWriter.h:78