OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
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 
33 template <class T = double, unsigned Dim = 3>
34 class PartBunchBase;
35 
36 class AttributeBase;
37 class Object;
38 class Table;
39 class ValueDefinition;
40 class DataSink;
41 class BoundaryGeometry;
42 
43 // store element name, max phase
44 typedef std::pair<std::string, double > MaxPhasesT;
45 typedef std::map<double, double> energyEvolution_t;
46 
47 
49 class OpalData {
50 
51 public:
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 {
65  WRITE,
66  APPEND,
67  UNDEFINED
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 NULL.
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  // Register the table [b]t[/b].
112  // Registered tables are invalidated to be refilled when an object
113  // on which they depend is changed or replaced.
114  void registerTable(Table *t);
115 
117  void unregisterTable(Table *t);
118 
120  // Registered expressions are invalidated to be recomputed when
121  // any object in the directory is changed or replaced.
123 
126 
128  void setP0(ValueDefinition *p0);
129 
131  void storeTitle(const std::string &);
132 
134  void printTitle(std::ostream &);
135 
137  std::string getTitle();
138 
140  // Loop over the directory and notify all objects to update themselves.
141  void update();
142 
144  // This functor is used to clear the reference count stored in an object.
146  virtual void operator()(Object *) const;
147  };
148 
149  std::map<std::string, std::string> getVariableData();
150  std::vector<std::string> getVariableNames();
151 
152  bool isInOPALCyclMode();
153  bool isInOPALTMode();
154  bool isOptimizerRun();
155 
156  void setInOPALCyclMode();
157  void setInOPALTMode();
158  void setOptimizerFlag();
159 
160  bool isInPrepState();
161  void setInPrepState(bool state);
162 
164  bool hasPriorTrack();
165 
167  void setPriorTrack(const bool &value = true);
168 
170  bool inRestartRun();
171 
173  void setRestartRun(const bool &value = true);
174 
176  void setRestartStep(int s);
177 
179  int getRestartStep();
180 
182  std::string getAuxiliaryOutputDirectory() const;
183 
185  std::string getInputFn();
186 
188  std::string getInputBasename();
189 
191  void storeInputFn(const std::string &fn);
192 
194  void checkAndAddOutputFileName(const std::string &outfn);
195 
197  std::string getRestartFileName();
198 
200  void setRestartFileName(std::string s);
201 
203  bool hasRestartFile();
204 
206  void setRestartDumpFreq(const int &N);
207 
209  int getRestartDumpFreq() const;
210 
211  void setOpenMode(OPENMODE openMode);
212  OPENMODE getOpenMode() const;
213 
215  void setLastStep(const int &step);
216 
218  int getLastStep() const;
219 
221  bool hasBunchAllocated();
222 
223  void bunchIsAllocated();
224 
226 
228 
230  bool hasDataSinkAllocated();
231 
233 
234  void setDataSink(DataSink *s);
235 
237  void setGlobalPhaseShift(double shift);
239  double getGlobalPhaseShift();
240 
245 
246  bool hasGlobalGeometry();
247 
248  void setMaxPhase(std::string elName, double phi);
249 
252  int getNumberOfMaxPhases();
253 
254  void addEnergyData(double spos, double ekin);
257 
258  unsigned long long getMaxTrackSteps();
259  void setMaxTrackSteps(unsigned long long s);
260  void incMaxTrackSteps(unsigned long long s);
261 
262  void addProblemCharacteristicValue(const std::string &name, unsigned int value);
263  const std::map<std::string, unsigned int> &getProblemCharacteristicValues() const;
264 
265  void storeArguments(int argc, char *argv[]);
266  std::vector<std::string> getArguments();
267 
268 private:
269 
270  static bool isInstantiated;
272  static std::stack<OpalData*> stashedInstances;
273 
274  OpalData();
275 
276  // Not implemented.
277  OpalData(const OpalData &);
278  void operator=(const OpalData &);
279 
280  // The private implementation details.
281  struct OpalDataImpl *p;
282 };
283 
284 //extern OpalData OPAL;
285 
286 #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:409
DataSink * getDataSink()
Definition: OpalData.cpp:389
void storeTitle(const std::string &)
Store the page title.
Definition: OpalData.cpp:634
double getP0() const
Return value of global reference momentum.
Definition: OpalData.cpp:569
int getLastStep() const
get the last step from a possible previous run
Definition: OpalData.cpp:360
void setOpenMode(OPENMODE openMode)
Definition: OpalData.cpp:348
void registerExpression(AttributeBase *)
Register expression.
Definition: OpalData.cpp:622
int getNumberOfMaxPhases()
Definition: OpalData.cpp:405
unsigned long long getMaxTrackSteps()
Definition: OpalData.cpp:235
void storeInputFn(const std::string &fn)
store opals input filename
Definition: OpalData.cpp:638
bool hasGlobalGeometry()
Definition: OpalData.cpp:464
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:548
std::string getInputBasename()
get input file name without extension
Definition: OpalData.cpp:658
void makeDirty(Object *object)
Invalidate expressions.
Definition: OpalData.cpp:574
void operator=(const OpalData &)
bool isInOPALTMode()
Definition: OpalData.cpp:275
OPENMODE getOpenMode() const
Definition: OpalData.cpp:352
void setP0(ValueDefinition *p0)
Set the global momentum.
Definition: OpalData.cpp:630
double getGlobalPhaseShift()
units: (sec)
Definition: OpalData.cpp:451
bool isOptimizerRun()
Definition: OpalData.cpp:279
std::map< std::string, std::string > getVariableData()
Definition: OpalData.cpp:700
struct OpalDataImpl * p
Definition: OpalData.h:281
void setOptimizerFlag()
Definition: OpalData.cpp:291
bool isInPrepState()
Definition: OpalData.cpp:295
std::string getTitle()
Get the title string.
Definition: OpalData.cpp:646
void checkAndAddOutputFileName(const std::string &outfn)
checks the output file names of all items to avoid duplicates
Definition: OpalData.cpp:664
void setPartBunch(PartBunchBase< double, 3 > *p)
Definition: OpalData.cpp:372
std::vector< MaxPhasesT >::iterator getFirstMaxPhases()
Definition: OpalData.cpp:397
void printNames(std::ostream &stream, const std::string &pattern)
Print all objects.
Definition: OpalData.cpp:579
void setInOPALCyclMode()
Definition: OpalData.cpp:283
void update()
Update all objects.
Definition: OpalData.cpp:674
bool isInOPALCyclMode()
Definition: OpalData.cpp:271
void apply(const ObjectFunction &)
Apply a function to all objects.
Definition: OpalData.cpp:468
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:759
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:654
void bunchIsAllocated()
Definition: OpalData.cpp:368
void unregisterExpression(AttributeBase *)
Unregister expression.
Definition: OpalData.cpp:626
OPENMODE
Enum for writing to files.
Definition: OpalData.h:64
Object * find(const std::string &name)
Find entry.
Definition: OpalData.cpp:565
bool hasPriorTrack()
true if in follow-up track
Definition: OpalData.cpp:303
static std::stack< OpalData * > stashedInstances
Definition: OpalData.h:272
int getRestartStep()
get the step where to restart
Definition: OpalData.cpp:323
void create(Object *newObject)
Create new object.
Definition: OpalData.cpp:475
static OpalData * instance
Definition: OpalData.h:271
void printTitle(std::ostream &)
Print the page title.
Definition: OpalData.cpp:642
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
bool hasDataSinkAllocated()
true if we already allocated a DataSink object
Definition: OpalData.cpp:380
void setGlobalPhaseShift(double shift)
units: (sec)
Definition: OpalData.cpp:446
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:614
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:752
void setInOPALTMode()
Definition: OpalData.cpp:287
static bool isInstantiated
Definition: OpalData.h:270
BoundaryGeometry * getGlobalGeometry()
Definition: OpalData.cpp:460
void define(Object *newObject)
Define a new object.
Definition: OpalData.cpp:488
energyEvolution_t::iterator getLastEnergyData()
Definition: OpalData.cpp:417
void setRestartStep(int s)
store the location where to restart
Definition: OpalData.cpp:319
void setGlobalGeometry(BoundaryGeometry *bg)
Definition: OpalData.cpp:456
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:610
std::string getAuxiliaryOutputDirectory() const
get the name of the the additional data directory
Definition: OpalData.cpp:650
void addProblemCharacteristicValue(const std::string &name, unsigned int value)
Definition: OpalData.cpp:740
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:748
PartBunchBase< double, 3 > * getPartBunch()
Definition: OpalData.cpp:376
std::vector< std::string > getVariableNames()
Definition: OpalData.cpp:720
Clear Reference.
Definition: OpalData.h:145
virtual void operator()(Object *) const
The function to be executed.
Definition: OpalData.cpp:53
The base class for all OPAL tables.
Definition: Table.h:42
The base class for all OPAL value definitions.