OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
Flatten.h
Go to the documentation of this file.
1 #ifndef OPAL_Flatten_HH
2 #define OPAL_Flatten_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: Flatten.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.2 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Template class: Flatten<T>
13 //
14 // ------------------------------------------------------------------------
15 //
16 // $Date: 2001/08/13 15:25:22 $
17 // $Author: jowett $
18 //
19 // ------------------------------------------------------------------------
20 
21 #include "Tables/RangeSelector.h"
25 //#include "AbstractObjects/OpalData.h"
26 #include "BeamlineCore/PatchRep.h"
28 #include "Beamlines/TBeamline.h"
30 
31 class RangeRep;
32 
33 
34 // Template class Flatten
35 // ------------------------------------------------------------------------
37 // The type of beam line members in the flat line is given as a template
38 // parameter. It may be any class derived from ElmPtr. Execution of
39 // this visitor yields a flat line of the type defined by the template
40 // parameter Member.
41 
42 template <class Member> class Flatten: public RangeSelector {
43 
44 public:
45 
47  // Attach this visitor to [b]bl[/b], [b]mem[/b] will receive the range
48  // [b]range[/b] ot the flat line.
49  Flatten(const Beamline &bl, TBeamline<Member> &mem, const RangeRep &range);
50 
51  virtual ~Flatten();
52 
54  virtual void execute();
55 
56 protected:
57 
59  virtual void handleBeamline(const FlaggedElmPtr &);
60 
62  virtual void handleElement(const FlaggedElmPtr &);
63 
66 
67 private:
68 
69  // Not implemented.
70  Flatten();
71  Flatten(const Flatten<Member> &);
72  void operator=(const Flatten<Member> &);
73 };
74 
75 
76 // Implementation of template class Flatten
77 // ------------------------------------------------------------------------
78 
79 template <class Member> inline
81  const RangeRep &range):
82  RangeSelector(beamline, range), itsTable(list)
83 {}
84 
85 
86 template <class Member> inline
88 {}
89 
90 
91 template <class Member> inline
93  itsTable.push_back(Member(Element::find("#S")->getElement(), 0));
95  itsTable.push_back(Member(Element::find("#E")->getElement(), 0));
96 }
97 
98 
99 template <class Member> inline void
101  AlignWrapper &wrap =
102  dynamic_cast<AlignWrapper &>(*fep.getElement()->makeAlignWrapper());
103 
104  if(itsRange.isActive()) {
105  // Append the entrance misalignment patch.
106  Euclid3D transform = wrap.getEntranceTransform();
107  PatchRep *patch = new PatchRep("[BEGIN]" + wrap.getName());
108  patch->setPatch(transform);
109  Member member(patch, 0);
110  itsTable.push_back(member);
111  }
112 
113  // Delegate algorithm to the beamline.
115 
116  if(itsRange.isActive()) {
117  // Append the exit misalignment patch.
118  Euclid3D transform = wrap.getExitTransform();
119  PatchRep *patch = new PatchRep("[END]" + wrap.getName());
120  patch->setPatch(transform);
121  Member member(patch, 0);
122  itsTable.push_back(member);
123  }
124 }
125 
126 
127 template <class Member> void
129  if(itsRange.isActive()) {
130  const std::string &name = fep.getElement()->getName();
131  if(name[0] != '#') {
132  Member member(fep);
133  itsTable.push_back(member);
134  }
135  }
136 }
137 
138 #endif // OPAL_Flatten_HH
virtual ~Flatten()
Definition: Flatten.h:87
virtual void handleBeamline(const FlaggedElmPtr &)
The operation to be done for beamlines.
Definition: Flatten.h:100
Define the position of a misaligned element.
Definition: AlignWrapper.h:39
virtual Euclid3D getEntranceTransform() const
Get entrance patch.
Flatten a beamline.
Definition: Flatten.h:42
An abstract visitor which calls the pure virtual method.
Definition: RangeSelector.h:32
virtual const std::string & getName() const
Get element name.
Definition: ElementBase.cpp:95
Representation for a geometry patch.
Definition: PatchRep.h:33
virtual Euclid3D getExitTransform() const
Get exit patch.
virtual void handleBeamline(const FlaggedElmPtr &)
The operation to be done for beamlines.
Displacement and rotation in space.
Definition: Euclid3D.h:68
void operator=(const Flatten< Member > &)
virtual void execute()
Apply the algorithm to the top-level beamline.
Definition: Flatten.h:92
Representation of a range within a beam line or sequence.
Definition: RangeRep.h:34
An abstract sequence of beam line components.
Definition: Beamline.h:37
virtual void handleElement(const FlaggedElmPtr &)
The operation to be done for elements.
Definition: Flatten.h:128
static Element * find(const std::string &name)
Find named Element.
Definition: Element.cpp:37
TBeamline< Member > & itsTable
The flat list to be filled.
Definition: Flatten.h:65
void setPatch(const Euclid3D &euclid)
Set patch.
Definition: PatchRep.cpp:134
const std::string name
virtual ElementBase * makeAlignWrapper()
Allow misalignment.
ElementBase * getElement() const
Get the element pointer.
Definition: ElmPtr.h:58
virtual void execute()
Execute the algorithm.
A section of a beam line.
Definition: FlaggedElmPtr.h:36