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