DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
FileReaderBase.hxx
Go to the documentation of this file.
1
4
5namespace dunedaq {
6namespace snbmodules {
7
8FileReaderBase::FileReaderBase(const std::string& name)
9 : m_configured(false)
10 , m_name(name)
11 , m_run_marker{ false }
12{
13}
14
15void
16FileReaderBase::init(std::shared_ptr<appfwk::ConfigurationManager> cfg)
17{
18 m_cfg = cfg;
20 << get_fcr_name() << ": Entering init() method";
21 // auto ini = args.get<appfwk::app::ModInit>();
22 auto ini = cfg->get_dal<appmodel::DataReaderModule>(m_name);
23 if (ini != nullptr && ini->get_configuration()->get_emulation_mode()) {
24
25 for (auto qi : ini->get_outputs()) {
26
27 try {
28 if (m_source_emus.find(qi->UID()) != m_source_emus.end()) {
29 TLOG() << get_fcr_name() << "Same queue instance used twice";
30 throw datahandlinglibs::FailedFakeCardInitialization(ERS_HERE, get_fcr_name(), "");
31 }
32 m_source_emus[qi->UID()] = create_source_emulator(qi->UID(), m_run_marker);
33 if (m_source_emus[qi->UID()].get() == nullptr) {
34 TLOG() << get_fcr_name() << "Source emulator could not be created";
35 throw datahandlinglibs::FailedFakeCardInitialization(ERS_HERE, get_fcr_name(), "");
36 }
37 // m_source_emus[qi->UID()]->init(cfg);
38 m_source_emus[qi->UID()]->set_sender(qi->UID());
39 } catch (const ers::Issue& excpt) {
40 throw datahandlinglibs::ResourceQueueError(ERS_HERE, qi->UID(), get_fcr_name(), excpt);
41 }
42 }
43 }
45 << get_fcr_name() << ": Exiting init() method";
46}
47
48void
49FileReaderBase::do_conf(const appfwk::DAQModule::CommandData_t& /*args*/)
50{
52 << get_fcr_name() << ": Entering do_conf() method";
53
54 if (m_configured) {
55 TLOG_DEBUG(dunedaq::datahandlinglibs::logging::TLVL_WORK_STEPS) << "This module is already configured!";
56 } else {
57 auto cfg = m_cfg->get_dal<appmodel::DataReaderModule>(get_fcr_name());
58
59 std::map<uint32_t, const confmodel::DetectorStream*> streams;
60 for (const auto& det_connections : cfg->get_connections()) {
61
62 for (const auto& stream : det_connections->streams()) {
63 streams[stream->get_source_id()] = stream;
64 }
65 }
66
67 for (const auto& qi : cfg->get_outputs()) {
68 auto q_with_id = qi->cast<confmodel::QueueWithSourceId>();
69 if (q_with_id == nullptr) {
70 throw datahandlinglibs::FailedFakeCardInitialization(
71 ERS_HERE, get_fcr_name(), "Queue is not of type QueueWithSourceId");
72 }
73 if (m_source_emus.find(q_with_id->UID()) == m_source_emus.end()) {
74 TLOG() << "Cannot find queue: " << q_with_id->UID() << std::endl;
75 throw datahandlinglibs::GenericConfigurationError(ERS_HERE, "Cannot find queue: " + q_with_id->UID());
76 }
77 if (m_source_emus[q_with_id->UID()]->is_configured()) {
78 TLOG() << "Emulator for queue name " << q_with_id->UID() << " was already configured";
79 throw datahandlinglibs::GenericConfigurationError(ERS_HERE, "Emulator configured twice: " + q_with_id->UID());
80 }
81 m_source_emus[q_with_id->UID()]->conf(streams[q_with_id->get_source_id()],
82 cfg->get_configuration()->get_snb_conf());
83 }
84 for (auto& [name, emu] : m_source_emus) {
85 if (!emu->is_configured()) {
86 throw datahandlinglibs::GenericConfigurationError(ERS_HERE, "Not all links were configured");
87 }
88 }
89
90 // Mark configured
91 m_configured = true;
92 }
93
95 << get_fcr_name() << ": Exiting do_conf() method";
96}
97
98void
99FileReaderBase::do_scrap(const appfwk::DAQModule::CommandData_t& args)
100{
102 << get_fcr_name() << ": Entering do_scrap() method";
103
104 for (auto& [name, emu] : m_source_emus) {
105 emu->scrap(args);
106 }
107
108 m_configured = false;
109
111 << get_fcr_name() << ": Exiting do_scrap() method";
112}
113void
114FileReaderBase::do_start(const appfwk::DAQModule::CommandData_t& args)
115{
117 << get_fcr_name() << ": Entering do_start() method";
118
119 m_run_marker.store(true);
120
121 for (auto& [name, emu] : m_source_emus) {
122 emu->start(args);
123 }
124
126 << get_fcr_name() << ": Exiting do_start() method";
127}
128
129void
130FileReaderBase::do_stop(const appfwk::DAQModule::CommandData_t& args)
131{
133 << get_fcr_name() << ": Entering do_stop() method";
134
135 m_run_marker = false;
136
137 for (auto& [name, emu] : m_source_emus) {
138 emu->stop(args);
139 }
140
142 << get_fcr_name() << ": Exiting do_stop() method";
143}
144
145} // namespace snbmodules
146} // namespace dunedaq
#define ERS_HERE
void do_scrap(const appfwk::DAQModule::CommandData_t &)
void init(std::shared_ptr< appfwk::ConfigurationManager > cfg)
void do_stop(const appfwk::DAQModule::CommandData_t &)
std::shared_ptr< appfwk::ConfigurationManager > m_cfg
void do_conf(const appfwk::DAQModule::CommandData_t &)
FileReaderBase(const std::string &name)
FileReaderBase Constructor.
std::map< std::string, std::shared_ptr< snbmodules::FileSourceConcept > > m_source_emus
void do_start(const appfwk::DAQModule::CommandData_t &)
virtual std::shared_ptr< snbmodules::FileSourceConcept > 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
The DUNE-DAQ namespace.