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/GlobalSystemOfUnits.h"
00005
00006
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008
00009 DDCompactViewImpl::DDCompactViewImpl(const DDLogicalPart & rootnodedata)
00010 : root_(rootnodedata)
00011 {
00012 LogDebug("DDCompactViewImpl") << "Root node data = " << rootnodedata << std::endl;
00013 }
00014
00015 DDCompactViewImpl::~DDCompactViewImpl()
00016 {
00017 GraphNav::adj_list::size_type it = 0;
00018 if ( graph_.size() == 0 ) {
00019 LogDebug("DDCompactViewImpl") << "In destructor, graph is empty. Root:" << root_ << std::endl;
00020 } else {
00021 LogDebug("DDCompactViewImpl") << "In destructor, graph is NOT empty. Root:" << root_ << " graph_.size() = " << graph_.size() << std::endl;
00022 for (; it < graph_.size() ; ++it) {
00023 GraphNav::edge_range erange = graph_.edges(it);
00024 for(; erange.first != erange.second; ++(erange.first)) {
00025 DDPosData * pd = graph_.edgeData(erange.first->second);
00026 delete pd;
00027 pd=0;
00028 }
00029 }
00030 }
00031 edm::LogInfo("DDCompactViewImpl") << std::endl << "DDD transient representation has been destructed." << std::endl << std::endl;
00032 }
00033
00034 graphwalker<DDLogicalPart,DDPosData*> DDCompactViewImpl::walker() const
00035 {
00036 DCOUT('C',"DDCompactView::walker() root_=" << root_);
00037 return graphwalker<DDLogicalPart,DDPosData*>(graph_,root_);
00038 }
00039
00040
00041
00042 #include "DetectorDescription/Core/interface/DDSolid.h"
00043 #include "DetectorDescription/Core/interface/DDMaterial.h"
00044 double DDCompactViewImpl::weight(const DDLogicalPart & aPart) const
00045 {
00046
00047
00048 if (!aPart)
00049 return -1;
00050 DDLogicalPart part = aPart;
00051
00052 if (part.weight())
00053 return part.weight();
00054
00055
00056 double childrenVols=0;
00057 double childrenWeights=0;
00058 walker_type walker(graph_,part);
00059 if(walker.firstChild()) {
00060 bool doIt=true;
00061 while(doIt) {
00062 double a_vol;
00063 DDLogicalPart child(walker.current().first);
00064 a_vol=child.solid().volume();
00065 if (a_vol <= 0.) {
00066 edm::LogError("DDCompactViewImpl") << "DD-WARNING: volume of solid=" << aPart.solid()
00067 << "is zero or negative, vol=" << a_vol/m3 << "m3" << std::endl;
00068 }
00069 DCOUT_V('C', "DC: weightcalc, currently=" << child.ddname().name()
00070 << " vol=" << a_vol/cm3 << "cm3");
00071 childrenVols += a_vol;
00072 childrenWeights += weight(child);
00073 doIt=walker.nextSibling();
00074 }
00075 }
00076
00077 double dens = part.material().density();
00078 if (dens <=0) {
00079 edm::LogError("DDCompactViewImpl") << "DD-WARNING: density of material=" << part.material().ddname()
00080 << " is negative or zero, rho=" << dens/g*cm3 << "g/cm3" << std::endl;
00081 }
00082 double p_vol = part.solid().volume();
00083 double w = (p_vol - childrenVols)*dens + childrenWeights;
00084 if ( (fabs(p_vol) - fabs(childrenVols))/fabs(p_vol) > 1.01 ) {
00085 edm::LogError("DDCompactViewImpl") << "DD-WARNING: parent-volume smaller than children, parent="
00086 << part.ddname() << " difference-vol="
00087 << (p_vol - childrenVols)/m3 << "m3, this is "
00088 << (childrenVols - p_vol)/p_vol << "% of the parent-vol." << std::endl;
00089 }
00090
00091
00092 part.weight() = w;
00093 return w;
00094
00095 }
00096
00097 void DDCompactViewImpl::position (const DDLogicalPart & self,
00098 const DDLogicalPart & parent,
00099 int copyno,
00100 const DDTranslation & trans,
00101 const DDRotation & rot,
00102 const DDDivision * div)
00103 {
00104 DDPosData * pd = new DDPosData(trans,rot,copyno,div);
00105 graph_.addEdge(parent,self,pd);
00106 }
00107
00108
00109 void DDCompactViewImpl::swap( DDCompactViewImpl& implToSwap ) {
00110 graph_.swap(implToSwap.graph_);
00111 }
00112
00113 DDCompactViewImpl::DDCompactViewImpl() { }