CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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)
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);
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 {
76  unsigned int childLevel = parentLevel - 1;
77  unsigned int maxNumParents = maxNumComponents(parentLevel);
78 
79  auto childType = alignmentLevels_[childLevel] ->levelType;
80  auto parentType = alignmentLevels_[parentLevel]->levelType;
81 
82  auto& children = alignableMap.find(alignableObjectId_.idToString(childType));
83  auto& parents = alignableMap.get (alignableObjectId_.idToString(parentType));
84  parents.reserve(maxNumParents);
85 
86  // This vector is used indicate if a parent already exists. It is initialized
87  // with 'naked' Alignables-pointers; if the pointer is not naked (!= nullptr)
88  // for one of the child-IDs, its parent was already built before.
89  Alignables tmpParents(maxNumParents, nullptr);
90 
91  for (auto* child: children) {
92  // get the number of the child-Alignable ...
93  const auto index = getIndexOfStructure(child->id(), parentLevel);
94  // ... and use it as index to get the parent of this child
95  auto& parent = tmpParents[index];
96 
97  // if parent was not built yet ...
98  if (!parent) {
99  // ... build new composite Alignable with ID of child (obviously its the
100  // first child of the Alignable)
101  if (alignmentLevels_[parentLevel]->isFlat) {
102  parent = new AlignableComposite(child->id(), parentType,
103  child->globalRotation());
104  } else {
105  parent = new AlignableComposite(child->id(), parentType,
107  }
108  parents.push_back(parent);
109  }
110 
111  // in all cases add the child to the parent Alignable
112  parent->addComponent(child);
113  }
114 
115  ss << " built " << parents.size() << " "
116  << alignableObjectId_.idToString(alignmentLevels_[parentLevel]->levelType)
117  << "(s) (theoretical maximum: " << maxNumParents
118  << ") consisting of " << children.size() << " "
119  << alignableObjectId_.idToString(alignmentLevels_[childLevel]->levelType)
120  << "(s)\n";
121 
122  return parents.size();
123 }
124 
125 //_____________________________________________________________________________
126 unsigned int AlignableCompositeBuilder
127 ::maxNumComponents(unsigned int startLevel) const
128 {
129  unsigned int components = 1;
130 
131  for (unsigned int level = startLevel;
132  level < alignmentLevels_.size();
133  ++level) {
134  components *= alignmentLevels_[level]->maxNumComponents;
135  }
136 
137  return components;
138 }
139 
140 //_____________________________________________________________________________
141 unsigned int AlignableCompositeBuilder
142 ::getIndexOfStructure(align::ID id, unsigned int level) const
143 {
144  // indexer returns a function pointer for the structure-type
145  auto indexOf = alignableIndexer_.get(alignmentLevels_[level]->levelType,
146  alignableObjectId_);
147 
148  if (alignmentLevels_.size() - 1 > level) {
149  return getIndexOfStructure(id, level + 1)
150  * alignmentLevels_[level]->maxNumComponents
151  + indexOf(id) - 1;
152  }
153 
154  return indexOf(id) - 1;
155 }
TkRotation< Scalar > RotationType
Definition: Definitions.h:29
TPRegexp parents
Definition: eve_filter.cc:21
unsigned int buildLevel(unsigned int parentLevel, AlignableMap &, std::ostringstream &)
Builds the components for a given level in the hierarchy.
std::vector< Alignable * > Alignables
Definition: Alignable.h:251
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
unsigned int buildAll(AlignableMap &)
Alignables & get(const std::string &name="")
Definition: AlignableMap.cc:9
def move
Definition: eostools.py:510
Alignables & find(const std::string &name="")
Definition: AlignableMap.cc:15
void clearAlignmentLevels()
Resets the alignment-levels.
unsigned int maxNumComponents(unsigned int startLevel) const
tuple level
Definition: testEve_cfg.py:34
void addAlignmentLevel(std::unique_ptr< AlignmentLevel > level)