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, std::function<
void
(DataType&&)> callback)
12
{
13
std::lock_guard<std::mutex> guard(
m_mutex
);
14
std::string
id
= conf->
UID
();
15
if
(
m_callback_map
.count(
id
) == 0) {
16
TLOG
() <<
"Registering DataMoveCallback with ID: "
<< id;
17
m_callback_map
[id] = std::make_shared<DataMoveCallback<DataType>>(
DataMoveCallback
(
id
, callback));
18
}
else
{
19
TLOG
() <<
"Callback is already registered with ID: "
<<
id
<<
" Ignoring this registration."
;
20
}
21
}
22
23
template
<
typename
DataType>
24
inline
std::shared_ptr<std::function<void(DataType&&)>>
25
DataMoveCallbackRegistry::get_callback
(
const
appmodel::DataMoveCallbackConf
* conf)
26
{
27
std::lock_guard<std::mutex> guard(
m_mutex
);
28
std::string
id
= conf->
UID
();
29
if
(
m_callback_map
.contains(
id
)) {
30
TLOG
() <<
"Providing DataMoveCallback with ID: "
<< id;
31
if
(
auto
callback =
dynamic_cast<
DataMoveCallback<DataType>
*
>
(
m_callback_map
[
id
].
get
()); callback !=
nullptr
) {
32
return
callback->m_callback;
33
}
else
{
34
// As this can happen due to a very bad config error and wherever the acquire is called will lead to undefined
35
// behavior
36
throw
GenericConfigurationError
(
37
ERS_HERE
,
38
std::format(
"Callback cast failed for function signature with datatypes (expected vs. registered) : {} vs. {}"
,
39
typeid
(
DataMoveCallback<DataType>
).name(),
40
typeid
(*
m_callback_map
[
id
]).name()));
41
}
42
}
else
{
43
TLOG
() <<
"No callback registered with ID: "
<<
id
<<
" Returning nullptr."
;
44
return
nullptr
;
45
}
46
}
47
}
48
}
DataHandlingIssues.hpp
ERS_HERE
#define ERS_HERE
Definition
LocalContext.hpp:141
dunedaq::appmodel::DataMoveCallbackConf
Definition
DataMoveCallbackConf.hpp:20
dunedaq::conffwk::DalObject::UID
const std::string & UID() const noexcept
Definition
DalObject.hpp:135
dunedaq::datahandlinglibs::DataMoveCallbackRegistry::get
static std::shared_ptr< DataMoveCallbackRegistry > get()
Definition
DataMoveCallbackRegistry.hpp:50
dunedaq::datahandlinglibs::DataMoveCallbackRegistry::m_callback_map
std::map< std::string, std::shared_ptr< CallbackConcept > > m_callback_map
Definition
DataMoveCallbackRegistry.hpp:89
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:25
dunedaq::datahandlinglibs::DataMoveCallbackRegistry::m_mutex
std::mutex m_mutex
Definition
DataMoveCallbackRegistry.hpp:88
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:37
TLOG
#define TLOG(...)
Definition
macro.hpp:22
dunedaq::datahandlinglibs
Definition
DataHandlingConcept.hpp:16
dunedaq
Including Qt Headers.
Definition
module.cpp:16
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.17.0