CMS 3D CMS Logo

Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends

DDExpandedView Class Reference

Provides an exploded view of the detector (tree-view) More...

#include <DDExpandedView.h>

List of all members.

Public Types

typedef std::vector< int > nav_type
 std::vector of sibling numbers
typedef std::pair< int const
*, size_t > 
NavRange

Public Member Functions

void clearScope ()
 clears the scope; the full tree is available, depth=0
int copyno () const
 Copy number associated with the current node.
nav_type copyNumbers () const
 return the stack of copy numbers
 DDExpandedView (const DDCompactView &)
 Constructs an expanded-view based on the compact-view.
int depth () const
 depth of the scope. 0 means unrestricted depth.
bool firstChild ()
 set the current node to the first child ...
const DDGeoHistorygeoHistory () const
 The list of ancestors up to the root-node of the current node.
bool goTo (int const *newpos, size_t sz)
bool goTo (NavRange)
bool goTo (const nav_type &)
 transversed the DDExpandedView according to the given stack of sibling numbers
bool goToHistory (const DDGeoHistory &sc)
const DDLogicalPartlogicalPart () const
 The logical-part of the current node in the expanded-view.
DDsvalues_type mergedSpecifics () const
void mergedSpecificsV (DDsvalues_type &res) const
nav_type navPos () const
 return the stack of sibling numbers which indicates the current position in the DDExpandedView
bool next ()
 set current node to the next node in the expanded tree
bool nextB ()
 broad search order of next()
bool nextSibling ()
 set the current node to the next sibling ...
bool parent ()
 set the current node to the parent node ...
void reset ()
 true, if a call to firstChild() would succeed (current node has at least one child)
const DDRotationMatrixrotation () const
 The absolute rotation of the current node.
const DDGeoHistoryscope () const
 The scope of the expanded-view.
bool setScope (const DDGeoHistory &hist, int depth=0)
 sets the scope of the expanded view
std::vector< const
DDsvalues_type * > 
specifics () const
 User specific data attached to the current node.
void specificsV (std::vector< const DDsvalues_type * > &vc) const
const DDTranslationtranslation () const
 The absolute translation of the current node.
virtual ~DDExpandedView ()

Protected Member Functions

bool descend (const DDGeoHistory &sc)

Protected Attributes

unsigned int depth_
 depth of the scope, 0==unrestricted depth
DDGeoHistory history_
 std::vector of DDExpandedNode
std::vector< nav_typenextBStack_
const DDRotationMatrix rot_
DDGeoHistory scope_
 scope of the expanded view
const DDTranslation trans_
DDCompactView::walker_type w2_
DDCompactView::walker_typewalker_
 the tricky walker
DDPosDataworldpos_
 ???

Friends

class DDFilteredView

Detailed Description

Provides an exploded view of the detector (tree-view)

DDExpandedView provides a tree-walker (iterator) for the expanded view of the detector description. Further it provides a registration mechanism for call-backs whenever a node in the expanded view becomes current and fullfills the user-defined predicate.

FIXME: DDExpandedView: in the Prototype just one class - FIXME: later seperation of interface & implementation! Taking a DDCompactView the DDExpandedView expands the compact-view into a detector tree. One instance of DDExpandedView corresponds to one node in the tree. It is the 'current' node. By using tree navigation ( next(), nextSibling(), parent(), firstChild() ) the DDExpandedView represents the new corresponding node.

Definition at line 35 of file DDExpandedView.h.


Member Typedef Documentation

typedef std::vector<int> DDExpandedView::nav_type

std::vector of sibling numbers

Definition at line 41 of file DDExpandedView.h.

typedef std::pair<int const *, size_t> DDExpandedView::NavRange

Definition at line 42 of file DDExpandedView.h.


Constructor & Destructor Documentation

DDExpandedView::DDExpandedView ( const DDCompactView cpv)

Constructs an expanded-view based on the compact-view.

After construction the instance corresponds to the root of the geometrical tree.

Definition at line 8 of file DDExpandedView.cc.

References history_, DDI::Singleton< I >::instance(), rot_, trans_, w2_, walker_, and worldpos_.

 : walker_(0),w2_(cpv.graph(),cpv.root()), trans_(DDTranslation()), rot_(DDRotationMatrix()),
   depth_(0), worldpos_(0)
{
  //  std::cout << "Building a DDExpandedView" << std::endl;
  // MEC:2010-02-08 - consider the ROOT as where you want to start LOOKING at
  // the DDD, and worldpos_ as the "real" root node of the graph.  MOVE all this 
  // logic to DDCompactView.  This should really be just the traverser...
  DDRotation::StoreT::instance().setReadOnly(false);
  worldpos_ = new DDPosData(DDTranslation(),DDRotation(),0);     
  DDRotation::StoreT::instance().setReadOnly(true);
  
  walker_ = &w2_;

  //  std::cout << "Walker: current.first=" << (*walker_).current().first << std::endl;
  //  std::cout << "Walker: current.second=" << (*walker_).current().second << std::endl;
  
  DDPosData * pd((*walker_).current().second);
  if (!pd)
    pd = worldpos_;  
  DDExpandedNode expn((*walker_).current().first,
                      pd,
                      trans_,
                      rot_,
                      0);
  
  // starting point for position calculations, == root of expanded view
  history_.push_back(expn);                                   
}
DDExpandedView::~DDExpandedView ( ) [virtual]

Definition at line 39 of file DDExpandedView.cc.

{ }  

Member Function Documentation

void DDExpandedView::clearScope ( )

clears the scope; the full tree is available, depth=0

Definition at line 371 of file DDExpandedView.cc.

References depth_, and scope_.

Referenced by DDFilteredView::clearScope(), and reset().

{
  scope_.clear();
  depth_=0;
}
int DDExpandedView::copyno ( void  ) const

Copy number associated with the current node.

Definition at line 72 of file DDExpandedView.cc.

References history_.

Referenced by PhysicalPartsTree::beginRun(), DDFilteredView::copyno(), DDExpandedViewDump(), DDI::Specific::node(), and TrackerGeometricDetExtraESModule::putOne().

{ 
  return history_.back().copyno();
  //return (*walker_).current().second->copyno_; 
}
DDExpandedView::nav_type DDExpandedView::copyNumbers ( ) const

return the stack of copy numbers

Definition at line 562 of file DDExpandedView.cc.

References history_, and query::result.

Referenced by DDFilteredView::copyNumbers().

{
  DDGeoHistory::size_type it = 0;
  DDGeoHistory::size_type sz = history_.size();
  nav_type result(sz);
  
  for (; it < sz; ++it) {
    result[it] = history_[it].copyno();
  }
  return result;
}
int DDExpandedView::depth ( ) const

depth of the scope. 0 means unrestricted depth.

Definition at line 66 of file DDExpandedView.cc.

References depth_.

Referenced by setScope().

{
  return depth_;
}
bool DDExpandedView::descend ( const DDGeoHistory sc) [protected]

Definition at line 462 of file DDExpandedView.cc.

References firstChild(), history_, nextSibling(), and query::result.

Referenced by setScope().

{
  DDGeoHistory::size_type mxx = sc.size();
  DDGeoHistory::size_type cur = 0;
  bool result(false);
  
  /* algo: compare currerent node in expanded-view with current-node in sc
           if matching:
             (A)go to first child in expanded-view, go one level deeper in sc
             iterate over all children in expanded-view until one of them
             matches the current node in sc. 
             if no one matches, return false
             else continue at (A)
           else return false
  */       
  const DDExpandedNode & curNode = history_.back();
  
  if (sc.size()) {
    //DCOUT('x', "curN=" << curNode.logicalPart() << " scope[0]=" << sc[cur].logicalPart() );
    if (curNode==sc[cur]) {
      bool res(false);
      while(cur+1 < mxx && firstChild()) {
        ++cur;
        //DCOUT('x', "fc-curN=" << history_.back().logicalPart() << " scope[x]=" << sc[cur].logicalPart() );
        if (!(history_.back()==sc[cur])) {
          while(nextSibling()) {
            //DCOUT('x', "ns-curN=" << history_.back().logicalPart() << " scope[x]=" << sc[cur].logicalPart() );
            if (history_.back()==sc[cur]) {
              res=true;
              break;
            }  
          }
        }  
        else {
          res=true;
        }
        if (res==false) 
          break;  
      }
      result = res;
    }     
  }
  return result; 
}
bool DDExpandedView::firstChild ( )

set the current node to the first child ...

returns true, if a child of the current node exists and updates this otherwise returns false

Definition at line 150 of file DDExpandedView.cc.

References depth_, history_, query::result, DDPosData::rot(), scope_, and DDPosData::trans_.

Referenced by MagGeoBuilderFromDDD::build(), descend(), goTo(), goToHistory(), next(), and DDI::Specific::node().

{
  bool result(false);
  bool depthNotReached(true);
  
  // Check for the depth within the scope ...
  if (depth_) {
    if ( (history_.size()-scope_.size())==depth_ ) {
      depthNotReached=false;
    }
  }
  if (depthNotReached) {
    if ((*walker_).firstChild()) {
      DDExpandedNode & expnBefore(history_.back());
      DDCompactView::walker_type::value_type curr = (*walker_).current();
 
      DDPosData * newPosd = curr.second;
    
          // T = ... (see nextSiblinig())
      DDTranslation newTrans = expnBefore.trans_ + expnBefore.rot_ * newPosd->trans_;
    
      // R = ... (see nextSibling())
      DDRotationMatrix newRot =  expnBefore.rot_ *  newPosd->rot();//.inverse();
    
      // create a new Expanded node and push it to the history ...
      DDExpandedNode expn(curr.first, curr.second,
                          newTrans, newRot, 0);
    
      history_.push_back(expn);                 
    
      /* debug output
      edm::LogInfo("DDExpandedView")  << "FIRSTCHILD: name=" << expn.logicalPart().ddname() 
           << " rot=";
         
      if (expn.absRotation().isIdentity())
        edm::LogInfo("DDExpandedView")  << "[none]" << std::endl;
      else
        edm::LogInfo("DDExpandedView")  << expn.absRotation() << std::endl;
      */
    
      result = true;                     
    } // if firstChild 
  } // if depthNotReached
  return result;
} 
const DDGeoHistory & DDExpandedView::geoHistory ( ) const
bool DDExpandedView::goTo ( const nav_type newpos)

transversed the DDExpandedView according to the given stack of sibling numbers

Definition at line 508 of file DDExpandedView.cc.

Referenced by goTo(), DDDefaultNumberingScheme::node(), and TrackerGeometricDetExtraESModule::produce().

                                                 {
  return goTo(&newpos.front(),newpos.size());

}
bool DDExpandedView::goTo ( NavRange  newpos)

Definition at line 513 of file DDExpandedView.cc.

References goTo().

                                         {
  return goTo(newpos.first,newpos.second);
}
bool DDExpandedView::goTo ( int const *  newpos,
size_t  sz 
)

Definition at line 517 of file DDExpandedView.cc.

References firstChild(), goToHistory(), history_, i, gen::k, nextSibling(), pos, reset(), and query::result.

{
  bool result(false);
  
  // save the current position
  //nav_type savedPos = navPos(); 
  DDGeoHistory savedPos = history_;
   
  // reset to root node 
  //FIXME: reset to root of scope!!
  reset();
  
  // try to navigate down to the newpos
  for (size_t i = 1; i < sz; ++i) {
    result = firstChild();
    if (result) {
      int pos = newpos[i];
      for(int k=0; k<pos; ++k) {
        result = nextSibling();
      }
    }
    else {
      break;
    }   
  }
  
  if (!result) {
    goToHistory(savedPos);
  }
  return result;
}
bool DDExpandedView::goToHistory ( const DDGeoHistory pos)

NOT IN THE PROTOTYPE

goTo will reset the ExpandedView if pos is not a valid position. Currently no checks are implemented to verify that pos is within the current scope of the ExpandedView.

Definition at line 424 of file DDExpandedView.cc.

References depth_, firstChild(), i, j, nextSibling(), reset(), query::result, asciidump::s, scope_, and setScope().

Referenced by DDFilteredView::firstChild(), goTo(), DDFilteredView::nextSibling(), and DDFilteredView::parent().

{
  bool result = true;
  int tempD = depth_;
  //DCOUT('G', " goto- target= " << pos );
  DDGeoHistory tempScope = scope_;
  reset();
  DDGeoHistory::size_type s = pos.size();
  for( DDGeoHistory::size_type j=1; j<s; ++j) {
    if (! firstChild()) {
      result = false;
      //edm::LogError("DDExpandedView") << " ERROR!  , wrong usage of DDExpandedView::goTo! " << std::endl;
      //exit(1);
      break;
    }  
    int i=0;
    for (; i<pos[j].siblingno(); ++i) {
      if (! nextSibling()) {
        //edm::LogError("DDExpandedView") << " ERROR!  , wrong usage of DDExpandedView::goTo! " << std::endl;        
        result = false;
      } 
    }
  }
  
  if (!result) {
    reset();
    setScope(tempScope, tempD);
  } 
  else {
    scope_ = tempScope;
    depth_ = tempD;
  }
  
  //DCOUT('G', " goto-result = " << history_ );
  return result;
}
const DDLogicalPart & DDExpandedView::logicalPart ( ) const
DDsvalues_type DDExpandedView::mergedSpecifics ( ) const

Definition at line 336 of file DDExpandedView.cc.

References mergedSpecificsV().

Referenced by MagGeoBuilderFromDDD::volumeHandle::volumeHandle().

                                                     {
  DDsvalues_type merged;
  mergedSpecificsV(merged);
  return merged;
}
void DDExpandedView::mergedSpecificsV ( DDsvalues_type res) const

Definition at line 343 of file DDExpandedView.cc.

References DDLogicalPart::attachedSpecifics(), geoHistory(), estimatePileup::hist, i, logicalPart(), and edm::merge().

Referenced by DDSpecificsFilter::accept_impl(), mergedSpecifics(), DDFilteredView::mergedSpecifics(), and DDFilteredView::mergedSpecificsV().

{

  merged.clear();
  const std::vector<std::pair<DDPartSelection*, DDsvalues_type*> > & specs = logicalPart().attachedSpecifics();
  if (specs.empty()) return;
  const DDGeoHistory & hist = geoHistory();
  for (size_t i=0; i<specs.size(); ++i) {
    const std::pair<DDPartSelection*,DDsvalues_type*>& sp = specs[i];
    const DDPartSelection & psel = *(sp.first);
    if (DDCompareEqual(hist, psel)())
      merge(merged,*sp.second);
  }
  // std::sort(merged.begin(),merged.end());
}
DDExpandedView::nav_type DDExpandedView::navPos ( ) const

return the stack of sibling numbers which indicates the current position in the DDExpandedView

Definition at line 550 of file DDExpandedView.cc.

References history_, i, j, and pos.

Referenced by DDDefaultNumberingScheme::DDDefaultNumberingScheme(), GeometryInfoDump::dumpInfo(), DDDefaultNumberingScheme::id(), and DDFilteredView::navPos().

{
  DDGeoHistory::size_type i=0;
  DDGeoHistory::size_type j=history_.size();
  nav_type pos(j);  
  
  for (;i<j;++i)
    pos[i] = history_[i].siblingno();
    
  return pos;   
}
bool DDExpandedView::next ( void  )

set current node to the next node in the expanded tree

Tree transversal:

  • try to go to the first child
  • else try to go to the next sibling
  • else try to go to the next sibling of the parent

Currently the whole remaining subtree is transversed when next() is subsequently called.

Definition at line 248 of file DDExpandedView.cc.

References firstChild(), nextSibling(), and parent().

Referenced by PhysicalPartsTree::beginRun(), DDDefaultNumberingScheme::DDDefaultNumberingScheme(), DDExpandedViewDump(), ddstats(), GeometryInfoDump::dumpInfo(), DDQuery::exec(), DDFilteredView::next(), and output().

{
  bool res(false);
  if(firstChild()) 
    res=true;
  else if(nextSibling())
    res=true;
  else {
   while(parent()) {
     //DCOUT('C', "pa=" << logicalPart() );
     if(nextSibling()) {
       //DCOUT('C', "ns=" << logicalPart() );
       res=true;
       break;
     }  
   }
   //DCOUT('C', current().first << " "<< current().second );
  }
  return res;
}
bool DDExpandedView::nextB ( )

broad search order of next()

broad first

Definition at line 271 of file DDExpandedView.cc.

{
   bool res(false);
   return res;  
}
bool DDExpandedView::nextSibling ( )

set the current node to the next sibling ...

returns true, if a next sibling exists and updates this otherwise returns false. If a scope was set, the nextSibling of the root of the scope is not selected.

Definition at line 103 of file DDExpandedView.cc.

References cmsDriverOptions::counter, history_, query::result, DDPosData::rot(), DDExpandedNode::rot_, scope_, and DDExpandedNode::trans_.

Referenced by MagGeoBuilderFromDDD::build(), descend(), goTo(), goToHistory(), next(), DDFilteredView::nextSibling(), and DDI::Specific::node().

{
  bool result(false);
  if (scope_.size() && history_.back() == scope_.back()) {
   ; // no-next-sibling, if current node is the root of the scope!
  } 
  else {
    if ((*walker_).nextSibling()) {
      DDExpandedNode & expn(history_.back()); // back of history_ is always current node
      DDCompactView::walker_type::value_type curr = (*walker_).current();
      DDPosData const * posdOld = expn.posd_;
      expn.logp_=curr.first;
      expn.posd_=curr.second;
      
      DDGeoHistory::size_type hsize = history_.size();
      
      
      if (hsize>1) {
        const DDExpandedNode & expnBefore(history_[hsize-2]);
        
        // T = T1 + INV[R1] * T2
        expn.trans_  = expnBefore.trans_ + (expnBefore.rot_ * expn.posd_->trans_);
     
        // R = R1*INV[R2]       
        // VI in principle we can do this
        if ( !(expn.posd_->rot()==posdOld->rot()) ) {
          expn.rot_ = expnBefore.rot_ * expn.posd_->rot();//.inverse();
          ++counter().diff;
        }else ++counter().same;

      }
      else {
        expn.trans_ = expn.posd_->trans_;
        expn.rot_ = expn.posd_->rot();//.inverse();
      }   
      ++expn.siblingno_;
      result = true; 
    }
  }
  return result;
}
bool DDExpandedView::parent ( )

set the current node to the parent node ...

returns ture, if a parent exists and updates this otherwise returns false. When false is returned, the root node of the scope is reached.

Definition at line 201 of file DDExpandedView.cc.

References history_, query::result, and scope_.

Referenced by next(), DDFilteredView::nextSibling(), reset(), and setScope().

{
  bool result(false);
  bool scopeRoot(false);
  
  // check for a scope
  if (scope_.size()) {
    if (scope_.back() == history_.back()) { 
      // the current node is the root of the scope
      scopeRoot = true;
    }  
  }
  
  if (!scopeRoot) {
    if ((*walker_).parent()) {
      history_.pop_back();
      result = true;
    }
  }   
  
  return result;  
}
void DDExpandedView::reset ( void  )

true, if a call to firstChild() would succeed (current node has at least one child)

clears the scope and sets the ExpandedView to its root-node

Definition at line 378 of file DDExpandedView.cc.

References clearScope(), and parent().

Referenced by DDDefaultNumberingScheme::DDDefaultNumberingScheme(), DDQuery::exec(), goTo(), goToHistory(), and DDFilteredView::reset().

{
   clearScope();
   while(parent()) 
     ;
}
const DDRotationMatrix & DDExpandedView::rotation ( void  ) const
const DDGeoHistory & DDExpandedView::scope ( ) const

The scope of the expanded-view.

All navigational commands only operate in the subtree rooted by the node marked by the node of the DDGeoHistory returned by this method. If the size() of the scope equals 0, the full scope covering the whole expanded-view is set (default).

Definition at line 366 of file DDExpandedView.cc.

References scope_.

Referenced by DDFilteredView::scope().

{
   return scope_;
}   
bool DDExpandedView::setScope ( const DDGeoHistory sc,
int  depth = 0 
)

sets the scope of the expanded view

The scope of the expanded-view is set to the subtree rooted by the node marked by the DDGeohistory hist. The current not of the expanded view is set to the root of the subtree. All navigational methods apply only on the subtree.

In case of hist not marking a valid node in the expanded-view, the state of the expanded-view is unchanged and false is returned by setScope(). Otherwise true is returned.

Definition at line 396 of file DDExpandedView.cc.

References depth(), depth_, descend(), parent(), query::result, and scope_.

Referenced by DDQuery::exec(), goToHistory(), and DDFilteredView::setScope().

{
  bool result(false);
  
  DDGeoHistory buf = scope_; // save current scope
  scope_.clear(); // sets scope to global (full) scope

  while (parent()) ; // move up to the root of the expanded-view
  
  if (descend(sc)) { // try to move down the given scope-history ...
    scope_ = sc;
    depth_ = depth;
    result = true;
  }  
  else {
    scope_ = buf;
  }
  
  return result;  
}
std::vector< const DDsvalues_type * > DDExpandedView::specifics ( ) const

User specific data attached to the current node.

User specific data can be attac hed to single nodes or a selection of nodes in the expanded view through the DDSpecifics interface.

The resulting std::vector is of size 0 if no specific data was attached.

Definition at line 302 of file DDExpandedView.cc.

References query::result, and specificsV().

Referenced by DDQuery::exec().

{
  // backward compatible
  std::vector<const DDsvalues_type * > result;
  specificsV(result);
  return result;
}
void DDExpandedView::specificsV ( std::vector< const DDsvalues_type * > &  vc) const

Definition at line 310 of file DDExpandedView.cc.

References DDLogicalPart::attachedSpecifics(), geoHistory(), estimatePileup::hist, i, and logicalPart().

Referenced by DDSpecificsFilter::accept_impl(), DDFilteredView::specifics(), specifics(), and DDFilteredView::specificsV().

{
  unsigned int i(0);
  //edm::LogInfo("DDExpandedView")  << " in ::specifics " << std::endl;
  const std::vector<std::pair<DDPartSelection*, DDsvalues_type*> > & specs = logicalPart().attachedSpecifics();
  if (specs.size()) { // do only if SpecPar has data defined 
    //edm::LogInfo("DDExpandedView")  << " found: specifics size=" << specs.size() << std::endl;
    result.reserve(specs.size());
    for (; i<specs.size(); ++i) {
      const std::pair<DDPartSelection*,DDsvalues_type*>& sp = specs[i];
      // a part selection
      const DDPartSelection & psel = *(sp.first);
      //edm::LogInfo("DDExpandedView")  << " partsel.size = " << psel.size() << std::endl;
      //edm::LogInfo("DDExpandedView")  << " geohistory   = " << geoHistory() << std::endl;
      const DDGeoHistory & hist = geoHistory();
      
      //dump(hist);
      //dump(psel);
      
      if (DDCompareEqual(hist, psel)()) //edm::LogInfo("DDExpandedView")  << "MATCH!!!!" << std::endl;
        result.push_back( sp.second );
    }
  }  
}
const DDTranslation & DDExpandedView::translation ( void  ) const

The absolute translation of the current node.

Definition at line 48 of file DDExpandedView.cc.

References history_.

Referenced by PhysicalPartsTree::beginRun(), MagGeoBuilderFromDDD::build(), DDExpandedViewDump(), GeometryInfoDump::dumpInfo(), output(), and DDFilteredView::translation().

{ 
  return history_.back().trans_; 
}

Friends And Related Function Documentation

friend class DDFilteredView [friend]

Definition at line 37 of file DDExpandedView.h.


Member Data Documentation

unsigned int DDExpandedView::depth_ [protected]

depth of the scope, 0==unrestricted depth

Definition at line 135 of file DDExpandedView.h.

Referenced by clearScope(), depth(), firstChild(), DDFilteredView::firstChild(), goToHistory(), and setScope().

std::vector<nav_type> DDExpandedView::nextBStack_ [protected]

Definition at line 137 of file DDExpandedView.h.

Definition at line 132 of file DDExpandedView.h.

Referenced by DDExpandedView().

Definition at line 131 of file DDExpandedView.h.

Referenced by DDExpandedView().

Definition at line 130 of file DDExpandedView.h.

Referenced by DDExpandedView().

the tricky walker

Definition at line 129 of file DDExpandedView.h.

Referenced by DDExpandedView().

???

Definition at line 136 of file DDExpandedView.h.

Referenced by DDExpandedView().