CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
UniqueObjectSelector< T > Class Template Reference

#include <UniqueObjectSelector.h>

Inheritance diagram for UniqueObjectSelector< T >:
edm::EDFilter edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 UniqueObjectSelector (const edm::ParameterSet &)
 
 ~UniqueObjectSelector ()
 
- Public Member Functions inherited from edm::EDFilter
 EDFilter ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDFilter ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Types

typedef std::vector< TObjectCollection
 
typedef std::vector
< edm::InputTag
vInputTag
 

Private Member Functions

bool filter (edm::Event &, const edm::EventSetup &)
 

Private Attributes

StringCutObjectSelector< T > * cut_
 
bool filter_
 
StringObjectFunction< T > * rank_
 
vInputTag src_
 

Additional Inherited Members

- Public Types inherited from edm::EDFilter
typedef EDFilter ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDFilter
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- 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

template<typename T>
class UniqueObjectSelector< T >

Select unique object. The objects contained in the input collection are first filtered by cuts and then ranked according to user-defined criteria. The highest ranked object passing all cuts is stored in the output collection.

Author
Christian Veelken, LLR
Version
Revision:
1.1
Id:
UniqueObjectSelector.h,v 1.1 2012/10/14 12:22:24 veelken Exp

Definition at line 30 of file UniqueObjectSelector.h.

Member Typedef Documentation

template<typename T >
typedef std::vector<T> UniqueObjectSelector< T >::ObjectCollection
private

Definition at line 47 of file UniqueObjectSelector.h.

template<typename T >
typedef std::vector<edm::InputTag> UniqueObjectSelector< T >::vInputTag
private

Definition at line 39 of file UniqueObjectSelector.h.

Constructor & Destructor Documentation

template<typename T >
UniqueObjectSelector< T >::UniqueObjectSelector ( const edm::ParameterSet cfg)
explicit

Definition at line 4 of file UniqueObjectSelector.cc.

References UniqueObjectSelector< T >::cut_, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), UniqueObjectSelector< T >::filter_, edm::ParameterSet::getParameter(), UniqueObjectSelector< T >::rank_, UniqueObjectSelector< T >::src_, and AlCaHLTBitMon_QueryRunRegistry::string.

5  : cut_(0),
6  rank_(0)
7 {
8  if ( cfg.existsAs<edm::InputTag>("src") ) src_.push_back(cfg.getParameter<edm::InputTag>("src"));
9  else src_ = cfg.getParameter<vInputTag>("src");
10 
11  if ( cfg.exists("cut" ) ) cut_ = new StringCutObjectSelector<T>(cfg.getParameter<std::string>("cut"));
13 
14  filter_ = cfg.getParameter<bool>("filter");
15 
16  produces<ObjectCollection>();
17 }
T getParameter(std::string const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:185
std::vector< edm::InputTag > vInputTag
bool exists(std::string const &parameterName) const
checks if a parameter exists
StringObjectFunction< T > * rank_
StringCutObjectSelector< T > * cut_
template<typename T >
UniqueObjectSelector< T >::~UniqueObjectSelector ( )

Definition at line 20 of file UniqueObjectSelector.cc.

21 {
22  delete cut_;
23  delete rank_;
24 }
StringObjectFunction< T > * rank_
StringCutObjectSelector< T > * cut_

Member Function Documentation

template<typename T >
bool UniqueObjectSelector< T >::filter ( edm::Event evt,
const edm::EventSetup es 
)
privatevirtual

Implements edm::EDFilter.

Definition at line 46 of file UniqueObjectSelector.cc.

References edm::Event::getByLabel(), dbtoconf::object, edm::Event::put(), and python.multivaluedict::sort().

47 {
48  std::vector<objectWithRank<T> > selectedObjects;
49 
50  // check which objects pass cuts
51  for ( vInputTag::const_iterator src_i = src_.begin();
52  src_i != src_.end(); ++src_i ) {
54  evt.getByLabel(*src_i, objects);
55  for ( typename ObjectCollection::const_iterator object = objects->begin();
56  object != objects->end(); ++object ) {
57  if ( !cut_ || (*cut_)(*object) ) { // either no cut defined or object passes cut
58  objectWithRank<T> selectedObject;
59  selectedObject.object_ = &(*object);
60  selectedObject.rank_ = (*rank_)(*object);
61  selectedObjects.push_back(selectedObject);
62  }
63  }
64  }
65 
66  // sort collection of selected objects by rank
67  higherRankT<T> higherRank;
68  std::sort(selectedObjects.begin(), selectedObjects.end(), higherRank);
69 
70  // store in output collection the object which passes selection and is of highest rank
71  std::auto_ptr<ObjectCollection> objects_output(new ObjectCollection());
72  if ( selectedObjects.size() > 0 ) objects_output->push_back(*selectedObjects.front().object_);
73 
74  evt.put(objects_output);
75 
76  if ( filter_ ) return (objects_output->size() > 0);
77  else return true;
78 }
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:405
list object
Definition: dbtoconf.py:77
StringCutObjectSelector< T > * cut_
std::vector< T > ObjectCollection

Member Data Documentation

template<typename T >
StringCutObjectSelector<T>* UniqueObjectSelector< T >::cut_
private
template<typename T >
bool UniqueObjectSelector< T >::filter_
private
template<typename T >
StringObjectFunction<T>* UniqueObjectSelector< T >::rank_
private
template<typename T >
vInputTag UniqueObjectSelector< T >::src_
private