OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalECollimator.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: OpalCollimator.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: OpalECollimator
10 // The class of OPAL elliptic collimators.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:39 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
20 #include "Attributes/Attributes.h"
23 
24 #include <boost/regex.hpp>
25 #include <cstdlib>
26 
27 // Class OpalECollimator
28 // ------------------------------------------------------------------------
29 
31  OpalElement(SIZE, "ECOLLIMATOR",
32  "The \"ECOLLIMATOR\" element defines an elliptic collimator."),
33  parmatint_m(NULL) {
35  ("XSIZE", "Horizontal half-aperture in m");
37  ("YSIZE", "Vertical half-aperture in m");
39  ("OUTFN", "Monitor output filename");
40 
41 
42  registerStringAttribute("OUTFN");
43  registerRealAttribute("XSIZE");
44  registerRealAttribute("YSIZE");
45 
47 
48  setElement((new FlexibleCollimatorRep("ECOLLIMATOR"))->makeAlignWrapper());
49 }
50 
51 
53  OpalElement(name, parent),
54  parmatint_m(NULL) {
55  setElement((new FlexibleCollimatorRep(name))->makeAlignWrapper());
56 }
57 
58 
60  if(parmatint_m)
61  delete parmatint_m;
62 }
63 
64 
66  return new OpalECollimator(name, this);
67 }
68 
69 
72 
73  const FlexibleCollimatorRep *coll =
74  dynamic_cast<const FlexibleCollimatorRep *>(base.removeWrappers());
75  std::string Double("(-?[0-9]+\\.?[0-9]*([Ee][+-]?[0-9]+)?)");
76  std::string desc = coll->getDescription();
77 
78  boost::regex parser("ellipse\\(" + Double + "," + Double + "\\)");
79  boost::smatch what;
80  if (!boost::regex_match(desc, what, parser)) return;
81 
82  double width = atof(std::string(what[1]).c_str());
83  double height = atof(std::string(what[3]).c_str());
84 
85  attributeRegistry["XSIZE"]->setReal(0.5 * width);
86  attributeRegistry["YSIZE"]->setReal(0.5 * height);
87 }
88 
89 
92 
93  FlexibleCollimatorRep *coll =
94  dynamic_cast<FlexibleCollimatorRep *>(getElement()->removeWrappers());
95  double length = Attributes::getReal(itsAttr[LENGTH]);
96  coll->setElementLength(length);
97 
98  if (getOpalName() != "ECOLLIMATOR") {
99  double width = 2 * Attributes::getReal(itsAttr[XSIZE]);
100  double height = 2 * Attributes::getReal(itsAttr[YSIZE]);
101  std::stringstream description;
102  description << "ellipse(" << width << "," << height << ")";
103  coll->setDescription(description.str());
104  }
105 
107 
109  const std::string matterDescriptor = Attributes::getString(itsAttr[PARTICLEMATTERINTERACTION]);
111  parmatint_m = orig->clone(getOpalName() + std::string("_parmatint"));
114  }
115 
116  // Transmit "unknown" attributes.
118 }
std::string getDescription() const
Representation for a collimator.
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 setElementLength(double length)
Set design length.
Definition: ElementBase.h:515
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
static ParticleMatterInteraction * find(const std::string &name)
Find named PARTICLEMATTERINTERACTION.
ParticleMatterInteractionHandler * handler_m
static std::map< std::string, OwnPtr< AttCell > > attributeRegistry
The registry for named attributes.
Definition: OpalElement.h:172
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:284
void setDescription(const std::string &desc)
void initParticleMatterInteractionHandler(ElementBase &element)
void setOutputFN(const std::string &fn)
Base class for all beam line elements.
Definition: OpalElement.h:41
ParticleMatterInteraction * parmatint_m
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:133
virtual ~OpalECollimator()
void registerOwnership() const
virtual void update()
Update the embedded CLASSIC element.
virtual void updateUnknown(ElementBase *)
Transmit the ``unknown&#39;&#39; (not known to OPAL) attributes to CLASSIC.
virtual void setParticleMatterInteraction(ParticleMatterInteractionHandler *spys)
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:128
virtual OpalECollimator * clone(const std::string &name)
Make clone.
virtual ParticleMatterInteraction * clone(const std::string &name)
Make clone.
const std::string name
OpalECollimator()
Exemplar constructor.
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
The ECOLLIMATOR element.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:296
virtual void update()
Update the embedded CLASSIC collimator.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
static AttCell * registerRealAttribute(const std::string &name)
Register a ``real&#39;&#39; element attribute.
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307