otsdaq  v1_01_04
 All Classes Namespaces Functions
EventBuilderInterface.cc
1 #include "otsdaq/EventBuilderApp/EventBuilderInterface.h"
2 #include "otsdaq-core/MessageFacility/MessageFacility.h"
3 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
4 
5 //#include "otsdaq-core/ConfigurationDataFormats/ConfigurationBase.h"
6 #include <iostream>
7 #include <set>
8 
9 using namespace ots;
10 
11 //========================================================================================================================
12 EventBuilderInterface::EventBuilderInterface(int mpi_rank, std::string name) :
13  mpi_rank_ (mpi_rank),
14  name_ (name)
15 {
16 }
17 
18 //========================================================================================================================
19 //EventBuilderInterface::EventBuilderInterface (std::string name, const OtsUDPFERConfiguration* artDAQBuilderConfiguration) :
20 // theARTDAQBuilderConfiguration_(artDAQBuilderConfiguration),
21 // name_ (name)
22 //{}
23 
24 //========================================================================================================================
25 EventBuilderInterface::~EventBuilderInterface(void)
26 {}
27 
28 //========================================================================================================================
29 void EventBuilderInterface::configure(fhicl::ParameterSet const& pset)
30 {
31  std::cout << __COUT_HDR_FL__ << "\tConfigure" << std::endl;
32  report_string_ = "";
33  external_request_status_ = true;
34 
35  // in the following block, we first destroy the existing EventBuilder
36  // instance, then create a new one. Doing it in one step does not
37  // produce the desired result since that creates a new instance and
38  // then deletes the old one, and we need the opposite order.
39  //event_builder_ptr_.reset(nullptr);
40  if (event_builder_ptr_.get() == 0) {
41  event_builder_ptr_.reset(new artdaq::EventBuilderCore(mpi_rank_, name_));
42  external_request_status_ = event_builder_ptr_->initialize(pset);
43  } else {
44  std::cout << __COUT_HDR_FL__ << "CANNOT RECONFIGURE!!!" << std::endl;
45  }
46  if (! external_request_status_) {
47  report_string_ = "Error initializing an EventBuilderCore named";
48  report_string_.append(name_ + " with ");
49  report_string_.append("ParameterSet = \"" + pset.to_string() + "\".");
50  }
51 
52 // return external_request_status_;
53 }
54 
55 //========================================================================================================================
56 void EventBuilderInterface::halt(void)
57 {
58  std::cout << __COUT_HDR_FL__ << "\tHalt" << std::endl;
59  report_string_ = "";
60  // Faking the transition...
61  external_request_status_ = event_builder_ptr_->shutdown();
62  if (! external_request_status_) {
63  report_string_ = "Error shutting down ";
64  report_string_.append(name_ + ".");
65  }
66 }
67 
68 //========================================================================================================================
69 void EventBuilderInterface::pause(void)
70 {
71  std::cout << __COUT_HDR_FL__ << "\tPause" << std::endl;
72  report_string_ = "";
73  external_request_status_ = event_builder_ptr_->pause();
74  if (! external_request_status_) {
75  report_string_ = "Error pausing ";
76  report_string_.append(name_ + ".");
77  }
78 
79  if (event_building_future_.valid()) {
80  event_building_future_.get();
81  }
82 }
83 
84 //========================================================================================================================
85 void EventBuilderInterface::resume(void)
86 {
87  std::cout << __COUT_HDR_FL__ << "\tResume" << std::endl;
88  report_string_ = "";
89  external_request_status_ = event_builder_ptr_->resume();
90  if (! external_request_status_) {
91  report_string_ = "Error resuming ";
92  report_string_.append(name_ + ".");
93  }
94 
95  event_building_future_ =
96  std::async(std::launch::async, &artdaq::EventBuilderCore::process_fragments,
97  event_builder_ptr_.get());
98 
99 }
100 
101 //========================================================================================================================
102 void EventBuilderInterface::start(std::string runNumber)
103 {
104  std::cout << __COUT_HDR_FL__ << "\tStart" << std::endl;
105 
106  //art::RunNumber_t artRunNumber = boost::lexical_cast<art::RunNumber_t>(runNumber);
107  art::RunID runId((art::RunNumber_t)boost::lexical_cast<art::RunNumber_t>(runNumber));
108 
109  report_string_ = "";
110  external_request_status_ = event_builder_ptr_->start(runId);
111  if (! external_request_status_) {
112  report_string_ = "Error starting ";
113  report_string_.append(name_ + " for run ");
114  report_string_.append("number ");
115  report_string_.append(boost::lexical_cast<std::string>(runId.run()));
116  report_string_.append(".");
117  }
118 
119  event_building_future_ = std::async(std::launch::async, &artdaq::EventBuilderCore::process_fragments, event_builder_ptr_.get());
120 
121 // return external_request_status_;
122 }
123 
124 //========================================================================================================================
125 void EventBuilderInterface::stop(void)
126 {
127  std::cout << __COUT_HDR_FL__ << "\tStart" << std::endl;
128  report_string_ = "";
129  external_request_status_ = event_builder_ptr_->stop();
130  if (! external_request_status_) {
131  report_string_ = "Error stopping ";
132  report_string_.append(name_ + ".");
133  }
134 
135  if (event_building_future_.valid()) {
136  event_building_future_.get();
137  }
138 }