OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
SumErrSqRadialPeak.h
Go to the documentation of this file.
1 #ifndef __SUMERRSQRADIALPEAK_H__
2 #define __SUMERRSQRADIALPEAK_H__
3 
4 #include <string>
5 
6 #include "boost/type_traits/remove_cv.hpp"
7 #include "boost/variant/get.hpp"
8 #include "boost/variant/variant.hpp"
9 #include "boost/smart_ptr.hpp"
10 
11 #include "Util/Types.h"
12 #include "Util/PeakReader.h"
14 
26 
27  static const std::string name;
28 
30  if (args.size() != 4) {
31  throw OptPilotException("SumErrSqRadialPeak::operator()",
32  "sumErrSqRadialPeak expects 4 arguments, " + std::to_string(args.size()) + " given");
33  }
34 
35  meas_filename_ = boost::get<std::string>(args[0]);
36  sim_filename_ = boost::get<std::string>(args[1]);
37  begin_ = boost::get<double>(args[2]);
38  end_ = boost::get<double>(args[3]);
39 
40  bool is_valid = true;
41 
42  boost::scoped_ptr<PeakReader> meas_peaks(new PeakReader(meas_filename_));
43  boost::scoped_ptr<PeakReader> sim_peaks(new PeakReader(sim_filename_));
44  try {
45  sim_peaks->parseFile();
46  meas_peaks->parseFile();
47 
48  if ( end_ < begin_ || end_ < 0 || begin_ < 0 )
49  throw OptPilotException("SumErrSqRadialPeak::operator()",
50  "Error check turn number range");
51 
52  } catch (OptPilotException &ex) {
53  std::cout << "Caught exception: " << ex.what() << std::endl;
54  is_valid = false;
55  }
56 
57  double sum = 0;
58  int nPeaks = end_ - begin_ + 1;
59 
60  for (int turn = begin_; turn < end_ + 1; ++turn) {
61  double sim_value = 0.0, meas_value = 0.0;
62  try {
63  sim_peaks->getPeak(turn, sim_value);
64  meas_peaks->getPeak(turn, meas_value);
65  } catch(OptPilotException &e) {
66  std::cout << "Exception while getting value "
67  << "from peak file: " << e.what()
68  << std::endl;
69  is_valid = false;
70  }
71  double val = meas_value - sim_value;
72  sum += val * val;
73  }
74 
75  return boost::make_tuple(std::sqrt(sum) / (double)nPeaks, is_valid);
76  }
77 
78 private:
79  std::string meas_filename_;
80  std::string sim_filename_;
81  int begin_;
82  int end_;
83 
84  // define a mapping to arguments in argument vector
85  boost::tuple<std::string, std::string, int, int> argument_types;
86  // :FIXME: remove unused enum
87 #if 0
88  enum {
89  meas_filename
90  , sim_filename
91  , begin
92  , end
93  } argument_type_id;
94 #endif
95 };
96 
97 #endif
98 // vi: set et ts=4 sw=4 sts=4:
99 // Local Variables:
100 // mode:c
101 // c-basic-offset: 4
102 // indent-tabs-mode:nil
103 // End:
virtual const char * what() const
constexpr double e
The value of .
Definition: Physics.h:40
Expressions::Result_t operator()(client::function::arguments_t args)
T::PETE_Expr_t::PETE_Return_t sum(const PETE_Expr< T > &expr)
Definition: PETE.h:1213
boost::tuple< double, bool > Result_t
Definition: Expression.h:37
static const std::string name
std::string meas_filename_
std::vector< argument_t > arguments_t
Definition: function.hpp:19
Implements a parser and value extractor for peak files (*.peaks)
Definition: PeakReader.h:13
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
boost::tuple< std::string, std::string, int, int > argument_types
Inform & endl(Inform &inf)
Definition: Inform.cpp:42