artdaq  v3_09_00
BuildInfo_module.hh
1 #ifndef ARTDAQ_ARTDAQ_ARTMODULES_BUILDINFO_MODULE_HH_
2 #define ARTDAQ_ARTDAQ_ARTMODULES_BUILDINFO_MODULE_HH_
3 
4 #include "art/Framework/Core/EDProducer.h"
5 #include "art/Framework/Core/ModuleMacros.h"
6 #include "art/Framework/Principal/Event.h"
7 #include "art/Framework/Principal/Run.h"
8 #include "artdaq-core/Data/PackageBuildInfo.hh"
9 #include "fhiclcpp/ParameterSet.h"
10 
11 #include <iostream>
12 #include <memory>
13 #include <string>
14 #include <utility>
15 #include <vector>
16 
17 namespace artdaq {
23 template<std::string* instanceName, typename... Pkgs>
24 class BuildInfo : public art::EDProducer
25 {
26 public:
34  explicit BuildInfo(fhicl::ParameterSet const& p);
35 
39  virtual ~BuildInfo() = default;
40 
48  void beginRun(art::Run& r) override;
49 
56  void produce(art::Event& e) override;
57 
58 private:
59  BuildInfo(BuildInfo const&) = delete;
60  BuildInfo(BuildInfo&&) = delete;
61  BuildInfo& operator=(BuildInfo const&) = delete;
62  BuildInfo& operator=(BuildInfo&&) = delete;
63 
64  std::unique_ptr<std::vector<PackageBuildInfo>> packages_;
65  std::string instanceName_;
66 
67  template<typename... Args>
68  struct fill_packages;
69 
70  template<typename Arg>
71  struct fill_packages<Arg>
72  {
73  static void doit(std::vector<PackageBuildInfo>& packages)
74  {
75  packages.emplace_back(Arg::getPackageBuildInfo());
76  }
77  };
78 
79  template<typename Arg, typename... Args>
80  struct fill_packages<Arg, Args...>
81  {
82  static void doit(std::vector<PackageBuildInfo>& packages)
83  {
84  packages.emplace_back(Arg::getPackageBuildInfo());
85  fill_packages<Args...>::doit(packages);
86  }
87  };
88 };
89 
90 template<std::string* instanceName, typename... Pkgs>
91 BuildInfo<instanceName, Pkgs...>::BuildInfo(fhicl::ParameterSet const& ps)
92  :
93 #if ART_HEX_VERSION >= 0x30200
94  EDProducer(ps)
95  ,
96 #endif
97  packages_(new std::vector<PackageBuildInfo>())
98  , instanceName_(ps.get<std::string>("instance_name", *instanceName))
99 {
100  fill_packages<Pkgs...>::doit(*packages_);
101 
102  produces<std::vector<PackageBuildInfo>, art::InRun>(instanceName_);
103 }
104 
105 template<std::string* instanceName, typename... Pkgs>
107 {
108  // JCF, 9/22/14
109 
110  // Previously, the vector pointed to by the member variable
111  // packages_ itself got stored in output on the call to "r.put()"
112  // below; what would then happen is that at the start of a new run
113  // or subrun, when r.put() got called again an exception would be
114  // thrown because packages_ would now be null thanks to the
115  // previous call to std::move. To make sure this doesn't happen, I
116  // now stash a copy of the vector pointed to by packages_, not the
117  // original member vector
118 
119  auto packages_deep_copy_ptr = std::make_unique<std::vector<PackageBuildInfo>>(*packages_);
120 
121  r.put(std::move(packages_deep_copy_ptr), instanceName_);
122 }
123 
124 template<std::string* instanceName, typename... Pkgs>
126 {
127  // nothing to be done for individual events
128 }
129 } // namespace artdaq
130 
131 #endif // ARTDAQ_ARTDAQ_ARTMODULES_BUILDINFO_MODULE_HH_
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.