CMS 3D CMS Logo

AlignableCompositeBuilder.cc
Go to the documentation of this file.
2 
3 // Original Author: Max Stark
4 // Created: Thu, 13 Jan 2016 10:22:57 CET
5 
6 // core framework functionality
8 
9 // alignment
11 
12 
13 
14 //=============================================================================
15 //=== PUBLIC METHOD IMPLEMENTATION ===
16 //=============================================================================
17 
18 //_____________________________________________________________________________
21  const TrackerGeometry* trackerGeometry,
22  const AlignableIndexer& alignableIndexer) :
23  trackerTopology_(trackerTopology),
24  alignableObjectId_(trackerGeometry, nullptr, nullptr),
25  alignableIndexer_(alignableIndexer)
26 {
27 }
28 
29 //_____________________________________________________________________________
31 ::addAlignmentLevel(std::unique_ptr<AlignmentLevel> level) {
32  alignmentLevels_.push_back(std::move(level));
33 }
34 
35 //_____________________________________________________________________________
38  alignmentLevels_.clear();
39 }
40 
41 //_____________________________________________________________________________
42 unsigned int AlignableCompositeBuilder
43 ::buildAll(AlignableMap& alignableMap, bool update)
44 {
45  auto highestLevel = alignmentLevels_.back()->levelType;
46 
47  std::ostringstream ss;
48  ss << "building CompositeAlignables for "
49  << alignableObjectId_.idToString(highestLevel) << "\n";
50 
51  unsigned int numCompositeAlignables = 0;
52  for (unsigned int level = 1; level < alignmentLevels_.size(); ++level) {
53  numCompositeAlignables += buildLevel(level, alignableMap, ss, update);
54  }
55 
56  ss << "built " << numCompositeAlignables << " CompositeAlignables for "
57  << alignableObjectId_.idToString(highestLevel);
58  edm::LogInfo("AlignableBuildProcess")
59  << "@SUB=AlignableCompositeBuilder::buildAll" << ss.str();
60 
61  return numCompositeAlignables;
62 }
63 
64 
65 
66 //=============================================================================
67 //=== PRIVATE METHOD IMPLEMENTATION ===
68 //=============================================================================
69 
70 //_____________________________________________________________________________
71 unsigned int AlignableCompositeBuilder
72 ::buildLevel(unsigned int parentLevel,
73  AlignableMap& alignableMap,
74  std::ostringstream& ss,
75  bool update)
76 {
77  unsigned int childLevel = parentLevel - 1;
78  unsigned int maxNumParents = maxNumComponents(parentLevel);
79 
80  auto childType = alignmentLevels_[childLevel] ->levelType;
81  auto parentType = alignmentLevels_[parentLevel]->levelType;
82 
83  auto& children = alignableMap.find(alignableObjectId_.idToString(childType));
84  auto& parents = alignableMap.get (alignableObjectId_.idToString(parentType));
85  if (!update) parents.reserve(maxNumParents);
86 
87  // This vector is used indicate if a parent already exists. It is initialized
88  // with 'naked' Alignables-pointers; if the pointer is not naked (!= nullptr)
89  // for one of the child-IDs, its parent was already built before.
90  Alignables tmpParents(maxNumParents, nullptr);
91 
92  for (auto* child: children) {
93  // get the number of the child-Alignable ...
94  const auto index = getIndexOfStructure(child->id(), parentLevel);
95  // ... and use it as index to get the parent of this child
96  auto& parent = tmpParents[index];
97 
98  // if parent was not built yet ...
99  if (!parent && !update) {
100  if (update) {
101  throw cms::Exception("LogicError")
102  << "@SUB=AlignableCompositeBuilder::buildLevel\n"
103  << "trying to update a non-existing AlignableComposite";
104  }
105  // ... build new composite Alignable with ID of child (obviously its the
106  // first child of the Alignable)
107  if (alignmentLevels_[parentLevel]->isFlat) {
108  parent = new AlignableComposite(child->id(), parentType,
109  child->globalRotation());
110  } else {
111  parent = new AlignableComposite(child->id(), parentType,
113  }
114  parents.push_back(parent);
115  } else if (update) {
116  if (alignmentLevels_[parentLevel]->isFlat) {
117  // needed to update rotation of flat composites
118  auto mother = dynamic_cast<AlignableComposite*>(child->mother());
119  if (!mother) {
120  throw cms::Exception("LogicError")
121  << "@SUB=AlignableCompositeBuilder::buildLevel\n"
122  << "trying to update a flat composite that is not of type "
123  << "AlignableComposite";
124  }
125  if (mother->id() == child->id()) {
126  mother->update(child->id(), parentType, child->globalRotation());
127  }
128  }
129  }
130 
131  // in all cases (except updates) add the child to the parent Alignable
132  if (!update) parent->addComponent(child);
133  }
134 
135  ss << " built " << parents.size() << " "
136  << alignableObjectId_.idToString(alignmentLevels_[parentLevel]->levelType)
137  << "(s) (theoretical maximum: " << maxNumParents
138  << ") consisting of " << children.size() << " "
139  << alignableObjectId_.idToString(alignmentLevels_[childLevel]->levelType)
140  << "(s)\n";
141 
142  return parents.size();
143 }
144 
145 //_____________________________________________________________________________
146 unsigned int AlignableCompositeBuilder
147 ::maxNumComponents(unsigned int startLevel) const
148 {
149  unsigned int components = 1;
150 
151  for (unsigned int level = startLevel;
152  level < alignmentLevels_.size();
153  ++level) {
154  components *= alignmentLevels_[level]->maxNumComponents;
155  }
156 
157  return components;
158 }
159 
160 //_____________________________________________________________________________
161 unsigned int AlignableCompositeBuilder
162 ::getIndexOfStructure(align::ID id, unsigned int level) const
163 {
164  // indexer returns a function pointer for the structure-type
165  auto indexOf = alignableIndexer_.get(alignmentLevels_[level]->levelType,
166  alignableObjectId_);
167 
168  if (alignmentLevels_.size() - 1 > level) {
169  return getIndexOfStructure(id, level + 1)
170  * alignmentLevels_[level]->maxNumComponents
171  + indexOf(id) - 1;
172  }
173 
174  return indexOf(id) - 1;
175 }
TkRotation< Scalar > RotationType
Definition: Definitions.h:29
TPRegexp parents
Definition: eve_filter.cc:21
std::vector< Alignable * > Alignables
Definition: Alignable.h:274
AlignableCompositeBuilder(const TrackerTopology *, const TrackerGeometry *, const AlignableIndexer &)
unsigned int getIndexOfStructure(align::ID, unsigned int level) const
uint32_t ID
Definition: Definitions.h:26
#define nullptr
Alignables & get(const std::string &name="")
Definition: AlignableMap.cc:9
Alignables & find(const std::string &name="")
Definition: AlignableMap.cc:15
void clearAlignmentLevels()
Resets the alignment-levels.
unsigned int maxNumComponents(unsigned int startLevel) const
#define update(a, b)
unsigned int buildLevel(unsigned int parentLevel, AlignableMap &, std::ostringstream &, bool update=false)
Builds the components for a given level in the hierarchy.
unsigned int buildAll(AlignableMap &, bool update=false)
def move(src, dest)
Definition: eostools.py:510
void addAlignmentLevel(std::unique_ptr< AlignmentLevel > level)