Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:28

0001 // The purpose of this EDProducer is to test the existence of
0002 // dictionaries for certain types, especially those from the standard
0003 // library.
0004 
0005 #include "FWCore/Framework/interface/global/EDProducer.h"
0006 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 #include "DataFormats/TestObjects/interface/ToyProducts.h"
0011 
0012 #include <cassert>
0013 #include <memory>
0014 #include <vector>
0015 
0016 namespace edm {
0017   class EventSetup;
0018 }
0019 
0020 namespace edmtest {
0021   class ExistingDictionaryTestProducer : public edm::global::EDProducer<> {
0022   public:
0023     explicit ExistingDictionaryTestProducer(edm::ParameterSet const&)
0024         : intToken_{produces<int>()},
0025           vecUniqIntToken_{produces<std::vector<std::unique_ptr<int>>>()},
0026           vecUniqIntProdToken_{produces<std::vector<std::unique_ptr<IntProduct>>>()} {}
0027 
0028     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0029       edm::ParameterSetDescription desc;
0030       descriptions.addDefault(desc);
0031     }
0032 
0033     void produce(edm::StreamID id, edm::Event& iEvent, edm::EventSetup const&) const override {
0034       iEvent.emplace(intToken_, 1);
0035 
0036       std::vector<std::unique_ptr<int>> foo;
0037       foo.emplace_back(std::make_unique<int>(1));
0038       iEvent.emplace(vecUniqIntToken_, std::move(foo));
0039 
0040       std::vector<std::unique_ptr<IntProduct>> foo2;
0041       foo2.emplace_back(std::make_unique<IntProduct>(1));
0042       iEvent.emplace(vecUniqIntProdToken_, std::move(foo2));
0043     }
0044 
0045   private:
0046     const edm::EDPutTokenT<int> intToken_;
0047     const edm::EDPutTokenT<std::vector<std::unique_ptr<int>>> vecUniqIntToken_;
0048     const edm::EDPutTokenT<std::vector<std::unique_ptr<IntProduct>>> vecUniqIntProdToken_;
0049   };
0050 
0051   class ExistingDictionaryTestAnalyzer : public edm::global::EDAnalyzer<> {
0052   public:
0053     explicit ExistingDictionaryTestAnalyzer(edm::ParameterSet const& iConfig)
0054         : intToken_{consumes(iConfig.getParameter<edm::InputTag>("src"))},
0055           vecUniqIntToken_{consumes(iConfig.getParameter<edm::InputTag>("src"))},
0056           vecUniqIntProdToken_{consumes(iConfig.getParameter<edm::InputTag>("src"))},
0057           testVecUniqInt_{iConfig.getParameter<bool>("testVecUniqInt")} {}
0058 
0059     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0060       edm::ParameterSetDescription desc;
0061       desc.add<edm::InputTag>("src", edm::InputTag{"prod"});
0062       desc.add<bool>("testVecUniqInt", true);
0063       descriptions.addDefault(desc);
0064     }
0065 
0066     void analyze(edm::StreamID id, edm::Event const& iEvent, edm::EventSetup const&) const override {
0067       assert(iEvent.get(intToken_) == 1);
0068 
0069       const auto& vecUniqInt = iEvent.get(vecUniqIntToken_);
0070       assert(vecUniqInt.size() == 1);
0071       for (const auto& elem : vecUniqInt) {
0072         if (testVecUniqInt_) {
0073           assert(elem.get() != nullptr);
0074           assert(*elem == 1);
0075         } else {
0076           if (elem) {
0077             edm::LogError("ExistingDictionaryTestAnalyzer")
0078                 << "I am now getting a valid pointer, please update the test";
0079           }
0080         }
0081       }
0082 
0083       const auto& vecUniqIntProd = iEvent.get(vecUniqIntProdToken_);
0084       assert(vecUniqIntProd.size() == 1);
0085       for (const auto& elem : vecUniqIntProd) {
0086         assert(elem.get() != nullptr);
0087         assert(elem->value == 1);
0088       }
0089     }
0090 
0091   private:
0092     const edm::EDGetTokenT<int> intToken_;
0093     const edm::EDGetTokenT<std::vector<std::unique_ptr<int>>> vecUniqIntToken_;
0094     const edm::EDGetTokenT<std::vector<std::unique_ptr<IntProduct>>> vecUniqIntProdToken_;
0095     const bool testVecUniqInt_;
0096   };
0097 }  // namespace edmtest
0098 
0099 using edmtest::ExistingDictionaryTestAnalyzer;
0100 using edmtest::ExistingDictionaryTestProducer;
0101 DEFINE_FWK_MODULE(ExistingDictionaryTestProducer);
0102 DEFINE_FWK_MODULE(ExistingDictionaryTestAnalyzer);