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:

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 >
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)
 
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 533 of file TableUtils.h.

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

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

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

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

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

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

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

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

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

◆ operator<<() [1/4]

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

Definition at line 670 of file TableUtils.h.

672 {
673  return dumpTable(out,
674  stat.m_counter,
675  stat.m_rowLabel,
676  stat.m_columnLabel,
677  stat.m_topLeftLable,
678  stat.m_labelPrefix,
679  stat.m_columnWidth,
680  stat.m_minLabelWidth,
681  stat.m_dumpHeader,
682  stat.m_dumpFooter,
683  stat.m_separateLastRow,
684  stat.m_precision);
685 }

◆ operator<<() [2/4]

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

Definition at line 652 of file TableUtils.h.

654 {
655  return dumpTable(out,
656  stat.m_counter,
657  stat.m_label,
658  stat.m_labelPrefix,
659  stat.m_columnWidth,
660  stat.m_minLabelWidth,
661  stat.m_dumpFooter,
662  stat.m_separateLastRow,
663  stat.m_precision);
664 }

◆ operator<<() [3/4]

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

Definition at line 708 of file TableUtils.h.

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

◆ operator<<() [4/4]

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

Definition at line 691 of file TableUtils.h.

693 {
694  return dumpTable(out,
695  stat.m_counter,
696  stat.m_label,
697  stat.m_labelPrefix,
698  stat.m_columnWidth,
699  stat.m_minLabelWidth,
700  stat.m_dumpFooter,
701  stat.m_separateLastRow,
702  stat.m_precision);
703 }
TableUtils::Range2D
Definition: TableUtils.h:62
TableUtils::MultiColumnTable
Definition: TableUtils.h:252
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:70
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
TableUtils::Range::size
std::size_t size() const
Definition: TableUtils.h:47
makeTable
TableUtils::StatTable< T > makeTable(const std::array< T, N > &counter, const std::array< std::string, N > &label)
Definition: TableUtils.h:523
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:153
add-xsec-uncert-quadrature-N.label
label
Definition: add-xsec-uncert-quadrature-N.py:104
TableUtils::Range< std::string >
beamspotman.stat
stat
Definition: beamspotman.py:262
TableUtils::StatTable
Definition: TableUtils.h:231
test_pyathena.counter
counter
Definition: test_pyathena.py:15
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7