41 if (stat.
keyword(
"ENDSEQUENCE")) {
87 for (std::list<SequenceMember*>::iterator j = i->itsList.begin();
88 j != i->itsList.end(); ++j) {
89 (*j)->itsPosition += i->fromPosition->itsPosition;
101 throw OpalException(
"SequenceParser::fillPositions()",
"Circular \"FROM\" clauses.");
111 i->fromPosition = &(*pos);
114 "SequenceParser::findFromPositions()",
"Not all FROM clauses resolved.");
124 if (ref ==
"ENTRY") {
126 }
else if (ref ==
"CENTRE" || ref.empty()) {
128 }
else if (ref ==
"EXIT") {
132 "SequenceParser::findNeighbourPositions()",
133 "Unknown reference flag \"" + ref +
"\" in <sequence> \""
137 for (TLine::iterator i =
itsLine.begin(); i !=
itsLine.end(); ++i) {
138 TLine::iterator j = i;
139 switch (i->itsFlag) {
144 std::string name = i->getElement()->getName();
149 i->itsPosition += length / 2.0;
151 i->itsPosition += length;
159 std::string name = j->getElement()->getName();
164 i->itsPosition += length;
166 i->itsPosition += length / 2.0;
243 std::shared_ptr<Object> copy;
249 "SequenceParser::parseMember()",
250 "You cannot redefine \"" + objName
251 +
"\" within the sequence of the same name.");
254 "SequenceParser::parseMember()",
255 "You cannot refer to \"" + objName
256 +
"\" within the sequence of the same name.");
259 "SequenceParser::parseMember()",
260 "You cannot redefine \"" + objName +
"\" within a sequence.");
264 copy = std::shared_ptr<Object>(obj->makeInstance(objName, stat,
this));
266 copy = std::shared_ptr<Object>(line->copy(objName));
268 copy = std::shared_ptr<Object>(obj->clone(objName));
272 copy = std::shared_ptr<Object>(obj);
283 member.
OpalElement = std::shared_ptr<Element>(elem);
295 "SequenceParser::parseMember()",
296 "Object \"" + objName +
"\" is not an element.");
300 "SequenceParser::parseMember()",
301 "Element class name \"" + clsName +
"\" is unknown.");
307 double position = 0.0;
308 std::string fromName;
317 flag |= (flag & 0x0001) ? 0x0008 : 0x0001;
318 }
else if (name ==
"DRIFT") {
321 flag |= (flag & 0x0002) ? 0x0008 : 0x0002;
322 }
else if (name ==
"FROM") {
327 }
else if (stat.
keyword(
"E")) {
330 throw ParseError(
"SequenceParser::parsePosition()",
"Expected 'S' or 'E'.");
335 flag |= (flag & 0x0004) ? 0x0008 : 0x0004;
336 }
else if (defined) {
340 attr->parse(stat,
true);
342 attr->parse(stat,
false);
345 "SequenceParser::parsePosition()",
346 "Delimiter \"=\" or \":=\" expected.");
350 "SequenceParser::parsePosition()",
"Element \"" + elem.
getOpalName()
351 +
"\" has no attribute \"" + name
356 "SequenceParser::parsePosition()",
"Overriding attributes not permitted here.");
385 if (fromName ==
"PREVIOUS") {
388 }
else if (fromName ==
"NEXT") {
391 }
else if (fromName ==
"#S") {
394 }
else if (fromName ==
"#E") {
403 if (i->fromName == fromName) {
405 i->itsList.push_back(&member);
413 ref.
itsList.push_back(&member);
420 throw ParseError(
"SequenceParser:parsePosition()",
"Conflicting keywords.");
A representation of an Object attribute.
The base class for all OPAL beam lines and sequences.
virtual ElementBase * copyStructure()
Make a structural copy.
virtual double getLength() const =0
Return element length.
static Element * find(const std::string &name)
Find named Element.
ReferenceType
Reference for element positioning.
void setElement(ElementBase *)
Set the element pointer.
void setReflectionFlag(bool flag) const
Set reflection flag.
The base class for all OPAL objects.
const std::string & getOpalName() const
Return object name.
virtual Attribute * findAttribute(const std::string &name)
Find an attribute by name.
void makeDirty(Object *object)
Invalidate expressions.
static OpalData * getInstance()
void define(Object *newObject)
Define a new object.
virtual void parseEnd(Statement &) const
Check for end of statement.
virtual Object * find(const std::string &) const
Find object by name in the main directory.
void stop() const
Set stop flag.
MemberType itsType
Type word.
std::shared_ptr< Element > OpalElement
double itsPosition
The position attribute ("AT" or "DRIFT").
PositionType itsFlag
Flag word.
void findFromPositions() const
void fillPositions() const
void parseMember(Statement &) const
virtual ~SequenceParser()
void findNeighbourPositions() const
virtual void parse(Statement &) const
Parse sequence member.
void parsePosition(Statement &, Object &, bool defined) const
void insertDrifts(TLine &line)
TLine::iterator findNamedPosition(TLine &, const std::string &) const
void storeLine(TLine &line)
Store sequence line.
void addEndMarkers(TLine &line) const
Interface for statements.
bool keyword(const char *s)
Test for keyword.
bool delimiter(char c)
Test for delimiter.
void start()
Return to start.
double getReal(const Attribute &attr)
Return real value.
std::string getString(const Attribute &attr)
Get string value.
std::string parseString(Statement &, const char msg[])
Parse string value.
void parseDelimiter(Statement &stat, char delim)
Test for one-character delimiter.
double parseRealConst(Statement &)
Parse real constant.
SequenceMember * fromPosition
std::list< SequenceMember * > itsList