OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
SingleMultipole.h
Go to the documentation of this file.
1 #ifndef CLASSIC_SingleMultipole_HH
2 #define CLASSIC_SingleMultipole_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: SingleMultipole.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.1.1.1 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Template class: SingleMultipole
13 //
14 // ------------------------------------------------------------------------
15 // Class category: BeamlineCore
16 // ------------------------------------------------------------------------
17 //
18 // $Date: 2000/03/27 09:32:34 $
19 // $Author: fci $
20 //
21 // ------------------------------------------------------------------------
22 
23 #include "AbsBeamline/Multipole.h"
29 
30 
31 // Template class SingleMultipole
32 // ------------------------------------------------------------------------
34 // Template for representation of single multipoles.
35 // Represents all the basic (design) multipole magnets found in an
36 // accelerator. A single multipole has only one multipole component,
37 // the pole-number of which cannot be changed (once a quadrupole, always
38 // a quadrupole). This differs from a MultipoleRep object which can
39 // have an arbitrary number of multipole components.
40 // [P]
41 // This template class can be used to instantiate classes like:
42 // [UL]
43 // [LI]Quadrupole (order = 2),
44 // [LI]Sextupole (order = 3),
45 // [LI]Octupole (order = 4),
46 // [LI]SkewQuadrupole (order = -2),
47 // [LI]SkewSextupole (order = -3),
48 // [LI]SkewOctupole (order = -4).
49 // [/UL]
50 // The order and the skew flag are encoded in the template parameter.
51 // A positive [b]order[/b] implies a normal multipole,
52 // A negative [b]order[/b] implies a skew multipole.
53 
54 template <int order>
55 class SingleMultipole: public Multipole {
56 
57 public:
58 
60  explicit SingleMultipole(const std::string &name);
61 
64  virtual ~SingleMultipole();
65 
67  // Version for non-constant object.
68  virtual BMultipoleField &getField() ;
69 
71  // Version for constant object.
72  virtual const BMultipoleField &getField() const;
73 
75  // Version for non-constant object.
76  virtual StraightGeometry &getGeometry();
77 
79  // Version for constant object.
80  virtual const StraightGeometry &getGeometry() const;
81 
83  // Return the single multipole component in T/m**(n-1).
84  virtual double getComponent() const;
85 
87  // Assign the single multipole component in T/m**(n-1).
88  virtual void setComponent(double Bn);
89 
91  // Return an identical deep copy of the element.
92  virtual ElementBase *clone() const;
93 
95  // This method constructs a Channel permitting read/write access to
96  // the attribute [b]aKey[/b] and returns it.
97  // If the attribute does not exist, it returns NULL.
98  virtual Channel *getChannel(const std::string &aKey, bool = false);
99 
101  // Return the image of the element, containing the name and type string
102  // of the element, and a copy of the user-defined attributes.
103  ElementImage *getImage() const;
104 
105 private:
106 
107  // Not implemented.
108  void operator=(const SingleMultipole &);
109 
110  // A temporary for magnetic field conversion.
112 
115 
118 
119  // The type string returned.
120  static const std::string type;
121 
122  // Attribute access table.
123  struct Entry {
124  const char *name;
125  double(SingleMultipole<order>::*get)() const;
126  void (SingleMultipole<order>::*set)(double);
127  };
128 
129  // The table of attributes.
130  static const Entry entries[];
131 };
132 
133 
134 // Implementation of template class SingleMultipole
135 // ------------------------------------------------------------------------
136 
137 template <int order>
139  Multipole(),
140  geometry(),
141  field()
142 {}
143 
144 
145 template <int order>
147 (const SingleMultipole &multipole):
148  Multipole(multipole),
149  geometry(multipole.geometry),
150  field(multipole.field)
151 {}
152 
153 
154 template <int order>
156  Multipole(name),
157  geometry(),
158  field()
159 {}
160 
161 
162 template <int order>
164 {}
165 
166 
167 template <int order> inline
169  return field.getComponent();
170 }
171 
172 template <int order> inline
174  field.setComponent(value);
175 }
176 
177 
178 template <int order>
180  tempField = BMultipoleField(field);
181  return tempField;
182 }
183 
184 
185 template <int order>
187  tempField = BMultipoleField(field);
188  return tempField;
189 }
190 
191 
192 template <int order> inline
194  return geometry;
195 }
196 
197 template <int order> inline
199  return geometry;
200 }
201 
202 
203 template <int order> inline
205  return new SingleMultipole<order>(*this);
206 }
207 
208 
209 template <int order> inline
210 Channel *SingleMultipole<order>::getChannel(const std::string &aKey, bool) {
211  for(const Entry *entry = entries; entry->name != 0; ++entry) {
212  if(aKey == entry->name) {
214  (*this, entry->get, entry->set);
215  }
216  }
217 
218  return ElementBase::getChannel(aKey);
219 }
220 
221 
222 template <int order> inline
225 
226  for(const Entry *entry = entries; entry->name != 0; ++entry) {
227  image->setAttribute(entry->name, (this->*(entry->get))());
228  }
229 
230  return image;
231 }
232 
233 
234 #endif // __SingleMultipole_HH
Representation for a single magnetic multipole field.
Interface for basic beam line object.
Definition: ElementBase.h:128
virtual void setComponent(double Bn)
Set component.
void(SingleMultipole< order >::* set)(double)
static const std::string type
virtual StraightGeometry & getGeometry()
Get geometry.
virtual ~SingleMultipole()
ElementImage * getImage() const
Construct an image.
virtual Channel * getChannel(const std::string &aKey, bool create=false)
Construct a read/write channel.
virtual double getComponent() const
Get component.
virtual BMultipoleField & getField()
Get field.
Interface for general multipole.
Definition: Multipole.h:46
const SingleMultipole< 4 >::Entry entries[]
Definition: Octupole.cpp:33
virtual Channel * getChannel(const std::string &aKey, bool=false)
Construct a read/write channel.
An image of an element.
Definition: ElementImage.h:35
virtual ElementImage * getImage() const
Construct an image.
void setAttribute(const std::string &aKey, double val)
Set value of an attribute.
A geometry representing a straight line.
StraightGeometry geometry
Multipole geometry.
Abstract interface for read/write access to variable.
Definition: Channel.h:32
virtual ElementBase * clone() const
Return clone.
Representation for single multipoles.
The magnetic field of a multipole.
const std::string name
BMultipoleField tempField
void operator=(const SingleMultipole &)
Access to a [b]double[/b] data member.
BSingleMultipoleField< order > field
The single multipole component.