DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
SchemaUtils.hpp
Go to the documentation of this file.
1
11#ifndef IOMANAGER_INCLUDE_IOMANAGER_SCHEMAUTILS_HPP_
12#define IOMANAGER_INCLUDE_IOMANAGER_SCHEMAUTILS_HPP_
13
16#include "confmodel/Service.hpp"
17#include "utilities/get_ips.hpp"
18
19#include <functional>
20#include <regex>
21#include <string>
22
23namespace dunedaq::iomanager {
24
26{
27 std::string uid{ "" };
28 std::string data_type{ "" };
29 std::string tag{ "" };
30 std::string session{ "" };
31
33
34 ConnectionId(std::string uid, std::string data_type, std::string tag = "", std::string session = "")
35 : uid(uid)
37 , tag(tag)
39 {
40 }
41
43 : uid(cfg->UID())
44 , data_type(cfg->get_data_type())
45 {
46 }
47};
48
49inline bool
50operator<(ConnectionId const& l, ConnectionId const& r)
51{
52 if (l.session == r.session || l.session == "" || r.session == "") {
53 if (l.data_type == r.data_type) {
54 if (l.uid == r.uid) {
55 return l.tag < r.tag;
56 }
57 return l.uid < r.uid;
58 }
59 return l.data_type < r.data_type;
60 }
61 return l.session < r.session;
62}
63inline bool
65{
66 return (l.session == "" || r.session == "" || l.session == r.session) && l.uid == r.uid && l.tag == r.tag &&
67 l.data_type == r.data_type;
68}
69
70inline bool
72{
73 if (search.data_type != check.data_type)
74 return false;
75
76 if (search.session != check.session && search.session != "" && check.session != "")
77 return false;
78
79 std::regex search_ex(search.uid);
80 return std::regex_match(check.uid, search_ex);
81}
82
83inline std::string
84to_string(const ConnectionId& conn_id)
85{
86 if (conn_id.session != "") {
87 return conn_id.session + "/" + conn_id.uid + (conn_id.tag != "" ? "+" + conn_id.tag : "") + "@@" +
88 conn_id.data_type;
89 }
90 return conn_id.uid + (conn_id.tag != "" ? "+" + conn_id.tag : "") + "@@" + conn_id.data_type;
91}
92
93inline std::string
95{
96 std::string uri = "";
97 if (netCon) {
98 TLOG_DEBUG(45) << "Getting URI for network connection " << netCon->UID();
99 auto service = netCon->get_associated_service();
100 auto protocol = service->get_protocol();
101 if (protocol == "tcp") {
102
103 std::string port = "*";
104 if (service->get_port() && service->get_port() != 0) {
105 port = std::to_string(service->get_port());
106 }
107 auto iface = service->get_eth_device_name();
108 uri = std::string(service->get_protocol() + "://" + dunedaq::utilities::get_interface_ip(iface) + ":" + port);
109 } else if (protocol == "inproc") {
110 uri = std::string(service->get_protocol() + "://" + service->get_path());
111 }
112 }
113 return uri;
114}
115
116} // namespace dunedaq::iomanager
117
118namespace std {
119
120template<>
121struct hash<dunedaq::iomanager::ConnectionId>
122{
123 std::size_t operator()(const dunedaq::iomanager::ConnectionId& conn_id) const
124 {
125 return std::hash<std::string>()(conn_id.session + conn_id.uid + conn_id.tag + conn_id.data_type);
126 }
127};
128
129} // namespace std
130
131#endif // IOMANAGER_INCLUDE_IOMANAGER_SCHEMAUTILS_HPP_
static void check(std::vector< conffwk::ConfigurationChange * > &changes, const InheritanceData &inheritance, const std::set< std::string > &class_names, const OksConfiguration::SMap &objects, const std::string &obj_class, const std::string &obj_id, const char action)
const std::string & UID() const noexcept
const dunedaq::confmodel::Service * get_associated_service() const
Get "associated_service" relationship value. Service provided by this connection.
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
bool is_match(ConnectionId const &search, ConnectionId const &check)
std::string to_string(const ConnectionId &conn_id)
bool operator<(ConnectionRegistration const &l, ConnectionRegistration const &r)
std::string get_uri_for_connection(const confmodel::NetworkConnection *netCon)
bool operator==(ConnectionId const &l, ConnectionId const &r)
std::string get_interface_ip(std::string eth_device_name, bool throw_if_missing=false)
Definition get_ips.hpp:73
The DUNE-DAQ namespace.
Unsupported std::string uri Execution of command std::string error Failed to create CommandFacility uri
Definition Issues.hpp:77
ConnectionId(std::string uid, std::string data_type, std::string tag="", std::string session="")
ConnectionId(const confmodel::Connection *cfg)
std::size_t operator()(const dunedaq::iomanager::ConnectionId &conn_id) const