DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
util.hpp
Go to the documentation of this file.
1#ifndef _dal_util_H_
2#define _dal_util_H_
3
4#include <exception>
5
7// #include "conffwk/DalObject.hpp"
8#include "nlohmann/json.hpp"
9#include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
10
13#include "confmodel/Segment.hpp"
14#include "confmodel/Service.hpp"
15#include "confmodel/Session.hpp"
18
19namespace dunedaq {
20
21namespace confmodel {
22
55get_session(dunedaq::conffwk::Configuration &conf, const std::string &name,
56 unsigned long rlevel = 10,
57 const std::vector<std::string> *rclasses = nullptr);
58
59template <typename T>
60void add_json_value(conffwk::ConfigObject &obj, std::string &name,
61 bool multi_value, nlohmann::json &attributes) {
62 if (!multi_value) {
63 T value;
64 obj.get(name, value);
65 attributes[name] = value;
66 } else {
67 std::vector<T> value_vector;
68 obj.get(name, value_vector);
69 attributes[name] = nlohmann::json(value_vector);
70 }
71}
72
73template <typename T>
74const std::vector<std::string> construct_commandline_parameters_appfwk(
75 const T *app, const conffwk::Configuration &confdb,
77
78 const dunedaq::confmodel::Service *control_service = nullptr;
79
80 for (auto const *as : app->get_exposes_service()) {
81 if (as->UID().ends_with("_control")) {
82 if (control_service)
83 throw DuplicatedControlService(ERS_HERE, as->UID());
84 control_service = as;
85 }
86 }
87
88 if (control_service == nullptr)
89 throw NoControlServiceDefined(ERS_HERE, app->UID());
90
91 const std::string control_uri = control_service->get_protocol() + "://" +
92 app->get_runs_on()->get_runs_on()->UID() +
93 ":" +
94 std::to_string(control_service->get_port());
95
96 const std::string configuration_uri = confdb.get_impl_spec();
97
98 return {
99 "-s",
100 session->UID(),
101 "--name",
102 app->UID(),
103 "-c",
104 control_uri,
105 "--configurationService",
106 configuration_uri,
107 };
108}
109
110} // namespace confmodel
111
112} // namespace dunedaq
113
114#endif
#define ERS_HERE
Defines base class for cache of template objects.
const std::string & get_impl_spec() const noexcept
const std::string & get_protocol() const
Get "protocol" attribute value.
Definition Service.hpp:99
uint16_t get_port() const
Get "port" attribute value.
Definition Service.hpp:130
conffwk entry point
const std::vector< std::string > construct_commandline_parameters_appfwk(const T *app, const conffwk::Configuration &confdb, const dunedaq::confmodel::Session *session)
Definition util.hpp:74
const dunedaq::confmodel::Session * get_session(dunedaq::conffwk::Configuration &conf, const std::string &name, unsigned long rlevel=10, const std::vector< std::string > *rclasses=nullptr)
Get session object.
void add_json_value(conffwk::ConfigObject &obj, std::string &name, bool multi_value, nlohmann::json &attributes)
Definition util.hpp:60
The DUNE-DAQ namespace.
Definition DataStore.hpp:57
msgpack::object obj