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 <fmt/format.h>
17#include <map>
18#include <string>
19#include <unordered_map>
20#include <vector>
21
22constexpr auto DEFAULT_MILLEPEDE_PARAMETER_FILE = "parameters.txt";
23constexpr auto DEFAULT_STEER_FILENAME = "steer.txt";
24constexpr auto DEFAULT_DATA_FILENAME = "data.bin";
25
26namespace R3B
27{
29 {
30 public:
41
42 SteerWriter() = default;
43 void set_filepath(std::string_view filepath) { filepath_ = filepath; }
44 void set_data_filepath(std::string_view filepath) { data_filepath_ = filepath; }
45 void set_parameter_file(std::string_view filename) { parameter_file_ = filename; }
46
47 void add_parameter_default(int par_num, const std::pair<float, float>& values);
48 void add_method(Method method, const std::pair<float, float>& values);
49 void add_other_options(std::vector<std::string> options);
50
51 void write();
52
53 private:
54 std::map<Method, std::pair<float, float>> methods_;
55 std::string filepath_ = DEFAULT_STEER_FILENAME;
56 std::string parameter_file_ = DEFAULT_MILLEPEDE_PARAMETER_FILE;
57 std::string data_filepath_ = DEFAULT_DATA_FILENAME;
58 std::unordered_map<int, std::pair<float, float>> parameter_defaults_;
59 std::vector<std::vector<std::string>> other_options_;
60
61 void write_parameter_defaults();
62 void write_data_file(std::ofstream& ofile);
63 void write_methods(std::ofstream& ofile);
64 void write_others(std::ofstream& ofile);
65 };
66
67} // namespace R3B
68
69template <>
70class fmt::formatter<R3B::SteerWriter::Method>
71{
72 public:
73 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
74 template <typename FmtContent>
75 constexpr auto format(const R3B::SteerWriter::Method& method, FmtContent& ctn) const
76 {
77 switch (method)
78 {
80 return format_to(ctn.out(), "{}", "inversion");
81 break;
83 return format_to(ctn.out(), "{}", "diagonalization");
84 break;
86 return format_to(ctn.out(), "{}", "fullGMRES");
87 break;
89 return format_to(ctn.out(), "{}", "sparseGMRES");
90 break;
92 return format_to(ctn.out(), "{}", "cholesky");
93 break;
95 return format_to(ctn.out(), "{}", "bandcholesky");
96 break;
98 return format_to(ctn.out(), "{}", "HIP");
99 break;
100 default:
101 return format_to(ctn.out(), "{}", "unrecognized");
102 break;
103 }
104 }
105};
constexpr auto DEFAULT_STEER_FILENAME
Definition SteerWriter.h:23
constexpr auto DEFAULT_MILLEPEDE_PARAMETER_FILE
Definition SteerWriter.h:22
constexpr auto DEFAULT_DATA_FILENAME
Definition SteerWriter.h:24
void set_data_filepath(std::string_view filepath)
Definition SteerWriter.h:44
void add_method(Method method, const std::pair< float, float > &values)
void set_parameter_file(std::string_view filename)
Definition SteerWriter.h:45
void add_other_options(std::vector< std::string > options)
void add_parameter_default(int par_num, const std::pair< float, float > &values)
SteerWriter()=default
void set_filepath(std::string_view filepath)
Definition SteerWriter.h:43
constexpr auto format(const R3B::SteerWriter::Method &method, FmtContent &ctn) const
Definition SteerWriter.h:75
static constexpr auto parse(format_parse_context &ctx)
Definition SteerWriter.h:73