|
| 1 | +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" |
| 2 | +#include "FWCore/ParameterSet/interface/ParameterSet.h" |
| 3 | +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" |
| 4 | +#include "FWCore/Utilities/interface/InputTag.h" |
| 5 | +#include "HeterogeneousCore/AlpakaCore/interface/alpaka/global/EDProducer.h" |
| 6 | +#include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESGetToken.h" |
| 7 | +#include "HeterogeneousCore/AlpakaInterface/interface/config.h" |
| 8 | +#include "HeterogeneousCore/AlpakaTest/interface/AlpakaESTestRecords.h" |
| 9 | +#include "HeterogeneousCore/AlpakaTest/interface/alpaka/AlpakaESTestData.h" |
| 10 | + |
| 11 | +namespace ALPAKA_ACCELERATOR_NAMESPACE { |
| 12 | + /** |
| 13 | + * This class tests various ways of a device ESProduct being missing |
| 14 | + */ |
| 15 | + class TestAlpakaGlobalProducerNullES : public global::EDProducer<> { |
| 16 | + public: |
| 17 | + TestAlpakaGlobalProducerNullES(edm::ParameterSet const& config) |
| 18 | + : esTokenA_(esConsumes(config.getParameter<edm::ESInputTag>("eventSetupSource"))), |
| 19 | + esTokenC_(esConsumes(config.getParameter<edm::ESInputTag>("eventSetupSource"))), |
| 20 | + esTokenCNotExist_(esConsumes(edm::ESInputTag("", "doesNotExist"))) {} |
| 21 | + |
| 22 | + void produce(edm::StreamID, device::Event& iEvent, device::EventSetup const& iSetup) const override { |
| 23 | + bool threw = false; |
| 24 | + try { |
| 25 | + [[maybe_unused]] auto handleA = iSetup.getHandle(esTokenA_); |
| 26 | + } catch (cms::Exception& e) { |
| 27 | + threw = true; |
| 28 | + } |
| 29 | + if (not threw) { |
| 30 | + throw cms::Exception("Assert") << "Getting AlpakaESTestDataADevice ESProduct did not throw"; |
| 31 | + } |
| 32 | + |
| 33 | + threw = false; |
| 34 | + try { |
| 35 | + [[maybe_unused]] auto const& prodC = iSetup.getData(esTokenC_); |
| 36 | + } catch (cms::Exception& e) { |
| 37 | + threw = true; |
| 38 | + } |
| 39 | + if (not threw) { |
| 40 | + throw cms::Exception("Assert") << "Getting AlpakaESTestDataCDevice ESProduct did not throw"; |
| 41 | + } |
| 42 | + |
| 43 | + auto handleC = iSetup.getHandle(esTokenCNotExist_); |
| 44 | + if (handleC.isValid()) { |
| 45 | + throw cms::Exception("Assert") << "Getting non-existing AlpakaESTestDataCDevice succeeded, should have failed"; |
| 46 | + } |
| 47 | + threw = false; |
| 48 | + try { |
| 49 | + [[maybe_unused]] auto const& prodC = *handleC; |
| 50 | + } catch (cms::Exception& e) { |
| 51 | + threw = true; |
| 52 | + } |
| 53 | + if (not threw) { |
| 54 | + throw cms::Exception("Assert") |
| 55 | + << "De-referencing ESHandle of non-existentAlpakaESTestDataADevice did not throw"; |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { |
| 60 | + edm::ParameterSetDescription desc; |
| 61 | + desc.add("eventSetupSource", edm::ESInputTag{}); |
| 62 | + descriptions.addWithDefaultLabel(desc); |
| 63 | + } |
| 64 | + |
| 65 | + private: |
| 66 | + const device::ESGetToken<AlpakaESTestDataADevice, AlpakaESTestRecordA> esTokenA_; |
| 67 | + const device::ESGetToken<AlpakaESTestDataCDevice, AlpakaESTestRecordA> esTokenC_; |
| 68 | + const device::ESGetToken<AlpakaESTestDataCDevice, AlpakaESTestRecordA> esTokenCNotExist_; |
| 69 | + }; |
| 70 | + |
| 71 | +} // namespace ALPAKA_ACCELERATOR_NAMESPACE |
| 72 | + |
| 73 | +#include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h" |
| 74 | +DEFINE_FWK_ALPAKA_MODULE(TestAlpakaGlobalProducerNullES); |
0 commit comments