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:
71 
75 
76  void setupGeometry(MuonNumberingRecord const&, shared_ptr<HostType>&);
77  void setupDBGeometry(DTRecoGeometryRcd const&, shared_ptr<HostType>&);
78 
80 
88  const string m_alignmentsLabel;
89  const string m_myLabel;
90  const string m_attribute;
91  const string m_value;
93  bool m_fromDDD;
94 };
95 
97  : m_tag(iConfig.getParameter<ESInputTag>("DDDetector")),
98  m_alignmentsLabel(iConfig.getParameter<string>("alignmentsLabel")),
99  m_myLabel(iConfig.getParameter<string>("appendToDataLabel")),
100  m_attribute(iConfig.getParameter<string>("attribute")),
101  m_value(iConfig.getParameter<string>("value")),
102  m_fromDDD(iConfig.getParameter<bool>("fromDDD"))
103 {
104  m_applyAlignment = iConfig.getParameter<bool>("applyAlignment");
105 
106  auto cc = setWhatProduced(this);
107 
108  if(m_applyAlignment) {
112  }
113 
114  if(m_fromDDD) {
116  m_cpvToken = cc.consumesFrom<DDDetector, GeometryFileRcd>(m_tag);
118  }
119 
120  edm::LogInfo("Geometry") << "@SUB=DTGeometryESProducer"
121  << "Label '" << m_myLabel << "' "
122  << (m_applyAlignment ? "looking for" : "IGNORING")
123  << " alignment labels '" << m_alignmentsLabel << "'.";
124 }
125 
127 
128 std::shared_ptr<DTGeometry>
130 
131  auto host = m_holder.makeOrGet([]() {
132  return new HostType;
133  });
134 
135  {
136  BenchmarkGrd counter("DTGeometryESProducer");
137 
138  if(m_fromDDD) {
139  host->ifRecordChanges<MuonNumberingRecord>(record,
140  [this, &host](auto const& rec) {
141  setupGeometry(rec, host);
142  });
143  } else {
144  host->ifRecordChanges<DTRecoGeometryRcd>(record,
145  [this, &host](auto const& rec) {
146  setupDBGeometry(rec, host);
147  });
148  }
149  }
150  //
151  // Called whenever the alignments or alignment errors change
152  //
153  if(m_applyAlignment) {
154  // m_applyAlignment is scheduled for removal.
155  // Ideal geometry obtained by using 'fake alignment' (with m_applyAlignment = true)
156  edm::ESHandle<Alignments> globalPosition;
157  record.getRecord<GlobalPositionRcd>().get(m_alignmentsLabel, globalPosition);
158  edm::ESHandle<Alignments> alignments;
159  record.getRecord<DTAlignmentRcd>().get(m_alignmentsLabel, alignments);
161  record.getRecord<DTAlignmentErrorExtendedRcd>().get(m_alignmentsLabel, alignmentErrors);
162  // Only apply alignment if values exist
163  if (alignments->empty() && alignmentErrors->empty() && globalPosition->empty()) {
164  edm::LogInfo("Config") << "@SUB=DTGeometryRecord::produce"
165  << "Alignment(Error)s and global position (label '"
166  << m_alignmentsLabel << "') empty: Geometry producer (label "
167  << "'" << m_myLabel << "') assumes fake and does not apply.";
168  } else {
169  GeometryAligner aligner;
170  aligner.applyAlignments<DTGeometry>( &(*host),
171  &(*alignments), &(*alignmentErrors),
172  align::DetectorGlobalPosition(*globalPosition, DetId(DetId::Muon)));
173  }
174  }
175 
176  return host; // automatically converts to std::shared_ptr<DTGeometry>
177 }
178 
179 void
181  shared_ptr<HostType>& host) {
182  host->clear();
183 
184  const auto& mdc = record.get(m_mdcToken);
185 
187 
189 
190  DDSpecParRefs myReg;
191  {
192  BenchmarkGrd b1("DTGeometryESProducer Filter Registry");
193  registry->filter(myReg, m_attribute, m_value);
194  }
195 
196  DTGeometryBuilder builder;
197  builder.build(*host, cpv.product(), mdc, myReg);
198 }
199 
200 void
202  std::shared_ptr<HostType>& host ) {
203  // host->clear();
204 
205  // edm::ESHandle<RecoIdealGeometry> rig;
206  // record.get(rig);
207 
208  // DTGeometryBuilderFromCondDB builder;
209  // builder.build(host, *rig);
210 }
211 
T getParameter(std::string const &) const
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:124
host
Definition: query.py:115
edm::ESGetToken< DDDetector, GeometryFileRcd > m_cpvToken
edm::ESGetToken< MuonNumbering, MuonNumberingRecord > m_mdcToken
bool empty() const
Test of empty vector without having to look into internals:
Definition: Alignments.h:15
void filter(DDSpecParRefs &, std::string_view, std::string_view) const
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
std::shared_ptr< T > makeOrGet(F iFunc)
If there isn&#39;t an object already available, creates a new one using iFunc.
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
Namespace of DDCMS conversion namespace.
Definition: DetId.h:18
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)
static Interceptor::Registry registry("Interceptor")
edm::ESGetToken< Alignments, DTAlignmentRcd > m_alignmentsToken
MuonNumberingRecord
Definition: align_cfg.py:65