OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
SpecificElementVisitor.h
Go to the documentation of this file.
1 //
2 // Class SpecificElementVisitor
3 // :FIXME: Add file description
4 //
5 // Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
6 // All rights reserved
7 //
8 // This file is part of OPAL.
9 //
10 // OPAL is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17 //
18 #ifndef SPECIFICELEMENTVISITOR_H
19 #define SPECIFICELEMENTVISITOR_H
20 
21 #include <list>
22 
25 #include "AbsBeamline/Corrector.h"
26 #include "AbsBeamline/Cyclotron.h"
27 #include "AbsBeamline/Drift.h"
28 #include "AbsBeamline/Degrader.h"
31 #include "AbsBeamline/Offset.h"
32 #include "AbsBeamline/Marker.h"
33 #include "AbsBeamline/Monitor.h"
34 #include "AbsBeamline/Multipole.h"
35 #include "AbsBeamline/MultipoleT.h"
40 #include "AbsBeamline/Probe.h"
41 #include "AbsBeamline/RBend.h"
42 #include "AbsBeamline/Ring.h"
43 #include "AbsBeamline/RFCavity.h"
44 #include "AbsBeamline/SBend.h"
45 #include "AbsBeamline/SBend3D.h"
47 #include "AbsBeamline/Septum.h"
48 #include "AbsBeamline/Solenoid.h"
49 #include "AbsBeamline/Source.h"
50 #include "AbsBeamline/Stripper.h"
52 #include "AbsBeamline/Vacuum.h"
56 
57 #ifdef ENABLE_OPAL_FEL
58 #include "AbsBeamline/Undulator.h"
59 #endif
60 
61 #include "Beamlines/Beamline.h"
63 
64 template <class ELEM1, class ELEM2>
65 struct CastsTrait {
66  typedef std::list<const ELEM1*> ElementList_t;
67 
68  static void apply(ElementList_t &, const ELEM2 &)
69  { }
70 };
71 
72 template <class ELEM>
73 struct CastsTrait<ELEM,ELEM> {
74  typedef std::list<const ELEM*> ElementList_t;
75 
76  static void apply(ElementList_t &allElements, const ELEM &element)
77  {
78  allElements.push_back(dynamic_cast<const ELEM*>(&element));
79  }
80 };
81 
82 template <class ELEM>
84 public:
85  SpecificElementVisitor(const Beamline &beamline);
86 
87  virtual void execute();
88 
90  virtual void visitBeamline(const Beamline &);
91 
93  virtual void visitCCollimator(const CCollimator &);
94 
96  virtual void visitComponent(const Component &);
97 
99  virtual void visitCorrector(const Corrector &);
100 
102  virtual void visitCyclotron(const Cyclotron &);
103 
105  virtual void visitDegrader(const Degrader &);
106 
108  virtual void visitDrift(const Drift &);
109 
111  virtual void visitFlaggedElmPtr(const FlaggedElmPtr &);
112 
114  virtual void visitFlexibleCollimator(const FlexibleCollimator &);
115 
117  virtual void visitMarker(const Marker &);
118 
120  virtual void visitMonitor(const Monitor &);
121 
123  virtual void visitMultipole(const Multipole &);
124 
126  virtual void visitMultipoleT(const MultipoleT &);
127 
129  virtual void visitMultipoleTStraight(const MultipoleTStraight &);
130 
133 
136 
138  virtual void visitOffset(const Offset &);
139 
141  virtual void visitOutputPlane(const OutputPlane &);
142 
144  virtual void visitProbe(const Probe &prob);
145 
147  virtual void visitRBend(const RBend &);
148 
150  virtual void visitRBend3D(const RBend3D &);
151 
153  virtual void visitRFCavity(const RFCavity &);
154 
156  virtual void visitRing(const Ring &);
157 
159  virtual void visitSBend(const SBend &);
160 
162  virtual void visitSBend3D(const SBend3D &);
163 
165  virtual void visitScalingFFAMagnet(const ScalingFFAMagnet &);
166 
168  virtual void visitSeptum(const Septum &);
169 
171  virtual void visitSolenoid(const Solenoid &);
172 
174  virtual void visitSource(const Source &);
175 
177  virtual void visitStripper(const Stripper &);
178 
180  virtual void visitTravelingWave(const TravelingWave &);
181 
182 #ifdef ENABLE_OPAL_FEL
183  virtual void visitUndulator(const Undulator &);
185 #endif
186 
188  virtual void visitVacuum(const Vacuum &);
189 
191  virtual void visitVariableRFCavity(const VariableRFCavity &vcav);
192 
195  (const VariableRFCavityFringeField &vcav);
196 
198  virtual void visitVerticalFFAMagnet(const VerticalFFAMagnet &);
199 
200 
201  size_t size() const;
202 
203  typedef std::list<const ELEM*> ElementList_t;
205  typedef typename ElementList_t::const_iterator const_iterator_t;
206 
207  typedef typename ElementList_t::reference reference_t;
208  typedef typename ElementList_t::const_reference const_reference_t;
209 
210  iterator_t begin();
211  const_iterator_t begin() const;
212 
213  iterator_t end();
214  const_iterator_t end() const;
215 
216  reference_t front();
217  const_reference_t front() const;
218 
219 private:
221 };
222 
223 template<class ELEM>
225  BeamlineVisitor(),
226  allElementsOfTypeE()
227 {
228  beamline.iterate(*this, false);
229 }
230 
231 template<class ELEM>
233 { }
234 
235 template<class ELEM>
237  element.iterate(*this, false);
238 }
239 
240 template<class ELEM>
242  CastsTrait<ELEM, CCollimator>::apply(allElementsOfTypeE, element);
243 }
244 
245 template<class ELEM>
247  CastsTrait<ELEM, Component>::apply(allElementsOfTypeE, element);
248 }
249 
250 template<class ELEM>
252  CastsTrait<ELEM, Corrector>::apply(allElementsOfTypeE, element);
253 }
254 
255 template<class ELEM>
257  CastsTrait<ELEM, Cyclotron>::apply(allElementsOfTypeE, element);
258 }
259 
260 template<class ELEM>
262  CastsTrait<ELEM, Degrader>::apply(allElementsOfTypeE, element);
263 }
264 
265 template<class ELEM>
267  CastsTrait<ELEM, Drift>::apply(allElementsOfTypeE, element);
268 }
269 
270 template<class ELEM>
272  const ElementBase* wrappedElement = element.getElement();
273  wrappedElement->accept(*this);
274 }
275 
276 template<class ELEM>
278  CastsTrait<ELEM, FlexibleCollimator>::apply(allElementsOfTypeE, element);
279 }
280 
281 template<class ELEM>
283  CastsTrait<ELEM, Marker>::apply(allElementsOfTypeE, element);
284 }
285 
286 template<class ELEM>
288  CastsTrait<ELEM, Monitor>::apply(allElementsOfTypeE, element);
289 }
290 
291 template<class ELEM>
293  CastsTrait<ELEM, Multipole>::apply(allElementsOfTypeE, element);
294 }
295 
296 template<class ELEM>
298  CastsTrait<ELEM, MultipoleT>::apply(allElementsOfTypeE, element);
299 }
300 
301 template<class ELEM>
303  CastsTrait<ELEM, MultipoleTStraight>::apply(allElementsOfTypeE, element);
304 }
305 
306 template<class ELEM>
308  CastsTrait<ELEM, MultipoleTCurvedConstRadius>::apply(allElementsOfTypeE, element);
309 }
310 
311 template<class ELEM>
313  CastsTrait<ELEM, MultipoleTCurvedVarRadius>::apply(allElementsOfTypeE, element);
314 }
315 
316 template<class ELEM>
318  CastsTrait<ELEM, Offset>::apply(allElementsOfTypeE, element);
319 }
320 
321 template<class ELEM>
323  CastsTrait<ELEM, OutputPlane>::apply(allElementsOfTypeE, element);
324 }
325 
326 template<class ELEM>
328  CastsTrait<ELEM, Probe>::apply(allElementsOfTypeE, element);
329 }
330 
331 template<class ELEM>
333  CastsTrait<ELEM, RBend>::apply(allElementsOfTypeE, element);
334 }
335 
336 template<class ELEM>
338  CastsTrait<ELEM, RBend3D>::apply(allElementsOfTypeE, element);
339 }
340 
341 template<class ELEM>
343  CastsTrait<ELEM, RFCavity>::apply(allElementsOfTypeE, element);
344 }
345 
346 template<class ELEM>
348  CastsTrait<ELEM, Ring>::apply(allElementsOfTypeE, element);
349 }
350 
351 template<class ELEM>
353  CastsTrait<ELEM, SBend>::apply(allElementsOfTypeE, element);
354 }
355 
356 template<class ELEM>
358  CastsTrait<ELEM, SBend3D>::apply(allElementsOfTypeE, element);
359 }
360 
361 template<class ELEM>
363  CastsTrait<ELEM, ScalingFFAMagnet>::apply(allElementsOfTypeE, element);
364 }
365 
366 template<class ELEM>
368  CastsTrait<ELEM, Septum>::apply(allElementsOfTypeE, element);
369 }
370 
371 template<class ELEM>
373  CastsTrait<ELEM, Solenoid>::apply(allElementsOfTypeE, element);
374 }
375 
376 template<class ELEM>
378  CastsTrait<ELEM, Source>::apply(allElementsOfTypeE, element);
379 }
380 
381 template<class ELEM>
383  CastsTrait<ELEM, Stripper>::apply(allElementsOfTypeE, element);
384 }
385 
386 template<class ELEM>
388  CastsTrait<ELEM, TravelingWave>::apply(allElementsOfTypeE, element);
389 }
390 
391 #ifdef ENABLE_OPAL_FEL
392 template<class ELEM>
394  CastsTrait<ELEM, Undulator>::apply(allElementsOfTypeE, element);
395 }
396 #endif
397 
398 template<class ELEM>
400  CastsTrait<ELEM, Vacuum>::apply(allElementsOfTypeE, element);
401 }
402 
403 template<class ELEM>
405  (const VariableRFCavity &element) {
406  CastsTrait<ELEM, VariableRFCavity>::apply(allElementsOfTypeE, element);
407 }
408 
409 template<class ELEM>
411  (const VariableRFCavityFringeField &element) {
413  element);
414 }
415 
416 template<class ELEM>
418  CastsTrait<ELEM, VerticalFFAMagnet>::apply(allElementsOfTypeE, element);
419 }
420 
421 template<class ELEM>
423  return allElementsOfTypeE.size();
424 }
425 
426 template<class ELEM>
428  return allElementsOfTypeE.begin();
429 }
430 
431 template<class ELEM>
433  return allElementsOfTypeE.begin();
434 }
435 
436 template<class ELEM>
438  return allElementsOfTypeE.end();
439 }
440 
441 template<class ELEM>
443  return allElementsOfTypeE.end();
444 }
445 
446 template<class ELEM>
448  return allElementsOfTypeE.front();
449 }
450 
451 template<class ELEM>
453  return allElementsOfTypeE.front();
454 }
455 
456 #endif
virtual void visitSolenoid(const Solenoid &)
Apply the algorithm to a solenoid.
virtual void visitOutputPlane(const OutputPlane &)
Apply the algorithm to an output plane.
virtual void visitVariableRFCavity(const VariableRFCavity &vcav)
Apply the algorithm to a variable RF cavity.
virtual void visitRFCavity(const RFCavity &)
Apply the algorithm to a RF cavity.
Interface for a marker.
Definition: Marker.h:32
virtual void visitCorrector(const Corrector &)
Apply the algorithm to a closed orbit corrector.
virtual void visitDegrader(const Degrader &)
Apply the algorithm to a degrader.
ElementList_t::const_reference const_reference_t
virtual void execute()
Execute the algorithm on the attached beam line.
virtual void visitComponent(const Component &)
Apply the algorithm to an arbitrary component.
virtual void accept(BeamlineVisitor &visitor) const =0
Apply visitor.
Interface for solenoids.
Definition: Solenoid.h:36
virtual void visitVacuum(const Vacuum &)
Apply the algorithm to a vacuum space.
Definition: Offset.h:53
Interface for solenoids.
Definition: RBend3D.h:39
ElementBase * getElement() const
Get the element pointer.
Definition: ElmPtr.h:58
ElementList_t::reference reference_t
An abstract sequence of beam line components.
Definition: Beamline.h:34
Interface for general multipole.
Definition: Multipole.h:47
ElementList_t::iterator iterator_t
Interface for drift space.
Definition: Drift.h:33
Definition: SBend.h:68
Interface for general corrector.
Definition: Corrector.h:35
Definition: Vacuum.h:61
virtual void iterate(BeamlineVisitor &, bool reverse) const =0
Apply visitor to all elements of the line.
std::list< const ELEM * > ElementList_t
virtual void visitFlexibleCollimator(const FlexibleCollimator &)
Apply the algorithm to a flexible collimator.
std::string::iterator iterator
Definition: MSLang.h:15
virtual void visitMultipoleTStraight(const MultipoleTStraight &)
Apply the algorithm to an arbitrary straight multipole.
virtual void visitDrift(const Drift &)
Apply the algorithm to a drift.
static void apply(ElementList_t &allElements, const ELEM &element)
virtual void visitMultipoleTCurvedVarRadius(const MultipoleTCurvedVarRadius &)
Apply the algorithm to an arbitrary curved multipole of variable radius.
SpecificElementVisitor(const Beamline &beamline)
virtual void visitCyclotron(const Cyclotron &)
Apply the algorithm to an cyclotron.
virtual void visitTravelingWave(const TravelingWave &)
Apply the algorithm to a traveling wave.
virtual void visitRBend(const RBend &)
Apply the algorithm to a rectangular bend.
virtual void visitSeptum(const Septum &)
Apply the algorithm to a septum.
virtual void visitVerticalFFAMagnet(const VerticalFFAMagnet &)
Apply the algorithm to a vertical FFA magnet.
virtual void visitScalingFFAMagnet(const ScalingFFAMagnet &)
Apply the algorithm to a scaling FFA magnet.
static void apply(ElementList_t &, const ELEM2 &)
virtual void visitFlaggedElmPtr(const FlaggedElmPtr &)
Apply the algorithm to a FlaggedElmPtr.
virtual void visitMultipole(const Multipole &)
Apply the algorithm to a multipole.
virtual void visitRBend3D(const RBend3D &)
Apply the algorithm to a rectangular bend.
virtual void visitOffset(const Offset &)
Apply the algorithm to an offset (placement).
virtual void visitMarker(const Marker &)
Apply the algorithm to a marker.
virtual void visitCCollimator(const CCollimator &)
Apply the algorithm to a collimator.
Definition: RBend.h:58
virtual void visitRing(const Ring &)
Apply the algorithm to a ring.
Definition: Source.h:30
virtual void visitStripper(const Stripper &)
Apply the algorithm to a particle stripper.
virtual void visitBeamline(const Beamline &)
Apply the algorithm to a beam line.
virtual void visitSBend(const SBend &)
Apply the algorithm to a sector bend.
ElementList_t::const_iterator const_iterator_t
Definition: Probe.h:28
virtual void visitProbe(const Probe &prob)
Apply the algorithm to a probe.
std::list< const ELEM * > ElementList_t
virtual void visitMultipoleTCurvedConstRadius(const MultipoleTCurvedConstRadius &)
Apply the algorithm to an arbitrary curved multipole of constant radius.
A section of a beam line.
Definition: FlaggedElmPtr.h:36
Ring describes a ring type geometry for tracking.
Definition: Ring.h:53
Definition: Septum.h:23
Interface for a single beam element.
Definition: Component.h:50
virtual void visitSBend3D(const SBend3D &)
Apply the algorithm to a sector bend with 3D field map.
virtual void visitSource(const Source &)
Apply the algorithm to a source.
std::list< const ELEM1 * > ElementList_t
virtual void visitMonitor(const Monitor &)
Apply the algorithm to a beam position monitor.
virtual void visitVariableRFCavityFringeField(const VariableRFCavityFringeField &vcav)
Apply the algorithm to a variable RF cavity with Fringe Field..
virtual void visitMultipoleT(const MultipoleT &)
Apply the algorithm to an arbitrary multipole.