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 // Modified by Sergio Lo Meo (sergio.lo.meo@cern.ch) Mon, 31 August 2020
17 //
18 //
50 #include "DTGeometryBuilder.h"
51 
52 #include <memory>
53 #include <iostream>
54 #include <iterator>
55 #include <string>
56 
57 using namespace edm;
58 using namespace std;
59 using namespace cms;
60 
62 public:
64  ~DTGeometryESProducer() override;
65 
66  using ReturnType = shared_ptr<DTGeometry>;
68 
69  ReturnType produce(const MuonGeometryRecord& record);
70 
71 private:
73 
74  void setupGeometry(MuonNumberingRecord const&, shared_ptr<HostType>&);
75  void setupDBGeometry(DTRecoGeometryRcd const&, shared_ptr<HostType>&);
76 
78 
86  const string m_alignmentsLabel;
87  const string m_myLabel;
88  const string m_attribute;
89  const string m_value;
91  bool m_fromDDD;
92 };
93 
95  : m_tag(iConfig.getParameter<ESInputTag>("DDDetector")),
96  m_alignmentsLabel(iConfig.getParameter<string>("alignmentsLabel")),
97  m_myLabel(iConfig.getParameter<string>("appendToDataLabel")),
98  m_attribute(iConfig.getParameter<string>("attribute")),
99  m_value(iConfig.getParameter<string>("value")),
100  m_fromDDD(iConfig.getParameter<bool>("fromDDD")) {
101  m_applyAlignment = iConfig.getParameter<bool>("applyAlignment");
102 
103  auto cc = setWhatProduced(this);
104 
105  if (m_applyAlignment) {
110  }
111 
112  if (m_fromDDD) {
116  }
117 
118  edm::LogInfo("Geometry") << "@SUB=DTGeometryESProducer"
119  << "Label '" << m_myLabel << "' " << (m_applyAlignment ? "looking for" : "IGNORING")
120  << " alignment labels '" << m_alignmentsLabel << "'.";
121 }
122 
124 
125 std::shared_ptr<DTGeometry> DTGeometryESProducer::produce(const MuonGeometryRecord& record) {
126  auto host = m_holder.makeOrGet([]() { return new HostType; });
127 
128  {
129  BenchmarkGrd counter("DTGeometryESProducer");
130 
131  if (m_fromDDD) {
132  host->ifRecordChanges<MuonNumberingRecord>(record, [this, &host](auto const& rec) { setupGeometry(rec, host); });
133  } else {
134  host->ifRecordChanges<DTRecoGeometryRcd>(record, [this, &host](auto const& rec) { setupDBGeometry(rec, host); });
135  }
136  }
137 
138  if (m_applyAlignment) {
139  const auto& globalPosition = record.get(m_globalPositionToken);
140  const auto& alignments = record.get(m_alignmentsToken);
141  const auto& alignmentErrors = record.get(m_alignmentErrorsToken);
142 
143  if (alignments.empty() && alignmentErrors.empty() && globalPosition.empty()) {
144  edm::LogInfo("Config") << "@SUB=DTGeometryRecord::produce"
145  << "Alignment and global position errors";
146 
147  } else {
148  GeometryAligner aligner;
149  aligner.applyAlignments<DTGeometry>(
150  &(*host), &alignments, &alignmentErrors, align::DetectorGlobalPosition(globalPosition, DetId(DetId::Muon)));
151  }
152  }
153 
154  return host;
155 }
156 
158  host->clear();
159 
160  const auto& mdc = record.get(m_mdcToken);
161 
162  edm::ESTransientHandle<DDDetector> cpv = record.getTransientHandle(m_cpvToken);
163 
164  ESTransientHandle<DDSpecParRegistry> registry = record.getTransientHandle(m_registryToken);
165 
166  DDSpecParRefs myReg;
167  {
168  BenchmarkGrd b1("DTGeometryESProducer Filter Registry");
169  registry->filter(myReg, m_attribute, m_value);
170  }
171 
172  DTGeometryBuilder builder;
173  builder.build(*host, cpv.product(), mdc, myReg);
174 }
175 
176 void DTGeometryESProducer::setupDBGeometry(const DTRecoGeometryRcd& record, std::shared_ptr<HostType>& host) {
177  // host->clear();
178  // edm::ESHandle<RecoIdealGeometry> rig;
179  // record.get(rig);
180  // DTGeometryBuilderFromCondDB builder;
181  // builder.build(host, *rig);
182 }
183 
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:166
weight_default_t b1[25]
Definition: b1.h:9
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::ESGetToken< MuonGeometryConstants, IdealGeometryRecord > m_mdcToken
string host
Definition: query.py:115
Class to update a given geometry with a set of alignments.
dd4hep::SpecParRefs DDSpecParRefs
Definition: DDCompactView.h:29
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
edm::ESGetToken< AlignmentErrorsExtended, DTAlignmentErrorExtendedRcd > m_alignmentErrorsToken
void build(DTGeometry &, const DDDetector *, const MuonGeometryConstants &, const dd4hep::SpecParRefs &)
ESProductHost< DTGeometry, MuonNumberingRecord, DTRecoGeometryRcd > HostType
void applyAlignments(const C *geometry, const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates)
dd4hep::SpecParRegistry DDSpecParRegistry
Definition: DDCompactView.h:28
shared_ptr< DTGeometry > ReturnType
edm::ESGetToken< Alignments, GlobalPositionRcd > m_globalPositionToken
ReusableObjectHolder< HostType > m_holder
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:61
std::shared_ptr< T > makeOrGet(FM &&iMakeFunc)
Takes an object from the queue if one is available, or creates one using iMakeFunc.
Namespace of DDCMS conversion namespace.
Log< level::Info, false > LogInfo
Definition: DetId.h:17
ReturnType produce(const MuonGeometryRecord &record)
edm::ESGetToken< DDSpecParRegistry, DDSpecParRegistryRcd > m_registryToken
T const * product() const
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