artdaq  v3_08_00
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 "artdaq-core/Data/PackageBuildInfo.hh"
6 #include "fhiclcpp/ParameterSet.h"
7 
8 #include <iostream>
9 
10 namespace artdaq {
16 template<std::string* instanceName, typename... Pkgs>
17 class BuildInfo : public art::EDProducer
18 {
19 public:
27  explicit BuildInfo(fhicl::ParameterSet const& p);
28 
32  virtual ~BuildInfo() = default;
33 
41  void beginRun(art::Run& r) override;
42 
49  void produce(art::Event& e) override;
50 
51 private:
52  std::unique_ptr<std::vector<PackageBuildInfo>> packages_;
53  std::string instanceName_;
54 
55  template<typename... Args>
56  struct fill_packages;
57 
58  template<typename Arg>
59  struct fill_packages<Arg>
60  {
61  static void doit(std::vector<PackageBuildInfo>& packages)
62  {
63  packages.emplace_back(Arg::getPackageBuildInfo());
64  }
65  };
66 
67  template<typename Arg, typename... Args>
68  struct fill_packages<Arg, Args...>
69  {
70  static void doit(std::vector<PackageBuildInfo>& packages)
71  {
72  packages.emplace_back(Arg::getPackageBuildInfo());
73  fill_packages<Args...>::doit(packages);
74  }
75  };
76 };
77 
78 template<std::string* instanceName, typename... Pkgs>
79 BuildInfo<instanceName, Pkgs...>::BuildInfo(fhicl::ParameterSet const& ps)
80  :
81 #if ART_HEX_VERSION >= 0x30200
82  EDProducer(ps)
83  ,
84 #endif
85  packages_(new std::vector<PackageBuildInfo>())
86  , instanceName_(ps.get<std::string>("instance_name", *instanceName))
87 {
88  fill_packages<Pkgs...>::doit(*packages_);
89 
90  produces<std::vector<PackageBuildInfo>, art::InRun>(instanceName_);
91 }
92 
93 template<std::string* instanceName, typename... Pkgs>
95 {
96  // JCF, 9/22/14
97 
98  // Previously, the vector pointed to by the member variable
99  // packages_ itself got stored in output on the call to "e.put()"
100  // below; what would then happen is that at the start of a new run
101  // or subrun, when e.put() got called again an exception would be
102  // thrown because packages_ would now be null thanks to the
103  // previous call to std::move. To make sure this doesn't happen, I
104  // now stash a copy of the vector pointed to by packages_, not the
105  // original member vector
106 
107  auto packages_deep_copy_ptr = std::unique_ptr<std::vector<PackageBuildInfo>>(
108  new std::vector<PackageBuildInfo>(*packages_));
109 
110  e.put(std::move(packages_deep_copy_ptr), instanceName_);
111 }
112 
113 template<std::string* instanceName, typename... Pkgs>
115 {
116  // nothing to be done for individual events
117 }
118 } // namespace artdaq
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.