CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DetectorDescription/Core/src/DDScope.cc

Go to the documentation of this file.
00001 #include "DetectorDescription/Core/interface/DDScope.h"
00002 
00003 dd_scope_class DDScopeClassification::operator()( const DDGeoHistory & left,
00004                                                   const DDGeoHistory & right ) const
00005 {
00006   dd_scope_class result = subtree;
00007   DDGeoHistory::const_iterator lit = left.begin(); // left-iterator
00008   DDGeoHistory::const_iterator rit = right.begin(); // right-iterator
00009 
00010   while( lit != left.end() && rit != right.end())
00011   {
00012     if( lit->siblingno() != rit->siblingno())
00013     {
00014       result = different_branch;
00015       break;
00016     }  
00017     ++lit;
00018     ++rit;
00019   }
00020   
00021   if( result != different_branch )
00022   {
00023     if( lit == left.end()) { // left history leaf node marks the root of a subtree which contains
00024       result = supertree;    // the leaf node of the right history or both roots are the same ...
00025     }
00026     else
00027     {
00028       result = subtree;
00029     }    
00030   }
00031   return result;
00032 }
00033 
00034 DDScope::DDScope( void )
00035  : depth_( 0 )
00036 {}
00037 
00038 DDScope::DDScope( const DDGeoHistory & h, int depth )
00039  : depth_( depth )
00040 {
00041   subtrees_.push_back( h );
00042 }
00043 
00044 DDScope::~DDScope( void ) 
00045 {}
00046 
00047 bool
00048 DDScope::addScope( const DDGeoHistory & h )
00049 {
00050   bool result = false;
00051   scope_type::iterator it = subtrees_.begin();
00052   scope_type buf;
00053   int supertreeCount = 0;
00054   bool diffBranch = false;
00055   bool subTree = false;
00056    
00057   for(; it != subtrees_.end(); ++it )
00058   {
00059     dd_scope_class classification = classify_( h, *it );
00060     switch( classification )
00061     { 
00062     case different_branch:
00063       buf.push_back( *it );
00064       diffBranch = true;
00065       break;
00066      
00067     case subtree:
00068       buf.push_back( *it );
00069       subTree = true;
00070       break;
00071      
00072     case supertree:
00073       ++supertreeCount;
00074       if( supertreeCount == 1 )
00075         buf.push_back(h);
00076       break;
00077        
00078     default:
00079       break;  
00080     }
00081   }
00082    
00083   if( diffBranch )
00084   {
00085     if( subTree == false )
00086     {
00087       buf.push_back(h);
00088     }  
00089   }
00090    
00091   if( !subtrees_.size()) 
00092     subtrees_.push_back( h );
00093   else  
00094     subtrees_ = buf;
00095    
00096    return result;
00097 }
00098 
00099 void
00100 DDScope::setDepth( int d )
00101 {
00102   depth_ = d;
00103 }
00104 
00105 int
00106 DDScope::depth( void ) const
00107 {
00108   return depth_;
00109 }
00110 
00111 const DDScope::scope_type &
00112 DDScope::scope( void ) const
00113 {
00114   return subtrees_;
00115 }
00116 
00117 std::ostream & operator<<( std::ostream & os, const DDScope & scope )
00118 {
00119    DDScope::scope_type::const_iterator it = scope.subtrees_.begin();
00120    for(; it != scope.subtrees_.end(); ++ it )
00121    {
00122      os << *it << std::endl;
00123    }
00124    return os;
00125 }