CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DetectorDescription/Core/src/hierarchy.cc

Go to the documentation of this file.
00001 //#include "DetectorDescription/Core/src/test_core.h"
00002 
00003 //#include <time.h>
00004 //#include <sys/times.h>
00005 
00006 // Two modules of CLHEP are partly used in DDD
00007 // . unit definitions (such as m, cm, GeV, ...) of module CLHEP/Units
00008 // . rotation matrices and translation std::vectors of module CLHEP/Vector
00009 //   (they are typedef'd to DDRotationMatrix and DDTranslation in
00010 //   DDD/DDCore/interface/DDTransform.h
00011 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00012 
00013 
00014 // Interface
00015 /*
00016   Doc!
00017 */
00018 //#include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
00019 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00020 #include "DetectorDescription/Core/interface/DDSolid.h"
00021 #include "DetectorDescription/Core/interface/DDMaterial.h"
00022 //#include "DetectorDescription/Core/interface/DDTransform.h"
00023 #include "DetectorDescription/Core/interface/DDCompactView.h"
00024 //#include "DetectorDescription/Core/interface/DDExpandedView.h"
00025 //#include "DetectorDescription/Core/interface/DDNodes.h"
00026 //#include "DetectorDescription/Core/interface/DDSpecifics.h"
00027 #include "DetectorDescription/Core/interface/DDPartSelection.h"
00028 #include "DetectorDescription/Core/interface/DDName.h"
00029 //#include "DetectorDescription/Core/interface/DDAlgo.h"
00030 //#include "DetectorDescription/Core/interface/DDInit.h"
00031 //#include "DetectorDescription/Core/interface/DDScope.h"
00032 //#include "DetectorDescription/Core/interface/DDFilter.h"
00033 //#include "DetectorDescription/Core/interface/DDQuery.h"
00034 //#include "DetectorDescription/Core/interface/DDFilteredView.h"
00035 //#include "DetectorDescription/Core/interface/DDNumberingScheme.h"
00036 
00037 //#include "DetectorDescription/ExprAlgo/interface/ExprEvalSingleton.h"
00038 //#include "Solid.h"
00039 
00040 //#include <typeinfo>
00041 #include <fstream>
00042 #include <string>
00043 #include <set>
00044 #include <iostream>
00045 #include <map>
00046 
00047 std::string link(std::string & nm, std::string & ns)
00048 {
00049    return ns + nm + ".html";
00050 }
00051 
00052 void streamSolid(DDSolid s, std::ostream & os) {
00053   DDSolidShape sp = s.shape();
00054   if ( (sp==ddpolycone_rrz) || (sp==ddpolyhedra_rrz) ) {
00055     unsigned int i = 0;
00056     const std::vector<double> & p = s.parameters();
00057     if (sp==ddpolyhedra_rrz){
00058       os << "numSides=" << p[0] << " ";
00059       ++i;
00060     }
00061     os <<"startPhi[deg]=" << p[i]/deg << " deltaPhi[deg]" << p[i+1]/deg << std::endl;
00062     i +=2;
00063     os << "<table><tr><td>z[cm]</td><td>rMin[cm]</td><td>rMax[cm]</td></tr>";
00064     while ( i+1 < p.size()) {
00065       os << "<tr><td>" << p[i]/cm << "</td>";
00066       os << "<td>" << p[i+1]/cm << "</td>";
00067       os << "<td>" << p[i+2]/cm << "</td></tr>" << std::endl;
00068       i = i+3;  
00069     }
00070     os << "</table>" << std::endl;
00071   } else
00072   {
00073     os << s;
00074   }
00075 }
00076 
00077 void generateHtml(std::vector<DDLogicalPart> & v, std::map<DDLogicalPart,int> & c)
00078 {
00079    static DDCompactView cpv;
00080    std::string name = v.back().name().name();
00081    std::string ns   = v.back().name().ns();
00082    std::string fname = link(name,ns);
00083    std::ofstream file(fname.c_str());
00084    
00085    
00086    file << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" << std::endl;
00087    file << "<html><head><title>DDD-part:" << ns << " " << name << "</title>";
00088    file << "<body><h2>"
00089         <<  "name=" << name << "  namespace=" << ns << "</h2>" << std::endl;
00090    file << "<br>weight = " << cpv.weight(v.back())/kg << "kg<br>" << std::endl;
00091    //file << "volume = " << v.back().solid().volume()/m3 << "m3<br>" << std::endl;
00092    //file << "solid  = " << typeid(v.back().solid().rep()).name() << "  ";
00093            streamSolid(v.back().solid(),file);
00094    file << "<br>" << std::endl;
00095    std::string mname = v.back().material().name().name();
00096    std::string mns   = v.back().material().name().ns();
00097    std::string lk = mns + ".html#" + mname;
00098    file << "material = " << "<a href=\""  << lk <<  "\">"  
00099                          << mname << "</a>" << std::endl;
00100    file << "density = "  << v.back().material().density()/g*cm3 << "g/cm3<br>" << std::endl;
00101                          
00102    // link children
00103    file << "<br>Children:<br>" << std::endl;
00104    std::map<DDLogicalPart,int>::iterator cit = c.begin();
00105    for (; cit != c.end(); ++cit) {
00106      std::string nm, nsp;
00107      nm = cit->first.name().name(); nsp = cit->first.name().ns();
00108      file << "<a href=\"" << link(nm,nsp) << "\">"
00109           << nm  << "(" << cit->second << ")</a> " << std::endl;
00110    }
00111    
00112    file << "<br><br>Ancestors:<br>";
00113    int s = v.size();
00114    --s; --s;
00115    for (; s>=0; --s) {
00116      std::string nm,nsp;
00117      nm = v[s].name().name();
00118      nsp = v[s].name().ns();
00119      file << std::string(2*s,' ') << "<a href=\"" << link(nm,nsp) << "\">"
00120               << nm << "</a><br> " << std::endl;
00121    }
00122    file << "<br>SpecPars:<br>" << std::endl;
00123    file << "<table><tbody>" << std::endl;
00124    typedef std::vector< std::pair<DDPartSelection*,DDsvalues_type*> > sv_type;
00125    sv_type sv = v.back().attachedSpecifics();
00126    sv_type::iterator sit = sv.begin();
00127    for (; sit != sv.end(); ++sit) {
00128      file << "<tr>" << std::endl
00129           << " <td>" << *(sit->first) <<"</td>" << std::endl;
00130      file << " <td>";     
00131      DDsvalues_type::iterator svit = sit->second->begin();
00132      for(; svit != sit->second->end(); ++svit) {
00133        file << svit->second << "<br>" <<std::endl;
00134      }
00135      file << "</td>" << std::endl
00136           << "</tr>" << std::endl;
00137      
00138    }
00139    file << "</table></tbody>" << std::endl;
00140    
00141    file << "<br></body></html>" <<std::endl;
00142    file.close();
00143 }
00144 
00145 void writeMaterials(std::map<std::string,std::set<DDMaterial> > & m)
00146 {
00147    std::map<std::string, std::set<DDMaterial> >::iterator it = m.begin();
00148    for (; it != m.end(); ++it) {
00149      std::string fname = it->first + ".html"; 
00150      std::ofstream file(fname.c_str());
00151      file << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" << std::endl;
00152      file << "<html><head><title>DDD-Materials</title>";
00153      file << "<body>";
00154      std::set<DDMaterial>::iterator mit = it->second.begin();
00155      for (; mit != it->second.end(); ++mit) {
00156        file << "<a name=\"" << mit->name().name() << "\">";
00157        file << mit->name().name() << " d=" << mit->density()/g*cm3 
00158             << "g/cm3";
00159             
00160        file << "</a><br>";
00161      }      
00162      file << "</body></html>" << std::endl;
00163      file.close();
00164    }
00165 
00166 }
00167 
00168 void hierarchy(const DDLogicalPart & parent)
00169 {
00170   static  DDCompactView cpv ;
00171   static DDCompactView::graph_type g = cpv.graph();
00172   static int count=0;
00173   static std::vector<DDLogicalPart> history;
00174   static std::map<std::string,std::set<DDMaterial> > materials;
00175   //DDCompactView::graph_type::adj_iterator it = g.begin();
00176   
00177   history.push_back(parent);
00178   materials[parent.material().name().ns()].insert(parent.material());
00179   std::cout << history.size() << std::string(2*count,' ') << " " << parent.ddname() << std::endl;
00180   DDCompactView::graph_type::edge_range er = g.edges(parent);
00181   DDCompactView::graph_type::edge_iterator eit = er.first;
00182   std::map<DDLogicalPart,int> children;
00183   for (; eit != er.second; ++eit) {  
00184      children[g.nodeData(*eit)]++;
00185   }
00186   
00187   generateHtml(history,children);
00188   
00189   std::map<DDLogicalPart,int>::iterator cit = children.begin();
00190   for (; cit != children.end(); ++cit) {
00191      ++count;
00192      hierarchy(cit->first);
00193      history.pop_back();
00194      --count;
00195   }
00196   
00197   writeMaterials(materials);
00198 }
00199