Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ClusterMultiplicityFilter multithread safe #12024

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -4,23 +4,26 @@
#include <string>

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDFilter.h"
#include "FWCore/Framework/interface/stream/EDFilter.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
#include "DataFormats/Common/interface/DetSetVectorNew.h"


class ClusterMultiplicityFilter : public edm::EDFilter {
class ClusterMultiplicityFilter : public edm::stream::EDFilter<> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could easily be converted to a edm::global::EDFilter<> which would safe memory and be faster for the framework.

public:
explicit ClusterMultiplicityFilter(const edm::ParameterSet&);
~ClusterMultiplicityFilter();

private:
virtual void beginJob() ;
virtual bool filter(edm::Event&, const edm::EventSetup&);
virtual void endJob() ;

unsigned int maxNumberOfClusters_;
std::string clusterCollectionLabel_;
virtual bool filter(edm::Event&, const edm::EventSetup&) override;

const unsigned int maxNumberOfClusters_;
const edm::InputTag clusterCollectionTag_;

edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster> > clusters_;

};

Expand Down
@@ -1,8 +1,8 @@
import FWCore.ParameterSet.Config as cms

tifClusterFilter = cms.EDFilter("ClusterMultiplicityFilter",
MaxNumberOfClusters = cms.untracked.uint32(300),
ClusterCollectionLabel = cms.untracked.string('siStripClusters')
MaxNumberOfClusters = cms.uint32(300),
ClusterCollection = cms.InputTag('siStripClusters')
)


Expand Up @@ -15,19 +15,15 @@
#include <memory>

#include "RecoLocalTracker/SubCollectionProducers/interface/ClusterMultiplicityFilter.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
#include "DataFormats/Common/interface/DetSetVector.h"

#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"


ClusterMultiplicityFilter::ClusterMultiplicityFilter(const edm::ParameterSet& iConfig)
ClusterMultiplicityFilter::ClusterMultiplicityFilter(const edm::ParameterSet& iConfig) :
maxNumberOfClusters_(iConfig.getParameter<unsigned int>("MaxNumberOfClusters")),
clusterCollectionTag_(iConfig.getParameter<edm::InputTag>("ClusterCollection"))
{
maxNumberOfClusters_ = iConfig.getUntrackedParameter<unsigned int>("MaxNumberOfClusters");
clusterCollectionLabel_ = iConfig.getUntrackedParameter<std::string>("ClusterCollectionLabel");
clusters_ = consumes<edmNew::DetSetVector<SiStripCluster> >(clusterCollectionTag_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make this const as well if you move its initialization to before the {.

}


Expand All @@ -40,22 +36,22 @@ bool ClusterMultiplicityFilter::filter(edm::Event& iEvent, const edm::EventSetup

bool result = true;

const edm::DetSetVector<SiStripCluster> *clusters = 0;
edm::Handle<edm::DetSetVector<SiStripCluster> > clusterHandle;
iEvent.getByLabel(clusterCollectionLabel_,clusterHandle);
const edmNew::DetSetVector<SiStripCluster> *clusters = 0;
edm::Handle<edmNew::DetSetVector<SiStripCluster> > clusterHandle;
iEvent.getByToken(clusters_,clusterHandle);
if( !clusterHandle.isValid() ) {
throw cms::Exception("CorruptData")
<< "ClusterMultiplicityFilter requires collection <edm::DetSetVector<SiStripCluster> with label " << clusterCollectionLabel_ << std::endl;
<< "ClusterMultiplicityFilter requires collection <edm::DetSetVector<SiStripCluster> with label " << clusterCollectionTag_.label() << std::endl;
}

clusters = clusterHandle.product();
const edm::DetSetVector<SiStripCluster>& input = *clusters;
const edmNew::DetSetVector<SiStripCluster>& input = *clusters;

unsigned int totalClusters = 0;

//loop over detectors
for (edm::DetSetVector<SiStripCluster>::const_iterator DSViter=input.begin(); DSViter!=input.end();DSViter++ ) {
totalClusters+=DSViter->data.size();
for (edmNew::DetSetVector<SiStripCluster>::const_iterator DSViter=input.begin(); DSViter!=input.end();DSViter++ ) {
totalClusters+=DSViter->size();
}


Expand All @@ -66,13 +62,3 @@ bool ClusterMultiplicityFilter::filter(edm::Event& iEvent, const edm::EventSetup

return result;
}


void ClusterMultiplicityFilter::beginJob() {
}


// ------------ method called once each job just after ending the event loop ------------
void ClusterMultiplicityFilter::endJob() {
}