Skip to content

Commit

Permalink
Merge pull request #34989 from makortel/esconsumesSimPPS
Browse files Browse the repository at this point in the history
Migrate some modules in SimPPS to esConsumes
  • Loading branch information
cmsbuild authored Aug 31, 2021
2 parents 76650c3 + 9b19580 commit 28c1c05
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 66 deletions.
36 changes: 7 additions & 29 deletions SimPPS/PPSSimTrackProducer/plugins/PPSSimTrackProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/InputTag.h"
Expand All @@ -49,18 +48,16 @@
class PPSSimTrackProducer : public edm::stream::EDProducer<> {
public:
explicit PPSSimTrackProducer(const edm::ParameterSet&);
~PPSSimTrackProducer() override;
~PPSSimTrackProducer() override = default;

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

private:
void beginStream(edm::StreamID) override;
void produce(edm::Event&, const edm::EventSetup&) override;
void endStream() override;

// ----------member data ---------------------------
bool m_verbosity;
ProtonTransport* theTransporter;
ProtonTransport theTransporter;
edm::InputTag m_InTag;
edm::EDGetTokenT<edm::HepMCProduct> m_InTagToken;

Expand All @@ -79,11 +76,8 @@ class PPSSimTrackProducer : public edm::stream::EDProducer<> {
//
// constructors and destructor
//
PPSSimTrackProducer::PPSSimTrackProducer(const edm::ParameterSet& iConfig) {
//now do what ever other initialization is needed
// TransportHector
theTransporter = new ProtonTransport(iConfig);

PPSSimTrackProducer::PPSSimTrackProducer(const edm::ParameterSet& iConfig)
: theTransporter(iConfig, consumesCollector()) {
m_InTag = iConfig.getParameter<edm::InputTag>("HepMCProductLabel");
m_InTagToken = consumes<edm::HepMCProduct>(m_InTag);

Expand All @@ -103,15 +97,6 @@ PPSSimTrackProducer::PPSSimTrackProducer(const edm::ParameterSet& iConfig) {
}
}

PPSSimTrackProducer::~PPSSimTrackProducer() {
// do anything here that needs to be done at destruction time
// (e.g. close files, deallocate resources etc.)
if (theTransporter) {
delete theTransporter;
theTransporter = nullptr;
}
}

//
// member functions
//
Expand Down Expand Up @@ -143,8 +128,8 @@ void PPSSimTrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe

evt = new HepMC::GenEvent(HepMCEvt->GetEvent()->signal_process_id(), HepMCEvt->GetEvent()->event_number());

theTransporter->process(HepMCEvt->GetEvent(), iSetup, engine);
theTransporter->addPartToHepMC(HepMCEvt->GetEvent(), evt);
theTransporter.process(HepMCEvt->GetEvent(), iSetup, engine);
theTransporter.addPartToHepMC(HepMCEvt->GetEvent(), evt);

if (m_verbosity)
evt->print();
Expand All @@ -155,7 +140,7 @@ void PPSSimTrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
iEvent.put(std::move(newProduct));

unique_ptr<LHCTransportLinkContainer> NewCorrespondenceMap(new edm::LHCTransportLinkContainer());
edm::LHCTransportLinkContainer thisLink(theTransporter->getCorrespondenceMap());
edm::LHCTransportLinkContainer thisLink(theTransporter.getCorrespondenceMap());
(*NewCorrespondenceMap).swap(thisLink);

if (m_verbosity) {
Expand All @@ -169,13 +154,6 @@ void PPSSimTrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
// in fact, it MUST NOT be delete here, as a protection is missing in above package
edm::LogVerbatim("ProtonTransportEventProcessing") << "produce end ";
}
// The methods below are pure virtual, so it needs to be implemented even if not used
//
// ------------ method called once each stream before processing any runs, lumis or events ------------
void PPSSimTrackProducer::beginStream(edm::StreamID) {}

// ------------ method called once each stream after processing all runs, lumis and events ------------
void PPSSimTrackProducer::endStream() {}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
/* to be done */
Expand Down
2 changes: 1 addition & 1 deletion SimPPS/RPDigiProducer/plugins/DeadChannelsManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

DeadChannelsManager::DeadChannelsManager() { analysisMaskPresent = false; }

DeadChannelsManager::DeadChannelsManager(edm::ESHandle<TotemAnalysisMask> _analysisMask) {
DeadChannelsManager::DeadChannelsManager(const TotemAnalysisMask* _analysisMask) {
analysisMask = _analysisMask;
analysisMaskPresent = true;
}
Expand Down
6 changes: 2 additions & 4 deletions SimPPS/RPDigiProducer/plugins/DeadChannelsManager.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef SimPPS_RPDigiProducer_DEAD_CHANNELS_MANAGER
#define SimPPS_RPDigiProducer_DEAD_CHANNELS_MANAGER

#include "FWCore/Framework/interface/ESHandle.h"
#include "SimPPS/RPDigiProducer/interface/RPSimTypes.h"
#include "CondFormats/PPSObjects/interface/TotemAnalysisMask.h"

Expand All @@ -13,15 +12,15 @@
*/
class DeadChannelsManager {
private:
edm::ESHandle<TotemAnalysisMask> analysisMask;
const TotemAnalysisMask* analysisMask;
bool analysisMaskPresent; //this variable indicates whether analysisMask is present or not

public:
/**
* This constructor allows us to set analysisMask. The analysisMask can be read from
* EventSetup.
*/
DeadChannelsManager(edm::ESHandle<TotemAnalysisMask> analysisMask);
DeadChannelsManager(const TotemAnalysisMask* analysisMask);
DeadChannelsManager();
/**
* This function answers the question whether given channel is dead or not.
Expand All @@ -37,7 +36,6 @@ class DeadChannelsManager {
*/
bool isChannelDead(RPDetId detectorId, unsigned short stripNumber);
void displayMap();
static uint32_t rawToDecId(uint32_t raw);
};

#endif
16 changes: 7 additions & 9 deletions SimPPS/RPDigiProducer/plugins/RPDigiProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/Exception.h"
Expand Down Expand Up @@ -53,7 +52,7 @@ namespace CLHEP {
class RPDigiProducer : public edm::EDProducer {
public:
explicit RPDigiProducer(const edm::ParameterSet&);
~RPDigiProducer() override;
~RPDigiProducer() override = default;

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

Expand Down Expand Up @@ -85,6 +84,7 @@ class RPDigiProducer : public edm::EDProducer {
bool simulateDeadChannels;

edm::EDGetTokenT<CrossingFrame<PSimHit>> tokenCrossingFrameTotemRP;
edm::ESGetToken<TotemAnalysisMask, TotemReadoutRcd> tokenAnalysisMask;
};

RPDigiProducer::RPDigiProducer(const edm::ParameterSet& conf) : conf_(conf) {
Expand All @@ -102,12 +102,11 @@ RPDigiProducer::RPDigiProducer(const edm::ParameterSet& conf) : conf_(conf) {
"simulateDeadChannels")) { //check if "simulateDeadChannels" variable is defined in configuration file
simulateDeadChannels = conf.getParameter<bool>("simulateDeadChannels");
}
if (simulateDeadChannels) {
tokenAnalysisMask = esConsumes();
}
}

RPDigiProducer::~RPDigiProducer() {
// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)
}
//
// member functions
//
Expand Down Expand Up @@ -201,9 +200,8 @@ void RPDigiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
void RPDigiProducer::beginRun(const edm::Run& beginrun, const edm::EventSetup& es) {
// get analysis mask to mask channels
if (simulateDeadChannels) {
edm::ESHandle<TotemAnalysisMask> analysisMask;
es.get<TotemReadoutRcd>().get(analysisMask);
deadChannelsManager = DeadChannelsManager(analysisMask); //set analysisMask in deadChannelsManager
//set analysisMask in deadChannelsManager
deadChannelsManager = DeadChannelsManager(&es.getData(tokenAnalysisMask));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "CondFormats/PPSObjects/interface/CTPPSBeamParameters.h"
#include "CondFormats/PPSObjects/interface/LHCInterpolatedOpticalFunctionsSetCollection.h"
#include "CondFormats/RunInfo/interface/LHCInfo.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
Expand All @@ -21,20 +21,21 @@

class OpticalFunctionsTransport : public BaseProtonTransport {
public:
OpticalFunctionsTransport(const edm::ParameterSet& ps);
OpticalFunctionsTransport(const edm::ParameterSet& ps, edm::ConsumesCollector iC);
~OpticalFunctionsTransport() override{};

void process(const HepMC::GenEvent* ev, const edm::EventSetup& es, CLHEP::HepRandomEngine* engine) override;

private:
bool transportProton(const HepMC::GenParticle*);

std::string lhcInfoLabel_;
std::string opticsLabel_;
edm::ESGetToken<LHCInfo, LHCInfoRcd> lhcInfoToken_;
edm::ESGetToken<CTPPSBeamParameters, CTPPSBeamParametersRcd> beamParametersToken_;
edm::ESGetToken<LHCInterpolatedOpticalFunctionsSetCollection, CTPPSInterpolatedOpticsRcd> opticsToken_;

edm::ESHandle<LHCInfo> lhcInfo_;
edm::ESHandle<CTPPSBeamParameters> beamParameters_;
edm::ESHandle<LHCInterpolatedOpticalFunctionsSetCollection> opticalFunctions_;
const LHCInfo* lhcInfo_;
const CTPPSBeamParameters* beamParameters_;
const LHCInterpolatedOpticalFunctionsSetCollection* opticalFunctions_;
unsigned int optFunctionId45_;
unsigned int optFunctionId56_;

Expand Down
11 changes: 5 additions & 6 deletions SimTransport/PPSProtonTransport/interface/ProtonTransport.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#ifndef PROTONTRANSPORT
#define PROTONTRANSPORT
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "HepMC/GenEvent.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "SimDataFormats/Forward/interface/LHCTransportLink.h"
#include "SimTransport/PPSProtonTransport/interface/BaseProtonTransport.h"

#include <memory>
#include <vector>

class ProtonTransport {
public:
ProtonTransport(const edm::ParameterSet& iConfig);
~ProtonTransport() {
if (instance_)
delete instance_;
};
ProtonTransport(const edm::ParameterSet& iConfig, edm::ConsumesCollector iC);
~ProtonTransport() = default;

std::vector<LHCTransportLink>& getCorrespondenceMap() { return instance_->getCorrespondenceMap(); }
void process(const HepMC::GenEvent* ev, const edm::EventSetup& es, CLHEP::HepRandomEngine* engine) {
Expand All @@ -24,6 +23,6 @@ class ProtonTransport {
void addPartToHepMC(const HepMC::GenEvent* iev, HepMC::GenEvent* ev) { instance_->addPartToHepMC(iev, ev); }

private:
BaseProtonTransport* instance_;
std::unique_ptr<BaseProtonTransport> instance_;
};
#endif
13 changes: 7 additions & 6 deletions SimTransport/PPSProtonTransport/src/OpticalFunctionsTransport.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "SimTransport/PPSProtonTransport/interface/OpticalFunctionsTransport.h"
#include "DataFormats/CTPPSDetId/interface/CTPPSDetId.h"

OpticalFunctionsTransport::OpticalFunctionsTransport(const edm::ParameterSet& iConfig)
OpticalFunctionsTransport::OpticalFunctionsTransport(const edm::ParameterSet& iConfig, edm::ConsumesCollector iC)
: BaseProtonTransport(iConfig),
lhcInfoLabel_(iConfig.getParameter<std::string>("lhcInfoLabel")),
opticsLabel_(iConfig.getParameter<std::string>("opticsLabel")),
lhcInfoToken_(iC.esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("lhcInfoLabel")))),
beamParametersToken_(iC.esConsumes()),
opticsToken_(iC.esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("opticsLabel")))),
useEmpiricalApertures_(iConfig.getParameter<bool>("useEmpiricalApertures")),
empiricalAperture45_xi0_int_(iConfig.getParameter<double>("empiricalAperture45_xi0_int")),
empiricalAperture45_xi0_slp_(iConfig.getParameter<double>("empiricalAperture45_xi0_slp")),
Expand All @@ -22,9 +23,9 @@ void OpticalFunctionsTransport::process(const HepMC::GenEvent* evt,
CLHEP::HepRandomEngine* _engine) {
this->clear();

iSetup.get<LHCInfoRcd>().get(lhcInfoLabel_, lhcInfo_);
iSetup.get<CTPPSBeamParametersRcd>().get(beamParameters_);
iSetup.get<CTPPSInterpolatedOpticsRcd>().get(opticsLabel_, opticalFunctions_);
lhcInfo_ = &iSetup.getData(lhcInfoToken_);
beamParameters_ = &iSetup.getData(beamParametersToken_);
opticalFunctions_ = &iSetup.getData(opticsToken_);

// Choose the optical function corresponding to the first station ono each side (it is in lhc ref. frame)
optFunctionId45_ = 0;
Expand Down
8 changes: 4 additions & 4 deletions SimTransport/PPSProtonTransport/src/ProtonTransport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
#include <CLHEP/Units/GlobalSystemOfUnits.h>
#include <cctype>

ProtonTransport::ProtonTransport(const edm::ParameterSet &iConfig) : instance_(nullptr) {
ProtonTransport::ProtonTransport(const edm::ParameterSet &iConfig, edm::ConsumesCollector iC) {
std::string transportMethod_ = iConfig.getParameter<std::string>("TransportMethod");
for (auto &c : transportMethod_)
c = toupper(c); // just to on the safe side

if (transportMethod_ == "HECTOR") {
instance_ = new HectorTransport(iConfig);
instance_ = std::make_unique<HectorTransport>(iConfig);
} else if (transportMethod_ == "TOTEM") {
instance_ = new TotemTransport(iConfig);
instance_ = std::make_unique<TotemTransport>(iConfig);
} else if (transportMethod_ == "OPTICALFUNCTIONS") {
instance_ = new OpticalFunctionsTransport(iConfig);
instance_ = std::make_unique<OpticalFunctionsTransport>(iConfig, iC);
} else {
throw cms::Exception("ProtonTransport")
<< "Unknow transport method. Is must be either HECTOR, TOTEM or OPTICALFUNCTIONS (case insensitive)";
Expand Down

0 comments on commit 28c1c05

Please sign in to comment.