artdaq_demo_hdf5  v1_04_00
MakeDatasetPlugin.cc
1 #include "artdaq-demo-hdf5/HDF5/MakeDatasetPlugin.hh"
2 #include "artdaq-core/Utilities/ExceptionHandler.hh"
3 
4 #include "cetlib/BasicPluginFactory.h"
5 #include "fhiclcpp/ParameterSet.h"
6 
7 #include <sstream>
8 
9 namespace artdaq {
10 namespace hdf5 {
11 std::unique_ptr<artdaq::hdf5::FragmentDataset>
12 MakeDatasetPlugin(const fhicl::ParameterSet& pset,
13  const std::string& plugin_label)
14 {
15  static cet::BasicPluginFactory bpf("dataset", "make");
16 
17  fhicl::ParameterSet dataset_pset;
18 
19  try
20  {
21  dataset_pset = pset.get<fhicl::ParameterSet>(plugin_label);
22  }
23  catch (...)
24  {
25  std::stringstream errmsg;
26  errmsg
27  << "Error in artdaq::MakeDatasetPlugin: Unable to find the Dataset plugin parameters in the FHiCL code \"" << dataset_pset.to_string()
28  << "\"; FHiCL table with label \"" << plugin_label
29  << "\" may not exist, or if it does, one or more parameters may be missing.";
30  ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
31  }
32 
33  try
34  {
35  auto Dataset =
36  bpf.makePlugin<std::unique_ptr<FragmentDataset>,
37  const fhicl::ParameterSet&>(
38  dataset_pset.get<std::string>("datasetPluginType"),
39  dataset_pset);
40 
41  return Dataset;
42  }
43  catch (...)
44  {
45  std::stringstream errmsg;
46  errmsg
47  << "Unable to create Dataset plugin using the FHiCL parameters \""
48  << dataset_pset.to_string()
49  << "\"";
50  ExceptionHandler(ExceptionHandlerRethrow::yes, errmsg.str());
51  }
52 
53  return nullptr;
54 }
55 } // namespace hdf5
56 } // namespace artdaq