Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /** \class edm::AssociationMapProducer
0002 \author W. David Dagenhart, created 10 March 2015
0003 */
0004 
0005 #include "DataFormats/Common/interface/AssociationMap.h"
0006 #include "DataFormats/Common/interface/OneToValue.h"
0007 #include "DataFormats/Common/interface/OneToOne.h"
0008 #include "DataFormats/Common/interface/OneToMany.h"
0009 #include "DataFormats/Common/interface/OneToManyWithQuality.h"
0010 #include "DataFormats/Common/interface/Handle.h"
0011 #include "DataFormats/Common/interface/View.h"
0012 #include "FWCore/Framework/interface/one/EDProducer.h"
0013 #include "FWCore/Framework/interface/Event.h"
0014 #include "FWCore/Framework/interface/makeRefToBaseProdFrom.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "FWCore/Utilities/interface/EDGetToken.h"
0017 #include "FWCore/Utilities/interface/InputTag.h"
0018 #include "FWCore/Framework/interface/MakerMacros.h"
0019 
0020 #include <memory>
0021 #include <vector>
0022 
0023 namespace edm {
0024   class EventSetup;
0025 }
0026 
0027 namespace edmtest {
0028 
0029   class AssociationMapProducer : public edm::one::EDProducer<> {
0030   public:
0031     explicit AssociationMapProducer(edm::ParameterSet const&);
0032     ~AssociationMapProducer() override;
0033 
0034     void produce(edm::Event&, edm::EventSetup const&) override;
0035 
0036     typedef edm::AssociationMap<edm::OneToValue<std::vector<int>, double> > AssocOneToValue;
0037     typedef edm::AssociationMap<edm::OneToOne<std::vector<int>, std::vector<int> > > AssocOneToOne;
0038     typedef edm::AssociationMap<edm::OneToMany<std::vector<int>, std::vector<int> > > AssocOneToMany;
0039     typedef edm::AssociationMap<edm::OneToManyWithQuality<std::vector<int>, std::vector<int>, double> >
0040         AssocOneToManyWithQuality;
0041     typedef edm::AssociationMap<edm::OneToOne<edm::View<int>, edm::View<int> > > AssocOneToOneView;
0042 
0043   private:
0044     edm::EDGetTokenT<std::vector<int> > inputToken1_;
0045     edm::EDGetTokenT<std::vector<int> > inputToken2_;
0046 
0047     edm::EDGetTokenT<edm::View<int> > inputToken1V_;
0048     edm::EDGetTokenT<edm::View<int> > inputToken2V_;
0049   };
0050 
0051   AssociationMapProducer::AssociationMapProducer(edm::ParameterSet const& pset) {
0052     inputToken1_ = consumes<std::vector<int> >(pset.getParameter<edm::InputTag>("inputTag1"));
0053     inputToken2_ = consumes<std::vector<int> >(pset.getParameter<edm::InputTag>("inputTag2"));
0054 
0055     inputToken1V_ = consumes<edm::View<int> >(pset.getParameter<edm::InputTag>("inputTag1"));
0056     inputToken2V_ = consumes<edm::View<int> >(pset.getParameter<edm::InputTag>("inputTag2"));
0057 
0058     produces<AssocOneToOne>();
0059     produces<AssocOneToOne>("twoArg");
0060     produces<AssocOneToValue>();
0061     produces<AssocOneToValue>("handleArg");
0062     produces<AssocOneToMany>();
0063     produces<AssocOneToManyWithQuality>();
0064     produces<AssocOneToOneView>();
0065     produces<AssocOneToOneView>("twoArg");
0066   }
0067 
0068   AssociationMapProducer::~AssociationMapProducer() {}
0069 
0070   void AssociationMapProducer::produce(edm::Event& event, edm::EventSetup const&) {
0071     edm::Handle<std::vector<int> > inputCollection1 = event.getHandle(inputToken1_);
0072 
0073     edm::Handle<std::vector<int> > inputCollection2 = event.getHandle(inputToken2_);
0074 
0075     // insert some entries into some AssociationMaps, in another
0076     // module we will readout the contents and check that we readout
0077     // the same content as was put in. Note that the particular values
0078     // used are arbitrary and have no meaning.
0079 
0080     auto assoc1 = std::make_unique<AssocOneToOne>(&event.productGetter());
0081     assoc1->insert(edm::Ref<std::vector<int> >(inputCollection1, 0), edm::Ref<std::vector<int> >(inputCollection2, 1));
0082     assoc1->insert(edm::Ref<std::vector<int> >(inputCollection1, 2), edm::Ref<std::vector<int> >(inputCollection2, 3));
0083     event.put(std::move(assoc1));
0084 
0085     auto assoc2 = std::make_unique<AssocOneToOne>(inputCollection1, inputCollection2);
0086     assoc2->insert(edm::Ref<std::vector<int> >(inputCollection1, 0), edm::Ref<std::vector<int> >(inputCollection2, 1));
0087     assoc2->insert(edm::Ref<std::vector<int> >(inputCollection1, 2), edm::Ref<std::vector<int> >(inputCollection2, 4));
0088     event.put(std::move(assoc2), "twoArg");
0089 
0090     auto assoc3 = std::make_unique<AssocOneToValue>(&event.productGetter());
0091     assoc3->insert(edm::Ref<std::vector<int> >(inputCollection1, 0), 11.0);
0092     assoc3->insert(edm::Ref<std::vector<int> >(inputCollection1, 2), 12.0);
0093     event.put(std::move(assoc3));
0094 
0095     auto assoc4 = std::make_unique<AssocOneToValue>(inputCollection1);
0096     assoc4->insert(edm::Ref<std::vector<int> >(inputCollection1, 0), 21.0);
0097     assoc4->insert(edm::Ref<std::vector<int> >(inputCollection1, 2), 22.0);
0098     event.put(std::move(assoc4), "handleArg");
0099 
0100     auto assoc5 = std::make_unique<AssocOneToMany>(&event.productGetter());
0101     assoc5->insert(edm::Ref<std::vector<int> >(inputCollection1, 0), edm::Ref<std::vector<int> >(inputCollection2, 1));
0102     assoc5->insert(edm::Ref<std::vector<int> >(inputCollection1, 2), edm::Ref<std::vector<int> >(inputCollection2, 4));
0103     assoc5->insert(edm::Ref<std::vector<int> >(inputCollection1, 2), edm::Ref<std::vector<int> >(inputCollection2, 6));
0104     event.put(std::move(assoc5));
0105 
0106     auto assoc6 = std::make_unique<AssocOneToManyWithQuality>(&event.productGetter());
0107     assoc6->insert(edm::Ref<std::vector<int> >(inputCollection1, 0),
0108                    AssocOneToManyWithQuality::data_type(edm::Ref<std::vector<int> >(inputCollection2, 1), 31.0));
0109     assoc6->insert(edm::Ref<std::vector<int> >(inputCollection1, 2),
0110                    AssocOneToManyWithQuality::data_type(edm::Ref<std::vector<int> >(inputCollection2, 4), 32.0));
0111     assoc6->insert(edm::Ref<std::vector<int> >(inputCollection1, 2),
0112                    AssocOneToManyWithQuality::data_type(edm::Ref<std::vector<int> >(inputCollection2, 7), 33.0));
0113     event.put(std::move(assoc6));
0114 
0115     edm::View<int> const& inputView1 = event.get(inputToken1V_);
0116 
0117     edm::Handle<edm::View<int> > inputView2 = event.getHandle(inputToken2V_);
0118 
0119     auto assoc7 = std::make_unique<AssocOneToOneView>(&event.productGetter());
0120     assoc7->insert(inputView1.refAt(0), inputView2->refAt(3));
0121     assoc7->insert(inputView1.refAt(2), inputView2->refAt(4));
0122     event.put(std::move(assoc7));
0123 
0124     auto assoc8 = std::make_unique<AssocOneToOneView>(edm::makeRefToBaseProdFrom(inputView1.refAt(0), event),
0125                                                       edm::makeRefToBaseProdFrom(inputView2->refAt(0), event));
0126 
0127     assoc8->insert(inputView1.refAt(0), inputView2->refAt(5));
0128     assoc8->insert(inputView1.refAt(2), inputView2->refAt(6));
0129     event.put(std::move(assoc8), "twoArg");
0130   }
0131 }  // namespace edmtest
0132 using edmtest::AssociationMapProducer;
0133 DEFINE_FWK_MODULE(AssociationMapProducer);