66* Rewritten + Moved out common functionailities to DetGeomDesc(Builder) by Gabrielle Hugo.
77* Migrated to DD4hep by Wagner Carvalho and Gabrielle Hugo.
88*
9+ * Add the capability of reading PPS reco geometry from the database
10+ *
911****************************************************************************/
1012
1113#include " FWCore/ParameterSet/interface/ParameterSet.h"
1921#include " DetectorDescription/DDCMS/interface/DDCompactView.h"
2022#include " CondFormats/PPSObjects/interface/CTPPSRPAlignmentCorrectionsData.h"
2123
24+ #include " CondFormats/GeometryObjects/interface/PDetGeomDesc.h"
2225#include " CondFormats/AlignmentRecord/interface/RPRealAlignmentRecord.h"
2326#include " CondFormats/AlignmentRecord/interface/RPMisalignedAlignmentRecord.h"
2427#include " Geometry/Records/interface/IdealGeometryRecord.h"
28+ #include " Geometry/Records/interface/VeryForwardIdealGeometryRecord.h"
2529#include " Geometry/Records/interface/VeryForwardMisalignedGeometryRecord.h"
2630#include " Geometry/Records/interface/VeryForwardRealGeometryRecord.h"
2731
@@ -55,68 +59,96 @@ class CTPPSGeometryESModule : public edm::ESProducer {
5559
5660private:
5761 std::unique_ptr<DetGeomDesc> produceIdealGD (const IdealGeometryRecord&);
62+ std::unique_ptr<DetGeomDesc> produceIdealGDFromPreprocessedDB (const VeryForwardIdealGeometryRecord&);
5863 std::vector<int > fillCopyNos (TGeoIterator& it);
5964
60- template <typename ALIGNMENT_REC>
61- struct GDTokens {
62- explicit GDTokens (edm::ESConsumesCollector&& iCC)
63- : idealGDToken_{iCC.consumesFrom <DetGeomDesc, IdealGeometryRecord>(edm::ESInputTag ())},
64- alignmentToken_{iCC.consumesFrom <CTPPSRPAlignmentCorrectionsData, ALIGNMENT_REC>(edm::ESInputTag ())} {}
65- const edm::ESGetToken<DetGeomDesc, IdealGeometryRecord> idealGDToken_;
66- const edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, ALIGNMENT_REC> alignmentToken_;
67- };
68-
6965 std::unique_ptr<DetGeomDesc> produceRealGD (const VeryForwardRealGeometryRecord&);
66+ std::unique_ptr<DetGeomDesc> produceRealGDFromPreprocessedDB (const VeryForwardRealGeometryRecord&);
7067 std::unique_ptr<CTPPSGeometry> produceRealTG (const VeryForwardRealGeometryRecord&);
7168
7269 std::unique_ptr<DetGeomDesc> produceMisalignedGD (const VeryForwardMisalignedGeometryRecord&);
70+ std::unique_ptr<DetGeomDesc> produceMisalignedGDFromPreprocessedDB (const VeryForwardMisalignedGeometryRecord&);
7371 std::unique_ptr<CTPPSGeometry> produceMisalignedTG (const VeryForwardMisalignedGeometryRecord&);
7472
75- template <typename REC>
76- std::unique_ptr<DetGeomDesc> produceGD (IdealGeometryRecord const &,
73+ template <typename REC, typename GEO >
74+ std::unique_ptr<DetGeomDesc> produceGD (const GEO &,
7775 const std::optional<REC>&,
78- GDTokens<REC> const &,
76+ edm::ESGetToken<DetGeomDesc, GEO> const &,
77+ edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, REC> const &,
7978 const char * name);
8079
8180 const unsigned int verbosity_;
8281 const bool isRun2_;
8382
8483 edm::ESGetToken<DDCompactView, IdealGeometryRecord> ddToken_;
8584 edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> dd4hepToken_;
86- const bool fromDD4hep_;
85+ edm::ESGetToken<PDetGeomDesc, VeryForwardIdealGeometryRecord> dbToken_;
86+ const bool fromPreprocessedDB_, fromDD4hep_;
8787
88- const GDTokens<RPRealAlignmentRecord> gdRealTokens_;
89- const GDTokens<RPMisalignedAlignmentRecord> gdMisTokens_;
88+ edm::ESGetToken<DetGeomDesc, IdealGeometryRecord> idealGDToken_;
89+ edm::ESGetToken<DetGeomDesc, VeryForwardIdealGeometryRecord> idealDBGDToken_;
90+ edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, RPRealAlignmentRecord> realAlignmentToken_;
91+ edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, RPMisalignedAlignmentRecord> misAlignmentToken_;
9092
91- const edm::ESGetToken<DetGeomDesc, VeryForwardRealGeometryRecord> dgdRealToken_;
92- const edm::ESGetToken<DetGeomDesc, VeryForwardMisalignedGeometryRecord> dgdMisToken_;
93+ edm::ESGetToken<DetGeomDesc, VeryForwardRealGeometryRecord> dgdRealToken_;
94+ edm::ESGetToken<DetGeomDesc, VeryForwardMisalignedGeometryRecord> dgdMisToken_;
9395};
9496
9597CTPPSGeometryESModule::CTPPSGeometryESModule (const edm::ParameterSet& iConfig)
9698 : verbosity_(iConfig.getUntrackedParameter<unsigned int >(" verbosity" )),
9799 isRun2_(iConfig.getParameter<bool >(" isRun2" )),
98- fromDD4hep_(iConfig.getUntrackedParameter<bool >(" fromDD4hep" , false )),
99- gdRealTokens_{setWhatProduced (this , &CTPPSGeometryESModule::produceRealGD)},
100- gdMisTokens_{setWhatProduced (this , &CTPPSGeometryESModule::produceMisalignedGD)},
101- dgdRealToken_{
102- setWhatProduced (this , &CTPPSGeometryESModule::produceRealTG).consumes <DetGeomDesc>(edm::ESInputTag ())},
103- dgdMisToken_{
104- setWhatProduced (this , &CTPPSGeometryESModule::produceMisalignedTG).consumes <DetGeomDesc>(edm::ESInputTag ())} {
105- auto c = setWhatProduced (this , &CTPPSGeometryESModule::produceIdealGD);
106-
107- if (!fromDD4hep_) {
100+ fromPreprocessedDB_(iConfig.getUntrackedParameter<bool >(" fromPreprocessedDB" , false )),
101+ fromDD4hep_(iConfig.getUntrackedParameter<bool >(" fromDD4hep" , false )) {
102+ if (fromPreprocessedDB_) {
103+ auto c = setWhatProduced (this , &CTPPSGeometryESModule::produceIdealGDFromPreprocessedDB);
104+ dbToken_ = c.consumes <PDetGeomDesc>(edm::ESInputTag (" " , iConfig.getParameter <std::string>(" dbTag" )));
105+
106+ auto c1 = setWhatProduced (this , &CTPPSGeometryESModule::produceRealGDFromPreprocessedDB);
107+ idealDBGDToken_ = c1.consumesFrom <DetGeomDesc, VeryForwardIdealGeometryRecord>(edm::ESInputTag ());
108+ realAlignmentToken_ = c1.consumesFrom <CTPPSRPAlignmentCorrectionsData, RPRealAlignmentRecord>(edm::ESInputTag ());
109+
110+ auto c2 = setWhatProduced (this , &CTPPSGeometryESModule::produceMisalignedGDFromPreprocessedDB);
111+ misAlignmentToken_ =
112+ c2.consumesFrom <CTPPSRPAlignmentCorrectionsData, RPMisalignedAlignmentRecord>(edm::ESInputTag ());
113+ } else if (!fromDD4hep_) {
114+ auto c = setWhatProduced (this , &CTPPSGeometryESModule::produceIdealGD);
108115 ddToken_ = c.consumes <DDCompactView>(edm::ESInputTag (" " , iConfig.getParameter <std::string>(" compactViewTag" )));
116+
117+ auto c1 = setWhatProduced (this , &CTPPSGeometryESModule::produceRealGD);
118+ idealGDToken_ = c1.consumesFrom <DetGeomDesc, IdealGeometryRecord>(edm::ESInputTag ());
119+ realAlignmentToken_ = c1.consumesFrom <CTPPSRPAlignmentCorrectionsData, RPRealAlignmentRecord>(edm::ESInputTag ());
120+
121+ auto c2 = setWhatProduced (this , &CTPPSGeometryESModule::produceMisalignedGD);
122+ misAlignmentToken_ =
123+ c2.consumesFrom <CTPPSRPAlignmentCorrectionsData, RPMisalignedAlignmentRecord>(edm::ESInputTag ());
109124 } else {
125+ auto c = setWhatProduced (this , &CTPPSGeometryESModule::produceIdealGD);
110126 dd4hepToken_ =
111127 c.consumes <cms::DDCompactView>(edm::ESInputTag (" " , iConfig.getParameter <std::string>(" compactViewTag" )));
128+
129+ auto c1 = setWhatProduced (this , &CTPPSGeometryESModule::produceRealGD);
130+ idealGDToken_ = c1.consumesFrom <DetGeomDesc, IdealGeometryRecord>(edm::ESInputTag ());
131+ realAlignmentToken_ = c1.consumesFrom <CTPPSRPAlignmentCorrectionsData, RPRealAlignmentRecord>(edm::ESInputTag ());
132+
133+ auto c2 = setWhatProduced (this , &CTPPSGeometryESModule::produceMisalignedGD);
134+ misAlignmentToken_ =
135+ c2.consumesFrom <CTPPSRPAlignmentCorrectionsData, RPMisalignedAlignmentRecord>(edm::ESInputTag ());
112136 }
137+
138+ auto c_RTG = setWhatProduced (this , &CTPPSGeometryESModule::produceRealTG);
139+ dgdRealToken_ = c_RTG.consumes <DetGeomDesc>(edm::ESInputTag ());
140+
141+ auto c_MTG = setWhatProduced (this , &CTPPSGeometryESModule::produceMisalignedTG);
142+ dgdMisToken_ = c_MTG.consumes <DetGeomDesc>(edm::ESInputTag ());
113143}
114144
115145void CTPPSGeometryESModule::fillDescriptions (edm::ConfigurationDescriptions& descriptions) {
116146 edm::ParameterSetDescription desc;
117147 desc.addUntracked <unsigned int >(" verbosity" , 1 );
118148 desc.add <bool >(" isRun2" , false )->setComment (" Switch to legacy (2017-18) definition of diamond geometry" );
149+ desc.add <std::string>(" dbTag" , std::string ());
119150 desc.add <std::string>(" compactViewTag" , std::string ());
151+ desc.addUntracked <bool >(" fromPreprocessedDB" , false );
120152 desc.addUntracked <bool >(" fromDD4hep" , false );
121153 descriptions.add (" CTPPSGeometryESModule" , desc);
122154}
@@ -139,18 +171,32 @@ std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceIdealGD(const IdealGe
139171 }
140172}
141173
142- template <typename REC>
143- std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceGD (IdealGeometryRecord const & iIdealRec,
144- std::optional<REC> const & iAlignRec,
145- GDTokens<REC> const & iTokens,
146- const char * name) {
174+ std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceIdealGDFromPreprocessedDB (
175+ const VeryForwardIdealGeometryRecord& iRecord) {
176+ // Get the PDetGeomDesc from EventSetup
177+ auto const & myDB = iRecord.get (dbToken_);
178+
179+ edm::LogInfo (" CTPPSGeometryESModule" ) << " myDB size = " << myDB.container_ .size ();
180+
181+ // Build geo from PDetGeomDesc DB object.
182+ auto pdet = std::make_unique<DetGeomDesc>(myDB);
183+ return pdet;
184+ }
185+
186+ template <typename REC, typename GEO>
187+ std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceGD (
188+ GEO const & iIdealRec,
189+ std::optional<REC> const & iAlignRec,
190+ edm::ESGetToken<DetGeomDesc, GEO> const & iGDToken,
191+ edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, REC> const & iAlignToken,
192+ const char * name) {
147193 // get the input GeometricalDet
148- auto const & idealGD = iIdealRec.get (iTokens. idealGDToken_ );
194+ auto const & idealGD = iIdealRec.get (iGDToken );
149195
150196 // load alignments
151197 CTPPSRPAlignmentCorrectionsData const * alignments = nullptr ;
152198 if (iAlignRec) {
153- auto alignmentsHandle = iAlignRec->getHandle (iTokens. alignmentToken_ );
199+ auto alignmentsHandle = iAlignRec->getHandle (iAlignToken );
154200 if (alignmentsHandle.isValid ()) {
155201 alignments = alignmentsHandle.product ();
156202 }
@@ -168,10 +214,33 @@ std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceGD(IdealGeometryRecor
168214 return CTPPSGeometryESCommon::applyAlignments (idealGD, alignments);
169215}
170216
217+ std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceRealGDFromPreprocessedDB (
218+ const VeryForwardRealGeometryRecord& iRecord) {
219+ return produceGD (iRecord.getRecord <VeryForwardIdealGeometryRecord>(),
220+ iRecord.tryToGetRecord <RPRealAlignmentRecord>(),
221+ idealDBGDToken_,
222+ realAlignmentToken_,
223+ " CTPPSGeometryESModule::produceRealGDFromPreprocessedDB" );
224+ }
225+
226+ // ----------------------------------------------------------------------------------------------------
227+
228+ std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceMisalignedGDFromPreprocessedDB (
229+ const VeryForwardMisalignedGeometryRecord& iRecord) {
230+ return produceGD (iRecord.getRecord <VeryForwardIdealGeometryRecord>(),
231+ iRecord.tryToGetRecord <RPMisalignedAlignmentRecord>(),
232+ idealDBGDToken_,
233+ misAlignmentToken_,
234+ " CTPPSGeometryESModule::produceMisalignedGDFromPreprocessedDB" );
235+ }
236+
237+ // ----------------------------------------------------------------------------------------------------
238+
171239std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceRealGD (const VeryForwardRealGeometryRecord& iRecord) {
172240 return produceGD (iRecord.getRecord <IdealGeometryRecord>(),
173241 iRecord.tryToGetRecord <RPRealAlignmentRecord>(),
174- gdRealTokens_,
242+ idealGDToken_,
243+ realAlignmentToken_,
175244 " CTPPSGeometryESModule::produceRealGD" );
176245}
177246
@@ -181,7 +250,8 @@ std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceMisalignedGD(
181250 const VeryForwardMisalignedGeometryRecord& iRecord) {
182251 return produceGD (iRecord.getRecord <IdealGeometryRecord>(),
183252 iRecord.tryToGetRecord <RPMisalignedAlignmentRecord>(),
184- gdMisTokens_,
253+ idealGDToken_,
254+ misAlignmentToken_,
185255 " CTPPSGeometryESModule::produceMisalignedGD" );
186256}
187257
0 commit comments