ATLAS Offline Software
Loading...
Searching...
No Matches
TopLevelPlacements.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4
6#include "GaudiKernel/SystemOfUnits.h"
9#include <iostream>
10#include <utility>
11
12
13const GeoTrf::Transform3D TopLevelPlacements::s_identityTransform = GeoTrf::Transform3D::Identity();
14
16 : m_noTopLevelTable(true) {
17 fillPlacements(topLevelTable);
18}
19
21 std::map<std::string, Part*>::const_iterator iter;
22 for (iter = m_parts.begin(); iter != m_parts.end(); ++iter) delete iter->second;
23}
24
25const GeoTrf::Transform3D&
26TopLevelPlacements::transform(const std::string& partName) const {
27 Part* part = getPart(partName);
28
29 if (part) return part->transform;
30
32}
33
34bool
35TopLevelPlacements::present(const std::string& partName) const {
36 // If no table present assume everything is present.
37 if (m_noTopLevelTable) return true;
38
39 return(getPart(partName) != nullptr);
40}
41
42void
44 if (topLevelTable.get() == nullptr) {
45 m_noTopLevelTable = true;
46 return;
47 }
48 m_noTopLevelTable = false;
49 int numParts = topLevelTable->size();
50 for (int i = 0; i < numParts; i++) {
51 const IRDBRecord* record = (*topLevelTable)[i];
52 std::string label = record->getString("LABEL");
53
54 Part* part = new Part;
55 part->label = label;
56 part->transform = partTransform(record);
57
58 m_parts[label] = part;
59 }
60}
61
62GeoTrf::Transform3D
64 double posX = record->getDouble("POSX") * Gaudi::Units::mm;
65 double posY = record->getDouble("POSY") * Gaudi::Units::mm;
66 double posZ = record->getDouble("POSZ") * Gaudi::Units::mm;
67 double rotX = record->getDouble("ROTX") * Gaudi::Units::degree;
68 double rotY = record->getDouble("ROTY") * Gaudi::Units::degree;
69 double rotZ = record->getDouble("ROTZ") * Gaudi::Units::degree;
70 int rotOrder = record->getInt("ROTORDER");
71
72 // Translation part
73 GeoTrf::Translate3D transform(posX, posY, posZ);
74
75 // If rotation is zero return translation
76 if (rotX == 0 && rotY == 0 && rotZ == 0) {
77 return transform;
78 }
79
80 // For rotation have to look at order.
81 // 123 means rotate around X, then Y , then Z.
82 // 312 means rotate around Z, then X , then Y.
83 // etc
84
85 int ixyz1 = rotOrder / 100 - 1;
86 int ixyz2 = (rotOrder % 100) / 10 - 1;
87 int ixyz3 = (rotOrder % 10) - 1;
88
89 if (ixyz1 < 0 || ixyz1 > 2 ||
90 ixyz2 < 0 || ixyz2 > 2 ||
91 ixyz3 < 0 || ixyz3 > 2) {
92 std::cout << "ERROR: Invalid rotation order:" << rotOrder << std::endl;
93 ixyz1 = 0;
94 ixyz2 = 1;
95 ixyz3 = 2;
96 }
97
98 // List of the three transforms
99 GeoTrf::Transform3D* xformList[3] = {
100 nullptr, nullptr, nullptr
101 };
102 if (rotX != 0) xformList[0] = new GeoTrf::RotateX3D(rotX);
103 if (rotY != 0) xformList[1] = new GeoTrf::RotateY3D(rotY);
104 if (rotZ != 0) xformList[2] = new GeoTrf::RotateZ3D(rotZ);
105
106 GeoTrf::Transform3D rotation(GeoTrf::Transform3D::Identity());
107 if (xformList[ixyz1]) rotation = *(xformList[ixyz1]) * rotation;
108 if (xformList[ixyz2]) rotation = *(xformList[ixyz2]) * rotation;
109 if (xformList[ixyz3]) rotation = *(xformList[ixyz3]) * rotation;
110
111 delete xformList[0];
112 delete xformList[1];
113 delete xformList[2];
114
115 return transform * rotation;
116}
117
119TopLevelPlacements::getPart(const std::string& partName) const {
120 std::map<std::string, Part*>::const_iterator iter;
121 iter = m_parts.find(partName);
122 if (iter == m_parts.end()) return nullptr;
123
124 return iter->second;
125}
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition of the abstract IRDBRecord interface.
Definition of the abstract IRDBRecordset interface.
IRDBRecord is one record in the IRDBRecordset object.
Definition IRDBRecord.h:27
virtual const std::string & getString(const std::string &fieldName) const =0
Get string field value.
virtual int getInt(const std::string &fieldName) const =0
Get int field value.
virtual double getDouble(const std::string &fieldName) const =0
Get double field value.
virtual unsigned int size() const =0
GeoTrf::Transform3D partTransform(const IRDBRecord *record) const
Part * getPart(const std::string &partName) const
static const GeoTrf::Transform3D s_identityTransform
const GeoTrf::Transform3D & transform(const std::string &partName) const
std::map< std::string, Part * > m_parts
TopLevelPlacements(const IRDBRecordset_ptr &topLevelTable)
void fillPlacements(const IRDBRecordset_ptr &topLevelTable)
bool present(const std::string &partName) const
std::string label(const std::string &format, int i)
Definition label.h:19