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 
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; // cond::service::PoolDBOutputService::writeOne interface requires raw pointer.
82  int counter = 0;
83  if (geoInfoRoot) {
84  buildSerializableDataFromGeoInfo(&serializableData, geoInfoRoot.get(), counter);
85  }
86 
87  // Save geometry in the database
88  if (serializableData.container_.empty()) {
89  throw cms::Exception("PPSGeometryBuilder") << "PDetGeomDesc is empty, no geometry to save in the database.";
90  } else {
91  if (dbService_.isAvailable()) {
92  dbService_->writeOneIOV(serializableData, dbService_->beginOfTime(), "VeryForwardIdealGeometryRecord");
93  edm::LogInfo("PPSGeometryBuilder") << "Successfully wrote DB, with " << serializableData.container_.size()
94  << " PDetGeomDesc items.";
95  } else {
96  throw cms::Exception("PPSGeometryBuilder") << "PoolDBService required.";
97  }
98  }
99 }
100 
101 /*
102  * Build persistent data items to be stored in DB (PDetGeomDesc) from geo info (DetGeomDesc).
103  * Recursive, depth-first search.
104  */
106  const DetGeomDesc* geoInfo,
107  int& counter) {
108  PDetGeomDesc::Item serializableItem = buildItemFromDetGeomDesc(geoInfo);
109  counter++;
110 
111  // Store item in serializableData
112  if ((!fromDD4hep_ && counter >= 2) // Old DD: Skip CMSE
113  || (fromDD4hep_ && counter >= 4)) { // DD4hep: Skip world + OCMS + CMSE
114  serializableData->container_.emplace_back(serializableItem);
115  }
116 
117  // Recursive calls on children
118  for (auto& child : geoInfo->components()) {
119  buildSerializableDataFromGeoInfo(serializableData, child, counter);
120  }
121 }
122 
123 /*
124  * Build Item from DetGeomDesc info.
125  */
128  result.dx_ = geoInfo->translation().X();
129  result.dy_ = geoInfo->translation().Y();
130  result.dz_ = geoInfo->translation().Z();
131 
132  const DDRotationMatrix& rot = geoInfo->rotation();
133  rot.GetComponents(result.axx_,
134  result.axy_,
135  result.axz_,
136  result.ayx_,
137  result.ayy_,
138  result.ayz_,
139  result.azx_,
140  result.azy_,
141  result.azz_);
142  result.name_ = geoInfo->name();
143  result.params_ = geoInfo->params();
144  result.copy_ = geoInfo->copyno();
145  result.z_ = geoInfo->parentZPosition();
146  result.sensorType_ = geoInfo->sensorType();
147  result.geographicalID_ = geoInfo->geographicalID();
148 
149  return result;
150 }
151 
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const Translation & translation() const
Definition: DetGeomDesc.h:80
int copyno() const
Definition: DetGeomDesc.h:74
edm::ESWatcher< IdealGeometryRecord > watcherIdealGeometry_
DetId geographicalID() const
Definition: DetGeomDesc.h:102
PPSGeometryBuilder(const edm::ParameterSet &)
const std::string & sensorType() const
Definition: DetGeomDesc.h:99
const Container & components() const
Definition: DetGeomDesc.h:105
int iEvent
Definition: GenABIO.cc:224
float parentZPosition() const
Definition: DetGeomDesc.h:106
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > dd4hepToken_
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
PDetGeomDesc::Item buildItemFromDetGeomDesc(const DetGeomDesc *geoInfo)
void buildSerializableDataFromGeoInfo(PDetGeomDesc *serializableData, const DetGeomDesc *geoInfo, int &counter)
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool getData(T &iHolder) const
Definition: EventSetup.h:122
std::vector< Item > container_
Definition: PDetGeomDesc.h:26
std::unique_ptr< DetGeomDesc > buildDetGeomDescFromCompactView(const DDCompactView &myCompactView, const bool isRun2)
edm::ESGetToken< DDCompactView, IdealGeometryRecord > ddToken_
Log< level::Info, false > LogInfo
edm::Service< cond::service::PoolDBOutputService > dbService_
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
const RotationMatrix & rotation() const
Definition: DetGeomDesc.h:81
const std::string & name() const
Definition: DetGeomDesc.h:73
HLT enums.
static std::atomic< unsigned int > counter
bool isAvailable() const
Definition: Service.h:40
void analyze(const edm::Event &, const edm::EventSetup &) override
const std::vector< double > & params() const
Definition: DetGeomDesc.h:88