CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlignableBuilder.cc
Go to the documentation of this file.
3 
5 
6 
7 //__________________________________________________________________________________________________
9  bool flat,
10  unsigned int maxComponent ) :
11  type_(type),
12  flat_(flat),
13  maxComponent_(maxComponent)
14 {
15 }
16 
17 //__________________________________________________________________________________________________
19  theModuleType(moduleType),
20  theCounters(counters)
21 {
22 }
23 
24 //__________________________________________________________________________________________________
26  bool flat,
27  unsigned int maxComponent)
28 {
29  theLevelInfos.push_back( LevelInfo(type, flat, maxComponent) );
30 }
31 
32 //__________________________________________________________________________________________________
34 {
35  build(0, theModuleType, setup); // build the first level above the modules
36 
37  for (unsigned int l = 1; l < theLevelInfos.size(); ++l)
38  build(l, theLevelInfos[l - 1].type_, setup);
39 }
40 
41 //__________________________________________________________________________________________________
42 unsigned int AlignableBuilder::maxComponent(unsigned int level) const
43 {
44  unsigned int max = 1;
45 
46  for (unsigned int l = level; l < theLevelInfos.size(); ++l)
47  {
48  max *= theLevelInfos[l].maxComponent_;
49  }
50 
51  return max;
52 }
53 
54 //__________________________________________________________________________________________________
55 unsigned int AlignableBuilder::index( unsigned int level, align::ID id ) const
56 {
58 
59  if (theLevelInfos.size() - 1 > level)
60  {
61  return index(level + 1, id) * info.maxComponent_ + theCounters.get(info.type_)(id) - 1;
62  }
63 
64  return theCounters.get(info.type_)(id) - 1;
65 }
66 
67 
68 //__________________________________________________________________________________________________
71 {
72  AlignableObjectId objId;
73 
74  const LevelInfo& momInfo = theLevelInfos[level];
75 
76  align::StructureType momType = momInfo.type_;
77 
78  const align::Alignables& daus = setup.find( objId.typeToName(dauType) );
79 
80  unsigned int nDau = daus.size();
81 
82  align::Alignables& moms = setup.get( objId.typeToName(momType) );
83 
84  moms.reserve(nDau);
85 
86  // In order not to depend on the order of the daughter list,
87  // we define flags to indicate the existence of a mother;
88  // 0 if it hasn't been created.
89  // We use vector instead of map for speed.
90  align::Alignables tempMoms(maxComponent(level), 0); // init all to 0
91 
92  for (unsigned int i = 0; i < nDau; ++i)
93  {
94  Alignable* dau = daus[i];
95 
96  Alignable*& mom = tempMoms[index( level, dau->id() )];
97 
98  if (0 == mom)
99  {
100  // create new mom with id and rot of 1st dau
101  if ( momInfo.flat_ )
102  mom = new AlignableComposite( dau->id(), momType, dau->globalRotation() );
103  else
104  mom = new AlignableComposite( dau->id(), momType, align::RotationType() );
105 
106  moms.push_back(mom);
107  }
108 
109  mom->addComponent(dau);
110  }
111 }
TkRotation< Scalar > RotationType
Definition: Definitions.h:29
type
Definition: HCALResponse.h:22
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:180
int i
Definition: DBlmapReader.cc:9
Type & find(const std::string &name="")
Definition: AlignSetup.h:58
void build(unsigned int level, align::StructureType dauType, AlignSetup< align::Alignables > &setup) const
Build the components for a given level in the hierarchy.
uint32_t ID
Definition: Definitions.h:26
std::vector< LevelInfo > theLevelInfos
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:132
virtual align::Counter get(align::StructureType) const
Get a counter based on its structure type.
Definition: Counters.cc:8
const std::string & typeToName(align::StructureType type) const
Convert type to name.
unsigned int index(unsigned int level, align::ID) const
void buildAll(AlignSetup< align::Alignables > &setup) const
Build the components for all levels given by user.
AlignableBuilder(align::StructureType moduleType, Counters &counter)
Init the module type.
LevelInfo(align::StructureType, bool flat, unsigned int maxComponent)
void addLevelInfo(align::StructureType, bool flat, unsigned int maxComponent)
Add info required to build a level to the list.
const T & max(const T &a, const T &b)
Type & get(const std::string &name="")
Definition: AlignSetup.h:52
align::StructureType theModuleType
Allows conversion between type and name, and vice-versa.
virtual void addComponent(Alignable *)=0
align::StructureType type_
std::vector< Alignable * > Alignables
Definition: Utilities.h:28
unsigned int maxComponent(unsigned int level) const
Find max number of components for a given level in the hierarchy.
tuple level
Definition: testEve_cfg.py:34
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")