OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
MultipoleRep.cpp
Go to the documentation of this file.
1 //
2 // Class MultipoleRep
3 // Representation for a general multipole.
4 //
5 // Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
6 // All rights reserved
7 //
8 // This file is part of OPAL.
9 //
10 // OPAL is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17 //
21 #include <cctype>
22 
23 // Attribute access table.
24 // ------------------------------------------------------------------------
25 
26 namespace {
27  struct Entry {
28  const char *name;
29  double(MultipoleRep::*get)() const;
30  void (MultipoleRep::*set)(double);
31  };
32 
33  const Entry entries[] = {
34  {
35  "L",
38  },
39  { 0, 0, 0 }
40  };
41 }
42 
43 
45  Multipole(),
46  geometry(),
47  field()
48 {}
49 
50 
52  Multipole(multipole),
53  geometry(multipole.geometry),
54  field(multipole.field)
55 {}
56 
57 
58 MultipoleRep::MultipoleRep(const std::string &name):
59  Multipole(name),
60  geometry(),
61  field()
62 {}
63 
64 
66 {}
67 
68 
70  return new MultipoleRep(*this);
71 }
72 
73 
74 Channel *MultipoleRep::getChannel(const std::string &aKey, bool create) {
75  if(aKey[0] == 'A' || aKey[0] == 'B') {
76  int n = 0;
77 
78  for(std::string::size_type k = 1; k < aKey.length(); k++) {
79  if(isdigit(aKey[k])) {
80  n = 10 * n + aKey[k] - '0';
81  } else {
82  return 0;
83  }
84  }
85 
86  if(aKey[0] == 'B') {
90  } else {
94  }
95  } else {
96  for(const Entry *entry = entries; entry->name != 0; ++entry) {
97  if(aKey == entry->name) {
99  (*this, entry->get, entry->set);
100  }
101  }
102 
103  return ElementBase::getChannel(aKey, create);
104  }
105 }
106 
107 
109  return geometry;
110 }
111 
113  return geometry;
114 }
115 
116 
118  return field;
119 }
120 
121 
123  return field;
124 }
125 
126 
128  field = aField;
129 }
const std::string name
virtual Channel * getChannel(const std::string &aKey, bool create=false)
Construct a read/write channel.
virtual double getElementLength() const
Get design length.
Definition: ElementBase.h:432
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:436
Interface for general multipole.
Definition: Multipole.h:47
void setNormalComponent(int, double)
Set normal component.
Definition: Multipole.h:147
double getSkewComponent(int n) const
Get skew component.
Definition: Multipole.cpp:93
void setSkewComponent(int, double)
Set skew component.
Definition: Multipole.h:152
double getNormalComponent(int n) const
Get normal component.
Definition: Multipole.cpp:85
virtual ElementBase * clone() const
Return clone.
virtual Channel * getChannel(const std::string &aKey, bool=false)
Construct a read/write channel.
StraightGeometry geometry
Multipole geometry.
Definition: MultipoleRep.h:69
virtual ~MultipoleRep()
virtual BMultipoleField & getField()
Get field.
BMultipoleField field
Multipole field.
Definition: MultipoleRep.h:72
virtual void setField(const BMultipoleField &field)
Set mulitpole field.
virtual StraightGeometry & getGeometry()
Get geometry.
A geometry representing a straight line.
Abstract interface for read/write access to variable.
Definition: Channel.h:32
Access to an indexed [b]double[/b] data member.
Access to a [b]double[/b] data member.
The magnetic field of a multipole.