// $Id: Rstats.cpp 983 2018-01-02 20:35:59Z mueller $ // // Copyright 2011-2017 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free // Software Foundation, either version 3, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for complete details. // // Revision History: // Date Rev Version Comment // 2017-02-04 865 1.0.4 add NameMaxLength(); Print(): add counter name // 2017-02-18 851 1.0.3 add IncLogHist; fix + and * operator definition // 2013-02-03 481 1.0.2 use Rexception // 2011-03-06 367 1.0.1 use max from algorithm // 2011-02-06 359 1.0 Initial version // --------------------------------------------------------------------------- /*! \file \brief Implemenation of Rstats . */ #include #include "Rstats.hpp" #include "RosFill.hpp" #include "RosPrintf.hpp" #include "Rexception.hpp" using namespace std; /*! \class Retro::Rstats \brief FIXME_docs */ // all method definitions in namespace Retro namespace Retro { //------------------------------------------+----------------------------------- //! Default constructor Rstats::Rstats() : fValue(), fName(), fText(), fHash(0), fFormat("f"), fWidth(12), fPrec(0) {} //------------------------------------------+----------------------------------- //! Copy constructor Rstats::Rstats(const Rstats& rhs) : fValue(rhs.fValue), fName(rhs.fName), fText(rhs.fText), fHash(rhs.fHash), fFormat(rhs.fFormat), fWidth(rhs.fWidth), fPrec(rhs.fPrec) {} //------------------------------------------+----------------------------------- //! Destructor Rstats::~Rstats() {} //------------------------------------------+----------------------------------- //! FIXME_docs void Rstats::Define(size_t ind, const std::string& name, const std::string& text) { // update hash for (size_t i=0; i= Size()) { fValue.resize(ind+1); fName.resize(ind+1); fText.resize(ind+1); } fValue[ind] = 0.; fName[ind] = name; fText[ind] = text; } return; } //------------------------------------------+----------------------------------- //! FIXME_docs void Rstats::IncLogHist(size_t ind, size_t maskfirst, size_t masklast, size_t val) { if (val == 0) return; size_t mask = maskfirst; while (ind < fValue.size()) { if (val <= mask || mask >= masklast) { // val in bin or last bin Inc(ind); return; } mask = (mask<<1) | 0x1; ind += 1; } return; } //------------------------------------------+----------------------------------- //! FIXME_docs void Rstats::SetFormat(const char* format, int width, int prec) { fFormat = format; fWidth = width; fPrec = prec; return; } //------------------------------------------+----------------------------------- //! FIXME_docs size_t Rstats::NameMaxLength() const { size_t maxlen = 0; for (size_t i=0; i maxlen) maxlen = len; } return maxlen; } //------------------------------------------+----------------------------------- //! FIXME_docs void Rstats::Print(std::ostream& os, const char* format, int width, int prec) const { if (format == 0 || format[0]==0) { format = fFormat.c_str(); width = fWidth; prec = fPrec; } size_t maxlen = NameMaxLength(); for (size_t i=0; i= 0) { // full dump size_t maxlen=8; for (size_t i=0; i