DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
ipm
include
ipm
ZmqContext.hpp
Go to the documentation of this file.
1
#ifndef IPM_INCLUDE_IPM_ZMQCONTEXT_HPP_
2
#define IPM_INCLUDE_IPM_ZMQCONTEXT_HPP_
3
12
13
#include "
ers/Issue.hpp
"
14
#include "
logging/Logging.hpp
"
// NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
15
#include "zmq.hpp"
16
17
enum
18
{
19
TLVL_ZMQCONTEXT
= 10,
20
TLVL_CONNECTIONSTRING
= 11,
21
TLVL_ZMQPUBLISHER_SEND_START
= 12,
22
TLVL_ZMQPUBLISHER_SEND_ERR
= 2,
23
TLVL_ZMQPUBLISHER_SEND_END
= 13,
24
TLVL_ZMQPUBLISHER_DESTRUCTOR
= 5,
25
TLVL_ZMQRECEIVER_RECV_HDR
= 14,
26
TLVL_ZMQRECEIVER_RECV_HDR_2
= 15,
27
TLVL_ZMQRECEIVER_RECV_DATA
= 16,
28
TLVL_ZMQRECEIVER_RECV_DATA_2
= 17,
29
TLVL_ZMQRECEIVER_RECV_END
= 18,
30
TLVL_ZMQSENDER_SEND_START
= 19,
31
TLVL_ZMQSENDER_SEND_ERR
= 3,
32
TLVL_ZMQSENDER_SEND_END
= 20,
33
TLVL_ZMQSENDER_DESTRUCTOR
= 5,
34
TLVL_ZMQSUBSCRIBER_RECV_HDR
= 21,
35
TLVL_ZMQSUBSCRIBER_RECV_HDR_2
= 22,
36
TLVL_ZMQSUBSCRIBER_RECV_DATA
= 23,
37
TLVL_ZMQSUBSCRIBER_RECV_DATA_2
= 24,
38
TLVL_ZMQSUBSCRIBER_RECV_END
= 25,
39
};
40
41
namespace
dunedaq
{
42
51
ERS_DECLARE_ISSUE
(
ipm
,
52
ZmqOperationError,
53
connection_name <<
": An exception occured while calling "
<< operation <<
" on the ZMQ "
<< direction
54
<<
" socket: "
<< what <<
" (connection_string: "
<< connection_string <<
")"
,
55
((std::string)connection_name)((std::string)operation)((std::string)direction)((
const
char
*)what)(
56
(std::string)connection_string))
// NOLINT
58
66
ERS_DECLARE_ISSUE
(
67
ipm
,
68
ZmqSendError,
69
connection_name <<
": An exception occurred while sending "
<< N <<
" bytes to "
<< topic <<
": "
<< what,
70
((std::string)connection_name)((
const
char
*)what)((
int
)N)((std::string)topic))
// NOLINT
72
79
ERS_DECLARE_ISSUE
(
ipm
,
80
ZmqReceiveError,
81
connection_name <<
": An exception occured while receiving "
<< which <<
": "
<< what,
82
((std::string)connection_name)((
const
char
*)what)((
const
char
*)which))
// NOLINT
84
91
ERS_DECLARE_ISSUE
(
ipm
,
92
ZmqSubscribeError,
93
connection_name <<
": An execption occured while subscribing to "
<< topic <<
": "
<< what,
94
((std::string)connection_name)((
const
char
*)what)((std::string)topic))
// NOLINT
96
103
ERS_DECLARE_ISSUE
(
ipm
,
104
ZmqUnsubscribeError,
105
connection_name <<
": An execption occured while unsubscribing from "
<< topic <<
": "
<< what,
106
((std::string)connection_name)((
const
char
*)what)((std::string)topic))
// NOLINT
108
109
namespace
ipm
{
110
class
ZmqContext
111
{
112
public
:
113
static
ZmqContext
&
instance
()
114
{
115
static
ZmqContext
s_ctx;
116
return
s_ctx;
117
}
118
119
zmq::context_t&
GetContext
() {
return
m_context
; }
120
121
void
set_context_threads
(
int
nthreads)
122
{
123
TLOG_DEBUG
(
TLVL_ZMQCONTEXT
) <<
"Setting ZMQ Context IO thread count to "
<< nthreads;
124
m_context
.set(zmq::ctxopt::io_threads, nthreads);
125
}
126
void
set_context_maxsockets
(
int
max_sockets)
127
{
128
TLOG_DEBUG
(
TLVL_ZMQCONTEXT
) <<
"Setting ZMQ Context max sockets to "
<< max_sockets;
129
m_context
.set(zmq::ctxopt::max_sockets, max_sockets);
130
}
131
132
private
:
133
ZmqContext
()
134
{
135
auto
threads_c = getenv(
"IPM_ZMQ_IO_THREADS"
);
136
if
(threads_c !=
nullptr
) {
137
auto
threads = std::atoi(threads_c);
// NOLINT If a conversion error occurs, we discard the result
138
if
(threads > 1) {
139
set_context_threads
(threads);
140
}
141
}
142
143
bool
sockets_set =
false
;
144
auto
sockets_c = getenv(
"IPM_ZMQ_MAX_SOCKETS"
);
145
if
(sockets_c !=
nullptr
) {
146
auto
sockets = std::atoi(sockets_c);
// NOLINT If a conversion error occurs, we discard the result
147
if
(sockets >
s_minimum_sockets
) {
148
set_context_maxsockets
(sockets);
149
sockets_set =
true
;
150
}
151
}
152
if
(!sockets_set) {
153
set_context_maxsockets
(
s_minimum_sockets
);
154
}
155
}
156
~ZmqContext
()
157
{
158
TLOG_DEBUG
(
TLVL_ZMQCONTEXT
) <<
"Closing ZMQ Context"
;
159
m_context
.close();
160
TLOG_DEBUG
(
TLVL_ZMQCONTEXT
) <<
"ZMQ Context closed"
;
161
}
162
zmq::context_t
m_context
;
163
static
constexpr
int
s_minimum_sockets
= 16636;
164
165
ZmqContext
(
ZmqContext
const
&) =
delete
;
166
ZmqContext
(
ZmqContext
&&) =
delete
;
167
ZmqContext
&
operator=
(
ZmqContext
const
&) =
delete
;
168
ZmqContext
&
operator=
(
ZmqContext
&&) =
delete
;
169
};
170
}
// namespace ipm
171
}
// namespace dunedaq
172
173
#endif
// IPM_INCLUDE_IPM_ZMQCONTEXT_HPP_
Issue.hpp
TLVL_ZMQSUBSCRIBER_RECV_DATA_2
@ TLVL_ZMQSUBSCRIBER_RECV_DATA_2
Definition
ZmqContext.hpp:37
TLVL_ZMQSUBSCRIBER_RECV_HDR
@ TLVL_ZMQSUBSCRIBER_RECV_HDR
Definition
ZmqContext.hpp:34
TLVL_ZMQSUBSCRIBER_RECV_END
@ TLVL_ZMQSUBSCRIBER_RECV_END
Definition
ZmqContext.hpp:38
TLVL_ZMQRECEIVER_RECV_HDR_2
@ TLVL_ZMQRECEIVER_RECV_HDR_2
Definition
ZmqContext.hpp:26
TLVL_ZMQSUBSCRIBER_RECV_DATA
@ TLVL_ZMQSUBSCRIBER_RECV_DATA
Definition
ZmqContext.hpp:36
TLVL_ZMQSENDER_SEND_END
@ TLVL_ZMQSENDER_SEND_END
Definition
ZmqContext.hpp:32
TLVL_ZMQRECEIVER_RECV_DATA
@ TLVL_ZMQRECEIVER_RECV_DATA
Definition
ZmqContext.hpp:27
TLVL_ZMQSUBSCRIBER_RECV_HDR_2
@ TLVL_ZMQSUBSCRIBER_RECV_HDR_2
Definition
ZmqContext.hpp:35
TLVL_ZMQCONTEXT
@ TLVL_ZMQCONTEXT
Definition
ZmqContext.hpp:19
TLVL_ZMQSENDER_DESTRUCTOR
@ TLVL_ZMQSENDER_DESTRUCTOR
Definition
ZmqContext.hpp:33
TLVL_ZMQPUBLISHER_DESTRUCTOR
@ TLVL_ZMQPUBLISHER_DESTRUCTOR
Definition
ZmqContext.hpp:24
TLVL_ZMQPUBLISHER_SEND_START
@ TLVL_ZMQPUBLISHER_SEND_START
Definition
ZmqContext.hpp:21
TLVL_ZMQPUBLISHER_SEND_ERR
@ TLVL_ZMQPUBLISHER_SEND_ERR
Definition
ZmqContext.hpp:22
TLVL_CONNECTIONSTRING
@ TLVL_CONNECTIONSTRING
Definition
ZmqContext.hpp:20
TLVL_ZMQRECEIVER_RECV_END
@ TLVL_ZMQRECEIVER_RECV_END
Definition
ZmqContext.hpp:29
TLVL_ZMQRECEIVER_RECV_HDR
@ TLVL_ZMQRECEIVER_RECV_HDR
Definition
ZmqContext.hpp:25
TLVL_ZMQRECEIVER_RECV_DATA_2
@ TLVL_ZMQRECEIVER_RECV_DATA_2
Definition
ZmqContext.hpp:28
TLVL_ZMQSENDER_SEND_ERR
@ TLVL_ZMQSENDER_SEND_ERR
Definition
ZmqContext.hpp:31
TLVL_ZMQPUBLISHER_SEND_END
@ TLVL_ZMQPUBLISHER_SEND_END
Definition
ZmqContext.hpp:23
TLVL_ZMQSENDER_SEND_START
@ TLVL_ZMQSENDER_SEND_START
Definition
ZmqContext.hpp:30
dunedaq::ipm::ZmqContext::ZmqContext
ZmqContext()
Definition
ZmqContext.hpp:133
dunedaq::ipm::ZmqContext::set_context_threads
void set_context_threads(int nthreads)
Definition
ZmqContext.hpp:121
dunedaq::ipm::ZmqContext::instance
static ZmqContext & instance()
Definition
ZmqContext.hpp:113
dunedaq::ipm::ZmqContext::operator=
ZmqContext & operator=(ZmqContext &&)=delete
dunedaq::ipm::ZmqContext::set_context_maxsockets
void set_context_maxsockets(int max_sockets)
Definition
ZmqContext.hpp:126
dunedaq::ipm::ZmqContext::m_context
zmq::context_t m_context
Definition
ZmqContext.hpp:162
dunedaq::ipm::ZmqContext::~ZmqContext
~ZmqContext()
Definition
ZmqContext.hpp:156
dunedaq::ipm::ZmqContext::ZmqContext
ZmqContext(ZmqContext const &)=delete
dunedaq::ipm::ZmqContext::s_minimum_sockets
static constexpr int s_minimum_sockets
Definition
ZmqContext.hpp:163
dunedaq::ipm::ZmqContext::ZmqContext
ZmqContext(ZmqContext &&)=delete
dunedaq::ipm::ZmqContext::GetContext
zmq::context_t & GetContext()
Definition
ZmqContext.hpp:119
dunedaq::ipm::ZmqContext::operator=
ZmqContext & operator=(ZmqContext const &)=delete
Logging.hpp
TLOG_DEBUG
#define TLOG_DEBUG(lvl,...)
Definition
Logging.hpp:112
ERS_DECLARE_ISSUE
#define ERS_DECLARE_ISSUE( namespace_name, class_name, message_, attributes)
Definition
macro.hpp:65
dunedaq::ipm
An ERS Error indicating that an exception was thrown from ZMQ while performing an operation.
Definition
PluginInfo.hpp:26
dunedaq
Including Qt Headers.
Definition
module.cpp:16
Generated on
for DUNE-DAQ by
1.17.0