OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
Element.h
Go to the documentation of this file.
1 //
2 // Class Element
3 // The base class for all OPAL elements.
4 // It implements the common behaviour of elements, it can also be used via
5 // dynamic casting to determine whether an object represents an element.
6 //
7 // Each Element object contains a pointer to a CLASSIC beam line element,
8 // known as the ``ideal'' element.
9 //
10 // If sharable flag is set, all occurrences of the element are supposed to
11 // have the same imperfections. Thus the assembly is shared when it is used
12 // more than once in beam lines or sequences.
13 //
14 // If the sharable flag is not set, each occurrence of the element is supposed
15 // to have its own imperfections, but the same ideal representation.
16 //
17 // Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
18 // All rights reserved
19 //
20 // This file is part of OPAL.
21 //
22 // OPAL is free software: you can redistribute it and/or modify
23 // it under the terms of the GNU General Public License as published by
24 // the Free Software Foundation, either version 3 of the License, or
25 // (at your option) any later version.
26 //
27 // You should have received a copy of the GNU General Public License
28 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
29 //
30 #ifndef OPAL_Element_HH
31 #define OPAL_Element_HH
32 
33 #include "AbstractObjects/Object.h"
36 
37 
38 class Element: public Object {
39 
40 public:
41 
43  // Used in the SEQUENCE command.
45  IS_ENTRY, // Reference point is at element entrance.
46  IS_CENTRE, // Reference point is at element centre
47  IS_EXIT // Reference point is at element exit.
48  };
49 
50  virtual ~Element();
51 
53  // Return true, if the replacement is also an Element.
54  virtual bool canReplaceBy(Object *object);
55 
57  // If an element with the name [b]name[/b] exists,
58  // return a pointer to that element.
59  // If no such element exists, throw [b]OpalException[/b].
60  static Element *find(const std::string &name);
61 
63  // Return the string "ELEMENT".
64  virtual const std::string getCategory() const;
65 
67  // If true, the object's execute() function should be traced.
68  // Always false for elements.
69  virtual bool shouldTrace() const;
70 
72  // If true, the data structure should be updated before calling execute().
73  // Always false for elements.
74  virtual bool shouldUpdate() const;
75 
76 
78  virtual double getLength() const = 0;
79 
81  virtual double getEntrance(ReferenceType) const;
82 
84  virtual double getExit(ReferenceType) const;
85 
87  // If true, all references to this name are to the same object.
88  virtual void setShared(bool);
89 
91  // Return a pointer to the embedded CLASSIC ElementBase
92  inline ElementBase *getElement() const;
93 
95  inline void setElement(ElementBase *);
96 
97 protected:
98 
100  Element(int size, const char *name, const char *help);
101 
103  Element(const std::string &name, Element *parent);
104 
105 private:
106 
107  // Not implemented.
109  Element(const Element &);
110  void operator=(const Element &);
111 
112  // The embedded CLASSIC element.
114 };
115 
116 
117 // Inline functions.
118 // ------------------------------------------------------------------------
119 
121  return &*itsClassicElement;
122 }
123 
124 
125 inline void Element::setElement(ElementBase *base) {
126  itsClassicElement = base;
127 }
128 
129 #endif // OPAL_Element_HH
const std::string name
virtual double getEntrance(ReferenceType) const
Return arc length from origin to entrance (negative !).
Definition: Element.cpp:71
virtual void setShared(bool)
Set shared flag.
Definition: Element.cpp:101
Pointer< ElementBase > itsClassicElement
Definition: Element.h:113
virtual ~Element()
Definition: Element.cpp:36
virtual const std::string getCategory() const
Return the object category as a string.
Definition: Element.cpp:56
virtual double getLength() const =0
Return element length.
static Element * find(const std::string &name)
Find named Element.
Definition: Element.cpp:45
ReferenceType
Reference for element positioning.
Definition: Element.h:44
@ IS_EXIT
Definition: Element.h:47
@ IS_ENTRY
Definition: Element.h:45
@ IS_CENTRE
Definition: Element.h:46
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:120
Element(const Element &)
void operator=(const Element &)
virtual bool canReplaceBy(Object *object)
Test if replacement is allowed.
Definition: Element.cpp:40
virtual bool shouldTrace() const
Trace flag.
Definition: Element.cpp:61
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:125
virtual bool shouldUpdate() const
Update flag.
Definition: Element.cpp:66
virtual double getExit(ReferenceType) const
Return arc length from origin to exit (positive !).
Definition: Element.cpp:86
The base class for all OPAL objects.
Definition: Object.h:48