OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
Sequence.h
Go to the documentation of this file.
1 //
2 // Class Sequence
3 // The SEQUENCE definition.
4 // A Sequence contains a CLASSIC TBeamline<SequenceMember> which represents
5 // the sequence of elements in the line and their positions. The sequence
6 // definition is parsed in collaboration with a SequenceParser.
7 //
8 // Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
9 // All rights reserved
10 //
11 // This file is part of OPAL.
12 //
13 // OPAL is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20 //
21 #ifndef OPAL_Sequence_HH
22 #define OPAL_Sequence_HH
23 
26 #include "Beamlines/TBeamline.h"
27 #include "Lines/SequenceMember.h"
29 #include <list>
30 
31 class TokenStream;
32 
33 class Sequence: public BeamSequence {
34 
35  friend class Edit;
36  friend class SequenceParser;
37  friend class SequenceTemplate;
38 
39 public:
40 
43 
45  Sequence();
46 
47  virtual ~Sequence();
48 
50  // The new object is an empty sequence, it will be filled in by the parser.
51  virtual Sequence *clone(const std::string &name);
52 
54  virtual Sequence *copy(const std::string &name);
55 
57  virtual double getLength() const;
58 
60  virtual double getEntrance(ReferenceType) const;
61 
63  virtual double getExit(ReferenceType) const;
64 
66  // "ENTRY", "CENTRE", or "EXIT".
68 
70  // Arguments:
71  // [ol]
72  // [li] Name to be given to the template.
73  // [li] Token stream to be read for the sequence line.
74  // [li] Statement to be read for the arguments.
75  // [/ol]
76  virtual Object *makeTemplate(const std::string &, TokenStream &, Statement &);
77 
79  virtual void parse(Statement &);
80 
82  virtual void print(std::ostream &) const;
83 
85  virtual void replace(Object *oldObject, Object *newObject);
86 
88  // Recompute drift lengths.
89  virtual void update();
90 
92  // The result it the ideal line.
93  virtual TLine *fetchLine() const;
94 
96  // Assign to the underlying ideal line and re-insert the drifts.
97  void storeLine(TLine &line);
98 
99 private:
100 
101  // Not implemented.
102  Sequence(const Sequence &);
103  void operator=(const Sequence &);
104 
105  // Clone constructor.
106  Sequence(const std::string &name, Sequence *parent);
107 
108  // Add the top-level begin and end markers.
109  void addEndMarkers(TLine &line) const;
110 
111  // Compute drift length for a generated drift.
112  double findDriftLength(TLine::iterator drift) const;
113 
114  // Find named position in sequence line.
115  TLine::iterator findNamedPosition(TLine &, const std::string &) const;
116 
117  // Insert the top-level drift spaces.
118  void insertDrifts(TLine &line);
119 
120  // Recompute drift lengths for a given sequence or sub-sequence.
121  static void updateList(Sequence *, TLine *);
122 
123  // The reference code.
125 
126  // The reference point.
127  std::string itsRefPoint;
128 };
129 
130 #endif // OPAL_Sequence_HH
const std::string name
std::string::iterator iterator
Definition: MSLang.h:16
The base class for all OPAL beam lines and sequences.
Definition: BeamSequence.h:32
ReferenceType
Reference for element positioning.
Definition: Element.h:44
The base class for all OPAL objects.
Definition: Object.h:48
Interface for statements.
Definition: Statement.h:38
Abstract interface for a stream of input tokens.
Definition: TokenStream.h:33
virtual double getLength() const
Return sequence length.
Definition: Sequence.cpp:150
TBeamline< SequenceMember > TLine
The type of a sequence line.
Definition: Sequence.h:42
virtual void print(std::ostream &) const
Print sequence.
Definition: Sequence.cpp:218
std::string itsRefPoint
Definition: Sequence.h:127
ReferenceType itsCode
Definition: Sequence.h:124
friend class Edit
Definition: Sequence.h:35
virtual Object * makeTemplate(const std::string &, TokenStream &, Statement &)
Make a sequence template.
Definition: Sequence.cpp:192
void insertDrifts(TLine &line)
Definition: Sequence.cpp:368
Sequence()
Exemplar constructor.
Definition: Sequence.cpp:52
virtual double getExit(ReferenceType) const
Return the arc length from origin to exit.
Definition: Sequence.cpp:166
virtual double getEntrance(ReferenceType) const
Return the arc length from origin to entrance.
Definition: Sequence.cpp:155
virtual void update()
Update the embedded CLASSIC beam line.
Definition: Sequence.cpp:272
TLine::iterator findNamedPosition(TLine &, const std::string &) const
Definition: Sequence.cpp:124
void operator=(const Sequence &)
virtual TLine * fetchLine() const
Return the embedded CLASSIC beam line.
Definition: Sequence.cpp:278
Sequence(const Sequence &)
virtual Sequence * clone(const std::string &name)
Make clone.
Definition: Sequence.cpp:97
void storeLine(TLine &line)
Store sequence line.
Definition: Sequence.cpp:283
virtual void replace(Object *oldObject, Object *newObject)
Replace references to elements.
Definition: Sequence.cpp:259
virtual Sequence * copy(const std::string &name)
Make copy of the sequence line.
Definition: Sequence.cpp:102
void addEndMarkers(TLine &line) const
Definition: Sequence.cpp:312
virtual void parse(Statement &)
Parse sequence.
Definition: Sequence.cpp:206
ReferenceType getReference() const
Return the reference type flag.
Definition: Sequence.cpp:177
virtual ~Sequence()
Definition: Sequence.cpp:93
double findDriftLength(TLine::iterator drift) const
Definition: Sequence.cpp:325
static void updateList(Sequence *, TLine *)
Definition: Sequence.cpp:383
The parser for SEQUENCE members.