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 //=== PUBLIC METHOD IMPLEMENTATION ===
14 //=============================================================================
15 
16 //_____________________________________________________________________________
18  const TrackerGeometry* trackerGeometry,
19  const AlignableIndexer& alignableIndexer)
20  : trackerTopology_(trackerTopology),
21  alignableObjectId_(trackerGeometry, nullptr, nullptr, nullptr),
22  alignableIndexer_(alignableIndexer) {}
23 
24 //_____________________________________________________________________________
25 void AlignableCompositeBuilder ::addAlignmentLevel(std::unique_ptr<AlignmentLevel> level) {
26  alignmentLevels_.push_back(std::move(level));
27 }
28 
29 //_____________________________________________________________________________
31 
32 //_____________________________________________________________________________
33 unsigned int AlignableCompositeBuilder ::buildAll(AlignableMap& alignableMap, bool update) {
34  auto highestLevel = alignmentLevels_.back()->levelType;
35 
36  std::ostringstream ss;
37  ss << "building CompositeAlignables for " << alignableObjectId_.idToString(highestLevel) << "\n";
38 
39  unsigned int numCompositeAlignables = 0;
40  for (unsigned int level = 1; level < alignmentLevels_.size(); ++level) {
41  numCompositeAlignables += buildLevel(level, alignableMap, ss, update);
42  }
43 
44  ss << "built " << numCompositeAlignables << " CompositeAlignables for "
45  << alignableObjectId_.idToString(highestLevel);
46  edm::LogInfo("AlignableBuildProcess") << "@SUB=AlignableCompositeBuilder::buildAll" << ss.str();
47 
48  return numCompositeAlignables;
49 }
50 
51 //=============================================================================
52 //=== PRIVATE METHOD IMPLEMENTATION ===
53 //=============================================================================
54 
55 //_____________________________________________________________________________
56 unsigned int AlignableCompositeBuilder ::buildLevel(unsigned int parentLevel,
57  AlignableMap& alignableMap,
58  std::ostringstream& ss,
59  bool update) {
60  unsigned int childLevel = parentLevel - 1;
61  unsigned int maxNumParents = maxNumComponents(parentLevel);
62 
63  auto childType = alignmentLevels_[childLevel]->levelType;
64  auto parentType = alignmentLevels_[parentLevel]->levelType;
65 
66  auto& children = alignableMap.find(alignableObjectId_.idToString(childType));
67  auto& parents = alignableMap.get(alignableObjectId_.idToString(parentType));
68  if (!update)
69  parents.reserve(maxNumParents);
70 
71  // This vector is used indicate if a parent already exists. It is initialized
72  // with 'naked' Alignables-pointers; if the pointer is not naked (!= nullptr)
73  // for one of the child-IDs, its parent was already built before.
74  align::Alignables tmpParents(maxNumParents, nullptr);
75 
76  for (auto* child : children) {
77  // get the number of the child-Alignable ...
78  const auto index = getIndexOfStructure(child->id(), parentLevel);
79  // ... and use it as index to get the parent of this child
80  auto& parent = tmpParents[index];
81 
82  // if parent was not built yet ...
83  if (!parent && !update) {
84  if (update) {
85  throw cms::Exception("LogicError") << "@SUB=AlignableCompositeBuilder::buildLevel\n"
86  << "trying to update a non-existing AlignableComposite";
87  }
88  // ... build new composite Alignable with ID of child (obviously its the
89  // first child of the Alignable)
90  if (alignmentLevels_[parentLevel]->isFlat) {
91  parent = new AlignableComposite(child->id(), parentType, child->globalRotation());
92  } else {
93  parent = new AlignableComposite(child->id(), parentType, align::RotationType());
94  }
95  parents.push_back(parent);
96  } else if (update) {
97  if (alignmentLevels_[parentLevel]->isFlat) {
98  // needed to update rotation of flat composites
99  auto mother = dynamic_cast<AlignableComposite*>(child->mother());
100  if (!mother) {
101  throw cms::Exception("LogicError") << "@SUB=AlignableCompositeBuilder::buildLevel\n"
102  << "trying to update a flat composite that is not of type "
103  << "AlignableComposite";
104  }
105  if (mother->id() == child->id()) {
106  mother->update(child->id(), parentType, child->globalRotation());
107  }
108  }
109  }
110 
111  // in all cases (except updates) add the child to the parent Alignable
112  if (!update)
113  parent->addComponent(child);
114  }
115 
116  ss << " built " << parents.size() << " " << alignableObjectId_.idToString(alignmentLevels_[parentLevel]->levelType)
117  << "(s) (theoretical maximum: " << maxNumParents << ") consisting of " << children.size() << " "
118  << alignableObjectId_.idToString(alignmentLevels_[childLevel]->levelType) << "(s)\n";
119 
120  return parents.size();
121 }
122 
123 //_____________________________________________________________________________
124 unsigned int AlignableCompositeBuilder ::maxNumComponents(unsigned int startLevel) const {
125  unsigned int components = 1;
126 
127  for (unsigned int level = startLevel; level < alignmentLevels_.size(); ++level) {
128  components *= alignmentLevels_[level]->maxNumComponents;
129  }
130 
131  return components;
132 }
133 
134 //_____________________________________________________________________________
136  // indexer returns a function pointer for the structure-type
137  auto indexOf = alignableIndexer_.get(alignmentLevels_[level]->levelType, alignableObjectId_);
138 
139  if (alignmentLevels_.size() - 1 > level) {
140  return getIndexOfStructure(id, level + 1) * alignmentLevels_[level]->maxNumComponents + indexOf(id) - 1;
141  }
142 
143  return indexOf(id) - 1;
144 }
personalPlayback.level
level
Definition: personalPlayback.py:22
MessageLogger.h
AlignableIndexer::get
virtual align::Counter get(align::StructureType, const AlignableObjectId &) const
Get a counter based on its structure type.
Definition: AlignableIndexer.cc:7
align::RotationType
TkRotation< Scalar > RotationType
Definition: Definitions.h:27
AlignableMap
Definition: AlignableMap.h:27
class-composition.children
children
Definition: class-composition.py:88
TrackerTopology
Definition: TrackerTopology.h:16
AlignableCompositeBuilder::alignmentLevels_
align::AlignmentLevels alignmentLevels_
Definition: AlignableCompositeBuilder.h:68
AlignableIndexer
Definition: AlignableIndexer.h:34
AlignableComposite
Definition: AlignableComposite.h:25
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
AlignableCompositeBuilder.h
AlignableCompositeBuilder::clearAlignmentLevels
void clearAlignmentLevels()
Resets the alignment-levels.
Definition: AlignableCompositeBuilder.cc:30
AlignableCompositeBuilder::alignableObjectId_
const AlignableObjectId alignableObjectId_
Definition: AlignableCompositeBuilder.h:64
AlignableCompositeBuilder::alignableIndexer_
AlignableIndexer alignableIndexer_
Definition: AlignableCompositeBuilder.h:66
AlignableCompositeBuilder::buildLevel
unsigned int buildLevel(unsigned int parentLevel, AlignableMap &, std::ostringstream &, bool update=false)
Builds the components for a given level in the hierarchy.
Definition: AlignableCompositeBuilder.cc:56
AlignableMap::find
align::Alignables & find(const std::string &name="")
Definition: AlignableMap.cc:10
align::ID
uint32_t ID
Definition: Definitions.h:24
AlignableCompositeBuilder::maxNumComponents
unsigned int maxNumComponents(unsigned int startLevel) const
Definition: AlignableCompositeBuilder.cc:124
AlignableCompositeBuilder::buildAll
unsigned int buildAll(AlignableMap &, bool update=false)
Definition: AlignableCompositeBuilder.cc:33
AlignableObjectId.h
AlignableCompositeBuilder::addAlignmentLevel
void addAlignmentLevel(std::unique_ptr< AlignmentLevel > level)
Definition: AlignableCompositeBuilder.cc:25
align::Alignables
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
eostools.move
def move(src, dest)
Definition: eostools.py:511
AlignableCompositeBuilder::AlignableCompositeBuilder
AlignableCompositeBuilder(const TrackerTopology *, const TrackerGeometry *, const AlignableIndexer &)
Definition: AlignableCompositeBuilder.cc:17
makeMuonMisalignmentScenario.components
string components
Definition: makeMuonMisalignmentScenario.py:58
Exception
Definition: hltDiff.cc:245
AlignableCompositeBuilder::getIndexOfStructure
unsigned int getIndexOfStructure(align::ID, unsigned int level) const
Definition: AlignableCompositeBuilder.cc:135
AlignableMap::get
align::Alignables & get(const std::string &name="")
Definition: AlignableMap.cc:7
AlignableObjectId::idToString
const char * idToString(align::StructureType type) const
Definition: AlignableObjectId.cc:272
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
parents
TPRegexp parents
Definition: eve_filter.cc:21
child
Definition: simpleInheritance.h:11
class-composition.parent
parent
Definition: class-composition.py:88
update
#define update(a, b)
Definition: TrackClassifier.cc:10
TrackerGeometry
Definition: TrackerGeometry.h:14