artdaq  v3_12_02
MakeTransferPlugin.cc
1 #include "artdaq/TransferPlugins/MakeTransferPlugin.hh"
2 #include "artdaq-core/Utilities/ExceptionHandler.hh"
3 
4 #include "fhiclcpp/ParameterSet.h"
5 
6 #include "cetlib/BasicPluginFactory.h"
7 
8 #include <sstream>
9 #include <utility> // std::move()
10 
11 namespace artdaq {
12 std::unique_ptr<artdaq::TransferInterface>
13 MakeTransferPlugin(const fhicl::ParameterSet& pset,
14  const std::string& plugin_label,
16 {
17  static cet::BasicPluginFactory bpf("transfer", "make");
18 
19  fhicl::ParameterSet transfer_pset;
20 
21  try
22  {
23  transfer_pset = pset.get<fhicl::ParameterSet>(plugin_label);
24  }
25  catch (...)
26  {
27  std::stringstream errmsg;
28  errmsg
29  << "Error in artdaq::MakeTransferPlugin: Unable to find the transfer plugin parameters in the FHiCL code \"" << transfer_pset.to_string()
30  << "\"; FHiCL table with label \"" << plugin_label
31  << "\" may not exist, or if it does, one or more parameters may be missing.";
32  ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
33  }
34 
35  try
36  {
37  auto transfer =
38  bpf.makePlugin<std::unique_ptr<TransferInterface>,
39  const fhicl::ParameterSet&,
41  transfer_pset.get<std::string>("transferPluginType"),
42  transfer_pset,
43  std::move(role)); // NOLINT(performance-move-const-arg)
44 
45  return transfer;
46  }
47  catch (...)
48  {
49  std::stringstream errmsg;
50  errmsg
51  << "Unable to create transfer plugin using the FHiCL parameters \""
52  << transfer_pset.to_string()
53  << "\"";
54  ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
55  }
56 
57  return nullptr;
58 }
59 } // namespace artdaq
std::unique_ptr< artdaq::TransferInterface > MakeTransferPlugin(const fhicl::ParameterSet &pset, const std::string &plugin_label, TransferInterface::Role role)
Load a TransferInterface plugin.
Role
Used to determine if a TransferInterface is a Sender or Receiver.