OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
Element.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: Element.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: Element
10 // The base class for all OPAL beamline elements.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:34 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
22 #include "Utilities/Options.h"
23 
24 
25 // Class Element
26 // ------------------------------------------------------------------------
27 
29 {}
30 
31 
33  return (dynamic_cast<Element *>(object) != 0);
34 }
35 
36 
37 Element *Element::find(const std::string &name) {
39  Element *element = dynamic_cast<Element *>(opal->find(name));
40  if(element == 0) {
41  throw OpalException("Element::find()",
42  "Element \"" + name + "\" not found.");
43  }
44  return element;
45 }
46 
47 
48 const std::string Element::getCategory() const {
49  return "ELEMENT";
50 }
51 
52 
53 bool Element::shouldTrace() const {
54  return false;
55 
56 }
57 
58 bool Element::shouldUpdate() const {
59  return false;
60 }
61 
62 
64  switch(ref) {
65 
66  case IS_CENTRE:
67  return (- getLength() / 2.0);
68 
69  case IS_EXIT:
70  return (- getLength());
71 
72  default:
73  return 0.0;
74  }
75 }
76 
77 
79  switch(ref) {
80 
81  case IS_ENTRY:
82  return getLength();
83 
84  case IS_CENTRE:
85  return (getLength() / 2.0);
86 
87  default:
88  return 0.0;
89  }
90 }
91 
92 
93 void Element::setShared(bool flag) {
94  Object::setShared(flag);
95  if(flag) itsClassicElement->makeSharable();
96 }
97 
98 
99 Element::Element(int size, const char *name, const char *help):
100  Object(size, name, help)
101 {}
102 
103 
104 Element::Element(const std::string &name, Element *parent):
105  Object(name, parent)
106 {}
Pointer< ElementBase > itsClassicElement
Definition: Element.h:121
virtual double getExit(ReferenceType) const
Return arc length from origin to exit (positive !).
Definition: Element.cpp:78
The global OPAL structure.
Definition: OpalData.h:54
virtual void setShared(bool)
Set/reset shared flag.
Definition: Object.cpp:252
The base class for all OPAL exceptions.
Definition: OpalException.h:28
virtual void setShared(bool)
Set shared flag.
Definition: Element.cpp:93
virtual bool shouldUpdate() const
Update flag.
Definition: Element.cpp:58
virtual bool canReplaceBy(Object *object)
Test if replacement is allowed.
Definition: Element.cpp:32
virtual void makeSharable()
Set sharable flag.
static OpalData * getInstance()
Definition: OpalData.cpp:209
The base class for all OPAL elements.
Definition: Element.h:46
ReferenceType
Reference for element positioning.
Definition: Element.h:52
static Element * find(const std::string &name)
Find named Element.
Definition: Element.cpp:37
virtual double getLength() const =0
Return element length.
virtual bool shouldTrace() const
Trace flag.
Definition: Element.cpp:53
Object * find(const std::string &name)
Find entry.
Definition: OpalData.cpp:618
The base class for all OPAL objects.
Definition: Object.h:48
const std::string name
virtual const std::string getCategory() const
Return the object category as a string.
Definition: Element.cpp:48
virtual double getEntrance(ReferenceType) const
Return arc length from origin to entrance (negative !).
Definition: Element.cpp:63
virtual ~Element()
Definition: Element.cpp:28