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