DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
datahandlinglibs
include
datahandlinglibs
detail
DataMoveCallbackRegistry.hxx
Go to the documentation of this file.
1
#include "
datahandlinglibs/DataHandlingIssues.hpp
"
2
3
#include <functional>
4
5
namespace
dunedaq
{
6
7
namespace
datahandlinglibs
{
8
9
template
<
typename
DataType>
10
inline
void
11
DataMoveCallbackRegistry::register_callback
(
const
appmodel::DataMoveCallbackConf
* conf,
12
std::function<
void
(DataType&&)> callback)
13
{
14
std::lock_guard<std::mutex> guard(
m_mutex
);
15
std::string
id
= conf->
UID
();
16
if
(
m_callback_map
.count(
id
) == 0) {
17
TLOG
() <<
"Registering DataMoveCallback with ID: "
<< id;
18
m_callback_map
[id] = std::make_shared<DataMoveCallback<DataType>>(
DataMoveCallback
(
id
, callback));
19
}
else
{
20
TLOG
() <<
"Callback is already registered with ID: "
<<
id
<<
" Ignoring this registration."
;
21
}
22
}
23
24
template
<
typename
DataType>
25
inline
std::shared_ptr<std::function<void(DataType&&)>>
26
DataMoveCallbackRegistry::get_callback
(
const
appmodel::DataMoveCallbackConf
* conf)
27
{
28
std::lock_guard<std::mutex> guard(
m_mutex
);
29
std::string
id
= conf->
UID
();
30
if
(
m_callback_map
.contains(
id
)) {
31
TLOG
() <<
"Providing DataMoveCallback with ID: "
<< id;
32
if
(
auto
callback =
dynamic_cast<
DataMoveCallback<DataType>
*
>
(
m_callback_map
[
id
].
get
()); callback !=
nullptr
) {
33
return
callback->m_callback;
34
}
else
{
35
// As this can happen due to a very bad config error and wherever the acquire is called will lead to undefined
36
// behavior
37
throw
GenericConfigurationError
(
38
ERS_HERE
,
39
std::format(
"Callback cast failed for function signature with datatypes (expected vs. registered) : {} vs. {}"
,
40
typeid
(
DataMoveCallback<DataType>
).name(),
41
typeid
(*
m_callback_map
[
id
]).name()));
42
}
43
}
else
{
44
TLOG
() <<
"No callback registered with ID: "
<<
id
<<
" Returning nullptr."
;
45
return
nullptr
;
46
}
47
}
48
}
49
}
DataHandlingIssues.hpp
ERS_HERE
#define ERS_HERE
Definition
LocalContext.hpp:127
dunedaq::appmodel::DataMoveCallbackConf
Definition
DataMoveCallbackConf.hpp:20
dunedaq::conffwk::DalObject::UID
const std::string & UID() const noexcept
Definition
DalObject.hpp:119
dunedaq::datahandlinglibs::DataMoveCallbackRegistry::get
static std::shared_ptr< DataMoveCallbackRegistry > get()
Definition
DataMoveCallbackRegistry.hpp:52
dunedaq::datahandlinglibs::DataMoveCallbackRegistry::m_callback_map
std::map< std::string, std::shared_ptr< CallbackConcept > > m_callback_map
Definition
DataMoveCallbackRegistry.hpp:92
dunedaq::datahandlinglibs::DataMoveCallbackRegistry::get_callback
std::shared_ptr< std::function< void(DataType &&)> > get_callback(const appmodel::DataMoveCallbackConf *conf)
Gets the callback function registered with the given configuration.
Definition
DataMoveCallbackRegistry.hxx:26
dunedaq::datahandlinglibs::DataMoveCallbackRegistry::m_mutex
std::mutex m_mutex
Definition
DataMoveCallbackRegistry.hpp:91
dunedaq::datahandlinglibs::DataMoveCallbackRegistry::register_callback
void register_callback(const appmodel::DataMoveCallbackConf *conf, std::function< void(DataType &&)> callback)
Registers a callback function with a configuration object.
Definition
DataMoveCallbackRegistry.hxx:11
dunedaq::datahandlinglibs::DataMoveCallback
Definition
DataMoveCallbackRegistry.hpp:39
dunedaq::datahandlinglibs::DataMoveCallback::DataMoveCallback
DataMoveCallback(std::string id, std::function< void(DataType &&)> callback)
Definition
DataMoveCallbackRegistry.hpp:41
TLOG
#define TLOG(...)
Definition
macro.hpp:21
dunedaq::datahandlinglibs
Definition
DataHandlingConcept.hpp:16
dunedaq
The DUNE-DAQ namespace.
Definition
cib_utilities.cpp:5
dunedaq::GenericConfigurationError
SourceID[" << sourceid << "] Command daqdataformats::SourceID Readout Initialization std::string initerror Configuration std::string conferror GenericConfigurationError
Definition
DataHandlingIssues.hpp:51
Generated on
for DUNE-DAQ by
1.18.0