CMS 3D CMS Logo

SlimmingThingProducer.cc
Go to the documentation of this file.
2 #include "DataFormats/TestObjects/interface/Thing.h"
3 #include "DataFormats/TestObjects/interface/ThingCollection.h"
4 #include "DataFormats/TestObjects/interface/TrackOfThings.h"
15 #include "WhatsIt.h"
16 #include "GadgetRcd.h"
18 
19 #include <set>
20 #include <string>
21 
22 namespace edmtest {
23 
25  public:
27 
29 
31 
32  std::optional<edmtest::Thing> choose(unsigned int iIndex, edmtest::Thing const& iItem) const;
33 
34  void reset() { keysToSave_.clear(); }
35 
36  private:
39  std::set<unsigned int> keysToSave_;
40  unsigned int const offsetToThinnedKey_;
41  unsigned int const offsetToValue_;
42  unsigned int const expectedCollectionSize_;
44  };
45 
47  : trackToken_(cc.consumes<TrackOfThingsCollection>(pset.getParameter<edm::InputTag>("trackTag"))),
48  setupToken_(cc.esConsumes<edmtest::WhatsIt, GadgetRcd>()),
49  offsetToThinnedKey_(pset.getParameter<unsigned int>("offsetToThinnedKey")),
50  offsetToValue_(pset.getParameter<unsigned int>("offsetToValue")),
51  expectedCollectionSize_(pset.getParameter<unsigned int>("expectedCollectionSize")),
52  slimmedValueFactor_(pset.getParameter<int>("slimmedValueFactor")) {}
53 
55  desc.add<edm::InputTag>("trackTag");
56  desc.add<unsigned int>("offsetToThinnedKey");
57  desc.add<unsigned int>("offsetToValue", 0);
58  desc.add<unsigned int>("expectedCollectionSize");
59  desc.add<int>("slimmedValueFactor", 1);
60  }
61 
63  edm::Event const& event,
64  edm::EventSetup const& es) {
65  for (auto const& track : event.get(trackToken_)) {
66  keysToSave_.insert(track.ref1.key() - offsetToThinnedKey_);
67  keysToSave_.insert(track.ref2.key() - offsetToThinnedKey_);
68  keysToSave_.insert(track.ptr1.key() - offsetToThinnedKey_);
69  keysToSave_.insert(track.ptr2.key() - offsetToThinnedKey_);
70  }
71 
72  // Just checking to see if the collection got passed in. Not really using it for anything.
73  if (tc->size() != expectedCollectionSize_) {
74  throw cms::Exception("TestFailure") << "SlimmingThingSelector::preChoose, collection size = " << tc->size()
75  << " expected size = " << expectedCollectionSize_;
76  }
77 
78  // Just checking to see the EventSetup works from here. Not really using it for anything.
80  pSetup.isValid();
81  }
82 
83  std::optional<edmtest::Thing> SlimmingThingSelector::choose(unsigned int iIndex, edmtest::Thing const& iItem) const {
84  // Just checking to see the element in the container got passed in OK. Not really using it.
85  // Just using %10 because it coincidentally works with the arbitrary numbers I picked, no meaning really.
86  auto const expected = slimmedValueFactor_ * (iIndex + offsetToValue_);
87  if (static_cast<unsigned>(iItem.a % 10) != static_cast<unsigned>(expected % 10)) {
88  throw cms::Exception("TestFailure") << "SlimmingThingSelector::choose, item content = " << iItem.a
89  << " index = " << iIndex << " expected " << expected;
90  }
91 
92  // Save the Things referenced by the Tracks
93  if (keysToSave_.find(iIndex) == keysToSave_.end())
94  return {};
95  auto copy = iItem;
96  copy.a *= 10;
97  return copy;
98  }
99 } // namespace edmtest
100 
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::optional< edmtest::Thing > choose(unsigned int iIndex, edmtest::Thing const &iItem) const
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
std::set< unsigned int > keysToSave_
void preChoose(edm::Handle< edmtest::ThingCollection > tc, edm::Event const &event, edm::EventSetup const &es)
edm::ThinningProducer< edmtest::ThingCollection, edmtest::SlimmingThingSelector > SlimmingThingProducer
edm::EDGetTokenT< TrackOfThingsCollection > const trackToken_
edm::ESGetToken< edmtest::WhatsIt, GadgetRcd > const setupToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
static void fillPSetDescription(edm::ParameterSetDescription &desc)
bool isValid() const
Definition: ESHandle.h:44
HLT enums.
SlimmingThingSelector(edm::ParameterSet const &pset, edm::ConsumesCollector &&cc)
Definition: event.py:1