00001 #include "otsdaq/AggregatorApp/AggregatorInterface.h"
00002 #include "otsdaq-core/MessageFacility/MessageFacility.h"
00003 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
00004
00005 #include <iostream>
00006 #include <set>
00007
00008
00009 using namespace ots;
00010
00011
00012 AggregatorInterface::AggregatorInterface(int mpi_rank, std::string name) :
00013 mpi_rank_ (mpi_rank),
00014 name_ (name)
00015 {
00016 }
00017
00018
00019
00020
00021
00022
00023
00024
00025 AggregatorInterface::~AggregatorInterface(void)
00026 {}
00027
00028
00029 void AggregatorInterface::configure(fhicl::ParameterSet const& pset)
00030 {
00031 std::cout << __COUT_HDR_FL__ << "\tConfigure" << std::endl;
00032 report_string_ = "";
00033
00034
00035 if (aggregator_ptr_.get() == 0) {
00036 aggregator_ptr_.reset(new artdaq::AggregatorCore(mpi_rank_, name_));
00037 external_request_status_ = aggregator_ptr_->initialize(pset);
00038 } else {
00039 std::cout << __COUT_HDR_FL__ << "CANNOT RECONFIGURE!" << std::endl;
00040 }
00041 if (!external_request_status_) {
00042 report_string_ = "Error initializing ";
00043 report_string_.append(name_ + " ");
00044 report_string_.append("with ParameterSet = \"" + pset.to_string() + "\".");
00045 }
00046 }
00047
00048
00049 void AggregatorInterface::halt(void)
00050 {
00051 std::cout << __COUT_HDR_FL__ << "\tHalt" << std::endl;
00052 report_string_ = "";
00053 external_request_status_ = aggregator_ptr_->shutdown();
00054 if (!external_request_status_) {
00055 report_string_ = "Error shutting down ";
00056 report_string_.append(name_ + ".");
00057 }
00058 }
00059
00060
00061 void AggregatorInterface::pause(void)
00062 {
00063 std::cout << __COUT_HDR_FL__ << "\tPause" << std::endl;
00064 report_string_ = "";
00065 external_request_status_ = aggregator_ptr_->pause();
00066 if (!external_request_status_) {
00067 report_string_ = "Error pausing ";
00068 report_string_.append(name_ + ".");
00069 }
00070
00071 if (aggregator_future_.valid()) {
00072 aggregator_future_.get();
00073 }
00074 }
00075
00076
00077 void AggregatorInterface::resume(void)
00078 {
00079 std::cout << __COUT_HDR_FL__ << "\tResume" << std::endl;
00080 report_string_ = "";
00081 external_request_status_ = aggregator_ptr_->resume();
00082 if (!external_request_status_) {
00083 report_string_ = "Error resuming ";
00084 report_string_.append(name_ + ".");
00085 }
00086
00087 aggregator_future_ =
00088 std::async(std::launch::async, &artdaq::AggregatorCore::process_fragments, aggregator_ptr_.get());
00089
00090 }
00091
00092
00093 void AggregatorInterface::start(std::string runNumber)
00094 {
00095 std::cout << __COUT_HDR_FL__ << "\tStart" << std::endl;
00096
00097
00098 art::RunID runId((art::RunNumber_t)boost::lexical_cast<art::RunNumber_t>(runNumber));
00099
00100 report_string_ = "";
00101 external_request_status_ = aggregator_ptr_->start(runId);
00102 if (!external_request_status_) {
00103 report_string_ = "Error starting ";
00104 report_string_.append(name_ + " ");
00105 report_string_.append("for run number ");
00106 report_string_.append(boost::lexical_cast<std::string>(runId.run()));
00107 report_string_.append(".");
00108 }
00109
00110 aggregator_future_ = std::async(std::launch::async, &artdaq::AggregatorCore::process_fragments, aggregator_ptr_.get());
00111 }
00112
00113
00114 void AggregatorInterface::stop(void)
00115 {
00116 std::cout << __COUT_HDR_FL__ << "\tStop" << std::endl;
00117 report_string_ = "";
00118 external_request_status_ = aggregator_ptr_->stop();
00119 if (!external_request_status_) {
00120 report_string_ = "Error stopping ";
00121 report_string_.append(name_ + ".");
00122 }
00123
00124 if (aggregator_future_.valid()) {
00125 aggregator_future_.get();
00126 }
00127 }