BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Report.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Fit/Adapter/Report.cpp
6 //! @brief Implements report namespace.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #include "Fit/Adapter/Report.h"
18 #include <iomanip>
19 #include <sstream>
20 
21 namespace {
22 
23 const int column_width = 18;
24 
25 template <typename T>
26 std::string reportValue(const std::string& name, T value)
27 {
28  std::ostringstream result;
29  result << std::setw(column_width) << std::left << name << ": " << value << std::endl;
30  return result.str();
31 }
32 
33 std::string reportDescription(const MinimizerAdapter& minimizer)
34 {
35  std::ostringstream result;
36  result << reportValue("MinimizerType", minimizer.minimizerName());
37  result << reportValue("AlgorithmName", minimizer.algorithmName());
38  return result.str();
39 }
40 
41 std::string reportOption(const MinimizerAdapter& minimizer)
42 {
43  if (minimizer.options().empty())
44  return "";
45 
46  std::ostringstream result;
47  result << mumufit::utils::sectionString("Options");
48  for (const auto& option : minimizer.options()) {
49  std::ostringstream opt;
50  opt << std::setw(5) << std::left << option->value_str() << option->description();
51  result << reportValue(option->name(), opt.str());
52  }
53  result << mumufit::utils::sectionString("OptionString");
54  result << minimizer.options().toOptionString() << std::endl;
55 
56  return result.str();
57 }
58 
59 std::string reportStatus(const MinimizerAdapter& minimizer)
60 {
61  std::ostringstream result;
62  result << mumufit::utils::sectionString("Status");
63 
64  auto status = minimizer.statusMap();
65  for (const auto& it : status)
66  result << reportValue(it.first, it.second);
67 
68  return result.str();
69 }
70 
71 } // namespace
72 
73 // ************************************************************************************************
74 // implement API
75 // ************************************************************************************************
76 
78 {
79  std::ostringstream result;
80 
82  result << reportDescription(minimizer);
83  result << reportOption(minimizer);
84  result << reportStatus(minimizer);
85 
86  return result.str();
87 }
Declares class MinimizerAdapter.
Declares namespace MinimizerUtils.
Declares report namespace.
Abstract base class that adapts the CERN ROOT minimizer to our IMinimizer.
std::string algorithmName() const override
Returns name of the minimization algorithm.
virtual std::map< std::string, std::string > statusMap() const
Returns map of string representing different minimizer statuses.
std::string minimizerName() const override
Returns name of the minimizer.
MinimizerOptions & options()
std::string toOptionString() const
Returns string with all options (i.e. "Strategy=1;Tolerance=0.01;")
bool empty() const
std::string reportToString(const MinimizerAdapter &minimizer)
Reports results of minimization in the form of multi-line string.
Definition: Report.cpp:77
std::string sectionString(const std::string &sectionName="", size_t report_width=80)
Returns horizontal line of 80 characters length with section name in it.