CMS 3D CMS Logo

DDCompactViewImpl.cc

Go to the documentation of this file.
00001 #include "DetectorDescription/Core/interface/DDCompactViewImpl.h"
00002 #include "DetectorDescription/Core/interface/DDCompactView.h"
00003 #include "DetectorDescription/Base/interface/DDdebug.h"
00004 #include "CLHEP/Units/SystemOfUnits.h"
00005 
00006 // Message logger.
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 
00009 DDCompactViewImpl::DDCompactViewImpl(const DDLogicalPart & rootnodedata)
00010   :  root_(rootnodedata)//, rootWalker_(0)
00011 {
00012   //  edm::LogInfo("DDCompactViewImpl") << "Root node data = " << rootnodedata << std::endl;
00013    //buildTree(rootnodedata,root_);
00014    //buildGraph();
00015 }
00016 
00017 
00018 DDCompactViewImpl::DDCompactViewImpl()
00019  : root_("")
00020 {
00021 
00022 }
00023 
00024 
00025 DDCompactViewImpl::~DDCompactViewImpl() 
00026 {  
00027    GraphNav::adj_list::size_type it = 0;
00028    for (; it < graph_.size() ; ++it) {
00029      GraphNav::edge_range erange = graph_.edges(it); //it->second.begin();
00030      for(; erange.first != erange.second; ++(erange.first)) {
00031        DDPosData * pd = graph_.edgeData(erange.first->second);
00032        delete pd;
00033        pd=0;
00034      }  
00035    }
00036    edm::LogInfo("DDCompactViewImpl") << std::endl << "DDD transient representation has been destructed." << std::endl << std::endl;   
00037 }
00038 
00039 
00040 // deprecated
00041 void DDCompactViewImpl::buildPaths()
00042 {
00043   //paths_ = new GraphNavPaths(graph_,root_); // good luck!
00044 }
00045 
00046 
00047 /*
00048 std::pair<bool,DDPhysicalPart> DDCompactViewImpl::goTo(const DDPartSelector & path) const
00049 {
00050   std::pair<bool,DDPhysicalPart> result(std::make_pair(false,DDPhysicalPart()));
00051   DDPhysicalPart & pp(result.second);
00052   DDTranslation trans;
00053   DDRotationMatrix rot;
00054   return result;
00055 }
00056 
00057 */
00058 
00059 graphwalker<DDLogicalPart,DDPosData*> DDCompactViewImpl::walker() const
00060 {
00061    DCOUT('C',"DDCompactView::walker() root_=" << root_);
00062    return graphwalker<DDLogicalPart,DDPosData*>(graph_,root_);
00063 }
00064 
00065 // calculates the weight and caches it in LogicalPartImpl
00066 //double DDCompactViewImpl::weight(DDLogicalPart & part)
00067 #include "DetectorDescription/Core/interface/DDSolid.h"
00068 #include "DetectorDescription/Core/interface/DDMaterial.h"
00069 double DDCompactViewImpl::weight(const DDLogicalPart & aPart) const
00070 {
00071  // return 0;
00072 
00073    if (!aPart)
00074      return -1;
00075    DDLogicalPart part = aPart;
00076    //double result;  
00077    if (part.weight())
00078      return part.weight();
00079    
00080    // weigth = (parent.vol - children.vol)*parent.density + weight(children)
00081    double childrenVols=0;
00082    double childrenWeights=0;
00083    walker_type walker(graph_,part);
00084    if(walker.firstChild()) {
00085      bool doIt=true;
00086      while(doIt) {
00087        double a_vol;
00088        DDLogicalPart child(walker.current().first);
00089        a_vol=child.solid().volume();
00090        if (a_vol <= 0.) {
00091          edm::LogError("DDCompactViewImpl")  << "DD-WARNING: volume of solid=" << aPart.solid() 
00092                << "is zero or negative, vol=" << a_vol/m3 << "m3" << std::endl;
00093        }
00094        DCOUT_V('C', "DC: weightcalc, currently=" << child.ddname().name()
00095             << " vol=" << a_vol/cm3 << "cm3");
00096        childrenVols += a_vol;
00097        childrenWeights += weight(child); // recursive
00098        doIt=walker.nextSibling();
00099      }
00100    }
00101    
00102    double dens = part.material().density();
00103    if (dens <=0) {
00104      edm::LogError("DDCompactViewImpl")  << "DD-WARNING: density of material=" << part.material().ddname() 
00105            << " is negative or zero, rho=" << dens/g*cm3 << "g/cm3" << std::endl;
00106    }
00107    double p_vol  = part.solid().volume();
00108    double w =   (p_vol - childrenVols)*dens + childrenWeights; 
00109    if (  (fabs(p_vol) - fabs(childrenVols))/fabs(p_vol) > 1.01 ) {
00110      edm::LogError("DDCompactViewImpl")  << "DD-WARNING: parent-volume smaller than children, parent=" 
00111           << part.ddname() << " difference-vol=" 
00112            << (p_vol - childrenVols)/m3 << "m3, this is " 
00113            << (childrenVols - p_vol)/p_vol << "% of the parent-vol." << std::endl;
00114    }
00115   
00116    //part.rep().weight_=w;
00117    part.weight() = w;
00118    return w;
00119    
00120 }
00121 
00122 /*
00123 expnode_t * DDCompactViewImpl::expand(const DDPartSelector & path) const
00124 {
00125    //FIXME: DDCompactViewImpl::expand - add?? isUnique(path) ??...
00126    expnode_t * result = 0;
00127    return result;
00128     
00129 }
00130 
00131 */

Generated on Tue Jun 9 17:32:11 2009 for CMSSW by  doxygen 1.5.4