CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Alignment/CommonAlignment/src/AlignableBuilder.cc

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); // build the first level above the modules
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   // In order not to depend on the order of the daughter list,
00087   // we define flags to indicate the existence of a mother;
00088   // 0 if it hasn't been created.
00089   // We use vector instead of map for speed.
00090   align::Alignables tempMoms(maxComponent(level), 0); // init all to 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       // create new mom with id and rot of 1st dau
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 }