OPAL (Object Oriented Parallel Accelerator Library)  2024.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 
33 template <class T = double, unsigned Dim = 3>
35 
36 class AttributeBase;
37 class Object;
38 class Table;
39 class ValueDefinition;
40 class DataSink;
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: 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 
234  bool hasDataSinkAllocated();
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 
256  int getNumberOfMaxPhases();
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 
272 private:
273 
274  static bool isInstantiated;
276  static std::stack<OpalData*> stashedInstances;
277 
278  OpalData();
279 
280  // Not implemented.
281  OpalData(const OpalData &);
282  void operator=(const OpalData &);
283 
284  // The private implementation details.
285  struct OpalDataImpl *p;
286 };
287 
288 //extern OpalData OPAL;
289 
290 #endif // OPAL_OpalData_HH
void setOpenMode(OpenMode openMode)
Definition: OpalData.cpp:349
int getRestartStep()
get the step where to restart
Definition: OpalData.cpp:324
int getLastStep() const
get the last step from a possible previous run
Definition: OpalData.cpp:361
The global OPAL structure.
Definition: OpalData.h:49
void setMaxTrackSteps(unsigned long long s)
Definition: OpalData.cpp:240
static OpalData * getInstance()
Definition: OpalData.cpp:196
bool hasDataSinkAllocated()
true if we already allocated a DataSink object
Definition: OpalData.cpp:381
void setP0(ValueDefinition *p0)
Set the global momentum.
Definition: OpalData.cpp:646
The base class for all OPAL objects.
Definition: Object.h:48
void setInPrepState(bool state)
Definition: OpalData.cpp:300
double getGlobalPhaseShift()
units: (sec)
Definition: OpalData.cpp:452
std::vector< std::string > getVariableNames()
Definition: OpalData.cpp:736
void setGlobalPhaseShift(double shift)
units: (sec)
Definition: OpalData.cpp:447
void update()
Update all objects.
Definition: OpalData.cpp:690
void setLastStep(const int &step)
set the last step in a run for possible follow-up run
Definition: OpalData.cpp:357
energyEvolution_t::iterator getFirstEnergyData()
Definition: OpalData.cpp:414
bool hasBunchAllocated()
true if we already allocated a ParticleBunch object
Definition: OpalData.cpp:365
void define(Object *newObject)
Define a new object.
Definition: OpalData.cpp:489
static OpalData * popInstance()
Definition: OpalData.cpp:223
void setGlobalGeometry(BoundaryGeometry *bg)
Definition: OpalData.cpp:457
void setMaxPhase(std::string elName, double phi)
Definition: OpalData.cpp:394
void printTitle(std::ostream &)
Print the page title.
Definition: OpalData.cpp:658
std::string getTitle()
Get the title string.
Definition: OpalData.cpp:662
void makeDirty(Object *object)
Invalidate expressions.
Definition: OpalData.cpp:579
std::vector< std::string > getArguments()
Definition: OpalData.cpp:775
The base class for all OPAL tables.
Definition: Table.h:42
static void deleteInstance()
Definition: OpalData.cpp:206
std::string getInputFn()
get opals input filename
Definition: OpalData.cpp:670
void setRestartStep(int s)
store the location where to restart
Definition: OpalData.cpp:320
std::string getRestartFileName()
get opals restart h5 format filename
Definition: OpalData.cpp:328
bool inRestartRun()
true if we do a restart run
Definition: OpalData.cpp:312
void bunchIsAllocated()
Definition: OpalData.cpp:369
virtual void operator()(Object *) const
The function to be executed.
Definition: OpalData.cpp:54
void checkAndAddOutputFileName(const std::string &outfn)
checks the output file names of all items to avoid duplicates
Definition: OpalData.cpp:680
BoundaryGeometry * getGlobalGeometry()
Definition: OpalData.cpp:461
int getNumberOfMaxPhases()
Definition: OpalData.cpp:406
void storeTitle(const std::string &)
Store the page title.
Definition: OpalData.cpp:650
void reset()
reset object for consecutive runs
Definition: OpalData.cpp:256
void setInOPALTMode()
Definition: OpalData.cpp:288
void create(Object *newObject)
Create new object.
Definition: OpalData.cpp:476
static std::stack< OpalData * > stashedInstances
Definition: OpalData.h:276
void setRestartRun(const bool &value=true)
set OPAL in restart mode
Definition: OpalData.cpp:316
std::vector< MaxPhasesT >::iterator getLastMaxPhases()
Definition: OpalData.cpp:402
std::vector< std::string > getAllNames() const
Get a list of all objects.
Definition: OpalData.cpp:615
std::string::iterator iterator
Definition: MSLang.h:15
void operator=(const OpalData &)
bool hasRestartFile()
true if we do a restart from specified h5 file
Definition: OpalData.cpp:337
std::string getAuxiliaryOutputDirectory() const
get the name of the the additional data directory
Definition: OpalData.cpp:666
void unregisterTable(Table *t)
Unregister table.
Definition: OpalData.cpp:630
DataSink * getDataSink()
Definition: OpalData.cpp:390
static void stashInstance()
Definition: OpalData.cpp:212
void setRestartDumpFreq(const int &N)
set the dump frequency as found in restart file
Definition: OpalData.cpp:341
void unregisterExpression(AttributeBase *)
Unregister expression.
Definition: OpalData.cpp:642
std::map< std::string, std::string > getVariableData()
Definition: OpalData.cpp:716
void apply(const ObjectFunction &)
Apply a function to all objects.
Definition: OpalData.cpp:469
void printNames(std::ostream &stream, const std::string &pattern)
Print all objects.
Definition: OpalData.cpp:584
OpenMode
Enum for writing to files.
Definition: OpalData.h:64
bool isInPrepState()
Definition: OpalData.cpp:296
Clear Reference.
Definition: OpalData.h:149
static bool isInstantiated
Definition: OpalData.h:274
void addEnergyData(double spos, double ekin)
Definition: OpalData.cpp:410
Abstract base class for attribute values of different types.
Definition: AttributeBase.h:32
double getP0() const
Return value of global reference momentum.
Definition: OpalData.cpp:575
void setOptimizerFlag()
Definition: OpalData.cpp:292
OpenMode getOpenMode() const
Definition: OpalData.cpp:353
void storeArguments(int argc, char *argv[])
Definition: OpalData.cpp:768
bool isInOPALTMode()
Definition: OpalData.cpp:276
bool isOptimizerRun()
Definition: OpalData.cpp:280
The base class for all OPAL value definitions.
void setDataSink(DataSink *s)
Definition: OpalData.cpp:385
const std::string name
std::vector< MaxPhasesT >::iterator getFirstMaxPhases()
Definition: OpalData.cpp:398
struct OpalDataImpl * p
Definition: OpalData.h:285
PartBunchBase< double, 3 > * getPartBunch()
Definition: OpalData.cpp:377
void addProblemCharacteristicValue(const std::string &name, unsigned int value)
Definition: OpalData.cpp:756
std::string getInputBasename()
get input file name without extension
Definition: OpalData.cpp:674
unsigned long long getMaxTrackSteps()
Definition: OpalData.cpp:236
bool isInOPALCyclMode()
Definition: OpalData.cpp:272
Object * find(const std::string &name)
Find entry.
Definition: OpalData.cpp:571
void storeInputFn(const std::string &fn)
store opals input filename
Definition: OpalData.cpp:654
void erase(const std::string &name)
Delete existing entry.
Definition: OpalData.cpp:554
void setPartBunch(PartBunchBase< double, 3 > *p)
Definition: OpalData.cpp:373
Abstract base class for functor objects whose argument is an Object.
std::map< double, double > energyEvolution_t
Definition: OpalData.h:45
int getRestartDumpFreq() const
get the dump frequency as found in restart file
Definition: OpalData.cpp:345
void registerExpression(AttributeBase *)
Register expression.
Definition: OpalData.cpp:638
void registerTable(Table *t)
Register table.
Definition: OpalData.cpp:626
std::pair< std::string, double > MaxPhasesT
Definition: OpalData.h:41
energyEvolution_t::iterator getLastEnergyData()
Definition: OpalData.cpp:418
void setInOPALCyclMode()
Definition: OpalData.cpp:284
void incMaxTrackSteps(unsigned long long s)
Definition: OpalData.cpp:244
void setPriorTrack(const bool &value=true)
true if in follow-up track
Definition: OpalData.cpp:308
const std::map< std::string, unsigned int > & getProblemCharacteristicValues() const
Definition: OpalData.cpp:764
static OpalData * instance
Definition: OpalData.h:275
bool hasPriorTrack()
true if in follow-up track
Definition: OpalData.cpp:304
void setRestartFileName(std::string s)
store opals restart h5 format filename
Definition: OpalData.cpp:332
bool hasGlobalGeometry()
Definition: OpalData.cpp:465