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 void set_working_dir(std::string_view dir) { working_dir_ = dir; }
52
53 void add_parameter_default(int par_num, const std::pair<float, float>& values);
54 void add_method(Method method, const std::pair<float, float>& values);
55 void add_other_options(std::vector<std::string> options);
56
57 void write();
58
59 static constexpr auto convert_method_to_str(Method) -> std::string_view;
60
61 private:
62 std::map<Method, std::pair<float, float>> methods_;
66 std::unordered_map<int, std::pair<float, float>> parameter_defaults_;
67 std::vector<std::vector<std::string>> other_options_;
68 std::string working_dir_ = ".";
69
71 void write_data_file(std::ofstream& ofile);
72 void write_methods(std::ofstream& ofile);
73 void write_others(std::ofstream& ofile);
74 };
75
76} // namespace R3B
77
78template <>
79class fmt::formatter<R3B::SteerWriter::Method>
80{
81 public:
82 static constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
83 template <typename FmtContent>
84 constexpr auto format(const R3B::SteerWriter::Method& method, FmtContent& ctn) const
85 {
86 return fmt::format_to(ctn.out(), "{}", R3B::SteerWriter::convert_method_to_str(method));
87 }
88};
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:65
void set_data_filepath(std::string_view filepath)
Definition SteerWriter.h:49
void set_working_dir(std::string_view dir)
Definition SteerWriter.h:51
std::vector< std::vector< std::string > > other_options_
Definition SteerWriter.h:67
std::string parameter_file_
Definition SteerWriter.h:64
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:62
void set_parameter_file(std::string_view filename)
Definition SteerWriter.h:50
std::string filepath_
Definition SteerWriter.h:63
std::string working_dir_
Definition SteerWriter.h:68
void add_other_options(std::vector< std::string > options)
void add_parameter_default(int par_num, const std::pair< float, float > &values)
static constexpr auto convert_method_to_str(Method) -> std::string_view
SteerWriter()=default
std::unordered_map< int, std::pair< float, float > > parameter_defaults_
Definition SteerWriter.h:66
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:84
static constexpr auto parse(format_parse_context &ctx)
Definition SteerWriter.h:82