Skip to content

Commit

Permalink
Merge pull request #36321 from Dr15Jones/modernizeDPGAnalysisSiStripT…
Browse files Browse the repository at this point in the history
…ools

Use thread safe modules in DPGAnalysis/SiStripTools
  • Loading branch information
cmsbuild authored Dec 7, 2021
2 parents f8acea5 + 71fbca3 commit 1122cb3
Show file tree
Hide file tree
Showing 30 changed files with 151 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Run.h"
Expand Down Expand Up @@ -56,7 +56,7 @@
// class decleration
//

class APVCyclePhaseDebuggerFromL1TS : public edm::EDAnalyzer {
class APVCyclePhaseDebuggerFromL1TS : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
public:
explicit APVCyclePhaseDebuggerFromL1TS(const edm::ParameterSet&);
~APVCyclePhaseDebuggerFromL1TS() override;
Expand All @@ -66,6 +66,7 @@ class APVCyclePhaseDebuggerFromL1TS : public edm::EDAnalyzer {
private:
void beginRun(const edm::Run&, const edm::EventSetup&) override;
void analyze(const edm::Event&, const edm::EventSetup&) override;
void endRun(const edm::Run&, const edm::EventSetup&) override {}

// ----------member data ---------------------------

Expand Down
6 changes: 4 additions & 2 deletions DPGAnalysis/SiStripTools/plugins/APVCyclePhaseMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "TProfile.h"

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
Expand All @@ -47,7 +47,7 @@
// class decleration
//

class APVCyclePhaseMonitor : public edm::EDAnalyzer {
class APVCyclePhaseMonitor : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
public:
explicit APVCyclePhaseMonitor(const edm::ParameterSet&);
~APVCyclePhaseMonitor() override;
Expand Down Expand Up @@ -108,6 +108,8 @@ APVCyclePhaseMonitor::APVCyclePhaseMonitor(const edm::ParameterSet& iConfig)
_nevents(0) {
//now do what ever initialization is needed

usesResource(TFileService::kSharedResource);

edm::LogInfo("UsedAPVCyclePhaseCollection")
<< " APVCyclePhaseCollection " << iConfig.getParameter<edm::InputTag>("apvCyclePhaseCollection") << " used";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/one/EDProducer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Run.h"
Expand Down Expand Up @@ -51,7 +51,7 @@
// class decleration
//

class APVCyclePhaseProducerFromL1ABC : public edm::EDProducer {
class APVCyclePhaseProducerFromL1ABC : public edm::one::EDProducer<edm::one::WatchRuns> {
public:
explicit APVCyclePhaseProducerFromL1ABC(const edm::ParameterSet&);
~APVCyclePhaseProducerFromL1ABC() override;
Expand Down
5 changes: 3 additions & 2 deletions DPGAnalysis/SiStripTools/plugins/APVShotsAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <string>

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/ESWatcher.h"

#include "FWCore/Framework/interface/Event.h"
Expand Down Expand Up @@ -66,7 +66,7 @@
// class decleration
//

class APVShotsAnalyzer : public edm::EDAnalyzer {
class APVShotsAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources, edm::one::WatchRuns> {
public:
explicit APVShotsAnalyzer(const edm::ParameterSet&);
~APVShotsAnalyzer() override;
Expand Down Expand Up @@ -153,6 +153,7 @@ APVShotsAnalyzer::APVShotsAnalyzer(const edm::ParameterSet& iConfig)
_nevents(0),
_rhm(consumesCollector()) {
//now do what ever initialization is needed
usesResource(TFileService::kSharedResource);

if (!_zs)
_suffix += "_notZS";
Expand Down
34 changes: 13 additions & 21 deletions DPGAnalysis/SiStripTools/plugins/APVShotsFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

// system include files
#include <memory>
#include <atomic>

// user include files
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDFilter.h"
#include "FWCore/Framework/interface/ESWatcher.h"
#include "FWCore/Framework/interface/global/EDFilter.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
Expand Down Expand Up @@ -53,34 +53,31 @@
// class declaration
//

class APVShotsFilter : public edm::EDFilter {
class APVShotsFilter : public edm::global::EDFilter<> {
public:
explicit APVShotsFilter(const edm::ParameterSet&);
~APVShotsFilter() override;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
bool filter(edm::Event&, const edm::EventSetup&) override;
bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
void endJob() override;

void updateDetCabling(const SiStripDetCablingRcd& iRcd);
// ----------member data ---------------------------

edm::EDGetTokenT<EventWithHistory> heToken_;
edm::EDGetTokenT<APVCyclePhaseCollection> apvphaseToken_;
edm::EDGetTokenT<edm::DetSetVector<SiStripDigi> > digisToken_;

bool _selectAPVshots;
const bool _selectAPVshots;

bool _zs;
int _nevents;
const bool _zs;
mutable std::atomic<int> _nevents;

// DetCabling
bool _useCabling;
edm::ESWatcher<SiStripDetCablingRcd> _detCablingWatcher;
edm::ESGetToken<SiStripDetCabling, SiStripDetCablingRcd> _detCablingToken;
const SiStripDetCabling* _detCabling = nullptr; //!< The cabling object.
const bool _useCabling;
const edm::ESGetToken<SiStripDetCabling, SiStripDetCablingRcd> _detCablingToken;
};

//
Expand All @@ -99,8 +96,6 @@ APVShotsFilter::APVShotsFilter(const edm::ParameterSet& iConfig)
_zs(iConfig.getUntrackedParameter<bool>("zeroSuppressed", true)),
_nevents(0),
_useCabling(iConfig.getUntrackedParameter<bool>("useCabling", true)),
_detCablingWatcher(_useCabling ? decltype(_detCablingWatcher){this, &APVShotsFilter::updateDetCabling}
: decltype(_detCablingWatcher){}),
_detCablingToken(_useCabling ? decltype(_detCablingToken){esConsumes()} : decltype(_detCablingToken){}) {
//now do what ever initialization is needed
edm::InputTag digicollection = iConfig.getParameter<edm::InputTag>("digiCollection");
Expand All @@ -115,21 +110,20 @@ APVShotsFilter::APVShotsFilter(const edm::ParameterSet& iConfig)
APVShotsFilter::~APVShotsFilter() {
// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)
if (_detCabling)
_detCabling = nullptr;
}

//
// member functions
//

// ------------ method called on each new Event ------------
bool APVShotsFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
bool APVShotsFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
using namespace edm;

const SiStripDetCabling* _detCabling = nullptr; //!< The cabling object.
if (_useCabling) {
//retrieve cabling
_detCablingWatcher.check(iSetup);
_detCabling = &iSetup.getData(_detCablingToken);
}
_nevents++;

Expand Down Expand Up @@ -223,9 +217,7 @@ bool APVShotsFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
}

// ------------ method called once each job just after ending the event loop ------------
void APVShotsFilter::endJob() { edm::LogInfo("APVShotsFilter") << _nevents << " analyzed events"; }

void APVShotsFilter::updateDetCabling(const SiStripDetCablingRcd& iRcd) { _detCabling = &iRcd.get(_detCablingToken); }
void APVShotsFilter::endJob() { edm::LogInfo("APVShotsFilter") << _nevents.load() << " analyzed events"; }

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void APVShotsFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
Expand Down
5 changes: 3 additions & 2 deletions DPGAnalysis/SiStripTools/plugins/BigEventsDebugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Run.h"
Expand Down Expand Up @@ -53,7 +53,7 @@
//

template <class T>
class BigEventsDebugger : public edm::EDAnalyzer {
class BigEventsDebugger : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
explicit BigEventsDebugger(const edm::ParameterSet&);
~BigEventsDebugger() override;
Expand Down Expand Up @@ -100,6 +100,7 @@ BigEventsDebugger<T>::BigEventsDebugger(const edm::ParameterSet& iConfig)

{
//now do what ever initialization is needed
usesResource(TFileService::kSharedResource);

std::vector<edm::ParameterSet> selconfigs = iConfig.getParameter<std::vector<edm::ParameterSet> >("selections");

Expand Down
5 changes: 3 additions & 2 deletions DPGAnalysis/SiStripTools/plugins/CommonModeAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <string>

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/ESWatcher.h"

#include "FWCore/Framework/interface/Event.h"
Expand Down Expand Up @@ -62,7 +62,7 @@
// class decleration
//

class CommonModeAnalyzer : public edm::EDAnalyzer {
class CommonModeAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources, edm::one::WatchRuns> {
public:
explicit CommonModeAnalyzer(const edm::ParameterSet&);
~CommonModeAnalyzer() override;
Expand Down Expand Up @@ -137,6 +137,7 @@ CommonModeAnalyzer::CommonModeAnalyzer(const edm::ParameterSet& iConfig)
m_detCablingWatcher(this, &CommonModeAnalyzer::updateDetCabling),
m_detCablingToken(esConsumes()) {
//now do what ever initialization is needed
usesResource(TFileService::kSharedResource);

edm::Service<TFileService> tfserv;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/global/EDProducer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Run.h"
Expand All @@ -41,26 +41,23 @@
// class decleration
//

class ConfigurableAPVCyclePhaseProducer : public edm::EDProducer {
class ConfigurableAPVCyclePhaseProducer : public edm::global::EDProducer<edm::RunCache<APVCyclePhaseCollection>> {
public:
explicit ConfigurableAPVCyclePhaseProducer(const edm::ParameterSet&);
~ConfigurableAPVCyclePhaseProducer() override;

private:
void beginJob() override;
void beginRun(const edm::Run&, const edm::EventSetup&) override;
void produce(edm::Event&, const edm::EventSetup&) override;
void endJob() override;
std::shared_ptr<APVCyclePhaseCollection> globalBeginRun(const edm::Run&, const edm::EventSetup&) const override;
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
void globalEndRun(edm::Run const&, edm::EventSetup const&) const override {}

// ----------member data ---------------------------

const std::vector<std::string> _defpartnames;
const std::vector<int> _defphases;

std::map<int, std::vector<std::string> > _runpartnames;
std::map<int, std::vector<int> > _runphases;

APVCyclePhaseCollection _currapvphases;
std::map<int, std::vector<std::string>> _runpartnames;
std::map<int, std::vector<int>> _runphases;
};

//
Expand All @@ -75,9 +72,8 @@ class ConfigurableAPVCyclePhaseProducer : public edm::EDProducer {
// constructors and destructor
//
ConfigurableAPVCyclePhaseProducer::ConfigurableAPVCyclePhaseProducer(const edm::ParameterSet& iConfig)
: _defpartnames(iConfig.getParameter<std::vector<std::string> >("defaultPartitionNames")),
_defphases(iConfig.getParameter<std::vector<int> >("defaultPhases")),
_currapvphases() {
: _defpartnames(iConfig.getParameter<std::vector<std::string>>("defaultPartitionNames")),
_defphases(iConfig.getParameter<std::vector<int>>("defaultPhases")) {
produces<APVCyclePhaseCollection, edm::InEvent>();

//now do what ever other initialization is needed
Expand All @@ -88,12 +84,12 @@ ConfigurableAPVCyclePhaseProducer::ConfigurableAPVCyclePhaseProducer(const edm::
<< " Inconsistent default phases/partitions vector sizes: " << _defphases.size() << " " << _defpartnames.size();
}

std::vector<edm::ParameterSet> vps(iConfig.getParameter<std::vector<edm::ParameterSet> >("runPhases"));
std::vector<edm::ParameterSet> vps(iConfig.getParameter<std::vector<edm::ParameterSet>>("runPhases"));

for (std::vector<edm::ParameterSet>::const_iterator ps = vps.begin(); ps != vps.end(); ps++) {
_runphases[ps->getParameter<int>("runNumber")] = ps->getUntrackedParameter<std::vector<int> >("phases", _defphases);
_runphases[ps->getParameter<int>("runNumber")] = ps->getUntrackedParameter<std::vector<int>>("phases", _defphases);
_runpartnames[ps->getParameter<int>("runNumber")] =
ps->getUntrackedParameter<std::vector<std::string> >("partitions", _defpartnames);
ps->getUntrackedParameter<std::vector<std::string>>("partitions", _defpartnames);

if (_runphases[ps->getParameter<int>("runNumber")].size() <
_runpartnames[ps->getParameter<int>("runNumber")].size()) {
Expand All @@ -116,18 +112,19 @@ ConfigurableAPVCyclePhaseProducer::~ConfigurableAPVCyclePhaseProducer() {
//

// ------------ method called to produce the data ------------
void ConfigurableAPVCyclePhaseProducer::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
std::shared_ptr<APVCyclePhaseCollection> ConfigurableAPVCyclePhaseProducer::globalBeginRun(
const edm::Run& iRun, const edm::EventSetup& iSetup) const {
using namespace edm;

_currapvphases.get().clear();
auto currapvphases = std::make_shared<APVCyclePhaseCollection>();

// fill phase map

const std::map<int, std::vector<std::string> >& _crunpartnames = _runpartnames;
const std::map<int, std::vector<int> >& _crunphases = _runphases;
const std::map<int, std::vector<std::string>>& _crunpartnames = _runpartnames;
const std::map<int, std::vector<int>>& _crunphases = _runphases;

std::map<int, std::vector<int> >::const_iterator trphases = _crunphases.find(iRun.run());
std::map<int, std::vector<std::string> >::const_iterator trpartnames = _crunpartnames.find(iRun.run());
std::map<int, std::vector<int>>::const_iterator trphases = _crunphases.find(iRun.run());
std::map<int, std::vector<std::string>>::const_iterator trpartnames = _crunpartnames.find(iRun.run());

std::vector<int> phases = _defphases;
std::vector<std::string> partnames = _defpartnames;
Expand All @@ -147,29 +144,27 @@ void ConfigurableAPVCyclePhaseProducer::beginRun(const edm::Run& iRun, const edm

for (unsigned int ipart = 0; ipart < partnames.size(); ++ipart) {
if (phases[ipart] >= 0) {
_currapvphases.get()[partnames[ipart]] = phases[ipart];
currapvphases->get()[partnames[ipart]] = phases[ipart];
}
}

for (std::map<std::string, int>::const_iterator it = _currapvphases.get().begin(); it != _currapvphases.get().end();
for (std::map<std::string, int>::const_iterator it = currapvphases->get().begin(); it != currapvphases->get().end();
it++) {
edm::LogInfo("APVCyclePhaseProducerDebug") << "partition " << it->first << " phase " << it->second;
}
return currapvphases;
}

void ConfigurableAPVCyclePhaseProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
void ConfigurableAPVCyclePhaseProducer::produce(edm::StreamID,
edm::Event& iEvent,
const edm::EventSetup& iSetup) const {
using namespace edm;

std::unique_ptr<APVCyclePhaseCollection> apvphases(new APVCyclePhaseCollection(_currapvphases));
std::unique_ptr<APVCyclePhaseCollection> apvphases =
std::make_unique<APVCyclePhaseCollection>(*runCache(iEvent.getRun().index()));

iEvent.put(std::move(apvphases));
}

// ------------ method called once each job just before starting event loop ------------
void ConfigurableAPVCyclePhaseProducer::beginJob() {}

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

//define this as a plug-in
DEFINE_FWK_MODULE(ConfigurableAPVCyclePhaseProducer);
Loading

0 comments on commit 1122cb3

Please sign in to comment.