OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalRCollimator.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: OpalRCollimator.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: OpalRCollimator
10 // The class of OPAL rectangular collimators.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:40 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
21 #include "Attributes/Attributes.h"
24 
25 #include <boost/regex.hpp>
26 #include <cstdlib>
27 
28 // Class OpalRCollimator
29 // ------------------------------------------------------------------------
30 
32  OpalElement(SIZE, "RCOLLIMATOR",
33  "The \"RCOLLIMATOR\" element defines a rectangular collimator."),
34  parmatint_m(NULL) {
36  ("XSIZE", "Horizontal half-aperture in m");
38  ("YSIZE", "Vertical half-aperture in m");
40  ("OUTFN", "Monitor output filename");
41 
42  registerStringAttribute("OUTFN");
43  registerRealAttribute("XSIZE");
44  registerRealAttribute("YSIZE");
45 
47 
48  setElement((new FlexibleCollimatorRep("RCOLLIMATOR"))->makeAlignWrapper());
49 }
50 
51 
53  OpalElement(name, parent),
54  parmatint_m(NULL) {
55  setElement((new FlexibleCollimatorRep(name))->makeAlignWrapper());
56 }
57 
58 
60  delete parmatint_m;
61 }
62 
63 
65  return new OpalRCollimator(name, this);
66 }
67 
68 
72 
73  const FlexibleCollimatorRep *coll =
74  dynamic_cast<const FlexibleCollimatorRep *>(base.removeWrappers());
75 
76  std::string Double("(-?[0-9]+\\.?[0-9]*([Ee][+-]?[0-9]+)?)");
77  std::string desc = coll->getDescription();
78 
79  boost::regex parser("rectangle\\(" + Double + "," + Double + "\\)");
80  boost::smatch what;
81  if (!boost::regex_match(desc, what, parser)) return;
82 
83  double width = atof(std::string(what[1]).c_str());
84  double height = atof(std::string(what[3]).c_str());
85 
86  attributeRegistry["XSIZE"]->setReal(0.5 * width);
87  attributeRegistry["YSIZE"]->setReal(0.5 * height);
88 }
89 
90 
93 
94  FlexibleCollimatorRep *coll =
95  dynamic_cast<FlexibleCollimatorRep *>(getElement()->removeWrappers());
97 
98  if (getOpalName() != "RCOLLIMATOR") {
99  double width = 2 * Attributes::getReal(itsAttr[XSIZE]);
100  double height = 2 * Attributes::getReal(itsAttr[YSIZE]);
101  std::stringstream description;
102  description << "rectangle(" << width << "," << height << ")";
103  coll->setDescription(description.str());
104 
106  }
107 
112  }
113 
114  // Transmit "unknown" attributes.
116 }
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 ~OpalRCollimator()
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
ValueFlag
Switch for value desired on ATTLIST command.
Definition: OpalElement.h:71
virtual OpalRCollimator * clone(const std::string &name)
Make clone.
The RCOLLIMATOR element.
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
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:133
void registerOwnership() const
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
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
const std::string name
virtual void update()
Update the embedded CLASSIC collimator.
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
ParticleMatterInteraction * parmatint_m
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.
OpalRCollimator()
Exemplar constructor.
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307