Go to the documentation of this file.00001 #include "Alignment/CommonAlignment/interface/AlignableComposite.h"
00002 #include "Alignment/CommonAlignment/interface/AlignableObjectId.h"
00003
00004 #include "Alignment/CommonAlignment/interface/AlignableBuilder.h"
00005
00006
00007
00008 AlignableBuilder::LevelInfo::LevelInfo( align::StructureType type,
00009 bool flat,
00010 unsigned int maxComponent ) :
00011 type_(type),
00012 flat_(flat),
00013 maxComponent_(maxComponent)
00014 {
00015 }
00016
00017
00018 AlignableBuilder::AlignableBuilder(align::StructureType moduleType, Counters& counters ):
00019 theModuleType(moduleType),
00020 theCounters(counters)
00021 {
00022 }
00023
00024
00025 void AlignableBuilder::addLevelInfo(align::StructureType type,
00026 bool flat,
00027 unsigned int maxComponent)
00028 {
00029 theLevelInfos.push_back( LevelInfo(type, flat, maxComponent) );
00030 }
00031
00032
00033 void AlignableBuilder::buildAll( AlignSetup<align::Alignables>& setup ) const
00034 {
00035 build(0, theModuleType, setup);
00036
00037 for (unsigned int l = 1; l < theLevelInfos.size(); ++l)
00038 build(l, theLevelInfos[l - 1].type_, setup);
00039 }
00040
00041
00042 unsigned int AlignableBuilder::maxComponent(unsigned int level) const
00043 {
00044 unsigned int max = 1;
00045
00046 for (unsigned int l = level; l < theLevelInfos.size(); ++l)
00047 {
00048 max *= theLevelInfos[l].maxComponent_;
00049 }
00050
00051 return max;
00052 }
00053
00054
00055 unsigned int AlignableBuilder::index( unsigned int level, align::ID id ) const
00056 {
00057 const LevelInfo& info = theLevelInfos[level];
00058
00059 if (theLevelInfos.size() - 1 > level)
00060 {
00061 return index(level + 1, id) * info.maxComponent_ + theCounters.get(info.type_)(id) - 1;
00062 }
00063
00064 return theCounters.get(info.type_)(id) - 1;
00065 }
00066
00067
00068
00069 void AlignableBuilder::build( unsigned int level, align::StructureType dauType,
00070 AlignSetup<align::Alignables>& setup ) const
00071 {
00072 AlignableObjectId objId;
00073
00074 const LevelInfo& momInfo = theLevelInfos[level];
00075
00076 align::StructureType momType = momInfo.type_;
00077
00078 const align::Alignables& daus = setup.find( objId.typeToName(dauType) );
00079
00080 unsigned int nDau = daus.size();
00081
00082 align::Alignables& moms = setup.get( objId.typeToName(momType) );
00083
00084 moms.reserve(nDau);
00085
00086
00087
00088
00089
00090 align::Alignables tempMoms(maxComponent(level), 0);
00091
00092 for (unsigned int i = 0; i < nDau; ++i)
00093 {
00094 Alignable* dau = daus[i];
00095
00096 Alignable*& mom = tempMoms[index( level, dau->id() )];
00097
00098 if (0 == mom)
00099 {
00100
00101 if ( momInfo.flat_ )
00102 mom = new AlignableComposite( dau->id(), momType, dau->globalRotation() );
00103 else
00104 mom = new AlignableComposite( dau->id(), momType, align::RotationType() );
00105
00106 moms.push_back(mom);
00107 }
00108
00109 mom->addComponent(dau);
00110 }
00111 }