CMS 3D CMS Logo

TrackOfThingsProducer.cc
Go to the documentation of this file.
1 
6 #include "DataFormats/TestObjects/interface/ThingCollection.h"
7 #include "DataFormats/TestObjects/interface/TrackOfThings.h"
13 
14 namespace edm {
15  class EventSetup;
16 }
17 
18 namespace edmtest {
19 
21  public:
23  ~TrackOfThingsProducer() override;
24 
25  void produce(edm::Event&, edm::EventSetup const&) override;
26 
27  private:
28  void incrementKey(std::vector<unsigned int>::const_iterator& key) const;
29 
31  std::vector<unsigned int> keysToReference_;
32  };
33 
35  inputToken_ = consumes<ThingCollection>(pset.getParameter<edm::InputTag>("inputTag"));
36 
37  keysToReference_ = pset.getParameter<std::vector<unsigned int> >("keysToReference");
38 
39  produces<TrackOfThingsCollection>();
40  }
41 
43 
44  void TrackOfThingsProducer::incrementKey(std::vector<unsigned int>::const_iterator& key) const {
45  ++key;
46  if (key == keysToReference_.end())
47  key = keysToReference_.begin();
48  }
49 
52 
53  auto result = std::make_unique<TrackOfThingsCollection>();
54 
55  // Arbitrarily fabricate some fake data with TrackOfThings pointing to
56  // Thing objects in products written to the event by a different module.
57  // The numbers in the keys here are made up, passed in via the configuration
58  // and have no meaning other than that we will later check that we can
59  // read out what we put in here.
60  std::vector<unsigned int>::const_iterator key = keysToReference_.begin();
61  for (unsigned int i = 0; i < 5; ++i) {
62  edmtest::TrackOfThings trackOfThings;
63 
64  trackOfThings.ref1 = edm::Ref<ThingCollection>(inputCollection, *key);
66 
67  trackOfThings.ref2 = edm::Ref<ThingCollection>(inputCollection, *key);
69 
70  trackOfThings.ptr1 = edm::Ptr<Thing>(inputCollection, *key);
72 
73  trackOfThings.ptr2 = edm::Ptr<Thing>(inputCollection, *key);
75 
76  trackOfThings.refToBase1 = edm::RefToBase<Thing>(trackOfThings.ref1);
77 
78  for (auto iKey : keysToReference_) {
79  trackOfThings.refVector1.push_back(edm::Ref<ThingCollection>(inputCollection, iKey));
80  trackOfThings.ptrVector1.push_back(edm::Ptr<Thing>(inputCollection, iKey));
81  trackOfThings.refToBaseVector1.push_back(
83  }
84 
85  result->push_back(trackOfThings);
86  }
87 
88  event.put(std::move(result));
89  }
90 } // namespace edmtest
TrackOfThingsProducer(edm::ParameterSet const &)
void produce(edm::Event &, edm::EventSetup const &) override
key
prepare the HTCondor submission files and eventually submit them
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< ThingCollection > inputToken_
HLT enums.
std::vector< unsigned int > keysToReference_
void incrementKey(std::vector< unsigned int >::const_iterator &key) const
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1