Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <iostream>
0002 #include "DataFormats/TestObjects/interface/OtherThing.h"
0003 #include "DataFormats/TestObjects/interface/OtherThingCollection.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "DataFormats/Common/interface/Handle.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "FWCore/Utilities/interface/Exception.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/Framework/interface/stream/EDAnalyzer.h"
0011 #include "FWCore/Utilities/interface/InputTag.h"
0012 #include "FWCore/Utilities/interface/EDGetToken.h"
0013 
0014 namespace edmtest {
0015 
0016   class OtherThingRefComparer : public edm::stream::EDAnalyzer<> {
0017   public:
0018     explicit OtherThingRefComparer(edm::ParameterSet const& pset);
0019 
0020     void analyze(edm::Event const& e, edm::EventSetup const& c) override;
0021 
0022     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0023 
0024   private:
0025     edm::EDGetTokenT<OtherThingCollection> token1_;
0026     edm::EDGetTokenT<OtherThingCollection> token2_;
0027   };
0028 
0029   OtherThingRefComparer::OtherThingRefComparer(edm::ParameterSet const& pset)
0030       : token1_(consumes<OtherThingCollection>(pset.getUntrackedParameter<edm::InputTag>("first"))),
0031         token2_(consumes<OtherThingCollection>(pset.getUntrackedParameter<edm::InputTag>("second"))) {}
0032 
0033   void OtherThingRefComparer::analyze(edm::Event const& e, edm::EventSetup const&) {
0034     auto const& t1_ = e.get(token1_);
0035     auto const& t2_ = e.get(token2_);
0036 
0037     assert(t1_.size() == t2_.size());
0038 
0039     {
0040       auto iter2 = t2_.begin();
0041       for (auto const& o1 : t1_) {
0042         if (o1.ref != iter2->ref) {
0043           throw cms::Exception("RefCompareFailure")
0044               << "edm::Refs are not equal" << o1.ref.id() << " " << iter2->ref.id();
0045         }
0046         ++iter2;
0047       }
0048     }
0049 
0050     {
0051       auto iter2 = t2_.begin();
0052       for (auto const& o1 : t1_) {
0053         if (o1.ptr != iter2->ptr) {
0054           throw cms::Exception("RefCompareFailure")
0055               << "edm::Ptrs are not equal" << o1.ptr.id() << " " << iter2->ptr.id();
0056         }
0057         ++iter2;
0058       }
0059     }
0060   }
0061 
0062   void OtherThingRefComparer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0063     edm::ParameterSetDescription desc;
0064     desc.addUntracked<edm::InputTag>("first", edm::InputTag("OtherThing", "testUserTag"))
0065         ->setComment("Where to get the first OtherThingCollection");
0066     desc.addUntracked<edm::InputTag>("second", edm::InputTag("OtherThing", "testUserTag"))
0067         ->setComment("Where to get the second OtherThingCollection");
0068     descriptions.add("otherThingRefComparer", desc);
0069   }
0070 
0071 }  // namespace edmtest
0072 using edmtest::OtherThingRefComparer;
0073 DEFINE_FWK_MODULE(OtherThingRefComparer);