OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
ParticleMatterInteraction.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: ParticleMatterInteraction.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.3.4.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: ParticleMatterInteraction
10 // The class for the OPAL PARTICLEMATTERINTERACTION command.
11 //
12 // $Date: 2009/07/14 22:09:00 $
13 // $Author: C. Kraus $
14 //
15 // ------------------------------------------------------------------------
16 
19 #include "Attributes/Attributes.h"
20 #include "Physics/Physics.h"
25 #include "Utilities/Util.h"
26 
27 extern Inform *gmsg;
28 
29 using namespace Physics;
30 
31 
32 // Class ParticleMatterInteraction
33 // ------------------------------------------------------------------------
34 
35 // The attributes of class ParticleMatterInteraction.
36 namespace {
37  enum {
38  // DESCRIPTION OF SINGLE PARTICLE:
39  TYPE, // The type of the wake
40  MATERIAL, // From of the tube
41  ENABLERUTHERFORD,
42  SIZE
43  };
44 }
45 
47  Definition(SIZE, "PARTICLEMATTERINTERACTION",
48  "The \"SURFACE_PHYSICS\" statement defines data for the particle mater interaction handler "
49  "on an element."),
50  handler_m(0) {
52  ("TYPE", "Specifies the particle mater interaction handler: Collimator");
53 
55  ("MATERIAL", "The material of the surface");
56 
57  itsAttr[ENABLERUTHERFORD] = Attributes::makeBool("ENABLERUTHERFORD",
58  "Enable large angle scattering", true);
59 
60  ParticleMatterInteraction *defParticleMatterInteraction = clone("UNNAMED_PARTICLEMATTERINTERACTION");
61  defParticleMatterInteraction->builtin = true;
62 
63  try {
64  defParticleMatterInteraction->update();
65  OpalData::getInstance()->define(defParticleMatterInteraction);
66  } catch(...) {
67  delete defParticleMatterInteraction;
68  }
69 
71 }
72 
73 
75  Definition(name, parent),
76  handler_m(parent->handler_m)
77 {}
78 
79 
81  if(handler_m)
82  delete handler_m;
83 }
84 
85 
87  // Can replace only by another PARTICLEMATTERINTERACTION.
88  return dynamic_cast<ParticleMatterInteraction *>(object) != 0;
89 }
90 
91 
93  return new ParticleMatterInteraction(name, this);
94 }
95 
96 
98  update();
99 }
100 
101 
103  ParticleMatterInteraction *parmatint = dynamic_cast<ParticleMatterInteraction *>(OpalData::getInstance()->find(name));
104 
105  if(parmatint == 0) {
106  throw OpalException("ParticleMatterInteraction::find()", "ParticleMatterInteraction \"" + name + "\" not found.");
107  }
108  return parmatint;
109 }
110 
111 
113  // Set default name.
114  if(getOpalName().empty()) setOpalName("UNNAMED_PARTICLEMATTERINTERACTION");
115 }
116 
117 
119 
120  std::string material = Util::toUpper(Attributes::getString(itsAttr[MATERIAL]));
121  bool enableRutherford = Attributes::getBool(itsAttr[ENABLERUTHERFORD]);
122 
123  const std::string type = Util::toUpper(Attributes::getString(itsAttr[TYPE]));
124  if(type == "CCOLLIMATOR" ||
125  type == "COLLIMATOR" ||
126  type == "DEGRADER") {
127 
128  handler_m = new CollimatorPhysics(getOpalName(), &element, material, enableRutherford);
129  *gmsg << *this << endl;
130  }
131  else if(type == "BEAMSTRIPPING") {
132  handler_m = new BeamStrippingPhysics(getOpalName(), &element);
133  *gmsg << *this << endl;
134  }
135  else {
136  handler_m = 0;
137  INFOMSG(getOpalName() + ": no particle mater interaction handler attached, TYPE == " << Attributes::getString(itsAttr[TYPE]) << endl);
138  }
139 }
140 
142  handler_m->updateElement(element);
143 }
144 
145 void ParticleMatterInteraction::print(std::ostream &os) const {
146  os << "* ************* P A R T I C L E M A T T E R I N T E R A C T I O N ****************** " << std::endl;
147  os << "* PARTICLEMATTERINTERACTION " << getOpalName() << '\n'
148  << "* TYPE " << Attributes::getString(itsAttr[TYPE]) << '\n';
149 
150  if ( Attributes::getString(itsAttr[TYPE]) != "BEAMSTRIPPING" )
151  os << "* MATERIAL " << Attributes::getString(itsAttr[MATERIAL]) << '\n';
152 
153  os << "* ********************************************************************************** " << std::endl;
154 }
Interface for basic beam line object.
Definition: ElementBase.h:128
void define(Object *newObject)
Define a new object.
Definition: OpalData.cpp:538
The base class for all OPAL definitions.
Definition: Definition.h:30
The base class for all OPAL exceptions.
Definition: OpalException.h:28
Inform * gmsg
Definition: Main.cpp:21
std::string toUpper(const std::string &str)
Definition: Util.cpp:130
void updateElement(ElementBase *element)
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
virtual bool canReplaceBy(Object *object)
Test if replacement is allowed.
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 OpalData * getInstance()
Definition: OpalData.cpp:209
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:284
virtual void update()
Update the PARTICLEMATTERINTERACTION data.
void initParticleMatterInteractionHandler(ElementBase &element)
virtual void execute()
Check the PARTICLEMATTERINTERACTION data.
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:194
#define INFOMSG(msg)
Definition: IpplInfo.h:397
Object * find(const std::string &name)
Find entry.
Definition: OpalData.cpp:618
The base class for all OPAL objects.
Definition: Object.h:48
virtual ParticleMatterInteraction * clone(const std::string &name)
Make clone.
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:56
void print(std::ostream &os) const
Print the object.
const std::string name
void setOpalName(const std::string &name)
Set object name.
Definition: Object.cpp:305
bool builtin
Built-in flag.
Definition: Object.h:231
ParticleMatterInteraction()
Exemplar constructor.
Definition: Inform.h:41
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:296
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307