OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
ElementBase.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: ElementBase.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.2 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: ElementBase
10 // The very base class for beamline representation objects. A beamline
11 // is modelled as a composite structure having a single root object
12 // (the top level beamline), which contains both "single" leaf-type
13 // elements (Components), as well as sub-lines (composites).
14 //
15 // ------------------------------------------------------------------------
16 // Class category: AbsBeamline
17 // ------------------------------------------------------------------------
18 //
19 // $Date: 2000/12/16 16:26:43 $
20 // $Author: mad $
21 //
22 // ------------------------------------------------------------------------
23 
27 #include "Channels/Channel.h"
28 #include <string>
29 
30 #include "Structure/BoundaryGeometry.h" // OPAL file
31 #include "Solvers/WakeFunction.hh"
33 
34 using namespace std;
35 
36 // Class ElementBase
37 // ------------------------------------------------------------------------
38 
40  ElementBase("")
41 {}
42 
43 
45  RCObject(),
46  shareFlag(true),
47  csTrafoGlobal2Local_m(right.csTrafoGlobal2Local_m),
48  misalignment_m(right.misalignment_m),
49  aperture_m(right.aperture_m),
50  elementEdge_m(right.elementEdge_m),
51  rotationZAxis_m(right.rotationZAxis_m),
52  elementID(right.elementID),
53  userAttribs(right.userAttribs),
54  wake_m(right.wake_m),
55  bgeometry_m(right.bgeometry_m),
56  parmatint_m(right.parmatint_m),
57  elType_m(right.elType_m),
58  positionIsFixed(right.positionIsFixed),
59  elementPosition_m(right.elementPosition_m),
60  elemedgeSet_m(right.elemedgeSet_m)
61 {
62 
63  if(parmatint_m) {
65  }
66  if(bgeometry_m)
68 }
69 
70 
71 ElementBase::ElementBase(const std::string &name):
72  RCObject(),
73  shareFlag(true),
74  csTrafoGlobal2Local_m(),
75  misalignment_m(),
76  elementEdge_m(0),
77  rotationZAxis_m(0.0),
78  elementID(name),
79  userAttribs(),
80  wake_m(NULL),
81  bgeometry_m(NULL),
82  parmatint_m(NULL),
83  elType_m(isOther),
84  positionIsFixed(false),
85  elementPosition_m(0.0),
86  elemedgeSet_m(false)
87 {}
88 
89 
91 
92 {}
93 
94 
95 const std::string &ElementBase::getName() const
96 
97 {
98  return elementID;
99 }
100 
101 
102 void ElementBase::setName(const std::string &name) {
103  elementID = name;
104 }
105 
106 
107 double ElementBase::getAttribute(const std::string &aKey) const {
108  const ConstChannel *aChannel = getConstChannel(aKey);
109 
110  if(aChannel != NULL) {
111  double val = *aChannel;
112  delete aChannel;
113  return val;
114  } else {
115  return 0.0;
116  }
117 }
118 
119 
120 bool ElementBase::hasAttribute(const std::string &aKey) const {
121  const ConstChannel *aChannel = getConstChannel(aKey);
122 
123  if(aChannel != NULL) {
124  delete aChannel;
125  return true;
126  } else {
127  return false;
128  }
129 }
130 
131 
132 void ElementBase::removeAttribute(const std::string &aKey) {
134 }
135 
136 
137 void ElementBase::setAttribute(const std::string &aKey, double val) {
138  Channel *aChannel = getChannel(aKey, true);
139 
140  if(aChannel != NULL && aChannel->isSettable()) {
141  *aChannel = val;
142  delete aChannel;
143  } else
144  cout << "Channel NULL or not Settable" << endl;
145 }
146 
147 
148 Channel *ElementBase::getChannel(const std::string &aKey, bool create) {
149  return userAttribs.getChannel(aKey, create);
150 }
151 
152 
153 const ConstChannel *ElementBase::getConstChannel(const std::string &aKey) const {
154  // Use const_cast to allow calling the non-const method GetChannel().
155  // The const return value of this method will nevertheless inhibit set().
156  return const_cast<ElementBase *>(this)->getChannel(aKey);
157 }
158 
159 
161  switch (type) {
162  case ALIGNWRAPPER:
163  return "AlignWrapper";
164  case BEAMBEAM:
165  return "BeamBeam";
166  case BEAMLINE:
167  return "Beamline";
168  case BEAMSTRIPPING:
169  return "BeamStripping";
170  case CCOLLIMATOR:
171  return "CCollimator";
172  case CORRECTOR:
173  return "Corrector";
174  case CORRECTORWRAPPER:
175  return "Correctorwrapper";
176  case CYCLOTRON:
177  return "Cyclotron";
178  case CYCLOTRONWRAPPER:
179  return "Cyclotronwrapper";
180  case CYCLOTRONVALLEY:
181  return "CyclotronValley";
182  case DEGRADER:
183  return "Degrader";
184  case DIAGNOSTIC:
185  return "Diagnostic";
186  case DRIFT:
187  return "Drift";
188  case INTEGRATOR:
189  return "Integrator";
190  case LAMBERTSON:
191  return "Lambertson";
192  case MARKER:
193  return "Marker";
194  case MONITOR:
195  return "Monitor";
196  case MULTIPOLE:
197  return "Multipole";
198  case MULTIPOLEWRAPPER:
199  return "Multipolewrapper";
200  case OFFSET:
201  return "Offset";
202  case PARALLELPLATE:
203  return "ParallelPlate";
204  case PATCH:
205  return "Patch";
206  case PROBE:
207  return "Probe";
208  case RBEND:
209  return "RBend";
210  case RBENDWRAPPER:
211  return "RBendwrapper";
212  case RFCAVITY:
213  return "RFCavity";
214  case RFQUADRUPOLE:
215  return "RFQuadrupole";
216  case RING:
217  return "Ring";
218  case SBEND3D:
219  return "SBend3D";
220  case SBEND:
221  return "SBend";
222  case SBENDWRAPPER:
223  return "SBendwrapper";
224  case SEPARATOR:
225  return "Separator";
226  case SEPTUM:
227  return "Septum";
228  case SOLENOID:
229  return "Solenoid";
230  case STRIPPER:
231  return "Stripper";
232  case TRAVELINGWAVE:
233  return "TravelingWave";
234  case VARIABLERFCAVITY:
235  return "VariableRFCavity";
236  case ANY:
237  default:
238  return "'unknown' type";
239  }
240 }
241 
243  std::string type = getTypeString();
244  return new ElementImage(getName(), type, userAttribs);
245 }
246 
247 
249  if(isSharable()) {
250  return this;
251  } else {
252  return clone();
253  }
254 }
255 
256 
258  shareFlag = true;
259 }
260 
261 
263  ElementBase *wrap = new AlignWrapper(this);
264  wrap->setName(getName());
265  return wrap;
266 }
267 
268 
270  return this;
271 }
272 
273 
276 }
277 
278 
280  return this;
281 }
282 
283 
285  return this;
286 }
287 
288 
290  return this;
291 }
292 
293 
295  return this;
296 }
297 
298 
300  return this;
301 }
302 
303 
305  return this;
306 }
307 
308 
310  for(AttributeSet::const_iterator i = set.begin(); i != set.end(); ++i) {
311  setAttribute(i->first, i->second);
312  }
313 
314  return true;
315 }
316 
318  wake_m = wk;//->clone(getName() + std::string("_wake")); }
319 }
320 
322  bgeometry_m = geo;//->clone(getName() + std::string("_wake")); }
323 }
324 
326  parmatint_m = parmatint;
327 }
328 
330  if (actionRange_m.size() > 0 && actionRange_m.front().second < s) {
331  actionRange_m.pop();
332  if (actionRange_m.size() > 0) {
333  elementEdge_m = actionRange_m.front().first;
334  }
335  }
336 }
virtual ElementBase * removeAlignWrapper()
Remove align wrapper.
Channel * getChannel(const std::string &aKey, bool create=false)
Construct a read/write channel.
Interface for basic beam line object.
Definition: ElementBase.h:128
virtual void removeAttribute(const std::string &aKey)
Remove an existing attribute.
BoundaryGeometry * bgeometry_m
Definition: ElementBase.h:488
Map of std::string versus double value.
Definition: AttributeSet.h:41
virtual void setName(const std::string &name)
Set element name.
const_iterator end() const
Iterator marking the end of the list.
Definition: AttributeSet.h:108
virtual ElementBase * removeWrappers()
Return the design element.
Define the position of a misaligned element.
Definition: AlignWrapper.h:39
NameMap::const_iterator const_iterator
An iterator for a map of name versus value.
Definition: AttributeSet.h:49
virtual ~ElementBase()
Definition: ElementBase.cpp:90
virtual Channel * getChannel(const std::string &aKey, bool create=false)
Construct a read/write channel.
std::string elementID
Definition: ElementBase.h:481
virtual void setAttribute(const std::string &aKey, double val)
Set value of an attribute.
virtual const std::string & getName() const
Get element name.
Definition: ElementBase.cpp:95
virtual ElementBase * removeFieldWrapper()
Remove field wrapper.
ParticleMatterInteractionHandler * parmatint_m
Definition: ElementBase.h:490
const_iterator begin() const
Iterator accessing first member.
Definition: AttributeSet.h:105
WakeFunction * wake_m
Definition: ElementBase.h:486
virtual void makeSharable()
Set sharable flag.
virtual ElementBase * makeWrappers()
Allow errors.
Abstract interface for read-only access to variable.
Definition: ConstChannel.h:29
virtual void setBoundaryGeometry(BoundaryGeometry *geo)
void updateElement(ElementBase *element)
double elementEdge_m
Definition: ElementBase.h:471
An image of an element.
Definition: ElementImage.h:35
virtual ElementImage * getImage() const
Construct an image.
Abstract base class for reference counted objects.
Definition: RCObject.h:42
std::string getTypeString() const
Definition: ElementBase.h:705
virtual ElementBase * copyStructure()
Make a structural copy.
virtual double getAttribute(const std::string &aKey) const
Get attribute value.
virtual ElementBase * clone() const =0
Return clone.
bool shareFlag
Definition: ElementBase.h:464
virtual void setParticleMatterInteraction(ParticleMatterInteractionHandler *spys)
void setCurrentSCoordinate(double s)
Abstract interface for read/write access to variable.
Definition: Channel.h:32
virtual const ConstChannel * getConstChannel(const std::string &aKey) const
Construct a read-only channel.
const std::string name
void removeAttribute(const std::string &aKey)
Remove an existing attribute.
virtual ElementBase * makeAlignWrapper()
Allow misalignment.
AttributeSet userAttribs
Definition: ElementBase.h:484
bool isSharable() const
Test if the element can be shared.
Definition: ElementBase.h:559
std::queue< std::pair< double, double > > actionRange_m
Definition: ElementBase.h:499
virtual bool isSettable() const
Test if settable.
Definition: Channel.cpp:36
virtual bool hasAttribute(const std::string &aKey) const
Test for existence of an attribute.
virtual ElementBase * makeFieldWrapper()
Allow field errors.
virtual void setWake(WakeFunction *wf)
attach a wake field to the element
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
bool update(const AttributeSet &)
Update element.