////////////////////////////////////////////////////////////////////////////////
// 
// Statistics.hh 
//
//    produced: 17 Sep 2021 jr
//
////////////////////////////////////////////////////////////////////////////////
#ifndef STATISTICS_HH
#define STATISTICS_HH

#include <stdlib.h>
#include <cstring>
#include <string>
#include <vector>
#include <fstream>
#include <filesystem>

#include "Global.hh"
#include "CommandlineOptions.hh"
#include "ContainerIO.hh"
#include "Message.hh"

namespace topcom {

  // statistical data of type "size_type" can conveniently be collected in a purely
  // static class (i.e., a global variable);
  // for performance reasons only already computed values can be handed over to this class;
  // moreover, it is assumed that only the master thread writes the statistics file;
  // this class is then only responsible for the file output:
  typedef std::unordered_map<std::string, size_type> statistics_table_type;

  class Statistics {
    typedef statistics_table_type table_type;
  private:
    static std::fstream _stats_stream;
    static table_type   _data_table;
  public:
    Statistics() {}
    Statistics(const Statistics&) {}
  public:
    // initialization:
    static void init();
    
    // termination:
    static void term();

    // report:
    static void report();

    // reset:
    static void reset();
    
    // modifiers:
    inline static std::fstream& stats_stream()                                      { return _stats_stream; }
    inline static void register_data(const std::string name, const size_type value) { _data_table.insert(std::pair(name, value)); }
    inline static void change_data(const std::string name, const size_type value)   { _data_table[name] = value; }

    // accessors:
    inline static size_type get_data(const std::string name)                       { return _data_table[name]; }

  };

}; // namespace topcom

#endif

// eof Statistics.hh
