CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ThinningDSVThingProducer.cc
Go to the documentation of this file.
4 #include "DataFormats/TestObjects/interface/Thing.h"
5 #include "DataFormats/TestObjects/interface/TrackOfDSVThings.h"
16 
17 #include <string>
18 
19 namespace edmtest {
20 
22  public:
24 
26 
28 
29  bool choose(unsigned int iIndex, edmtest::Thing const& iItem) const;
30 
31  void reset() { keysToSave_.clear(); }
32 
33  private:
36  unsigned int const offsetToValue_;
37  unsigned int const expectedDetSets_;
38  unsigned int const expectedDetSetSize_;
40  };
41 
43  : trackToken_(cc.consumes<TrackOfDSVThingsCollection>(pset.getParameter<edm::InputTag>("trackTag"))),
44  keysToSave_(pset.getParameter<bool>("thinnedRefSetIgnoreInvalidParentRef")
45  ? edm::ThinnedRefSetMode::ignoreInvalidParentRef
46  : edm::ThinnedRefSetMode::throwOnInvalidParentRef),
47  offsetToValue_(pset.getParameter<unsigned int>("offsetToValue")),
48  expectedDetSets_(pset.getParameter<unsigned int>("expectedDetSets")),
49  expectedDetSetSize_(pset.getParameter<unsigned int>("expectedDetSetSize")),
50  slimmedValueFactor_(pset.getParameter<int>("slimmedValueFactor")) {}
51 
53  desc.add<edm::InputTag>("trackTag");
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  desc.add<bool>("thinnedRefSetIgnoreInvalidParentRef", false);
59  }
60 
62  edm::Event const& event,
63  edm::EventSetup const& es) {
64  auto filler = keysToSave_.fill(edm::RefProd(tc), event.productGetter());
65  for (auto const& track : event.get(trackToken_)) {
66  filler.insert(track.ref1);
67  filler.insert(track.ref2);
68  }
69 
70  // Just checking to see if the collection got passed in. Not really using it for anything.
71  if (tc->size() != expectedDetSets_) {
72  throw cms::Exception("TestFailure") << "ThinningDSVThingSelector::preChoose, number of DetSets = " << tc->size()
73  << " expected = " << expectedDetSets_;
74  }
75  for (auto const& ds : *tc) {
76  if (ds.size() != expectedDetSetSize_) {
77  throw cms::Exception("TestFailure")
78  << "ThinningDSVThingSelector::preChoose, number of elements in DetSet with id " << ds.id() << " = "
79  << ds.size() << " expected = " << expectedDetSetSize_;
80  }
81  }
82  }
83 
84  bool ThinningDSVThingSelector::choose(unsigned int iIndex, edmtest::Thing const& iItem) const {
85  // Just checking to see the element in the container got passed in OK. Not really using it.
86  // Just using %10 because it coincidentally works with the arbitrary numbers I picked, no meaning really.
87  auto const expected = slimmedValueFactor_ * (iIndex + offsetToValue_);
88  if (static_cast<unsigned>(iItem.a % 10) != static_cast<unsigned>(expected % 10)) {
89  throw cms::Exception("TestFailure") << "ThinningDSVThingSelector::choose, item content = " << iItem.a
90  << " index = " << iIndex << " expected " << expected;
91  }
92 
93  // Save the Things referenced by the Tracks
94  return keysToSave_.contains(iIndex);
95  }
96 } // namespace edmtest
97 
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
bool contains(unsigned int key) const
Definition: ThinnedRefSet.h:94
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ThinnedRefSet< edmNew::DetSetVector< Thing > > keysToSave_
static void fillPSetDescription(edm::ParameterSetDescription &desc)
HLT enums.
ThinnedRefSetMode
Definition: ThinnedRefSet.h:54
ThinningDSVThingSelector(edm::ParameterSet const &pset, edm::ConsumesCollector &&cc)
void preChoose(edm::Handle< edmNew::DetSetVector< Thing >> tc, edm::Event const &event, edm::EventSetup const &es)
edm::EDGetTokenT< TrackOfDSVThingsCollection > const trackToken_
bool choose(unsigned int iIndex, edmtest::Thing const &iItem) const
Filler fill(RefProd< C > thinned, edm::EDProductGetter const &prodGetter)
Definition: ThinnedRefSet.h:88
Definition: event.py:1