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);
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
static OpalData * getInstance()
virtual void parse(Statement &)
Parse the object.
The parser for SEQUENCE members.
virtual double getLength() const
Return sequence length.
The base class for all OPAL objects.
virtual void execute()
Apply the algorithm to the top-level beamline.
std::string getString(const Attribute &attr)
Get string value.
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
void insertDrifts(TLine &line)
ReferenceType getReference() const
Return the reference type flag.
PositionType itsFlag
Flag word.
Replace all references to named element by a new version.
b Accompany it with a written valid for at least three to give any third for a charge no more than your cost of physically performing source a complete machine readable copy of the corresponding source code
ReferenceType
Reference for element positioning.
ElementBase * getElement() const
Get the element pointer.
virtual void print(std::ostream &) const
Print sequence.
virtual double getEntrance(ReferenceType) const
Return the arc length from origin to entrance.
virtual const std::string & getName() const
Get element name.
double findDriftLength(TLine::iterator drift) const
void addEndMarkers(TLine &line) const
Inform & endl(Inform &inf)
void setElement(ElementBase *)
Assign new CLASSIC element.
virtual Object * makeTemplate(const std::string &, TokenStream &, Statement &)
Make a sequence template.
bool isSharable() const
Test if the element can be shared.
std::string::iterator iterator
void storeLine(TLine &line)
Store sequence line.
TLine::iterator findNamedPosition(TLine &, const std::string &) const
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Abstract interface for a stream of input tokens.
The base class for all OPAL exceptions.
virtual double getEntrance(ReferenceType) const
Return arc length from origin to entrance (negative !).
The base class for all OPAL beam lines and sequences.
virtual Sequence * clone(const std::string &name)
Make clone.
virtual void update()
Update the embedded CLASSIC beam line.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Interface for statements.
ElementBase * getElement() const
Return the embedded CLASSIC element.
void apply(const ObjectFunction &)
Apply a function to all objects.
static void updateList(Sequence *, TLine *)
virtual void parse(Statement &)
Parse sequence.
const std::string & getOpalName() const
Return object name.
std::vector< Attribute > itsAttr
The object attributes.
MemberType itsType
Type word.
static Element * find(const std::string &name)
Find named Element.
virtual ElementBase * copyStructure()
Make a structural copy.
virtual ElementBase * clone() const =0
Return clone.
virtual Sequence * copy(const std::string &name)
Make copy of the sequence line.
double getReal(const Attribute &attr)
Return real value.
virtual bool isShared() const
Shared flag.
b mention the algorithm in the References section The appropriate citation is
virtual void setName(const std::string &name)
Set element name.
virtual double getExit(ReferenceType) const
Return the arc length from origin to exit.
TBeamline< SequenceMember > TLine
The type of a sequence line.
Object * find(const std::string &name)
Find entry.
void setElement(ElementBase *)
Set the element pointer.
Sequence()
Exemplar constructor.
void parseTemplate(TokenStream &, Statement &)
Parse the sequence template.
virtual TLine * fetchLine() const
Return the embedded CLASSIC beam line.
virtual void run() const
Read current stream.
int increment()
Increment and return the occurrence counter.
virtual void replace(Object *oldObject, Object *newObject)
Replace references to elements.
double itsPosition
The position attribute ("AT" or "DRIFT").
virtual double getExit(ReferenceType) const
Return arc length from origin to exit (positive !).
bool getReflectionFlag() const
Get reflection flag.
A representation of an Object attribute.