SimpleDerivedProducer_module.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // SimpleDerivedProducer
4 //
5 // ======================================================================
6 
11 #include "fhiclcpp/ParameterSet.h"
12 
13 #include <memory>
14 #include <vector>
15 
16 namespace arttest {
18 }
19 
21 
22 //--------------------------------------------------------------------
23 //
24 // Produces a SimpleProduct product instance.
25 //
27 public:
28  using SimpleDerivedProduct = std::vector<arttest::SimpleDerived>;
29 
31  : EDProducer{p}, size_(p.get<int>("nvalues"))
32  {
33  produces<SimpleDerivedProduct>("derived");
34  }
35 
36 private:
37  void produce(art::Event& e) override;
38 
39  int const size_; // number of Simples to put in the collection
40 };
41 
42 void
44 {
45  // Fill up a collection of SimpleDerived objects
46  auto prod = std::make_unique<SimpleDerivedProduct>();
47  int event_num = e.id().event();
48  for (int i = 0; i != size_; ++i) {
49  SimpleDerived sd;
50  sd.key = size_ - i + event_num;
51  sd.value = 1.5 * i + 100.0;
52  // sd.dummy_ = default-constructed value
53  prod->push_back(sd);
54  }
55 
56  // Put the product into the Event
57  e.put(std::move(prod), "derived");
58 }
59 
60 // ----------------------------------------------------------------------
61 
63 
64 // ======================================================================
std::vector< arttest::SimpleDerived > SimpleDerivedProduct
EDProducer()=default
SimpleDerivedProducer(fhicl::ParameterSet const &p)
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
p
Definition: test.py:228
EventNumber_t event() const
Definition: EventID.h:117
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:692
EventID id() const
Definition: Event.cc:37