1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
/***********************************************/
/**
* @file program.h
*
* @brief Interface for applications in groops.
*
* @author Torsten Mayer-Guerr
* @date 2008-07-27
*
*/
/***********************************************/
#ifndef __GROOPS_PROGRAM__
#define __GROOPS_PROGRAM__
#include "base/import.h"
#include "inputOutput/logging.h"
#include "config/config.h"
#include "parallel/parallel.h"
/***** DEFINE **********************************/
#ifndef GROOPS_TAGS
#define GROOPS_TAGS(tag_, ...) enum Tags {tag_, __VA_ARGS__};
#endif
namespace Program
{
constexpr Bool SINGLEPROCESS = TRUE;
constexpr Bool PARALLEL = FALSE;
/** @brief Tags to desribe programs. Used in @a GROOPS_REGISTER_PROGRAM. */
GROOPS_TAGS(NONE,
Covariance,
DoodsonHarmonics,
Gnss,
Grace,
Gravityfield,
Grid,
Instrument,
KalmanFilter,
Matrix,
Misc,
Noise,
NormalEquation,
Orbit,
Plot,
PotentialCoefficients,
Preprocessing,
Residuals,
Simulation,
Slr,
SpatialTimeSeries,
Statistics,
System,
TimeSeries,
TimeSplines,
VariationalEquation,
/* others */
Conversion, Provisional, Deprecated)
extern const char *tagStrings[];
} // namespace Program
/***** DEFINE **********************************/
#ifndef DOCSTRING
#define DOCSTRING "" //"documentation is missing.\n"
// #warning ******** documentation is missing **********
#endif
/***** DEFINE **********************************/
/** @brief Register a program in schema and documentation.
* A list of tags (from @a GROOPS_TAGS) followed the @a _name of the program and the short @a _description.
* The first tag should agree with the first part of the name/directory.
* The list should also include tags for the output/input file formats. */
#define GROOPS_REGISTER_PROGRAM(_name, _parallel, _description, ...) \
namespace Program\
{\
class _Program##_name : public Program\
{\
public:\
std::string name() const {return #_name;}\
std::string description() const {return _description;}\
std::string documentation() const {return DOCSTRING;}\
std::vector<Tags> tags() const {return std::vector<Tags>{__VA_ARGS__};}\
Bool isSingleProcess() const {return _parallel;}\
void run(Config &config, Parallel::CommunicatorPtr comm) const\
{\
::_name tmp;\
if(!isSingleProcess())\
tmp.run(config, comm);\
else if(::Parallel::isMaster(comm))\
tmp.run(config, ::Parallel::selfCommunicator());\
}\
};\
static _Program##_name program##_name;\
}\
// end macro
/***** DEFINE **********************************/
/** @brief Register an old name of a renamed program.
* This macro can be used to keep old config files working. */
#define GROOPS_RENAMED_PROGRAM(_oldname, _newname, _time) \
namespace Program\
{\
class _RenamedProgram##_oldname : public RenamedProgram\
{\
public:\
_RenamedProgram##_oldname(const Renamed &renamed) : RenamedProgram(renamed) {}\
};\
static _RenamedProgram##_oldname renamedprogram##_oldname(RenamedProgram::Renamed(#_oldname, #_newname, _time));\
}\
// end macro
/***** CLASS ***********************************/
namespace Program
{
/** @brief Interface for applications in groops.
* @ingroup programsGroup
* An application must implement a @a run(Config &config) function. */
class Program
{
public:
Program() {programList(this);}
virtual ~Program() {}
virtual std::string name() const = 0;
virtual std::string description() const = 0;
virtual std::string documentation() const = 0;
virtual std::vector<Tags> tags() const = 0;
virtual Bool isSingleProcess() const = 0;
virtual void run(Config &config, Parallel::CommunicatorPtr comm) const = 0;
static std::vector<Program*> programList(Program *program=nullptr);
static void sortList(std::vector<Program*> &list);
};
/***** CLASS ***********************************/
/** @brief Interface for renamed applications.
* @ingroup programsGroup */
class RenamedProgram
{
public:
class Renamed
{
public:
std::string oldName;
std::string newName;
Time time;
Renamed(const std::string &oldName_, const std::string &newName_, const Time &time_) : oldName(oldName_), newName(newName_), time(time_) {}
};
RenamedProgram(const Renamed &renamed) {renamedList(renamed);}
virtual ~RenamedProgram() {}
static std::vector<Renamed> renamedList(const Renamed &renamed = Renamed("", "", Time()));
};
} // namespace Program
/***********************************************/
#endif /* __GROOPS__ */
|