MixProducer_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: MixProducer
3 // Module Type: producer
4 // File: MixProducer_module.cc
5 //
6 // Generated at Wed May 11 10:14:20 2011 by Chris Green using artmod
7 // from art v0_06_02.
8 ////////////////////////////////////////////////////////////////////////
9 
17 #include "cetlib/map_vector.h"
18 
19 #include <atomic>
20 #include <iomanip>
21 #include <sstream>
22 #include <string>
23 #include <vector>
24 
25 namespace arttest {
26  class MixProducer;
27 }
28 
30 public:
31  struct Config {
32  };
34  explicit MixProducer(Parameters const& p, art::ProcessingFrame const&);
35 
36 private:
37  void produce(art::Event& e, art::ProcessingFrame const&) override;
38  void endSubRun(art::SubRun& sr, art::ProcessingFrame const&) override;
39  void endRun(art::Run& r, art::ProcessingFrame const&) override;
40 
44 
45  // Declare member data here.
46  std::atomic<size_t> eventCounter_{};
47  std::atomic<size_t> subrunCounter_{};
48  std::atomic<size_t> runCounter_{};
49 };
50 
52  art::ProcessingFrame const&)
53  : art::SharedProducer{p}
54 {
55  async<art::InEvent>();
56 
57  produces<double>("doubleLabel");
58  produces<IntProduct>("IntProductLabel");
59  produces<IntProduct>("SpottyProductLabel");
60  produces<std::string>("stringLabel");
61  produces<std::vector<double>>("doubleCollectionLabel");
62  produces<std::vector<art::Ptr<double>>>("doubleVectorPtrLabel");
63  produces<art::PtrVector<double>>("doublePtrVectorLabel");
64  produces<ProductWithPtrs>("ProductWithPtrsLabel");
65  produces<mv_t>("mapVectorLabel");
66  produces<std::vector<art::Ptr<mvv_t>>>("intVectorPtrLabel");
67  produces<double, art::InSubRun>("DoubleSRLabel");
68  produces<double, art::InRun>("DoubleRLabel");
69 }
70 
71 void
73 {
74  ++eventCounter_;
75 
76  // double
77  e.put(std::make_unique<double>(eventCounter_), "doubleLabel");
78 
79  // IntProduct
80  e.put(std::make_unique<IntProduct>(eventCounter_ + 1000000),
81  "IntProductLabel");
82 
83  // SpottyProduct
84  if (e.event() % 100) {
85  e.put(std::make_unique<IntProduct>(eventCounter_), "SpottyProductLabel");
86  }
87 
88  // std::string
89  std::ostringstream s;
90  s << "string value: " << std::setfill('0') << std::setw(7) << eventCounter_
91  << "\n";
92  e.put(std::make_unique<std::string>(s.str()), "stringLabel");
93 
94  // 1. std::vector<double>
95  //
96  // 2. std::vector<art::Ptr<double>>
97  //
98  // 3. art::PtrVector<double>
99  //
100  // 4. ProductWithPtrs
101  auto coll = std::make_unique<std::vector<double>>();
102  coll->reserve(10);
103  for (size_t i = 1; i < 11; ++i) {
104  coll->push_back(i + 10 * (eventCounter_ - 1));
105  }
106  e.put(move(coll), "doubleCollectionLabel"); // 1.
107  auto vpd = std::make_unique<std::vector<art::Ptr<double>>>();
108  vpd->reserve(3);
109  auto pvd = std::make_unique<art::PtrVector<double>>();
110  pvd->reserve(3);
111  art::ProductID const collID{
112  e.getProductID<std::vector<double>>("doubleCollectionLabel")};
113  vpd->emplace_back(collID, 0, e.productGetter(collID));
114  vpd->emplace_back(collID, 4, e.productGetter(collID));
115  vpd->emplace_back(collID, 8, e.productGetter(collID));
116  pvd->push_back(art::Ptr<double>(collID, 1, e.productGetter(collID)));
117  pvd->push_back(art::Ptr<double>(collID, 5, e.productGetter(collID)));
118  pvd->push_back(art::Ptr<double>(collID, 9, e.productGetter(collID)));
119  auto pwp = std::make_unique<ProductWithPtrs>(
120 #ifndef ART_NO_MIX_PTRVECTOR
121  *pvd.get(),
122 #endif
123  *vpd.get());
124  e.put(move(vpd), "doubleVectorPtrLabel"); // 2.
125  e.put(std::move(pvd), "doublePtrVectorLabel"); // 3.
126  e.put(move(pwp), "ProductWithPtrsLabel"); // 4.
127 
128  // map_vector, .
129  auto mv = std::make_unique<mv_t>();
130  static size_t constexpr mv_size{5};
131  mv->reserve(mv_size);
132  for (size_t i = 0; i < mv_size; ++i) {
133  (*mv)[cet::map_vector_key(
134  static_cast<mvm_t>(1 + i * 2 + 10 * (eventCounter_ - 1)))] =
135  (eventCounter_ - 1) * mv_size + i + 1;
136  }
137 
138  // Ptr into map_vector.
139  auto mvvp = std::make_unique<std::vector<art::Ptr<mvv_t>>>();
140  mvvp->reserve(mv_size);
141  art::ProductID const mvID{e.getProductID<mv_t>("mapVectorLabel")};
142  mvvp->emplace_back(mvID, 10 * (eventCounter_ - 1) + 7, e.productGetter(mvID));
143  mvvp->emplace_back(mvID, 10 * (eventCounter_ - 1) + 1, e.productGetter(mvID));
144  mvvp->emplace_back(mvID, 10 * (eventCounter_ - 1) + 3, e.productGetter(mvID));
145  mvvp->emplace_back(mvID, 10 * (eventCounter_ - 1) + 9, e.productGetter(mvID));
146  mvvp->emplace_back(mvID, 10 * (eventCounter_ - 1) + 5, e.productGetter(mvID));
147 
148  e.put(move(mvvp), "intVectorPtrLabel");
149  e.put(move(mv), "mapVectorLabel"); // Note we're putting these into the event
150  // in the "wrong" order.
151 }
152 
153 void
155 {
156  ++subrunCounter_;
157  sr.put(std::make_unique<double>(subrunCounter_), "DoubleSRLabel");
158 }
159 
160 void
162 {
163  ++runCounter_;
164  r.put(std::make_unique<double>(runCounter_), "DoubleRLabel");
165 }
166 
std::atomic< size_t > eventCounter_
EventNumber_t event() const
Definition: DataViewImpl.cc:96
std::atomic< size_t > subrunCounter_
MixProducer(Parameters const &p, art::ProcessingFrame const &)
ProductID getProductID(std::string const &instance_name="") const
Definition: DataViewImpl.h:347
std::pair< key_type, mapped_type > value_type
Definition: map_vector.h:89
std::atomic< size_t > runCounter_
Definition: Run.h:21
Value mapped_type
Definition: map_vector.h:88
void endSubRun(art::SubRun &sr, art::ProcessingFrame const &) override
mv_t::value_type mvv_t
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
void produce(art::Event &e, art::ProcessingFrame const &) override
SharedProducer(fhicl::ParameterSet const &pset)
EDProductGetter const * productGetter(ProductID const pid) const
mv_t::mapped_type mvm_t
p
Definition: test.py:228
void endRun(art::Run &r, art::ProcessingFrame const &) override
static const double s
Definition: Units.h:99
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:692
static const double sr
Definition: Units.h:167