DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
FileReaderBase.hxx
Go to the documentation of this file.
1
5
6namespace dunedaq {
7namespace snbmodules {
8
9FileReaderBase::FileReaderBase(const std::string& name)
10 : m_configured(false)
11 , m_name(name)
12 , m_run_marker{ false }
13{
14}
15
16void
17FileReaderBase::init(std::shared_ptr<appfwk::ConfigurationManager> cfg)
18{
19 m_cfg = cfg;
21 << get_fcr_name() << ": Entering init() method";
22 // auto ini = args.get<appfwk::app::ModInit>();
23 auto ini = cfg->get_dal<appmodel::DataReaderModule>(m_name);
24 if (ini != nullptr && ini->get_configuration()->get_emulation_mode()) {
25
26 for (auto cb : ini->get_raw_data_callbacks()) {
27
28 try {
29 if (m_source_emus.find(cb->UID()) != m_source_emus.end()) {
30 TLOG() << get_fcr_name() << "Same queue instance used twice";
31 throw datahandlinglibs::FailedFakeCardInitialization(ERS_HERE, get_fcr_name(), "");
32 }
34 if (m_source_emus[cb->UID()].get() == nullptr) {
35 TLOG() << get_fcr_name() << "Source emulator could not be created";
36 throw datahandlinglibs::FailedFakeCardInitialization(ERS_HERE, get_fcr_name(), "");
37 }
38 // m_source_emus[qi->UID()]->init(cfg);
39 } catch (const ers::Issue& excpt) {
40 throw datahandlinglibs::ResourceQueueError(ERS_HERE, cb->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& cb : cfg->get_raw_data_callbacks()) {
68 if (m_source_emus.find(cb->UID()) == m_source_emus.end()) {
69 TLOG() << "Cannot find queue: " << cb->UID() << std::endl;
70 throw datahandlinglibs::GenericConfigurationError(ERS_HERE, "Cannot find queue: " + cb->UID());
71 }
72 if (m_source_emus[cb->UID()]->is_configured()) {
73 TLOG() << "Emulator for queue name " << cb->UID() << " was already configured";
74 throw datahandlinglibs::GenericConfigurationError(ERS_HERE, "Emulator configured twice: " + cb->UID());
75 }
76 m_source_emus[cb->UID()]->set_sender(cb);
77 m_source_emus[cb->UID()]->conf(streams[cb->get_source_id()],
78 cfg->get_configuration()->get_snb_conf());
79 }
80 for (auto& [name, emu] : m_source_emus) {
81 if (!emu->is_configured()) {
82 throw datahandlinglibs::GenericConfigurationError(ERS_HERE, "Not all links were configured");
83 }
84 }
85
86 // Mark configured
87 m_configured = true;
88 }
89
91 << get_fcr_name() << ": Exiting do_conf() method";
92}
93
94void
95FileReaderBase::do_scrap(const appfwk::DAQModule::CommandData_t& args)
96{
98 << get_fcr_name() << ": Entering do_scrap() method";
99
100 for (auto& [name, emu] : m_source_emus) {
101 emu->scrap(args);
102 }
103
104 m_configured = false;
105
107 << get_fcr_name() << ": Exiting do_scrap() method";
108}
109void
110FileReaderBase::do_start(const appfwk::DAQModule::CommandData_t& args)
111{
113 << get_fcr_name() << ": Entering do_start() method";
114
115 m_run_marker.store(true);
116
117 for (auto& [name, emu] : m_source_emus) {
118 emu->start(args);
119 }
120
122 << get_fcr_name() << ": Exiting do_start() method";
123}
124
125void
126FileReaderBase::do_stop(const appfwk::DAQModule::CommandData_t& args)
127{
129 << get_fcr_name() << ": Entering do_stop() method";
130
131 m_run_marker = false;
132
133 for (auto& [name, emu] : m_source_emus) {
134 emu->stop(args);
135 }
136
138 << get_fcr_name() << ": Exiting do_stop() method";
139}
140
141} // namespace snbmodules
142} // namespace dunedaq
#define ERS_HERE
void do_scrap(const appfwk::DAQModule::CommandData_t &)
void init(std::shared_ptr< appfwk::ConfigurationManager > cfg)
virtual std::shared_ptr< snbmodules::FileSourceConcept > create_source_emulator(const appmodel::DataMoveCallbackConf *cb_conf, std::atomic< bool > &run_marker)=0
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 &)
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.