OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
FlatWriter.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: FlatWriter.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.2.4.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: FlatWriter
10 // The class for the OPAL FlatWriter command.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // Revision History:
15 // $Date: 2002/12/09 15:06:08 $
16 // $Author: jsberg $
17 //
18 // JMJ: removing dirty C-style hacking where splitName is constructed.
19 // 13/10/2000
20 // ------------------------------------------------------------------------
21 
22 #include "Lines/FlatWriter.h"
23 #include "AbsBeamline/Drift.h"
28 #include "AbstractObjects/Object.h"
30 #include "Attributes/Attributes.h"
31 #include "Beamlines/Beamline.h"
33 #include <vector>
34 #include <sstream>
35 
36 extern Inform *gmsg;
37 
38 // Class FlatWriter.
39 // ------------------------------------------------------------------------
40 // Visitor class for writing a line or sequence as a flat sequence in
41 // OPAL-8 format.
42 
44  std::ostream &os):
45  DefaultVisitor(bl, false, false),
46  itsPosition(0.0), itsSequence(seq), itsStream(os)
47 {}
48 
49 
51 {}
52 
53 
55  return itsSequence;
56 }
57 
58 
59 void FlatWriter::visitDrift(const Drift &drf) {
60  // All drifts are skipped, but their length is accumulated.
62 }
63 
64 
66  ElementBase *base = i.getElement();
67 
68  if(const MPSplitIntegrator *mpi =
69  dynamic_cast<const MPSplitIntegrator *>(&i)) {
70  // For a MPSliceIntegrator store the equivalent thin lenses.
71  double length = base->getElementLength();
72  std::vector<double> itsSlices;
73  mpi->getSlices(itsSlices);
74  int slices = itsSlices.size() - 1;
75 
76  if(slices > 1 && length != 0.0) {
77  // Construct internal element name.
78  // JMJ modified following to get rid of char stuff 13/10/2000
79  // This removes leading zeros in slice number and also changes
80  // underscore character to a pair of dots.
81  const std::string name = base->getName();
82 
83  // Store the slices in the temporary sequence.
84  // JMJ 18/12/2000, put name generation inside loop
85  // JMJ 19/12/2000, put declaration of splitNameStream inside loop so
86  // that it would be re-initialised each pass.
87  for(int k = 0; k < slices; ++k) {
88 
89  std::ostringstream splitNameStream;
90  splitNameStream << name << ".." << k + 1 << std::ends ;
91  std::string splitName = splitNameStream.str();
92 
93  // Find or construct internal element.
94  Object *split = OpalData::getInstance()->find(splitName);
95  if(split == 0) {
96  split = OpalData::getInstance()->find(name)->clone(splitName);
97  Attribute *attr = split->findAttribute("L");
98  Attributes::setReal(*attr, length / double(slices));
99  OpalData::getInstance()->define(split);
100  itsStream << *split;
101  }
102  SequenceMember member;
103  member.setElement(static_cast<Element *>(split)->getElement());
105  member.itsPosition = itsPosition + itsSlices[k] * length;
106  itsSequence.push_back(member);
107 
108  }
109 
110  itsPosition += length;
111  } else {
113  }
114  } else {
116  }
117 }
118 
119 
121  const std::string name = elem.getName();
122 
123  if(name[0] != '#') {
124  SequenceMember member;
125  member.setElement(const_cast<ElementBase *>(&elem));
127  double length = elem.getElementLength();
128  member.itsPosition = itsPosition + length / 2.0;
129  itsSequence.push_back(member);
130  itsPosition += length;
131  }
132 }
void setReal(Attribute &attr, double val)
Set real value.
Definition: Attributes.cpp:236
virtual void visitDrift(const Drift &)
Override drift operation.
Definition: FlatWriter.cpp:59
Interface for basic beam line object.
Definition: ElementBase.h:128
void define(Object *newObject)
Define a new object.
Definition: OpalData.cpp:538
FlatWriter(const Beamline &, Sequence::TLine &seq, std::ostream &os)
Definition: FlatWriter.cpp:43
double itsPosition
Definition: FlatWriter.h:62
virtual Attribute * findAttribute(const std::string &name)
Find an attribute by name.
ElementBase * getElement() const
Return the embedded element.
Definition: Integrator.h:97
Inform * gmsg
Definition: Main.cpp:21
std::ostream & itsStream
Definition: FlatWriter.h:68
virtual const std::string & getName() const
Get element name.
Definition: ElementBase.cpp:95
Interface for drift space.
Definition: Drift.h:33
Default algorithms.
double itsPosition
The position attribute (&quot;AT&quot; or &quot;DRIFT&quot;).
static OpalData * getInstance()
Definition: OpalData.cpp:209
MemberType itsType
Type word.
Template class for beam lines.
Definition: TBeamline.h:40
A representation of an Object attribute.
Definition: Attribute.h:55
virtual void applyDefault(const ElementBase &)
Apply default.
Definition: FlatWriter.cpp:120
virtual double getElementLength() const
Get design length.
Definition: ElementBase.h:511
virtual void visitMapIntegrator(const MapIntegrator &)
Override beamline exit.
Definition: FlatWriter.cpp:65
An abstract sequence of beam line components.
Definition: Beamline.h:37
Sequence::TLine & itsSequence
Definition: FlatWriter.h:65
Object * find(const std::string &name)
Find entry.
Definition: OpalData.cpp:618
The base class for all OPAL objects.
Definition: Object.h:48
virtual Object * clone(const std::string &name)=0
Return a clone.
const std::string name
const Sequence::TLine & getSequence() const
Return the temporary sequence.
Definition: FlatWriter.cpp:54
Integrator replacing each multipole by a set of thin lenses.
Definition: Inform.h:41
Integrate a map.
Definition: MapIntegrator.h:41
void setElement(ElementBase *)
Set the element pointer.
Definition: ElmPtr.h:63
A member of a SEQUENCE.