63 const ColDesc allColumns[] = {
89 const ColDesc printColumns[] = {
105 const ColDesc *findCol(
const Survey &table,
const std::string &colName) {
106 for(
const ColDesc *col = allColumns; col->colName; ++col) {
107 if(colName == col->colName) {
114 "\" has no column named \"" + colName +
"\".");
129 Column(
const Survey &tab,
const std::string &scol,
const ColDesc &col);
131 Column(
const Column &);
141 virtual void print(std::ostream &os,
int precedence = 99)
const;
166 Column::Column(
const Survey &tab,
167 const std::string &
name,
168 const ColDesc &desc):
177 Column::Column(
const Column &rhs):
179 itsTable(rhs.itsTable),
180 colName(rhs.colName),
192 return new Column(*
this);
196 double Column::evaluate()
const {
198 return (itsTable.*
get)(itsTable.getCurrent(), ind_1, ind_2);
202 void Column::print(std::ostream &os,
int)
const {
260 "The \"SURVEY\" command defines a table of survey data which "
261 "can be matched or tabulated."),
264 (
"LINE",
"Name of the lattice to be surveyed");
266 (
"RANGE",
"The range in the lattice");
268 (
"STATIC",
"If true, the table is not recalculated at each iteration");
270 (
"INIT",
"If given, this table position is used to initialise");
272 (
"X0",
"Initial X position in m");
274 (
"Y0",
"Initial Y position in m");
276 (
"Z0",
"Initial Z position in m");
278 (
"THETA0",
"Initial azimuth angle in rad");
280 (
"PHI0",
"Initial pitch angle in rad");
282 (
"PSI0",
"Initial roll angle in rad");
286 (
"L",
"Sum of design lengths in m");
294 Table(name, parent), itsTable(new
TLine(name)), itsVisitor(0)
305 return new Survey(name,
this);
323 std::cerr <<
"\n### Warning ### Survey table \"" <<
getOpalName()
324 <<
"\" contains no elements.\n" <<
std::endl;
326 itsTable->front().setSelectionFlag(
true);
327 itsTable->back().setSelectionFlag(
true);
343 double x, y, z, phi, theta, psi;
356 "\" is not suitable for initialising survey \"" +
381 if(! dynamic_cast<Beamline *>(&elem)) {
392 map.
getAll(x, y, z, phi, theta, psi);
402 for(TLine::const_iterator i =
itsTable->begin();
409 std::ostringstream os;
410 os << row << std::ends;
411 throw OpalException(
"Survey::setRow()",
"Row \"" + os.str() +
412 "\" not found in survey table \"" +
getOpalName() +
"\".");
418 const ColDesc *col = findCol(*
this, name);
419 return (this->*(col->get))(row, col->ind_1, col->ind_2);
425 for(
const ColDesc *col = printColumns; col->colName; ++col) {
427 new Column(*
this, col->colName, *col);
428 columns.push_back(
Cell(expr, col->printWidth, col->printPrecision));
436 const ColDesc *col = findCol(*
this, name);
439 std::vector<double> column;
444 column.push_back((this->*(col->get))(*
current, col->ind_1, col->ind_2));
471 std::vector<double> result;
473 if(columns.empty()) {
475 for(
const ColDesc *col = printColumns; col->colName != 0; ++col) {
476 result.push_back((this->*(col->get))(row, col->ind_1, col->ind_2));
480 for(std::vector<std::string>::const_iterator
name = columns.begin();
482 const ColDesc *col = findCol(*
this, *
name);
483 result.push_back((this->*(col->get))(row, col->ind_1, col->ind_2));
493 if(
itsLine == name)
return true;
496 for(TLine::const_iterator i =
itsTable->begin(); i !=
itsTable->end(); ++i) {
497 if(i->getElement()->getName() ==
name)
return true;
507 return new Column(*
this, colName, *findCol(*
this, colName));
512 return dynamic_cast<Survey *
>(rhs) != 0;
520 os <<
"Geometric layout for line: " <<
itsAttr[
LINE]
521 <<
", range: " <<
itsAttr[RANGE] <<
"." <<
'\n';
525 for(CellArray::const_iterator cell = cells.begin();
526 cell < cells.end(); ++cell) {
527 lineLength += cell->printWidth;
529 os << std::string(lineLength,
'-') <<
'\n';
533 for(CellArray::const_iterator cell = cells.begin();
534 cell < cells.end(); ++cell) {
535 std::ostringstream ss;
536 cell->itsExpr->print(ss, 0);
538 std::string image = ss.str();
540 if(
int(image.length()) < cell->printWidth) {
542 os << std::string(cell->printWidth - image.length(),
' ') << image;
545 os <<
' ' << std::string(image, 0, cell->printWidth - 3) <<
"..";
549 os << std::string(lineLength,
'-') <<
'\n';
552 std::streamsize old_prec = os.precision(6);
553 os.setf(std::ios::fixed, std::ios::floatfield);
557 if(
current->getSelectionFlag()) {
558 std::string
name =
current->getElement()->getName();
559 if(
int occur =
current->getCounter()) {
560 std::ostringstream tos;
561 tos << name <<
'[' << occur <<
']' << std::ends;
565 if(name.length() > 16) {
567 os << std::string(name, 0, 13) <<
".. ";
570 os << name << std::string(16 - name.length(),
' ');
573 for(CellArray::const_iterator cell = cells.begin();
574 cell != cells.end(); ++cell) {
575 os << std::setw(cell->printWidth)
576 << std::setprecision(cell->printPrecision)
577 << cell->itsExpr->evaluate();
584 os << std::string(lineLength,
'-') <<
'\n';
587 os.precision(old_prec);
588 os.setf(std::ios::fixed, std::ios::floatfield);
619 return atan2(rot(1, 2),
sqrt(rot(1, 0) * rot(1, 0) + rot(1, 1) * rot(1, 1)));
626 return (arg > 1.0
e-10) ?
atan2(rot(0, 2), rot(2, 2)) : 0.0;
633 return (arg > 1.0
e-10) ?
atan2(rot(1, 0), rot(1, 1)) : 0.0;
638 return row.
getMap().
M(ind_1, ind_2);
void setReal(Attribute &attr, double val)
Set real value.
std::vector< Cell > CellArray
An array of cell descriptors.
virtual void execute()
Check validity of survey definition.
virtual double getCell(const PlaceRep &row, const std::string &col)
Return a selected value in a selected row.
double getZ(const Row &, int=0, int=0) const
Z component of displacement.
virtual bool isDependent(const std::string &name) const
Find dependency.
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
double getX() const
Get displacement.
virtual void print(std::ostream &, int precedence=99) const =0
Print expression.
constexpr double e
The value of .
Interface for basic beam line object.
void operator=(const Scalar &)
TLine::const_iterator current
RangeRep getRange(const Attribute &attr)
Get range value.
virtual bool matches(Table *rhs) const
Check compatibility.
void leave(const FlaggedElmPtr &) const
Leave an element or line.
virtual Survey * clone(const std::string &name)
Make clone.
The base class for all OPAL exceptions.
double getZ() const
Get displacement.
virtual double getElementLength() const
Get design length.
void enter(const FlaggedElmPtr &) const
Enter an element or line.
Attribute makeRange(const std::string &name, const std::string &help)
Create a range attribute.
void update()
Update all objects.
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
bool isActive() const
Return status.
bool dynamic
Flag dynamic table.
const Euclid3D & getMap(const Row &) const
Position and orientation of local system.
virtual std::vector< double > getColumn(const RangeRep &range, const std::string &col)
Return column [b]col[/b] of this table, limited by [b]range[/b].
Representation of a table row reference.
double M(int row, int col) const
Get component.
virtual CellArray getDefault() const
Return the default print columns.
double getPsi(const Row &, int=0, int=0) const
Rotation about Z.
TableRowRep getTableRow(const Attribute &attr)
Get table row value.
The class for one row of the survey table.
Survey()
Exemplar constructor.
bool getBool(const Attribute &attr)
Return logical value.
bool isActive() const
Test for active range.
void printTitle(std::ostream &)
Print the page title.
Representation of a place within a beam line or sequence.
static OpalData * getInstance()
const std::string & getOpalName() const
Return object name.
void initialize()
Initialise data for search.
static BeamSequence * find(const std::string &name)
Find a BeamSequence by name.
double getX(const Row &, int=0, int=0) const
X component of displacement.
double getY(const Row &, int=0, int=0) const
Y component of displacement.
double getS() const
Return the accumulated length.
virtual double getElementLength() const
Get design length.
void getAll(double &x, double &y, double &z, double &vx, double &vy, double &vz) const
Unpack.
virtual std::vector< double > getRow(const PlaceRep &, const std::vector< std::string > &)
Return a table row, possible user-defined.
void enter(const FlaggedElmPtr &) const
Enter an element or line.
virtual const Beamline * getLine() const
Return embedded CLASSIC beamline.
void setCounter(int) const
Set clone counter.
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
virtual Beamline * fetchLine() const =0
Return the embedded CLASSIC beam line.
Displacement and rotation in space.
double getW(const Row &, int i1, int i2) const
Local axis vectors.
virtual Scalar< T > * clone() const =0
Copy scalar expression.
static Table * find(const std::string &name)
Find named Table.
const Row & getCurrent() const
Return current row of table.
static Rotation3D ZRotation(double angle)
Make rotation.
PETE_TBTree< FnArcTan2, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > atan2(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
virtual void execute()
Apply the algorithm to the top-level beamline.
void initialize()
Initialise data for search.
Representation of a range within a beam line or sequence.
void leave(const FlaggedElmPtr &) const
Leave an element or line.
An abstract sequence of beam line components.
PlaceRep getPosition() const
Return the row position representation.
void getMap(Euclid3D &) const
Return accumulated map.
Attribute makeTableRow(const std::string &name, const std::string &help)
Create a table row attribute.
const Rotation3D & getRotation() const
Get rotation.
double getPhi(const Row &, int=0, int=0) const
Rotation about X.
const Euclid3D & getMap() const
Return the accumulated geometry transform.
Tps< T > sqrt(const Tps< T > &x)
Square root.
The base class for all OPAL beam lines and sequences.
const Row & findRow(const PlaceRep &row)
double getTheta(const Row &, int=0, int=0) const
Rotation about Y.
virtual void fill()
Fill the buffer using the survey algorithm.
static Rotation3D YRotation(double angle)
Make rotation.
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Descriptor for printing a table cell.
virtual Expressions::PtrToScalar< double > makeColumnExpression(const std::string &colName) const
Return column.
static Rotation3D XRotation(double angle)
Make rotation.
virtual T evaluate() const =0
Evaluate.
void setMap(const Euclid3D &)
Reset accumulated map for restart.
std::string::iterator iterator
double getReal(const Attribute &attr)
Return real value.
const std::string & getTabName() const
Return the table name.
The base class for all OPAL tables.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Rotation in 3-dimensional space.
virtual double getLength()
Return the length of the table.
double getY() const
Get displacement.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
virtual void printTable(std::ostream &, const CellArray &) const
Print list for the table.
Inform & endl(Inform &inf)
double getS(const Row &, int=0, int=0) const
Arc length for given row.
A section of a beam line.
std::string getString(const Attribute &attr)
Get string value.