CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
CandViewRefRandomSelector Class Reference
Inheritance diagram for CandViewRefRandomSelector:
edm::EDFilter edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 CandViewRefRandomSelector (const edm::ParameterSet &pset)
 
bool filter (edm::Event &, const edm::EventSetup &) override
 
- Public Member Functions inherited from edm::EDFilter
 EDFilter ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDFilter () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Attributes

unsigned int choose_
 
bool filter_
 
TRandom3 randy_
 
unsigned int seed_
 
edm::InputTag src_
 

Additional Inherited Members

- Public Types inherited from edm::EDFilter
typedef EDFilter ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDFilter
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 25 of file CandViewRefRandomSelector.cc.

Constructor & Destructor Documentation

CandViewRefRandomSelector::CandViewRefRandomSelector ( const edm::ParameterSet pset)
explicit

Definition at line 37 of file CandViewRefRandomSelector.cc.

References choose_, edm::ParameterSet::exists(), filter_, edm::ParameterSet::getParameter(), randy_, seed_, and src_.

38  {
39  src_ = pset.getParameter<edm::InputTag>("src");
40  choose_ = pset.getParameter<unsigned int>("choose");
41  filter_ = pset.getParameter<bool>("filter");
42  seed_ = pset.exists("seed") ? pset.getParameter<unsigned int>("seed") : 123;
43  randy_ = TRandom3(seed_);
44  produces<reco::CandidateBaseRefVector>();
45 }
T getParameter(std::string const &) const
bool exists(std::string const &parameterName) const
checks if a parameter exists

Member Function Documentation

bool CandViewRefRandomSelector::filter ( edm::Event evt,
const edm::EventSetup es 
)
override

Definition at line 47 of file CandViewRefRandomSelector.cc.

References egammaForCoreTracking_cff::cands, choose_, DEFINE_FWK_MODULE, filter_, edm::Event::getByLabel(), mps_fire::i, eostools::move(), convertSQLitetoXML_cfg::output, edm::Event::put(), randy_, and src_.

48  {
50  evt.getByLabel(src_, cands);
51  auto output = std::make_unique<reco::CandidateBaseRefVector>(cands);
52  // If we don't have enough elements to select, just copy what we have
53  if (cands->size() <= choose_) {
54  for (size_t i = 0; i < cands->size(); ++i)
55  output->push_back(cands->refAt(i));
56  } else {
57  for (size_t i = 0; i < cands->size() && output->size() < choose_; ++i) {
58  // based on http://stackoverflow.com/questions/48087/
59  // select-a-random-n-elements-from-listt-in-c/48089#48089
60  double selectionProb =
61  (choose_ - output->size())*1.0/(cands->size() - i);
62  // throw a number to see if we select this element
63  if (randy_.Rndm() < selectionProb)
64  output->push_back(cands->refAt(i));
65  }
66  }
67  size_t outputSize = output->size();
68  evt.put(std::move(output));
69  return ( !filter_ || outputSize );
70 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:475
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

unsigned int CandViewRefRandomSelector::choose_
private

Definition at line 31 of file CandViewRefRandomSelector.cc.

Referenced by CandViewRefRandomSelector(), and filter().

bool CandViewRefRandomSelector::filter_
private

Definition at line 33 of file CandViewRefRandomSelector.cc.

Referenced by CandViewRefRandomSelector(), and filter().

TRandom3 CandViewRefRandomSelector::randy_
private

Definition at line 34 of file CandViewRefRandomSelector.cc.

Referenced by CandViewRefRandomSelector(), and filter().

unsigned int CandViewRefRandomSelector::seed_
private

Definition at line 32 of file CandViewRefRandomSelector.cc.

Referenced by CandViewRefRandomSelector().

edm::InputTag CandViewRefRandomSelector::src_
private

Definition at line 30 of file CandViewRefRandomSelector.cc.

Referenced by CandViewRefRandomSelector(), and filter().