CMS 3D CMS Logo

SlimmingDSVThingProducer.cc
Go to the documentation of this file.
3 #include "DataFormats/TestObjects/interface/Thing.h"
4 #include "DataFormats/TestObjects/interface/TrackOfDSVThings.h"
15 
16 #include <set>
17 #include <string>
18 
19 namespace edmtest {
20 
22  public:
24 
26 
28 
29  std::optional<edmtest::Thing> choose(unsigned int iIndex, edmtest::Thing const& iItem) const;
30 
31  void reset() { keysToSave_.clear(); }
32 
33  private:
35  std::set<unsigned int> keysToSave_;
36  unsigned int const offsetToThinnedKey_;
37  unsigned int const offsetToValue_;
38  unsigned int const expectedDetSets_;
39  unsigned int const expectedDetSetSize_;
41  };
42 
44  : trackToken_(cc.consumes<TrackOfDSVThingsCollection>(pset.getParameter<edm::InputTag>("trackTag"))),
45  offsetToThinnedKey_(pset.getParameter<unsigned int>("offsetToThinnedKey")),
46  offsetToValue_(pset.getParameter<unsigned int>("offsetToValue")),
47  expectedDetSets_(pset.getParameter<unsigned int>("expectedDetSets")),
48  expectedDetSetSize_(pset.getParameter<unsigned int>("expectedDetSetSize")),
49  slimmedValueFactor_(pset.getParameter<int>("slimmedValueFactor")) {}
50 
52  desc.add<edm::InputTag>("trackTag");
53  desc.add<unsigned int>("offsetToThinnedKey");
54  desc.add<unsigned int>("offsetToValue", 0);
55  desc.add<unsigned int>("expectedDetSets");
56  desc.add<unsigned int>("expectedDetSetSize");
57  desc.add<int>("slimmedValueFactor", 1);
58  }
59 
61  edm::Event const& event,
62  edm::EventSetup const& es) {
63  for (auto const& track : event.get(trackToken_)) {
64  keysToSave_.insert(track.ref1.key() - offsetToThinnedKey_);
65  keysToSave_.insert(track.ref2.key() - offsetToThinnedKey_);
66  }
67 
68  // Just checking to see if the collection got passed in. Not really using it for anything.
69  if (tc->size() != expectedDetSets_) {
70  throw cms::Exception("TestFailure") << "SlimmingDSVThingSelector::preChoose, number of DetSets = " << tc->size()
71  << " expected = " << expectedDetSets_;
72  }
73  for (auto const& ds : *tc) {
74  if (ds.size() != expectedDetSetSize_) {
75  throw cms::Exception("TestFailure")
76  << "SlimmingDSVThingSelector::preChoose, number of elements in DetSet with id " << ds.id() << " = "
77  << ds.size() << " expected = " << expectedDetSetSize_;
78  }
79  }
80  }
81 
82  std::optional<edmtest::Thing> SlimmingDSVThingSelector::choose(unsigned int iIndex,
83  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") << "SlimmingDSVThingSelector::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 std::nullopt;
95  auto copy = iItem;
96  copy.a *= 10;
97  return copy;
98  }
99 } // namespace edmtest
100 
static void fillPSetDescription(edm::ParameterSetDescription &desc)
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
std::optional< edmtest::Thing > choose(unsigned int iIndex, edmtest::Thing const &iItem) const
edm::EDGetTokenT< TrackOfDSVThingsCollection > const trackToken_
void preChoose(edm::Handle< edmNew::DetSetVector< Thing >> tc, edm::Event const &event, edm::EventSetup const &es)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HLT enums.
SlimmingDSVThingSelector(edm::ParameterSet const &pset, edm::ConsumesCollector &&cc)
Definition: event.py:1