artdaq  v3_07_02
TransferOutput_module.cc
1 #define TRACE_NAME "TransferOutput"
2 #include "artdaq/ArtModules/ArtdaqOutput.hh"
3 
4 #include <signal.h>
5 #include "artdaq/DAQdata/NetMonHeader.hh"
6 #include "artdaq/TransferPlugins/MakeTransferPlugin.hh"
7 #include "artdaq/TransferPlugins/TransferInterface.hh"
8 
9 namespace art {
10 class TransferOutput;
11 }
12 
19 {
20 public:
28  explicit TransferOutput(fhicl::ParameterSet const& ps);
29 
34 
35 protected:
42  virtual void SendMessage(artdaq::FragmentPtr& msg);
43 
44 private:
45  size_t send_timeout_us_;
46  size_t send_retry_count_;
47  std::unique_ptr<artdaq::TransferInterface> transfer_;
48 };
49 
50 art::TransferOutput::TransferOutput(fhicl::ParameterSet const& ps)
51  : ArtdaqOutput(ps), send_timeout_us_(ps.get<size_t>("send_timeout_us", 5000000)), send_retry_count_(ps.get<size_t>("send_retry_count", 5))
52 {
53  TLOG(TLVL_DEBUG) << "Begin: TransferOutput::TransferOutput(ParameterSet const& ps)";
54  transfer_ = artdaq::MakeTransferPlugin(ps, "transfer_plugin", artdaq::TransferInterface::Role::kSend);
55  TLOG(TLVL_DEBUG) << "END: TransferOutput::TransferOutput";
56 }
57 
59 {
60  TLOG(TLVL_DEBUG) << "Begin: TransferOutput::~TransferOutput()";
61 
62  auto sts = transfer_->transfer_fragment_min_blocking_mode(*artdaq::Fragment::eodFrag(0), 10000);
63  if (sts != artdaq::TransferInterface::CopyStatus::kSuccess) TLOG(TLVL_ERROR) << "Error sending EOD Fragment!";
64  transfer_.reset(nullptr);
65  TLOG(TLVL_DEBUG) << "End: TransferOutput::~TransferOutput()";
66 }
67 
68 void art::TransferOutput::SendMessage(artdaq::FragmentPtr& fragment)
69 {
70  TLOG(TLVL_DEBUG) << "Sending message with sequenceID=" << fragment->sequenceID() << ", type=" << fragment->type()
71  << ", length=" << fragment->dataSizeBytes();
73  size_t retries = 0;
74  while (sts != artdaq::TransferInterface::CopyStatus::kSuccess && retries <= send_retry_count_)
75  {
76  sts = transfer_->transfer_fragment_min_blocking_mode(*fragment, send_timeout_us_);
77  retries++;
78  }
79  if (retries > send_retry_count_)
80  {
81  TLOG(TLVL_ERROR) << "Error communicating with remote after " << retries << " tries. Closing art process";
82  kill(getpid(), SIGUSR2);
83  }
84 
85 #if 0
86  if (messageType == artdaq::Fragment::InitFragmentType)
87  {
88  std::fstream ostream("sendInitMessage_TransferOutput.bin", std::ios::out | std::ios::binary);
89  ostream.write(msg.Buffer(), msg.Length());
90  ostream.close();
91  }
92 #endif
93 }
94 
95 DEFINE_ART_MODULE(art::TransferOutput)
This is the base class for artdaq OutputModules, providing the serialization interface for art Events...
~TransferOutput()
TransferOutput Destructor.
std::unique_ptr< artdaq::TransferInterface > MakeTransferPlugin(const fhicl::ParameterSet &pset, std::string plugin_label, TransferInterface::Role role)
Load a TransferInterface plugin.
virtual void SendMessage(artdaq::FragmentPtr &msg)
Send a message using the Transfer Plugin
TransferOutput(fhicl::ParameterSet const &ps)
TransferOutput Constructor.
An art::OutputModule which sends events using DataSenderManager. This module is designed for transpor...
This TransferInterface is a Sender.
Some error occurred, but no exception was thrown.
The send operation completed successfully.