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 //auto ini = args.get<appfwk::app::ModInit>();
17 auto ini = cfg->get_dal<appmodel::DataReaderModule>(m_name);
18 if (ini != nullptr && ini->get_configuration()->get_emulation_mode()) {
19
20 for (auto cb : ini->get_raw_data_callbacks()) {
21
22 try {
23 if (m_source_emus.find(cb->UID()) != m_source_emus.end()) {
24 TLOG() << get_fcr_name() << "Same callback instance used twice";
25 throw datahandlinglibs::FailedFakeCardInitialization(ERS_HERE, get_fcr_name(), "");
26 }
28 if (m_source_emus[cb->UID()].get() == nullptr) {
29 TLOG() << get_fcr_name() << "Source emulator could not be created";
30 throw datahandlinglibs::FailedFakeCardInitialization(ERS_HERE, get_fcr_name(), "");
31 }
32 // m_source_emus[cb->UID()]->init(cfg);
33 } catch (const ers::Issue& excpt) {
34 throw datahandlinglibs::ResourceQueueError(ERS_HERE, cb->UID(), get_fcr_name(), excpt);
35 }
36 }
37 }
39}
40
41void
42FakeCardReaderBase::do_conf(const appfwk::DAQModule::CommandData_t& /*args*/)
43{
45
46 if (m_configured) {
47 TLOG_DEBUG(dunedaq::datahandlinglibs::logging::TLVL_WORK_STEPS) << "This module is already configured!";
48 } else {
49 auto cfg = m_cfg->get_dal<appmodel::DataReaderModule>(get_fcr_name());
50
51 std::map<uint32_t, const confmodel::DetectorStream*> streams;
52 for (const auto & det_connections : cfg->get_connections()) {
53
54 for (const auto& stream : det_connections->streams()) {
55 streams[stream->get_source_id()] = stream;
56 }
57 }
58
59 for (const auto& cb : cfg->get_raw_data_callbacks()) {
60 if (m_source_emus.find(cb->UID()) == m_source_emus.end()) {
61 TLOG() << "Cannot find queue: " << cb->UID() << std::endl;
62 throw datahandlinglibs::GenericConfigurationError(ERS_HERE, "Cannot find queue: " + cb->UID());
63 }
64 if (m_source_emus[cb->UID()]->is_configured()) {
65 TLOG() << "Emulator for queue name " << cb->UID() << " was already configured";
66 throw datahandlinglibs::GenericConfigurationError(ERS_HERE, "Emulator configured twice: " + cb->UID());
67 }
68 m_source_emus[cb->UID()]->set_sender(cb);
69 m_source_emus[cb->UID()]->conf(streams[cb->get_source_id()],
70 cfg->get_configuration()->get_emulation_conf());
71 }
72 for (auto& [name, emu] : m_source_emus) {
73 if (!emu->is_configured()) {
74 throw datahandlinglibs::GenericConfigurationError(ERS_HERE, "Not all links were configured");
75 }
76 }
77
78 // Mark configured
79 m_configured = true;
80 }
81
83}
84
85void
86FakeCardReaderBase::do_scrap(const appfwk::DAQModule::CommandData_t& args)
87{
89
90 for (auto& [name, emu] : m_source_emus) {
91 emu->scrap(args);
92 }
93
94 m_configured = false;
95
97}
98void
99FakeCardReaderBase::do_start(const appfwk::DAQModule::CommandData_t& args)
100{
102
103 m_run_marker.store(true);
104
105 for (auto& [name, emu] : m_source_emus) {
106 emu->start(args);
107 }
108
110}
111
112void
113FakeCardReaderBase::do_stop(const appfwk::DAQModule::CommandData_t& args)
114{
116
117 m_run_marker = false;
118
119 for (auto& [name, emu] : m_source_emus) {
120 emu->stop(args);
121 }
122
124}
125
126} // namespace datahandlinglibs
127} // namespace dunedaq
128
#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:69
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
#define TLOG(...)
Definition macro.hpp:22
Including Qt Headers.