OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
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
35
36#include <memory>
37
38
39class Element: public Object {
40
41public:
42
44 // Used in the SEQUENCE command.
46 IS_ENTRY, // Reference point is at element entrance.
47 IS_CENTRE, // Reference point is at element centre
48 IS_EXIT // Reference point is at element exit.
49 };
50
51 virtual ~Element();
52
54 // Return true, if the replacement is also an Element.
55 virtual bool canReplaceBy(Object *object);
56
58 // If an element with the name [b]name[/b] exists,
59 // return a pointer to that element.
60 // If no such element exists, throw [b]OpalException[/b].
61 static Element *find(const std::string &name);
62
64 // Return the string "ELEMENT".
65 virtual const std::string getCategory() const;
66
68 // If true, the object's execute() function should be traced.
69 // Always false for elements.
70 virtual bool shouldTrace() const;
71
73 // If true, the data structure should be updated before calling execute().
74 // Always false for elements.
75 virtual bool shouldUpdate() const;
76
77
79 virtual double getLength() const = 0;
80
82 virtual double getEntrance(ReferenceType) const;
83
85 virtual double getExit(ReferenceType) const;
86
88 // If true, all references to this name are to the same object.
89 virtual void setShared(bool);
90
92 // Return a pointer to the embedded CLASSIC ElementBase
93 inline ElementBase *getElement() const;
94
96 inline void setElement(ElementBase *);
97
98protected:
99
101 Element(int size, const char *name, const char *help);
102
104 Element(const std::string &name, Element *parent);
105
106private:
107
108 // Not implemented.
110 Element(const Element &);
111 void operator=(const Element &);
112
113 // The embedded CLASSIC element.
114 std::shared_ptr<ElementBase> itsClassicElement;
115};
116
117
118// Inline functions.
119// ------------------------------------------------------------------------
120
122 return &*itsClassicElement;
123}
124
125
127 itsClassicElement = std::shared_ptr<ElementBase>(base);
128}
129
130#endif // OPAL_Element_HH
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
virtual ~Element()
Definition Element.cpp:36
virtual const std::string getCategory() const
Return the object category as a string.
Definition Element.cpp:56
std::shared_ptr< ElementBase > itsClassicElement
Definition Element.h:114
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:45
@ IS_EXIT
Definition Element.h:48
@ IS_ENTRY
Definition Element.h:46
@ IS_CENTRE
Definition Element.h:47
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition Element.h:121
Element(const Element &)
Element(int size, const char *name, const char *help)
Constructor for exemplars.
Definition Element.cpp:107
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:126
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
Object(int size, const char *name, const char *help)
Constructor for exemplars.
Definition Object.cpp:354