|
| 1 | +#include "DataFormats/TestObjects/interface/ThingWithDoNotSort.h" |
| 2 | +#include "DataFormats/TestObjects/interface/ThingWithPostInsert.h" |
| 3 | +#include "FWCore/Framework/interface/Event.h" |
| 4 | +#include "FWCore/Framework/interface/global/EDProducer.h" |
| 5 | +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" |
| 6 | +#include "FWCore/ParameterSet/interface/ParameterSet.h" |
| 7 | +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" |
| 8 | +#include "FWCore/Utilities/interface/EDPutToken.h" |
| 9 | + |
| 10 | +namespace edmtest { |
| 11 | + |
| 12 | + class PostInsertProducer : public edm::global::EDProducer<> { |
| 13 | + public: |
| 14 | + explicit PostInsertProducer(edm::ParameterSet const& ps); |
| 15 | + |
| 16 | + void produce(edm::StreamID sid, edm::Event& event, edm::EventSetup const& es) const override; |
| 17 | + |
| 18 | + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); |
| 19 | + |
| 20 | + private: |
| 21 | + edm::EDPutTokenT<ThingWithPostInsert> putTokenPostInsert_; |
| 22 | + edm::EDPutTokenT<ThingWithDoNotSort> putTokenDoNotSort_; |
| 23 | + edm::EDPutTokenT<ThingWithPostInsert> emplaceTokenPostInsert_; |
| 24 | + edm::EDPutTokenT<ThingWithDoNotSort> emplaceTokenDoNotSort_; |
| 25 | + }; |
| 26 | + |
| 27 | + PostInsertProducer::PostInsertProducer(edm::ParameterSet const& iConfig) |
| 28 | + : putTokenPostInsert_{produces<ThingWithPostInsert>("put")}, |
| 29 | + putTokenDoNotSort_{produces<ThingWithDoNotSort>("put")}, |
| 30 | + emplaceTokenPostInsert_{produces<ThingWithPostInsert>("emplace")}, |
| 31 | + emplaceTokenDoNotSort_{produces<ThingWithDoNotSort>("emplace")} {} |
| 32 | + |
| 33 | + // Functions that gets called by framework every event |
| 34 | + void PostInsertProducer::produce(edm::StreamID sid, edm::Event& event, edm::EventSetup const& es) const { |
| 35 | + { |
| 36 | + // Check that event.put() calls ThingWithPostInsert::post_insert(). |
| 37 | + auto product = std::make_unique<ThingWithPostInsert>(42); |
| 38 | + assert(not product->valid()); |
| 39 | + assert(product->value() == 42); |
| 40 | + auto handle = event.put(putTokenPostInsert_, std::move(product)); |
| 41 | + assert(handle->valid()); |
| 42 | + assert(handle->value() == 42); |
| 43 | + } |
| 44 | + |
| 45 | + { |
| 46 | + // Check that event.put *does not* call ThingWithDoNotSort::post_insert(), |
| 47 | + // which would throw an exception. |
| 48 | + auto product = std::make_unique<ThingWithDoNotSort>(42); |
| 49 | + assert(product->value() == 42); |
| 50 | + auto handle = event.put(putTokenDoNotSort_, std::move(product)); |
| 51 | + assert(handle->value() == 42); |
| 52 | + } |
| 53 | + |
| 54 | + { |
| 55 | + // Check that event.emplace() calls ThingWithPostInsert::post_insert(). |
| 56 | + ThingWithPostInsert product{42}; |
| 57 | + assert(not product.valid()); |
| 58 | + assert(product.value() == 42); |
| 59 | + auto handle = event.emplace(emplaceTokenPostInsert_, product); |
| 60 | + assert(handle->valid()); |
| 61 | + assert(handle->value() == 42); |
| 62 | + } |
| 63 | + |
| 64 | + { |
| 65 | + // Check that event.emplace *does not* call ThingWithDoNotSort::post_insert(), |
| 66 | + // which would throw an exception. |
| 67 | + ThingWithDoNotSort product{42}; |
| 68 | + assert(product.value() == 42); |
| 69 | + auto handle = event.emplace(emplaceTokenDoNotSort_, product); |
| 70 | + assert(handle->value() == 42); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + void PostInsertProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { |
| 75 | + edm::ParameterSetDescription desc; |
| 76 | + descriptions.addWithDefaultLabel(desc); |
| 77 | + } |
| 78 | + |
| 79 | +} // namespace edmtest |
| 80 | + |
| 81 | +#include "FWCore/Framework/interface/MakerMacros.h" |
| 82 | +using edmtest::PostInsertProducer; |
| 83 | +DEFINE_FWK_MODULE(PostInsertProducer); |
0 commit comments