OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
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
26
27#include <iosfwd>
28#include <string>
29#include <vector>
30#include <map>
31#include <stack>
32
33template <class T = double, unsigned Dim = 3>
34class PartBunchBase;
35
36class AttributeBase;
37class Object;
38class Table;
39class ValueDefinition;
40class DataSink;
42
43// store element name, max phase
44typedef std::pair<std::string, double > MaxPhasesT;
45typedef std::map<double, double> energyEvolution_t;
46
47
49class OpalData {
50
51public:
52
53 static OpalData *getInstance();
54
55 static void deleteInstance();
56
57 static void stashInstance();
58
59 static OpalData *popInstance();
60
61 ~OpalData();
62
64 enum class OpenMode: unsigned short {
65 UNDEFINED,
66 WRITE,
67 APPEND
68 };
69
71 void reset();
72
74 // Loop over the directory and apply the given functor object to each
75 // object in turn.
76 void apply(const ObjectFunction &);
77
79 // No replacement is allowed; if an object with the same name exists,
80 // throw [b]OpalException[/b].
81 void create(Object *newObject);
82
84 // Replacement is allowed; however [b]OpalException[/b] is thrown,
85 // if the replacement cannot be done.
86 void define(Object *newObject);
87
89 // Identified by [b]name[/b].
90 void erase(const std::string &name);
91
93 // Identified by [b]name[/b].
94 Object *find(const std::string &name);
95
97 double getP0() const;
98
100 // Force re-evaluation of all expressions before next command is
101 // executed.
102 // Also set the [b]modified[/b] flag in [b]object[/b], if not nullptr.
103 void makeDirty(Object *object);
104
106 // Loop over the directory and print each object whose name matches
107 // the regular expression [b]pattern[/b].
108 void printNames(std::ostream &stream, const std::string &pattern);
109
111 // Loop over the directory and return a list of names of all objects
112 std::vector<std::string> getAllNames() const;
113
115 // Register the table [b]t[/b].
116 // Registered tables are invalidated to be refilled when an object
117 // on which they depend is changed or replaced.
118 void registerTable(Table *t);
119
121 void unregisterTable(Table *t);
122
124 // Registered expressions are invalidated to be recomputed when
125 // any object in the directory is changed or replaced.
127
130
132 void setP0(ValueDefinition *p0);
133
135 void storeTitle(const std::string &);
136
138 void printTitle(std::ostream &);
139
141 std::string getTitle();
142
144 // Loop over the directory and notify all objects to update themselves.
145 void update();
146
148 // This functor is used to clear the reference count stored in an object.
150 virtual void operator()(Object *) const;
151 };
152
153 std::map<std::string, std::string> getVariableData();
154 std::vector<std::string> getVariableNames();
155
156 bool isInOPALCyclMode();
157 bool isInOPALTMode();
158 bool isOptimizerRun();
159
160 void setInOPALCyclMode();
161 void setInOPALTMode();
162 void setOptimizerFlag();
163
164 bool isInPrepState();
165 void setInPrepState(bool state);
166
168 bool hasPriorTrack();
169
171 void setPriorTrack(const bool &value = true);
172
174 bool inRestartRun();
175
177 void setRestartRun(const bool &value = true);
178
180 void setRestartStep(int s);
181
183 int getRestartStep();
184
186 std::string getAuxiliaryOutputDirectory() const;
187
189 std::string getInputFn();
190
192 std::string getInputBasename();
193
195 void storeInputFn(const std::string &fn);
196
198 void checkAndAddOutputFileName(const std::string &outfn);
199
201 std::string getRestartFileName();
202
204 void setRestartFileName(std::string s);
205
207 bool hasRestartFile();
208
210 void setRestartDumpFreq(const int &N);
211
213 int getRestartDumpFreq() const;
214
215 void setOpenMode(OpenMode openMode);
216 OpenMode getOpenMode() const;
217
219 void setLastStep(const int &step);
220
222 int getLastStep() const;
223
225 bool hasBunchAllocated();
226
227 void bunchIsAllocated();
228
230
232
235
237
238 void setDataSink(DataSink *s);
239
241 void setGlobalPhaseShift(double shift);
243 double getGlobalPhaseShift();
244
249
250 bool hasGlobalGeometry();
251
252 void setMaxPhase(std::string elName, double phi);
253
257
258 void addEnergyData(double spos, double ekin);
261
262 unsigned long long getMaxTrackSteps();
263 void setMaxTrackSteps(unsigned long long s);
264 void incMaxTrackSteps(unsigned long long s);
265
266 void addProblemCharacteristicValue(const std::string &name, unsigned int value);
267 const std::map<std::string, unsigned int> &getProblemCharacteristicValues() const;
268
269 void storeArguments(int argc, char *argv[]);
270 std::vector<std::string> getArguments();
271
272private:
273
274 static bool isInstantiated;
276 static std::stack<OpalData*> stashedInstances;
277
278 OpalData();
279
280 // Not implemented.
282 void operator=(const OpalData &);
283
284 // The private implementation details.
286};
287
288//extern OpalData OPAL;
289
290#endif // OPAL_OpalData_HH
std::map< double, double > energyEvolution_t
Definition: OpalData.h:45
std::pair< std::string, double > MaxPhasesT
Definition: OpalData.h:41
const std::string name
std::string::iterator iterator
Definition: MSLang.h:16
Abstract base class for attribute values of different types.
Definition: AttributeBase.h:32
The base class for all OPAL objects.
Definition: Object.h:48
Abstract base class for functor objects whose argument is an Object.
The global OPAL structure.
Definition: OpalData.h:49
void addEnergyData(double spos, double ekin)
Definition: OpalData.cpp:410
DataSink * getDataSink()
Definition: OpalData.cpp:390
void storeTitle(const std::string &)
Store the page title.
Definition: OpalData.cpp:645
double getP0() const
Return value of global reference momentum.
Definition: OpalData.cpp:570
int getLastStep() const
get the last step from a possible previous run
Definition: OpalData.cpp:361
void registerExpression(AttributeBase *)
Register expression.
Definition: OpalData.cpp:633
int getNumberOfMaxPhases()
Definition: OpalData.cpp:406
unsigned long long getMaxTrackSteps()
Definition: OpalData.cpp:236
void storeInputFn(const std::string &fn)
store opals input filename
Definition: OpalData.cpp:649
bool hasGlobalGeometry()
Definition: OpalData.cpp:465
void setRestartDumpFreq(const int &N)
set the dump frequency as found in restart file
Definition: OpalData.cpp:341
std::vector< MaxPhasesT >::iterator getLastMaxPhases()
Definition: OpalData.cpp:402
void erase(const std::string &name)
Delete existing entry.
Definition: OpalData.cpp:549
std::string getInputBasename()
get input file name without extension
Definition: OpalData.cpp:669
void makeDirty(Object *object)
Invalidate expressions.
Definition: OpalData.cpp:574
void operator=(const OpalData &)
bool isInOPALTMode()
Definition: OpalData.cpp:276
void setP0(ValueDefinition *p0)
Set the global momentum.
Definition: OpalData.cpp:641
double getGlobalPhaseShift()
units: (sec)
Definition: OpalData.cpp:452
bool isOptimizerRun()
Definition: OpalData.cpp:280
std::map< std::string, std::string > getVariableData()
Definition: OpalData.cpp:711
struct OpalDataImpl * p
Definition: OpalData.h:285
void setOptimizerFlag()
Definition: OpalData.cpp:292
bool isInPrepState()
Definition: OpalData.cpp:296
std::string getTitle()
Get the title string.
Definition: OpalData.cpp:657
void checkAndAddOutputFileName(const std::string &outfn)
checks the output file names of all items to avoid duplicates
Definition: OpalData.cpp:675
void setPartBunch(PartBunchBase< double, 3 > *p)
Definition: OpalData.cpp:373
std::vector< MaxPhasesT >::iterator getFirstMaxPhases()
Definition: OpalData.cpp:398
void printNames(std::ostream &stream, const std::string &pattern)
Print all objects.
Definition: OpalData.cpp:579
void setInOPALCyclMode()
Definition: OpalData.cpp:284
void update()
Update all objects.
Definition: OpalData.cpp:685
bool isInOPALCyclMode()
Definition: OpalData.cpp:272
void apply(const ObjectFunction &)
Apply a function to all objects.
Definition: OpalData.cpp:469
bool hasRestartFile()
true if we do a restart from specified h5 file
Definition: OpalData.cpp:337
void setRestartRun(const bool &value=true)
set OPAL in restart mode
Definition: OpalData.cpp:316
void setMaxPhase(std::string elName, double phi)
Definition: OpalData.cpp:394
void setLastStep(const int &step)
set the last step in a run for possible follow-up run
Definition: OpalData.cpp:357
std::vector< std::string > getArguments()
Definition: OpalData.cpp:770
static void stashInstance()
Definition: OpalData.cpp:212
int getRestartDumpFreq() const
get the dump frequency as found in restart file
Definition: OpalData.cpp:345
std::string getRestartFileName()
get opals restart h5 format filename
Definition: OpalData.cpp:328
std::string getInputFn()
get opals input filename
Definition: OpalData.cpp:665
void bunchIsAllocated()
Definition: OpalData.cpp:369
void unregisterExpression(AttributeBase *)
Unregister expression.
Definition: OpalData.cpp:637
Object * find(const std::string &name)
Find entry.
Definition: OpalData.cpp:566
bool hasPriorTrack()
true if in follow-up track
Definition: OpalData.cpp:304
static std::stack< OpalData * > stashedInstances
Definition: OpalData.h:276
int getRestartStep()
get the step where to restart
Definition: OpalData.cpp:324
void create(Object *newObject)
Create new object.
Definition: OpalData.cpp:476
static OpalData * instance
Definition: OpalData.h:275
void printTitle(std::ostream &)
Print the page title.
Definition: OpalData.cpp:653
static void deleteInstance()
Definition: OpalData.cpp:206
void setRestartFileName(std::string s)
store opals restart h5 format filename
Definition: OpalData.cpp:332
void setInPrepState(bool state)
Definition: OpalData.cpp:300
void setPriorTrack(const bool &value=true)
true if in follow-up track
Definition: OpalData.cpp:308
void setDataSink(DataSink *s)
Definition: OpalData.cpp:385
OpenMode getOpenMode() const
Definition: OpalData.cpp:353
std::vector< std::string > getAllNames() const
Get a list of all objects.
Definition: OpalData.cpp:610
bool hasDataSinkAllocated()
true if we already allocated a DataSink object
Definition: OpalData.cpp:381
void setGlobalPhaseShift(double shift)
units: (sec)
Definition: OpalData.cpp:447
bool hasBunchAllocated()
true if we already allocated a ParticleBunch object
Definition: OpalData.cpp:365
energyEvolution_t::iterator getFirstEnergyData()
Definition: OpalData.cpp:414
void unregisterTable(Table *t)
Unregister table.
Definition: OpalData.cpp:625
OpalData(const OpalData &)
void reset()
reset object for consecutive runs
Definition: OpalData.cpp:256
static OpalData * getInstance()
Definition: OpalData.cpp:196
void setMaxTrackSteps(unsigned long long s)
Definition: OpalData.cpp:240
void storeArguments(int argc, char *argv[])
Definition: OpalData.cpp:763
void setInOPALTMode()
Definition: OpalData.cpp:288
static bool isInstantiated
Definition: OpalData.h:274
BoundaryGeometry * getGlobalGeometry()
Definition: OpalData.cpp:461
void define(Object *newObject)
Define a new object.
Definition: OpalData.cpp:489
energyEvolution_t::iterator getLastEnergyData()
Definition: OpalData.cpp:418
OpenMode
Enum for writing to files.
Definition: OpalData.h:64
void setRestartStep(int s)
store the location where to restart
Definition: OpalData.cpp:320
void setGlobalGeometry(BoundaryGeometry *bg)
Definition: OpalData.cpp:457
void incMaxTrackSteps(unsigned long long s)
Definition: OpalData.cpp:244
static OpalData * popInstance()
Definition: OpalData.cpp:223
void registerTable(Table *t)
Register table.
Definition: OpalData.cpp:621
std::string getAuxiliaryOutputDirectory() const
get the name of the the additional data directory
Definition: OpalData.cpp:661
void addProblemCharacteristicValue(const std::string &name, unsigned int value)
Definition: OpalData.cpp:751
void setOpenMode(OpenMode openMode)
Definition: OpalData.cpp:349
bool inRestartRun()
true if we do a restart run
Definition: OpalData.cpp:312
const std::map< std::string, unsigned int > & getProblemCharacteristicValues() const
Definition: OpalData.cpp:759
PartBunchBase< double, 3 > * getPartBunch()
Definition: OpalData.cpp:377
std::vector< std::string > getVariableNames()
Definition: OpalData.cpp:731
Clear Reference.
Definition: OpalData.h:149
virtual void operator()(Object *) const
The function to be executed.
Definition: OpalData.cpp:54
The base class for all OPAL tables.
Definition: Table.h:42
The base class for all OPAL value definitions.