OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
Table.h
Go to the documentation of this file.
1#ifndef OPAL_Table_HH
2#define OPAL_Table_HH 1
3
4// ------------------------------------------------------------------------
5// $RCSfile: Table.h,v $
6// ------------------------------------------------------------------------
7// $Revision: 1.1.1.1 $
8// ------------------------------------------------------------------------
9// Copyright: see Copyright.readme
10// ------------------------------------------------------------------------
11//
12// Class: Table
13//
14// ------------------------------------------------------------------------
15//
16// $Date: 2000/03/27 09:33:35 $
17// $Author: Andreas Adelmann $
18//
19// ------------------------------------------------------------------------
20
23#include <vector>
24
25class Attribute;
26class Beamline;
27class PlaceRep;
28class RangeRep;
29
30
31// Class Table
32// ------------------------------------------------------------------------
34// It implements the common behaviour of tables, it can also be used via
35// dynamic casting to determine whether an object represents a table.
36// During matching operations, a Table must often be recalculated. This
37// is done by calling its [tt]fill()[/tt] method. To avoid unnecessary
38// filling, the user may define a table as ``static'' in the command
39// creating the table. In this case OPAL assumes that the table never
40// changes.
41
42class Table: public Object {
43
44public:
45
47 struct Cell {
49 Cell(Expressions::PtrToScalar<double> expr, int width, int prec):
50 itsExpr(expr), printWidth(width), printPrecision(prec) {}
51
54
57
60 };
61
63 typedef std::vector<Cell> CellArray;
64
65 virtual ~Table();
66
68 // A table cannot be replaced, thus this method never returns true.
69 virtual bool canReplaceBy(Object *newObject);
70
72 // If [b]refill[/b] is true, call the table algorithm to fill the buffer.
73 virtual void fill() = 0;
74
76 // If a table with name [b]name[/b] exists, return a pointer to that table.
77 // If no such table exists, throw OpalException.
78 static Table *find(const std::string &name);
79
81 // Return the string "TABLE".
82 virtual const std::string getCategory() const;
83
85 // If true, the object's execute() function should be traced.
86 // Always true for tables.
87 virtual bool shouldTrace() const;
88
90 // If true, the data structure should be updated before calling execute().
91 // Always true for tables.
92 virtual bool shouldUpdate() const;
93
94
96 // Return the value stored in the table cell identified by the row
97 // at [b]row[/b] and the column name [b]col[/b].
98 virtual double getCell(const PlaceRep &row, const std::string &col) = 0;
99
101 virtual std::vector<double> getColumn
102 (const RangeRep &range, const std::string &col) = 0;
103
105 // Returns an array of column descriptors, which, when applied to a
106 // row of the table, gives the default print columns for this table.
107 virtual CellArray getDefault() const = 0;
108
110 // Returns the geometric length of the underlying beam line.
111 virtual double getLength() = 0;
112
114 // Returns the CLASSIC beamline representing the table.
115 // The data of the table are attached to each position in the line.
116 virtual const Beamline *getLine() const = 0;
117
119 // Returns the values stored in the row specified by the first argument,
120 // with columns selected by the names stored in the second argument.
121 virtual std::vector<double>
122 getRow(const PlaceRep &, const std::vector<std::string> &) = 0;
123
125 virtual void invalidate();
126
128 // Must be overridden in derived classes.
129 virtual bool isDependent(const std::string &name) const = 0;
130
132 makeColumnExpression(const std::string &) const = 0;
133
135 virtual bool matches(Table *rhs) const = 0;
136
138 virtual void printTable(std::ostream &, const CellArray &) const = 0;
139
140
141protected:
142
144 Table(int size, const char *name, const char *help);
145
147 Table(const std::string &name, Table *parent);
148
149
151 // If true, the table is dynamic. If it is also invalidated,
152 // it will be refilled when fill() is called.
154
156 // If true, the table has been invalidated. If it is also dynammic,
157 // it will be refilled when fill() is called.
158 bool refill;
159
160private:
161
162 // Not implemented.
164 Table(const Table &);
165 void operator=(const Table &);
166};
167
168#endif // OPAL_Table_HH
const std::string name
A representation of an Object attribute.
Definition: Attribute.h:52
The base class for all OPAL objects.
Definition: Object.h:48
Representation of a place within a beam line or sequence.
Definition: PlaceRep.h:41
Representation of a range within a beam line or sequence.
Definition: RangeRep.h:34
The base class for all OPAL tables.
Definition: Table.h:42
virtual double getCell(const PlaceRep &row, const std::string &col)=0
Return value in selected table cell.
virtual void invalidate()
Mark this table as invalid, if it is dynamic.
Definition: Table.cpp:65
virtual void printTable(std::ostream &, const CellArray &) const =0
Print list for the table.
virtual CellArray getDefault() const =0
Return the default print columns.
virtual std::vector< double > getRow(const PlaceRep &, const std::vector< std::string > &)=0
Return a table row.
virtual bool shouldUpdate() const
Update flag.
Definition: Table.cpp:60
virtual const std::string getCategory() const
Return the object category as a string.
Definition: Table.cpp:50
virtual Expressions::PtrToScalar< double > makeColumnExpression(const std::string &) const =0
virtual bool canReplaceBy(Object *newObject)
Test if object can be replaced.
Definition: Table.cpp:36
virtual std::vector< double > getColumn(const RangeRep &range, const std::string &col)=0
Return column [b]col[/b] of this table, limited by [b]range[/b].
virtual bool matches(Table *rhs) const =0
Check that [b]rhs[/b] is of same type as [b]this[/b].
virtual double getLength()=0
Return the length of the table.
virtual void fill()=0
Refill the buffer.
virtual bool isDependent(const std::string &name) const =0
Find out if table depends on the object identified by [b]name[/b].
virtual ~Table()
Definition: Table.cpp:30
void operator=(const Table &)
std::vector< Cell > CellArray
An array of cell descriptors.
Definition: Table.h:63
Table(const Table &)
bool refill
Refill flag.
Definition: Table.h:158
static Table * find(const std::string &name)
Find named Table.
Definition: Table.cpp:41
virtual const Beamline * getLine() const =0
Return embedded CLASSIC beamline.
virtual bool shouldTrace() const
Trace flag.
Definition: Table.cpp:55
bool dynamic
Flag dynamic table.
Definition: Table.h:153
Descriptor for printing a table cell.
Definition: Table.h:47
Cell(Expressions::PtrToScalar< double > expr, int width, int prec)
Constructor.
Definition: Table.h:49
int printWidth
The cell width in print characters.
Definition: Table.h:56
int printPrecision
The number of digits printed for this cell.
Definition: Table.h:59
Expressions::PtrToScalar< double > itsExpr
The expression generating the values for this Cell.
Definition: Table.h:53
An abstract sequence of beam line components.
Definition: Beamline.h:34