CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDHtmlFormatter.cc
Go to the documentation of this file.
1 namespace std { } using namespace std;
2 #include <sys/stat.h>
3 #include <sys/types.h>
4 #include <fstream>
5 #include "CLHEP/Units/GlobalSystemOfUnits.h"
7 
11 
12 //***** to get the typedef below to work properly...
13 //**** to get rid of compile errors about ambiguous delete of Stores
18 //***** Explicit template instantiation of Singleton
19 #include "DetectorDescription/Base/interface/Singleton.icc"
20 //*****
21 
22 ostream & operator<<(ostream & o, const DDHtmlFormatter & f)
23 {
24  o << f.os_.str(); f.os_.str("");
25  return o;
26 }
27 
28 DDHtmlFormatter DDHtmlFormatter::header(const string & title, const string & style)
29 {
30  pre();
31  os_ << "<html>\n<head>\n<title>" << title << "</title>" << endl;
32  os_ << "<link rel=\"stylesheet\" type=\"text/css\" href=\"" << style << "\">" << endl;
33  //os_ << "</head>\n<body>" << endl;
34  return *this;
35 }
36 
37 DDHtmlFormatter DDHtmlFormatter::link(const string & url, const string & txt, const string & target)
38 {
39  pre();
40  os_ << lnk(url,txt,target) << endl;
41  return *this;
42 }
43 
44 string DDHtmlFormatter::lnk(const string & url, const string & txt, const string & target)
45 {
46  string result;
47  result = string("<a href=\"") + url;
48  result += string("\" target=\"") + target;
49  result += string("\">")+ txt + string("</a>");
50  return result;
51 }
52 
54 {
55  pre();
56  os_ << "</body></html>" << endl;
57  return *this;
58 }
59 
60 
61 //=============================================================================================================
62 //=============================================================================================================
63 
64 
66 {
68  os_ << f.header(title_,"../style.css");
69  os_ << f.h2(title_) << f.p(text_);// << endl;
70  ns_type::const_iterator it = n_.begin();
71  ns_type::const_iterator ed = n_.end();
72  os_ << f.ul();
73  for (; it != ed; ++it) {
74  os_ << f.li(f.lnk(it->first + "/list.html" , it->first, target_));
75  }
76  os_ << f.ulEnd() << endl;
77  os_ << f.footer() << endl;
78 }
79 
80 //=============================================================================================================
81 
82 DDHtmlDetails::DDHtmlDetails(const string & cat, const string & txt) : cat_(cat), txt_(txt) { }
83 
85 {
86  DDLogicalPart lp;
88  return names_;
89 }
90 
92 {
93  DDMaterial lp;
95  return names_;
96 }
97 
99 {
100  DDSolid lp;
101  findNameSpaces(lp, names_);
102  return names_;
103 }
104 
106 {
107  DDSpecifics lp;
108  findNameSpaces(lp, names_);
109  return names_;
110 }
111 
113 {
114  DDRotation lp;
115  findNameSpaces(lp, names_);
116  return names_;
117 }
118 
119 
120 bool DDHtmlSoDetails::details(ostream & os, const DDName & nm)
121 {
122  os << f_.header("Solid Details")
123  << f_.h3(">> formatting under construction <<");
124  os << DDSolid(nm); return true;
125 }
126 
127 bool DDHtmlSpDetails::details(ostream & os, const DDName & nm)
128 {
129  os << f_.header("SpecPars Details")
130  << f_.h3(">> formatting under construction <<");
131  os << DDSpecifics(nm); return true;
132 }
133 
134 bool DDHtmlRoDetails::details(ostream & os, const DDName & nm)
135 {
136  os << f_.header("Rotations Details");
137 
138  DDRotation ddr(nm);
139  if ( ddr.isDefined().second == false ) {
140  os << "<b>ERROR!</b><br><p>The Rotation " << nm << " is not defined!</p>" << endl;
141  return false;
142  }
143  DD3Vector x, y, z;
144  ddr.matrix()->GetComponents(x, y, z);
145  os << f_.h2("Rotation: " + nm.fullname());
146  os << f_.h3("GEANT3 style:");
147  os << "<table border=\"0\">" << endl
148  << "<tr><td>thetaX =</td><td>" << x.Theta()/deg << " deg</td><tr>" << endl
149  << "<tr><td>phiX =</td><td>" << x.Phi()/deg << " deg</td><tr>" << endl
150  << "<tr><td>thetaY =</td><td>" << y.Theta()/deg << " deg</td><tr>" << endl
151  << "<tr><td>phiY =</td><td>" << y.Phi()/deg << " deg</td><tr>" << endl
152  << "<tr><td>thetaZ =</td><td>" << z.Theta()/deg << " deg</td><tr>" << endl
153  << "<tr><td>phiZ =</td><td>" << z.Phi()/deg << " deg</td><tr>" << endl
154  << "</table>";
155 
156  os << f_.h3("Rotation axis & angle (theta,phi,angle)") << endl;
157  os << DDRotation(nm); return true;
158 }
159 
160 bool DDHtmlMaDetails::details(ostream & os, const DDName & nm)
161 {
163  static bool once = false;
164  if (!once) {
165  once=true;
166  DDLogicalPart::iterator<DDLogicalPart> it, ed;
167  ed.end();
168 
169  for (; it != ed; ++it) {
170  if (it->isDefined().second)
171  parts_t::instance()[it->material()].insert(*it);
172  }
173  }
174 
175  string s = nm.ns() + " : " + nm.name();
176  DDMaterial ma(nm);
177  os << f_.header(s);
178  os << f_.h2("Material <b>" + s + "</b>");
179  os << f_.br();
180  if ( ma.isDefined().second == false ) {
181  os << "<b>ERROR!<b><br><p>The Material is not defined in namespace " << nm.ns() << "! </p>" << endl;
182  return false;
183  }
184 
185  os << "<p>density = " << ma.density()/g*cm3 << " g/cm3 </p>" << endl;
186  int co = ma.noOfConstituents();
187  if ( co ) {
188  os << f_.p("Composites by fraction-mass:");
189  os << f_.table()
190  << f_.tr() << f_.td("<b>fm</b>") << f_.td("<b>Material</b>") << f_.td("<b>elementary?</b>") << f_.trEnd();
191  for(int i=0; i<co; ++i) {
192  pair<DDMaterial,double> fm = ma.constituent(i);
193  string elem = "ERROR";
194  DDMaterial m = fm.first;
195  double frac = fm.second;
196 
197  if (m.isDefined().second) {
198  if (m.noOfConstituents())
199  elem = "no";
200  else
201  elem = "yes";
202  }
203  os << f_.tr() << "<td>" << frac << "</td>"
204  << f_.td(f_.lnk("../" + m.ddname().ns() + "/" + m.ddname().name() + ".html", m.ddname().fullname(), "_popup"))
205  << f_.td(elem) << f_.trEnd();
206  }
207  os << f_.tableEnd();
208  }
209  else { // if ( co ) ...
210  os << f_.p("ElementaryMaterial:");
211  os << "<p>z = " << ma.z() << "</p>" << endl;
212  os << "<p>a = " << ma.a()/g*mole << "g/mole</p>" << endl;
213  }
214 
215 
216  const set<DDLogicalPart> & lps = parts_t::instance()[ma];
217  set<DDLogicalPart>::const_iterator it(lps.begin()), ed(lps.end());
218  if ( it != ed ) {
219  os << f_.h3("Material used in following LogicalParts:") << endl;
220  os << "<p>" << endl;
221  }
222  for (; it != ed; ++it ) {
223  const DDName & n = it->ddname();
224  os << f_.link("../../lp/" + n.ns() + "/" + n.name() + ".html", n.fullname(), "_popup" );
225  }
226  os << "</p>" << endl;
227  return true;
228 }
229 
230 bool DDHtmlLpDetails::details(ostream & os, const DDName & nm)
231 {
232  static bool once = false;
234  if ( !once ) {
235  once = true;
236  DDSpecifics::iterator<DDSpecifics> it, ed;
237  ed.end();
238  for (; it != ed; ++it ) {
239  if (it->isDefined().second) {
240  const vector<DDPartSelection> & ps = it->selection();
241  vector<DDPartSelection>::const_iterator pit(ps.begin()), ped(ps.end());
242  for (; pit != ped; ++pit) {
243  if (pit->size()) {
244  lp_sp_t::instance()[pit->back().lp_].insert(*it);
245  }
246  }
247  }
248  }
249  }
250  string s = nm.ns() + " : " + nm.name();
251  DDLogicalPart lp(nm);
252  os << f_.header(s);
253  os << f_.h2("LogicalPart <b>" + s + "</b>");
254  os << f_.br();
255  if ( lp.isDefined().second == false ) {
256  os << "<b>ERROR!<b><br><p>The LogicalPart is not defined in namespace " << nm.ns() << "! </p>" << endl;
257  return false;
258  }
259 
260  string so_url = "../../so/" + lp.solid().ddname().ns() + "/" + lp.solid().ddname().name() + ".html";
261  string ma_url = "../../ma/" + lp.material().ddname().ns() + "/" + lp.material().ddname().name() + ".html";
262  string so_nm = lp.solid().ddname().ns() + ":" + lp.solid().ddname().name();
263  string ma_nm = lp.material().ddname().ns() + ":" + lp.material().ddname().name();
264  os << f_.table()
265  << f_.tr() << f_.td("Category") << f_.td( DDEnums::categoryName(lp.category()) ) << f_.trEnd()
266  << f_.tr() << f_.td("Solid") << f_.td( f_.lnk(so_url, so_nm, "_popup" )) << f_.trEnd()
267  << f_.tr() << f_.td("Material") << f_.td(f_.lnk(ma_url, ma_nm, "_popup")) << f_.trEnd();
268  os << f_.tableEnd();
269 
270  typedef map<DDLogicalPart, set<DDSpecifics> > lp_sp_type;
271  const lp_sp_type & lp_sp = lp_sp_t::instance();
272  lp_sp_type::const_iterator lpspit = lp_sp.find(lp);
273  if (lpspit != lp_sp.end()) {
274  os << f_.h3("assigned SpecPars (Specifics):");
275  set<DDSpecifics>::const_iterator it(lpspit->second.begin()), ed(lpspit->second.end());
276  os << "<p>" << endl;
277  for (; it != ed; ++it) {
278  os << f_.link("../../sp/" + it->ddname().ns() + "/" + it->ddname().name() + ".html", it->ddname().fullname(), "_popup")
279  << " " << endl;
280  }
281  os << "</p>" << endl;
282  }
283 
284  os << f_.footer();
285  return true;
286 }
287 
288 //=============================================================================================================
289 
291 {
292  cout << "---> dd_to_html() called with category=" << dtls.category() << endl;
293  const string & category = dtls.category();
294  const string & text = dtls.text();
295  ns_type & names = dtls.names();
296 
297  mkdir( category.c_str(), 0755 );
298 
299  // first the namespaces
300  string ns_fname = category + "/ns.html";
301  ofstream ns_file(ns_fname.c_str());
302  DDNsGenerator ns_gen(ns_file, text, "_list", names, "");
303  ns_gen.doit();
304  ns_file.close();
305 
306  // list all logical parts per namespace
307  ns_type::const_iterator it(names.begin()), ed(names.end());
308  for( ; it != ed; ++it ) {
309 
310  const string & ns = it->first;
311 
312  // create directories named like the namespaces
313  string dir = category + "/" + ns;
314  mkdir( dir.c_str(), 0755 );
315 
316  // create a html file listing all instances of a namespace
317  string fname = category + "/" + ns + "/list.html";
318  ofstream list_file(fname.c_str());
320  list_file << f.header(text)
321  << f.p("Instances in Namespace <b>" + ns + "</b><br>");
322  list_file << f.ul();
323  // loop over all instances of a single namespace
324  set<string>::const_iterator nit(it->second.begin()), ned(it->second.end());
325  for(; nit != ned; ++nit) {
326 
327  const string & nm = *nit;
328  string result_s = nm;
329 
330  // details for each instance
331  string d_fname = category + "/" + ns + "/" + nm + ".html";
332  ofstream detail_file(d_fname.c_str());
333  DDName an(nm,ns);
334  bool result = dtls.details(detail_file, an);
335 
336  if (!result) result_s = ">> ERROR: " + nm + " <<";
337  list_file << f.li(f.lnk(nm+".html", result_s, "_details"));
338 
339  }
340  list_file << f.ulEnd() << f.footer();
341  }
342 }
343 
344 //=============================================================================================================
345 //=============================================================================================================
346 
347 
349 {
351  os_ << f.header(t_);
352  os_ << "<frameset cols=\"25%,*\">" << endl;
353  os_ << " <frameset rows=\"50%,*\">" << endl;
354  os_ << " <frame src=\"" << u1_ << "\" name=\"" << n1_ << "\">" << endl;
355  os_ << " <frame src=\"" << u2_ << "\" name=\"" << n2_ << "\">" << endl;
356  os_ << " </frameset>" << endl;
357  os_ << " <frame src=\"" << u3_ << "\" name=\"" << n3_ << "\">" << endl;
358  os_ << "</frameset>" << endl;
359  os_ << f.footer() << endl;
360 }
361 
362 void dd_html_frameset(ostream & os)
363 {
365  os << f.header("DDD Reports");
366  os << "<frameset rows=\"50%,50%\"> " << endl
367  << " <frameset cols=\"50%,50%\">" << endl
368  << " <frame name=\"_ns\" src=\"ns.html\">" << endl
369  << " <frame name=\"_list\">" << endl
370  << " </frameset>" << endl
371  << " <frameset cols=\"50%,50%\">" << endl
372  << " <frame name=\"_details\">" << endl
373  << " <frame name=\"_popup\">" << endl
374  << " </frameset>" << endl
375  << "</frameset>" << endl
376  << endl;
377  os << f.footer();
378 
379 }
380 
381 void dd_html_menu_frameset(ostream & os)
382 {
384  os << f.header("DDD Web Representation");
385  os << "<frameset cols=\"20%,80%\">" << endl
386  << " <frame name=\"_menu\" src=\"menu.html\">" << endl
387  << " <frame name=\"_selection\" >" << endl
388  << "</frameset>" << endl;
389 
390  os << f.footer();
391 }
392 
393 
394 void dd_html_menu(ostream & os)
395 {
397  os << f.header("DDD Web Main Menu","style.css");
398  os << f.h1("Select a Category:")
399  << f.p(f.lnk("lp/index.html", "LogicalParts", "_selection"))
400  << f.p(f.lnk("ma/index.html", "Materials", "_selection"))
401  << f.p(f.lnk("so/index.html", "Solids", "_selection"))
402  << f.p(f.lnk("ro/index.html", "Rotations", "_selection"))
403  << f.p(f.lnk("sp/index.html", "SpecPars", "_selection"))
404  ;
405 
406  os << f.footer();
407 }
408 
409 
410 
double a() const
returns the atomic mass
Definition: DDMaterial.cc:97
bool details(std::ostream &os, const DDName &)
int i
Definition: DBlmapReader.cc:9
def_type isDefined() const
Definition: DDBase.h:115
void dd_html_frameset(std::ostream &os)
DDHtmlFormatter li(const std::string &content)
static const HistoName names[]
bool details(std::ostream &os, const DDName &)
static PFTauRenderPlugin instance
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
DDEnums::Category category(void) const
Returns the categorization of the DDLogicalPart (sensitive detector element, cable, ...)
virtual bool details(std::ostream &os, const DDName &)=0
DDHtmlFormatter br()
DDHtmlFormatter h3(const std::string &content)
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:101
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:18
ostream & operator<<(std::ostream &o, vector< std::string > const &iValue)
Definition: refresh.cc:46
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
float float float z
A DDSolid represents the shape of a part.
Definition: DDSolid.h:35
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:66
bool details(std::ostream &os, const DDName &)
DDHtmlFormatter h1(const std::string &content)
DDHtmlFormatter td(const std::string &content)
double z() const
retruns the atomic number
Definition: DDMaterial.cc:103
DDHtmlFormatter f_
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
void dd_html_menu(std::ostream &os)
DDHtmlFormatter h2(const std::string &content)
tuple result
Definition: query.py:137
const std::string fullname() const
Definition: DDName.h:56
FractionV::value_type constituent(int i) const
returns the i-th compound material and its fraction-mass
Definition: DDMaterial.cc:89
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:88
std::ostream & os_
double f[11][100]
tuple text
Definition: runonSM.py:42
bool details(std::ostream &os, const DDName &)
virtual ns_type & names()=0
DDHtmlFormatter ulEnd()
DDHtmlFormatter table(int border=0)
void dd_to_html(DDHtmlDetails &det)
ns_type & names()
DDHtmlFormatter tableEnd()
DDHtmlDetails(const std::string &cat, const std::string &txt)
double density() const
returns the density
Definition: DDMaterial.cc:109
void dd_html_menu_frameset(std::ostream &os)
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
Definition: DDMaterial.cc:83
const std::string & text()
string fname
main script
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()
bool details(std::ostream &os, const DDName &)
tuple cout
Definition: gather_cfg.py:121
ns_type & names()
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()
volatile std::atomic< bool > shutdown_flag false
Definition: DDAxes.h:10
std::stringstream os_
DDRotationMatrix * matrix()
Definition: DDTransform.h:94
DDHtmlFormatter ul()
ns_type & names()
DDHtmlFormatter link(const std::string &url, const std::string &text, const std::string &target="_self")
DDHtmlFormatter footer()
std::map< std::string, std::set< std::string > > ns_type
static const char *const categoryName(Category s)
Definition: DDEnums.h:17
const std::string & name() const
Returns the name.
Definition: DDName.cc:87
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:40
const N & ddname() const
Definition: DDBase.h:84