OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
MultipoleRep.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: MultipoleRep.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.2 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: MultipoleRep
10 // Defines a concrete representation for a general multipole.
11 //
12 // ------------------------------------------------------------------------
13 // Class category: BeamlineCore
14 // ------------------------------------------------------------------------
15 //
16 // $Date: 2001/08/24 19:31:20 $
17 // $Author: jsberg $
18 //
19 // ------------------------------------------------------------------------
20 
26 #include <cctype>
27 
28 // Attribute access table.
29 // ------------------------------------------------------------------------
30 
31 namespace {
32  struct Entry {
33  const char *name;
34  double(MultipoleRep::*get)() const;
35  void (MultipoleRep::*set)(double);
36  };
37 
38  const Entry entries[] = {
39  {
40  "L",
43  },
44  { 0, 0, 0 }
45  };
46 }
47 
48 
49 // Class MultipoleRep
50 // ------------------------------------------------------------------------
51 
53  Multipole(),
54  geometry(),
55  field()
56 {}
57 
58 
60  Multipole(multipole),
61  geometry(multipole.geometry),
62  field(multipole.field)
63 {}
64 
65 
66 MultipoleRep::MultipoleRep(const std::string &name):
67  Multipole(name),
68  geometry(),
69  field()
70 {}
71 
72 
74 {}
75 
76 
78  return new MultipoleRep(*this);
79 }
80 
81 
82 Channel *MultipoleRep::getChannel(const std::string &aKey, bool create) {
83  if(aKey[0] == 'A' || aKey[0] == 'B') {
84  int n = 0;
85 
86  for(std::string::size_type k = 1; k < aKey.length(); k++) {
87  if(isdigit(aKey[k])) {
88  n = 10 * n + aKey[k] - '0';
89  } else {
90  return 0;
91  }
92  }
93 
94  if(aKey[0] == 'B') {
98  } else {
102  }
103  } else {
104  for(const Entry *entry = entries; entry->name != 0; ++entry) {
105  if(aKey == entry->name) {
107  (*this, entry->get, entry->set);
108  }
109  }
110 
111  return ElementBase::getChannel(aKey, create);
112  }
113 }
114 
115 
117  return geometry;
118 }
119 
121  return geometry;
122 }
123 
124 
127 
128  for(const Entry *entry = entries; entry->name != 0; ++entry) {
129  image->setAttribute(entry->name, (this->*(entry->get))());
130  }
131 
132  for(int n = 1; n <= field.order(); n++) {
133  char buffer[20];
134  char *p = buffer;
135  int k = n;
136 
137  while(k != 0) {
138  *p++ = k % 10 + '0';
139  k /= 10;
140  }
141 
142  std::string name(" ");
143  while(p > buffer) name += *--p;
144 
145  double b = getNormalComponent(n);
146  if(b != 0.0) {
147  name[0] = 'b';
148  image->setAttribute(name, b);
149  }
150 
151  double a = getSkewComponent(n);
152  if(a != 0.0) {
153  name[0] = 'a';
154  image->setAttribute(name, a);
155  }
156  }
157 
158  return image;
159 }
160 
161 
163  return field;
164 }
165 
166 
168  return field;
169 }
170 
171 
173  field = aField;
174 }
175 
176 
178  ElementBase *wrap = new MultipoleWrapper(this);
179  wrap->setName(getName());
180  return wrap;
181 }
double getNormalComponent(int n) const
Get normal component.
Definition: Multipole.cpp:82
void setSkewComponent(int, double)
Set skew component.
Definition: Multipole.h:155
virtual ElementBase * clone() const
Return clone.
Interface for basic beam line object.
Definition: ElementBase.h:128
virtual void setField(const BMultipoleField &field)
Set mulitpole field.
Representation for a general multipole.
Definition: MultipoleRep.h:31
virtual ~MultipoleRep()
virtual void setName(const std::string &name)
Set element name.
virtual ElementImage * getImage() const
Construct an image.
void setNormalComponent(int, double)
Set normal component.
Definition: Multipole.h:150
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:515
virtual Channel * getChannel(const std::string &aKey, bool create=false)
Construct a read/write channel.
virtual StraightGeometry & getGeometry()
Get geometry.
Representation of a perturbed multipole.
virtual const std::string & getName() const
Get element name.
Definition: ElementBase.cpp:95
virtual BMultipoleField & getField()
Get field.
Interface for general multipole.
Definition: Multipole.h:46
Access to an indexed [b]double[/b] data member.
BMultipoleField field
Multipole field.
Definition: MultipoleRep.h:89
virtual double getElementLength() const
Get design length.
Definition: ElementBase.h:511
double getSkewComponent(int n) const
Get skew component.
Definition: Multipole.cpp:90
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.
StraightGeometry geometry
Multipole geometry.
Definition: MultipoleRep.h:86
A geometry representing a straight line.
Abstract interface for read/write access to variable.
Definition: Channel.h:32
The magnetic field of a multipole.
const std::string name
virtual Channel * getChannel(const std::string &aKey, bool=false)
Construct a read/write channel.
int order() const
Return order.
virtual ElementBase * makeFieldWrapper()
Allow field errors.
Access to a [b]double[/b] data member.