OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalData.h
Go to the documentation of this file.
1 #ifndef OPAL_OpalData_HH
2 #define OPAL_OpalData_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: OpalData.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.1.1.1.4.2 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Class: OpalData
13 //
14 // ------------------------------------------------------------------------
15 //
16 // $Date: 2004/11/12 20:10:11 $
17 // $Author: adelmann $
18 //
19 // ------------------------------------------------------------------------
21 
22 #include <iosfwd>
23 #include <string>
24 #include <vector>
25 #include <map>
26 #include <stack>
27 
28 template <class T = double, unsigned Dim = 3>
30 
31 class EnvelopeBunch;
32 class AttributeBase;
33 class Object;
34 class Table;
35 class ValueDefinition;
36 class DataSink;
38 
39 // store element name, max phase
40 typedef std::pair<std::string, double > MaxPhasesT;
41 typedef std::map<double, double> energyEvolution_t;
43 
44 
45 
46 // Class OpalData
47 // ------------------------------------------------------------------------
49 // The OPAL object holds all global data required for an OPAL execution.
50 // In particular it contains the main Directory, which allows retrieval
51 // of command objects by their name. For other data refer to the
52 // implementation file.
53 
54 class OpalData {
55 
56 public:
57 
58  static OpalData *getInstance();
59 
60  static void deleteInstance();
61 
62  static void stashInstance();
63 
64  static OpalData *popInstance();
65 
66  ~OpalData();
67 
69  enum class OPENMODE {
70  WRITE,
71  APPEND,
72  UNDEFINED
73  };
74 
76  void reset();
77 
79  // Loop over the directory and apply the given functor object to each
80  // object in turn.
81  void apply(const ObjectFunction &);
82 
84  // No replacement is allowed; if an object with the same name exists,
85  // throw [b]OpalException[/b].
86  void create(Object *newObject);
87 
89  // Replacement is allowed; however [b]OpalException[/b] is thrown,
90  // if the replacement cannot be done.
91  void define(Object *newObject);
92 
94  // Identified by [b]name[/b].
95  void erase(const std::string &name);
96 
98  // Identified by [b]name[/b].
99  Object *find(const std::string &name);
100 
102  double getP0() const;
103 
105  // Force re-evaluation of all expressions before next command is
106  // executed.
107  // Also set the [b]modified[/b] flag in [b]object[/b], if not NULL.
108  void makeDirty(Object *object);
109 
111  // Loop over the directory and print each object whose name matches
112  // the regular expression [b]pattern[/b].
113  void printNames(std::ostream &stream, const std::string &pattern);
114 
116  // Register the table [b]t[/b].
117  // Registered tables are invalidated to be refilled when an object
118  // on which they depend is changed or replaced.
119  void registerTable(Table *t);
120 
122  void unregisterTable(Table *t);
123 
125  // Registered expressions are invalidated to be recomputed when
126  // any object in the directory is changed or replaced.
128 
131 
133  void setP0(ValueDefinition *p0);
134 
136  void storeTitle(const std::string &);
137 
139  void printTitle(std::ostream &);
140 
142  std::string getTitle();
143 
145  // Loop over the directory and notify all objects to update themselves.
146  void update();
147 
149  // This functor is used to clear the reference count stored in an object.
151  virtual void operator()(Object *) const;
152  };
153 
154  std::vector<std::string> getAllNames();
155 
156  bool isInOPALCyclMode();
157  bool isInOPALTMode();
158  bool isInOPALEnvMode();
159  bool isOptimizerRun();
160 
161  void setInOPALCyclMode();
162  void setInOPALTMode();
163  void setInOPALEnvMode();
164  void setOptimizerFlag();
165 
166  bool isInPrepState();
167  void setInPrepState(bool state);
168 
170  bool hasPriorTrack();
171 
173  void setPriorTrack(const bool &value = true);
174 
176  bool inRestartRun();
177 
179  void setRestartRun(const bool &value = true);
180 
182  void setRestartStep(int s);
183 
185  int getRestartStep();
186 
188  std::string getInputFn();
189 
191  std::string getInputBasename();
192 
194  void storeInputFn(const std::string &fn);
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  bool hasSLBunchAllocated();
238 
239  void slbunchIsAllocated();
240 
242 
244 
246  void setGlobalPhaseShift(double shift);
248  double getGlobalPhaseShift();
249 
254 
255 
256  bool hasGlobalGeometry();
257 
258  void setMaxPhase(std::string elName, double phi);
259 
262  int getNumberOfMaxPhases();
263 
264  void addEnergyData(double spos, double ekin);
267 
268  unsigned long long getMaxTrackSteps();
269  void setMaxTrackSteps(unsigned long long s);
270  void incMaxTrackSteps(unsigned long long s);
271 
272  void addProblemCharacteristicValue(const std::string &name, unsigned int value);
273  const std::map<std::string, unsigned int> &getProblemCharacteristicValues() const;
274 
275  void storeArguments(int argc, char *argv[]);
276  std::vector<std::string> getArguments();
277 
278 private:
279 
280  static bool isInstantiated;
282  static std::stack<OpalData*> stashedInstances;
283 
284  OpalData();
285 
286  // Not implemented.
287  OpalData(const OpalData &);
288  void operator=(const OpalData &);
289 
290  // The private implementation details.
291  struct OpalDataImpl *p;
292 };
293 
294 //extern OpalData OPAL;
295 
296 #endif // OPAL_OpalData_HH
void setPartBunch(PartBunchBase< double, 3 > *p)
Definition: OpalData.cpp:417
static void deleteInstance()
Definition: OpalData.cpp:219
std::string getRestartFileName()
get opals restart h5 format filename
Definition: OpalData.cpp:354
The global OPAL structure.
Definition: OpalData.h:54
energyEvolution_t::iterator getLastEnergyData()
Definition: OpalData.cpp:463
PartBunchBase< double, 3 > * getPartBunch()
Definition: OpalData.cpp:421
std::vector< MaxPhasesT >::iterator getLastMaxPhases()
Definition: OpalData.cpp:447
bool isInPrepState()
Definition: OpalData.cpp:320
void setPriorTrack(const bool &value=true)
true if in follow-up track
Definition: OpalData.cpp:332
void setOpenMode(OPENMODE openMode)
Definition: OpalData.cpp:377
Abstract base class for attribute values of different types.
Definition: AttributeBase.h:32
void setInOPALCyclMode()
Definition: OpalData.cpp:304
void define(Object *newObject)
Define a new object.
Definition: OpalData.cpp:538
double getP0() const
Return value of global reference momentum.
Definition: OpalData.cpp:623
void create(Object *newObject)
Create new object.
Definition: OpalData.cpp:524
int getRestartDumpFreq() const
get the dump frequency as found in restart file
Definition: OpalData.cpp:373
core of the envelope tracker based on Rene Bakkers BET implementation
Definition: EnvelopeBunch.h:60
void bunchIsAllocated()
Definition: OpalData.cpp:413
void setRestartRun(const bool &value=true)
set OPAL in restart mode
Definition: OpalData.cpp:340
void setInOPALEnvMode()
Definition: OpalData.cpp:312
bool inRestartRun()
true if we do a restart run
Definition: OpalData.cpp:336
std::vector< std::string > getAllNames()
Definition: OpalData.cpp:749
void storeInputFn(const std::string &fn)
store opals input filename
Definition: OpalData.cpp:700
bool hasSLBunchAllocated()
true if we already allocated a ParticleBunch object
Definition: OpalData.cpp:393
bool hasDataSinkAllocated()
true if we already allocated a DataSink object
Definition: OpalData.cpp:426
bool isInOPALCyclMode()
Definition: OpalData.cpp:288
int getRestartStep()
get the step where to restart
Definition: OpalData.cpp:349
energyEvolution_t::value_type energyEvData_t
Definition: OpalData.h:42
struct OpalDataImpl * p
Definition: OpalData.h:291
static std::stack< OpalData * > stashedInstances
Definition: OpalData.h:282
void update()
Update all objects.
Definition: OpalData.cpp:723
unsigned long long getMaxTrackSteps()
Definition: OpalData.cpp:249
const std::map< std::string, unsigned int > & getProblemCharacteristicValues() const
Definition: OpalData.cpp:826
Clear Reference.
Definition: OpalData.h:150
static OpalData * instance
Definition: OpalData.h:281
void setDataSink(DataSink *s)
Definition: OpalData.cpp:430
void apply(const ObjectFunction &)
Apply a function to all objects.
Definition: OpalData.cpp:516
std::pair< std::string, double > MaxPhasesT
Definition: OpalData.h:37
bool hasPriorTrack()
true if in follow-up track
Definition: OpalData.cpp:328
bool hasGlobalGeometry()
Definition: OpalData.cpp:510
void addEnergyData(double spos, double ekin)
Definition: OpalData.cpp:455
void printTitle(std::ostream &)
Print the page title.
Definition: OpalData.cpp:705
std::vector< std::string > getArguments()
Definition: OpalData.cpp:837
std::string getTitle()
Get the title string.
Definition: OpalData.cpp:709
void unregisterTable(Table *t)
Unregister table.
Definition: OpalData.cpp:672
static OpalData * getInstance()
Definition: OpalData.cpp:209
void storeTitle(const std::string &)
Store the page title.
Definition: OpalData.cpp:696
bool isInOPALTMode()
Definition: OpalData.cpp:292
static bool isInstantiated
Definition: OpalData.h:280
Class: DataSink.
Definition: OpalData.h:29
void incMaxTrackSteps(unsigned long long s)
Definition: OpalData.cpp:257
double getGlobalPhaseShift()
units: (sec)
Definition: OpalData.cpp:497
void setRestartDumpFreq(const int &N)
set the dump frequency as found in restart file
Definition: OpalData.cpp:369
int getLastStep() const
get the last step from a possible previous run
Definition: OpalData.cpp:389
void setGlobalGeometry(BoundaryGeometry *bg)
Definition: OpalData.cpp:502
OPENMODE
Enum for writing to files.
Definition: OpalData.h:69
virtual void operator()(Object *) const
The function to be executed.
Definition: OpalData.cpp:54
bool hasBunchAllocated()
true if we already allocated a ParticleBunch object
Definition: OpalData.cpp:409
static void stashInstance()
Definition: OpalData.cpp:225
void addProblemCharacteristicValue(const std::string &name, unsigned int value)
Definition: OpalData.cpp:818
std::string getInputFn()
get opals input filename
Definition: OpalData.cpp:713
void setOptimizerFlag()
Definition: OpalData.cpp:316
OPENMODE getOpenMode() const
Definition: OpalData.cpp:381
std::map< double, double > energyEvolution_t
Definition: OpalData.h:41
EnvelopeBunch * getSLPartBunch()
Definition: OpalData.cpp:405
void registerExpression(AttributeBase *)
Register expression.
Definition: OpalData.cpp:681
void operator=(const OpalData &)
T * value_type(const SliceIterator< T > &)
std::vector< MaxPhasesT >::iterator getFirstMaxPhases()
Definition: OpalData.cpp:443
int getNumberOfMaxPhases()
Definition: OpalData.cpp:451
void printNames(std::ostream &stream, const std::string &pattern)
Print all objects.
Definition: OpalData.cpp:635
void setLastStep(const int &step)
set the last step in a run for possible follow-up run
Definition: OpalData.cpp:385
void unregisterExpression(AttributeBase *)
Unregister expression.
Definition: OpalData.cpp:686
static OpalData * popInstance()
Definition: OpalData.cpp:236
bool hasRestartFile()
true if we do a restart from specified h5 file
Definition: OpalData.cpp:364
Object * find(const std::string &name)
Find entry.
Definition: OpalData.cpp:618
void setGlobalPhaseShift(double shift)
units: (sec)
Definition: OpalData.cpp:492
The base class for all OPAL objects.
Definition: Object.h:48
The base class for all OPAL value definitions.
const std::string name
DataSink * getDataSink()
Definition: OpalData.cpp:435
void storeArguments(int argc, char *argv[])
Definition: OpalData.cpp:830
void setRestartFileName(std::string s)
store opals restart h5 format filename
Definition: OpalData.cpp:359
void reset()
reset object for consecutive runs
Definition: OpalData.cpp:270
void setMaxTrackSteps(unsigned long long s)
Definition: OpalData.cpp:253
Abstract base class for functor objects whose argument is an Object.
void erase(const std::string &name)
Delete existing entry.
Definition: OpalData.cpp:599
void setP0(ValueDefinition *p0)
Set the global momentum.
Definition: OpalData.cpp:691
bool isOptimizerRun()
Definition: OpalData.cpp:300
std::string::iterator iterator
Definition: MSLang.h:16
void setInOPALTMode()
Definition: OpalData.cpp:308
void setSLPartBunch(EnvelopeBunch *p)
Definition: OpalData.cpp:401
The base class for all OPAL tables.
Definition: Table.h:42
std::string getInputBasename()
get input file name without extension
Definition: OpalData.cpp:717
energyEvolution_t::iterator getFirstEnergyData()
Definition: OpalData.cpp:459
bool isInOPALEnvMode()
Definition: OpalData.cpp:296
void setMaxPhase(std::string elName, double phi)
Definition: OpalData.cpp:439
void slbunchIsAllocated()
Definition: OpalData.cpp:397
void registerTable(Table *t)
Register table.
Definition: OpalData.cpp:667
void setInPrepState(bool state)
Definition: OpalData.cpp:324
BoundaryGeometry * getGlobalGeometry()
Definition: OpalData.cpp:506
void makeDirty(Object *object)
Invalidate expressions.
Definition: OpalData.cpp:629
void setRestartStep(int s)
store the location where to restart
Definition: OpalData.cpp:345