diff --git a/src/internal/mana_lib.hpp b/src/internal/mana_lib.hpp index 957df05..8cb8527 100644 --- a/src/internal/mana_lib.hpp +++ b/src/internal/mana_lib.hpp @@ -256,6 +256,25 @@ struct ManaCSink: public IManaSink } }; +struct ObjectPath +{ + std::string path; + std::string objectName; + std::vector components; + + ObjectPath(const std::string &path, const std::string &sep = "\\.") + : path(path) + { + split_string(path, std::regex(sep), std::back_inserter(components)); + + if (!components.empty()) + { + objectName = components.back(); + components.pop_back(); + } + } +}; + } // namespace mesytec::mnode::mana #endif /* AAB5E4D2_A05B_4F2F_B76A_406A5A569D55 */ diff --git a/src/internal/mana_root.hpp b/src/internal/mana_root.hpp new file mode 100644 index 0000000..b47c4b1 --- /dev/null +++ b/src/internal/mana_root.hpp @@ -0,0 +1,29 @@ +#ifndef C1A4FAE3_95D5_446C_9D8B_3040BB335215 +#define C1A4FAE3_95D5_446C_9D8B_3040BB335215 + +#include +#include + +namespace mesytec::mnode::mana +{ + +template TDirectory *root_mkpath_cd(It begin, It end) +{ + TDirectory *result = nullptr; + for (auto it = begin; it != end; ++it) + { + result = gDirectory->mkdir(it->c_str(), "", true); + result->cd(); + } + + return result; +} + +template TDirectory *root_mkpath_cd(const C &components) +{ + return root_mkpath_cd(components.begin(), components.end()); +} + +} // namespace mesytec::mnode::mana + +#endif /* C1A4FAE3_95D5_446C_9D8B_3040BB335215 */ diff --git a/src/mana_plugin_root_histogram.cc b/src/mana_plugin_root_histogram.cc index 85b456b..e120375 100644 --- a/src/mana_plugin_root_histogram.cc +++ b/src/mana_plugin_root_histogram.cc @@ -6,9 +6,11 @@ #include #include "internal/mana_lib.hpp" +#include "internal/mana_root.hpp" #include "internal/rxi/log.hpp" using namespace mesytec::mnode; +using namespace mesytec::mnode::mana; struct Context { @@ -43,39 +45,6 @@ MANA_DEFINE_PLUGIN_SHUTDOWN(shutdown) g_ctx = nullptr; } -struct ObjectPath -{ - std::string path; - std::string objectName; - std::vector components; - - ObjectPath(const std::string &path, const std::string &sep = "\\.") - : path(path) - { - std::regex re(sep); - std::sregex_token_iterator it(path.begin(), path.end(), re, -1); - std::copy(it, std::sregex_token_iterator(), std::back_inserter(components)); - - if (!components.empty()) - { - objectName = components.back(); - components.pop_back(); - } - } -}; - -template TDirectory *root_mkpath_cd(It begin, It end) -{ - TDirectory *result = nullptr; - for (auto it = begin; it != end; ++it) - { - result = gDirectory->mkdir(it->c_str(), "", true); - result->cd(); - } - - return result; -} - inline std::vector> make_hitcount_histos(TDirectory *baseDir, const nlohmann::json &jRun) {