Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00012
00013
00014
00015
00016
00017
00018
00019 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00020 #include "DetectorDescription/Core/interface/DDSolid.h"
00021 #include "DetectorDescription/Core/interface/DDMaterial.h"
00022
00023 #include "DetectorDescription/Core/interface/DDCompactView.h"
00024
00025
00026
00027 #include "DetectorDescription/Core/interface/DDPartSelection.h"
00028 #include "DetectorDescription/Core/interface/DDName.h"
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
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
00092
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
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
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