otsdaq  v1_01_03
 All Classes Namespaces Functions
AggregatorInterface.cc
1 #include "otsdaq/AggregatorApp/AggregatorInterface.h"
2 #include "otsdaq-core/MessageFacility/MessageFacility.h"
3 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
4 //#include "otsdaq-demo/UserConfigurationDataFormats/FEROtsUDPHardwareConfiguration.h"
5 #include <iostream>
6 #include <set>
7 
8 
9 using namespace ots;
10 
11 //========================================================================================================================
12 AggregatorInterface::AggregatorInterface(int mpi_rank, std::string name) :
13  mpi_rank_ (mpi_rank),
14  name_ (name)
15 {
16 }
17 
18 //========================================================================================================================
19 //AggregatorInterface::AggregatorInterface (std::string name, const OtsUDPFERConfiguration* artDAQBuilderConfiguration) :
20 // theARTDAQBuilderConfiguration_(artDAQBuilderConfiguration),
21 // name_ (name)
22 //{}
23 
24 //========================================================================================================================
25 AggregatorInterface::~AggregatorInterface(void)
26 {}
27 
28 //========================================================================================================================
29 void AggregatorInterface::configure(fhicl::ParameterSet const& pset)
30 {
31  std::cout << __COUT_HDR_FL__ << "\tConfigure" << std::endl;
32  report_string_ = "";
33 
34  //aggregator_ptr_.reset(nullptr);
35  if (aggregator_ptr_.get() == 0) {
36  aggregator_ptr_.reset(new artdaq::AggregatorCore(mpi_rank_, name_));
37  external_request_status_ = aggregator_ptr_->initialize(pset);
38  } else {
39  std::cout << __COUT_HDR_FL__ << "CANNOT RECONFIGURE!" << std::endl;
40  }
41  if (!external_request_status_) {
42  report_string_ = "Error initializing ";
43  report_string_.append(name_ + " ");
44  report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
45  }
46 }
47 
48 //========================================================================================================================
49 void AggregatorInterface::halt(void)
50 {
51  std::cout << __COUT_HDR_FL__ << "\tHalt" << std::endl;
52  report_string_ = "";
53  external_request_status_ = aggregator_ptr_->shutdown();
54  if (!external_request_status_) {
55  report_string_ = "Error shutting down ";
56  report_string_.append(name_ + ".");
57  }
58 }
59 
60 //========================================================================================================================
61 void AggregatorInterface::pause(void)
62 {
63  std::cout << __COUT_HDR_FL__ << "\tPause" << std::endl;
64  report_string_ = "";
65  external_request_status_ = aggregator_ptr_->pause();
66  if (!external_request_status_) {
67  report_string_ = "Error pausing ";
68  report_string_.append(name_ + ".");
69  }
70 
71  if (aggregator_future_.valid()) {
72  aggregator_future_.get();
73  }
74 }
75 
76 //========================================================================================================================
77 void AggregatorInterface::resume(void)
78 {
79  std::cout << __COUT_HDR_FL__ << "\tResume" << std::endl;
80  report_string_ = "";
81  external_request_status_ = aggregator_ptr_->resume();
82  if (!external_request_status_) {
83  report_string_ = "Error resuming ";
84  report_string_.append(name_ + ".");
85  }
86 
87  aggregator_future_ =
88  std::async(std::launch::async, &artdaq::AggregatorCore::process_fragments, aggregator_ptr_.get());
89 
90 }
91 
92 //========================================================================================================================
93 void AggregatorInterface::start(std::string runNumber)
94 {
95  std::cout << __COUT_HDR_FL__ << "\tStart" << std::endl;
96 
97  //art::RunNumber_t artRunNumber = boost::lexical_cast<art::RunNumber_t>(runNumber);
98  art::RunID runId((art::RunNumber_t)boost::lexical_cast<art::RunNumber_t>(runNumber));
99 
100  report_string_ = "";
101  external_request_status_ = aggregator_ptr_->start(runId);
102  if (!external_request_status_) {
103  report_string_ = "Error starting ";
104  report_string_.append(name_ + " ");
105  report_string_.append("for run number ");
106  report_string_.append(boost::lexical_cast<std::string>(runId.run()));
107  report_string_.append(".");
108  }
109 
110  aggregator_future_ = std::async(std::launch::async, &artdaq::AggregatorCore::process_fragments, aggregator_ptr_.get());
111 }
112 
113 //========================================================================================================================
114 void AggregatorInterface::stop(void)
115 {
116  std::cout << __COUT_HDR_FL__ << "\tStop" << std::endl;
117  report_string_ = "";
118  external_request_status_ = aggregator_ptr_->stop();
119  if (!external_request_status_) {
120  report_string_ = "Error stopping ";
121  report_string_.append(name_ + ".");
122  }
123 
124  if (aggregator_future_.valid()) {
125  aggregator_future_.get();
126  }
127 }