BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
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> std::string reportValue(const std::string& name, T value)
26 {
27  std::ostringstream result;
28  result << std::setw(column_width) << std::left << name << ": " << value << std::endl;
29  return result.str();
30 }
31 
32 std::string reportDescription(const MinimizerAdapter& minimizer)
33 {
34  std::ostringstream result;
35  result << reportValue("MinimizerType", minimizer.minimizerName());
36  result << reportValue("AlgorithmName", minimizer.algorithmName());
37  return result.str();
38 }
39 
40 std::string reportOption(const MinimizerAdapter& minimizer)
41 {
42  if (minimizer.options().empty())
43  return "";
44 
45  std::ostringstream result;
46  result << mumufit::utils::sectionString("Options");
47  for (auto option : minimizer.options()) {
48  std::ostringstream opt;
49  opt << std::setw(5) << std::left << option->value() << option->description();
50  result << reportValue(option->name(), opt.str());
51  }
52  result << mumufit::utils::sectionString("OptionString");
53  result << minimizer.options().toOptionString() << std::endl;
54 
55  return result.str();
56 }
57 
58 std::string reportStatus(const MinimizerAdapter& minimizer)
59 {
60  std::ostringstream result;
61  result << mumufit::utils::sectionString("Status");
62 
63  auto status = minimizer.statusMap();
64  for (auto it : status)
65  result << reportValue(it.first, it.second);
66 
67  return result.str();
68 }
69 
70 } // namespace
71 
72 // ************************************************************************************************
73 // implement API
74 // ************************************************************************************************
75 
77 {
78  std::ostringstream result;
79 
81  result << reportDescription(minimizer);
82  result << reportOption(minimizer);
83  result << reportStatus(minimizer);
84 
85  return result.str();
86 }
Declares class MinimizerAdapter.
Declares namespace MinimizerUtils.
Declares report namespace.
Abstract base class that adapts the CERN ROOT minimizer to our IMinimizer.
virtual std::map< std::string, std::string > statusMap() const
Returns map of string representing different minimizer statuses.
std::string minimizerName() const final
Returns name of the minimizer.
std::string algorithmName() const final
Returns name of the minimization algorithm.
MinimizerOptions & options()
std::string toOptionString() const
Returns string with all options (i.e. "Strategy=1;Tolerance=0.01;")
bool empty() const
QString const & name(EShape k)
Definition: particles.cpp:21
std::string reportToString(const MinimizerAdapter &minimizer)
Reports results of minimization in the form of multi-line string.
Definition: Report.cpp:76
std::string sectionString(const std::string &sectionName="", size_t report_width=80)
Returns horizontal line of 80 characters length with section name in it.