CMS 3D CMS Logo

PPSGeometryBuilder.cc
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * DB builder for PPS geometry
4  *
5  * Author: Wagner Carvalho (wcarvalh@cern.ch)
6  * Moved out common functionalities to DetGeomDesc(Builder) + support both old DD and DD4hep, by Gabrielle Hugo.
7  *
8  ****************************************************************************/
9 
20 
25 
28 
30 public:
31  explicit PPSGeometryBuilder(const edm::ParameterSet&);
32  void analyze(const edm::Event&, const edm::EventSetup&) override;
33 
34 private:
35  void buildSerializableDataFromGeoInfo(PDetGeomDesc* serializableData, const DetGeomDesc* geoInfo, int& counter);
37 
38  bool fromDD4hep_;
44 };
45 
47  : fromDD4hep_(iConfig.getUntrackedParameter<bool>("fromDD4hep", false)),
48  compactViewTag_(iConfig.getUntrackedParameter<std::string>("compactViewTag", "XMLIdealGeometryESSource_CTPPS")),
49  ddToken_(esConsumes(edm::ESInputTag("", compactViewTag_))),
50  dd4hepToken_(esConsumes(edm::ESInputTag("", compactViewTag_))) {}
51 
52 /*
53  * Save PPS geo to DB.
54  */
56  // Get DetGeomDesc tree
57  std::unique_ptr<DetGeomDesc> geoInfoRoot = nullptr;
58  if (watcherIdealGeometry_.check(iSetup)) {
59  edm::LogInfo("PPSGeometryBuilder") << "Got IdealGeometryRecord ";
60  // old DD
61  if (!fromDD4hep_) {
62  // Get CompactView from IdealGeometryRecord
63  auto const& myCompactView = iSetup.getData(ddToken_);
64 
65  // Build geometry
66  geoInfoRoot = detgeomdescbuilder::buildDetGeomDescFromCompactView(myCompactView);
67  }
68  // DD4hep
69  else {
70  // Get CompactView from IdealGeometryRecord
71  auto const& myCompactView = iSetup.getData(dd4hepToken_);
72 
73  // Build geometry
74  geoInfoRoot = detgeomdescbuilder::buildDetGeomDescFromCompactView(myCompactView);
75  }
76  }
77 
78  // Build persistent geometry data from geometry
79  PDetGeomDesc* serializableData =
80  new PDetGeomDesc(); // cond::service::PoolDBOutputService::writeOne interface requires raw pointer.
81  int counter = 0;
82  if (geoInfoRoot) {
83  buildSerializableDataFromGeoInfo(serializableData, geoInfoRoot.get(), counter);
84  }
85 
86  // Save geometry in the database
87  if (serializableData->container_.empty()) {
88  throw cms::Exception("PPSGeometryBuilder") << "PDetGeomDesc is empty, no geometry to save in the database.";
89  } else {
90  if (dbService_.isAvailable()) {
91  dbService_->writeOne(serializableData, dbService_->beginOfTime(), "VeryForwardIdealGeometryRecord");
92  edm::LogInfo("PPSGeometryBuilder") << "Successfully wrote DB, with " << serializableData->container_.size()
93  << " PDetGeomDesc items.";
94  } else {
95  throw cms::Exception("PPSGeometryBuilder") << "PoolDBService required.";
96  }
97  }
98 }
99 
100 /*
101  * Build persistent data items to be stored in DB (PDetGeomDesc) from geo info (DetGeomDesc).
102  * Recursive, depth-first search.
103  */
105  const DetGeomDesc* geoInfo,
106  int& counter) {
107  PDetGeomDesc::Item serializableItem = buildItemFromDetGeomDesc(geoInfo);
108  counter++;
109 
110  // Store item in serializableData
111  if ((!fromDD4hep_ && counter >= 2) // Old DD: Skip CMSE
112  || (fromDD4hep_ && counter >= 4)) { // DD4hep: Skip world + OCMS + CMSE
113  serializableData->container_.emplace_back(serializableItem);
114  }
115 
116  // Recursive calls on children
117  for (auto& child : geoInfo->components()) {
118  buildSerializableDataFromGeoInfo(serializableData, child, counter);
119  }
120 }
121 
122 /*
123  * Build Item from DetGeomDesc info.
124  */
127  result.dx_ = geoInfo->translation().X();
128  result.dy_ = geoInfo->translation().Y();
129  result.dz_ = geoInfo->translation().Z();
130 
131  const DDRotationMatrix& rot = geoInfo->rotation();
132  rot.GetComponents(result.axx_,
133  result.axy_,
134  result.axz_,
135  result.ayx_,
136  result.ayy_,
137  result.ayz_,
138  result.azx_,
139  result.azy_,
140  result.azz_);
141  result.name_ = geoInfo->name();
142  result.params_ = geoInfo->params();
143  result.copy_ = geoInfo->copyno();
144  result.z_ = geoInfo->parentZPosition();
145  result.sensorType_ = geoInfo->sensorType();
146  result.geographicalID_ = geoInfo->geographicalID();
147 
148  return result;
149 }
150 
PPSGeometryBuilder::watcherIdealGeometry_
edm::ESWatcher< IdealGeometryRecord > watcherIdealGeometry_
Definition: PPSGeometryBuilder.cc:48
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
counter
Definition: counter.py:1
electrons_cff.bool
bool
Definition: electrons_cff.py:393
EDAnalyzer.h
PPSGeometryBuilder::PPSGeometryBuilder
PPSGeometryBuilder(const edm::ParameterSet &)
Definition: PPSGeometryBuilder.cc:46
funct::false
false
Definition: Factorize.h:29
cond::service::PoolDBOutputService::beginOfTime
cond::Time_t beginOfTime() const
Definition: PoolDBOutputService.cc:215
edm::ESWatcher< IdealGeometryRecord >
PPSGeometryBuilder::compactViewTag_
std::string compactViewTag_
Definition: PPSGeometryBuilder.cc:45
ESHandle.h
DetGeomDesc::translation
const Translation & translation() const
Definition: DetGeomDesc.h:73
ESInputTag
PDetGeomDesc::Item
Definition: PDetGeomDesc.h:11
edm
HLT enums.
Definition: AlignableModifier.h:19
DetGeomDesc::sensorType
const std::string & sensorType() const
Definition: DetGeomDesc.h:91
PPSGeometryBuilder::buildItemFromDetGeomDesc
PDetGeomDesc::Item buildItemFromDetGeomDesc(const DetGeomDesc *geoInfo)
Definition: PPSGeometryBuilder.cc:125
PPSGeometryBuilder
Definition: PPSGeometryBuilder.cc:29
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
DetGeomDesc::parentZPosition
float parentZPosition() const
Definition: DetGeomDesc.h:98
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
PPSGeometryBuilder::buildSerializableDataFromGeoInfo
void buildSerializableDataFromGeoInfo(PDetGeomDesc *serializableData, const DetGeomDesc *geoInfo, int &counter)
Definition: PPSGeometryBuilder.cc:104
DDCompactView.h
MakerMacros.h
PoolDBOutputService.h
DetGeomDesc::geographicalID
DetId geographicalID() const
Definition: DetGeomDesc.h:94
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PDetGeomDesc.h
Service.h
DDCompactView.h
PDetGeomDesc::container_
std::vector< Item > container_
Definition: PDetGeomDesc.h:26
PPSGeometryBuilder::dbService_
edm::Service< cond::service::PoolDBOutputService > dbService_
Definition: PPSGeometryBuilder.cc:49
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
DetGeomDesc::components
const Container & components() const
Definition: DetGeomDesc.h:97
PPSGeometryBuilder::dd4hepToken_
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > dd4hepToken_
Definition: PPSGeometryBuilder.cc:47
DetGeomDesc::name
const std::string & name() const
Definition: DetGeomDesc.h:66
DetGeomDescBuilder.h
edm::Service< cond::service::PoolDBOutputService >
iEvent
int iEvent
Definition: GenABIO.cc:224
DetGeomDesc
Definition: DetGeomDesc.h:49
IdealGeometryRecord.h
PPSGeometryBuilder::fromDD4hep_
bool fromDD4hep_
Definition: PPSGeometryBuilder.cc:44
counter
static std::atomic< unsigned int > counter
Definition: SharedResourceNames.cc:17
edm::EventSetup
Definition: EventSetup.h:57
PDetGeomDesc
Definition: PDetGeomDesc.h:9
PPSGeometryBuilder::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: PPSGeometryBuilder.cc:55
edm::ESGetToken< DDCompactView, IdealGeometryRecord >
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:120
detgeomdescbuilder::buildDetGeomDescFromCompactView
std::unique_ptr< DetGeomDesc > buildDetGeomDescFromCompactView(const DDCompactView &myCompactView)
Definition: DetGeomDescBuilder.cc:9
VeryForwardIdealGeometryRecord.h
std
Definition: JetResolutionObject.h:76
DDRotationMatrix
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
Definition: DDRotationMatrix.h:8
PPSGeometryBuilder::ddToken_
edm::ESGetToken< DDCompactView, IdealGeometryRecord > ddToken_
Definition: PPSGeometryBuilder.cc:46
ESWatcher.h
Exception
Definition: hltDiff.cc:246
cond::service::PoolDBOutputService::writeOne
Hash writeOne(const T *payload, Time_t time, const std::string &recordName)
Definition: PoolDBOutputService.h:63
makeMuonMisalignmentScenario.rot
rot
Definition: makeMuonMisalignmentScenario.py:322
EventSetup.h
Exception.h
DetGeomDesc::params
const std::vector< double > & params() const
Definition: DetGeomDesc.h:80
mps_fire.result
result
Definition: mps_fire.py:311
ParameterSet.h
DetGeomDesc::copyno
int copyno() const
Definition: DetGeomDesc.h:67
DetGeomDesc::rotation
const RotationMatrix & rotation() const
Definition: DetGeomDesc.h:74
edm::Event
Definition: Event.h:73
child
Definition: simpleInheritance.h:11