Skip to content

Commit

Permalink
Merge pull request #4010 from ktf/backport-3966
Browse files Browse the repository at this point in the history
Allow a SingleObjectSelector to be a stream::EDFilter
  • Loading branch information
davidlange6 committed Jun 3, 2014
2 parents 860f02b + fea11b6 commit 0a28283
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 54 deletions.
6 changes: 3 additions & 3 deletions CommonTools/CandAlgos/interface/CandDecaySelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ namespace helper {
std::auto_ptr<reco::CandidateCollection> selCands_;
};

template<>
struct StoreManagerTrait<reco::CandidateCollection> {
template<typename EdmFilter>
struct StoreManagerTrait<reco::CandidateCollection, EdmFilter> {
typedef CandDecayStoreManager type;
typedef ObjectSelectorBase<reco::CandidateCollection> base;
typedef ObjectSelectorBase<reco::CandidateCollection, EdmFilter> base;
};

}
Expand Down
4 changes: 2 additions & 2 deletions CommonTools/RecoAlgos/plugins/VertexSelector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"

typedef SingleObjectSelector<
using VertexSelector = SingleObjectSelectorStream<
reco::VertexCollection,
StringCutObjectSelector<reco::Vertex>
> VertexSelector;
>;

DEFINE_FWK_MODULE(VertexSelector);
4 changes: 2 additions & 2 deletions CommonTools/UtilAlgos/interface/NullPostProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#include "FWCore/Framework/interface/ConsumesCollector.h"
namespace helper {

template<typename OutputCollection>
template<typename OutputCollection, typename EdmFilter=edm::EDFilter>
struct NullPostProcessor {
NullPostProcessor( const edm::ParameterSet & iConfig, edm::ConsumesCollector && iC ) :
NullPostProcessor( iConfig ) { }
NullPostProcessor( const edm::ParameterSet & iConfig ) { }
void init( edm::EDFilter & ) { }
void init( EdmFilter & ) { }
void process( edm::OrphanHandle<OutputCollection>, edm::Event & ) { }
};

Expand Down
13 changes: 7 additions & 6 deletions CommonTools/UtilAlgos/interface/ObjectSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,22 @@
template<typename Selector,
typename OutputCollection = typename ::helper::SelectedOutputCollectionTrait<typename Selector::collection>::type,
typename SizeSelector = NonNullNumberSelector,
typename PostProcessor = ::helper::NullPostProcessor<OutputCollection>,
typename StoreManager = typename ::helper::StoreManagerTrait<OutputCollection>::type,
typename Base = typename ::helper::StoreManagerTrait<OutputCollection>::base,
typename PostProcessor = ::helper::NullPostProcessor<OutputCollection, edm::EDFilter>,
typename StoreManager = typename ::helper::StoreManagerTrait<OutputCollection, edm::EDFilter>::type,
typename Base = typename ::helper::StoreManagerTrait<OutputCollection, edm::EDFilter>::base,
typename Init = typename ::reco::modules::EventSetupInit<Selector>::type
>
class ObjectSelector : public Base {
public:
/// constructor
// ObjectSelector()=default;
explicit ObjectSelector(const edm::ParameterSet & cfg) :
Base(cfg),
srcToken_(edm::EDFilter::consumes<typename Selector::collection>(cfg.template getParameter<edm::InputTag>("src"))),
srcToken_( this-> template consumes<typename Selector::collection>(cfg.template getParameter<edm::InputTag>("src"))),
filter_(false),
selector_(cfg, edm::EDFilter::consumesCollector()),
selector_(cfg, this->consumesCollector()),
sizeSelector_(reco::modules::make<SizeSelector>(cfg)),
postProcessor_(cfg, edm::EDFilter::consumesCollector()) {
postProcessor_(cfg, this->consumesCollector()) {
const std::string filter("filter");
std::vector<std::string> bools = cfg.template getParameterNamesForType<bool>();
bool found = std::find(bools.begin(), bools.end(), filter) != bools.end();
Expand Down
4 changes: 2 additions & 2 deletions CommonTools/UtilAlgos/interface/SingleObjectRefSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ template<typename InputType, typename Selector,
typename OutputCollection = typename ::helper::SelectedOutputCollectionTrait<edm::View<InputType> >::type,
typename StoreContainer = typename ::helper::StoreContainerTrait<OutputCollection>::type,
typename PostProcessor = ::helper::NullPostProcessor<OutputCollection>,
typename StoreManager = typename ::helper::StoreManagerTrait<OutputCollection>::type,
typename Base = typename ::helper::StoreManagerTrait<OutputCollection>::base,
typename StoreManager = typename ::helper::StoreManagerTrait<OutputCollection, edm::EDFilter>::type,
typename Base = typename ::helper::StoreManagerTrait<OutputCollection, edm::EDFilter>::base,
typename RefAdder = typename ::helper::SelectionAdderTrait<edm::View<InputType>, StoreContainer>::type>
class SingleObjectRefSelector :
public ObjectSelector<SingleElementCollectionRefSelector<InputType, Selector, OutputCollection, StoreContainer, RefAdder>,
Expand Down
56 changes: 49 additions & 7 deletions CommonTools/UtilAlgos/interface/SingleObjectSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,64 @@
#include "CommonTools/UtilAlgos/interface/SelectionAdderTrait.h"
#include "CommonTools/UtilAlgos/interface/SingleElementCollectionSelector.h"



/* the following is just to ease transition
* grep -r SingleObjectSelector * | wc
* 209 540 22532
*/


template<typename InputCollection, typename Selector,
typename EdmFilter,
typename OutputCollection = typename ::helper::SelectedOutputCollectionTrait<InputCollection>::type,
typename StoreContainer = typename ::helper::StoreContainerTrait<OutputCollection>::type,
typename PostProcessor = ::helper::NullPostProcessor<OutputCollection>,
typename StoreManager = typename ::helper::StoreManagerTrait<OutputCollection>::type,
typename Base = typename ::helper::StoreManagerTrait<OutputCollection>::base,
typename PostProcessor = ::helper::NullPostProcessor<OutputCollection, EdmFilter>,
typename StoreManager = typename ::helper::StoreManagerTrait<OutputCollection, EdmFilter>::type,
typename Base = typename ::helper::StoreManagerTrait<OutputCollection, EdmFilter>::base,
typename RefAdder = typename ::helper::SelectionAdderTrait<InputCollection, StoreContainer>::type>
class SingleObjectSelector :
class SingleObjectSelectorBase :
public ObjectSelector<SingleElementCollectionSelector<InputCollection, Selector, OutputCollection, StoreContainer, RefAdder>,
OutputCollection, NonNullNumberSelector, PostProcessor, StoreManager, Base> {
public:
explicit SingleObjectSelector( const edm::ParameterSet & cfg ) :
// SingleObjectSelectorBase() = default;
explicit SingleObjectSelectorBase( const edm::ParameterSet & cfg ) :
ObjectSelector<SingleElementCollectionSelector<InputCollection, Selector, OutputCollection, StoreContainer, RefAdder>,
OutputCollection, NonNullNumberSelector, PostProcessor>( cfg ) { }
virtual ~SingleObjectSelector() { }
OutputCollection, NonNullNumberSelector, PostProcessor, StoreManager, Base>( cfg ) { }
virtual ~SingleObjectSelectorBase() { }
};



template<typename InputCollection, typename Selector,
typename OutputCollection = typename ::helper::SelectedOutputCollectionTrait<InputCollection>::type,
typename StoreContainer = typename ::helper::StoreContainerTrait<OutputCollection>::type,
typename PostProcessor = ::helper::NullPostProcessor<OutputCollection, edm::EDFilter> >
using SingleObjectSelectorLegacy = SingleObjectSelectorBase<InputCollection,Selector, edm::EDFilter,
OutputCollection,StoreContainer,PostProcessor
>;



#include "FWCore/Framework/interface/stream/EDFilter.h"

template<typename InputCollection, typename Selector,
typename OutputCollection = typename ::helper::SelectedOutputCollectionTrait<InputCollection>::type,
typename StoreContainer = typename ::helper::StoreContainerTrait<OutputCollection>::type,
typename PostProcessor = ::helper::NullPostProcessor<OutputCollection, edm::stream::EDFilter<> > >
using SingleObjectSelectorStream = SingleObjectSelectorBase<InputCollection,Selector, edm::stream::EDFilter<>,
OutputCollection,StoreContainer,PostProcessor
>;


template<typename InputCollection, typename Selector,
typename OutputCollection = typename ::helper::SelectedOutputCollectionTrait<InputCollection>::type,
typename StoreContainer = typename ::helper::StoreContainerTrait<OutputCollection>::type,
typename PostProcessor = ::helper::NullPostProcessor<OutputCollection, edm::stream::EDFilter<> > >
using SingleObjectSelector = SingleObjectSelectorStream<InputCollection,Selector,
OutputCollection,StoreContainer,PostProcessor>;



#endif

40 changes: 8 additions & 32 deletions CommonTools/UtilAlgos/interface/StoreManagerTrait.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,39 +63,15 @@ namespace helper {
}
};

/*
template<typename OutputCollection, typename InputCollection>
struct OutputCollectionCreator {
static std::auto_ptr<OutputCollection> createNewCollection( const edm::Handle<InputCollection> & ) {
return std::auto_ptr<OutputCollection>( new OutputCollection );
}
};

template<typename T, typename InputCollection>
struct OutputCollectionCreator<edm::RefToBaseVector<T>, InputCollection> {
static std::auto_ptr<edm::RefToBaseVector<T> > createNewCollection( const edm::Handle<InputCollection> & h ) {
return std::auto_ptr<edm::RefToBaseVector<T> >( new edm::RefToBaseVector<T>(h) );
}
};
*/

/*
template<typename T1, typename T2>
struct OutputCollectionCreator<RefToBaseVector<T1>, RefToBaseVector<T2> > {
static RefToBaseVector<T1> * createNewCollection( const edm::Handle<RefToBaseVector<T2> > & h ) {
return new RefToBaseVector<T1>(h);
}
};
*/

template<typename OutputCollection,
typename ClonePolicy = IteratorToObjectConverter<OutputCollection> >
struct CollectionStoreManager {
typedef OutputCollection collection;
template<typename C>
CollectionStoreManager( const edm::Handle<C> & h ) :
selected_( new OutputCollection ) {
// selected_ = OutputCollectionCreator<OutputCollection, C>::createNewCollection(h);
selected_( new OutputCollection ) {
}
template<typename I>
void cloneAndStore( const I & begin, const I & end, edm::Event & ) {
Expand All @@ -113,17 +89,17 @@ namespace helper {
std::auto_ptr<collection> selected_;
};

template<typename OutputCollection>
struct ObjectSelectorBase : public edm::EDFilter {
ObjectSelectorBase( const edm::ParameterSet & cfg ) {
produces<OutputCollection>();
template<typename OutputCollection, typename EdmFilter>
struct ObjectSelectorBase : public EdmFilter {
ObjectSelectorBase( const edm::ParameterSet &) {
this-> template produces<OutputCollection>();
}
};

template<typename OutputCollection>
template<typename OutputCollection, typename EdmFilter=edm::EDFilter>
struct StoreManagerTrait {
typedef CollectionStoreManager<OutputCollection> type;
typedef ObjectSelectorBase<OutputCollection> base;
using type = CollectionStoreManager<OutputCollection>;
using base = ObjectSelectorBase<OutputCollection, EdmFilter>;
};

}
Expand Down
2 changes: 2 additions & 0 deletions Validation/RecoTrack/plugins/SealModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ DEFINE_EDM_PLUGIN(MTVHistoProducerAlgoFactory, MTVHistoProducerAlgoForTracker,
// TPSelectorForFakeRate ;
// DEFINE_FWK_MODULE( TPSelectorForFakeRate );

/*
#include "CommonTools/UtilAlgos/interface/StringCutObjectSelector.h"
#include "CommonTools/UtilAlgos/interface/SingleObjectSelector.h"
#include "DataFormats/TrackReco/interface/Track.h"
Expand All @@ -63,3 +64,4 @@ typedef SingleObjectSelector<
> TrackSelectorForValidation;
DEFINE_FWK_MODULE(TrackSelectorForValidation);
*/
14 changes: 14 additions & 0 deletions Validation/RecoTrack/plugins/SealModule2.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "FWCore/PluginManager/interface/ModuleDef.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "CommonTools/UtilAlgos/interface/StringCutObjectSelector.h"
#include "CommonTools/UtilAlgos/interface/SingleObjectSelector.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"

typedef SingleObjectSelector<
std::vector<reco::Track>,
StringCutObjectSelector<reco::Track>
> TrackSelectorForValidation;

DEFINE_FWK_MODULE(TrackSelectorForValidation);

0 comments on commit 0a28283

Please sign in to comment.