factor out common code
This commit is contained in:
parent
8dfa2d798a
commit
ee8305cd0c
3 changed files with 50 additions and 33 deletions
|
@ -256,6 +256,25 @@ struct ManaCSink: public IManaSink
|
|||
}
|
||||
};
|
||||
|
||||
struct ObjectPath
|
||||
{
|
||||
std::string path;
|
||||
std::string objectName;
|
||||
std::vector<std::string> 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 */
|
||||
|
|
29
src/internal/mana_root.hpp
Normal file
29
src/internal/mana_root.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef C1A4FAE3_95D5_446C_9D8B_3040BB335215
|
||||
#define C1A4FAE3_95D5_446C_9D8B_3040BB335215
|
||||
|
||||
#include <TDirectory.h>
|
||||
#include <mesytec-mnode/mnode_string.hpp>
|
||||
|
||||
namespace mesytec::mnode::mana
|
||||
{
|
||||
|
||||
template <typename It> 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 <typename C> 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 */
|
|
@ -6,9 +6,11 @@
|
|||
#include <vector>
|
||||
|
||||
#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<std::string> 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 <typename It> 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<std::vector<TH1 *>> make_hitcount_histos(TDirectory *baseDir,
|
||||
const nlohmann::json &jRun)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue