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