Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
FileNameManager.cpp
Go to the documentation of this file.
1#include "FileNameManager.h"
2
3#include <algorithm>
4#include <cctype>
5#include <filesystem>
6#include <stdexcept>
7#include <utility>
8
9#include "MartyAdapter.h"
10#include "MartyPathProxy.h"
11
12namespace fs = std::filesystem;
13
14void FileNameManager::setTestingRoots(const std::string& templateRoot,
15 const std::string& baseTemplateRoot,
16 const std::string& assetsRoot) {
17 test_template_root = templateRoot;
18 test_base_template_root = baseTemplateRoot;
19 test_assets_root = assetsRoot;
20}
21
23 test_template_root.clear();
24 test_base_template_root.clear();
25 test_assets_root.clear();
26}
27
28std::shared_ptr<FileNameManager> FileNameManager::getInstance(const std::string& wilson, const std::string& model) {
29 if (wilson.empty() || model.empty()) {
30 throw std::runtime_error("FileNameManager must be initialized with Wilson and model parameters.");
31 }
32
33 auto adapter = std::make_shared<MartyAdapter>();
34 auto proxy = std::make_shared<MartyPathProxy>(adapter);
35 return std::shared_ptr<FileNameManager>(new FileNameManager(wilson, model, proxy));
36}
37
38FileNameManager::FileNameManager(const std::string& wilson,
39 const std::string& model,
40 std::shared_ptr<IMartyPathProxy> path_proxy)
41 : path_proxy_(std::move(path_proxy)),
42 wilson_(wilson),
43 model_(model),
44 lowercaseWilson_(toLowercase(wilson)),
45 lowercaseModel_(toLowercase(model)) {
46 if (!path_proxy_) {
47 throw std::invalid_argument("FileNameManager requires a non-null IMartyPathProxy.");
48 }
49
50 const fs::path output_root = !test_template_root.empty()
51 ? fs::path(test_template_root)
52 : path_proxy_->get_path(MartyPath::MARTY_TEMP_DIR);
53
54 const fs::path base_template_root = !test_base_template_root.empty()
55 ? fs::path(test_base_template_root)
56 : path_proxy_->get_path(MartyPath::TEMPLATE_DIR);
57
58 templateDir_ = ensureTrailingSlash(output_root.string());
59 baseTemplateDir_ = ensureTrailingSlash(base_template_root.string());
60
61 if (!test_assets_root.empty()) {
62 const fs::path mapping_dir = fs::path(test_assets_root) / "input_files" / "marty_mapping";
63 smMappingFile_ = (mapping_dir / "sm.json").string();
64 bsmMappingFile_ = (mapping_dir / (lowercaseModel_ + ".json")).string();
65 } else {
66 smMappingFile_ = path_proxy_->get_path(MartyPath::SM_MAPPING_FILE).string();
67
68 const auto bsm_path = path_proxy_->get_optional_path(MartyPath::BSM_MAPPING_FILE);
69 if (bsm_path.has_value()) {
70 bsmMappingFile_ = bsm_path.value().string();
71 }
72 }
73
74 fs::create_directories(templateDir_);
75}
76
77std::string FileNameManager::toLowercase(std::string value) {
78 std::transform(value.begin(), value.end(), value.begin(),
79 [](unsigned char c){ return static_cast<char>(std::tolower(c)); });
80 return value;
81}
82
83std::string FileNameManager::ensureTrailingSlash(const std::string& value) {
84 if (value.empty()) {
85 return value;
86 }
87
88 if (value.back() == '/' || value.back() == '\\') {
89 return value;
90 }
91
92 return value + "/";
93}
94
96 return templateDir_ + "generated_" + model_ + "_" + wilson_ + ".cpp";
97}
98
100 return templateDir_ + "generated_" + model_ + "_" + wilson_;
101}
102
104 return templateDir_ + "libs/" + wilson_ + "_" + model_+ "/script/example_" + lowercaseWilson_ + "_" + lowercaseModel_ + ".cpp";
105}
106
108 return templateDir_ + "libs/" + wilson_ + "_" + model_+ "/bin/example_" + lowercaseWilson_ + "_" + lowercaseModel_ + ".x";
109}
110
112 return templateDir_ + "libs/" + wilson_ + "_" + model_+ "/include/params.h";
113}
114
115std::string FileNameManager::getHelperFileName(const std::string &ext) const {
116 if (ext=="h") return templateDir_ + "libs/" + wilson_ + "_" + model_ + "/include/csv_helper." + ext;
117 if (ext=="cpp") return templateDir_ + "libs/" + wilson_ + "_" + model_ + "/src/csv_helper." + ext;
118 throw std::runtime_error("Unsupported extension");
119}
120
121std::string FileNameManager::getBaseHelperFileName(const std::string &ext) const {
122 if (ext=="h" || ext=="cpp") return baseTemplateDir_ + "csv_helper." + ext;
123 throw std::runtime_error("Unsupported extension");
124}
125
126std::string FileNameManager::getOutputDir() const {
127 return templateDir_;
128}
129
131 return baseTemplateDir_;
132}
133
134std::string FileNameManager::getLibDir() const {
135 return templateDir_ + "libs/" + wilson_ + "_" + model_ + "/";
136}
137
139 return templateDir_ + model_ + "_wilson.csv";
140}
141
143 return bsmMappingFile_.value_or(smMappingFile_);
144}
145
147
148 return smMappingFile_;
149}
150
151std::optional<std::string> FileNameManager::getBsmMappingFileName() const {
152 return bsmMappingFile_;
153}
154
156 return getLibDir() + "bin/paramlist.csv";
157}
Manages file and directory names for generated MARTY code and assets.
@ TEMPLATE_DIR
Read-only directory containing generated-code templates.
@ MARTY_TEMP_DIR
Writable cache directory used for generated MARTY files.
Core-side adapter giving MARTY access to configuration and managed paths.
MartyPath
Enumerates MARTY-related filesystem resources.
@ BSM_MAPPING_FILE
static std::shared_ptr< FileNameManager > getInstance(const std::string &wilson="", const std::string &model="")
Retrieves a FileNameManager for a given (wilson, model) pair.
std::string getNumGeneratedFileName() const
std::string getCsvWilsonFileName() const
std::optional< std::string > getBsmMappingFileName() const
std::string getGeneratedFileName() const
std::string getExecutableFileName() const
std::string getParamFileName() const
std::string getOutputDir() const
static void setTestingRoots(const std::string &templateRoot, const std::string &baseTemplateRoot, const std::string &assetsRoot)
Testing-only root overrides.
std::string getNumExecutableFileName() const
std::string getTemplateDir() const
std::string getNumParamFileName() const
std::string getHelperFileName(const std::string &extension) const
std::string getBaseHelperFileName(const std::string &extension) const
std::string getSmMappingFileName() const
std::string getLibDir() const
static void clearTestingRoots()
FileNameManager(const FileNameManager &)=delete
std::string getjsondbmodel() const
Legacy accessor kept for existing code.
Hash specialization for SymbolId<Tag>.
Definition BlockName.h:353