CMS 3D CMS Logo

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