CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 =
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 
const std::vector< double > & params() const
Definition: DetGeomDesc.h:88
uint32_t geographicalID_
Definition: PDetGeomDesc.h:18
DetId geographicalID() const
Definition: DetGeomDesc.h:102
const Translation & translation() const
Definition: DetGeomDesc.h:80
const std::string & sensorType() const
Definition: DetGeomDesc.h:99
edm::ESWatcher< IdealGeometryRecord > watcherIdealGeometry_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PPSGeometryBuilder(const edm::ParameterSet &)
Hash writeOne(const T *payloadPtr, Time_t time, const std::string &recordName)
tuple result
Definition: mps_fire.py:311
bool getData(T &iHolder) const
Definition: EventSetup.h:128
int iEvent
Definition: GenABIO.cc:224
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)
bool isAvailable() const
Definition: Service.h:40
std::vector< Item > container_
Definition: PDetGeomDesc.h:26
std::unique_ptr< DetGeomDesc > buildDetGeomDescFromCompactView(const DDCompactView &myCompactView, const bool isRun2)
const Container & components() const
Definition: DetGeomDesc.h:105
edm::ESGetToken< DDCompactView, IdealGeometryRecord > ddToken_
const std::string & name() const
Definition: DetGeomDesc.h:73
Log< level::Info, false > LogInfo
edm::Service< cond::service::PoolDBOutputService > dbService_
std::vector< double > params_
Definition: PDetGeomDesc.h:17
int copyno() const
Definition: DetGeomDesc.h:74
float parentZPosition() const
Definition: DetGeomDesc.h:106
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
static std::atomic< unsigned int > counter
std::string name_
Definition: PDetGeomDesc.h:16
const RotationMatrix & rotation() const
Definition: DetGeomDesc.h:81
void analyze(const edm::Event &, const edm::EventSetup &) override
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::string sensorType_
Definition: PDetGeomDesc.h:21