Line data Source code
1 : /**
2 : * @file TPReplayModule.hpp
3 : *
4 : * TPReplayModule is a DAQModule for replaying trigger primitives in the system.
5 : *
6 : * This is part of the DUNE DAQ Application Framework, copyright 2020.
7 : * Licensing/copyright details are in the COPYING file that you should have
8 : * received with this code.
9 : */
10 :
11 : #ifndef TRIGGER_PLUGINS_TPREPLAYMODULE_HPP_
12 : #define TRIGGER_PLUGINS_TPREPLAYMODULE_HPP_
13 :
14 : #include "trigger/TPSet.hpp"
15 : #include "trigger/TriggerPrimitiveTypeAdapter.hpp"
16 : #include "trigger/opmon/tpreplaymodule_info.pb.h"
17 :
18 : #include "appmodel/TPReplayModule.hpp"
19 : #include "appmodel/TPReplayModuleConf.hpp"
20 : #include "appmodel/TPStreamConf.hpp"
21 :
22 : #include "appfwk/ConfigurationManager.hpp"
23 : #include "appfwk/DAQModule.hpp"
24 : #include "confmodel/Connection.hpp"
25 : #include "confmodel/DetectorConfig.hpp"
26 : #include "confmodel/Session.hpp"
27 :
28 : #include "daqdataformats/SourceID.hpp"
29 : #include "detchannelmaps/TPCChannelMap.hpp"
30 : #include "detdataformats/DetID.hpp"
31 : #include "hdf5libs/HDF5RawDataFile.hpp"
32 : #include "iomanager/Sender.hpp"
33 : #include "triggeralgs/TriggerPrimitive.hpp"
34 : #include "triggeralgs/Types.hpp"
35 : #include "utilities/WorkerThread.hpp"
36 :
37 : #include <memory>
38 : #include <string>
39 : #include <vector>
40 :
41 : using TriggerPrimitive = dunedaq::trgdataformats::TriggerPrimitive;
42 :
43 : DUNE_DAQ_TYPESTRING(dunedaq::trigger::TriggerPrimitiveTypeAdapter, "TriggerPrimitive")
44 0 : DUNE_DAQ_TYPESTRING(std::vector<dunedaq::trigger::TriggerPrimitiveTypeAdapter>, "TriggerPrimitiveVector")
45 :
46 : namespace dunedaq {
47 : namespace trigger {
48 : class TPReplayModule : public dunedaq::appfwk::DAQModule
49 : {
50 : public:
51 : /**
52 : * @brief TPReplayModule Constructor
53 : * @param name Instance name for this TPReplayModule instance
54 : */
55 : explicit TPReplayModule(const std::string& name);
56 :
57 : TPReplayModule(const TPReplayModule&) = delete; ///< TPReplayModule is not copy-constructible
58 : TPReplayModule& operator=(const TPReplayModule&) = delete; ///< TPReplayModule is not copy-assignable
59 : TPReplayModule(TPReplayModule&&) = delete; ///< TPReplayModule is not move-constructible
60 : TPReplayModule& operator=(TPReplayModule&&) = delete; ///< TPReplayModule is not move-assignable
61 :
62 : void init(std::shared_ptr<appfwk::ConfigurationManager> mcfg) override;
63 : void generate_opmon_data() override;
64 :
65 : private:
66 : // Commands
67 : void do_configure(const CommandData_t& /*obj*/);
68 : void do_start(const CommandData_t& obj);
69 : void do_stop(const CommandData_t& obj);
70 : void do_scrap(const CommandData_t& obj);
71 :
72 : // Threading
73 : void do_work(std::atomic<bool>&,
74 : std::deque<std::vector<TriggerPrimitiveTypeAdapter>>& tpvs,
75 : std::shared_ptr<iomanager::SenderConcept<std::vector<trigger::TriggerPrimitiveTypeAdapter>>>& tp_sink,
76 : std::chrono::steady_clock::time_point earliest_timestamp_time);
77 : std::vector<std::unique_ptr<std::thread>> m_threads;
78 : std::atomic<bool> m_running_flag;
79 :
80 : // TP streams
81 : struct TPStream
82 : {
83 : std::shared_ptr<iomanager::SenderConcept<std::vector<trigger::TriggerPrimitiveTypeAdapter>>> tp_sink;
84 : std::deque<std::vector<TriggerPrimitiveTypeAdapter>>& tpvs; // use ref for mem optimization
85 : };
86 : std::vector<TPStream> m_tp_streams;
87 : std::map<int, std::string> m_tpstream_files;
88 : triggeralgs::timestamp_t m_earliest_first_tp_timestamp;
89 : triggeralgs::timestamp_t m_latest_last_tp_timestamp;
90 :
91 : // TP data
92 : std::map<std::string, std::map<int, std::deque<std::vector<TriggerPrimitiveTypeAdapter>>>> read_tps(
93 : std::map<int, std::string>);
94 : // ROU plane vectors of TPs (one per frag)
95 : std::map<std::string, std::map<int, std::deque<std::vector<TriggerPrimitiveTypeAdapter>>>> m_all_tp_data;
96 :
97 : // Configuration
98 : const appmodel::TPReplayModule* m_mtrg;
99 : const appmodel::TPReplayModuleConf* m_conf;
100 : double m_clocks_per_us;
101 : int m_loops;
102 : std::chrono::milliseconds m_queue_timeout;
103 : std::chrono::steady_clock::time_point m_run_start_time;
104 :
105 : // Channel maps, plane related
106 : std::string m_channel_map_name;
107 : std::shared_ptr<detchannelmaps::TPCChannelMap> m_channel_map;
108 : bool m_filter_planes;
109 : std::set<int> m_filter_planes_ids;
110 : std::unordered_set<detdataformats::DetID::Subdetector> m_validSubdetectors;
111 :
112 : // opmon
113 : using metric_counter_type = uint64_t;
114 : std::atomic<metric_counter_type> m_tp_made_count;
115 : std::atomic<metric_counter_type> m_tpv_made_count;
116 : std::atomic<metric_counter_type> m_tpv_failed_sent_count;
117 : };
118 : } // namespace trigger
119 : } // namespace dunedaq
120 :
121 : #endif // TRIGGER_PLUGINS_TPREPLAYMODULE_HPP_
|