DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
FakeCardReaderBase.hxx
Go to the documentation of this file.
1namespace dunedaq {
2namespace datahandlinglibs {
3
5 : m_configured(false)
6 , m_name(name)
7 , m_run_marker{ false }
8{
9}
10
11void
12FakeCardReaderBase::init(std::shared_ptr<appfwk::ConfigurationManager> cfg)
13{
14 m_cfg = cfg;
16 << get_fcr_name() << ": Entering init() method";
17 // auto ini = args.get<appfwk::app::ModInit>();
18 auto ini = cfg->get_dal<appmodel::DataReaderModule>(m_name);
19 if (ini != nullptr && ini->get_configuration()->get_emulation_mode()) {
20
21 for (auto cb : ini->get_raw_data_callbacks()) {
22
23 try {
24 if (m_source_emus.find(cb->UID()) != m_source_emus.end()) {
25 TLOG() << get_fcr_name() << "Same callback instance used twice";
26 throw datahandlinglibs::FailedFakeCardInitialization(ERS_HERE, get_fcr_name(), "");
27 }
29 if (m_source_emus[cb->UID()].get() == nullptr) {
30 TLOG() << get_fcr_name() << "Source emulator could not be created";
31 throw datahandlinglibs::FailedFakeCardInitialization(ERS_HERE, get_fcr_name(), "");
32 }
33 // m_source_emus[cb->UID()]->init(cfg);
34 } catch (const ers::Issue& excpt) {
35 throw datahandlinglibs::ResourceQueueError(ERS_HERE, cb->UID(), get_fcr_name(), excpt);
36 }
37 }
38 }
40 << get_fcr_name() << ": Exiting init() method";
41}
42
43void
44FakeCardReaderBase::do_conf(const appfwk::DAQModule::CommandData_t& /*args*/)
45{
47 << get_fcr_name() << ": Entering do_conf() method";
48
49 if (m_configured) {
50 TLOG_DEBUG(dunedaq::datahandlinglibs::logging::TLVL_WORK_STEPS) << "This module is already configured!";
51 } else {
52 auto cfg = m_cfg->get_dal<appmodel::DataReaderModule>(get_fcr_name());
53
54 std::map<uint32_t, const confmodel::DetectorStream*> streams;
55 for (const auto& det_connections : cfg->get_connections()) {
56
57 for (const auto& stream : det_connections->streams()) {
58 streams[stream->get_source_id()] = stream;
59 }
60 }
61
62 for (const auto& cb : cfg->get_raw_data_callbacks()) {
63 if (m_source_emus.find(cb->UID()) == m_source_emus.end()) {
64 TLOG() << "Cannot find queue: " << cb->UID() << std::endl;
65 throw datahandlinglibs::GenericConfigurationError(ERS_HERE, "Cannot find queue: " + cb->UID());
66 }
67 if (m_source_emus[cb->UID()]->is_configured()) {
68 TLOG() << "Emulator for queue name " << cb->UID() << " was already configured";
69 throw datahandlinglibs::GenericConfigurationError(ERS_HERE, "Emulator configured twice: " + cb->UID());
70 }
71 m_source_emus[cb->UID()]->set_sink_config(cb);
72 m_source_emus[cb->UID()]->conf(streams[cb->get_source_id()], cfg->get_configuration()->get_emulation_conf());
73 }
74 for (auto& [name, emu] : m_source_emus) {
75 if (!emu->is_configured()) {
76 throw datahandlinglibs::GenericConfigurationError(ERS_HERE, "Not all links were configured");
77 }
78 }
79
80 // Mark configured
81 m_configured = true;
82 }
83
85 << get_fcr_name() << ": Exiting do_conf() method";
86}
87
88void
89FakeCardReaderBase::do_scrap(const appfwk::DAQModule::CommandData_t& args)
90{
92 << get_fcr_name() << ": Entering do_scrap() method";
93
94 for (auto& [name, emu] : m_source_emus) {
95 emu->scrap(args);
96 }
97
98 m_configured = false;
99
101 << get_fcr_name() << ": Exiting do_scrap() method";
102}
103void
104FakeCardReaderBase::do_start(const appfwk::DAQModule::CommandData_t& args)
105{
107 << get_fcr_name() << ": Entering do_start() method";
108
109 m_run_marker.store(true);
110
111 for (auto& [name, emu] : m_source_emus) {
112 emu->acquire_callback();
113 emu->start(args);
114 }
115
117 << get_fcr_name() << ": Exiting do_start() method";
118}
119
120void
121FakeCardReaderBase::do_stop(const appfwk::DAQModule::CommandData_t& args)
122{
124 << get_fcr_name() << ": Entering do_stop() method";
125
126 m_run_marker = false;
127
128 for (auto& [name, emu] : m_source_emus) {
129 emu->stop(args);
130 }
131
133 << get_fcr_name() << ": Exiting do_stop() method";
134}
135
136} // namespace datahandlinglibs
137} // namespace dunedaq
#define ERS_HERE
void init(std::shared_ptr< appfwk::ConfigurationManager > cfg)
void do_stop(const appfwk::DAQModule::CommandData_t &)
void do_scrap(const appfwk::DAQModule::CommandData_t &)
void do_conf(const appfwk::DAQModule::CommandData_t &)
std::map< std::string, std::shared_ptr< datahandlinglibs::SourceEmulatorConcept > > m_source_emus
virtual std::shared_ptr< datahandlinglibs::SourceEmulatorConcept > create_source_emulator(const appmodel::DataMoveCallbackConf *cb, std::atomic< bool > &run_marker)=0
std::shared_ptr< appfwk::ConfigurationManager > m_cfg
FakeCardReaderBase(const std::string &name)
FakeCardReaderBase Constructor.
void do_start(const appfwk::DAQModule::CommandData_t &)
Base class for any user define issue.
Definition Issue.hpp:76
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:116
#define TLOG(...)
Definition macro.hpp:21
The DUNE-DAQ namespace.