ATLAS Offline Software
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 
13 const 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 
26 TopLevelPlacements::transform(const std::string& partName) const {
27  Part* part = getPart(partName);
28 
29  if (part) return part->transform;
30 
31  return s_identityTransform;
32 }
33 
34 bool
35 TopLevelPlacements::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 
42 void
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 
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 
119 TopLevelPlacements::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 }
IRDBRecord::getInt
virtual int getInt(const std::string &fieldName) const =0
Get int field value.
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
TopLevelPlacements::transform
const GeoTrf::Transform3D & transform(const std::string &partName) const
Definition: TopLevelPlacements.cxx:26
TopLevelPlacements::m_parts
std::map< std::string, Part * > m_parts
Definition: TopLevelPlacements.h:41
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
IRDBRecord::getString
virtual const std::string & getString(const std::string &fieldName) const =0
Get string field value.
beamspotman.posX
posX
Definition: beamspotman.py:1624
TopLevelPlacements::s_identityTransform
static const GeoTrf::Transform3D s_identityTransform
Definition: TopLevelPlacements.h:44
TopLevelPlacements::partTransform
GeoTrf::Transform3D partTransform(const IRDBRecord *record) const
Definition: TopLevelPlacements.cxx:63
TopLevelPlacements::present
bool present(const std::string &partName) const
Definition: TopLevelPlacements.cxx:35
TopLevelPlacements::TopLevelPlacements
TopLevelPlacements(const IRDBRecordset_ptr &topLevelTable)
Definition: TopLevelPlacements.cxx:15
TopLevelPlacements::m_noTopLevelTable
bool m_noTopLevelTable
Definition: TopLevelPlacements.h:42
lumiFormat.i
int i
Definition: lumiFormat.py:92
beamspotman.posZ
posZ
Definition: beamspotman.py:1624
xAOD::rotation
rotation
Definition: TrackSurface_v1.cxx:15
TopLevelPlacements::Part
Definition: TopLevelPlacements.h:31
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
TopLevelPlacements::~TopLevelPlacements
~TopLevelPlacements()
Definition: TopLevelPlacements.cxx:20
IRDBRecordset_ptr
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition: IRDBAccessSvc.h:25
beamspotman.posY
posY
Definition: beamspotman.py:1624
python.SystemOfUnits.mm
int mm
Definition: SystemOfUnits.py:83
TopLevelPlacements::fillPlacements
void fillPlacements(const IRDBRecordset_ptr &topLevelTable)
Definition: TopLevelPlacements.cxx:43
IRDBRecord.h
Definition of the abstract IRDBRecord interface.
IRDBRecord
IRDBRecord is one record in the IRDBRecordset object.
Definition: IRDBRecord.h:27
TopLevelPlacements::getPart
Part * getPart(const std::string &partName) const
Definition: TopLevelPlacements.cxx:119
DetType::Part
Part
Definition: DetType.h:14
IRDBRecord::getDouble
virtual double getDouble(const std::string &fieldName) const =0
Get double field value.
TopLevelPlacements.h
IRDBRecordset.h
Definition of the abstract IRDBRecordset interface.
python.SystemOfUnits.degree
tuple degree
Definition: SystemOfUnits.py:106