RadialPeak.h 1.97 KB
Newer Older
adelmann's avatar
adelmann committed
1 2 3 4 5
#ifndef __RADIALPEAK_H__
#define __RADIALPEAK_H__

#include <string>

6
#include "boost/type_traits/remove_cv.hpp"
adelmann's avatar
adelmann committed
7 8 9 10 11 12 13 14 15 16
#include "boost/variant/get.hpp"
#include "boost/variant/variant.hpp"
#include "boost/smart_ptr.hpp"

#include "Util/Types.h"
#include "Util/PeakReader.h"
#include "Expression/Parser/function.hpp"

/**
 * A simple expression to get the n-th peak of a radial probe
17
 *
adelmann's avatar
adelmann committed
18 19
 */
struct RadialPeak {
20

adelmann's avatar
adelmann committed
21
    static const std::string name;
22

adelmann's avatar
adelmann committed
23
    Expressions::Result_t operator()(client::function::arguments_t args) {
24 25 26 27
        if (args.size() != 2) {
            throw OptPilotException("RadialPeak::operator()",
                                    "radialPeak expects 2 arguments, " + std::to_string(args.size()) + " given");
        }
adelmann's avatar
adelmann committed
28 29 30

        peak_filename_ = boost::get<std::string>(args[0]);
        turn_number_   = boost::get<double>(args[1]);
31

adelmann's avatar
adelmann committed
32
        bool is_valid = true;
33

adelmann's avatar
adelmann committed
34 35 36 37 38 39 40
        boost::scoped_ptr<PeakReader> sim_peaks(new PeakReader(peak_filename_));
        try {
            sim_peaks->parseFile();
        } catch (OptPilotException &ex) {
            std::cout << "Caught exception: " << ex.what() << std::endl;
            is_valid = false;
        }
41

adelmann's avatar
adelmann committed
42 43 44 45 46 47 48 49 50
        double sim_radius = 0.0;
        try {
            sim_peaks->getPeak(turn_number_, sim_radius);
        } catch(OptPilotException &e) {
            std::cout << "Exception while getting value "
                      << "from peak file: " << e.what()
                      << std::endl;
            is_valid = false;
        }
51

adelmann's avatar
adelmann committed
52 53
        return boost::make_tuple(sim_radius, is_valid);
    }
54

adelmann's avatar
adelmann committed
55
private:
56

adelmann's avatar
adelmann committed
57 58
    std::string peak_filename_;
    int turn_number_;
59

adelmann's avatar
adelmann committed
60 61
    // define a mapping to arguments in argument vector
    boost::tuple<std::string, int> argument_types;
gsell's avatar
gsell committed
62 63
    // :FIXME: remove unused enum
#if 0
adelmann's avatar
adelmann committed
64 65 66 67
    enum {
          peak_filename
        , turn_number
    } argument_type_id;
gsell's avatar
gsell committed
68
#endif
adelmann's avatar
adelmann committed
69 70 71
};

#endif
gsell's avatar
gsell committed
72 73 74 75
// vi: set et ts=4 sw=4 sts=4:
// Local Variables:
// mode:c
// c-basic-offset: 4
gsell's avatar
gsell committed
76 77 78
// indent-tabs-mode: nil
// require-final-newline: nil
// End: