CMS 3D CMS Logo

DTGeometryESProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DetectorDescription/DTGeometryESProducer
4 // Class: DTGeometryESProducer
5 //
13 //
14 // Original Author: Ianna Osborne
15 // Created: Wed, 16 Jan 2019 10:19:37 GMT
16 //
17 //
30 
49 #include "DTGeometryBuilder.h"
50 
51 #include <memory>
52 #include <iostream>
53 #include <iterator>
54 #include <string>
55 
56 using namespace edm;
57 using namespace std;
58 using namespace cms;
59 
61 public:
63  ~DTGeometryESProducer() override;
64 
65  using ReturnType = shared_ptr<DTGeometry>;
67 
68  ReturnType produce(const MuonGeometryRecord& record);
69 
70 private:
72 
73  void setupGeometry(MuonNumberingRecord const&, shared_ptr<HostType>&);
74  void setupDBGeometry(DTRecoGeometryRcd const&, shared_ptr<HostType>&);
75 
77 
85  const string m_alignmentsLabel;
86  const string m_myLabel;
87  const string m_attribute;
88  const string m_value;
90  bool m_fromDDD;
91 };
92 
94  : m_tag(iConfig.getParameter<ESInputTag>("DDDetector")),
95  m_alignmentsLabel(iConfig.getParameter<string>("alignmentsLabel")),
96  m_myLabel(iConfig.getParameter<string>("appendToDataLabel")),
97  m_attribute(iConfig.getParameter<string>("attribute")),
98  m_value(iConfig.getParameter<string>("value")),
99  m_fromDDD(iConfig.getParameter<bool>("fromDDD")) {
100  m_applyAlignment = iConfig.getParameter<bool>("applyAlignment");
101 
102  auto cc = setWhatProduced(this);
103 
104  if (m_applyAlignment) {
109  }
110 
111  if (m_fromDDD) {
113  m_cpvToken = cc.consumesFrom<DDDetector, IdealGeometryRecord>(m_tag);
115  }
116 
117  edm::LogInfo("Geometry") << "@SUB=DTGeometryESProducer"
118  << "Label '" << m_myLabel << "' " << (m_applyAlignment ? "looking for" : "IGNORING")
119  << " alignment labels '" << m_alignmentsLabel << "'.";
120 }
121 
123 
124 std::shared_ptr<DTGeometry> DTGeometryESProducer::produce(const MuonGeometryRecord& record) {
125  auto host = m_holder.makeOrGet([]() { return new HostType; });
126 
127  {
128  BenchmarkGrd counter("DTGeometryESProducer");
129 
130  if (m_fromDDD) {
131  host->ifRecordChanges<MuonNumberingRecord>(record, [this, &host](auto const& rec) { setupGeometry(rec, host); });
132  } else {
133  host->ifRecordChanges<DTRecoGeometryRcd>(record, [this, &host](auto const& rec) { setupDBGeometry(rec, host); });
134  }
135  }
136  //
137  // Called whenever the alignments or alignment errors change
138  //
139  if (m_applyAlignment) {
140  // m_applyAlignment is scheduled for removal.
141  // Ideal geometry obtained by using 'fake alignment' (with m_applyAlignment = true)
142  edm::ESHandle<Alignments> globalPosition;
143  record.getRecord<GlobalPositionRcd>().get(m_alignmentsLabel, globalPosition);
144  edm::ESHandle<Alignments> alignments;
145  record.getRecord<DTAlignmentRcd>().get(m_alignmentsLabel, alignments);
147  record.getRecord<DTAlignmentErrorExtendedRcd>().get(m_alignmentsLabel, alignmentErrors);
148  // Only apply alignment if values exist
149  if (alignments->empty() && alignmentErrors->empty() && globalPosition->empty()) {
150  edm::LogInfo("Config") << "@SUB=DTGeometryRecord::produce"
151  << "Alignment(Error)s and global position (label '" << m_alignmentsLabel
152  << "') empty: Geometry producer (label "
153  << "'" << m_myLabel << "') assumes fake and does not apply.";
154  } else {
155  GeometryAligner aligner;
156  aligner.applyAlignments<DTGeometry>(&(*host),
157  &(*alignments),
158  &(*alignmentErrors),
159  align::DetectorGlobalPosition(*globalPosition, DetId(DetId::Muon)));
160  }
161  }
162 
163  return host; // automatically converts to std::shared_ptr<DTGeometry>
164 }
165 
167  host->clear();
168 
169  const auto& mdc = record.get(m_mdcToken);
170 
172 
174 
175  DDSpecParRefs myReg;
176  {
177  BenchmarkGrd b1("DTGeometryESProducer Filter Registry");
178  registry->filter(myReg, m_attribute, m_value);
179  }
180 
181  DTGeometryBuilder builder;
182  builder.build(*host, cpv.product(), mdc, myReg);
183 }
184 
185 void DTGeometryESProducer::setupDBGeometry(const DTRecoGeometryRcd& record, std::shared_ptr<HostType>& host) {
186  // host->clear();
187 
188  // edm::ESHandle<RecoIdealGeometry> rig;
189  // record.get(rig);
190 
191  // DTGeometryBuilderFromCondDB builder;
192  // builder.build(host, *rig);
193 }
194 
T getParameter(std::string const &) const
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
host
Definition: query.py:115
edm::ESGetToken< MuonNumbering, MuonNumberingRecord > m_mdcToken
bool empty() const
Test of empty vector without having to look into internals:
Definition: Alignments.h:15
Class to update a given geometry with a set of alignments.
JetCorrectorParameters::Record record
Definition: classes.h:7
edm::ESGetToken< AlignmentErrorsExtended, DTAlignmentErrorExtendedRcd > m_alignmentErrorsToken
ESTransientHandle< ProductT > getTransientHandle(ESGetToken< ProductT, DepRecordT > const &iToken) const
void filter(DDSpecParRefs &, std::string_view, std::string_view) const
ESProductHost< DTGeometry, MuonNumberingRecord, DTRecoGeometryRcd > HostType
shared_ptr< DTGeometry > ReturnType
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
edm::ESGetToken< Alignments, GlobalPositionRcd > m_globalPositionToken
void build(DTGeometry &, const DDDetector *, const MuonNumbering &, const DDSpecParRefs &)
ReusableObjectHolder< HostType > m_holder
std::shared_ptr< T > makeOrGet(F iFunc)
If there isn&#39;t an object already available, creates a new one using iFunc.
Namespace of DDCMS conversion namespace.
Definition: DetId.h:17
ReturnType produce(const MuonGeometryRecord &record)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void applyAlignments(C *geometry, const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates)
bool empty() const
Test of empty vector without having to look into internals:
T const * product() const
std::vector< const DDSpecPar * > DDSpecParRefs
edm::ESGetToken< DDSpecParRegistry, DDSpecParRegistryRcd > m_registryToken
void setupDBGeometry(DTRecoGeometryRcd const &, shared_ptr< HostType > &)
DTGeometryESProducer(const ParameterSet &)
HLT enums.
static std::atomic< unsigned int > counter
void setupGeometry(MuonNumberingRecord const &, shared_ptr< HostType > &)
const AlignTransform & DetectorGlobalPosition(const Alignments &allGlobals, const DetId &id)
edm::ESGetToken< DDDetector, IdealGeometryRecord > m_cpvToken
edm::ESGetToken< Alignments, DTAlignmentRcd > m_alignmentsToken