ATLAS Offline Software
Classes | Namespaces | Typedefs | Functions
TableUtils.h File Reference
#include <array>
#include <string>
#include <cassert>
#include <iomanip>
#include <ostream>
#include <stdexcept>
#include <vector>
#include <utility>
#include <limits>
Include dependency graph for TableUtils.h:
This graph shows which files directly or indirectly include this file:

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

 TableUtils
 

Typedefs

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

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, const std::string &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 ([[maybe_unused]] const std::size_t categories, [[maybe_unused]] const std::size_t sub_categories, [[maybe_unused]] const std::size_t n_counter)
 
constexpr std::size_t TableUtils::subCategoryStride ([[maybe_unused]] const std::size_t categories, [[maybe_unused]] const std::size_t sub_categories, [[maybe_unused]] const std::size_t n_counter)
 
constexpr std::size_t TableUtils::counterStride ([[maybe_unused]] const std::size_t categories, [[maybe_unused]] const std::size_t sub_categories, [[maybe_unused]] 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, RatioDefinition > TableUtils::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, RatioDefinition > TableUtils::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 ([[maybe_unused]] const std::size_t categories, [[maybe_unused]] const std::size_t sub_categories, [[maybe_unused]] const std::vector< RatioDefinition > &ratio_def)
 
std::size_t TableUtils::subCategoryStride ([[maybe_unused]] const std::size_t categories, [[maybe_unused]] const std::size_t sub_categories, [[maybe_unused]] const std::vector< RatioDefinition > &ratio_def)
 
constexpr std::size_t TableUtils::ratioStride ([[maybe_unused]] const std::size_t categories, [[maybe_unused]] const std::size_t sub_categories, [[maybe_unused]] 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, const std::string &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, const std::string &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, const std::string &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, const std::string &top_left_label="")
 
template<typename T >
std::ostream & operator<< (std::ostream &out, const TableUtils::StatTable< T > &stat)
 
template<typename T >
std::ostream & operator<< (std::ostream &out, const TableUtils::MultiColumnTable< 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,
const std::string &  top_left_label = "" 
)

Definition at line 531 of file TableUtils.h.

534  {
536  TableUtils::Range2D<T> {!counter.empty() ? counter[0].data() : nullptr,
537  counter.size(), column_label.size(),
538  !counter.empty() ? static_cast<std::size_t>(&counter[1][0] - &counter[0][0]) : 0u,
539  0u, // index of first column
540  1u}, // offset between columns
541  TableUtils::Range<std::string> {row_label.data(), row_label.size(), 1u},
542  TableUtils::Range<std::string> {column_label.data(), column_label.size(),1u},
543  top_left_label
544  };
545 }

◆ 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 521 of file TableUtils.h.

522  {
523  return TableUtils::StatTable<T> {
524  TableUtils::Range<T> {counter.data(), counter.size()},
525  TableUtils::Range<std::string> {label.data(), label.size() }
526  };
527 }

◆ 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,
const std::string &  top_left_label = "" 
)

Definition at line 587 of file TableUtils.h.

594  {
595  if (start_row_idx + (row_label.size()-1) * row_stride >= counter.size()*N
596  || start_column_idx + (column_label.size()-1) * column_stride >= counter.size()*N
597  || (row_stride*row_label.size()>column_stride && column_stride*column_label.size()>row_stride) ) {
598  std::stringstream msg;
599  msg << "Counter dimension and label dimensions (" << row_label.size() << " * " << column_label.size()
600  << ") do not match: [" << start_row_idx << ", "
601  << start_row_idx << " + " << (row_label.size()-1) << " * " << row_stride << " = "
602  << (start_row_idx + (row_label.size()-1) * row_stride)
603  << " or "
604  << start_column_idx << " + " << (column_label.size()-1) << " * " << column_stride << " = "
605  << (start_column_idx + (column_label.size()-1) * column_stride)
606  << " !< " << counter.size()
607  << std::endl
608  << (start_row_idx + (row_label.size()-1) * row_stride) << " >= " << (counter.size()*N)
609  << " || " << (start_column_idx + (column_label.size()-1) * column_stride) << " >= " << (counter.size()*N)
610  << " || ( " << (row_stride*row_label.size()) << " > " << column_stride << " && " << (column_stride*column_label.size()) << " > " << (row_stride)
611  << ")";
612  msg << " [row_labels:";
613  for (const std::string &label : row_label) {
614  msg << " " << label;
615  }
616  msg << "; column_labels:";
617  for (const std::string &label : column_label) {
618  msg << " " << label;
619  }
620  msg << "]";
621  throw std::logic_error(msg.str());
622  }
624  TableUtils::Range2D<T> {!counter.empty() && N>0 ? counter[start_row_idx].data() : nullptr,
625  row_label.size(), // n-rows
626  column_label.size(), // n-columns
627  row_stride, // offset between rows
628  start_column_idx, // first column index
629  column_stride}, // offset between columns
630  TableUtils::Range<std::string> {row_label.data(), row_label.size() },
631  TableUtils::Range<std::string> {column_label.data(), column_label.size()},
632  top_left_label};
633 }

◆ 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,
const std::string &  top_left_label = "" 
)

Definition at line 638 of file TableUtils.h.

641  {
642  return makeTable(counter, 0u, column_label.size(), row_label, column_label, top_left_label);
643 }

◆ 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,
const std::string &  top_left_label = "" 
)

Definition at line 549 of file TableUtils.h.

554  {
555  if (start_idx + (row_label.size()-1) * row_stride >= counter.size() || row_stride < column_label.size()) {
556  std::stringstream msg;
557  msg << "Counter dimension and label dimensions (" << row_label.size() << " * " << column_label.size()
558  << ") do not match: [" << start_idx << ", "
559  << start_idx << " + " << (row_label.size()-1) << " * " << row_stride << " = "
560  << (start_idx + (row_label.size()-1) * row_stride)
561  << " !< " << counter.size();
562  msg << " [row_labels:";
563  for (const std::string &label : row_label) {
564  msg << " " << label;
565  }
566  msg << "; column_labels:";
567  for (const std::string &label : column_label) {
568  msg << " " << label;
569  }
570  msg << "]";
571  throw std::logic_error(msg.str());
572  }
574  TableUtils::Range2D<T> {!counter.empty() ? &counter[start_idx] : nullptr,
575  row_label.size(), // n-rows
576  column_label.size(), // n-columns
577  row_stride, // offset between rows
578  0u, // first column index
579  1u}, // offset between columns
580  TableUtils::Range<std::string> {row_label.data(), row_label.size() },
581  TableUtils::Range<std::string> {column_label.data(), column_label.size()},
582  top_left_label
583  };
584 }

◆ operator<<() [1/2]

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

Definition at line 706 of file TableUtils.h.

708 {
709  return dumpTable(out,
710  stat.m_counter,
711  stat.m_rowLabel,
712  stat.m_columnLabel,
713  stat.m_topLeftLable,
714  stat.m_labelPrefix,
715  stat.m_columnWidth,
716  stat.m_minLabelWidth,
717  stat.m_dumpHeader,
718  stat.m_dumpFooter,
719  stat.m_separateLastRow,
720  stat.m_precision);
721 }

◆ operator<<() [2/2]

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

Definition at line 689 of file TableUtils.h.

691 {
692  return dumpTable(out,
693  stat.m_counter,
694  stat.m_label,
695  stat.m_labelPrefix,
696  stat.m_columnWidth,
697  stat.m_minLabelWidth,
698  stat.m_dumpFooter,
699  stat.m_separateLastRow,
700  stat.m_precision);
701 }
TableUtils::Range2D
Definition: TableUtils.h:60
TableUtils::MultiColumnTable
Definition: TableUtils.h:250
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:83
TableUtils::Range::size
std::size_t size() const
Definition: TableUtils.h:45
makeTable
TableUtils::StatTable< T > makeTable(const std::array< T, N > &counter, const std::array< std::string, N > &label)
Definition: TableUtils.h:521
TableUtils::dumpTable
T_Stream & dumpTable(T_Stream &out, Range2D< T_Counter > counter, const Range< std::string > &row_label, const Range< std::string > &column_label, const std::string &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)
Definition: TableUtils.h:151
TableUtils::Range< std::string >
beamspotman.stat
stat
Definition: beamspotman.py:266
TableUtils::StatTable
Definition: TableUtils.h:229
test_pyathena.counter
counter
Definition: test_pyathena.py:15
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7