warn if root histo plugin is initialized multiple times

This commit is contained in:
Florian Lüke 2024-12-27 13:53:09 +01:00
parent 59b11c94a7
commit 8c1e122e06

View file

@ -20,18 +20,30 @@ struct Context
std::vector<std::vector<TH1 *>> rawHistograms;
};
static Context *g_ctx = nullptr;
MANA_DEFINE_PLUGIN_INIT(init)
{
if (g_ctx)
{
log_warn("init() called multiple times. This plugin is a singleton!");
return g_ctx;
}
log_set_level(LOG_INFO);
static Context g_ctx;
log_debug("init: ctx=%p", &g_ctx);
return &g_ctx;
log_debug("init");
return g_ctx = new Context;
}
MANA_DEFINE_PLUGIN_SHUTDOWN(shutdown)
{
(void)context;
log_debug("shutdown");
if (context != g_ctx)
{
log_warn("shutdown() called with invalid context");
return;
}
delete g_ctx;
g_ctx = nullptr;
}
struct ObjectPath
@ -145,7 +157,8 @@ inline std::string histo_info(const std::vector<std::vector<TH1 *>> &histos)
}
}
return fmt::format("histoCount={}, histoMem={} MiB", histoCount, histoMem / (1024.0 * 1024));
return fmt::format("histoCount={}, histoMem={:.2f} MiB", histoCount,
histoMem / (1024.0 * 1024));
}
MANA_DEFINE_PLUGIN_BEGIN_RUN(begin_run)