20 LArFormattingHelper::PrintFormatCharacter(static_cast<unsigned int>(style), stream);
27 LArFormattingHelper::PrintFormatCharacter(static_cast<unsigned int>(color), stream);
32 void LArFormattingHelper::ResetStyle(std::ostream &
stream)
34 LArFormattingHelper::SetStyle(REGULAR, stream);
39 void LArFormattingHelper::ResetColor(std::ostream &
stream)
41 LArFormattingHelper::SetColor(DEFAULT, stream);
46 void LArFormattingHelper::Reset(std::ostream &
stream)
48 LArFormattingHelper::ResetColor(stream);
49 LArFormattingHelper::ResetStyle(stream);
54 void LArFormattingHelper::PrintFormatCharacter(
const unsigned int code, std::ostream &
stream)
56 if (!(stream << LArFormattingHelper::GetFormatCharacter(code)))
57 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
62 std::string LArFormattingHelper::GetFormatCharacter(
const unsigned int code)
64 const std::string startFormattingCode(
"\x1B[");
65 const std::string endFormattingCode(
"m");
66 return (startFormattingCode +
std::to_string(code) + endFormattingCode);
71 void LArFormattingHelper::PrintHeader(
const std::string &title,
const unsigned int width)
73 LArFormattingHelper::SetStyle(BOLD);
74 std::cout << std::endl << std::string(width,
'-') <<
"\r-" << title << std::endl;
75 LArFormattingHelper::Reset();
80 void LArFormattingHelper::PrintRule(
const unsigned int width)
82 LArFormattingHelper::PrintHeader(
"", width);
88 LArFormattingHelper::Table::Table(
const StringVector &columnTitles,
const unsigned int precision) :
89 m_columnTitles(columnTitles),
90 m_precision(precision)
102 if (m_columnTitles[m_elements.size() % m_columnTitles.size()] ==
"")
104 m_format.push_back(
"");
105 m_elements.push_back(
"");
113 if (column >= m_columnTitles.size())
114 throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
116 return (m_columnTitles[column] ==
"");
123 if (m_widths.empty() || m_elements.empty())
124 throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
126 const unsigned int currentElementIndex(m_elements.size() - 1);
127 const unsigned int column(currentElementIndex % m_widths.size());
128 m_widths[column] = std::max(static_cast<unsigned int>(m_elements[currentElementIndex].length()), m_widths[column]);
135 if (m_columnTitles.empty())
138 this->PrintColumnTitles();
139 this->PrintHorizontalLine();
140 this->PrintTableElements();
147 for (
unsigned int i = 0, nColumns = m_columnTitles.size(); i < nColumns; ++i)
155 for (
unsigned int i = 0, nColumns = m_columnTitles.size(); i < nColumns; ++i)
163 if (m_columnTitles.empty())
166 const unsigned int nRows((m_elements.size() + m_columnTitles.size() - 1) / m_columnTitles.size());
167 const unsigned int nColumns(m_columnTitles.size());
168 if (nRows * nColumns != m_elements.size())
170 std::cout <<
"LArFormattingHelper::Table::PrintTableElements - Error: Number of table elements added doesn't fill a whole row" << std::endl;
171 throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
174 for (
unsigned int i = 0; i < nRows * nColumns; i++)
175 this->PrintTableCell(m_elements[i], m_format[i], i);
182 if (m_columnTitles.empty())
185 const unsigned int column(index % m_widths.size());
187 const std::string separator(this->IsSeparatorColumn(column) ?
"" :
" ");
188 std::cout <<
"|" << format << separator << std::setw(m_widths[column]) << std::internal << value << separator
189 << std::resetiosflags(std::ios::adjustfield);
192 if (column == m_columnTitles.size() - 1)
void PrintTableCell(const std::string &value, const std::string &format, const unsigned int index) const
Print a table cell.
static std::string format(PyObject *obj, unsigned int pos, unsigned int indent, unsigned int maxlen, unsigned int depth)
bool IsSeparatorColumn(const unsigned int column) const
If the supplied column is a separator (vertical rule)
void PrintTableElements() const
Print the table elements.
Math::BigFloat precision(-16)
Color
Style code enumeration.
static std::string GetFormatCharacter(const unsigned int code)
Get a formatting character.
void PrintHorizontalLine() const
Print a horizontal line.
std::stringstream m_stringstream
The stringstream to print objects to.
const unsigned int m_precision
The number of significant figures to use when displaying number types.
const pandora::StringVector m_columnTitles
The vector of columns titles in the table.
void CheckAndSetSeparatorColumn()
Check if the next table cell is in a separator column, if so add a blank element. ...
Style
Style code enumeration.
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
std::string to_string(WindowPattern const &pattern)
std::vector< unsigned int > m_widths
The widths of each column (in units of number of characters)
void Print() const
Print the table.
static void ResetStyle(std::ostream &stream=std::cout)
Reset the style of the standard output stream.
void UpdateColumnWidth()
Update the width of the last column in which an element was added.
void PrintColumnTitles() const
Print the column titles.
BEGIN_PROLOG could also be cout