Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:47:08

0001 // -*- C++ -*-
0002 //
0003 // Package:     FWCore/Framework
0004 // Class  :     TestPRegisterModule2
0005 //
0006 /**\class TestPRegisterModule2
0007 
0008  Description:
0009 
0010  Usage:
0011 
0012    \author Stefano ARGIRO, Chris Jones
0013    \date 19 May 2005
0014 */
0015 
0016 #include "DataFormats/Common/interface/Handle.h"
0017 #include "DataFormats/Provenance/interface/StableProvenance.h"
0018 #include "DataFormats/TestObjects/interface/ToyProducts.h"
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/FrameworkfwdMostUsed.h"
0021 #include "FWCore/Framework/interface/MakerMacros.h"
0022 #include "FWCore/Framework/interface/global/EDProducer.h"
0023 #include "FWCore/Utilities/interface/InputTag.h"
0024 #include "FWCore/Utilities/interface/TypeID.h"
0025 
0026 #include "cppunit/extensions/HelperMacros.h"
0027 
0028 #include <memory>
0029 #include <vector>
0030 
0031 class TestPRegisterModule2 : public edm::global::EDProducer<> {
0032 public:
0033   explicit TestPRegisterModule2(edm::ParameterSet const&);
0034   void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
0035 };
0036 
0037 TestPRegisterModule2::TestPRegisterModule2(edm::ParameterSet const&) {
0038   produces<edmtest::DoubleProduct>();
0039   consumes<edmtest::StringProduct>(edm::InputTag{"m2"});
0040 }
0041 
0042 void TestPRegisterModule2::produce(edm::StreamID, edm::Event& event, edm::EventSetup const&) const {
0043   std::vector<edm::StableProvenance const*> plist;
0044   event.getAllStableProvenance(plist);
0045 
0046   std::vector<edm::StableProvenance const*>::const_iterator pd = plist.begin();
0047 
0048   CPPUNIT_ASSERT(0 != plist.size());
0049   CPPUNIT_ASSERT(2 == plist.size());
0050   CPPUNIT_ASSERT(pd != plist.end());
0051   if (pd == plist.end())
0052     return;  // To silence Coverity
0053   edmtest::StringProduct stringprod;
0054   edm::TypeID stringID(stringprod);
0055   CPPUNIT_ASSERT(stringID.friendlyClassName() == (*pd)->friendlyClassName());
0056   CPPUNIT_ASSERT((*pd)->moduleLabel() == "m1");
0057 
0058   ++pd;
0059   CPPUNIT_ASSERT(pd != plist.end());
0060   if (pd == plist.end())
0061     return;  // To silence Coverity
0062 
0063   edmtest::DoubleProduct dprod;
0064   edm::TypeID dID(dprod);
0065   CPPUNIT_ASSERT(dID.friendlyClassName() == (*pd)->friendlyClassName());
0066   CPPUNIT_ASSERT((*pd)->moduleLabel() == "m2");
0067 
0068   edm::Handle<edmtest::StringProduct> stringp;
0069   event.getByLabel("m2", stringp);
0070   CPPUNIT_ASSERT(stringp->name_ == "m1");
0071 
0072   event.put(std::make_unique<edmtest::DoubleProduct>());
0073 }
0074 
0075 DEFINE_FWK_MODULE(TestPRegisterModule2);