54 "The \"SEQUENCE\" statement initiates parsing of an "
56 "\t<label>: SEQUENCE,L=<length>,REFER=<reference>\n"
58 "\t\t<object>: <class>,AT=<real>{,<attribute>=<value>}\n"
59 "\t\t<object>: <class>,DRIFT=<real>{,<attribute>=<value>}\n"
63 (
"TYPE",
"The design type");
65 (
"L",
"Total length of sequence in m");
69 "Reference position for members:\n"
70 "\tENTRY | EXIT | CENTRE (default is CENTRE)",
"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\")");
115 newLine->push_back(member);
130 if(iter->getElement()->getName() ==
name) {
133 while(++test != line.end()) {
134 if(test->getElement()->getName() ==
name) {
135 throw OpalException(
"Sequence::findNamedPosition()",
"Element \"" +
136 name +
"\" is not unique in sequence.");
146 "Element \"" +
name +
"\" not found in sequence.");
161 return (- iter->itsPosition);
172 return (
getLength() - iter->itsPosition);
183 }
else if(
ref ==
"EXIT") {
220 std::streamsize old_prec = os.precision(12);
227 os <<
',' << i.getName()
228 << (i.isExpression() ?
":=" :
"=") << i;
234 for(TLine::const_iterator iter = line->begin();
235 iter != line->end(); ++iter) {
263 if(oldElement != 0 && newElement != 0) {
286 line->erase(line->begin(), line->end());
298 const std::string &
name = i->getElement()->getName();
302 i->OpalElement = elem;
318 line.push_front(member);
321 line.push_back(member);
329 const std::string prev_name = prev->getElement()->getName();
335 double prev_exit = prev->itsPosition + prev_elem->
getExit(
itsCode);
339 const std::string next_name = next->getElement()->getName();
347 double driftLength = next_entry - prev_exit;
349 static double tolerance = 1.0e-8;
350 if(
std::abs(driftLength) < tolerance) {
352 }
else if(driftLength < 0.0) {
354 std::ostringstream os;
355 os <<
"Inconsistent positions in sequence \"" <<
getOpalName() +
"\";\n"
356 <<
"previous element: \"" << prev_name +
"\" at = "
357 << prev->itsPosition <<
",\n"
358 <<
"following element: \"" << next_name +
"\" at = "
359 << next->itsPosition <<
"." << std::ends;
360 throw OpalException(
"Sequence::findDriftLength()", os.str());
372 if(i == line.end())
break;
378 line.insert(i, member);
389 if(iter == last)
break;
392 TLine *sub_line =
dynamic_cast<TLine *
>(base);
394 const std::string &sub_name = sub_line->
getName();
402 if(iter == last)
break;
404 iter->setLength(driftLength);
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
Inform & endl(Inform &inf)
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.
std::string::iterator iterator
A representation of an Object attribute.
The base class for all OPAL beam lines and sequences.
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.
void setElement(ElementBase *)
Assign new CLASSIC element.
virtual double getExit(ReferenceType) const
Return arc length from origin to exit (positive !).
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 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 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.
Interface for statements.
Abstract interface for a stream of input tokens.
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 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.
The parser for SEQUENCE members.
void parseTemplate(TokenStream &, Statement &)
Parse the sequence template.
virtual void run() const
Read current stream.
The base class for all OPAL exceptions.