EventGenerator_module.cc
Go to the documentation of this file.
1 //--------------------------------------------------------------------
2 //
3 // Main motivation for RunProductProducer is to test product
4 // aggregation.
5 //
6 //--------------------------------------------------------------------
7 
13 #include "fhiclcpp/types/Atom.h"
14 
15 #include <atomic>
16 
17 namespace {
18 
19  auto
20  produce_particle_ids(std::size_t const nParticles)
21  {
22  auto particle_ids = std::make_unique<std::vector<int>>(nParticles);
23  auto i = static_cast<int>(-nParticles);
24  std::generate(begin(*particle_ids), end(*particle_ids), [&i] {
25  auto const value = i;
26  i += 2;
27  return value;
28  });
29  return particle_ids;
30  }
31 
32  class EventGenerator : public art::EDProducer {
33  static constexpr unsigned maxParticleSize_{10u};
34  std::atomic<unsigned> nPOTs_{};
35  std::atomic<unsigned> nParticles_{};
36 
37  public:
38  struct Config {
39  };
40  using Parameters = EDProducer::Table<Config>;
41  explicit EventGenerator(Parameters const& ps) : EDProducer{ps}
42  {
43  produces<std::vector<int>>("GenParticles");
44  produces<unsigned, art::InSubRun>("nParticles");
45  produces<unsigned, art::InRun>("nPOTs");
46  }
47 
48  void
49  produce(art::Event& e) override
50  {
51  auto const n = (e.id().event() % maxParticleSize_);
52  nParticles_ += n;
53  e.put(produce_particle_ids(n), "GenParticles");
54  ++nPOTs_;
55  }
56 
57  void
58  endSubRun(art::SubRun& sr) override
59  {
60  sr.put(std::make_unique<unsigned>(nParticles_),
61  "nParticles",
63  nParticles_ = 0u;
64  }
65 
66  void
67  endRun(art::Run& r) override
68  {
69  r.put(std::make_unique<unsigned>(nPOTs_), "nPOTs", art::runFragment());
70  nPOTs_ = 0u;
71  }
72 
73  }; // EventGenerator
74 
75 } // namespace
76 
77 DEFINE_ART_MODULE(EventGenerator)
static const double ps
Definition: Units.h:103
Definition: Run.h:21
constexpr auto runFragment()
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
auto begin(Data< Value > const &data)
constexpr auto subRunFragment()
EventNumber_t event() const
Definition: EventID.h:117
end
Definition: test.py:8
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:692
static const double sr
Definition: Units.h:167
EventID id() const
Definition: Event.cc:37