artdaq  v3_04_01
BuildInfo_module.hh
1 #include "art/Framework/Core/EDProducer.h"
2 #include "art/Framework/Core/ModuleMacros.h"
3 #include "art/Framework/Principal/Event.h"
4 #include "art/Framework/Principal/Run.h"
5 #include "fhiclcpp/ParameterSet.h"
6 #include "artdaq-core/Data/PackageBuildInfo.hh"
7 
8 #include <iostream>
9 
10 
11 namespace artdaq
12 {
18  template <std::string* instanceName, typename... Pkgs>
19  class BuildInfo : public art::EDProducer
20  {
21  public:
29  explicit BuildInfo(fhicl::ParameterSet const& p);
30 
34  virtual ~BuildInfo() = default;
35 
43  void beginRun(art::Run& r) override;
44 
51  void produce(art::Event& e) override;
52 
53  private:
54 
55  std::unique_ptr<std::vector<PackageBuildInfo>> packages_;
56  std::string instanceName_;
57 
58  template <typename... Args>
59  struct fill_packages;
60 
61  template <typename Arg>
62  struct fill_packages<Arg>
63  {
64  static void doit(std::vector<PackageBuildInfo>& packages)
65  {
66  packages.emplace_back(Arg::getPackageBuildInfo());
67  }
68  };
69 
70  template <typename Arg, typename... Args>
71  struct fill_packages<Arg, Args...>
72  {
73  static void doit(std::vector<PackageBuildInfo>& packages)
74  {
75  packages.emplace_back(Arg::getPackageBuildInfo());
76  fill_packages<Args...>::doit(packages);
77  }
78  };
79  };
80 
81  template <std::string* instanceName, typename... Pkgs>
82  BuildInfo<instanceName, Pkgs...>::BuildInfo(fhicl::ParameterSet const& ps):
83  packages_(new std::vector<PackageBuildInfo>())
84  , instanceName_(ps.get<std::string>("instance_name", *instanceName))
85  {
86  fill_packages<Pkgs...>::doit(*packages_);
87 
88  produces<std::vector<PackageBuildInfo>, art::InRun>(instanceName_);
89  }
90 
91  template <std::string* instanceName, typename... Pkgs>
93  {
94  // JCF, 9/22/14
95 
96  // Previously, the vector pointed to by the member variable
97  // packages_ itself got stored in output on the call to "e.put()"
98  // below; what would then happen is that at the start of a new run
99  // or subrun, when e.put() got called again an exception would be
100  // thrown because packages_ would now be null thanks to the
101  // previous call to std::move. To make sure this doesn't happen, I
102  // now stash a copy of the vector pointed to by packages_, not the
103  // original member vector
104 
105  auto packages_deep_copy_ptr = std::unique_ptr<std::vector<PackageBuildInfo>>(
106  new std::vector<PackageBuildInfo>(*packages_));
107 
108  e.put(std::move(packages_deep_copy_ptr), instanceName_);
109  }
110 
111  template <std::string* instanceName, typename... Pkgs>
113  {
114  // nothing to be done for individual events
115  }
116 }
virtual ~BuildInfo()=default
Default Destructor.
void produce(art::Event &e) override
Perform actions for each event.
void beginRun(art::Run &r) override
Perform actions at the beginning of the Run.
BuildInfo(fhicl::ParameterSet const &p)
BuildInfo module Constructor.
BuildInfo is an art::EDProducer which saves information about package builds to the data file...
static std::string instanceName
Name of this BuildInfo instance.