$treeview $search $mathjax $extrastylesheet
artdaq
v3_04_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "art/Framework/Core/EDProducer.h" 00002 #include "art/Framework/Core/ModuleMacros.h" 00003 #include "art/Framework/Principal/Event.h" 00004 #include "art/Framework/Principal/Run.h" 00005 #include "fhiclcpp/ParameterSet.h" 00006 #include "artdaq-core/Data/PackageBuildInfo.hh" 00007 00008 #include <iostream> 00009 00010 00011 namespace artdaq 00012 { 00018 template <std::string* instanceName, typename... Pkgs> 00019 class BuildInfo : public art::EDProducer 00020 { 00021 public: 00029 explicit BuildInfo(fhicl::ParameterSet const& p); 00030 00034 virtual ~BuildInfo() = default; 00035 00043 void beginRun(art::Run& r) override; 00044 00051 void produce(art::Event& e) override; 00052 00053 private: 00054 00055 std::unique_ptr<std::vector<PackageBuildInfo>> packages_; 00056 std::string instanceName_; 00057 00058 template <typename... Args> 00059 struct fill_packages; 00060 00061 template <typename Arg> 00062 struct fill_packages<Arg> 00063 { 00064 static void doit(std::vector<PackageBuildInfo>& packages) 00065 { 00066 packages.emplace_back(Arg::getPackageBuildInfo()); 00067 } 00068 }; 00069 00070 template <typename Arg, typename... Args> 00071 struct fill_packages<Arg, Args...> 00072 { 00073 static void doit(std::vector<PackageBuildInfo>& packages) 00074 { 00075 packages.emplace_back(Arg::getPackageBuildInfo()); 00076 fill_packages<Args...>::doit(packages); 00077 } 00078 }; 00079 }; 00080 00081 template <std::string* instanceName, typename... Pkgs> 00082 BuildInfo<instanceName, Pkgs...>::BuildInfo(fhicl::ParameterSet const& ps): 00083 packages_(new std::vector<PackageBuildInfo>()) 00084 , instanceName_(ps.get<std::string>("instance_name", *instanceName)) 00085 { 00086 fill_packages<Pkgs...>::doit(*packages_); 00087 00088 produces<std::vector<PackageBuildInfo>, art::InRun>(instanceName_); 00089 } 00090 00091 template <std::string* instanceName, typename... Pkgs> 00092 void BuildInfo<instanceName, Pkgs...>::beginRun(art::Run& e) 00093 { 00094 // JCF, 9/22/14 00095 00096 // Previously, the vector pointed to by the member variable 00097 // packages_ itself got stored in output on the call to "e.put()" 00098 // below; what would then happen is that at the start of a new run 00099 // or subrun, when e.put() got called again an exception would be 00100 // thrown because packages_ would now be null thanks to the 00101 // previous call to std::move. To make sure this doesn't happen, I 00102 // now stash a copy of the vector pointed to by packages_, not the 00103 // original member vector 00104 00105 auto packages_deep_copy_ptr = std::unique_ptr<std::vector<PackageBuildInfo>>( 00106 new std::vector<PackageBuildInfo>(*packages_)); 00107 00108 e.put(std::move(packages_deep_copy_ptr), instanceName_); 00109 } 00110 00111 template <std::string* instanceName, typename... Pkgs> 00112 void BuildInfo<instanceName, Pkgs...>::produce(art::Event&) 00113 { 00114 // nothing to be done for individual events 00115 } 00116 }