13std::string api_path_name(
APIPath path_name)
35 return "UNKNOWN_API_PATH";
38bool is_default_input_path(
APIPath path_name)
52bool is_user_input_path(
APIPath path_name)
68bool is_directory_path(
APIPath path_name)
82bool is_writable_cache_directory_path(
APIPath path_name)
93std::string lower_extension(
const fs::path& path)
95 std::string extension = path.extension().string();
96 std::transform(extension.begin(), extension.end(), extension.begin(),
97 [](
unsigned char c) { return static_cast<char>(std::tolower(c)); });
101bool validate_pre_init_path_override(
APIPath path_name,
const fs::path& path)
104 LOG_ERROR(
"HyperisoMaster",
"LHA_PATH is provided through init()/switch_lha() and cannot be overridden through pre_init_set_paths.");
109 if (is_writable_cache_directory_path(path_name)) {
110 fs::create_directories(path, ec);
112 LOG_ERROR(
"HyperisoMaster",
"Cannot create cache directory for", api_path_name(path_name),
":", path.string(), ec.message());
117 if (!fs::exists(path, ec) || ec) {
118 LOG_ERROR(
"HyperisoMaster",
"Path override for", api_path_name(path_name),
"does not exist:", path.string());
122 if (is_directory_path(path_name)) {
123 if (!fs::is_directory(path, ec) || ec) {
124 LOG_ERROR(
"HyperisoMaster",
"Path override for", api_path_name(path_name),
"must be an existing directory:", path.string());
130 if (!fs::is_regular_file(path, ec) || ec) {
131 LOG_ERROR(
"HyperisoMaster",
"Path override for", api_path_name(path_name),
"must be an existing file:", path.string());
135 const std::string extension = lower_extension(path);
136 if (is_default_input_path(path_name)) {
137 if (extension !=
".json") {
138 LOG_ERROR(
"HyperisoMaster",
"Path override for", api_path_name(path_name),
"must use the .json extension:", path.string());
141 LOG_WARN(
"HyperisoMaster",
"Overriding a Hyperiso default path is not the expected runtime behavior. Make sure you know what you are doing:", api_path_name(path_name));
145 if (is_user_input_path(path_name)) {
146 if (extension !=
".yaml" && extension !=
".yml") {
147 LOG_ERROR(
"HyperisoMaster",
"Path override for", api_path_name(path_name),
"must use the .yaml or .yml extension:", path.string());
153 LOG_ERROR(
"HyperisoMaster",
"Unsupported APIPath override:", api_path_name(path_name));
159void HyperisoMaster::ensure_memory_manager_created() {
160 std::shared_ptr<ParamBlockLoader> pbl = std::make_shared<ParamBlockLoader>();
161 std::shared_ptr<CorrelationLoader<ParamId>> cl_param = std::make_shared<CorrelationLoader<ParamId>>();
162 std::shared_ptr<CorrelationLoader<ExperimentObs>> cl_obs = std::make_shared<CorrelationLoader<ExperimentObs>>();
163 std::shared_ptr<SpectrumCalculator> spectrum_c = std::make_shared<SpectrumCalculator>();
164 std::shared_ptr<IPathsProvider> dpp = path_overrides.empty()
165 ? std::static_pointer_cast<IPathsProvider>(std::make_shared<DefaultPathsProvider>())
170bool HyperisoMaster::should_validate_marty_runtime(
const HyperisoConfig& config)
const {
172 const bool hyp_as_sm_marty = flag_it != config.
flags.end() && flag_it->second;
176bool HyperisoMaster::validate_marty_runtime_if_needed(
const HyperisoConfig& config,
const std::string& context)
const {
177 if (!should_validate_marty_runtime(config)) {
182 return install.valid;
186 ensure_memory_manager_created();
187 if (!validate_marty_runtime_if_needed(config,
"HyperisoMaster::init")) {
203 ensure_memory_manager_created();
206 if (mm->is_ready()) {
207 LOG_WARN(
"HyperisoMaster",
"pre_init_add_block must be called before init; this prototype will only affect future LHA reloads.");
210 mm->add_lha_prototype(blockName, itemCount, valueIdx, scaleIdx, rgIdx, binIdx, globalScale);
215 ensure_memory_manager_created();
218 if (mm->is_ready()) {
219 LOG_WARN(
"HyperisoMaster",
"pre_init_add_blocks must be called before init; these prototypes will only affect future LHA reloads.");
222 mm->add_lha_prototypes(prototypes);
228 if (!install.valid) {
229 LOG_ERROR(
"MartyConfigError", install.error);
233 if (install.has_executable) {
234 LOG_DEBUG(
"MARTY executable detected at", install.marty_executable.string());
236 LOG_WARN(
"MartyRuntimeConfig",
"No bin/marty executable found under", install.prefix.string(),
"continuing because libmarty and marty.h are present.");
239 LOG_INFO(
"MARTY runtime path registered:", install.prefix.string());
246 if (!resolved.valid) {
247 throw std::runtime_error(resolved.error);
249 LOG_INFO(
"SOFTSUSY runtime path registered:", resolved.executable.string());
254 ensure_memory_manager_created();
257 if (mm->is_ready()) {
258 LOG_WARN(
"HyperisoMaster",
"pre_init_set_paths must be called before init; these path overrides will only affect future reloads.");
261 if (pathOverrides.empty()) {
262 LOG_WARN(
"HyperisoMaster",
"pre_init_set_paths called with an empty override map; keeping existing paths.");
266 bool installed_any_path =
false;
267 for (
const auto& [path_name, raw_path] : pathOverrides) {
268 const fs::path candidate(raw_path);
269 if (!validate_pre_init_path_override(path_name, candidate)) {
274 const fs::path normalized = fs::weakly_canonical(candidate, ec);
275 path_overrides[path_name] = ec ? fs::absolute(candidate) : normalized;
276 installed_any_path =
true;
279 if (!installed_any_path) {
283 mm->set_paths_provider(std::make_shared<OverridePathsProvider>(path_overrides));
284 LOG_INFO(
"Hyperiso path overrides registered:", path_overrides.size());
312 ensure_memory_manager_created();
313 if (!validate_marty_runtime_if_needed(config,
"HyperisoMaster::switch_lha")) {
ExternalFlag
Flags describing external input characteristics.
@ HYP_AS_SM_MARTY
If true, use Hyperiso as SM values for Wilson coefficients (up to NNLO).
High-level helpers for initializing and monitoring the Hyperiso framework.
APIPath
Enumerates the filesystem paths exposed through the public API.
@ USER_OBS_VALUES
YAML/YML file containing user observable overrides.
@ DEFAULT_NUISANCES
JSON file containing default nuisance definitions.
@ USER_OBS_CORR
YAML/YML file containing user observable correlation overrides.
@ USER_NUISANCES
YAML/YML file containing user nuisance overrides.
@ TEMPLATE_DIR
Read-only directory containing generated-code templates.
@ DEFAULT_OBS_CORR
JSON file containing default observable correlations.
@ USER_PARAM_CORR
YAML/YML file containing user parameter correlation overrides.
@ DEFAULT_PARAM_VALUES
JSON file containing default parameter values.
@ USER_SM_PARAMS
YAML/YML file containing user SM parameter overrides.
@ DEFAULT_OBS_VALUES
JSON file containing default observable values.
@ MARTY_TEMP_DIR
Writable cache directory used for generated MARTY files.
@ LHA_PATH
Path to the active LHA file.
@ PARAM_MAPPING_DIR
Read-only directory containing MARTY/Hyperiso parameter mappings.
@ SPECTRUM_DIR
Writable cache directory used for generated spectrum files.
@ USER_FLAVOR_PARAMS
YAML/YML file containing user flavor parameter overrides.
@ ASSETS_ROOT
Root directory for HyperISO read-only assets.
@ DEFAULT_PARAM_CORR
JSON file containing default parameter correlations.
@ USER_DECAY_PARAMS
YAML/YML file containing user decay parameter overrides.
#define LOG_ERROR(type,...)
Macro for logging error messages and terminating the application.
#define LOG_INFO(...)
Macro for logging informational messages.
#define LOG_DEBUG(...)
Macro for logging debug messages.
#define LOG_WARN(...)
Macro for logging warning messages.
Block identifier with alias support.
static void print_startup(const std::string &lha_file, const HyperisoConfig &config)
void pre_init_add_block(BlockName blockName, size_t itemCount=2, size_t valueIdx=1, int scaleIdx=-1, int rgIdx=-1, int binIdx=-1, bool globalScale=false)
Registers one additional LHA block prototype before init().
void init(const std::string &lhaFile, HyperisoConfig config)
Initializes Hyperiso using a LHA file and a full Config object.
bool check_flag(ExternalFlag flag)
Checks if a specific external flag is active.
void pre_init_add_blocks(const std::vector< LhaPrototypeSpec > &prototypes)
Registers several additional LHA block prototypes before init().
void pre_init_set_paths(const std::map< APIPath, std::string > &pathOverrides)
Overrides selected HyperISO filesystem paths before init().
void switch_lha(const std::string &lhaFile, HyperisoConfig config)
Switches the LHA file and applies a new configuration.
void pre_init_set_marty_path(const std::string &martyInstallPath)
Registers an existing MARTY installation before init().
void pre_init_set_spectrum_cache_dir(const std::string &cacheDir)
Sets the writable spectrum cache directory before init().
Model get_model()
Retrieves the current model type used by Hyperiso.
void pre_init_set_marty_cache_dir(const std::string &cacheDir)
Sets the writable MARTY generated-code/cache directory before init().
void pre_init_set_softsusy_path(const std::string &softsusyPath)
Registers a SOFTSUSY executable or installation directory before init().
static InstallInfo set_external_install_path(const std::filesystem::path &path)
Register a user-provided MARTY installation path.
static InstallInfo require_available(const std::string &context)
Validate and return the active MARTY installation.
const MemoryCache & getMemoryCache()
Retrieves the current memory cache.
void switch_lha(const std::string &lhaFile, HyperisoConfig config)
Registers several additional LHA block prototypes.
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.
Resolution set_external_path(const std::string &path)
Hash specialization for SymbolId<Tag>.
Configuration object controlling model, input flags and optional MARTY resources.
std::map< ExternalFlag, bool > flags
External flags describing the nature of the inputs.
Model model
Current model.
Interface providing all filesystem paths used by HyperISO.
HyperisoConfig config
Config struct for various flags and runtime information.
Default path provider with validated user overrides.