ProductIDGetter_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: ProductIDGetter
3 // Module Type: producer
4 // File: ProductIDGetter_module.cc
5 //
6 // Generated at Wed Jun 15 17:19:52 2011 by Chris Green using artmod
7 // from art v0_07_09.
8 ////////////////////////////////////////////////////////////////////////
9 
11 
17 
18 #include <vector>
19 
20 namespace art {
21  namespace test {
22  class ProductIDGetter;
23  }
24 } // namespace art
25 
27 public:
28  struct Config {
29  };
31  explicit ProductIDGetter(Parameters const&);
32 
33 private:
34  void beginSubRun(art::SubRun&) override;
35  void produce(art::Event&) override;
36 };
37 
39  : EDProducer{ps}
40 {
41  produces<std::vector<int>, art::InSubRun>();
42  produces<art::Ptr<int>, art::InSubRun>();
43  produces<std::vector<int>>();
44  produces<art::Ptr<int>>();
45 }
46 
47 void
49 {
50  auto vip = std::make_unique<std::vector<int>>();
51  vip->push_back(1);
52  vip->push_back(3);
53  vip->push_back(5);
54  vip->push_back(7);
55 
56  art::ProductID const pv{sr.getProductID<std::vector<int>>()};
57  auto ptr = std::make_unique<art::Ptr<int>>(pv, 2, sr.productGetter(pv));
58 
59  BOOST_REQUIRE(ptr->id().isValid());
60 
61  art::ProductID const id{sr.put(std::move(vip))};
62  art::Ptr<int> const ptr_check{id, 2, sr.productGetter(id)};
63 
64  BOOST_REQUIRE_EQUAL(ptr->id(), ptr_check.id());
65  BOOST_REQUIRE(!ptr_check.isAvailable());
66 
67  sr.put(std::move(ptr), art::fullSubRun());
68 }
69 
70 void
72 {
73  // Test that getting a ProductID for an unregistered product yields an
74  // exception.
75  BOOST_REQUIRE_EXCEPTION(
76  e.getProductID<int>(), art::Exception, [](art::Exception const& e) {
77  return e.categoryCode() == art::errors::ProductRegistrationFailure;
78  });
79 
80  auto vip = std::make_unique<std::vector<int>>();
81  vip->push_back(0);
82  vip->push_back(2);
83  vip->push_back(4);
84  vip->push_back(6);
85 
86  art::ProductID const pv{e.getProductID<std::vector<int>>()};
87  auto ptr = std::make_unique<art::Ptr<int>>(pv, 2, e.productGetter(pv));
88 
89  BOOST_REQUIRE(ptr->id().isValid());
90 
91  art::ProductID const id{e.put(std::move(vip))};
92  art::Ptr<int> const ptr_check{id, 2, e.productGetter(id)};
93 
94  BOOST_REQUIRE_EQUAL(ptr->id(), ptr_check.id());
95  BOOST_REQUIRE(!ptr_check.isAvailable());
96 
97  e.put(std::move(ptr));
98 }
99 
ProductID getProductID(std::string const &instance_name="") const
Definition: DataViewImpl.h:347
static const double ps
Definition: Units.h:103
Definition: test.py:1
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
void beginSubRun(art::SubRun &) override
EDProductGetter const * productGetter(ProductID const pid) const
BOOST_REQUIRE(inFile)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void produce(art::Event &) override
constexpr auto fullSubRun()
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:692
static const double sr
Definition: Units.h:167
Definition: fwd.h:26
EDProductGetter const * productGetter() const
Definition: Ptr.h:220