Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:34

0001 /* This was written to benchmark some changes to
0002 the getByLabel function and supporting code. It makes
0003 a lot of getByLabel calls although it is not particularly
0004 realistic ... */
0005 
0006 #include "FWCore/Framework/interface/global/EDProducer.h"
0007 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0008 #include "DataFormats/Common/interface/Handle.h"
0009 #include "DataFormats/TestObjects/interface/ToyProducts.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 #include "FWCore/Utilities/interface/InputTag.h"
0013 
0014 #include <memory>
0015 #include <vector>
0016 
0017 namespace edmtest {
0018 
0019   class ManyProductProducer : public edm::global::EDProducer<> {
0020   public:
0021     explicit ManyProductProducer(edm::ParameterSet const& iConfig);
0022 
0023     void produce(edm::StreamID, edm::Event& e, edm::EventSetup const& c) const final;
0024 
0025   private:
0026     unsigned int nProducts_;
0027     std::vector<std::string> instanceNames_;
0028   };
0029 
0030   ManyProductProducer::ManyProductProducer(edm::ParameterSet const& iConfig)
0031       : nProducts_(iConfig.getUntrackedParameter<unsigned int>("nProducts", 1)) {
0032     for (unsigned int i = 0; i < nProducts_; ++i) {
0033       std::stringstream instanceName;
0034       instanceName << "i" << i;
0035       instanceNames_.push_back(instanceName.str());
0036       produces<IntProduct>(instanceName.str());
0037     }
0038   }
0039 
0040   // Functions that gets called by framework every event
0041   void ManyProductProducer::produce(edm::StreamID, edm::Event& e, edm::EventSetup const&) const {
0042     for (unsigned int i = 0; i < nProducts_; ++i) {
0043       e.put(std::make_unique<IntProduct>(1), instanceNames_[i]);
0044     }
0045   }
0046 
0047   class ManyProductAnalyzer : public edm::global::EDAnalyzer<> {
0048   public:
0049     explicit ManyProductAnalyzer(edm::ParameterSet const& iConfig);
0050 
0051     void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const final;
0052 
0053   private:
0054     unsigned int nProducts_;
0055     std::vector<edm::InputTag> tags_;
0056   };
0057 
0058   ManyProductAnalyzer::ManyProductAnalyzer(edm::ParameterSet const& iConfig)
0059       : nProducts_(iConfig.getUntrackedParameter<unsigned int>("nProducts", 1)) {
0060     for (unsigned int i = 0; i < nProducts_; ++i) {
0061       std::stringstream instanceName;
0062       instanceName << "i" << i;
0063       edm::InputTag tag("produceInts", instanceName.str());
0064       tags_.push_back(tag);
0065     }
0066   }
0067 
0068   void ManyProductAnalyzer::analyze(edm::StreamID, edm::Event const& e, edm::EventSetup const&) const {
0069     edm::Handle<IntProduct> h;
0070     for (auto const& tag : tags_) {
0071       e.getByLabel(tag, h);
0072       if (!h.isValid()) {
0073         abort();
0074       }
0075     }
0076   }
0077 }  // namespace edmtest
0078 
0079 using edmtest::ManyProductProducer;
0080 DEFINE_FWK_MODULE(ManyProductProducer);
0081 
0082 using edmtest::ManyProductAnalyzer;
0083 DEFINE_FWK_MODULE(ManyProductAnalyzer);