OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
OpalDegrader.cpp
Go to the documentation of this file.
1 //
2 // Class OpalDegrader
3 // The DEGRADER element.
4 //
5 // Copyright (c) 200x - 2023, 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 //
18 #include "Elements/OpalDegrader.h"
19 #include "Attributes/Attributes.h"
22 
23 
25  OpalElement(SIZE, "DEGRADER",
26  "The \"DEGRADER\" element defines a degrader."),
27  parmatint_m(nullptr) {
29  ("XSIZE", "Horizontal axis of the transverse elliptical shape [m]", 1E6);
30 
32  ("YSIZE", "Vertical axis of the transverse elliptical shape [m]", 1E6);
33 
35 
36  setElement(new DegraderRep("DEGRADER"));
37 }
38 
39 
40 OpalDegrader::OpalDegrader(const std::string& name, OpalDegrader* parent):
41  OpalElement(name, parent),
42  parmatint_m(nullptr) {
43  setElement(new DegraderRep(name));
44 }
45 
46 
48  if (parmatint_m)
49  delete parmatint_m;
50 }
51 
52 
53 OpalDegrader* OpalDegrader::clone(const std::string& name) {
54  return new OpalDegrader(name, this);
55 }
56 
57 
60 
61  DegraderRep* deg = dynamic_cast<DegraderRep*>(getElement());
62 
63  double length = Attributes::getReal(itsAttr[LENGTH]);
64  double xsize = Attributes::getReal(itsAttr[XSIZE]);
65  double ysize = Attributes::getReal(itsAttr[YSIZE]);
66 
67  deg->setElementLength(length);
68  deg->setDimensions(xsize, ysize);
69 
70  if (itsAttr[PARTICLEMATTERINTERACTION] && parmatint_m == nullptr) {
71  const std::string matterDescriptor = Attributes::getString(itsAttr[PARTICLEMATTERINTERACTION]);
73  parmatint_m = orig->clone(matterDescriptor);
76  }
77 
78  // Transmit "unknown" attributes.
80 }
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
virtual void setParticleMatterInteraction(ParticleMatterInteractionHandler *spys)
static ParticleMatterInteraction * find(const std::string &name)
Find named PARTICLEMATTERINTERACTION.
virtual void update()
Update the embedded CLASSIC collimator.
OpalDegrader()
Exemplar constructor.
virtual OpalDegrader * clone(const std::string &name)
Make clone.
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:125
void initParticleMatterInteractionHandler(ElementBase &element)
virtual ~OpalDegrader()
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:120
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
const std::string name
T deg(T x)
Convert radians to degrees.
Definition: matheval.hpp:75
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
ParticleMatterInteractionHandler * handler_m
virtual ParticleMatterInteraction * clone(const std::string &name)
Make clone.
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:419
virtual void updateUnknown(ElementBase *)
Transmit the ``unknown&#39;&#39; (not known to OPAL) attributes to CLASSIC.
ParticleMatterInteraction * parmatint_m
Definition: OpalDegrader.h:54
void setDimensions(double xsize, double ysize)
Definition: Degrader.cpp:65
virtual void update()
Update the embedded CLASSIC element.
void registerOwnership() const