Line data Source code
1 : /**
2 : * @file SNBFileReaderModule.cpp SNBFileReaderModule class implementation
3 : *
4 : * This is part of the DUNE DAQ , copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 : #include "SNBFileReaderModule.hpp"
9 :
10 : // #include "appfwk/app/Nljs.hpp"
11 : // #include "appfwk/cmd/Nljs.hpp"
12 : #include "logging/Logging.hpp"
13 :
14 : #include "datahandlinglibs/DataHandlingIssues.hpp"
15 : #include "datahandlinglibs/ReadoutLogging.hpp"
16 : // #include "snbmodules/sourceemulatorconfig/Nljs.hpp"
17 : #include "appmodel/DataReaderModule.hpp"
18 : #include "snbmodules/readout/FileSourceModel.hpp"
19 :
20 : // #include "fdreadoutlibs/DUNEWIBSuperChunkTypeAdapter.hpp"
21 : #include "fdreadoutlibs/CRTBernTypeAdapter.hpp"
22 : #include "fdreadoutlibs/CRTGrenobleTypeAdapter.hpp"
23 : #include "fdreadoutlibs/DAPHNEStreamSuperChunkTypeAdapter.hpp"
24 : #include "fdreadoutlibs/DAPHNESuperChunkTypeAdapter.hpp"
25 : #include "fdreadoutlibs/DUNEWIBEthTypeAdapter.hpp"
26 : #include "fdreadoutlibs/TDEEthTypeAdapter.hpp"
27 :
28 : #include <chrono>
29 : #include <fstream>
30 : #include <iomanip>
31 : #include <limits>
32 : #include <memory>
33 : #include <sstream>
34 : #include <string>
35 : #include <utility>
36 : #include <vector>
37 :
38 : using namespace dunedaq::datahandlinglibs::logging;
39 :
40 : namespace dunedaq {
41 :
42 : // DUNE_DAQ_TYPESTRING(dunedaq::fdreadoutlibs::types::DUNEWIBSuperChunkTypeAdapter, "WIB2Frame")
43 0 : DUNE_DAQ_TYPESTRING(dunedaq::fdreadoutlibs::types::DUNEWIBEthTypeAdapter, "WIBEthFrame")
44 0 : DUNE_DAQ_TYPESTRING(dunedaq::fdreadoutlibs::types::DAPHNESuperChunkTypeAdapter, "PDSFrame")
45 0 : DUNE_DAQ_TYPESTRING(dunedaq::fdreadoutlibs::types::DAPHNEStreamSuperChunkTypeAdapter, "PDSStreamFrame")
46 0 : DUNE_DAQ_TYPESTRING(dunedaq::fdreadoutlibs::types::TDEEthTypeAdapter, "TDEEthFrame")
47 0 : DUNE_DAQ_TYPESTRING(dunedaq::fdreadoutlibs::types::CRTBernTypeAdapter, "CRTBernFrame")
48 0 : DUNE_DAQ_TYPESTRING(dunedaq::fdreadoutlibs::types::CRTGrenobleTypeAdapter, "CRTGrenobleFrame")
49 :
50 : namespace fdreadoutmodules {
51 :
52 0 : SNBFileReaderModule::SNBFileReaderModule(const std::string& name)
53 : : DAQModule(name)
54 0 : , FileReaderBase(name)
55 : {
56 0 : inherited_mod::register_command("conf", &inherited_fcr::do_conf);
57 0 : inherited_mod::register_command("scrap", &inherited_fcr::do_scrap);
58 0 : inherited_mod::register_command("start", &inherited_fcr::do_start);
59 0 : inherited_mod::register_command("stop_trigger_sources", &inherited_fcr::do_stop);
60 0 : }
61 :
62 : void
63 0 : SNBFileReaderModule::init(std::shared_ptr<appfwk::ConfigurationManager> cfg)
64 : {
65 0 : TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << get_name() << ": Entering init() method";
66 0 : inherited_fcr::init(cfg);
67 0 : TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << get_name() << ": Exiting init() method";
68 0 : }
69 :
70 : std::shared_ptr<snbmodules::FileSourceConcept>
71 0 : SNBFileReaderModule::create_source_emulator(std::string q_id, std::atomic<bool>& run_marker)
72 : {
73 : //! Values suitable to emulation
74 :
75 0 : static constexpr int daphnestream_time_tick_diff =
76 : fdreadoutlibs::types::DAPHNEStreamSuperChunkTypeAdapter::expected_tick_difference;
77 0 : static constexpr double daphnestream_rate_khz =
78 : 62500. / daphnestream_time_tick_diff / fdreadoutlibs::types::kDAPHNEStreamNumFrames;
79 :
80 0 : static constexpr int daphne_time_tick_diff =
81 : fdreadoutlibs::types::DAPHNESuperChunkTypeAdapter::expected_tick_difference;
82 0 : static constexpr double daphne_rate_khz = 62500. / daphne_time_tick_diff / fdreadoutlibs::types::kDAPHNENumFrames;
83 :
84 0 : static constexpr int wibeth_time_tick_diff = fdreadoutlibs::types::DUNEWIBEthTypeAdapter::expected_tick_difference;
85 0 : static constexpr double wibeth_rate_khz = 62500. / wibeth_time_tick_diff;
86 :
87 0 : static constexpr int tdeeth_time_tick_diff = fdreadoutlibs::types::TDEEthTypeAdapter::expected_tick_difference;
88 0 : static constexpr double tdeeth_rate_khz = 62500. / tdeeth_time_tick_diff;
89 0 : static constexpr double crtbern_rate_khz = 100;
90 0 : static constexpr double crtgrenoble_rate_khz = 100;
91 :
92 0 : auto datatypes = dunedaq::iomanager::IOManager::get()->get_datatypes(q_id);
93 0 : if (datatypes.size() != 1) {
94 0 : ers::error(dunedaq::datahandlinglibs::GenericConfigurationError(
95 0 : ERS_HERE, "Multiple output data types specified! Expected only a single type!"));
96 : }
97 0 : std::string raw_dt{ *datatypes.begin() };
98 0 : TLOG() << "Choosing specialization for SourceEmulator with raw_input" << " [uid:" << q_id << " , data_type:" << raw_dt
99 0 : << ']';
100 :
101 : // IF WIBETH
102 0 : if (raw_dt.find("WIBEthFrame") != std::string::npos) {
103 0 : TLOG_DEBUG(TLVL_WORK_STEPS) << "Creating fake wibeth link";
104 0 : auto source_emu_model = std::make_shared<snbmodules::FileSourceModel<fdreadoutlibs::types::DUNEWIBEthTypeAdapter>>(
105 0 : q_id, run_marker, wibeth_rate_khz);
106 0 : register_node(q_id, source_emu_model);
107 0 : return source_emu_model;
108 0 : }
109 :
110 : // IF PDS
111 0 : if (raw_dt.find("PDSFrame") != std::string::npos) {
112 0 : TLOG_DEBUG(TLVL_WORK_STEPS) << "Creating fake pds link";
113 0 : auto source_emu_model =
114 : std::make_shared<snbmodules::FileSourceModel<fdreadoutlibs::types::DAPHNESuperChunkTypeAdapter>>(
115 0 : q_id, run_marker, daphne_rate_khz);
116 0 : register_node(q_id, source_emu_model);
117 0 : return source_emu_model;
118 0 : }
119 :
120 : // IF PDSStream
121 0 : if (raw_dt.find("PDSStreamFrame") != std::string::npos) {
122 0 : TLOG_DEBUG(TLVL_WORK_STEPS) << "Creating fake pds stream link";
123 0 : auto source_emu_model =
124 : std::make_shared<snbmodules::FileSourceModel<fdreadoutlibs::types::DAPHNEStreamSuperChunkTypeAdapter>>(
125 0 : q_id, run_marker, daphnestream_rate_khz);
126 0 : register_node(q_id, source_emu_model);
127 0 : return source_emu_model;
128 0 : }
129 :
130 : // IF TDEEth
131 0 : if (raw_dt.find("TDEEthFrame") != std::string::npos) {
132 0 : TLOG_DEBUG(TLVL_WORK_STEPS) << "Creating fake tde link";
133 0 : auto source_emu_model = std::make_shared<snbmodules::FileSourceModel<fdreadoutlibs::types::TDEEthTypeAdapter>>(
134 0 : q_id, run_marker, tdeeth_rate_khz);
135 0 : register_node(q_id, source_emu_model);
136 0 : return source_emu_model;
137 0 : }
138 :
139 : // IF CRTBern
140 0 : if (raw_dt.find("CRTBernFrame") != std::string::npos) {
141 0 : TLOG_DEBUG(TLVL_WORK_STEPS) << "Creating fake crt bern link";
142 0 : auto source_emu_model = std::make_shared<snbmodules::FileSourceModel<fdreadoutlibs::types::CRTBernTypeAdapter>>(
143 0 : q_id, run_marker, crtbern_rate_khz);
144 0 : register_node(q_id, source_emu_model);
145 0 : return source_emu_model;
146 0 : }
147 :
148 : // IF CRTGrenoble
149 0 : if (raw_dt.find("CRTGrenobleFrame") != std::string::npos) {
150 0 : TLOG_DEBUG(TLVL_WORK_STEPS) << "Creating fake crt grenoble link";
151 0 : auto source_emu_model = std::make_shared<snbmodules::FileSourceModel<fdreadoutlibs::types::CRTGrenobleTypeAdapter>>(
152 0 : q_id, run_marker, crtgrenoble_rate_khz);
153 0 : register_node(q_id, source_emu_model);
154 0 : return source_emu_model;
155 0 : }
156 :
157 0 : return nullptr;
158 0 : }
159 :
160 : } // namespace fdreadoutmodules
161 : } // namespace dunedaq
162 :
163 0 : DEFINE_DUNE_DAQ_MODULE(dunedaq::fdreadoutmodules::SNBFileReaderModule)
|