OpalData.h 6.5 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 25 26
#include <iosfwd>
#include <string>
#include <vector>

class PartBunch;
27
class EnvelopeBunch;
gsell's avatar
gsell committed
28 29 30 31 32
class AttributeBase;
class Object;
class Table;
class ValueDefinition;
class DataSink;
33
class BoundaryGeometry;
gsell's avatar
gsell committed
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

// store element name, max phase
typedef std::pair<std::string, double > MaxPhasesT;



// 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();

    ~OpalData();

    /// 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;
    };

    std::vector<std::string> getAllNames();

    /// 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();

    /// get opals input filename
    std::string getInputFn();

154 155 156
    /// get input file name without extension
    std::string getInputBasename();

gsell's avatar
gsell committed
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
    /// 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;

    /// 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();

    PartBunch *getPartBunch();

    void setPartBunch(PartBunch *p);

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

    DataSink *getDataSink();

    void setDataSink(DataSink *s);

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

    void slbunchIsAllocated();

    EnvelopeBunch *getSLPartBunch();

    void setSLPartBunch(EnvelopeBunch *p);

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

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

    void setMaxPhase(std::string elName, double phi);

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

222 223 224
    unsigned long long getMaxTrackSteps();
    void setMaxTrackSteps(unsigned long long s);
    void incMaxTrackSteps(unsigned long long s);
225

gsell's avatar
gsell committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
private:

    static bool isInstatiated;
    static OpalData *instance;

    OpalData();

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

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

//extern OpalData OPAL;

#endif // OPAL_OpalData_HH