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

Use ESGetToken in FWRecoGeometryESProducer and FWTGeoRecoGeometryESProducer #28564

Merged
merged 3 commits into from Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 13 additions & 7 deletions Fireworks/Geometry/interface/FWRecoGeometryESProducer.h
Expand Up @@ -4,18 +4,20 @@
#include <memory>

#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Utilities/interface/ESGetToken.h"
#include "DataFormats/GeometryVector/interface/GlobalPoint.h"

namespace edm {
class ParameterSet;
}

class CaloGeometry;
class HGCalGeometry;
class CaloGeometryRecord;
class GlobalTrackingGeometry;
class GlobalTrackingGeometryRecord;
class TrackerGeometry;
class FastTimeGeometry;
class IdealGeometryRecord;
class FWRecoGeometry;
class FWRecoGeometryRecord;
class GeomDet;
Expand Down Expand Up @@ -56,11 +58,15 @@ class FWRecoGeometryESProducer : public edm::ESProducer {
void fillShapeAndPlacement(unsigned int id, const GeomDet* det, FWRecoGeometry&);
void writeTrackerParametersXML(FWRecoGeometry&);

edm::ESHandle<GlobalTrackingGeometry> m_geomRecord;
const CaloGeometry* m_caloGeom;
edm::ESHandle<FastTimeGeometry> m_ftlBarrelGeom, m_ftlEndcapGeom;
std::vector<edm::ESHandle<HGCalGeometry> > m_hgcalGeoms;
const TrackerGeometry* m_trackerGeom;
edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> m_trackingGeomToken;
edm::ESGetToken<FastTimeGeometry, IdealGeometryRecord> m_ftlBarrelGeomToken;
edm::ESGetToken<FastTimeGeometry, IdealGeometryRecord> m_ftlEndcapGeomToken;
edm::ESGetToken<CaloGeometry, CaloGeometryRecord> m_caloGeomToken;
const GlobalTrackingGeometry* m_trackingGeom = nullptr;
const CaloGeometry* m_caloGeom = nullptr;
const FastTimeGeometry* m_ftlBarrelGeom = nullptr;
const FastTimeGeometry* m_ftlEndcapGeom = nullptr;
const TrackerGeometry* m_trackerGeom = nullptr;

unsigned int m_current;
bool m_tracker;
Expand Down
19 changes: 13 additions & 6 deletions Fireworks/Geometry/interface/FWTGeoRecoGeometryESProducer.h
Expand Up @@ -4,17 +4,20 @@
#include <memory>

#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Utilities/interface/ESGetToken.h"
#include "DataFormats/GeometryVector/interface/GlobalPoint.h"

namespace edm {
class ParameterSet;
}

class CaloGeometry;
class CaloGeometryRecord;
class GlobalTrackingGeometry;
class GlobalTrackingGeometryRecord;
class TrackerGeometry;
class TrackerTopology;
class TrackerTopologyRcd;
class FWTGeoRecoGeometry;
class FWTGeoRecoGeometryRecord;

Expand Down Expand Up @@ -85,12 +88,16 @@ class FWTGeoRecoGeometryESProducer : public edm::ESProducer {
std::map<TGeoShape*, TGeoVolume*> m_shapeToVolume;
std::map<ERecoDet, TGeoMedium*> m_recoMedium;

edm::ESHandle<GlobalTrackingGeometry> m_geomRecord;
const CaloGeometry* m_caloGeom;
const TrackerGeometry* m_trackerGeom;
const TrackerTopology* m_trackerTopology;
edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> m_trackingGeomToken;
edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> m_trackerTopologyToken;
edm::ESGetToken<CaloGeometry, CaloGeometryRecord> m_caloGeomToken;

TGeoMedium* m_dummyMedium;
const GlobalTrackingGeometry* m_trackingGeom = nullptr;
const CaloGeometry* m_caloGeom = nullptr;
const TrackerGeometry* m_trackerGeom = nullptr;
const TrackerTopology* m_trackerTopology = nullptr;

TGeoMedium* m_dummyMedium = nullptr;

bool m_tracker;
bool m_muon;
Expand Down
52 changes: 29 additions & 23 deletions Fireworks/Geometry/src/FWRecoGeometryESProducer.cc
Expand Up @@ -101,7 +101,17 @@ FWRecoGeometryESProducer::FWRecoGeometryESProducer(const edm::ParameterSet& pset
m_muon = pset.getUntrackedParameter<bool>("Muon", true);
m_calo = pset.getUntrackedParameter<bool>("Calo", true);
m_timing = pset.getUntrackedParameter<bool>("Timing", false);
setWhatProduced(this);
auto cc = setWhatProduced(this);
if (m_tracker or m_muon) {
cc.setConsumes(m_trackingGeomToken);
}
if (m_timing) {
cc.setConsumes(m_ftlBarrelGeomToken, edm::ESInputTag{"", "FastTimeBarrel"})
.setConsumes(m_ftlEndcapGeomToken, edm::ESInputTag{"", "SFBX"});
}
if (m_calo) {
cc.setConsumes(m_caloGeomToken);
}
}

FWRecoGeometryESProducer::~FWRecoGeometryESProducer(void) {}
Expand All @@ -112,9 +122,9 @@ std::unique_ptr<FWRecoGeometry> FWRecoGeometryESProducer::produce(const FWRecoGe
auto fwRecoGeometry = std::make_unique<FWRecoGeometry>();

if (m_tracker || m_muon) {
record.getRecord<GlobalTrackingGeometryRecord>().get(m_geomRecord);
m_trackingGeom = &record.get(m_trackingGeomToken);
DetId detId(DetId::Tracker, 0);
m_trackerGeom = (const TrackerGeometry*)m_geomRecord->slaveGeometry(detId);
m_trackerGeom = static_cast<const TrackerGeometry*>(m_trackingGeom->slaveGeometry(detId));
}

if (m_tracker) {
Expand All @@ -134,15 +144,13 @@ std::unique_ptr<FWRecoGeometry> FWRecoGeometryESProducer::produce(const FWRecoGe
addME0Geometry(*fwRecoGeometry);
}
if (m_calo) {
edm::ESHandle<CaloGeometry> caloGeomH;
record.getRecord<CaloGeometryRecord>().get(caloGeomH);
m_caloGeom = caloGeomH.product();
m_caloGeom = &record.get(m_caloGeomToken);
addCaloGeometry(*fwRecoGeometry);
}

if (m_timing) {
record.getRecord<CaloGeometryRecord>().getRecord<IdealGeometryRecord>().get("FastTimeBarrel", m_ftlBarrelGeom);
record.getRecord<CaloGeometryRecord>().getRecord<IdealGeometryRecord>().get("SFBX", m_ftlEndcapGeom);
m_ftlBarrelGeom = &record.getRecord<CaloGeometryRecord>().get(m_ftlBarrelGeomToken);
makortel marked this conversation as resolved.
Show resolved Hide resolved
m_ftlEndcapGeom = &record.getRecord<CaloGeometryRecord>().get(m_ftlEndcapGeomToken);
addFTLGeometry(*fwRecoGeometry);
}

Expand All @@ -155,7 +163,7 @@ std::unique_ptr<FWRecoGeometry> FWRecoGeometryESProducer::produce(const FWRecoGe

void FWRecoGeometryESProducer::addCSCGeometry(FWRecoGeometry& fwRecoGeometry) {
DetId detId(DetId::Muon, 2);
const CSCGeometry* cscGeometry = (const CSCGeometry*)m_geomRecord->slaveGeometry(detId);
const CSCGeometry* cscGeometry = static_cast<const CSCGeometry*>(m_trackingGeom->slaveGeometry(detId));
for (auto it = cscGeometry->chambers().begin(), end = cscGeometry->chambers().end(); it != end; ++it) {
const CSCChamber* chamber = *it;

Expand Down Expand Up @@ -195,7 +203,7 @@ void FWRecoGeometryESProducer::addCSCGeometry(FWRecoGeometry& fwRecoGeometry) {

void FWRecoGeometryESProducer::addDTGeometry(FWRecoGeometry& fwRecoGeometry) {
DetId detId(DetId::Muon, 1);
const DTGeometry* dtGeometry = (const DTGeometry*)m_geomRecord->slaveGeometry(detId);
const DTGeometry* dtGeometry = static_cast<const DTGeometry*>(m_trackingGeom->slaveGeometry(detId));

//
// DT chambers geometry
Expand Down Expand Up @@ -242,7 +250,7 @@ void FWRecoGeometryESProducer::addRPCGeometry(FWRecoGeometry& fwRecoGeometry) {
// RPC rolls geometry
//
DetId detId(DetId::Muon, 3);
const RPCGeometry* rpcGeom = (const RPCGeometry*)m_geomRecord->slaveGeometry(detId);
const RPCGeometry* rpcGeom = static_cast<const RPCGeometry*>(m_trackingGeom->slaveGeometry(detId));
for (auto it = rpcGeom->rolls().begin(), end = rpcGeom->rolls().end(); it != end; ++it) {
const RPCRoll* roll = (*it);
if (roll) {
Expand All @@ -259,7 +267,7 @@ void FWRecoGeometryESProducer::addRPCGeometry(FWRecoGeometry& fwRecoGeometry) {

try {
RPCDetId id(1, 1, 4, 1, 1, 1, 1);
m_geomRecord->slaveGeometry(detId);
m_trackingGeom->slaveGeometry(detId);
fwRecoGeometry.extraDet.Add(new TNamed("RE4", "RPC endcap station 4"));
} catch (std::runtime_error& e) {
std::cerr << e.what() << std::endl;
Expand All @@ -273,7 +281,7 @@ void FWRecoGeometryESProducer::addGEMGeometry(FWRecoGeometry& fwRecoGeometry) {

try {
DetId detId(DetId::Muon, 4);
const GEMGeometry* gemGeom = (const GEMGeometry*)m_geomRecord->slaveGeometry(detId);
const GEMGeometry* gemGeom = static_cast<const GEMGeometry*>(m_trackingGeom->slaveGeometry(detId));

// add in superChambers - gem Segments are based on superChambers
for (auto sc : gemGeom->superChambers()) {
Expand Down Expand Up @@ -315,7 +323,7 @@ void FWRecoGeometryESProducer::addGEMGeometry(FWRecoGeometry& fwRecoGeometry) {
fwRecoGeometry.extraDet.Add(new TNamed("GEM", "GEM muon detector"));
try {
GEMDetId id(1, 1, 2, 1, 1, 1);
m_geomRecord->slaveGeometry(id);
m_trackingGeom->slaveGeometry(id);
fwRecoGeometry.extraDet.Add(new TNamed("GE2", "GEM endcap station 2"));
} catch (std::runtime_error& e) {
std::cerr << e.what() << std::endl;
Expand All @@ -333,7 +341,7 @@ void FWRecoGeometryESProducer::addME0Geometry(FWRecoGeometry& fwRecoGeometry) {

DetId detId(DetId::Muon, 5);
try {
const ME0Geometry* me0Geom = (const ME0Geometry*)m_geomRecord->slaveGeometry(detId);
const ME0Geometry* me0Geom = static_cast<const ME0Geometry*>(m_trackingGeom->slaveGeometry(detId));
for (auto roll : me0Geom->etaPartitions()) {
if (roll) {
unsigned int rawid = roll->geographicalId().rawId();
Expand Down Expand Up @@ -511,17 +519,15 @@ void FWRecoGeometryESProducer::addCaloGeometry(FWRecoGeometry& fwRecoGeometry) {

void FWRecoGeometryESProducer::addFTLGeometry(FWRecoGeometry& fwRecoGeometry) {
// do the barrel
std::vector<DetId> vid = std::move(m_ftlBarrelGeom->getValidDetIds());
for (std::vector<DetId>::const_iterator it = vid.begin(), end = vid.end(); it != end; ++it) {
unsigned int id = insert_id(it->rawId(), fwRecoGeometry);
const auto& cor = m_ftlBarrelGeom->getCorners(*it);
for (const auto& detid : m_ftlBarrelGeom->getValidDetIds()) {
unsigned int id = insert_id(detid.rawId(), fwRecoGeometry);
const auto& cor = m_ftlBarrelGeom->getCorners(detid);
fillPoints(id, cor.begin(), cor.end(), fwRecoGeometry);
}
// do the endcap
vid = std::move(m_ftlEndcapGeom->getValidDetIds());
for (std::vector<DetId>::const_iterator it = vid.begin(), end = vid.end(); it != end; ++it) {
unsigned int id = insert_id(it->rawId(), fwRecoGeometry);
const auto& cor = m_ftlEndcapGeom->getCorners(*it);
for (const auto& detid : m_ftlEndcapGeom->getValidDetIds()) {
unsigned int id = insert_id(detid.rawId(), fwRecoGeometry);
const auto& cor = m_ftlEndcapGeom->getCorners(detid);
fillPoints(id, cor.begin(), cor.end(), fwRecoGeometry);
}
}
Expand Down
39 changes: 22 additions & 17 deletions Fireworks/Geometry/src/FWTGeoRecoGeometryESProducer.cc
Expand Up @@ -65,7 +65,16 @@ FWTGeoRecoGeometryESProducer::FWTGeoRecoGeometryESProducer(const edm::ParameterS
m_muon = pset.getUntrackedParameter<bool>("Muon", true);
m_calo = pset.getUntrackedParameter<bool>("Calo", true);

setWhatProduced(this);
auto cc = setWhatProduced(this);
if (m_tracker || m_muon) {
cc.setConsumes(m_trackingGeomToken);
}
if (m_tracker) {
cc.setConsumes(m_trackerTopologyToken);
}
if (m_calo) {
cc.setConsumes(m_caloGeomToken);
}
}

FWTGeoRecoGeometryESProducer::~FWTGeoRecoGeometryESProducer(void) {}
Expand Down Expand Up @@ -257,9 +266,7 @@ std::unique_ptr<FWTGeoRecoGeometry> FWTGeoRecoGeometryESProducer::produce(const
auto fwTGeoRecoGeometry = std::make_unique<FWTGeoRecoGeometry>();

if (m_calo) {
edm::ESHandle<CaloGeometry> caloH;
record.getRecord<CaloGeometryRecord>().get(caloH);
m_caloGeom = caloH.product();
m_caloGeom = &record.get(m_caloGeomToken);
}

TGeoManager* geom = new TGeoManager("cmsGeo", "CMS Detector");
Expand All @@ -284,16 +291,14 @@ std::unique_ptr<FWTGeoRecoGeometry> FWTGeoRecoGeometryESProducer::produce(const
top->SetLineColor(kBlue);

if (m_tracker || m_muon) {
record.getRecord<GlobalTrackingGeometryRecord>().get(m_geomRecord);
m_trackingGeom = &record.get(m_trackingGeomToken);
}

if (m_tracker) {
DetId detId(DetId::Tracker, 0);
m_trackerGeom = (const TrackerGeometry*)m_geomRecord->slaveGeometry(detId);
m_trackerGeom = static_cast<const TrackerGeometry*>(m_trackingGeom->slaveGeometry(detId));

edm::ESHandle<TrackerTopology> trackerTopologyHandle;
record.getRecord<TrackerTopologyRcd>().get(trackerTopologyHandle);
m_trackerTopology = trackerTopologyHandle.product();
m_trackerTopology = &record.get(m_trackerTopologyToken);

addPixelBarrelGeometry();
addPixelForwardGeometry();
Expand Down Expand Up @@ -555,7 +560,7 @@ void FWTGeoRecoGeometryESProducer::addDTGeometry() {
//
{
TGeoVolume* assembly = GetDaughter(assemblyTop, "DTChamber", kMuonDT);
auto const& dtChamberGeom = m_geomRecord->slaveGeometry(DTChamberId())->dets();
auto const& dtChamberGeom = m_trackingGeom->slaveGeometry(DTChamberId())->dets();
for (auto it = dtChamberGeom.begin(), end = dtChamberGeom.end(); it != end; ++it) {
if (auto chamber = dynamic_cast<const DTChamber*>(*it)) {
DTChamberId detid = chamber->geographicalId();
Expand All @@ -576,7 +581,7 @@ void FWTGeoRecoGeometryESProducer::addDTGeometry() {
// Fill in DT super layer parameters
{
TGeoVolume* assembly = GetDaughter(assemblyTop, "DTSuperLayer", kMuonDT);
auto const& dtSuperLayerGeom = m_geomRecord->slaveGeometry(DTSuperLayerId())->dets();
auto const& dtSuperLayerGeom = m_trackingGeom->slaveGeometry(DTSuperLayerId())->dets();
for (auto it = dtSuperLayerGeom.begin(), end = dtSuperLayerGeom.end(); it != end; ++it) {
if (auto* superlayer = dynamic_cast<const DTSuperLayer*>(*it)) {
DTSuperLayerId detid(DetId(superlayer->geographicalId()));
Expand All @@ -597,7 +602,7 @@ void FWTGeoRecoGeometryESProducer::addDTGeometry() {
// Fill in DT layer parameters
{
TGeoVolume* assembly = GetDaughter(assemblyTop, "DTLayer", kMuonDT);
auto const& dtLayerGeom = m_geomRecord->slaveGeometry(DTLayerId())->dets();
auto const& dtLayerGeom = m_trackingGeom->slaveGeometry(DTLayerId())->dets();
for (auto it = dtLayerGeom.begin(), end = dtLayerGeom.end(); it != end; ++it) {
if (auto layer = dynamic_cast<const DTLayer*>(*it)) {
DTLayerId detid(DetId(layer->geographicalId()));
Expand All @@ -621,13 +626,13 @@ void FWTGeoRecoGeometryESProducer::addDTGeometry() {
//______________________________________________________________________________

void FWTGeoRecoGeometryESProducer::addCSCGeometry() {
if (!m_geomRecord->slaveGeometry(CSCDetId()))
if (!m_trackingGeom->slaveGeometry(CSCDetId()))
throw cms::Exception("FatalError") << "Cannnot find CSCGeometry\n";

TGeoVolume* tv = GetTopHolder("Muon", kMuonRPC);
TGeoVolume* assembly = GetDaughter(tv, "CSC", kMuonCSC);

auto const& cscGeom = m_geomRecord->slaveGeometry(CSCDetId())->dets();
auto const& cscGeom = m_trackingGeom->slaveGeometry(CSCDetId())->dets();
for (auto it = cscGeom.begin(), itEnd = cscGeom.end(); it != itEnd; ++it) {
unsigned int rawid = (*it)->geographicalId();
CSCDetId detId(rawid);
Expand Down Expand Up @@ -659,7 +664,7 @@ void FWTGeoRecoGeometryESProducer::addCSCGeometry() {
void FWTGeoRecoGeometryESProducer::addGEMGeometry() {
try {
DetId detId(DetId::Muon, MuonSubdetId::GEM);
const GEMGeometry* gemGeom = (const GEMGeometry*)m_geomRecord->slaveGeometry(detId);
const GEMGeometry* gemGeom = static_cast<const GEMGeometry*>(m_trackingGeom->slaveGeometry(detId));

TGeoVolume* tv = GetTopHolder("Muon", kMuonRPC);
TGeoVolume* assemblyTop = GetDaughter(tv, "GEM", kMuonGEM);
Expand Down Expand Up @@ -720,7 +725,7 @@ void FWTGeoRecoGeometryESProducer::addRPCGeometry() {
TGeoVolume* assembly = GetDaughter(tv, "RPC", kMuonRPC);

DetId detId(DetId::Muon, MuonSubdetId::RPC);
const RPCGeometry* rpcGeom = (const RPCGeometry*)m_geomRecord->slaveGeometry(detId);
const RPCGeometry* rpcGeom = static_cast<const RPCGeometry*>(m_trackingGeom->slaveGeometry(detId));
for (auto it = rpcGeom->rolls().begin(), end = rpcGeom->rolls().end(); it != end; ++it) {
RPCRoll const* roll = (*it);
if (roll) {
Expand Down Expand Up @@ -749,7 +754,7 @@ void FWTGeoRecoGeometryESProducer::addME0Geometry() {

DetId detId(DetId::Muon, 5);
try {
const ME0Geometry* me0Geom = (const ME0Geometry*)m_geomRecord->slaveGeometry(detId);
const ME0Geometry* me0Geom = static_cast<const ME0Geometry*>(m_trackingGeom->slaveGeometry(detId));

for (auto roll : me0Geom->etaPartitions()) {
if (roll) {
Expand Down