OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
OpalSlit.cpp
Go to the documentation of this file.
1//
2// Class OpalSlit
3// The SLIT element.
4//
5// Copyright (c) 200x - 2020, 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/OpalSlit.h"
22
23#include <memory>
24#include <sstream>
25#include <string>
26#include <typeinfo>
27#include <vector>
28
30 OpalElement(SIZE, "SLIT",
31 "The \"SLIT\" element defines a slit."),
32 parmatint_m(nullptr) {
34 ("XSIZE", "Horizontal half-aperture in m");
36 ("YSIZE", "Vertical half-aperture in m");
37
39
41}
42
43
44OpalSlit::OpalSlit(const std::string& name, OpalSlit* parent):
45 OpalElement(name, parent),
46 parmatint_m(nullptr) {
48}
49
50
52 if (parmatint_m)
53 delete parmatint_m;
54}
55
56
57OpalSlit* OpalSlit::clone(const std::string& name) {
58 return new OpalSlit(name, this);
59}
60
61
64
66 dynamic_cast<FlexibleCollimatorRep*>(getElement());
67
68 double length = Attributes::getReal(itsAttr[LENGTH]);
69 coll->setElementLength(length);
70
71 if (getOpalName() != "SLIT") {
72 double width = 2 * Attributes::getReal(itsAttr[XSIZE]);
73 double height = 2 * Attributes::getReal(itsAttr[YSIZE]);
74 std::stringstream description;
75 description << "rectangle(" << width << "," << height << ")";
76 coll->setDescription(description.str());
77 }
78
80
82 const std::string matterDescriptor = Attributes::getString(itsAttr[PARTICLEMATTERINTERACTION]);
84 parmatint_m = orig->clone(matterDescriptor);
87 }
88
89 std::vector<double> apert = {Attributes::getReal(itsAttr[XSIZE]),
91 1.0};
93
94 // Transmit "unknown" attributes.
96}
@ SIZE
Definition IndexMap.cpp:174
const std::string name
double getReal(const Attribute &attr)
Return real value.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
std::string getString(const Attribute &attr)
Get string value.
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition Element.h:120
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition Element.h:125
const std::string & getOpalName() const
Return object name.
Definition Object.cpp:310
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:216
void setAperture(const ApertureType &type, const std::vector< double > &args)
virtual void setElementLength(double length)
Set design length.
void setOutputFN(std::string fn)
Set output filename.
virtual void setParticleMatterInteraction(ParticleMatterInteractionHandler *spys)
void setDescription(const std::string &desc)
@ PARTICLEMATTERINTERACTION
Definition OpalElement.h:42
virtual void updateUnknown(ElementBase *)
Transmit the `‘unknown’' (not known to OPAL) attributes to CLASSIC.
virtual void update()
Update the embedded CLASSIC element.
void registerOwnership() const
virtual ~OpalSlit()
Definition OpalSlit.cpp:51
virtual OpalSlit * clone(const std::string &name)
Make clone.
Definition OpalSlit.cpp:57
OpalSlit()
Exemplar constructor.
Definition OpalSlit.cpp:29
ParticleMatterInteraction * parmatint_m
Definition OpalSlit.h:56
virtual void update()
Update the embedded CLASSIC collimator.
Definition OpalSlit.cpp:62
virtual ParticleMatterInteraction * clone(const std::string &name)
Make clone.
static ParticleMatterInteraction * find(const std::string &name)
Find named PARTICLEMATTERINTERACTION.
ParticleMatterInteractionHandler * handler_m
void initParticleMatterInteractionHandler(ElementBase &element)