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