OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
ProbeVariable.h
Go to the documentation of this file.
1 #ifndef __PROBEVARIABLE_H__
2 #define __PROBEVARIABLE_H__
3 
4 #include <string>
5 
6 #include "boost/variant/get.hpp"
7 #include "boost/variant/variant.hpp"
8 #include "boost/smart_ptr.hpp"
9 
10 #include "Util/Types.h"
11 #include "Util/ProbeReader.h"
13 
14 struct ProbeVariable {
15 
16  static const std::string name;
17 
19  if (args.size() != 3) {
20  throw OptPilotException("ProbeVariable::operator()",
21  "probeVariable expects 3 arguments, " + std::to_string(args.size()) + " given");
22  }
23 
24  var_name_ = boost::get<std::string>(args[0]);
25  id_ = boost::get<double>(args[1]); //FIXME Can't we use integer?
26  probe_filename_ = boost::get<std::string>(args[2]);
27 
28  bool is_valid = true;
29 
30  boost::scoped_ptr<ProbeReader> sim_probe(new ProbeReader(probe_filename_));
31 
32  try {
33  sim_probe->parseFile();
34  } catch (OptPilotException &ex) {
35  std::cout << "Caught exception: " << ex.what() << std::endl;
36  is_valid = false;
37  }
38 
39  double sim_value = 0.0;
40  try {
41  sim_probe->getVariableValue(id_, var_name_, sim_value);
42  } catch(OptPilotException &e) {
43  std::cout << "Exception while getting value "
44  << "from Probe file: " << e.what()
45  << std::endl;
46  is_valid = false;
47  }
48 
49  return boost::make_tuple(sim_value, is_valid);
50  }
51 
52 private:
53  std::string var_name_;
54  int id_;
55  std::string probe_filename_;
56 
57  // define a mapping to arguments in argument vector
58  boost::tuple<std::string, int, std::string> argument_types;
59  // :FIXME: unused
60 #if 0
61  enum {
62  var_name
63  , id
64  , probe_filename
65  } argument_type_id;
66 #endif
67 };
68 
69 #endif
virtual const char * what() const
constexpr double e
The value of .
Definition: Physics.h:40
static const std::string name
Definition: ProbeVariable.h:16
std::string var_name_
Definition: ProbeVariable.h:53
boost::tuple< double, bool > Result_t
Definition: Expression.h:37
std::string probe_filename_
Definition: ProbeVariable.h:55
boost::tuple< std::string, int, std::string > argument_types
Definition: ProbeVariable.h:58
std::vector< argument_t > arguments_t
Definition: function.hpp:19
Expressions::Result_t operator()(client::function::arguments_t args)
Definition: ProbeVariable.h:18
Inform & endl(Inform &inf)
Definition: Inform.cpp:42