8 #include <framework/utilities/HTML.h> 
   10 #include <boost/algorithm/string/replace.hpp> 
   13 #include <TMatrixFBase.h> 
   17 #include <framework/gearbox/Unit.h> 
   23 using namespace boost::algorithm;
 
   25 std::string 
HTML::getString(
const TMatrixFBase& matrix, 
int precision, 
bool color)
 
   27   const int nr = matrix.GetNrows();
 
   28   const int nc = matrix.GetNcols();
 
   30   TMatrixD matrix_double(nr, nc);
 
   31   for (
int ir = 0; ir < nr; ir++)
 
   32     for (
int ic = 0; ic < nc; ic++)
 
   33       matrix_double(ir, ic) = matrix(ir, ic);
 
   34   return getString(matrix_double, precision, color);
 
   37 std::string 
HTML::getString(
const TMatrixDBase& matrix, 
int precision, 
bool color)
 
   39   std::stringstream stream;
 
   40   stream.precision(precision);
 
   42   stream << 
"<table padding=0>";
 
   43   const double max = matrix.Max();
 
   44   const double min = matrix.Min();
 
   45   for (
int i = 0; i < matrix.GetNrows(); i++) {
 
   47     for (
int k = 0; k < matrix.GetNcols(); k++) {
 
   48       const double value = matrix(i, k);
 
   49       stream << 
"<td align=right";
 
   50       if (color and value != 0.0) {
 
   56           b = g = 255 - 180 * value / max;
 
   58           r = 255 - 200 * value / min;
 
   60         stream << 
" bgcolor=" << std::setfill(
'0') << std::hex;
 
   61         stream << std::setw(2) << r;
 
   62         stream << std::setw(2) << g;
 
   63         stream << std::setw(2) << b;
 
   64         stream << std::dec << std::setfill(
' ');
 
   66       stream << 
">" << std::setw(11) << value;
 
   79   std::stringstream stream;
 
   80   stream.precision(precision);
 
   82   stream << std::fixed << 
"(" << vec.x() << 
", " <<  vec.y() << 
", " <<  vec.z() << 
")";
 
   88   std::stringstream stream;
 
   89   stream.precision(precision);
 
   90   std::string displayedUnitType = unitType;
 
   93     displayedUnitType = 
"\x0b5m";
 
   98          << 
") " << displayedUnitType;
 
  106   std::string unitType;
 
  110   for (
auto entry : xyz)
 
  111     if (std::abs(entry) > max)
 
  112       max = std::abs(entry);
 
  124   std::stringstream stream;
 
  125   stream << 
"<small><tt>";
 
  128   for (
int i = 0; i < length; i++) {
 
  131     snprintf(str, 
sizeof(str), 
"%08x ", buf[i]);
 
  134   stream << 
"</tt></small>";
 
  141   std::string tmp = html;
 
  143   replace_all(tmp, 
"<br>", 
"\n");
 
  144   replace_all(tmp, 
"</p>", 
"\n");
 
  145   replace_all(tmp, 
"</tr>", 
"\n");
 
  146   replace_all(tmp, 
" ", 
" ");
 
  149   replace_all(tmp, 
"\x0b5", 
"u");
 
  152   const static std::regex tagRegex(
"<.*?>");
 
  153   tmp = std::regex_replace(tmp, tagRegex, 
"");
 
  162   std::string tmp = str;
 
  163   replace_all(tmp, 
"&", 
"&"); 
 
  164   replace_all(tmp, 
">", 
">");
 
  165   replace_all(tmp, 
"<", 
"<");
 
  166   replace_all(tmp, 
"\"", 
""");
 
  172   std::string tmp = str;
 
  174   replace_all(tmp, 
""", 
"\"");
 
  175   replace_all(tmp, 
">", 
">");
 
  176   replace_all(tmp, 
"<", 
"<");
 
  177   replace_all(tmp, 
"&", 
"&"); 
 
static double convertValueToUnit(double value, const std::string &unitString)
Converts a floating point value from the standard framework unit to the given unit.
std::string escape(const std::string &str)
Convert &, <, > etc.
std::string getHexDump(const int *buf, int length)
Create hexdump of given buffer.
std::string chooseUnitOfLength(const TVector3 &vec)
get a string with a unit type to convert a vector, so that it is easily readable.
std::string unescape(const std::string &str)
inverse of escape()
std::string getStringConvertToUnit(const TVector3 &vec, int precision=2, const std::string &unitType="cm")
get a string with vector coordinates: (x, y, z).
std::string getString(const TMatrixFBase &matrix, int precision=2, bool color=true)
get HTML table representing a matrix.
std::string htmlToPlainText(const std::string &html)
Reformat given HTML string into terminal-friendly plain text.
Abstract base class for different kinds of events.