artdaq  v3_08_00
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:
40  virtual void SendMessage(artdaq::FragmentPtr& msg);
41 
42 private:
43  size_t send_timeout_us_;
44  size_t send_retry_count_;
45  std::unique_ptr<artdaq::TransferInterface> transfer_;
46 };
47 
48 art::TransferOutput::TransferOutput(fhicl::ParameterSet const& ps)
49  : ArtdaqOutput(ps), send_timeout_us_(ps.get<size_t>("send_timeout_us", 5000000)), send_retry_count_(ps.get<size_t>("send_retry_count", 5))
50 {
51  TLOG(TLVL_DEBUG) << "Begin: TransferOutput::TransferOutput(ParameterSet const& ps)";
52  transfer_ = artdaq::MakeTransferPlugin(ps, "transfer_plugin", artdaq::TransferInterface::Role::kSend);
53  TLOG(TLVL_DEBUG) << "END: TransferOutput::TransferOutput";
54 }
55 
57 {
58  TLOG(TLVL_DEBUG) << "Begin: TransferOutput::~TransferOutput()";
59 
60  auto sts = transfer_->transfer_fragment_min_blocking_mode(*artdaq::Fragment::eodFrag(0), 10000);
61  if (sts != artdaq::TransferInterface::CopyStatus::kSuccess) TLOG(TLVL_ERROR) << "Error sending EOD Fragment!";
62  transfer_.reset(nullptr);
63  TLOG(TLVL_DEBUG) << "End: TransferOutput::~TransferOutput()";
64 }
65 
66 void art::TransferOutput::SendMessage(artdaq::FragmentPtr& fragment)
67 {
68  TLOG(TLVL_DEBUG) << "Sending message with sequenceID=" << fragment->sequenceID() << ", type=" << fragment->type()
69  << ", length=" << fragment->dataSizeBytes();
71  size_t retries = 0;
72  while (sts != artdaq::TransferInterface::CopyStatus::kSuccess && retries <= send_retry_count_)
73  {
74  sts = transfer_->transfer_fragment_min_blocking_mode(*fragment, send_timeout_us_);
75  retries++;
76  }
77  if (retries > send_retry_count_)
78  {
79  TLOG(TLVL_ERROR) << "Error communicating with remote after " << retries << " tries. Closing art process";
80  kill(getpid(), SIGUSR2);
81  }
82 
83 #if 0
84  if (messageType == artdaq::Fragment::InitFragmentType)
85  {
86  std::fstream ostream("sendInitMessage_TransferOutput.bin", std::ios::out | std::ios::binary);
87  ostream.write(msg.Buffer(), msg.Length());
88  ostream.close();
89  }
90 #endif
91 }
92 
93 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.