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\")");
99 for (TLine::iterator i = oldLine->begin(); i != oldLine->end(); ++i) {
108 newLine->push_back(member);
117 TLine::iterator first = line.begin();
118 TLine::iterator last = line.end();
120 for (TLine::iterator iter = first; iter != last; ++iter) {
122 if (iter->getElement()->getName() == name) {
123 TLine::iterator test = iter;
125 while (++test != line.end()) {
126 if (test->getElement()->getName() == name) {
128 "Sequence::findNamedPosition()",
129 "Element \"" + name +
"\" is not unique in sequence.");
139 "Sequence::findNamedPosition()",
"Element \"" + name +
"\" not found in sequence.");
150 return (-iter->itsPosition);
160 return (
getLength() - iter->itsPosition);
168 if (ref ==
"ENTRY") {
170 }
else if (ref ==
"EXIT") {
202 std::streamsize old_prec = os.precision(12);
209 os <<
',' << i.getName() << (i.isExpression() ?
":=" :
"=") << i;
213 os <<
";" << std::endl;
215 for (TLine::const_iterator iter = line->begin(); iter != line->end(); ++iter) {
220 if (name[0] !=
'#') {
228 os <<
';' << std::endl;
233 os <<
"ENDSEQUENCE;" << std::endl;
235 os.precision(old_prec);
242 if (oldElement != 0 && newElement != 0) {
258 line->erase(line->begin(), line->end());
268 for (TLine::iterator i = line->begin(); i != line->end(); ++i) {
270 const std::string& name = i->getElement()->getName();
274 i->OpalElement = std::shared_ptr<Element>(elem);
289 line.push_front(member);
292 line.push_back(member);
297 TLine::iterator prev(drift);
299 const std::string prev_name = prev->getElement()->getName();
304 std::shared_ptr<Element> prev_elem = prev->OpalElement;
305 double prev_exit = prev->itsPosition + prev_elem->getExit(
itsCode);
307 TLine::iterator next(drift);
309 const std::string next_name = next->getElement()->getName();
314 std::shared_ptr<Element> next_elem = next->OpalElement;
315 double next_entry = next->itsPosition + next_elem->getEntrance(
itsCode);
317 double driftLength = next_entry - prev_exit;
319 static double tolerance = 1.0e-8;
320 if (std::abs(driftLength) < tolerance) {
322 }
else if (driftLength < 0.0) {
324 std::ostringstream os;
325 os <<
"Inconsistent positions in sequence \"" <<
getOpalName() +
"\";\n"
326 <<
"previous element: \"" << prev_name +
"\" at = " << prev->itsPosition <<
",\n"
327 <<
"following element: \"" << next_name +
"\" at = " << next->itsPosition <<
"."
329 throw OpalException(
"Sequence::findDriftLength()", os.str());
337 TLine::iterator i = line.begin();
340 if (i == line.end())
break;
346 line.insert(i, member);
351 TLine::iterator iter = line->begin();
352 TLine::iterator last = line->end();
356 if (iter == last)
break;
361 const std::string& sub_name = sub_line->
getName();
370 if (iter == last)
break;
372 iter->setLength(driftLength);
A representation of an Object attribute.
The base class for all OPAL beam lines and sequences.
void execute() override
Apply the algorithm to the top-level beamline.
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.
virtual double getEntrance(ReferenceType) const
Return arc length from origin to entrance (negative !).
std::shared_ptr< ElementBase > getElementPtr() const
Return the embedded OPALX element as shared_ptr.
static Element * find(const std::string &name)
Find named Element.
ReferenceType
Reference for element positioning.
ElementBase * getElement() const
Return the embedded OPALX element.
void setElement(ElementBase *)
Assign new OPALX element.
virtual double getExit(ReferenceType) const
Return arc length from origin to exit (positive !).
ElementBase * getElement() const
Get the element pointer.
void setElement(ElementBase *)
Set the element pointer.
bool getReflectionFlag() const
Get reflection flag.
The base class for all OPAL objects.
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
const std::string & getOpalName() const
Return object name.
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 run() const
Read current stream.
Replace all references to named element by a new version.
MemberType itsType
Type word.
double itsPosition
The position attribute ("AT" or "DRIFT").
PositionType itsFlag
Flag word.
The parser for SEQUENCE members.
void parseTemplate(TokenStream &, Statement &)
Parse the sequence template.
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 OPALX beam line.
TLine::iterator findNamedPosition(TLine &, const std::string &) const
virtual TLine * fetchLine() const
Return the embedded OPALX 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 SequenceTemplate
double findDriftLength(TLine::iterator drift) const
static void updateList(Sequence *, TLine *)
Interface for statements.
Abstract interface for a stream of input tokens.
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.