61 double AttAdd(
double a,
double b)
68 "The \"LINE\" statement defines a beamline list.\n"
69 "\t<name> : line = (<list>)") {
71 (
"TYPE",
"Design type");
74 (
"L",
"Total length of line in m");
75 itsAttr[LENGTH].setReadOnly(
true);
78 (
"ORIGIN",
"The location of the particle source");
81 (
"ORIENTATION",
"The Tait-Bryan angles for the orientation of the particle source");
84 (
"X",
"The x-coordinate of the location of the particle source", 0);
87 (
"Y",
"The y-coordinate of the location of the particle source", 0);
90 (
"Z",
"The z-coordinate of the location of the particle source", 0);
93 (
"THETA",
"The rotation about the y-axis of the particle source", 0);
96 (
"PHI",
"The rotation about the x-axis of the particle source", 0);
99 (
"PSI",
"The rotation about the z-axis of the particle source", 0);
119 return new Line(name,
this);
127 std::copy(oldLine->begin(), oldLine->end(), std::back_inserter(*newLine));
168 line->push_front(first);
172 line->push_back(last);
176 for(FlaggedBeamline::iterator i = line->begin(); i != line->end(); ++i) {
177 auto actname = i->getElement()->getName();
202 attr->
parse(stat,
true);
204 attr->
parse(stat,
false);
213 if (origin.size() == 3) {
220 throw OpalException(
"Line::parse",
"Parameter origin is array of 3 values (x, y, z);\n" +
221 std::to_string(origin.size()) +
" values provided");
226 if (direction.size() == 3) {
227 const double &theta = direction[0];
228 const double &phi = direction[1];
229 const double &psi = direction[2];
231 Quaternion rotTheta(cos(0.5 * theta), 0, -sin(0.5 * theta), 0);
232 Quaternion rotPhi(cos(0.5 * phi), -sin(0.5 * phi), 0, 0);
233 Quaternion rotPsi(cos(0.5 * psi), 0, 0, -sin(0.5 * psi));
238 throw OpalException(
"Line::parse",
"Parameter orientation is array of 3 values (theta, phi, psi);\n" +
239 std::to_string(direction.size()) +
" values provided");
253 Quaternion rotTheta(cos(0.5 * theta), 0, -sin(0.5 * theta), 0);
254 Quaternion rotPhi(cos(0.5 * phi), -sin(0.5 * phi), 0, 0);
255 Quaternion rotPsi(cos(0.5 * psi), 0, 0, -sin(0.5 * psi));
263 !
itsAttr[THETA].defaultUsed() ||
275 for(FlaggedBeamline::const_iterator i = line->begin();
276 i != line->end(); ++i) {
277 const std::string name = i->getElement()->getName();
280 if(i->getReflectionFlag()) os <<
'-';
315 while(repeat-- > 0) {
317 for(FlaggedBeamline::reverse_iterator i = subLine->rbegin();
318 i != subLine->rend(); ++i) {
321 line->push_back(fep);
324 for(FlaggedBeamline::iterator i = subLine->begin();
325 i != subLine->end(); ++i) {
327 line->push_back(fep);
333 std::string name =
parseString(stat,
"Line member expected.");
338 "Element \"" + name +
"\" is undefined.");
345 obj = obj->makeInstance(name, stat, 0);
349 while(repeat-- > 0) {
352 line->push_back(member);
357 "Object \"" + name +
"\" cannot be a line member.");
371 if(oldElement != 0 && newElement != 0) {
ippl::Vector< T, Dim > Vector_t
TBeamline< FlaggedElmPtr > FlaggedBeamline
A beam line with flagged elements.
Representation objects and parsers for attribute expressions.
std::string parseString(Statement &, const char msg[])
Parse string value.
void parseDelimiter(Statement &stat, char delim)
Test for one-character delimiter.
A function of two U's returning a T.
double getReal(const Attribute &attr)
Return real value.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
virtual ElementBase * copyStructure()
Make a structural copy.
A representation of an Object attribute.
void setDefault()
Assign default value.
void parse(Statement &stat, bool eval)
Parse attribute.
BeamSequence(int size, const char *name, const char *help)
Constructor for exemplars.
static Element * find(const std::string &name)
Find named Element.
ElementBase * getElement() const
Return the embedded CLASSIC element.
Element(int size, const char *name, const char *help)
Constructor for exemplars.
void setElement(ElementBase *)
Assign new CLASSIC element.
A pointer to a scalar expression.
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
const std::string & getOpalName() const
Return object name.
Object(int size, const char *name, const char *help)
Constructor for exemplars.
int increment()
Increment and return the occurrence counter.
virtual Attribute * findAttribute(const std::string &name)
Find an attribute by name.
std::vector< Attribute > itsAttr
The object attributes.
void apply(const ObjectFunction &)
Apply a function to all objects.
Object * find(const std::string &name)
Find entry.
static OpalData * getInstance()
virtual void execute()
Apply the algorithm to the top-level beamline.
A section of a beam line.
void setReflectionFlag(bool flag) const
Set reflection flag.
void setRelativeFlag(bool flag)
void setOrigin3D(const Vector_t< double, 3 > &ori)
void setInitialDirection(const Quaternion &rot)
Object attribute with an ``automatic'' scalar value.
static Scalar< T > * make(const TFunction2< T, U > &, PtrToScalar< U > left, PtrToScalar< U > right)
Make a new expression.
An expression defined as a reference to a scalar.
virtual void replace(Object *oldObject, Object *newObject)
Replace references.
friend class LineTemplate
virtual void parse(Statement &stat)
Parse the line object.
virtual FlaggedBeamline * fetchLine() const
Return the embedded CLASSIC beam line.
virtual void print(std::ostream &stream) const
Print the line.
virtual Line * copy(const std::string &name)
Make complete copy.
virtual double getLength() const
Return line length.
virtual Object * makeTemplate(const std::string &name, TokenStream &is, Statement &stat)
Make a line template.
void parseList(Statement &)
Line()
Exemplar constructor.
virtual Line * clone(const std::string &name)
Make clone.
void parseTemplate(TokenStream &is, Statement &stat)
Parse the line template.
Replace all references to named element by a new version.
bool isValid() const
Test for validity.
Interface for statements.
bool integer(int &value)
Return signed integer.
bool delimiter(char c)
Test for delimiter.
Abstract interface for a stream of input tokens.
The base class for all OPAL exceptions.