OpalData.h 7.74 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#ifndef OPAL_OpalData_HH
#define OPAL_OpalData_HH

// ------------------------------------------------------------------------
// $RCSfile: OpalData.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1.4.2 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: OpalData
//
// ------------------------------------------------------------------------
//
// $Date: 2004/11/12 20:10:11 $
// $Author: adelmann $
//
// ------------------------------------------------------------------------
#include "AbstractObjects/ObjectFunction.h"
21

gsell's avatar
gsell committed
22 23 24
#include <iosfwd>
#include <string>
#include <vector>
25
#include <map>
26
#include <stack>
gsell's avatar
gsell committed
27

28 29 30
template <class T = double, unsigned Dim = 3>
class PartBunchBase;

gsell's avatar
gsell committed
31 32 33 34 35
class AttributeBase;
class Object;
class Table;
class ValueDefinition;
class DataSink;
36
class BoundaryGeometry;
gsell's avatar
gsell committed
37 38 39

// store element name, max phase
typedef std::pair<std::string, double > MaxPhasesT;
40
typedef std::map<double, double> energyEvolution_t;
gsell's avatar
gsell committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

// Class OpalData
// ------------------------------------------------------------------------
/// The global OPAL structure.
//  The OPAL object holds all global data required for an OPAL execution.
//  In particular it contains the main Directory, which allows retrieval
//  of command objects by their name.  For other data refer to the
//  implementation file.

class OpalData {

public:

    static OpalData *getInstance();

    static void deleteInstance();

58 59 60 61
    static void stashInstance();

    static OpalData *popInstance();

gsell's avatar
gsell committed
62 63
    ~OpalData();

64 65 66 67 68 69 70
    /// Enum for writing to files
    enum class OPENMODE {
        WRITE,
        APPEND,
        UNDEFINED
    };

gsell's avatar
gsell committed
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
    /// reset object for consecutive runs
    void reset();

    /// Apply a function to all objects.
    //  Loop over the directory and apply the given functor object to each
    //  object in turn.
    void apply(const ObjectFunction &);

    /// Create new object.
    //  No replacement is allowed; if an object with the same name exists,
    //  throw [b]OpalException[/b].
    void create(Object *newObject);

    /// Define a new object.
    //  Replacement is allowed; however [b]OpalException[/b] is thrown,
    //  if the replacement cannot be done.
    void define(Object *newObject);

    /// Delete existing entry.
    //  Identified by [b]name[/b].
    void erase(const std::string &name);

    /// Find entry.
    //  Identified by [b]name[/b].
    Object *find(const std::string &name);

    /// Return value of global reference momentum.
    double getP0() const;

    /// Invalidate expressions.
    //  Force re-evaluation of all expressions before next command is
    //  executed.
    //  Also set the [b]modified[/b] flag in [b]object[/b], if not NULL.
    void makeDirty(Object *object);

    /// Print all objects.
    //  Loop over the directory and print each object whose name matches
    //  the regular expression [b]pattern[/b].
    void printNames(std::ostream &stream, const std::string &pattern);

    /// Register table.
    //  Register the table [b]t[/b].
    //  Registered tables are invalidated to be refilled when an object
    //  on which they depend is changed or replaced.
    void registerTable(Table *t);

    /// Unregister table.
    void unregisterTable(Table *t);

    /// Register expression.
    //  Registered expressions are invalidated to be recomputed when
    //  any object in the directory is changed or replaced.
    void registerExpression(AttributeBase *);

    /// Unregister expression.
    void unregisterExpression(AttributeBase *);

    /// Set the global momentum.
    void setP0(ValueDefinition *p0);

    /// Store the page title.
    void storeTitle(const std::string &);

    /// Print the page title.
    void printTitle(std::ostream &);

    /// Get the title string
    std::string getTitle();

    /// Update all objects.
    //  Loop over the directory and notify all objects to update themselves.
    void update();

    /// Clear Reference.
    //  This functor is used to clear the reference count stored in an object.
    struct ClearReference: public ObjectFunction {
        virtual void operator()(Object *) const;
    };

150
    std::map<std::string, std::string> getVariableData();
151
    std::vector<std::string> getVariableNames();
gsell's avatar
gsell committed
152

153 154
    bool isInOPALCyclMode();
    bool isInOPALTMode();
155
    bool isOptimizerRun();
156 157 158

    void setInOPALCyclMode();
    void setInOPALTMode();
159
    void setOptimizerFlag();
160

161 162 163 164 165 166 167 168 169
    bool isInPrepState();
    void setInPrepState(bool state);

    /// true if in follow-up track
    bool hasPriorTrack();

    /// true if in follow-up track
    void setPriorTrack(const bool &value = true);

gsell's avatar
gsell committed
170 171 172 173 174 175 176 177 178 179 180 181
    /// true if we do a restart run
    bool inRestartRun();

    /// set OPAL in restart mode
    void setRestartRun(const bool &value = true);

    /// store the location where to restart
    void setRestartStep(int s);

    /// get the step where to restart
    int getRestartStep();

frey_m's avatar
frey_m committed
182 183
    /// get the name of the the additional data directory
    std::string getAuxiliaryOutputDirectory() const;
184

gsell's avatar
gsell committed
185 186 187
    /// get opals input filename
    std::string getInputFn();

188 189 190
    /// get input file name without extension
    std::string getInputBasename();

gsell's avatar
gsell committed
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
    /// store opals input filename
    void storeInputFn(const std::string &fn);

    /// get opals restart h5 format filename
    std::string getRestartFileName();

    /// store opals restart h5 format filename
    void setRestartFileName(std::string s);

    /// true if we do a restart from specified h5 file
    bool hasRestartFile();

    /// set the dump frequency as found in restart file
    void setRestartDumpFreq(const int &N);

    /// get the dump frequency as found in restart file
    int getRestartDumpFreq() const;

209 210 211
    void setOpenMode(OPENMODE openMode);
    OPENMODE getOpenMode() const;

gsell's avatar
gsell committed
212 213 214 215 216 217 218 219 220 221 222
    /// set the last step in a run for possible follow-up run
    void setLastStep(const int &step);

    /// get the last step from a possible previous run
    int getLastStep() const;

    /// true if we already allocated a ParticleBunch object
    bool hasBunchAllocated();

    void bunchIsAllocated();

223
    PartBunchBase<double, 3> *getPartBunch();
gsell's avatar
gsell committed
224

225
    void setPartBunch(PartBunchBase<double, 3> *p);
gsell's avatar
gsell committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243

    /// true if we already allocated a DataSink object
    bool hasDataSinkAllocated();

    DataSink *getDataSink();

    void setDataSink(DataSink *s);

    /// units: (sec)
    void   setGlobalPhaseShift(double shift);
    /// units: (sec)
    double getGlobalPhaseShift();

    ///
    void setGlobalGeometry(BoundaryGeometry *bg);
    ///
    BoundaryGeometry *getGlobalGeometry();

244

245
    bool hasGlobalGeometry();
246

gsell's avatar
gsell committed
247 248 249 250 251 252
    void setMaxPhase(std::string elName, double phi);

    std::vector<MaxPhasesT>::iterator getFirstMaxPhases();
    std::vector<MaxPhasesT>::iterator getLastMaxPhases();
    int getNumberOfMaxPhases();

253 254 255 256
    void addEnergyData(double spos, double ekin);
    energyEvolution_t::iterator getFirstEnergyData();
    energyEvolution_t::iterator getLastEnergyData();

257 258 259
    unsigned long long getMaxTrackSteps();
    void setMaxTrackSteps(unsigned long long s);
    void incMaxTrackSteps(unsigned long long s);
260

adelmann's avatar
adelmann committed
261 262 263
    void addProblemCharacteristicValue(const std::string &name, unsigned int value);
    const std::map<std::string, unsigned int> &getProblemCharacteristicValues() const;

264 265
    void storeArguments(int argc, char *argv[]);
    std::vector<std::string> getArguments();
frey_m's avatar
frey_m committed
266

gsell's avatar
gsell committed
267 268
private:

269
    static bool isInstantiated;
gsell's avatar
gsell committed
270
    static OpalData *instance;
271
    static std::stack<OpalData*> stashedInstances;
gsell's avatar
gsell committed
272 273 274 275 276 277 278 279 280 281 282 283 284

    OpalData();

    // Not implemented.
    OpalData(const OpalData &);
    void operator=(const OpalData &);

    // The private implementation details.
    struct OpalDataImpl *p;
};

//extern OpalData OPAL;

frey_m's avatar
frey_m committed
285
#endif // OPAL_OpalData_HH