artdaq  v2_02_03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
EventBuilderCore.hh
1 #ifndef artdaq_Application_MPI2_EventBuilderCore_hh
2 #define artdaq_Application_MPI2_EventBuilderCore_hh
3 
4 #include <string>
5 #include <atomic>
6 
7 #include "fhiclcpp/ParameterSet.h"
8 #include "canvas/Persistency/Provenance/RunID.h"
9 
10 #include "artdaq-utilities/Plugins/MetricManager.hh"
11 
12 #include "artdaq/DAQrate/DataReceiverManager.hh"
13 #include "artdaq/DAQrate/EventStore.hh"
14 #include "artdaq/Application/StatisticsHelper.hh"
15 
16 namespace artdaq
17 {
18  class EventBuilderCore;
19 }
20 
26 {
27 public:
28  static const std::string INPUT_FRAGMENTS_STAT_KEY;
29  static const std::string INPUT_WAIT_STAT_KEY;
30  static const std::string STORE_EVENT_WAIT_STAT_KEY;
31 
37  EventBuilderCore(int rank, std::string name);
38 
42  EventBuilderCore(EventBuilderCore const&) = delete;
43 
48 
54 
75  bool initialize(fhicl::ParameterSet const& pset);
76 
82  bool start(art::RunID id);
83 
88  bool stop();
89 
94  bool pause();
95 
100  bool resume();
101 
106  bool shutdown();
107 
113  bool soft_initialize(fhicl::ParameterSet const& pset);
114 
120  bool reinitialize(fhicl::ParameterSet const& pset);
121 
127  size_t process_fragments();
128 
140  std::string report(std::string const& which) const;
141 
142 private:
143  void initializeEventStore(fhicl::ParameterSet pset);
144 
145  std::string name_;
146 
147  std::string init_string_;
148  fhicl::ParameterSet previous_pset_;
149 
150  fhicl::ParameterSet data_pset_;
151  size_t expected_fragments_per_event_;
152  size_t eod_fragments_received_;
153  bool use_art_;
154  art::RunID run_id_;
155 
156  std::unique_ptr<artdaq::DataReceiverManager> receiver_ptr_;
157  std::unique_ptr<artdaq::EventStore> event_store_ptr_;
158  bool art_initialized_;
159  std::atomic<bool> stop_requested_;
160  std::atomic<bool> pause_requested_;
161  std::atomic<bool> run_is_paused_;
162  std::atomic<bool> processing_fragments_;
163  size_t inrun_recv_timeout_usec_;
164  size_t endrun_recv_timeout_usec_;
165  size_t pause_recv_timeout_usec_;
166  bool verbose_;
167 
168  size_t fragment_count_in_run_;
169 
170  /* This is used for syncronization between the thread running
171  process_fragments() and XMLRPC calls. This will be locked before data
172  readout begins by the start() and resume() methods in the event builder.
173  It will be unlocked by the process_fragments() thread once EOD fragments
174  and all data has been received. The stop() and pause() methods will
175  attempt to lock the mutex as well and will be blocked until all data has
176  been clocked into the EventBuilderCore. */
177  std::mutex flush_mutex_;
178 
179  // attributes and methods for statistics gathering & reporting
180  artdaq::StatisticsHelper statsHelper_;
181 
182  std::string buildStatisticsString_();
183 
184  artdaq::MetricManager metricMan_;
185 
186  void sendMetrics_();
187 
188  void logMessage_(std::string const& text);
189 };
190 
191 #endif /* artdaq_Application_MPI2_EventBuilderCore_hh */
This class manages MonitoredQuantity instances for the *Core classes.
std::string report(std::string const &which) const
Send a report on a given run-time quantity.
static const std::string INPUT_FRAGMENTS_STAT_KEY
Key for the Input Fragments MonitoredQuantity.
bool resume()
Resumes the EventBuilderCore.
bool initialize(fhicl::ParameterSet const &pset)
Processes the initialize request.
static const std::string STORE_EVENT_WAIT_STAT_KEY
Key for the Store Event Wait MonitoredQuantity.
static const std::string INPUT_WAIT_STAT_KEY
Key for the Input Wait MonitoredQuantity.
EventBuilderCore(int rank, std::string name)
EventBuilderCore Constructor.
size_t process_fragments()
The main loop of the EventBuilderCore. Receives Fragment objects from DataReceiverManager and enqueue...
bool start(art::RunID id)
Start the EventBuilderCore.
bool stop()
Stops the EventBuilderCore.
bool pause()
Pauses the EventBuilderCore.
bool reinitialize(fhicl::ParameterSet const &pset)
Reinitializes the EventBuilderCore.
EventBuilderCore implements the state machine for the EventBuilder artdaq application. EventBuilderCore receives Fragment objects from the DataReceiverManager, and sends them to the EventStore.
bool shutdown()
Shuts Down the EventBuilderCore.
bool soft_initialize(fhicl::ParameterSet const &pset)
Soft-Initializes the EventBuilderCore. No-Op.
EventBuilderCore & operator=(EventBuilderCore const &)=delete
Copy Assignment operator is deleted.