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 qi : ini->get_outputs()) {
21
22 try {
23 if (m_source_emus.find(qi->UID()) != m_source_emus.end()) {
24 TLOG() << get_fcr_name() << "Same queue instance used twice";
25 throw datahandlinglibs::FailedFakeCardInitialization(ERS_HERE, get_fcr_name(), "");
26 }
27 m_source_emus[qi->UID()] = create_source_emulator(qi->UID(), m_run_marker);
28 if (m_source_emus[qi->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[qi->UID()]->init(cfg);
33 m_source_emus[qi->UID()]->set_sender(qi->UID());
34 } catch (const ers::Issue& excpt) {
35 throw datahandlinglibs::ResourceQueueError(ERS_HERE, qi->UID(), get_fcr_name(), excpt);
36 }
37 }
38 }
40}
41
42void
43FakeCardReaderBase::do_conf(const nlohmann::json& /*args*/)
44{
46
47 if (m_configured) {
48 TLOG_DEBUG(dunedaq::datahandlinglibs::logging::TLVL_WORK_STEPS) << "This module is already configured!";
49 } else {
50 auto cfg = m_cfg->get_dal<appmodel::DataReaderModule>(get_fcr_name());
51
52 std::map<uint32_t, const confmodel::DetectorStream*> streams;
53 for (const auto & det_connections : cfg->get_connections()) {
54
55 for (const auto& stream : det_connections->get_streams()) {
56 streams[stream->get_source_id()] = stream;
57 }
58 }
59
60 for (const auto& qi : cfg->get_outputs()) {
61 auto q_with_id = qi->cast<confmodel::QueueWithSourceId>();
62 if (q_with_id == nullptr) {
63 throw datahandlinglibs::FailedFakeCardInitialization(ERS_HERE, get_fcr_name(), "Queue is not of type QueueWithSourceId");
64 }
65 if (m_source_emus.find(q_with_id->UID()) == m_source_emus.end()) {
66 TLOG() << "Cannot find queue: " << q_with_id->UID() << std::endl;
67 throw datahandlinglibs::GenericConfigurationError(ERS_HERE, "Cannot find queue: " + q_with_id->UID());
68 }
69 if (m_source_emus[q_with_id->UID()]->is_configured()) {
70 TLOG() << "Emulator for queue name " << q_with_id->UID() << " was already configured";
71 throw datahandlinglibs::GenericConfigurationError(ERS_HERE, "Emulator configured twice: " + q_with_id->UID());
72 }
73 m_source_emus[q_with_id->UID()]->conf(streams[q_with_id->get_source_id()], cfg->get_configuration()->get_emulation_conf());
74 }
75 for (auto& [name, emu] : m_source_emus) {
76 if (!emu->is_configured()) {
77 throw datahandlinglibs::GenericConfigurationError(ERS_HERE, "Not all links were configured");
78 }
79 }
80
81 // Mark configured
82 m_configured = true;
83 }
84
86}
87
88void
89FakeCardReaderBase::do_scrap(const nlohmann::json& args)
90{
92
93 for (auto& [name, emu] : m_source_emus) {
94 emu->scrap(args);
95 }
96
97 m_configured = false;
98
100}
101void
102FakeCardReaderBase::do_start(const nlohmann::json& args)
103{
105
106 m_run_marker.store(true);
107
108 for (auto& [name, emu] : m_source_emus) {
109 emu->start(args);
110 }
111
113}
114
115void
116FakeCardReaderBase::do_stop(const nlohmann::json& args)
117{
119
120 m_run_marker = false;
121
122 for (auto& [name, emu] : m_source_emus) {
123 emu->stop(args);
124 }
125
127}
128
129} // namespace datahandlinglibs
130} // namespace dunedaq
131
#define ERS_HERE
void init(std::shared_ptr< appfwk::ConfigurationManager > cfg)
std::map< std::string, std::shared_ptr< datahandlinglibs::SourceEmulatorConcept > > m_source_emus
std::shared_ptr< appfwk::ConfigurationManager > m_cfg
FakeCardReaderBase(const std::string &name)
FakeCardReaderBase Constructor.
virtual std::shared_ptr< datahandlinglibs::SourceEmulatorConcept > create_source_emulator(std::string qi, std::atomic< bool > &run_marker)=0
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.