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_;
40  bool isRun2_;
45 };
46 
48  : fromDD4hep_(iConfig.getUntrackedParameter<bool>("fromDD4hep", false)),
49  compactViewTag_(iConfig.getUntrackedParameter<std::string>("compactViewTag", "XMLIdealGeometryESSource_CTPPS")),
50  isRun2_(iConfig.getUntrackedParameter<bool>("isRun2", false)),
51  ddToken_(esConsumes(edm::ESInputTag("", compactViewTag_))),
52  dd4hepToken_(esConsumes(edm::ESInputTag("", compactViewTag_))) {}
53 
54 /*
55  * Save PPS geo to DB.
56  */
58  // Get DetGeomDesc tree
59  std::unique_ptr<DetGeomDesc> geoInfoRoot = nullptr;
60  if (watcherIdealGeometry_.check(iSetup)) {
61  edm::LogInfo("PPSGeometryBuilder") << "Got IdealGeometryRecord ";
62  // old DD
63  if (!fromDD4hep_) {
64  // Get CompactView from IdealGeometryRecord
65  auto const& myCompactView = iSetup.getData(ddToken_);
66 
67  // Build geometry
69  }
70  // DD4hep
71  else {
72  // Get CompactView from IdealGeometryRecord
73  auto const& myCompactView = iSetup.getData(dd4hepToken_);
74 
75  // Build geometry
77  }
78  }
79 
80  // Build persistent geometry data from geometry
81  PDetGeomDesc* serializableData =
82  new PDetGeomDesc(); // cond::service::PoolDBOutputService::writeOne interface requires raw pointer.
83  int counter = 0;
84  if (geoInfoRoot) {
85  buildSerializableDataFromGeoInfo(serializableData, geoInfoRoot.get(), counter);
86  }
87 
88  // Save geometry in the database
89  if (serializableData->container_.empty()) {
90  throw cms::Exception("PPSGeometryBuilder") << "PDetGeomDesc is empty, no geometry to save in the database.";
91  } else {
92  if (dbService_.isAvailable()) {
93  dbService_->writeOne(serializableData, dbService_->beginOfTime(), "VeryForwardIdealGeometryRecord");
94  edm::LogInfo("PPSGeometryBuilder") << "Successfully wrote DB, with " << serializableData->container_.size()
95  << " PDetGeomDesc items.";
96  } else {
97  throw cms::Exception("PPSGeometryBuilder") << "PoolDBService required.";
98  }
99  }
100 }
101 
102 /*
103  * Build persistent data items to be stored in DB (PDetGeomDesc) from geo info (DetGeomDesc).
104  * Recursive, depth-first search.
105  */
107  const DetGeomDesc* geoInfo,
108  int& counter) {
109  PDetGeomDesc::Item serializableItem = buildItemFromDetGeomDesc(geoInfo);
110  counter++;
111 
112  // Store item in serializableData
113  if ((!fromDD4hep_ && counter >= 2) // Old DD: Skip CMSE
114  || (fromDD4hep_ && counter >= 4)) { // DD4hep: Skip world + OCMS + CMSE
115  serializableData->container_.emplace_back(serializableItem);
116  }
117 
118  // Recursive calls on children
119  for (auto& child : geoInfo->components()) {
120  buildSerializableDataFromGeoInfo(serializableData, child, counter);
121  }
122 }
123 
124 /*
125  * Build Item from DetGeomDesc info.
126  */
129  result.dx_ = geoInfo->translation().X();
130  result.dy_ = geoInfo->translation().Y();
131  result.dz_ = geoInfo->translation().Z();
132 
133  const DDRotationMatrix& rot = geoInfo->rotation();
134  rot.GetComponents(result.axx_,
135  result.axy_,
136  result.axz_,
137  result.ayx_,
138  result.ayy_,
139  result.ayz_,
140  result.azx_,
141  result.azy_,
142  result.azz_);
143  result.name_ = geoInfo->name();
144  result.params_ = geoInfo->params();
145  result.copy_ = geoInfo->copyno();
146  result.z_ = geoInfo->parentZPosition();
147  result.sensorType_ = geoInfo->sensorType();
148  result.geographicalID_ = geoInfo->geographicalID();
149 
150  return result;
151 }
152 
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:366
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:44
ESHandle.h
DetGeomDesc::translation
const Translation & translation() const
Definition: DetGeomDesc.h:75
ESInputTag
PDetGeomDesc::Item
Definition: PDetGeomDesc.h:11
edm
HLT enums.
Definition: AlignableModifier.h:19
DetGeomDesc::sensorType
const std::string & sensorType() const
Definition: DetGeomDesc.h:94
PPSGeometryBuilder::buildItemFromDetGeomDesc
PDetGeomDesc::Item buildItemFromDetGeomDesc(const DetGeomDesc *geoInfo)
Definition: PPSGeometryBuilder.cc:126
PPSGeometryBuilder
Definition: PPSGeometryBuilder.cc:28
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:101
PPSGeometryBuilder::isRun2_
bool isRun2_
Definition: PPSGeometryBuilder.cc:45
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
PPSGeometryBuilder::buildSerializableDataFromGeoInfo
void buildSerializableDataFromGeoInfo(PDetGeomDesc *serializableData, const DetGeomDesc *geoInfo, int &counter)
Definition: PPSGeometryBuilder.cc:105
DDCompactView.h
MakerMacros.h
PoolDBOutputService.h
DetGeomDesc::geographicalID
DetId geographicalID() const
Definition: DetGeomDesc.h:97
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:100
PPSGeometryBuilder::dd4hepToken_
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > dd4hepToken_
Definition: PPSGeometryBuilder.cc:47
DetGeomDesc::name
const std::string & name() const
Definition: DetGeomDesc.h:68
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:43
counter
static std::atomic< unsigned int > counter
Definition: SharedResourceNames.cc:18
edm::EventSetup
Definition: EventSetup.h:58
PDetGeomDesc
Definition: PDetGeomDesc.h:9
PPSGeometryBuilder::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: PPSGeometryBuilder.cc:56
edm::ESGetToken< DDCompactView, IdealGeometryRecord >
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
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:245
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:83
mps_fire.result
result
Definition: mps_fire.py:311
ParameterSet.h
DetGeomDesc::copyno
int copyno() const
Definition: DetGeomDesc.h:69
DetGeomDesc::rotation
const RotationMatrix & rotation() const
Definition: DetGeomDesc.h:76
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
child
Definition: simpleInheritance.h:11
detgeomdescbuilder::buildDetGeomDescFromCompactView
std::unique_ptr< DetGeomDesc > buildDetGeomDescFromCompactView(const DDCompactView &myCompactView, const bool isRun2)
Definition: DetGeomDescBuilder.cc:10