OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
OpalData.h
Go to the documentation of this file.
1//
2// Class OpalData
3// The global OPAL structure.
4// The OPAL object holds all global data required for a OPAL execution.
5// In particular it contains the main Directory, which allows retrieval
6// of command objects by their name. For other data refer to the
7// implementation file.
8//
9// Copyright (c) 200x - 2021, Paul Scherrer Institut, Villigen PSI, Switzerland
10// All rights reserved
11//
12// This file is part of OPAL.
13//
14// OPAL is free software: you can redistribute it and/or modify
15// it under the terms of the GNU General Public License as published by
16// the Free Software Foundation, either version 3 of the License, or
17// (at your option) any later version.
18//
19// You should have received a copy of the GNU General Public License
20// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
21//
22#ifndef OPAL_OpalData_HH
23#define OPAL_OpalData_HH
24
25#include <iosfwd>
26#include <map>
27#include <stack>
28#include <string>
29#include <vector>
31#include "OPALTypes.h"
32
33class AttributeBase;
34class Object;
35class Table;
36class ValueDefinition;
37class DataSink;
39
40// store element name, max phase
41typedef std::pair<std::string, double> MaxPhasesT;
42typedef std::map<double, double> energyEvolution_t;
43
45class OpalData {
46public:
47 static OpalData* getInstance();
48
49 static void deleteInstance();
50
51 static void stashInstance();
52
53 static OpalData* popInstance();
54
55 ~OpalData();
56
58 enum class OpenMode : unsigned short { UNDEFINED, WRITE, APPEND };
59
61 void reset();
62
64 // Loop over the directory and apply the given functor object to each
65 // object in turn.
66 void apply(const ObjectFunction&);
67
69 // No replacement is allowed; if an object with the same name exists,
70 // throw [b]OpalException[/b].
71 void create(Object* newObject);
72
74 // Replacement is allowed; however [b]OpalException[/b] is thrown,
75 // if the replacement cannot be done.
76 void define(Object* newObject);
77
79 // Identified by [b]name[/b].
80 void erase(const std::string& name);
81
83 // Identified by [b]name[/b].
84 Object* find(const std::string& name);
85
87 double getP0() const;
88
90 // Force re-evaluation of all expressions before next command is
91 // executed.
92 // Also set the [b]modified[/b] flag in [b]object[/b], if not nullptr.
93 void makeDirty(Object* object);
94
96 // Loop over the directory and print each object whose name matches
97 // the regular expression [b]pattern[/b].
98 void printNames(std::ostream& stream, const std::string& pattern);
99 void printAllNames(std::ostream& stream);
100
102 // Register the table [b]t[/b].
103 // Registered tables are invalidated to be refilled when an object
104 // on which they depend is changed or replaced.
105 void registerTable(Table* t);
106
108 void unregisterTable(Table* t);
109
111 // Registered expressions are invalidated to be recomputed when
112 // any object in the directory is changed or replaced.
114
117
119 void setP0(ValueDefinition* p0);
120
122 void storeTitle(const std::string&);
123
125 void printTitle(std::ostream&);
126
128 std::string getTitle();
129
131 // Loop over the directory and notify all objects to update themselves.
132 void update();
133
135 // This functor is used to clear the reference count stored in an object.
137 virtual void operator()(Object*) const;
138 };
139
140 std::map<std::string, std::string> getVariableData();
141 std::vector<std::string> getVariableNames();
142
143 bool isInOPALCyclMode();
144 bool isInOPALTMode();
145 bool isOptimizerRun();
146
147 void setInOPALCyclMode();
148 void setInOPALTMode();
149 void setOptimizerFlag();
150
151 bool isInPrepState();
152 void setInPrepState(bool state);
153
155 bool hasPriorTrack();
156
158 void setPriorTrack(const bool& value = true);
159
161 bool inRestartRun();
162
164 void setRestartRun(const bool& value = true);
165
167 void setRestartStep(int s);
168
170 int getRestartStep();
171
173 std::string getAuxiliaryOutputDirectory() const;
174
176 std::string getInputFn();
177
179 std::string getInputBasename();
180
182 void storeInputFn(const std::string& fn);
183
185 void checkAndAddOutputFileName(const std::string& outfn);
186
188 std::string getRestartFileName();
189
191 void setRestartFileName(std::string s);
192
194 bool hasRestartFile();
195
197 void setRestartDumpFreq(const int& N);
198
200 int getRestartDumpFreq() const;
201
202 void setOpenMode(OpenMode openMode);
203 OpenMode getOpenMode() const;
204
206 void setLastStep(const int& step);
207
209 int getLastStep() const;
210
212 bool hasBunchAllocated();
213
214 void bunchIsAllocated();
215
217
219
222
224
225 void setDataSink(DataSink* s);
226
228 void setGlobalPhaseShift(double shift);
230 double getGlobalPhaseShift();
231
236
237 bool hasGlobalGeometry();
238
239 void setMaxPhase(std::string elName, double phi);
240
241 std::vector<MaxPhasesT>::iterator getFirstMaxPhases();
242 std::vector<MaxPhasesT>::iterator getLastMaxPhases();
244
245 void addEnergyData(double spos, double ekin);
246 energyEvolution_t::iterator getFirstEnergyData();
247 energyEvolution_t::iterator getLastEnergyData();
248
249 unsigned long long getMaxTrackSteps();
250 void setMaxTrackSteps(unsigned long long s);
251 void incMaxTrackSteps(unsigned long long s);
252
253 void addProblemCharacteristicValue(const std::string& name, unsigned int value);
254 const std::map<std::string, unsigned int>& getProblemCharacteristicValues() const;
255
256 void storeArguments(int argc, char* argv[]);
257 std::vector<std::string> getArguments();
258
259private:
260 static bool isInstantiated;
261 static OpalData* instance; // \todo should be a smart pointer and we then should get ridd of deleteInstance
262 static std::stack<OpalData*> stashedInstances;
263
264 OpalData();
265
266 // Not implemented.
268 void operator=(const OpalData&);
269
270 // The private implementation details.
272};
273
274// extern OpalData OPAL;
275
276#endif // OPAL_OpalData_HH
PartBunch< PLayout_t< double, 3 >, double, 3 > PartBunch_t
std::map< double, double > energyEvolution_t
Definition OpalData.h:42
std::pair< std::string, double > MaxPhasesT
Definition OpalData.h:41
Abstract base class for attribute values of different types.
The base class for all OPAL objects.
Definition Object.h:48
Abstract base class for functor objects whose argument is an Object.
void addEnergyData(double spos, double ekin)
Definition OpalData.cpp:409
void printAllNames(std::ostream &stream)
Definition OpalData.cpp:577
DataSink * getDataSink()
Definition OpalData.cpp:389
void storeTitle(const std::string &)
Store the page title.
Definition OpalData.cpp:661
double getP0() const
Return value of global reference momentum.
Definition OpalData.cpp:567
int getLastStep() const
get the last step from a possible previous run
Definition OpalData.cpp:360
void registerExpression(AttributeBase *)
Register expression.
Definition OpalData.cpp:649
int getNumberOfMaxPhases()
Definition OpalData.cpp:405
PartBunch_t * getPartBunch()
Definition OpalData.cpp:376
unsigned long long getMaxTrackSteps()
Definition OpalData.cpp:235
void storeInputFn(const std::string &fn)
store opals input filename
Definition OpalData.cpp:665
void setPartBunch(PartBunch_t *p)
Definition OpalData.cpp:372
bool hasGlobalGeometry()
Definition OpalData.cpp:463
void setRestartDumpFreq(const int &N)
set the dump frequency as found in restart file
Definition OpalData.cpp:340
std::vector< MaxPhasesT >::iterator getLastMaxPhases()
Definition OpalData.cpp:401
void erase(const std::string &name)
Delete existing entry.
Definition OpalData.cpp:547
std::string getInputBasename()
get input file name without extension
Definition OpalData.cpp:685
void makeDirty(Object *object)
Invalidate expressions.
Definition OpalData.cpp:571
void operator=(const OpalData &)
bool isInOPALTMode()
Definition OpalData.cpp:275
void setP0(ValueDefinition *p0)
Set the global momentum.
Definition OpalData.cpp:657
double getGlobalPhaseShift()
units: (sec)
Definition OpalData.cpp:450
bool isOptimizerRun()
Definition OpalData.cpp:279
std::map< std::string, std::string > getVariableData()
Definition OpalData.cpp:726
struct OpalDataImpl * p
Definition OpalData.h:271
void setOptimizerFlag()
Definition OpalData.cpp:291
bool isInPrepState()
Definition OpalData.cpp:295
std::string getTitle()
Get the title string.
Definition OpalData.cpp:673
void checkAndAddOutputFileName(const std::string &outfn)
checks the output file names of all items to avoid duplicates
Definition OpalData.cpp:691
std::vector< MaxPhasesT >::iterator getFirstMaxPhases()
Definition OpalData.cpp:397
void printNames(std::ostream &stream, const std::string &pattern)
Print all objects.
Definition OpalData.cpp:606
void setInOPALCyclMode()
Definition OpalData.cpp:283
void update()
Update all objects.
Definition OpalData.cpp:701
bool isInOPALCyclMode()
Definition OpalData.cpp:271
void apply(const ObjectFunction &)
Apply a function to all objects.
Definition OpalData.cpp:467
bool hasRestartFile()
true if we do a restart from specified h5 file
Definition OpalData.cpp:336
void setRestartRun(const bool &value=true)
set OPAL in restart mode
Definition OpalData.cpp:315
void setMaxPhase(std::string elName, double phi)
Definition OpalData.cpp:393
void setLastStep(const int &step)
set the last step in a run for possible follow-up run
Definition OpalData.cpp:356
std::vector< std::string > getArguments()
Definition OpalData.cpp:787
static void stashInstance()
Definition OpalData.cpp:211
int getRestartDumpFreq() const
get the dump frequency as found in restart file
Definition OpalData.cpp:344
std::string getRestartFileName()
get opals restart h5 format filename
Definition OpalData.cpp:327
std::string getInputFn()
get opals input filename
Definition OpalData.cpp:681
void bunchIsAllocated()
Definition OpalData.cpp:368
void unregisterExpression(AttributeBase *)
Unregister expression.
Definition OpalData.cpp:653
Object * find(const std::string &name)
Find entry.
Definition OpalData.cpp:563
bool hasPriorTrack()
true if in follow-up track
Definition OpalData.cpp:303
static std::stack< OpalData * > stashedInstances
Definition OpalData.h:262
int getRestartStep()
get the step where to restart
Definition OpalData.cpp:323
void create(Object *newObject)
Create new object.
Definition OpalData.cpp:473
static OpalData * instance
Definition OpalData.h:261
void printTitle(std::ostream &)
Print the page title.
Definition OpalData.cpp:669
static void deleteInstance()
Definition OpalData.cpp:205
void setRestartFileName(std::string s)
store opals restart h5 format filename
Definition OpalData.cpp:331
void setInPrepState(bool state)
Definition OpalData.cpp:299
void setPriorTrack(const bool &value=true)
true if in follow-up track
Definition OpalData.cpp:307
void setDataSink(DataSink *s)
Definition OpalData.cpp:384
OpenMode getOpenMode() const
Definition OpalData.cpp:352
bool hasDataSinkAllocated()
true if we already allocated a DataSink object
Definition OpalData.cpp:380
void setGlobalPhaseShift(double shift)
units: (sec)
Definition OpalData.cpp:445
bool hasBunchAllocated()
true if we already allocated a ParticleBunch object
Definition OpalData.cpp:364
energyEvolution_t::iterator getFirstEnergyData()
Definition OpalData.cpp:413
void unregisterTable(Table *t)
Unregister table.
Definition OpalData.cpp:641
OpalData(const OpalData &)
void reset()
reset object for consecutive runs
Definition OpalData.cpp:255
static OpalData * getInstance()
Definition OpalData.cpp:195
void setMaxTrackSteps(unsigned long long s)
Definition OpalData.cpp:239
void storeArguments(int argc, char *argv[])
Definition OpalData.cpp:780
void setInOPALTMode()
Definition OpalData.cpp:287
static bool isInstantiated
Definition OpalData.h:260
BoundaryGeometry * getGlobalGeometry()
Definition OpalData.cpp:459
void define(Object *newObject)
Define a new object.
Definition OpalData.cpp:486
energyEvolution_t::iterator getLastEnergyData()
Definition OpalData.cpp:417
OpenMode
Enum for writing to files.
Definition OpalData.h:58
void setRestartStep(int s)
store the location where to restart
Definition OpalData.cpp:319
void setGlobalGeometry(BoundaryGeometry *bg)
Definition OpalData.cpp:455
void incMaxTrackSteps(unsigned long long s)
Definition OpalData.cpp:243
static OpalData * popInstance()
Definition OpalData.cpp:222
void registerTable(Table *t)
Register table.
Definition OpalData.cpp:637
std::string getAuxiliaryOutputDirectory() const
get the name of the the additional data directory
Definition OpalData.cpp:677
void addProblemCharacteristicValue(const std::string &name, unsigned int value)
Definition OpalData.cpp:768
void setOpenMode(OpenMode openMode)
Definition OpalData.cpp:348
bool inRestartRun()
true if we do a restart run
Definition OpalData.cpp:311
const std::map< std::string, unsigned int > & getProblemCharacteristicValues() const
Definition OpalData.cpp:776
std::vector< std::string > getVariableNames()
Definition OpalData.cpp:748
Clear Reference.
Definition OpalData.h:136
virtual void operator()(Object *) const
The function to be executed.
Definition OpalData.cpp:52
The base class for all OPAL tables.
Definition Table.h:42
The base class for all OPAL value definitions.