artdaq  v2_03_02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
AggregatorCore.hh
1 #ifndef artdaq_Application_MPI2_AggregatorCore_hh
2 #define artdaq_Application_MPI2_AggregatorCore_hh
3 
4 #include <string>
5 #include <vector>
6 #include <atomic>
7 #include <thread>
8 
9 #include "fhiclcpp/ParameterSet.h"
10 #include "canvas/Persistency/Provenance/RunID.h"
11 
12 #include "artdaq-core/Core/GlobalQueue.hh"
13 #include "artdaq-utilities/Plugins/MetricManager.hh"
14 
15 #include "artdaq/DAQrate/DataSenderManager.hh"
16 #include "artdaq/DAQrate/DataReceiverManager.hh"
17 #include "artdaq/DAQrate/EventStore.hh"
18 #include "artdaq/Application/StatisticsHelper.hh"
19 #include "artdaq/TransferPlugins/TransferInterface.hh"
20 
21 
22 namespace artdaq
23 {
24  class AggregatorCore;
25 }
26 
32 {
33 public:
34  static const std::string INPUT_EVENTS_STAT_KEY;
35  static const std::string INPUT_WAIT_STAT_KEY;
36  static const std::string STORE_EVENT_WAIT_STAT_KEY;
37  static const std::string SHM_COPY_TIME_STAT_KEY;
38  static const std::string FILE_CHECK_TIME_STAT_KEY;
39 
46  AggregatorCore(int rank, std::string name);
47 
51  AggregatorCore(AggregatorCore const&) = delete;
52 
57 
62  AggregatorCore& operator=(AggregatorCore const&) = delete;
63 
96  bool initialize(fhicl::ParameterSet const& pset);
97 
103  bool start(art::RunID id);
104 
109  bool stop();
110 
115  bool pause();
116 
121  bool resume();
122 
127  bool shutdown();
128 
134  bool soft_initialize(fhicl::ParameterSet const& pset);
135 
141  bool reinitialize(fhicl::ParameterSet const& pset);
142 
155  size_t process_fragments();
156 
171  std::string report(std::string const& which) const;
172 
180  std::string register_monitor(fhicl::ParameterSet const& pset);
181 
187  std::string unregister_monitor(std::string const& label);
188 
189 private:
190  std::string name_;
191  art::RunID run_id_;
192  bool art_initialized_;
193 
194  fhicl::ParameterSet data_pset_;
195  std::string init_string_;
196  size_t expected_events_per_bunch_;
197  size_t inrun_recv_timeout_usec_;
198  size_t endrun_recv_timeout_usec_;
199  size_t pause_recv_timeout_usec_;
200  size_t onmon_event_prescale_;
201  int32_t filesize_check_interval_seconds_;
202  int32_t filesize_check_interval_events_;
203  bool is_data_logger_;
204  bool is_online_monitor_;
205  bool is_dispatcher_;
206  artdaq::detail::seconds enq_timeout_;
207 
208  std::unique_ptr<artdaq::DataReceiverManager> receiver_ptr_;
209  std::unique_ptr<artdaq::DataSenderManager> sender_ptr_;
210  std::unique_ptr<artdaq::EventStore> event_store_ptr_;
211  artdaq::RawEventQueue& event_queue_;
212  fhicl::ParameterSet previous_pset_;
213  std::atomic<bool> stop_requested_;
214  std::atomic<bool> local_pause_requested_;
215  std::atomic<bool> processing_fragments_;
216 
217  size_t event_count_in_run_;
218  size_t event_count_in_subrun_;
219  time_t subrun_start_time_;
220  std::string disk_writing_directory_;
221 
222  size_t getLatestFileSize_() const;
223 
224  std::vector<std::vector<std::string>> xmlrpc_client_lists_;
225  size_t file_close_threshold_bytes_;
226  time_t file_close_timeout_secs_;
227  size_t file_close_event_count_;
228 
229  bool sendPauseAndResume_();
230 
231  std::atomic<bool> system_pause_requested_;
232  std::shared_ptr<std::thread> pause_thread_;
233 
234  void logMessage_(std::string const& text);
235 
236  artdaq::StatisticsHelper stats_helper_;
237 
238  std::string buildStatisticsString_();
239 
240  double previous_run_duration_;
241  artdaq::MetricManager metricMan_;
242 
243  void sendMetrics_();
244 
245  std::unique_ptr<Fragment> init_fragment_ptr_;
246 
247  std::mutex dispatcher_transfers_mutex_;
248  std::deque<std::unique_ptr<TransferInterface>> dispatcher_transfers_;
249  size_t new_transfers_;
250 };
251 
252 #endif
253 
254 // LocalWords: ds
This class manages MonitoredQuantity instances for the *Core classes.
static const std::string INPUT_EVENTS_STAT_KEY
Key for the Input Events MonitoredQuantity.
static const std::string SHM_COPY_TIME_STAT_KEY
Key for the Shared Memory Copy Time MonitoredQuantity.
bool reinitialize(fhicl::ParameterSet const &pset)
Reinitializes the AggregatorCore. No-Op.
bool stop()
Stops the AggregatorCore.
AggregatorCore & operator=(AggregatorCore const &)=delete
Copy Assignment operator is deleted.
bool shutdown()
Shuts Down the AggregatorCore.
bool start(art::RunID id)
Start the AggregatorCore.
std::string unregister_monitor(std::string const &label)
Delete the TransferInterface having the given unique label.
AggregatorCore(int rank, std::string name)
AggregatorCore Constructor.
static const std::string INPUT_WAIT_STAT_KEY
Key for the Input Wait MonitoredQuantity.
bool soft_initialize(fhicl::ParameterSet const &pset)
Soft-Initializes the AggregatorCore. No-Op.
bool resume()
Resumes the AggregatorCore.
std::string register_monitor(fhicl::ParameterSet const &pset)
Create a new TransferInterface instance using the given configuration.
static const std::string FILE_CHECK_TIME_STAT_KEY
Key for the File Check Time MonitoredQuantity.
AggregatorCore implements the state machine for the Aggregator artdaq application. AggregatorCore processes incoming events in one of three roles: Data Logger, Online Monitor, or Dispatcher.
std::string report(std::string const &which) const
Send a report on a given run-time quantity.
bool initialize(fhicl::ParameterSet const &pset)
Processes the initialize request.
bool pause()
Pauses the AggregatorCore.
static const std::string STORE_EVENT_WAIT_STAT_KEY
Key for the EventStore Event Wait MonitoredQuantity.
size_t process_fragments()
The main working loop of the AggregatorCore. Receives events from DataReceiverManager and processes t...