Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
MappingDatabase.cpp
Go to the documentation of this file.
1#include "MappingDatabase.h"
3#include "JsonParser.h"
4#include <iostream>
5
6
7MappingDatabase::MappingDatabase(const std::string& instanceName, const std::string& jsonFilePath,
8 std::shared_ptr<IParamMappingSource> loader) {
9
10 if (jsonFilePath.empty()) {
11 std::cerr << "Instance " << instanceName
12 << " was not found and no JSON path was provided." << std::endl;
13 }
14
15 if (!loader) {
16 loader = std::make_shared<JsonParamMappingAdapter>(std::make_shared<JSONParser>());
17 }
18
19 load(jsonFilePath, loader);
20}
21
22void MappingDatabase::load(const std::string& jsonFilePath,
23 const std::shared_ptr<IParamMappingSource>& loader) {
24 try {
25 paramsMap = loader->loadFromFile(jsonFilePath);
26 } catch (const std::exception& e) {
27 std::cerr << "Failed to load mapping from " << jsonFilePath
28 << " : " << e.what() << std::endl;
29 paramsMap.clear();
30 }
31}
32
33std::unordered_map<std::string, InterpretedParam> MappingDatabase::getParams() const {
34 return std::unordered_map<std::string, InterpretedParam>(paramsMap.begin(), paramsMap.end());
35}
Adapter to load parameter mappings from a JSON/YAML-like DBNode tree.
Lightweight JSON parser/serializer for DBNode trees.
In-memory store of parameter mappings loaded from an external file.
std::unordered_map< std::string, InterpretedParam > getParams() const
Returns the current parameter mapping.
MappingDatabase(const std::string &instanceName, const std::string &jsonFilePath, std::shared_ptr< IParamMappingSource > loader)
Constructs a MappingDatabase and immediately loads mappings.