AssnsProducer_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: AssnsProducer
3 // Module Type: producer
4 // File: AssnsProducer_module.cc
5 //
6 // Generated at Thu Jul 7 13:34:45 2011 by Chris Green using artmod
7 // from art v0_07_12.
8 ////////////////////////////////////////////////////////////////////////
9 
16 
17 #include "cetlib/map_vector.h"
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 using std::make_unique;
24 using std::string;
25 using std::vector;
26 
27 using art::ProductID;
28 using art::Ptr;
29 
30 using uintvec = vector<size_t>;
31 using stringvec = vector<string>;
33 
34 namespace arttest {
35  class AssnsProducer;
36 }
37 
39 public:
40  explicit AssnsProducer(fhicl::ParameterSet const& p);
41 
42 private:
43  void produce(art::Event& e) override;
44 
45  std::string const wantVoid_; // "ALL," "NONE," or "SOME."
46  bool const wantMV_; // Produce mapvector and derived Assns.
47  bool const wantMany_; // Produce many-to-many associations.
48  bool const dinkVoid_; // Distinguish ABV from ABD with extra entry.
49  bool const wantAmbiguous_; // Add an extra ABD to cause ambiguity.
50 };
51 
52 namespace {
54  using AssnsABY_t = art::Assns<size_t, string, string>;
55  using AssnsVoid_t = art::Assns<size_t, string>;
56 } // namespace
57 
59  : EDProducer{ps}
60  , wantVoid_{ps.get<std::string>("wantVoid", "ALL")}
61  , wantMV_{ps.get<bool>("wantMV", true)}
62  , wantMany_{ps.get<bool>("wantMany", true)}
63  , dinkVoid_{ps.get<bool>("dinkVoid", false)}
64  , wantAmbiguous_{ps.get<bool>("wantAmbiguous", false)}
65 {
66  produces<uintvec>();
67  produces<stringvec>();
68  if (wantMV_) {
69  produces<mapvec>("mv");
70  produces<AssnsABX_t>("mapvec");
71  if (wantMany_) {
72  produces<AssnsABX_t>("manymapvec");
73  }
74  if (wantVoid_ != "NONE") {
75  produces<AssnsVoid_t>("mapvec");
76  if (wantMany_) {
77  produces<AssnsVoid_t>("manymapvec");
78  }
79  }
80  }
81  produces<AssnsABX_t>();
82  if (wantMany_) {
83  produces<AssnsABX_t>("many");
84  }
85  if (wantVoid_ == "ALL") {
86  produces<AssnsVoid_t>();
87  if (wantMany_) {
88  produces<AssnsVoid_t>("many");
89  }
90  }
91  if (wantAmbiguous_) {
92  produces<AssnsABY_t>();
93  }
94 }
95 
96 void
98 {
99 
100  // Create the data products among which we will make associations.
101  auto vui = make_unique<uintvec>(uintvec{2, 0, 1});
102  auto vs = make_unique<stringvec>(stringvec{"one", "two", "zero"});
103 
104  // Making a map_vector is hard.
105  auto mvs = make_unique<mapvec>();
106  using key_t = mapvec::key_type;
107  mvs->reserve(4);
108  (*mvs)[key_t(0)] = "zero";
109  (*mvs)[key_t(11)] = "one";
110  (*mvs)[key_t(22)] = "two";
111 
112  // Extra members.
113  if (dinkVoid_) {
114  vui->emplace_back(4);
115  vs->emplace_back("four");
116  (*mvs)[key_t(33)] = "four";
117  }
118 
119  // We will need the product IDs of the data products.
120  ProductID const vui_pid{e.getProductID<uintvec>()};
121  ProductID const vs_pid{e.getProductID<stringvec>()};
122 
123  // Create the association objects.
124  // Assns into vectors.
125  auto a = std::make_unique<AssnsABX_t>();
126  auto ay = std::make_unique<AssnsABY_t>();
127  auto av = std::make_unique<AssnsVoid_t>();
128 
129  // Assns into map_vector.
130  auto b = std::make_unique<AssnsABX_t>();
131  auto bv = std::make_unique<AssnsVoid_t>();
132 
133  // addS will add to both x and xv a reference between slot1 of
134  // productID1 and slot2 of productID2. The reference in x will have
135  // associated data td.
136  auto addS = [&e](auto& x,
137  auto& xv,
138  ProductID const id1,
139  size_t const slot1,
140  ProductID const id2,
141  size_t const slot2,
142  auto td) {
143  Ptr<size_t> const p1{id1, slot1, e.productGetter(id1)};
144  Ptr<string> const p2{id2, slot2, e.productGetter(id2)};
145  x->addSingle(p1, p2, td);
146  xv->addSingle(p1, p2);
147  };
148  // AddSV adds only to x, and has no td.
149  auto addSV = [&e](auto& x,
150  ProductID const id1,
151  size_t const slot1,
152  ProductID const id2,
153  size_t const slot2) {
154  Ptr<size_t> const p1{id1, slot1, e.productGetter(id1)};
155  Ptr<string> const p2{id2, slot2, e.productGetter(id2)};
156  x->addSingle(p1, p2);
157  };
158  // AddSS adds only to x (with td).
159  auto addSS = [&e](auto& x,
160  ProductID const id1,
161  size_t const slot1,
162  ProductID const id2,
163  size_t const slot2,
164  auto td) {
165  Ptr<size_t> const p1{id1, slot1, e.productGetter(id1)};
166  Ptr<string> const p2{id2, slot2, e.productGetter(id2)};
167  x->addSingle(p1, p2, td);
168  };
169 
170  // We add associations in an order such that the associated data are
171  // in alphabetical order.
172  addS(a, av, vui_pid, 1, vs_pid, 2, AssnTestData(1, 2, "A"));
173  addSS(ay, vui_pid, 1, vs_pid, 2, "A");
174 
175  addS(a, av, vui_pid, 2, vs_pid, 0, AssnTestData(2, 0, "B"));
176  addSS(ay, vui_pid, 2, vs_pid, 0, "B");
177 
178  addS(a, av, vui_pid, 0, vs_pid, 1, AssnTestData(0, 1, "C"));
179  addSS(ay, vui_pid, 0, vs_pid, 1, "C");
180 
181  if (dinkVoid_) {
182  addSV(av, vui_pid, 3, vs_pid, 3);
183  }
184 
185  auto am = make_unique<AssnsABX_t>(*a);
186  auto avm = make_unique<AssnsVoid_t>(*av);
187 
188  addS(am, avm, vui_pid, 1, vs_pid, 2, AssnTestData(1, 2, "AA"));
189 
190  if (dinkVoid_) {
191  addSV(avm, vui_pid, 3, vs_pid, 3);
192  }
193 
194  std::unique_ptr<AssnsABX_t> bm;
195  std::unique_ptr<AssnsVoid_t> bvm;
196 
197  if (wantMV_) {
198  ProductID const mvs_pid{e.getProductID<mapvec>("mv")};
199  addS(b, bv, vui_pid, 1, mvs_pid, 0, AssnTestData(1, 0, "A"));
200  addS(b, bv, vui_pid, 2, mvs_pid, 11, AssnTestData(2, 11, "B"));
201  addS(b, bv, vui_pid, 0, mvs_pid, 22, AssnTestData(0, 22, "C"));
202  if (dinkVoid_) {
203  addSV(bv, vui_pid, 3, mvs_pid, 33);
204  }
205  bm = make_unique<AssnsABX_t>(*b);
206  bvm = make_unique<AssnsVoid_t>(*bv);
207  addS(bm, bvm, vui_pid, 1, mvs_pid, 0, AssnTestData(1, 0, "AA"));
208  if (dinkVoid_) {
209  addSV(bvm, vui_pid, 3, mvs_pid, 33);
210  }
211  }
212 
213  e.put(std::move(vui));
214  e.put(std::move(vs));
215  if (wantMV_) {
216  e.put(std::move(mvs), "mv");
217  e.put(std::move(b), "mapvec");
218  if (wantMany_) {
219  e.put(std::move(bm), "manymapvec");
220  }
221  if (wantVoid_ != "NONE") {
222  e.put(std::move(bv), "mapvec");
223  if (wantMany_) {
224  e.put(std::move(bvm), "manymapvec");
225  }
226  }
227  }
228  e.put(std::move(a));
229  if (wantMany_) {
230  e.put(std::move(am), "many");
231  }
232  if (wantVoid_ == "ALL") {
233  e.put(std::move(av));
234  if (wantMany_) {
235  e.put(std::move(avm), "many");
236  }
237  }
238  if (wantAmbiguous_) {
239  e.put(std::move(ay));
240  }
241 }
242 
map_vector_key key_type
Definition: map_vector.h:87
ProductID getProductID(std::string const &instance_name="") const
Definition: DataViewImpl.h:347
static const double ps
Definition: Units.h:103
std::string string
Definition: nybbler.cc:12
EDProducer()=default
AssnsProducer(fhicl::ParameterSet const &p)
void produce(art::Event &e) override
std::vector< std::string > stringvec
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
const double a
EDProductGetter const * productGetter(ProductID const pid) const
vector< size_t > uintvec
p
Definition: test.py:228
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:692
Definition: fwd.h:26
std::string key_t
Definition: KeyAssembler.h:71