CMS 3D CMS Logo

AssociationMapProducer.cc
Go to the documentation of this file.
1 
19 
20 #include <memory>
21 #include <vector>
22 
23 namespace edm {
24  class EventSetup;
25 }
26 
27 namespace edmtest {
28 
30  public:
32  ~AssociationMapProducer() override;
33 
34  void produce(edm::Event&, edm::EventSetup const&) override;
35 
39  typedef edm::AssociationMap<edm::OneToManyWithQuality<std::vector<int>, std::vector<int>, double> >
42 
43  private:
46 
49  };
50 
52  inputToken1_ = consumes<std::vector<int> >(pset.getParameter<edm::InputTag>("inputTag1"));
53  inputToken2_ = consumes<std::vector<int> >(pset.getParameter<edm::InputTag>("inputTag2"));
54 
55  inputToken1V_ = consumes<edm::View<int> >(pset.getParameter<edm::InputTag>("inputTag1"));
56  inputToken2V_ = consumes<edm::View<int> >(pset.getParameter<edm::InputTag>("inputTag2"));
57 
58  produces<AssocOneToOne>();
59  produces<AssocOneToOne>("twoArg");
60  produces<AssocOneToValue>();
61  produces<AssocOneToValue>("handleArg");
62  produces<AssocOneToMany>();
63  produces<AssocOneToManyWithQuality>();
64  produces<AssocOneToOneView>();
65  produces<AssocOneToOneView>("twoArg");
66  }
67 
69 
71  edm::Handle<std::vector<int> > inputCollection1 = event.getHandle(inputToken1_);
72 
73  edm::Handle<std::vector<int> > inputCollection2 = event.getHandle(inputToken2_);
74 
75  // insert some entries into some AssociationMaps, in another
76  // module we will readout the contents and check that we readout
77  // the same content as was put in. Note that the particular values
78  // used are arbitrary and have no meaning.
79 
80  auto assoc1 = std::make_unique<AssocOneToOne>(&event.productGetter());
81  assoc1->insert(edm::Ref<std::vector<int> >(inputCollection1, 0), edm::Ref<std::vector<int> >(inputCollection2, 1));
82  assoc1->insert(edm::Ref<std::vector<int> >(inputCollection1, 2), edm::Ref<std::vector<int> >(inputCollection2, 3));
83  event.put(std::move(assoc1));
84 
85  auto assoc2 = std::make_unique<AssocOneToOne>(inputCollection1, inputCollection2);
86  assoc2->insert(edm::Ref<std::vector<int> >(inputCollection1, 0), edm::Ref<std::vector<int> >(inputCollection2, 1));
87  assoc2->insert(edm::Ref<std::vector<int> >(inputCollection1, 2), edm::Ref<std::vector<int> >(inputCollection2, 4));
88  event.put(std::move(assoc2), "twoArg");
89 
90  auto assoc3 = std::make_unique<AssocOneToValue>(&event.productGetter());
91  assoc3->insert(edm::Ref<std::vector<int> >(inputCollection1, 0), 11.0);
92  assoc3->insert(edm::Ref<std::vector<int> >(inputCollection1, 2), 12.0);
93  event.put(std::move(assoc3));
94 
95  auto assoc4 = std::make_unique<AssocOneToValue>(inputCollection1);
96  assoc4->insert(edm::Ref<std::vector<int> >(inputCollection1, 0), 21.0);
97  assoc4->insert(edm::Ref<std::vector<int> >(inputCollection1, 2), 22.0);
98  event.put(std::move(assoc4), "handleArg");
99 
100  auto assoc5 = std::make_unique<AssocOneToMany>(&event.productGetter());
101  assoc5->insert(edm::Ref<std::vector<int> >(inputCollection1, 0), edm::Ref<std::vector<int> >(inputCollection2, 1));
102  assoc5->insert(edm::Ref<std::vector<int> >(inputCollection1, 2), edm::Ref<std::vector<int> >(inputCollection2, 4));
103  assoc5->insert(edm::Ref<std::vector<int> >(inputCollection1, 2), edm::Ref<std::vector<int> >(inputCollection2, 6));
104  event.put(std::move(assoc5));
105 
106  auto assoc6 = std::make_unique<AssocOneToManyWithQuality>(&event.productGetter());
107  assoc6->insert(edm::Ref<std::vector<int> >(inputCollection1, 0),
108  AssocOneToManyWithQuality::data_type(edm::Ref<std::vector<int> >(inputCollection2, 1), 31.0));
109  assoc6->insert(edm::Ref<std::vector<int> >(inputCollection1, 2),
110  AssocOneToManyWithQuality::data_type(edm::Ref<std::vector<int> >(inputCollection2, 4), 32.0));
111  assoc6->insert(edm::Ref<std::vector<int> >(inputCollection1, 2),
112  AssocOneToManyWithQuality::data_type(edm::Ref<std::vector<int> >(inputCollection2, 7), 33.0));
113  event.put(std::move(assoc6));
114 
115  edm::View<int> const& inputView1 = event.get(inputToken1V_);
116 
117  edm::Handle<edm::View<int> > inputView2 = event.getHandle(inputToken2V_);
118 
119  auto assoc7 = std::make_unique<AssocOneToOneView>(&event.productGetter());
120  assoc7->insert(inputView1.refAt(0), inputView2->refAt(3));
121  assoc7->insert(inputView1.refAt(2), inputView2->refAt(4));
122  event.put(std::move(assoc7));
123 
124  auto assoc8 = std::make_unique<AssocOneToOneView>(edm::makeRefToBaseProdFrom(inputView1.refAt(0), event),
125  edm::makeRefToBaseProdFrom(inputView2->refAt(0), event));
126 
127  assoc8->insert(inputView1.refAt(0), inputView2->refAt(5));
128  assoc8->insert(inputView1.refAt(2), inputView2->refAt(6));
129  event.put(std::move(assoc8), "twoArg");
130  }
131 } // namespace edmtest
edm::AssociationMap< edm::OneToMany< std::vector< int >, std::vector< int > > > AssocOneToMany
edm::AssociationMap< edm::OneToValue< std::vector< int >, double > > AssocOneToValue
void produce(edm::Event &, edm::EventSetup const &) override
RefToBase< value_type > refAt(size_type i) const
edm::AssociationMap< edm::OneToManyWithQuality< std::vector< int >, std::vector< int >, double > > AssocOneToManyWithQuality
Tag::data_type data_type
insert data type
edm::EDGetTokenT< edm::View< int > > inputToken1V_
edm::AssociationMap< edm::OneToOne< std::vector< int >, std::vector< int > > > AssocOneToOne
edm::AssociationMap< edm::OneToOne< edm::View< int >, edm::View< int > > > AssocOneToOneView
edm::EDGetTokenT< std::vector< int > > inputToken2_
edm::EDGetTokenT< edm::View< int > > inputToken2V_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< std::vector< int > > inputToken1_
RefToBaseProd< T > makeRefToBaseProdFrom(RefToBase< T > const &iRef, Event const &iEvent)
HLT enums.
AssociationMapProducer(edm::ParameterSet const &)
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1