ATLAS Offline Software
Element.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <list>
7 
8 using namespace NswAsBuilt;
9 
10 //===============================================================================
11 Element::Element(std::unique_ptr<ElementModel> deformationModel)
12 : m_deformationModel(std::move(deformationModel))
13 , m_nominalPar(m_deformationModel->nParameters())
14 , m_correctedPar(m_deformationModel->nParameters())
15 { }
16 
17 
18 //===============================================================================
20 {
22 }
23 
24 
25 //===============================================================================
27 {
29 }
30 
31 
32 //===============================================================================
34 {
35  m_deformationModel->transform(parameterVector(iclass), local);
36 }
37 
38 
39 //===============================================================================
40 void Element::transformToFrame(ParameterClass iclass, const VectorSetRef& local, const Element* frame) const
41 {
42  const Element* el = this;
43  while ((el!=nullptr) && (el!=frame)) {
44  el->transform(iclass, local);
45  el = el->m_mother;
46  }
47 }
48 
49 
50 //===============================================================================
52 {
53  m_deformationModel->cacheTransform(m_correctedPar);
54  m_deformationModel->cacheTransform(m_nominalPar);
55 }
56 
57 
58 //===============================================================================
59 double Element::getParameter(ParameterClass iclass, ipar_t ipar) const
60 {
61  const auto& parvec = parameterVector(iclass).parameters;
62  if (ipar>=parvec.size()) {
63  throw std::runtime_error("Element::getParameter: Parameter exceeds parvec size "+std::to_string(ipar));
64  }
65  return parvec[ipar];
66 }
67 
68 
69 //===============================================================================
70 void Element::setParameter(ParameterClass iclass, ipar_t ipar, double value)
71 {
72  auto& parvec = parameterVector(iclass).parameters;
73  if (ipar>=parvec.size()) {
74  throw std::runtime_error("Element::setParameter: Parameter exceeds parvec size "+std::to_string(ipar));
75  }
76  parvec[ipar] = value;
77  parameterVector(iclass).transformCacheValid = false;
78 }
79 
80 
81 //===============================================================================
82 void Element::setParametersFromMap(ParameterClass iclass, const std::map<std::string, double>& values)
83 {
84  for (const auto& p : values) {
85  setParameter(iclass, m_deformationModel->getParameterIndex(p.first), p.second);
86  }
87  m_deformationModel->cacheTransform(parameterVector(iclass));
88 }
89 
90 
91 //===============================================================================
92 Element* Element::addDaughter(std::unique_ptr<Element> daughter)
93 {
94  if (daughter->m_mother) {
95  throw std::runtime_error("Element has a defined mother already");
96  }
97  daughter->m_mother = this;
98  m_daughters.push_back(std::move(daughter));
99  return m_daughters.back().get();
100 }
101 
102 
103 //===============================================================================
104 void Element::traverseTree(const std::function<void(Element&)>& callback)
105 {
106  struct tree_t {
107  using iter = daughterVec_t::iterator;
108  tree_t(iter _it, iter _end):
109  it{_it},end{_end}{}
110  iter it;
111  iter end;
112  };
113  std::list<tree_t> dtree;
114  callback(*this);
115  dtree.emplace_back(m_daughters.begin(), m_daughters.end());
116  while (!dtree.empty()) {
117  auto& it = dtree.back().it;
118  if (it != dtree.back().end) {
119  Element& el = **it;
120  callback(el);
121  dtree.emplace_back(el.m_daughters.begin(), el.m_daughters.end());
122  ++it;
123  } else {
124  dtree.pop_back();
125  }
126  }
127 }
128 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
NswAsBuilt::Element::Element
Element()=delete
NswAsBuilt::ElementModel::ParameterVector
Definition: ElementModel.h:44
skel.it
it
Definition: skel.GENtoEVGEN.py:396
runLayerRecalibration.callback
callback
Definition: runLayerRecalibration.py:64
athena.value
value
Definition: athena.py:124
NswAsBuilt::Element::traverseTree
void traverseTree(const std::function< void(Element &)> &callback)
Definition: Element.cxx:104
NswAsBuilt::ElementModel::ParameterVector::parameters
std::vector< double > parameters
Definition: ElementModel.h:45
NswAsBuilt::Element::m_mother
Element * m_mother
Definition: Element.h:116
NswAsBuilt::Element::setParameter
void setParameter(ParameterClass iclass, ipar_t ipar, double value)
Definition: Element.cxx:70
NswAsBuilt::Element::ipar_t
ElementModel::ipar_t ipar_t
Definition: Element.h:55
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
Element.h
NswAsBuilt::Element::m_correctedPar
ParameterVector m_correctedPar
Definition: Element.h:113
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
NswAsBuilt::Element::m_deformationModel
std::unique_ptr< ElementModel > m_deformationModel
Definition: Element.h:111
NswAsBuilt::Element::m_nominalPar
ParameterVector m_nominalPar
Definition: Element.h:112
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
NswAsBuilt::ElementModel::ParameterVector::transformCacheValid
bool transformCacheValid
Definition: ElementModel.h:47
InDetDD::local
@ local
Definition: InDetDD_Defs.h:16
NswAsBuilt::Element::parameterVector
ParameterVector & parameterVector(ParameterClass iclass)
Definition: Element.cxx:19
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
NswAsBuilt::Element::transform
void transform(ParameterClass iclass, const VectorSetRef &local) const
Definition: Element.cxx:33
NswAsBuilt::Element::ParameterClass
ParameterClass
Definition: Element.h:63
NswAsBuilt::Element::m_daughters
daughterVec_t m_daughters
Definition: Element.h:115
NswAsBuilt::Element::getParameter
double getParameter(ParameterClass iclass, ipar_t ipar) const
Definition: Element.cxx:59
NswAsBuilt
Definition: CathodeBoardElement.h:12
NswAsBuilt::Element
Element: a node in a hierarchy of alignment frames.
Definition: Element.h:52
NswAsBuilt::Element::transformToFrame
void transformToFrame(ParameterClass iclass, const VectorSetRef &local, const Element *frame) const
Definition: Element.cxx:40
NswAsBuilt::Element::ParameterClass::CORRECTION
@ CORRECTION
NswAsBuilt::Element::addDaughter
Element * addDaughter(std::unique_ptr< Element > daughter)
Definition: Element.cxx:92
NswAsBuilt::Element::VectorSetRef
ElementModel::VectorSetRef VectorSetRef
Definition: Element.h:57
NswAsBuilt::Element::cacheTransforms
void cacheTransforms()
Definition: Element.cxx:51
NswAsBuilt::Element::setParametersFromMap
void setParametersFromMap(ParameterClass iclass, const std::map< std::string, double > &values)
Definition: Element.cxx:82