Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
MemoryManager.h
Go to the documentation of this file.
1#ifndef HYPERISO_MEMORY_MANAGER_H
2#define HYPERISO_MEMORY_MANAGER_H
3
4#include <unordered_map>
5#include <thread>
6
7#include "config.hpp"
8#include "Include.h"
9#include "BlockAccessor.h"
10#include "DBMemento.h"
11#include "CorrelationRepo.h"
12#include "ISpectrumCalculator.h"
13#include "IDataLoader.h"
14#include "IPathsProvider.h"
16#include "Config.h"
17
35
42 std::map<InternalFlag, bool> flags {{InternalFlag::PARAMS_CHANGED, false}};
43 fs::path lha_path;
44 std::vector<ParameterType> parameter_types;
45 std::thread::id thread_id;
46 bool is_ready;
47
48};
49
55struct ReadyGuard {
56 bool& flag;
57 ReadyGuard(bool& f) : flag(f) { flag = false; }
58 ~ReadyGuard() { flag = true; }
59};
60
68private:
69 static MemoryManager* instance;
70 MemoryCache cache;
71 std::shared_ptr<BlockAccessor> input_cache;
72 DBMemento memento;
73 CorrelationRepository correlation_repository;
74 std::shared_ptr<ISpectrumCalculator> sc;
75 std::shared_ptr<IDataLoader<BlockAccessor>> dl_ba;
76 std::shared_ptr<IDataLoader<CorrelationMatrixPair<ParamId>>> dl_cmp_p;
77 std::shared_ptr<IDataLoader<CorrelationMatrixPair<ExperimentObs>>> dl_cmp_o;
78 std::shared_ptr<IPathsProvider> paths_provider;
79 std::shared_ptr<ILhaPrototypeRegistry> lha_prototype_registry;
80
85
89 MemoryManager(std::shared_ptr<IDataLoader<BlockAccessor>> loader,
90 std::shared_ptr<IDataLoader<CorrelationMatrixPair<ParamId>>> param_corr,
91 std::shared_ptr<IDataLoader<CorrelationMatrixPair<ExperimentObs>>> obs_corr,
92 std::shared_ptr<ISpectrumCalculator> spectrum_c,
93 std::shared_ptr<IPathsProvider> paths_provider_,
94 std::shared_ptr<ILhaPrototypeRegistry> lha_prototype_registry_);
95
100 void check_if_ready();
101
107 void read_default_input();
108
114 void read_user_input();
115
122 void read_lha_input(const std::string& lhaFile, const HyperisoConfig& config);
123
133 fs::path format_lha_path(const std::string& path);
134
144 fs::path calculate_spectrum(fs::path input_lha_path, const HyperisoConfig& config);
145
153 void deduce_parameter_types(const HyperisoConfig &config);
154
160 void save_input_cache();
161
162public:
167 static MemoryManager* GetInstance();
168
175 static MemoryManager* Create(std::shared_ptr<IDataLoader<BlockAccessor>> loader,
176 std::shared_ptr<IDataLoader<CorrelationMatrixPair<ParamId>>> param_corr,
177 std::shared_ptr<IDataLoader<CorrelationMatrixPair<ExperimentObs>>> obs_corr,
178 std::shared_ptr<ISpectrumCalculator> spectrum_c,
179 std::shared_ptr<IPathsProvider> paths_provider,
180 std::shared_ptr<ILhaPrototypeRegistry> lha_prototype_registry=nullptr);
181
191 void set_paths_provider(std::shared_ptr<IPathsProvider> paths_provider_);
192
202 fs::path get_path(APIPath path_name);
203
212 void init(const std::string &lhaFile, HyperisoConfig config);
213
220 void add_lha_prototype(BlockName blockName,
221 size_t itemCount=2,
222 size_t valueIdx=1,
223 int scaleIdx=-1,
224 int rgIdx=-1,
225 int binIdx=-1,
226 bool globalScale=false);
227
231 void add_lha_prototypes(const std::vector<LhaPrototypeSpec>& prototypes);
232
243 void switch_lha(const std::string& lhaFile, HyperisoConfig config);
244
253
260 void reload_user_input(const std::string &lhaFile, HyperisoConfig config);
261
269 void switch_model(Model model = Model::SM);
270
276 inline const MemoryCache& getMemoryCache() { check_if_ready(); return cache; }
277
281 inline bool is_ready() const { return cache.is_ready; }
282
289 std::shared_ptr<BlockAccessor> extract_blocks(std::unordered_set<BlockName> block_names);
290
296 std::shared_ptr<BlockAccessor> extract_block_accessor();
297
304 std::shared_ptr<BlockAccessor> clone_input_cache_deep() const;
305
311
320 std::unordered_set<ParamId> get_all_source_parameters(const std::unordered_set<ParamId>& param_ids) const;
321
322 MemoryManager(const MemoryManager&) = delete;
324 MemoryManager(MemoryManager&&) noexcept = default;
325 MemoryManager& operator=(MemoryManager&&) noexcept = default;
326
327 friend class Parameters;
328};
329
330#endif // HYPERISO_MEMORY_MANAGER_H
Alias-aware façade for accessing and manipulating multiple parameter blocks.
Concrete memento for BlockAccessor snapshots.
Model
Defines a generic interface for data loading operations.
APIPath
Enumerates the filesystem paths exposed through the public API.
Declares the interface for spectrum calculators.
InternalFlag
Internal flags used for memory management status.
Block identifier with alias support.
Definition BlockName.h:59
Manages correlations between parameters and experiment-scoped observables.
Stack-based implementation of IDBMemento for BlockAccessor.
Definition DBMemento.h:39
Abstract interface for loading data into an object.
Definition IDataLoader.h:60
Singleton class responsible for initializing and managing memory, input files, and parameter blocks.
std::shared_ptr< BlockAccessor > extract_block_accessor()
Extracts all blocks from the cached input.
const MemoryCache & getMemoryCache()
Retrieves the current memory cache.
std::shared_ptr< BlockAccessor > clone_input_cache_deep() const
Deep-clones the raw input cache as independent plain blocks.
void reload_user_input(HyperisoConfig config)
Reloads user-specific input files.
void set_paths_provider(std::shared_ptr< IPathsProvider > paths_provider_)
Replaces the filesystem path provider used by the manager.
void switch_lha(const std::string &lhaFile, HyperisoConfig config)
Registers several additional LHA block prototypes.
std::unordered_set< ParamId > get_all_source_parameters(const std::unordered_set< ParamId > &param_ids) const
Computes all ultimate "source" parameters for a given set of parameter IDs.
MemoryManager(const MemoryManager &)=delete
MemoryManager & operator=(const MemoryManager &)=delete
void init(const std::string &lhaFile, HyperisoConfig config)
Initializes the memory manager with the provided LHA file and configuration.
static MemoryManager * GetInstance()
Retrieves the singleton instance of MemoryManager.
static MemoryManager * Create(std::shared_ptr< IDataLoader< BlockAccessor > > loader, std::shared_ptr< IDataLoader< CorrelationMatrixPair< ParamId > > > param_corr, std::shared_ptr< IDataLoader< CorrelationMatrixPair< ExperimentObs > > > obs_corr, std::shared_ptr< ISpectrumCalculator > spectrum_c, std::shared_ptr< IPathsProvider > paths_provider, std::shared_ptr< ILhaPrototypeRegistry > lha_prototype_registry=nullptr)
Retrieves/creates the singleton instance of MemoryManager with injected dependencies.
const CorrelationRepository & get_correlation_repository()
Retrieves the current correlation repository.
void switch_model(Model model=Model::SM)
Switches the model used for spectrum and parameters.
fs::path get_path(APIPath path_name)
Retrieves a public API path from the runtime cache or path provider.
std::shared_ptr< BlockAccessor > extract_blocks(std::unordered_set< BlockName > block_names)
Extracts specific blocks from the cached input.
MemoryManager(MemoryManager &&) noexcept=default
void add_lha_prototypes(const std::vector< LhaPrototypeSpec > &prototypes)
Registers several additional LHA block prototypes through the injected port.
void add_lha_prototype(BlockName blockName, size_t itemCount=2, size_t valueIdx=1, int scaleIdx=-1, int rgIdx=-1, int binIdx=-1, bool globalScale=false)
Registers an additional LHA block prototype before LHA parsing.
bool is_ready() const
Returns whether MemoryManager has already completed init().
Block-based parameter repository for one ParameterType namespace.
Definition Parameters.h:351
double f(double x)
Wilson special function f depending on x.
Stores a pair of correlation matrices (statistical and systematic) for a given key type.
Configuration object controlling model, input flags and optional MARTY resources.
Definition Config.h:24
Stores memory cache details for parameter management and runtime state.
std::vector< ParameterType > parameter_types
List of parameter types currently managed.
bool is_ready
Indicates if the memory manager is initialized and ready.
std::thread::id thread_id
Thread ID associated with the current cache usage.
std::map< InternalFlag, bool > flags
Internal status flags.
HyperisoConfig config
Config struct for various flags and runtime information.
fs::path lha_path
Path to the currently loaded LHA file.
RAII guard to toggle the "ready" flag while performing unsafe operations.
ReadyGuard(bool &f)