OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalSBend3D.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Chris Rogers
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * 1. Redistributions of source code must retain the above copyright notice,
7  * this list of conditions and the following disclaimer.
8  * 2. Redistributions in binary form must reproduce the above copyright notice,
9  * this list of conditions and the following disclaimer in the documentation
10  * and/or other materials provided with the distribution.
11  * 3. Neither the name of STFC nor the names of its contributors may be used to
12  * endorse or promote products derived from this software without specific
13  * prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "Elements/OpalSBend3D.h"
29 #include "Physics/Physics.h"
30 #include "AbsBeamline/SBend3D.h"
31 #include "Attributes/Attributes.h"
33 
34 extern Inform *gmsg;
35 
37  OpalElement(SIZE, "SBEND3D",
38  "The \"SBEND3D\" element defines a sector bending magnet.") {
40  ("FMAPFN", "The name of the field map.");
41  itsAttr[FIELD_UNITS] = Attributes::makeReal("FIELD_UNITS",
42  "Scale the field map up or down by this factor (default 1. is T).");
43  itsAttr[LENGTH_UNITS] = Attributes::makeReal("LENGTH_UNITS",
44  "Units for length coordinates (default 1. is mm).");
45  registerStringAttribute("FMAPFN");
46  registerRealAttribute("FIELD_UNITS");
47  registerRealAttribute("LENGTH_UNITS");
48 
50 
51  setElement((new SBend3D("SBEND3D"))->makeAlignWrapper());
52 }
53 
54 
55 OpalSBend3D::OpalSBend3D(const std::string &name, OpalSBend3D *parent):
56  OpalElement(name, parent) {
57  setElement((new SBend3D(name))->makeAlignWrapper());
58 }
59 
60 
62 }
63 
64 
65 OpalSBend3D *OpalSBend3D::clone(const std::string &name) {
66  return new OpalSBend3D(name, this);
67 }
68 
69 
70 void OpalSBend3D::
73 }
74 
75 
77  SBend3D *bend = dynamic_cast<SBend3D*>(getElement()->removeWrappers());
78  if (itsAttr[FIELD_UNITS])
79  bend->setFieldUnits(Attributes::getReal(itsAttr[FIELD_UNITS]));
80  if (itsAttr[LENGTH_UNITS])
81  bend->setLengthUnits(Attributes::getReal(itsAttr[LENGTH_UNITS]));
82  // this has to be done last as we initialise field map here
83  // (need units before initialisation)
86 
87 }
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Definition: OpalSBend3D.cpp:71
static AttCell * registerStringAttribute(const std::string &name)
Register a ``string&#39;&#39; element attribute.
Interface for basic beam line object.
Definition: ElementBase.h:128
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
ValueFlag
Switch for value desired on ATTLIST command.
Definition: OpalElement.h:71
virtual ElementBase * removeWrappers()
Return the design element.
virtual void update()
Definition: OpalSBend3D.cpp:76
Inform * gmsg
Definition: Main.cpp:21
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
virtual ~OpalSBend3D()
Definition: OpalSBend3D.cpp:61
void setFieldUnits(double fieldUnits)
Definition: SBend3D.h:143
Base class for all beam line elements.
Definition: OpalElement.h:41
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:133
void registerOwnership() const
virtual OpalSBend3D * clone(const std::string &name)
Definition: OpalSBend3D.cpp:65
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:128
void setLengthUnits(double lengthUnits)
Definition: SBend3D.h:137
const std::string name
virtual ElementBase * makeAlignWrapper()
Allow misalignment.
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
Definition: Inform.h:41
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:296
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
static AttCell * registerRealAttribute(const std::string &name)
Register a ``real&#39;&#39; element attribute.
void setFieldMapFileName(std::string name)
Definition: SBend3D.cpp:99
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307