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