OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalFlexibleCollimator.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: OpalFlexibleCollimator
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"
24 
25 #include <boost/regex.hpp>
26 
27 // Class OpalFlexibleCollimator
28 // ------------------------------------------------------------------------
29 
31  OpalElement(SIZE, "FLEXIBLECOLLIMATOR",
32  "The \"FLEXIBLECOLLIMATOR\" element defines a slit."),
33  partMatInt_m(NULL) {
35  ("FNAME", "File name containing description of holes");
37  ("DESCRIPTION", "String describing the distribution of holes");
39  ("OUTFN", "File name of log file for deleted particles");
41  ("DUMP", "Save quadtree and holes of collimator", false);
42 
43  registerStringAttribute("OUTFN");
45  registerStringAttribute("FNAME");
46 
48 
49  setElement((new FlexibleCollimatorRep("FLEXIBLECOLLIMATOR"))->makeAlignWrapper());
50 }
51 
52 
54  OpalElement(name, parent),
55  partMatInt_m(NULL) {
56  setElement((new FlexibleCollimatorRep(name))->makeAlignWrapper());
57 }
58 
59 
61  if(partMatInt_m)
62  delete partMatInt_m;
63 }
64 
65 
67  return new OpalFlexibleCollimator(name, this);
68 }
69 
70 
73 
74  const FlexibleCollimatorRep *coll =
75  dynamic_cast<const FlexibleCollimatorRep *>(base.removeWrappers());
76  attributeRegistry["DESCRIPTION"]->setString(coll->getDescription());
77 }
78 
79 
82 
83  FlexibleCollimatorRep *coll =
84  dynamic_cast<FlexibleCollimatorRep *>(getElement()->removeWrappers());
85  double length = Attributes::getReal(itsAttr[LENGTH]);
86  coll->setElementLength(length);
87 
88  std::string fname = Attributes::getString(itsAttr[FNAME]);
89  std::string desc = Attributes::getString(itsAttr[DESC]);
90  if (fname != "") {
91  std::ifstream it(fname);
92  std::string str((std::istreambuf_iterator<char>(it)),
93  std::istreambuf_iterator<char>());
94 
95  str = boost::regex_replace(str, boost::regex("//.*?\\n"), std::string(""), boost::match_default | boost::format_all);
96  str = boost::regex_replace(str, boost::regex("\\s"), std::string(""), boost::match_default | boost::format_all);
97 
98  coll->setDescription(str);
99  } else if (desc != "") {
100  desc = boost::regex_replace(desc, boost::regex("[\\t ]"), std::string(""), boost::match_default | boost::format_all);
101  coll->setDescription(desc);
102  } else if (getOpalName() != "FLEXIBLECOLLIMATOR") {
103  throw OpalException("OpalFlexibleCollimator::update",
104  "A description for the holes has to be provided, either using DESCRIPTION or FNAME");
105  }
107 
112  }
113 
116  }
117 
118  // Transmit "unknown" attributes.
120 }
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
The base class for all OPAL exceptions.
Definition: OpalException.h:28
virtual ElementBase * removeWrappers()
Return the design element.
ParticleMatterInteraction * partMatInt_m
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
virtual OpalFlexibleCollimator * clone(const std::string &name)
Make clone.
static ParticleMatterInteraction * find(const std::string &name)
Find named PARTICLEMATTERINTERACTION.
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:66
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 writeHolesAndQuadtree(const std::string &baseFilename) const
OpalFlexibleCollimator()
Exemplar constructor.
void initParticleMatterInteractionHandler(ElementBase &element)
virtual void update()
Update the embedded CLASSIC collimator.
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
The ECOLLIMATOR element.
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
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:56
const std::string name
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:296
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307