CMS 3D CMS Logo

DDHtmlFormatter.cc
Go to the documentation of this file.
4 #include "DetectorDescription/Core/interface/Singleton.icc"
21 
22 #include <fstream>
23 #include <map>
24 #include <memory>
25 #include <set>
26 #include <string>
27 #include <sys/stat.h>
28 #include <utility>
29 #include <vector>
30 
31 using namespace std;
32 using namespace geant_units::operators;
33 
34 ostream& operator<<(ostream& o, const DDHtmlFormatter& f) {
35  o << f.os_.str();
36  f.os_.str("");
37  return o;
38 }
39 
40 DDHtmlFormatter DDHtmlFormatter::header(const string& title, const string& style) {
41  pre();
42  os_ << "<html>\n<head>\n<title>" << title << "</title>" << endl;
43  os_ << "<link rel=\"stylesheet\" type=\"text/css\" href=\"" << style << "\">" << endl;
44  //os_ << "</head>\n<body>" << endl;
45  return *this;
46 }
47 
48 DDHtmlFormatter DDHtmlFormatter::link(const string& url, const string& txt, const string& target) {
49  pre();
50  os_ << lnk(url, txt, target) << endl;
51  return *this;
52 }
53 
54 string DDHtmlFormatter::lnk(const string& url, const string& txt, const string& target) {
55  string result;
56  result = string("<a href=\"") + url;
57  result += string("\" target=\"") + target;
58  result += string("\">") + txt + string("</a>");
59  return result;
60 }
61 
63  pre();
64  os_ << "</body></html>" << endl;
65  return *this;
66 }
67 
68 //=============================================================================================================
69 //=============================================================================================================
70 
73  os_ << f.header(title_, "../style.css");
74  os_ << f.h2(title_) << f.p(text_); // << endl;
75  ns_type::const_iterator it = n_.begin();
76  ns_type::const_iterator ed = n_.end();
77  os_ << f.ul();
78  for (; it != ed; ++it) {
79  os_ << f.li(f.lnk(it->first + "/list.html", it->first, target_));
80  }
81  os_ << f.ulEnd() << endl;
82  os_ << f.footer() << endl;
83 }
84 
85 DDHtmlDetails::DDHtmlDetails(const string& cat, const string& txt) : cat_(cat), txt_(txt) {}
86 
88  DDLogicalPart lp;
90  return names_;
91 }
92 
94  DDMaterial lp;
96  return names_;
97 }
98 
100  DDSolid lp;
101  findNameSpaces(lp, names_);
102  return names_;
103 }
104 
106  DDSpecifics lp;
107  findNameSpaces(lp, names_);
108  return names_;
109 }
110 
112  DDRotation lp;
113  findNameSpaces(lp, names_);
114  return names_;
115 }
116 
117 bool DDHtmlSoDetails::details(ostream& os, const DDName& nm) {
118  os << f_.header("Solid Details") << f_.h3(">> formatting under construction <<");
119  os << DDSolid(nm);
120  return true;
121 }
122 
123 bool DDHtmlSpDetails::details(ostream& os, const DDName& nm) {
124  os << f_.header("SpecPars Details") << f_.h3(">> formatting under construction <<");
125  os << DDSpecifics(nm);
126  return true;
127 }
128 
129 bool DDHtmlRoDetails::details(ostream& os, const DDName& nm) {
130  os << f_.header("Rotations Details");
131 
132  DDRotation ddr(nm);
133  if (ddr.isDefined().second == false) {
134  os << "<b>ERROR!</b><br><p>The Rotation " << nm << " is not defined!</p>" << endl;
135  return false;
136  }
137  DD3Vector x, y, z;
138  ddr.matrix().GetComponents(x, y, z);
139  os << f_.h2("Rotation: " + nm.fullname());
140  os << f_.h3("GEANT3 style:");
141  os << "<table border=\"0\">" << endl
142  << "<tr><td>thetaX =</td><td>" << convertRadToDeg(x.Theta()) << " deg</td><tr>" << endl
143  << "<tr><td>phiX =</td><td>" << convertRadToDeg(x.Phi()) << " deg</td><tr>" << endl
144  << "<tr><td>thetaY =</td><td>" << convertRadToDeg(y.Theta()) << " deg</td><tr>" << endl
145  << "<tr><td>phiY =</td><td>" << convertRadToDeg(y.Phi()) << " deg</td><tr>" << endl
146  << "<tr><td>thetaZ =</td><td>" << convertRadToDeg(z.Theta()) << " deg</td><tr>" << endl
147  << "<tr><td>phiZ =</td><td>" << convertRadToDeg(z.Phi()) << " deg</td><tr>" << endl
148  << "</table>";
149 
150  os << f_.h3("Rotation axis & angle (theta,phi,angle)") << endl;
151  os << DDRotation(nm);
152  return true;
153 }
154 
155 bool DDHtmlMaDetails::details(ostream& os, const DDName& nm) {
157  static bool once = false;
158  if (!once) {
159  once = true;
160  DDLogicalPart::iterator<DDLogicalPart> it, ed;
161  ed.end();
162 
163  for (; it != ed; ++it) {
164  if (it->isDefined().second)
165  parts_t::instance()[it->material()].insert(*it);
166  }
167  }
168 
169  string s = nm.ns() + " : " + nm.name();
170  DDMaterial ma(nm);
171  os << f_.header(s);
172  os << f_.h2("Material <b>" + s + "</b>");
173  os << f_.br();
174  if (ma.isDefined().second == false) {
175  os << "<b>ERROR!<b><br><p>The Material is not defined in namespace " << nm.ns() << "! </p>" << endl;
176  return false;
177  }
178 
179  os << "<p>density = " << convertUnitsTo(1._g_per_cm3, ma.density()) << " g/cm3 </p>" << endl;
180  int co = ma.noOfConstituents();
181  if (co) {
182  os << f_.p("Composites by fraction-mass:");
183  os << f_.table() << f_.tr() << f_.td("<b>fm</b>") << f_.td("<b>Material</b>") << f_.td("<b>elementary?</b>")
184  << f_.trEnd();
185  for (int i = 0; i < co; ++i) {
186  pair<DDMaterial, double> fm = ma.constituent(i);
187  string elem = "ERROR";
188  DDMaterial m = fm.first;
189  double frac = fm.second;
190 
191  if (m.isDefined().second) {
192  if (m.noOfConstituents())
193  elem = "no";
194  else
195  elem = "yes";
196  }
197  os << f_.tr() << "<td>" << frac << "</td>"
198  << f_.td(f_.lnk("../" + m.ddname().ns() + "/" + m.ddname().name() + ".html", m.ddname().fullname(), "_popup"))
199  << f_.td(elem) << f_.trEnd();
200  }
201  os << f_.tableEnd();
202  } else { // if ( co ) ...
203  os << f_.p("ElementaryMaterial:");
204  os << "<p>z = " << ma.z() << "</p>" << endl;
205  os << "<p>a = " << convertUnitsTo(1._g_per_mole, ma.a()) << "g/mole</p>" << endl;
206  }
207 
208  const set<DDLogicalPart>& lps = parts_t::instance()[ma];
209  set<DDLogicalPart>::const_iterator it(lps.begin()), ed(lps.end());
210  if (it != ed) {
211  os << f_.h3("Material used in following LogicalParts:") << endl;
212  os << "<p>" << endl;
213  }
214  for (; it != ed; ++it) {
215  const DDName& n = it->ddname();
216  os << f_.link("../../lp/" + n.ns() + "/" + n.name() + ".html", n.fullname(), "_popup");
217  }
218  os << "</p>" << endl;
219  return true;
220 }
221 
222 bool DDHtmlLpDetails::details(ostream& os, const DDName& nm) {
223  static bool once = false;
225  if (!once) {
226  once = true;
227  DDSpecifics::iterator<DDSpecifics> it, ed;
228  ed.end();
229  for (; it != ed; ++it) {
230  if (it->isDefined().second) {
231  const vector<DDPartSelection>& ps = it->selection();
232  vector<DDPartSelection>::const_iterator pit(ps.begin()), ped(ps.end());
233  for (; pit != ped; ++pit) {
234  if (!pit->empty()) {
235  lp_sp_t::instance()[pit->back().lp_].insert(*it);
236  }
237  }
238  }
239  }
240  }
241  string s = nm.ns() + " : " + nm.name();
242  DDLogicalPart lp(nm);
243  os << f_.header(s);
244  os << f_.h2("LogicalPart <b>" + s + "</b>");
245  os << f_.br();
246  if (lp.isDefined().second == false) {
247  os << "<b>ERROR!<b><br><p>The LogicalPart is not defined in namespace " << nm.ns() << "! </p>" << endl;
248  return false;
249  }
250 
251  string so_url = "../../so/" + lp.solid().ddname().ns() + "/" + lp.solid().ddname().name() + ".html";
252  string ma_url = "../../ma/" + lp.material().ddname().ns() + "/" + lp.material().ddname().name() + ".html";
253  string so_nm = lp.solid().ddname().ns() + ":" + lp.solid().ddname().name();
254  string ma_nm = lp.material().ddname().ns() + ":" + lp.material().ddname().name();
255  os << f_.table() << f_.tr() << f_.td("Category") << f_.td(DDEnums::categoryName(lp.category())) << f_.trEnd()
256  << f_.tr() << f_.td("Solid") << f_.td(f_.lnk(so_url, so_nm, "_popup")) << f_.trEnd() << f_.tr()
257  << f_.td("Material") << f_.td(f_.lnk(ma_url, ma_nm, "_popup")) << f_.trEnd();
258  os << f_.tableEnd();
259 
260  typedef map<DDLogicalPart, set<DDSpecifics> > lp_sp_type;
261  const lp_sp_type& lp_sp = lp_sp_t::instance();
262  lp_sp_type::const_iterator lpspit = lp_sp.find(lp);
263  if (lpspit != lp_sp.end()) {
264  os << f_.h3("assigned SpecPars (Specifics):");
265  set<DDSpecifics>::const_iterator it(lpspit->second.begin()), ed(lpspit->second.end());
266  os << "<p>" << endl;
267  for (; it != ed; ++it) {
268  os << f_.link("../../sp/" + it->ddname().ns() + "/" + it->ddname().name() + ".html",
269  it->ddname().fullname(),
270  "_popup")
271  << " " << endl;
272  }
273  os << "</p>" << endl;
274  }
275 
276  os << f_.footer();
277  return true;
278 }
279 
280 //=============================================================================================================
281 
283  cout << "---> dd_to_html() called with category=" << dtls.category() << endl;
284  const string& category = dtls.category();
285  const string& text = dtls.text();
286  ns_type& names = dtls.names();
287 
288  mkdir(category.c_str(), 0755);
289 
290  // first the namespaces
291  string ns_fname = category + "/ns.html";
292  ofstream ns_file(ns_fname.c_str());
293  DDNsGenerator ns_gen(ns_file, text, "_list", names, "");
294  ns_gen.doit();
295  ns_file.close();
296 
297  // list all logical parts per namespace
298  ns_type::const_iterator it(names.begin()), ed(names.end());
299  for (; it != ed; ++it) {
300  const string& ns = it->first;
301 
302  // create directories named like the namespaces
303  string dir = category + "/" + ns;
304  mkdir(dir.c_str(), 0755);
305 
306  // create a html file listing all instances of a namespace
307  string fname = category + "/" + ns + "/list.html";
308  ofstream list_file(fname.c_str());
310  list_file << f.header(text) << f.p("Instances in Namespace <b>" + ns + "</b><br>");
311  list_file << f.ul();
312  // loop over all instances of a single namespace
313  set<string>::const_iterator nit(it->second.begin()), ned(it->second.end());
314  for (; nit != ned; ++nit) {
315  const string& nm = *nit;
316  string result_s = nm;
317 
318  // details for each instance
319  string d_fname = category + "/" + ns + "/" + nm + ".html";
320  ofstream detail_file(d_fname.c_str());
321  DDName an(nm, ns);
322  bool result = dtls.details(detail_file, an);
323 
324  if (!result)
325  result_s = ">> ERROR: " + nm + " <<";
326  list_file << f.li(f.lnk(nm + ".html", result_s, "_details"));
327  }
328  list_file << f.ulEnd() << f.footer();
329  }
330 }
331 
332 //=============================================================================================================
333 //=============================================================================================================
334 
337  os_ << f.header(t_);
338  os_ << "<frameset cols=\"25%,*\">" << endl;
339  os_ << " <frameset rows=\"50%,*\">" << endl;
340  os_ << " <frame src=\"" << u1_ << "\" name=\"" << n1_ << "\">" << endl;
341  os_ << " <frame src=\"" << u2_ << "\" name=\"" << n2_ << "\">" << endl;
342  os_ << " </frameset>" << endl;
343  os_ << " <frame src=\"" << u3_ << "\" name=\"" << n3_ << "\">" << endl;
344  os_ << "</frameset>" << endl;
345  os_ << f.footer() << endl;
346 }
347 
348 void dd_html_frameset(ostream& os) {
350  os << f.header("DDD Reports");
351  os << "<frameset rows=\"50%,50%\"> " << endl
352  << " <frameset cols=\"50%,50%\">" << endl
353  << " <frame name=\"_ns\" src=\"ns.html\">" << endl
354  << " <frame name=\"_list\">" << endl
355  << " </frameset>" << endl
356  << " <frameset cols=\"50%,50%\">" << endl
357  << " <frame name=\"_details\">" << endl
358  << " <frame name=\"_popup\">" << endl
359  << " </frameset>" << endl
360  << "</frameset>" << endl
361  << endl;
362  os << f.footer();
363 }
364 
365 void dd_html_menu_frameset(ostream& os) {
367  os << f.header("DDD Web Representation");
368  os << "<frameset cols=\"20%,80%\">" << endl
369  << " <frame name=\"_menu\" src=\"menu.html\">" << endl
370  << " <frame name=\"_selection\" >" << endl
371  << "</frameset>" << endl;
372 
373  os << f.footer();
374 }
375 
376 void dd_html_menu(ostream& os) {
378  os << f.header("DDD Web Main Menu", "style.css");
379  os << f.h1("Select a Category:") << f.p(f.lnk("lp/index.html", "LogicalParts", "_selection"))
380  << f.p(f.lnk("ma/index.html", "Materials", "_selection")) << f.p(f.lnk("so/index.html", "Solids", "_selection"))
381  << f.p(f.lnk("ro/index.html", "Rotations", "_selection")) << f.p(f.lnk("sp/index.html", "SpecPars", "_selection"));
382 
383  os << f.footer();
384 }
bool details(std::ostream &os, const DDName &) override
void dd_html_menu_frameset(ostream &os)
ns_type & names() override
static PFTauRenderPlugin instance
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
bool details(std::ostream &os, const DDName &) override
virtual bool details(std::ostream &os, const DDName &)=0
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
DDHtmlFormatter br()
DDHtmlFormatter h3(const std::string &content)
bool details(std::ostream &os, const DDName &) override
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
__host__ __device__ VT * co
Definition: prefixScan.h:47
void dd_to_html(DDHtmlDetails &dtls)
bool details(std::ostream &os, const DDName &) override
const std::string names[nVars_]
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
constexpr NumType convertUnitsTo(double desiredUnits, NumType val)
Definition: GeantUnits.h:73
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
DDHtmlFormatter td(const std::string &content)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
DDHtmlFormatter f_
def cat(path)
Definition: eostools.py:401
DDHtmlFormatter p(const std::string &content)
const std::string & name() const
Returns the name.
Definition: DDName.cc:41
Definition: style.py:1
DDHtmlFormatter h2(const std::string &content)
void dd_html_menu(ostream &os)
std::map< std::string, std::set< std::string > > ns_type
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
DDEnums::Category category(void) const
Returns the categorization of the DDLogicalPart (sensitive detector element, cable, ...)
std::ostream & os_
double f[11][100]
bool details(std::ostream &os, const DDName &) override
virtual ns_type & names()=0
DDHtmlFormatter table(int border=0)
std::ostream & operator<<(std::ostream &out, const std::tuple< Types... > &value)
Definition: Utilities.h:32
double density() const
returns the density
Definition: DDMaterial.cc:80
ns_type & names() override
const DDMaterial & material(void) const
Returns a reference object of the material this LogicalPart is made of.
DDHtmlFormatter tableEnd()
double z() const
retruns the atomic number
Definition: DDMaterial.cc:78
FractionV::value_type constituent(int i) const
returns the i-th compound material and its fraction-mass
Definition: DDMaterial.cc:74
DDHtmlDetails(const std::string &cat, const std::string &txt)
const N & ddname() const
Definition: DDBase.h:61
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
Definition: DDMaterial.cc:72
const std::string fullname() const
Definition: DDName.h:43
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
ns_type & names() override
const std::string & text()
string fname
main script
def mkdir(path)
Definition: eostools.py:251
bool findNameSpaces(T dummy, ns_type &m)
DDHtmlFormatter tr()
DDHtmlFormatter header(const std::string &text, const std::string &style="../../style.css")
const std::string & category()
std::string lnk(const std::string &url, const std::string &text, const std::string &target="_self")
double a() const
returns the atomic mass
Definition: DDMaterial.cc:76
DDHtmlFormatter trEnd()
ns_type & names() override
def_type isDefined() const
Definition: DDBase.h:90
DDHtmlFormatter link(const std::string &url, const std::string &text, const std::string &target="_self")
DDHtmlFormatter footer()
static const char *const categoryName(Category s)
Definition: DDEnums.h:26
Interface to attach user specific data to nodes in the expanded-view.
Definition: DDSpecifics.h:41
ns_type & names() override
DDRotationMatrix & matrix()
Definition: DDTransform.h:85
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:52
void dd_html_frameset(ostream &os)