CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/DetectorDescription/RegressionTest/src/DDHtmlFormatter.cc

Go to the documentation of this file.
00001 namespace std { } using namespace std;
00002 #include <sys/stat.h>
00003 #include <sys/types.h>
00004 #include <fstream>
00005 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00006 #include "DetectorDescription/RegressionTest/interface/DDHtmlFormatter.h"
00007 
00008 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00009 #include "DetectorDescription/Core/interface/DDSpecifics.h"
00010 #include "DetectorDescription/Core/interface/DDPartSelection.h"
00011 
00012 //***** to get the typedef below to work properly...
00013 //**** to get rid of compile errors about ambiguous delete of Stores
00014 #include "DetectorDescription/Core/src/LogicalPart.h"
00015 #include "DetectorDescription/Core/src/Material.h"
00016 #include "DetectorDescription/Core/src/Specific.h"
00017 #include "DetectorDescription/Core/src/Solid.h"
00018 //***** Explicit template instantiation of Singleton
00019 #include "DetectorDescription/Base/interface/Singleton.icc"
00020 //*****
00021 
00022 ostream & operator<<(ostream & o, const DDHtmlFormatter & f)
00023 {
00024   o << f.os_.str(); f.os_.str("");
00025   return o;
00026 }
00027 
00028 DDHtmlFormatter DDHtmlFormatter::header(const string & title, const string & style)
00029 {
00030   pre();
00031   os_ << "<html>\n<head>\n<title>" << title << "</title>" << endl;
00032   os_ << "<link rel=\"stylesheet\" type=\"text/css\" href=\"" << style << "\">" << endl;
00033   //os_ << "</head>\n<body>" << endl;
00034   return *this;
00035 }
00036 
00037 DDHtmlFormatter DDHtmlFormatter::link(const string & url, const string & txt, const string & target)
00038 {
00039   pre();
00040   os_ << lnk(url,txt,target) << endl;
00041   return *this;
00042 }
00043 
00044 string DDHtmlFormatter::lnk(const string & url, const string & txt, const string & target)
00045 {
00046    string result;
00047    result = string("<a href=\"") + url;
00048    result += string("\" target=\"") + target;
00049    result += string("\">")+ txt + string("</a>");
00050    return result; 
00051 }
00052 
00053 DDHtmlFormatter DDHtmlFormatter::footer()
00054 {
00055   pre();
00056   os_ << "</body></html>" << endl;
00057   return *this;
00058 }
00059 
00060 
00061 //=============================================================================================================
00062 //=============================================================================================================
00063 
00064 
00065 void DDNsGenerator::doit()
00066 {  
00067   DDHtmlFormatter f;
00068   os_ << f.header(title_,"../style.css");
00069   os_ << f.h2(title_) << f.p(text_);// << endl;
00070   ns_type::const_iterator it = n_.begin(); 
00071   ns_type::const_iterator ed = n_.end(); 
00072   os_ << f.ul();
00073   for (; it != ed; ++it) {
00074     os_ << f.li(f.lnk(it->first + "/list.html"  , it->first, target_));
00075   }
00076   os_ << f.ulEnd() << endl;
00077   os_ << f.footer() << endl;
00078 } 
00079 
00080 //=============================================================================================================
00081 
00082 DDHtmlDetails::DDHtmlDetails(const string & cat, const string & txt) : cat_(cat), txt_(txt) { }
00083 
00084 ns_type & DDHtmlLpDetails::names() 
00085 {
00086    DDLogicalPart lp;
00087    findNameSpaces(lp, names_);
00088    return names_;
00089 }
00090 
00091 ns_type & DDHtmlMaDetails::names() 
00092 {
00093    DDMaterial lp;
00094    findNameSpaces(lp, names_);
00095    return names_;
00096 }
00097 
00098 ns_type & DDHtmlSoDetails::names() 
00099 {
00100    DDSolid lp;
00101    findNameSpaces(lp, names_);
00102    return names_;
00103 }
00104 
00105 ns_type & DDHtmlSpDetails::names() 
00106 {
00107    DDSpecifics lp;
00108    findNameSpaces(lp, names_);
00109    return names_;
00110 }
00111 
00112 ns_type & DDHtmlRoDetails::names() 
00113 {
00114    DDRotation lp;
00115    findNameSpaces(lp, names_);
00116    return names_;
00117 }
00118 
00119 
00120 bool DDHtmlSoDetails::details(ostream & os, const DDName & nm) 
00121 {
00122   os << f_.header("Solid Details")
00123      << f_.h3(">> formatting under construction <<"); 
00124   os << DDSolid(nm); return true; 
00125 }
00126 
00127 bool DDHtmlSpDetails::details(ostream & os, const DDName & nm) 
00128 {
00129   os << f_.header("SpecPars Details")
00130      << f_.h3(">> formatting under construction <<"); 
00131     os << DDSpecifics(nm); return true; 
00132 }
00133 
00134 bool DDHtmlRoDetails::details(ostream & os, const DDName & nm) 
00135 { 
00136   os << f_.header("Rotations Details");
00137 
00138   DDRotation ddr(nm);
00139   if ( ddr.isDefined().second == false ) {
00140     os << "<b>ERROR!</b><br><p>The Rotation " << nm << " is not defined!</p>" << endl;
00141     return false;
00142   }
00143   DD3Vector x, y, z;
00144   ddr.matrix()->GetComponents(x, y, z);
00145   os << f_.h2("Rotation: " + nm.fullname());
00146   os << f_.h3("GEANT3 style:"); 
00147   os << "<table border=\"0\">" << endl
00148      << "<tr><td>thetaX =</td><td>" << x.Theta()/deg << " deg</td><tr>" << endl
00149      << "<tr><td>phiX =</td><td>" << x.Phi()/deg << " deg</td><tr>" << endl
00150      << "<tr><td>thetaY =</td><td>" << y.Theta()/deg << " deg</td><tr>" << endl
00151      << "<tr><td>phiY =</td><td>" << y.Phi()/deg << " deg</td><tr>" << endl     
00152      << "<tr><td>thetaZ =</td><td>" << z.Theta()/deg << " deg</td><tr>" << endl
00153      << "<tr><td>phiZ =</td><td>" << z.Phi()/deg << " deg</td><tr>" << endl     
00154      << "</table>";
00155      
00156   os << f_.h3("Rotation axis & angle (theta,phi,angle)") << endl;   
00157   os << DDRotation(nm); return true; 
00158 }
00159 
00160 bool DDHtmlMaDetails::details(ostream & os, const DDName & nm)
00161 {
00162   typedef DDI::Singleton<map<DDMaterial, set<DDLogicalPart> > > parts_t;
00163   static bool once = false;
00164   if (!once) {
00165     once=true;
00166     DDLogicalPart::iterator<DDLogicalPart> it, ed;
00167     ed.end();
00168     
00169     for (; it != ed; ++it) {
00170       if (it->isDefined().second)
00171         parts_t::instance()[it->material()].insert(*it);
00172     }
00173   }
00174   
00175   string s = nm.ns() + " : " + nm.name();
00176   DDMaterial ma(nm);
00177   os << f_.header(s);
00178   os << f_.h2("Material <b>" + s + "</b>");
00179   os << f_.br();
00180   if ( ma.isDefined().second == false ) {
00181     os << "<b>ERROR!<b><br><p>The Material is not defined in namespace " << nm.ns() << "! </p>" << endl;
00182     return false;
00183   }
00184   
00185   os << "<p>density = " << ma.density()/g*cm3 << " g/cm3 </p>" << endl;
00186   int co = ma.noOfConstituents();
00187   if ( co ) {
00188     os << f_.p("Composites by fraction-mass:");
00189     os << f_.table() 
00190        << f_.tr() << f_.td("<b>fm</b>") << f_.td("<b>Material</b>") << f_.td("<b>elementary?</b>") << f_.trEnd();
00191     for(int i=0; i<co; ++i) {
00192       pair<DDMaterial,double> fm = ma.constituent(i);
00193       string elem = "ERROR";
00194       DDMaterial m = fm.first;
00195       double frac = fm.second;
00196 
00197       if (m.isDefined().second) {
00198         if (m.noOfConstituents()) 
00199             elem = "no";
00200          else
00201             elem = "yes";
00202       }
00203       os << f_.tr() << "<td>" << frac << "</td>" 
00204          << f_.td(f_.lnk("../" + m.ddname().ns() + "/" + m.ddname().name() + ".html", m.ddname().fullname(), "_popup"))
00205           << f_.td(elem) << f_.trEnd();
00206     }
00207     os << f_.tableEnd();
00208   }
00209   else { // if ( co ) ...
00210     os << f_.p("ElementaryMaterial:");
00211     os << "<p>z = " << ma.z() << "</p>" << endl;
00212     os << "<p>a = " << ma.a()/g*mole << "g/mole</p>" << endl;
00213   }
00214   
00215    
00216   const set<DDLogicalPart> & lps = parts_t::instance()[ma];
00217   set<DDLogicalPart>::const_iterator it(lps.begin()), ed(lps.end());
00218   if ( it != ed ) {
00219     os << f_.h3("Material used in following LogicalParts:") << endl;
00220     os << "<p>" << endl;
00221   }
00222   for (; it != ed; ++it ) {
00223     const DDName & n = it->ddname();
00224     os << f_.link("../../lp/" + n.ns() + "/" + n.name() + ".html", n.fullname(), "_popup" );
00225   }
00226   os << "</p>" << endl;
00227   return true;
00228 }
00229 
00230 bool DDHtmlLpDetails::details(ostream & os, const DDName & nm) 
00231 {
00232   static bool once = false;
00233   typedef DDI::Singleton< map<DDLogicalPart, set<DDSpecifics> > > lp_sp_t;
00234   if ( !once ) {
00235     once = true;
00236     DDSpecifics::iterator<DDSpecifics> it, ed;
00237     ed.end();
00238     for (; it != ed; ++it ) {
00239       if (it->isDefined().second) {
00240         const vector<DDPartSelection> & ps = it->selection();
00241          vector<DDPartSelection>::const_iterator pit(ps.begin()), ped(ps.end());
00242          for (; pit != ped; ++pit) {
00243            if (pit->size()) {
00244              lp_sp_t::instance()[pit->back().lp_].insert(*it);
00245            }
00246          }
00247       }
00248     }
00249   }
00250   string s = nm.ns() + " : " + nm.name();
00251   DDLogicalPart lp(nm);
00252   os << f_.header(s);
00253   os << f_.h2("LogicalPart <b>" + s + "</b>");
00254   os << f_.br();
00255   if ( lp.isDefined().second == false ) {
00256     os << "<b>ERROR!<b><br><p>The LogicalPart is not defined in namespace " << nm.ns() << "! </p>" << endl;
00257     return false;
00258   }
00259   
00260   string so_url = "../../so/" + lp.solid().ddname().ns() + "/" + lp.solid().ddname().name() + ".html";
00261   string ma_url = "../../ma/" + lp.material().ddname().ns() + "/" + lp.material().ddname().name() + ".html";
00262   string so_nm = lp.solid().ddname().ns() + ":" + lp.solid().ddname().name();
00263   string ma_nm = lp.material().ddname().ns() + ":" + lp.material().ddname().name();
00264   os << f_.table() 
00265      << f_.tr() << f_.td("Category") << f_.td( DDEnums::categoryName(lp.category()) ) << f_.trEnd()
00266      << f_.tr() << f_.td("Solid") << f_.td( f_.lnk(so_url, so_nm, "_popup" )) << f_.trEnd()
00267      << f_.tr() << f_.td("Material") << f_.td(f_.lnk(ma_url, ma_nm, "_popup")) << f_.trEnd();
00268   os << f_.tableEnd();     
00269   
00270   typedef map<DDLogicalPart, set<DDSpecifics> > lp_sp_type;
00271   const lp_sp_type & lp_sp = lp_sp_t::instance();
00272   lp_sp_type::const_iterator lpspit = lp_sp.find(lp);
00273   if (lpspit != lp_sp.end()) {
00274     os << f_.h3("assigned SpecPars (Specifics):");
00275     set<DDSpecifics>::const_iterator it(lpspit->second.begin()), ed(lpspit->second.end());
00276     os << "<p>" << endl;
00277     for (; it != ed; ++it) {
00278       os << f_.link("../../sp/" + it->ddname().ns() + "/" + it->ddname().name() + ".html", it->ddname().fullname(), "_popup")
00279          << " " << endl;
00280     }
00281     os << "</p>" << endl;
00282   }
00283         
00284   os << f_.footer();
00285   return true;
00286 }
00287 
00288 //=============================================================================================================
00289 
00290 void dd_to_html(DDHtmlDetails & dtls)
00291 {
00292   cout << "---> dd_to_html() called with category=" << dtls.category() << endl;
00293   const string & category = dtls.category();
00294   const string & text     = dtls.text();
00295   ns_type & names         = dtls.names();
00296   
00297   mkdir( category.c_str(), 0755 );
00298   
00299   // first the namespaces
00300   string ns_fname = category + "/ns.html";
00301   ofstream ns_file(ns_fname.c_str());
00302   DDNsGenerator ns_gen(ns_file, text, "_list", names, "");  
00303   ns_gen.doit();
00304   ns_file.close();
00305   
00306   // list all logical parts per namespace
00307   ns_type::const_iterator it(names.begin()), ed(names.end());
00308   for( ; it != ed; ++it ) {
00309     
00310     const string & ns = it->first;
00311     
00312     // create directories named like the namespaces
00313     string dir = category + "/" + ns;
00314     mkdir( dir.c_str(), 0755 );
00315 
00316     // create a html file listing all instances of a namespace
00317     string fname = category + "/" + ns + "/list.html";
00318     ofstream list_file(fname.c_str());
00319     DDHtmlFormatter f;
00320     list_file << f.header(text)
00321               << f.p("Instances in Namespace <b>" + ns + "</b><br>");
00322     list_file << f.ul();
00323     // loop over all instances of a single namespace
00324     set<string>::const_iterator nit(it->second.begin()), ned(it->second.end());
00325     for(; nit != ned; ++nit) {
00326 
00327       const string & nm = *nit;
00328       string result_s = nm;
00329 
00330       // details for each instance 
00331       string d_fname = category + "/" + ns + "/" + nm + ".html";
00332       ofstream detail_file(d_fname.c_str());
00333       DDName an(nm,ns);
00334       bool result = dtls.details(detail_file, an);
00335 
00336       if (!result) result_s = ">> ERROR: " + nm + " <<";
00337       list_file << f.li(f.lnk(nm+".html", result_s, "_details"));          
00338       
00339     }
00340     list_file << f.ulEnd() << f.footer();
00341   }
00342 }
00343 
00344 //=============================================================================================================
00345 //=============================================================================================================
00346 
00347 
00348 void DDFrameGenerator::doit()
00349 {
00350   DDHtmlFormatter f;
00351   os_ << f.header(t_);
00352   os_ << "<frameset cols=\"25%,*\">" << endl;
00353   os_ << "  <frameset rows=\"50%,*\">" << endl;
00354   os_ << "   <frame src=\"" << u1_ << "\" name=\"" << n1_ << "\">" << endl;
00355   os_ << "   <frame src=\"" << u2_ << "\" name=\"" << n2_ << "\">" << endl;
00356   os_ << "  </frameset>" << endl;
00357   os_ << " <frame src=\"" << u3_ << "\" name=\"" << n3_ << "\">" << endl;
00358   os_ << "</frameset>" << endl;
00359   os_ << f.footer() << endl;  
00360 }
00361 
00362 void dd_html_frameset(ostream & os)
00363 {
00364   DDHtmlFormatter f;
00365   os << f.header("DDD Reports");
00366   os << "<frameset rows=\"50%,50%\"> " << endl
00367      << "  <frameset cols=\"50%,50%\">" << endl
00368      << "    <frame name=\"_ns\" src=\"ns.html\">" << endl
00369      << "    <frame name=\"_list\">" << endl
00370      << "  </frameset>" << endl
00371      << "  <frameset cols=\"50%,50%\">" << endl
00372      << "    <frame name=\"_details\">" << endl
00373      << "    <frame name=\"_popup\">" << endl
00374      << "  </frameset>" << endl
00375      << "</frameset>" << endl
00376      << endl;
00377   os << f.footer();
00378 
00379 }
00380 
00381 void dd_html_menu_frameset(ostream & os)
00382 {
00383   DDHtmlFormatter f;
00384   os << f.header("DDD Web Representation");
00385   os << "<frameset cols=\"20%,80%\">" << endl
00386      << "  <frame name=\"_menu\" src=\"menu.html\">" << endl
00387      << "  <frame name=\"_selection\" >" << endl
00388      << "</frameset>" << endl;
00389      
00390   os << f.footer();    
00391 }
00392 
00393 
00394 void dd_html_menu(ostream & os)
00395 {
00396   DDHtmlFormatter f;
00397   os << f.header("DDD Web Main Menu","style.css");
00398   os << f.h1("Select a Category:") 
00399      << f.p(f.lnk("lp/index.html", "LogicalParts", "_selection")) 
00400      << f.p(f.lnk("ma/index.html", "Materials", "_selection"))
00401      << f.p(f.lnk("so/index.html", "Solids", "_selection"))
00402      << f.p(f.lnk("ro/index.html", "Rotations", "_selection"))
00403      << f.p(f.lnk("sp/index.html", "SpecPars", "_selection"))
00404      ;
00405      
00406   os << f.footer();
00407 }
00408 
00409 
00410