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