File indexing completed on 2024-04-06 12:05:34
0001 #include "DetectorDescription/Core/interface/DDRotationMatrix.h"
0002 #include "DetectorDescription/Core/interface/DDTranslation.h"
0003 #include "DetectorDescription/Core/interface/Singleton.h"
0004 #include "DetectorDescription/Core/interface/Singleton.icc"
0005 #include "DetectorDescription/Core/interface/DDBase.h"
0006 #include "DetectorDescription/Core/interface/DDEnums.h"
0007 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0008 #include "DetectorDescription/Core/interface/DDMaterial.h"
0009 #include "DetectorDescription/Core/interface/DDName.h"
0010 #include "DetectorDescription/Core/interface/DDPartSelection.h"
0011 #include "DetectorDescription/Core/interface/DDSolid.h"
0012 #include "DetectorDescription/Core/interface/DDSpecifics.h"
0013 #include "DetectorDescription/Core/interface/DDTransform.h"
0014 #include "DetectorDescription/Core/interface/LogicalPart.h"
0015 #include "DetectorDescription/Core/interface/Material.h"
0016 #include "DetectorDescription/Core/interface/Specific.h"
0017 #include "DetectorDescription/Core/interface/Solid.h"
0018 #include "DataFormats/Math/interface/GeantUnits.h"
0019 #include "DetectorDescription/RegressionTest/interface/DDErrorDetection.h"
0020 #include "DetectorDescription/RegressionTest/interface/DDHtmlFormatter.h"
0021
0022 #include <fstream>
0023 #include <map>
0024 #include <memory>
0025 #include <set>
0026 #include <string>
0027 #include <sys/stat.h>
0028 #include <utility>
0029 #include <vector>
0030
0031 using namespace std;
0032 using namespace geant_units::operators;
0033
0034 ostream& operator<<(ostream& o, const DDHtmlFormatter& f) {
0035 o << f.os_.str();
0036 f.os_.str("");
0037 return o;
0038 }
0039
0040 DDHtmlFormatter DDHtmlFormatter::header(const string& title, const string& style) {
0041 pre();
0042 os_ << "<html>\n<head>\n<title>" << title << "</title>" << endl;
0043 os_ << "<link rel=\"stylesheet\" type=\"text/css\" href=\"" << style << "\">" << endl;
0044
0045 return *this;
0046 }
0047
0048 DDHtmlFormatter DDHtmlFormatter::link(const string& url, const string& txt, const string& target) {
0049 pre();
0050 os_ << lnk(url, txt, target) << endl;
0051 return *this;
0052 }
0053
0054 string DDHtmlFormatter::lnk(const string& url, const string& txt, const string& target) {
0055 string result;
0056 result = string("<a href=\"") + url;
0057 result += string("\" target=\"") + target;
0058 result += string("\">") + txt + string("</a>");
0059 return result;
0060 }
0061
0062 DDHtmlFormatter DDHtmlFormatter::footer() {
0063 pre();
0064 os_ << "</body></html>" << endl;
0065 return *this;
0066 }
0067
0068
0069
0070
0071 void DDNsGenerator::doit() {
0072 DDHtmlFormatter f;
0073 os_ << f.header(title_, "../style.css");
0074 os_ << f.h2(title_) << f.p(text_);
0075 ns_type::const_iterator it = n_.begin();
0076 ns_type::const_iterator ed = n_.end();
0077 os_ << f.ul();
0078 for (; it != ed; ++it) {
0079 os_ << f.li(f.lnk(it->first + "/list.html", it->first, target_));
0080 }
0081 os_ << f.ulEnd() << endl;
0082 os_ << f.footer() << endl;
0083 }
0084
0085 DDHtmlDetails::DDHtmlDetails(const string& cat, const string& txt) : cat_(cat), txt_(txt) {}
0086
0087 ns_type& DDHtmlLpDetails::names() {
0088 DDLogicalPart lp;
0089 findNameSpaces(lp, names_);
0090 return names_;
0091 }
0092
0093 ns_type& DDHtmlMaDetails::names() {
0094 DDMaterial lp;
0095 findNameSpaces(lp, names_);
0096 return names_;
0097 }
0098
0099 ns_type& DDHtmlSoDetails::names() {
0100 DDSolid lp;
0101 findNameSpaces(lp, names_);
0102 return names_;
0103 }
0104
0105 ns_type& DDHtmlSpDetails::names() {
0106 DDSpecifics lp;
0107 findNameSpaces(lp, names_);
0108 return names_;
0109 }
0110
0111 ns_type& DDHtmlRoDetails::names() {
0112 DDRotation lp;
0113 findNameSpaces(lp, names_);
0114 return names_;
0115 }
0116
0117 bool DDHtmlSoDetails::details(ostream& os, const DDName& nm) {
0118 os << f_.header("Solid Details") << f_.h3(">> formatting under construction <<");
0119 os << DDSolid(nm);
0120 return true;
0121 }
0122
0123 bool DDHtmlSpDetails::details(ostream& os, const DDName& nm) {
0124 os << f_.header("SpecPars Details") << f_.h3(">> formatting under construction <<");
0125 os << DDSpecifics(nm);
0126 return true;
0127 }
0128
0129 bool DDHtmlRoDetails::details(ostream& os, const DDName& nm) {
0130 os << f_.header("Rotations Details");
0131
0132 DDRotation ddr(nm);
0133 if (ddr.isDefined().second == false) {
0134 os << "<b>ERROR!</b><br><p>The Rotation " << nm << " is not defined!</p>" << endl;
0135 return false;
0136 }
0137 DD3Vector x, y, z;
0138 ddr.matrix().GetComponents(x, y, z);
0139 os << f_.h2("Rotation: " + nm.fullname());
0140 os << f_.h3("GEANT3 style:");
0141 os << "<table border=\"0\">" << endl
0142 << "<tr><td>thetaX =</td><td>" << convertRadToDeg(x.Theta()) << " deg</td><tr>" << endl
0143 << "<tr><td>phiX =</td><td>" << convertRadToDeg(x.Phi()) << " deg</td><tr>" << endl
0144 << "<tr><td>thetaY =</td><td>" << convertRadToDeg(y.Theta()) << " deg</td><tr>" << endl
0145 << "<tr><td>phiY =</td><td>" << convertRadToDeg(y.Phi()) << " deg</td><tr>" << endl
0146 << "<tr><td>thetaZ =</td><td>" << convertRadToDeg(z.Theta()) << " deg</td><tr>" << endl
0147 << "<tr><td>phiZ =</td><td>" << convertRadToDeg(z.Phi()) << " deg</td><tr>" << endl
0148 << "</table>";
0149
0150 os << f_.h3("Rotation axis & angle (theta,phi,angle)") << endl;
0151 os << DDRotation(nm);
0152 return true;
0153 }
0154
0155 bool DDHtmlMaDetails::details(ostream& os, const DDName& nm) {
0156 typedef DDI::Singleton<map<DDMaterial, set<DDLogicalPart> > > parts_t;
0157 static bool once = false;
0158 if (!once) {
0159 once = true;
0160 DDLogicalPart::iterator<DDLogicalPart> it, ed;
0161 ed.end();
0162
0163 for (; it != ed; ++it) {
0164 if (it->isDefined().second)
0165 parts_t::instance()[it->material()].insert(*it);
0166 }
0167 }
0168
0169 string s = nm.ns() + " : " + nm.name();
0170 DDMaterial ma(nm);
0171 os << f_.header(s);
0172 os << f_.h2("Material <b>" + s + "</b>");
0173 os << f_.br();
0174 if (ma.isDefined().second == false) {
0175 os << "<b>ERROR!<b><br><p>The Material is not defined in namespace " << nm.ns() << "! </p>" << endl;
0176 return false;
0177 }
0178
0179 os << "<p>density = " << convertUnitsTo(1._g_per_cm3, ma.density()) << " g/cm3 </p>" << endl;
0180 int co = ma.noOfConstituents();
0181 if (co) {
0182 os << f_.p("Composites by fraction-mass:");
0183 os << f_.table() << f_.tr() << f_.td("<b>fm</b>") << f_.td("<b>Material</b>") << f_.td("<b>elementary?</b>")
0184 << f_.trEnd();
0185 for (int i = 0; i < co; ++i) {
0186 pair<DDMaterial, double> fm = ma.constituent(i);
0187 string elem = "ERROR";
0188 DDMaterial m = fm.first;
0189 double frac = fm.second;
0190
0191 if (m.isDefined().second) {
0192 if (m.noOfConstituents())
0193 elem = "no";
0194 else
0195 elem = "yes";
0196 }
0197 os << f_.tr() << "<td>" << frac << "</td>"
0198 << f_.td(f_.lnk("../" + m.ddname().ns() + "/" + m.ddname().name() + ".html", m.ddname().fullname(), "_popup"))
0199 << f_.td(elem) << f_.trEnd();
0200 }
0201 os << f_.tableEnd();
0202 } else {
0203 os << f_.p("ElementaryMaterial:");
0204 os << "<p>z = " << ma.z() << "</p>" << endl;
0205 os << "<p>a = " << convertUnitsTo(1._g_per_mole, ma.a()) << "g/mole</p>" << endl;
0206 }
0207
0208 const set<DDLogicalPart>& lps = parts_t::instance()[ma];
0209 set<DDLogicalPart>::const_iterator it(lps.begin()), ed(lps.end());
0210 if (it != ed) {
0211 os << f_.h3("Material used in following LogicalParts:") << endl;
0212 os << "<p>" << endl;
0213 }
0214 for (; it != ed; ++it) {
0215 const DDName& n = it->ddname();
0216 os << f_.link("../../lp/" + n.ns() + "/" + n.name() + ".html", n.fullname(), "_popup");
0217 }
0218 os << "</p>" << endl;
0219 return true;
0220 }
0221
0222 bool DDHtmlLpDetails::details(ostream& os, const DDName& nm) {
0223 static bool once = false;
0224 typedef DDI::Singleton<map<DDLogicalPart, set<DDSpecifics> > > lp_sp_t;
0225 if (!once) {
0226 once = true;
0227 DDSpecifics::iterator<DDSpecifics> it, ed;
0228 ed.end();
0229 for (; it != ed; ++it) {
0230 if (it->isDefined().second) {
0231 const vector<DDPartSelection>& ps = it->selection();
0232 vector<DDPartSelection>::const_iterator pit(ps.begin()), ped(ps.end());
0233 for (; pit != ped; ++pit) {
0234 if (!pit->empty()) {
0235 lp_sp_t::instance()[pit->back().lp_].insert(*it);
0236 }
0237 }
0238 }
0239 }
0240 }
0241 string s = nm.ns() + " : " + nm.name();
0242 DDLogicalPart lp(nm);
0243 os << f_.header(s);
0244 os << f_.h2("LogicalPart <b>" + s + "</b>");
0245 os << f_.br();
0246 if (lp.isDefined().second == false) {
0247 os << "<b>ERROR!<b><br><p>The LogicalPart is not defined in namespace " << nm.ns() << "! </p>" << endl;
0248 return false;
0249 }
0250
0251 string so_url = "../../so/" + lp.solid().ddname().ns() + "/" + lp.solid().ddname().name() + ".html";
0252 string ma_url = "../../ma/" + lp.material().ddname().ns() + "/" + lp.material().ddname().name() + ".html";
0253 string so_nm = lp.solid().ddname().ns() + ":" + lp.solid().ddname().name();
0254 string ma_nm = lp.material().ddname().ns() + ":" + lp.material().ddname().name();
0255 os << f_.table() << f_.tr() << f_.td("Category") << f_.td(DDEnums::categoryName(lp.category())) << f_.trEnd()
0256 << f_.tr() << f_.td("Solid") << f_.td(f_.lnk(so_url, so_nm, "_popup")) << f_.trEnd() << f_.tr()
0257 << f_.td("Material") << f_.td(f_.lnk(ma_url, ma_nm, "_popup")) << f_.trEnd();
0258 os << f_.tableEnd();
0259
0260 typedef map<DDLogicalPart, set<DDSpecifics> > lp_sp_type;
0261 const lp_sp_type& lp_sp = lp_sp_t::instance();
0262 lp_sp_type::const_iterator lpspit = lp_sp.find(lp);
0263 if (lpspit != lp_sp.end()) {
0264 os << f_.h3("assigned SpecPars (Specifics):");
0265 set<DDSpecifics>::const_iterator it(lpspit->second.begin()), ed(lpspit->second.end());
0266 os << "<p>" << endl;
0267 for (; it != ed; ++it) {
0268 os << f_.link("../../sp/" + it->ddname().ns() + "/" + it->ddname().name() + ".html",
0269 it->ddname().fullname(),
0270 "_popup")
0271 << " " << endl;
0272 }
0273 os << "</p>" << endl;
0274 }
0275
0276 os << f_.footer();
0277 return true;
0278 }
0279
0280
0281
0282 void dd_to_html(DDHtmlDetails& dtls) {
0283 cout << "---> dd_to_html() called with category=" << dtls.category() << endl;
0284 const string& category = dtls.category();
0285 const string& text = dtls.text();
0286 ns_type& names = dtls.names();
0287
0288 mkdir(category.c_str(), 0755);
0289
0290
0291 string ns_fname = category + "/ns.html";
0292 ofstream ns_file(ns_fname.c_str());
0293 DDNsGenerator ns_gen(ns_file, text, "_list", names, "");
0294 ns_gen.doit();
0295 ns_file.close();
0296
0297
0298 ns_type::const_iterator it(names.begin()), ed(names.end());
0299 for (; it != ed; ++it) {
0300 const string& ns = it->first;
0301
0302
0303 string dir = category + "/" + ns;
0304 mkdir(dir.c_str(), 0755);
0305
0306
0307 string fname = category + "/" + ns + "/list.html";
0308 ofstream list_file(fname.c_str());
0309 DDHtmlFormatter f;
0310 list_file << f.header(text) << f.p("Instances in Namespace <b>" + ns + "</b><br>");
0311 list_file << f.ul();
0312
0313 set<string>::const_iterator nit(it->second.begin()), ned(it->second.end());
0314 for (; nit != ned; ++nit) {
0315 const string& nm = *nit;
0316 string result_s = nm;
0317
0318
0319 string d_fname = category + "/" + ns + "/" + nm + ".html";
0320 ofstream detail_file(d_fname.c_str());
0321 DDName an(nm, ns);
0322 bool result = dtls.details(detail_file, an);
0323
0324 if (!result)
0325 result_s = ">> ERROR: " + nm + " <<";
0326 list_file << f.li(f.lnk(nm + ".html", result_s, "_details"));
0327 }
0328 list_file << f.ulEnd() << f.footer();
0329 }
0330 }
0331
0332
0333
0334
0335 void DDFrameGenerator::doit() {
0336 DDHtmlFormatter f;
0337 os_ << f.header(t_);
0338 os_ << "<frameset cols=\"25%,*\">" << endl;
0339 os_ << " <frameset rows=\"50%,*\">" << endl;
0340 os_ << " <frame src=\"" << u1_ << "\" name=\"" << n1_ << "\">" << endl;
0341 os_ << " <frame src=\"" << u2_ << "\" name=\"" << n2_ << "\">" << endl;
0342 os_ << " </frameset>" << endl;
0343 os_ << " <frame src=\"" << u3_ << "\" name=\"" << n3_ << "\">" << endl;
0344 os_ << "</frameset>" << endl;
0345 os_ << f.footer() << endl;
0346 }
0347
0348 void dd_html_frameset(ostream& os) {
0349 DDHtmlFormatter f;
0350 os << f.header("DDD Reports");
0351 os << "<frameset rows=\"50%,50%\"> " << endl
0352 << " <frameset cols=\"50%,50%\">" << endl
0353 << " <frame name=\"_ns\" src=\"ns.html\">" << endl
0354 << " <frame name=\"_list\">" << endl
0355 << " </frameset>" << endl
0356 << " <frameset cols=\"50%,50%\">" << endl
0357 << " <frame name=\"_details\">" << endl
0358 << " <frame name=\"_popup\">" << endl
0359 << " </frameset>" << endl
0360 << "</frameset>" << endl
0361 << endl;
0362 os << f.footer();
0363 }
0364
0365 void dd_html_menu_frameset(ostream& os) {
0366 DDHtmlFormatter f;
0367 os << f.header("DDD Web Representation");
0368 os << "<frameset cols=\"20%,80%\">" << endl
0369 << " <frame name=\"_menu\" src=\"menu.html\">" << endl
0370 << " <frame name=\"_selection\" >" << endl
0371 << "</frameset>" << endl;
0372
0373 os << f.footer();
0374 }
0375
0376 void dd_html_menu(ostream& os) {
0377 DDHtmlFormatter f;
0378 os << f.header("DDD Web Main Menu", "style.css");
0379 os << f.h1("Select a Category:") << f.p(f.lnk("lp/index.html", "LogicalParts", "_selection"))
0380 << f.p(f.lnk("ma/index.html", "Materials", "_selection")) << f.p(f.lnk("so/index.html", "Solids", "_selection"))
0381 << f.p(f.lnk("ro/index.html", "Rotations", "_selection")) << f.p(f.lnk("sp/index.html", "SpecPars", "_selection"));
0382
0383 os << f.footer();
0384 }