00001 #include "DetectorDescription/Core/interface/DDCompactView.h" 00002 #include "DetectorDescription/Core/interface/DDLogicalPart.h" 00003 #include "DetectorDescription/Core/interface/DDRoot.h" 00004 #include "DetectorDescription/Base/interface/DDdebug.h" 00005 #include "DetectorDescription/Base/interface/DDException.h" 00006 00007 #include <iostream> 00008 00009 //DDCompactViewImpl * DDCompactView::global_ = 0; 00010 00027 DDCompactView::DDCompactView() 00028 : rep_(0) 00029 { 00030 global(); 00031 } 00032 00033 // NOTE TO SELF: Mike, DO NOT try to fix the memory leak here by going global again!!! 00034 DDCompactView::DDCompactView(const DDLogicalPart & rootnodedata) 00035 : rep_(new DDCompactViewImpl(rootnodedata)) 00036 { 00037 // global_ = rep_; 00038 } 00039 00040 // Prototypish, to be used from within DDpos(...) 00041 // It will produce a new, empty compact-view with NO root-defined 00042 // Subsequent calls will be used for DDCore internal processing 00043 // (e.g. fetching the compact-view after parsing and restructuring 00044 // it to get rid of refletions ...) 00045 DDCompactView::DDCompactView(bool add) 00046 : rep_(0) 00047 { /* 00048 if (!global_) { 00049 global_ = new DDCompactViewImpl(); 00050 } 00051 rep_ = global_; */ 00052 global(); 00053 } 00054 00055 00056 DDCompactView::~DDCompactView() 00057 { 00058 DCOUT_V('C',"DC: Deleting compact VIEW!!!!!!!!! <<<<<<<<<<<<<<<=================="); 00059 } 00060 00061 00067 const graph_type & DDCompactView::graph() const 00068 { 00069 return rep_->graph(); 00070 } 00071 00072 00073 void DDCompactView::optimize() 00074 { 00075 // deprecated! 00076 //int i; 00077 } 00078 00079 graph_type & DDCompactView::writeableGraph() 00080 { 00081 return const_cast<graph_type&>(rep_->graph()); 00082 } 00083 00084 00085 void DDCompactView::print(std::ostream & os) const 00086 { 00087 rep_->print(os); 00088 } 00089 00090 00091 const DDLogicalPart & DDCompactView::root() const 00092 { 00093 return rep_->root(); 00094 } 00095 00096 00097 DDCompactView::walker_type DDCompactView::walker() const 00098 { 00099 return rep_->walker(); 00100 } 00101 00102 00121 double DDCompactView::weight(const DDLogicalPart & p) const 00122 { 00123 return rep_->weight(p); 00124 } 00125 00126 // >>---==========================<()>==========================---<< 00127 00128 // UNSTABLE STUFF below ... 00129 00130 void DDCompactView::global() 00131 { 00132 // DDLogicalPart l; 00133 // DDName n = l.ddname(); 00134 static DDCompactViewImpl* global_=0; 00135 if (!global_) { 00136 DDLogicalPart rt = DDRootDef::instance().root(); 00137 if(rt.isDefined().first) { 00138 const DDName & tmp = rt.ddname(); 00139 DDLogicalPart aRoot(tmp); 00140 global_ = new DDCompactViewImpl(aRoot); // FIXME!!!!!!! 00141 } 00142 } 00143 // DCOUT('C', "DC: CompactView root=" << DDRootDef::instance().root() ); 00144 if (!global_) 00145 throw DDException("Global CompactView construction failed .."); 00146 global_->setRoot(DDRootDef::instance().root()); 00147 00148 rep_ = global_; 00149 } 00150 00151 00152 void DDCompactView::setRoot(const DDLogicalPart & root) 00153 { 00154 rep_->setRoot(root); 00155 } 00156 00157 #include "DetectorDescription/Core/interface/DDMaterial.h" 00158 #include "DetectorDescription/Core/interface/DDSolid.h" 00159 #include "DetectorDescription/Core/interface/DDTransform.h" 00160 //#include "DetectorDescription/Core/interface/DDPosPart.h" 00161 #include "DetectorDescription/Core/interface/DDSpecifics.h" 00162 //#include "DetectorDescription/ExprAlgo/interface/ExprEvalSingleton.h" 00163 00164 void DDCompactView::clear() 00165 { 00166 00167 graph_type & g = writeableGraph(); 00168 00169 graph_type::adj_iterator ait = g.begin(); 00170 for (; ait != g.end(); ++ait) { 00171 graph_type::edge_list::iterator eit = ait->begin(); 00172 for (; eit != ait->end(); ++eit) { 00173 //DDTranslation* tp = const_cast<DDTranslation*>(&(eit->second->trans_)); 00174 //delete tp; 00175 delete g.edgeData(eit->second); eit->second=0; 00176 } 00177 } 00178 00179 DDMaterial::clear(); 00180 DDLogicalPart::clear(); 00181 DDSolid::clear(); 00182 DDRotation::clear(); 00183 DDSpecifics::clear(); 00184 DDValue::clear(); 00185 00186 //NOT GOOD Practice! either! -- Mike Case 00187 LPNAMES::instance().clear(); 00188 DIVNAMES::instance().clear(); 00189 //NOT GOOD Practice! -- Mike Case 00190 DDName::Registry& reg_ = DDI::Singleton<DDName::Registry>::instance(); 00191 reg_.clear(); 00192 00193 /* 00194 walker_type w(g,root()); 00195 bool goOn=true; 00196 std::vector<DDPosData*> v; 00197 while (goOn) { 00198 graph_type::value_type c = w.current(); 00199 //delete &(c.second->trans_);// &(c.second->trans_)=0; 00200 v.push_back(c.second); //c.second=0; 00201 goOn = w.next(); 00202 } 00203 std::vector<DDPosData*>::iterator it = v.begin(); 00204 for (; it != v.end(); ++it) 00205 delete *it; 00206 */ 00207 //(mec:2007-06-07) Do not understand, but setting this to 0 caused memory crashes, like Ptr was being 00208 // deleted twice or something? I only get the error message when exiting iguana :-( 00209 //(mec:2007-06-08) Got it. In the destructor of XMLIdealGeometrySource I do the illegal thing and "grab" 00210 // DDCompactView cpv; then I cpv.clear(); Since clear() sets this rep_=0, when the boost autopointer 00211 // goes out of scope, this 0 representation causes it to blow up... SOOO leave this problem until DD is 00212 // re-written... 00213 // rep_=0; 00214 }