55 "The \"SEQUENCE\" statement initiates parsing of an "
57 "\t<label>: SEQUENCE,L=<length>,REFER=<reference>\n"
59 "\t\t<object>: <class>,AT=<real>{,<attribute>=<value>}\n"
60 "\t\t<object>: <class>,DRIFT=<real>{,<attribute>=<value>}\n"
68 "Reference position for members:\n"
69 "\tENTRY | EXIT | CENTRE (default is CENTRE)",
73 "Element giving reference position for this sequence"
74 "\t(if given, this position is used instead of the centre, when the"
75 "\tsequence is nested in another sequence with \"REFER=CENTRE\")");
102 for (TLine::iterator i = oldLine->begin(); i != oldLine->end(); ++i) {
111 newLine->push_back(member);
120 TLine::iterator first = line.begin();
121 TLine::iterator last = line.end();
123 for (TLine::iterator iter = first; iter != last; ++iter) {
125 if (iter->getElement()->getName() == name) {
126 TLine::iterator test = iter;
128 while (++test != line.end()) {
129 if (test->getElement()->getName() == name) {
131 "Sequence::findNamedPosition()",
132 "Element \"" + name +
"\" is not unique in sequence.");
142 "Sequence::findNamedPosition()",
"Element \"" + name +
"\" not found in sequence.");
155 return (-iter->itsPosition);
165 return (
getLength() - iter->itsPosition);
173 if (ref ==
"ENTRY") {
175 }
else if (ref ==
"EXIT") {
208 std::streamsize old_prec = os.precision(12);
216 os <<
',' << i.getName() << (i.isExpression() ?
":=" :
"=") << i;
220 os <<
";" << std::endl;
222 for (TLine::const_iterator iter = line->begin(); iter != line->end(); ++iter) {
227 if (name[0] !=
'#') {
236 os <<
';' << std::endl;
241 os <<
"ENDSEQUENCE;" << std::endl;
243 os.precision(old_prec);
250 if (oldElement != 0 && newElement != 0) {
269 line->erase(line->begin(), line->end());
279 for (TLine::iterator i = line->begin(); i != line->end(); ++i) {
281 const std::string& name = i->getElement()->getName();
285 i->OpalElement = std::shared_ptr<Element>(elem);
300 line.push_front(member);
303 line.push_back(member);
308 TLine::iterator prev(drift);
310 const std::string prev_name = prev->getElement()->getName();
315 std::shared_ptr<Element> prev_elem = prev->OpalElement;
316 double prev_exit = prev->itsPosition + prev_elem->getExit(
itsCode);
318 TLine::iterator next(drift);
320 const std::string next_name = next->getElement()->getName();
325 std::shared_ptr<Element> next_elem = next->OpalElement;
326 double next_entry = next->itsPosition + next_elem->getEntrance(
itsCode);
328 double driftLength = next_entry - prev_exit;
330 static double tolerance = 1.0e-8;
331 if (std::abs(driftLength) < tolerance) {
333 }
else if (driftLength < 0.0) {
335 std::ostringstream os;
336 os <<
"Inconsistent positions in sequence \"" <<
getOpalName() +
"\";\n"
337 <<
"previous element: \"" << prev_name +
"\" at = " << prev->itsPosition <<
",\n"
338 <<
"following element: \"" << next_name +
"\" at = " << next->itsPosition <<
"."
340 throw OpalException(
"Sequence::findDriftLength()", os.str());
348 TLine::iterator i = line.begin();
358 line.insert(i, member);
363 TLine::iterator iter = line->begin();
364 TLine::iterator last = line->end();
374 const std::string& sub_name = sub_line->
getName();
386 iter->setLength(driftLength);
double getReal(const Attribute &attr)
Return real value.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
std::string getString(const Attribute &attr)
Get string value.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
virtual void setName(const std::string &name)
Set element name.
virtual const std::string & getName() const
Get element name.
virtual ElementBase * clone() const =0
Return clone.
virtual ElementBase * copyStructure()
Make a structural copy.
bool isSharable() const
Test if the element can be shared.
A representation of an Object attribute.
BeamSequence(int size, const char *name, const char *help)
Constructor for exemplars.
virtual double getEntrance(ReferenceType) const
Return arc length from origin to entrance (negative !).
static Element * find(const std::string &name)
Find named Element.
ReferenceType
Reference for element positioning.
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.
virtual double getExit(ReferenceType) const
Return arc length from origin to exit (positive !).
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.
std::vector< Attribute > itsAttr
The object attributes.
virtual void parse(Statement &)
Parse the object.
virtual bool isShared() const
Shared flag.
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.
ElementBase * getElement() const
Get the element pointer.
void setElement(ElementBase *)
Set the element pointer.
bool getReflectionFlag() const
Get reflection flag.
Replace all references to named element by a new version.
virtual double getLength() const
Return sequence length.
TBeamline< SequenceMember > TLine
The type of a sequence line.
virtual void print(std::ostream &) const
Print sequence.
virtual Object * makeTemplate(const std::string &, TokenStream &, Statement &)
Make a sequence template.
void insertDrifts(TLine &line)
Sequence()
Exemplar constructor.
virtual double getExit(ReferenceType) const
Return the arc length from origin to exit.
virtual double getEntrance(ReferenceType) const
Return the arc length from origin to entrance.
virtual void update()
Update the embedded CLASSIC beam line.
TLine::iterator findNamedPosition(TLine &, const std::string &) const
virtual TLine * fetchLine() const
Return the embedded CLASSIC beam line.
virtual Sequence * clone(const std::string &name)
Make clone.
void storeLine(TLine &line)
Store sequence line.
virtual void replace(Object *oldObject, Object *newObject)
Replace references to elements.
virtual Sequence * copy(const std::string &name)
Make copy of the sequence line.
void addEndMarkers(TLine &line) const
virtual void parse(Statement &)
Parse sequence.
ReferenceType getReference() const
Return the reference type flag.
friend class SequenceParser
friend class SequenceTemplate
double findDriftLength(TLine::iterator drift) const
static void updateList(Sequence *, TLine *)
MemberType itsType
Type word.
double itsPosition
The position attribute ("AT" or "DRIFT").
PositionType itsFlag
Flag word.
void parseTemplate(TokenStream &, Statement &)
Parse the sequence template.
virtual void run() const
Read current stream.
Interface for statements.
Abstract interface for a stream of input tokens.
The base class for all OPAL exceptions.