ATLAS Offline Software
Loading...
Searching...
No Matches
TableUtils.h File Reference
#include <array>
#include <string>
#include <string_view>
#include <cassert>
#include <iomanip>
#include <ostream>
#include <stdexcept>
#include <vector>
#include <utility>
#include <limits>

Go to the source code of this file.

Classes

struct  TableUtils::Range< T >
struct  TableUtils::Range< T >::const_iterator
struct  TableUtils::Range2D< T >
struct  TableUtils::Range2D< T >::const_iterator
struct  TableUtils::StatTable< T >
struct  TableUtils::MultiColumnTable< T >

Namespaces

namespace  TableUtils

Typedefs

using TableUtils::SummandDefinition = std::pair<std::size_t, int>
using TableUtils::RatioDefinition

Functions

template<class T_Stream, typename T_Counter>
T_Stream & TableUtils::dumpTable (T_Stream &out, Range< T_Counter > counter, const Range< std::string > &label, const std::string &label_prefix, const std::size_t column_width, const std::size_t min_label_width, const bool dump_footer, const bool separate_last_row, const unsigned int precision)
template<class T_Stream, typename T_Counter>
T_Stream & TableUtils::dumpTable (T_Stream &out, Range2D< T_Counter > counter, const Range< std::string > &row_label, const Range< std::string > &column_label, std::string_view top_left_label, const std::string &label_prefix, const std::size_t column_width, const std::size_t min_label_width, const bool dump_header, const bool dump_footer, const bool separate_last_row, const std::vector< unsigned int > &precision)
template<typename T_index, class T_string>
std::vector< std::string > TableUtils::makeLabelVector (T_index n_entries, std::initializer_list< std::pair< T_index, T_string > > a_list)
template<class T_Collection>
std::size_t TableUtils::maxLabelWidth (const T_Collection &col)
constexpr std::size_t TableUtils::categoryStride (const std::size_t categories, const std::size_t sub_categories, const std::size_t n_counter)
constexpr std::size_t TableUtils::subCategoryStride (const std::size_t categories, const std::size_t sub_categories, const std::size_t n_counter)
constexpr std::size_t TableUtils::counterStride (const std::size_t categories, const std::size_t sub_categories, const std::size_t n_counter)
template<typename T_Output, typename T_Input, const std::size_t N>
std::vector< T_Output > TableUtils::createCounterArrayWithProjections (const std::size_t categories, const std::size_t sub_categories, const std::vector< std::array< T_Input, N > > &input_counts)
template<typename T>
RatioDefinition TableUtils::defineSimpleRatio (T numerator, T denominator)
template<typename T>
std::tuple< std::string, RatioDefinitionTableUtils::defineSimpleRatio (std::string &&name, T numerator, T denominator)
template<typename T>
SummandDefinition TableUtils::defineSummand (T counter_idx, int multiplier)
std::size_t TableUtils::computeSum (const std::vector< SummandDefinition > &sum_def, std::size_t eta_offset, std::size_t row_stride, std::size_t seed_i, const std::vector< std::size_t > &stat)
float TableUtils::computeRatio (std::size_t numerator, std::size_t denominator)
float TableUtils::computeRatio (const RatioDefinition &ratio_def, std::size_t eta_offset, std::size_t row_stride, std::size_t seed_i, const std::vector< std::size_t > &stat)
std::tuple< std::string, RatioDefinitionTableUtils::makeRatioDefinition (std::string &&name, std::vector< SummandDefinition > &&numerator, std::vector< SummandDefinition > &&denominator)
std::tuple< std::vector< std::string >, std::vector< RatioDefinition > > TableUtils::splitRatioDefinitionsAndLabels (std::initializer_list< std::tuple< std::string, RatioDefinition > > a_ratio_list)
constexpr std::size_t TableUtils::categoryStride (const std::size_t categories, const std::size_t sub_categories, const std::vector< RatioDefinition > &ratio_def)
std::size_t TableUtils::subCategoryStride (const std::size_t categories, const std::size_t sub_categories, const std::vector< RatioDefinition > &ratio_def)
constexpr std::size_t TableUtils::ratioStride (const std::size_t categories, const std::size_t sub_categories, const std::vector< RatioDefinition > &ratio_def)
std::vector< float > TableUtils::computeRatios (const std::vector< RatioDefinition > &ratio_def, const std::size_t categories, const std::size_t sub_categories, const std::vector< std::size_t > &counter)
std::string TableUtils::makeBinLabel (const std::string &variable_name, const std::vector< float > &bins, std::size_t bin_i, bool abs_value=false, int precision=1)
std::string TableUtils::makeEtaBinLabel (const std::vector< float > &eta_bins, std::size_t eta_bin_i, bool abs_eta=false)
template<typename T, std::size_t N>
TableUtils::StatTable< T > makeTable (const std::array< T, N > &counter, const std::array< std::string, N > &label)
template<typename T, std::size_t Nrows, std::size_t Ncolumns>
TableUtils::MultiColumnTable< T > makeTable (const std::array< std::array< T, Ncolumns >, Nrows > &counter, const std::array< std::string, Nrows > &row_label, const std::array< std::string, Ncolumns > &column_label, std::string_view top_left_label="")
template<typename T>
TableUtils::MultiColumnTable< T > makeTable (const std::vector< T > &counter, std::size_t start_idx, std::size_t row_stride, const std::vector< std::string > &row_label, const std::vector< std::string > &column_label, std::string_view top_left_label="")
template<typename T, std::size_t N>
TableUtils::MultiColumnTable< T > makeTable (const std::vector< std::array< T, N > > &counter, std::size_t start_row_idx, std::size_t row_stride, std::size_t start_column_idx, std::size_t column_stride, const std::vector< std::string > &row_label, const std::vector< std::string > &column_label, std::string_view top_left_label="")
template<typename T>
TableUtils::MultiColumnTable< T > makeTable (const std::vector< T > &counter, const std::vector< std::string > &row_label, const std::vector< std::string > &column_label, std::string_view top_left_label="")
template<typename T>
MsgStream & operator<< (MsgStream &out, const TableUtils::StatTable< T > &stat)
template<typename T>
MsgStream & operator<< (MsgStream &out, const TableUtils::MultiColumnTable< T > &stat)
template<typename T>
std::ostream & operator<< (std::ostream &out, const TableUtils::StatTable< T > &stat)

Function Documentation

◆ makeTable() [1/5]

template<typename T, std::size_t Nrows, std::size_t Ncolumns>
TableUtils::MultiColumnTable< T > makeTable ( const std::array< std::array< T, Ncolumns >, Nrows > & counter,
const std::array< std::string, Nrows > & row_label,
const std::array< std::string, Ncolumns > & column_label,
std::string_view top_left_label = "" )

Definition at line 554 of file TableUtils.h.

557 {
559 TableUtils::Range2D<T> {!counter.empty() ? counter[0].data() : nullptr,
560 counter.size(), column_label.size(),
561 !counter.empty() ? static_cast<std::size_t>(&counter[1][0] - &counter[0][0]) : 0u,
562 0u, // index of first column
563 1u}, // offset between columns
564 TableUtils::Range<std::string> {row_label.data(), row_label.size(), 1u},
565 TableUtils::Range<std::string> {column_label.data(), column_label.size(),1u},
566 std::string{top_left_label}
567 };
568}
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
STL class.
@ u
Enums for curvilinear frames.
Definition ParamDefs.h:77
STL namespace.

◆ makeTable() [2/5]

template<typename T, std::size_t N>
TableUtils::StatTable< T > makeTable ( const std::array< T, N > & counter,
const std::array< std::string, N > & label )

Definition at line 544 of file TableUtils.h.

545 {
547 TableUtils::Range<T> {counter.data(), counter.size()},
549 };
550}
std::string label(const std::string &format, int i)
Definition label.h:19

◆ makeTable() [3/5]

template<typename T, std::size_t N>
TableUtils::MultiColumnTable< T > makeTable ( const std::vector< std::array< T, N > > & counter,
std::size_t start_row_idx,
std::size_t row_stride,
std::size_t start_column_idx,
std::size_t column_stride,
const std::vector< std::string > & row_label,
const std::vector< std::string > & column_label,
std::string_view top_left_label = "" )

Definition at line 610 of file TableUtils.h.

617 {
618 if (start_row_idx + (row_label.size()-1) * row_stride >= counter.size()*N
619 || start_column_idx + (column_label.size()-1) * column_stride >= counter.size()*N
620 || (row_stride*row_label.size()>column_stride && column_stride*column_label.size()>row_stride) ) {
621 std::stringstream msg;
622 msg << "Counter dimension and label dimensions (" << row_label.size() << " * " << column_label.size()
623 << ") do not match: [" << start_row_idx << ", "
624 << start_row_idx << " + " << (row_label.size()-1) << " * " << row_stride << " = "
625 << (start_row_idx + (row_label.size()-1) * row_stride)
626 << " or "
627 << start_column_idx << " + " << (column_label.size()-1) << " * " << column_stride << " = "
628 << (start_column_idx + (column_label.size()-1) * column_stride)
629 << " !< " << counter.size()
630 << std::endl
631 << (start_row_idx + (row_label.size()-1) * row_stride) << " >= " << (counter.size()*N)
632 << " || " << (start_column_idx + (column_label.size()-1) * column_stride) << " >= " << (counter.size()*N)
633 << " || ( " << (row_stride*row_label.size()) << " > " << column_stride << " && " << (column_stride*column_label.size()) << " > " << (row_stride)
634 << ")";
635 msg << " [row_labels:";
636 for (const std::string &label : row_label) {
637 msg << " " << label;
638 }
639 msg << "; column_labels:";
640 for (const std::string &label : column_label) {
641 msg << " " << label;
642 }
643 msg << "]";
644 throw std::logic_error(msg.str());
645 }
647 TableUtils::Range2D<T> {!counter.empty() && N>0 ? counter[start_row_idx].data() : nullptr,
648 row_label.size(), // n-rows
649 column_label.size(), // n-columns
650 row_stride, // offset between rows
651 start_column_idx, // first column index
652 column_stride}, // offset between columns
653 TableUtils::Range<std::string> {row_label.data(), row_label.size() },
654 TableUtils::Range<std::string> {column_label.data(), column_label.size()},
655 std::string{top_left_label}};
656}
constexpr std::size_t N
MsgStream & msg
Definition testRead.cxx:32

◆ makeTable() [4/5]

template<typename T>
TableUtils::MultiColumnTable< T > makeTable ( const std::vector< T > & counter,
const std::vector< std::string > & row_label,
const std::vector< std::string > & column_label,
std::string_view top_left_label = "" )

Definition at line 661 of file TableUtils.h.

664 {
665 return makeTable(counter, 0u, column_label.size(), row_label, column_label, top_left_label);
666}
TableUtils::StatTable< T > makeTable(const std::array< T, N > &counter, const std::array< std::string, N > &label)
Definition TableUtils.h:544

◆ makeTable() [5/5]

template<typename T>
TableUtils::MultiColumnTable< T > makeTable ( const std::vector< T > & counter,
std::size_t start_idx,
std::size_t row_stride,
const std::vector< std::string > & row_label,
const std::vector< std::string > & column_label,
std::string_view top_left_label = "" )

Definition at line 572 of file TableUtils.h.

577 {
578 if (start_idx + (row_label.size()-1) * row_stride >= counter.size() || row_stride < column_label.size()) {
579 std::stringstream msg;
580 msg << "Counter dimension and label dimensions (" << row_label.size() << " * " << column_label.size()
581 << ") do not match: [" << start_idx << ", "
582 << start_idx << " + " << (row_label.size()-1) << " * " << row_stride << " = "
583 << (start_idx + (row_label.size()-1) * row_stride)
584 << " !< " << counter.size();
585 msg << " [row_labels:";
586 for (const std::string &label : row_label) {
587 msg << " " << label;
588 }
589 msg << "; column_labels:";
590 for (const std::string &label : column_label) {
591 msg << " " << label;
592 }
593 msg << "]";
594 throw std::logic_error(msg.str());
595 }
597 TableUtils::Range2D<T> {!counter.empty() ? &counter[start_idx] : nullptr,
598 row_label.size(), // n-rows
599 column_label.size(), // n-columns
600 row_stride, // offset between rows
601 0u, // first column index
602 1u}, // offset between columns
603 TableUtils::Range<std::string> {row_label.data(), row_label.size() },
604 TableUtils::Range<std::string> {column_label.data(), column_label.size()},
605 std::string{top_left_label}
606 };
607}

◆ operator<<() [1/3]

template<typename T>
MsgStream & operator<< ( MsgStream & out,
const TableUtils::MultiColumnTable< T > & stat )
inline

Definition at line 691 of file TableUtils.h.

693{
694 return dumpTable(out,
695 stat.m_counter,
696 stat.m_rowLabel,
697 stat.m_columnLabel,
698 stat.m_topLeftLable,
699 stat.m_labelPrefix,
700 stat.m_columnWidth,
701 stat.m_minLabelWidth,
702 stat.m_dumpHeader,
703 stat.m_dumpFooter,
704 stat.m_separateLastRow,
705 stat.m_precision);
706}
T_Stream & dumpTable(T_Stream &out, Range< T_Counter > counter, const Range< std::string > &label, const std::string &label_prefix, const std::size_t column_width, const std::size_t min_label_width, const bool dump_footer, const bool separate_last_row, const unsigned int precision)
Definition TableUtils.h:106

◆ operator<<() [2/3]

template<typename T>
MsgStream & operator<< ( MsgStream & out,
const TableUtils::StatTable< T > & stat )
inline

Definition at line 673 of file TableUtils.h.

675{
676 return dumpTable(out,
677 stat.m_counter,
678 stat.m_label,
679 stat.m_labelPrefix,
680 stat.m_columnWidth,
681 stat.m_minLabelWidth,
682 stat.m_dumpFooter,
683 stat.m_separateLastRow,
684 stat.m_precision);
685}

◆ operator<<() [3/3]

template<typename T>
std::ostream & operator<< ( std::ostream & out,
const TableUtils::StatTable< T > & stat )
inline

Definition at line 712 of file TableUtils.h.

714{
715 return dumpTable(out,
716 stat.m_counter,
717 stat.m_label,
718 stat.m_labelPrefix,
719 stat.m_columnWidth,
720 stat.m_minLabelWidth,
721 stat.m_dumpFooter,
722 stat.m_separateLastRow,
723 stat.m_precision);
724}