OPAL (Object Oriented Parallel Accelerator Library) 2022.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
27#include "AbsBeamline/Drift.h"
31#include "AbsBeamline/Offset.h"
32#include "AbsBeamline/Marker.h"
33#include "AbsBeamline/Monitor.h"
39#include "AbsBeamline/Probe.h"
40#include "AbsBeamline/RBend.h"
41#include "AbsBeamline/Ring.h"
43#include "AbsBeamline/SBend.h"
44#include "AbsBeamline/SBend3D.h"
46#include "AbsBeamline/Septum.h"
48#include "AbsBeamline/Source.h"
51#include "AbsBeamline/Vacuum.h"
55
56#ifdef ENABLE_OPAL_FEL
58#endif
59
60#include "Beamlines/Beamline.h"
62
63template <class ELEM1, class ELEM2>
64struct CastsTrait {
65 typedef std::list<const ELEM1*> ElementList_t;
66
67 static void apply(ElementList_t &, const ELEM2 &)
68 { }
69};
70
71template <class ELEM>
72struct CastsTrait<ELEM,ELEM> {
73 typedef std::list<const ELEM*> ElementList_t;
74
75 static void apply(ElementList_t &allElements, const ELEM &element)
76 {
77 allElements.push_back(dynamic_cast<const ELEM*>(&element));
78 }
79};
80
81template <class ELEM>
83public:
84 SpecificElementVisitor(const Beamline &beamline);
85
86 virtual void execute();
87
89 virtual void visitBeamline(const Beamline &);
90
92 virtual void visitCCollimator(const CCollimator &);
93
95 virtual void visitComponent(const Component &);
96
98 virtual void visitCorrector(const Corrector &);
99
101 virtual void visitCyclotron(const Cyclotron &);
102
104 virtual void visitDegrader(const Degrader &);
105
107 virtual void visitDrift(const Drift &);
108
110 virtual void visitFlaggedElmPtr(const FlaggedElmPtr &);
111
113 virtual void visitFlexibleCollimator(const FlexibleCollimator &);
114
116 virtual void visitMarker(const Marker &);
117
119 virtual void visitMonitor(const Monitor &);
120
122 virtual void visitMultipole(const Multipole &);
123
125 virtual void visitMultipoleT(const MultipoleT &);
126
128 virtual void visitMultipoleTStraight(const MultipoleTStraight &);
129
132
135
137 virtual void visitOffset(const Offset &);
138
140 virtual void visitProbe(const Probe &prob);
141
143 virtual void visitRBend(const RBend &);
144
146 virtual void visitRBend3D(const RBend3D &);
147
149 virtual void visitRFCavity(const RFCavity &);
150
152 virtual void visitRing(const Ring &);
153
155 virtual void visitSBend(const SBend &);
156
158 virtual void visitSBend3D(const SBend3D &);
159
161 virtual void visitScalingFFAMagnet(const ScalingFFAMagnet &);
162
164 virtual void visitSeptum(const Septum &);
165
167 virtual void visitSolenoid(const Solenoid &);
168
170 virtual void visitSource(const Source &);
171
173 virtual void visitStripper(const Stripper &);
174
176 virtual void visitTravelingWave(const TravelingWave &);
177
178#ifdef ENABLE_OPAL_FEL
180 virtual void visitUndulator(const Undulator &);
181#endif
182
184 virtual void visitVacuum(const Vacuum &);
185
187 virtual void visitVariableRFCavity(const VariableRFCavity &vcav);
188
191 (const VariableRFCavityFringeField &vcav);
192
194 virtual void visitVerticalFFAMagnet(const VerticalFFAMagnet &);
195
196
197 size_t size() const;
198
199 typedef std::list<const ELEM*> ElementList_t;
201 typedef typename ElementList_t::const_iterator const_iterator_t;
202
203 typedef typename ElementList_t::reference reference_t;
204 typedef typename ElementList_t::const_reference const_reference_t;
205
207 const_iterator_t begin() const;
208
209 iterator_t end();
210 const_iterator_t end() const;
211
213 const_reference_t front() const;
214
215private:
217};
218
219template<class ELEM>
222 allElementsOfTypeE()
223{
224 beamline.iterate(*this, false);
225}
226
227template<class ELEM>
229{ }
230
231template<class ELEM>
233 element.iterate(*this, false);
234}
235
236template<class ELEM>
238 CastsTrait<ELEM, CCollimator>::apply(allElementsOfTypeE, element);
239}
240
241template<class ELEM>
243 CastsTrait<ELEM, Component>::apply(allElementsOfTypeE, element);
244}
245
246template<class ELEM>
248 CastsTrait<ELEM, Corrector>::apply(allElementsOfTypeE, element);
249}
250
251template<class ELEM>
253 CastsTrait<ELEM, Cyclotron>::apply(allElementsOfTypeE, element);
254}
255
256template<class ELEM>
258 CastsTrait<ELEM, Degrader>::apply(allElementsOfTypeE, element);
259}
260
261template<class ELEM>
263 CastsTrait<ELEM, Drift>::apply(allElementsOfTypeE, element);
264}
265
266template<class ELEM>
268 const ElementBase* wrappedElement = element.getElement();
269 wrappedElement->accept(*this);
270}
271
272template<class ELEM>
274 CastsTrait<ELEM, FlexibleCollimator>::apply(allElementsOfTypeE, element);
275}
276
277template<class ELEM>
279 CastsTrait<ELEM, Marker>::apply(allElementsOfTypeE, element);
280}
281
282template<class ELEM>
284 CastsTrait<ELEM, Monitor>::apply(allElementsOfTypeE, element);
285}
286
287template<class ELEM>
289 CastsTrait<ELEM, Multipole>::apply(allElementsOfTypeE, element);
290}
291
292template<class ELEM>
294 CastsTrait<ELEM, MultipoleT>::apply(allElementsOfTypeE, element);
295}
296
297template<class ELEM>
299 CastsTrait<ELEM, MultipoleTStraight>::apply(allElementsOfTypeE, element);
300}
301
302template<class ELEM>
304 CastsTrait<ELEM, MultipoleTCurvedConstRadius>::apply(allElementsOfTypeE, element);
305}
306
307template<class ELEM>
309 CastsTrait<ELEM, MultipoleTCurvedVarRadius>::apply(allElementsOfTypeE, element);
310}
311
312template<class ELEM>
314 CastsTrait<ELEM, Offset>::apply(allElementsOfTypeE, element);
315}
316
317template<class ELEM>
319 CastsTrait<ELEM, Probe>::apply(allElementsOfTypeE, element);
320}
321
322template<class ELEM>
324 CastsTrait<ELEM, RBend>::apply(allElementsOfTypeE, element);
325}
326
327template<class ELEM>
329 CastsTrait<ELEM, RBend3D>::apply(allElementsOfTypeE, element);
330}
331
332template<class ELEM>
334 CastsTrait<ELEM, RFCavity>::apply(allElementsOfTypeE, element);
335}
336
337template<class ELEM>
339 CastsTrait<ELEM, Ring>::apply(allElementsOfTypeE, element);
340}
341
342template<class ELEM>
344 CastsTrait<ELEM, SBend>::apply(allElementsOfTypeE, element);
345}
346
347template<class ELEM>
349 CastsTrait<ELEM, SBend3D>::apply(allElementsOfTypeE, element);
350}
351
352template<class ELEM>
354 CastsTrait<ELEM, ScalingFFAMagnet>::apply(allElementsOfTypeE, element);
355}
356
357template<class ELEM>
359 CastsTrait<ELEM, Septum>::apply(allElementsOfTypeE, element);
360}
361
362template<class ELEM>
364 CastsTrait<ELEM, Solenoid>::apply(allElementsOfTypeE, element);
365}
366
367template<class ELEM>
369 CastsTrait<ELEM, Source>::apply(allElementsOfTypeE, element);
370}
371
372template<class ELEM>
374 CastsTrait<ELEM, Stripper>::apply(allElementsOfTypeE, element);
375}
376
377template<class ELEM>
379 CastsTrait<ELEM, TravelingWave>::apply(allElementsOfTypeE, element);
380}
381
382#ifdef ENABLE_OPAL_FEL
383template<class ELEM>
385 CastsTrait<ELEM, Undulator>::apply(allElementsOfTypeE, element);
386}
387#endif
388
389template<class ELEM>
391 CastsTrait<ELEM, Vacuum>::apply(allElementsOfTypeE, element);
392}
393
394template<class ELEM>
396 (const VariableRFCavity &element) {
397 CastsTrait<ELEM, VariableRFCavity>::apply(allElementsOfTypeE, element);
398}
399
400template<class ELEM>
402 (const VariableRFCavityFringeField &element) {
404 element);
405}
406
407template<class ELEM>
409 CastsTrait<ELEM, VerticalFFAMagnet>::apply(allElementsOfTypeE, element);
410}
411
412template<class ELEM>
414 return allElementsOfTypeE.size();
415}
416
417template<class ELEM>
419 return allElementsOfTypeE.begin();
420}
421
422template<class ELEM>
424 return allElementsOfTypeE.begin();
425}
426
427template<class ELEM>
429 return allElementsOfTypeE.end();
430}
431
432template<class ELEM>
434 return allElementsOfTypeE.end();
435}
436
437template<class ELEM>
439 return allElementsOfTypeE.front();
440}
441
442template<class ELEM>
444 return allElementsOfTypeE.front();
445}
446
447#endif
std::string::iterator iterator
Definition: MSLang.h:16
Interface for a single beam element.
Definition: Component.h:50
Interface for general corrector.
Definition: Corrector.h:35
Interface for drift space.
Definition: Drift.h:33
virtual void accept(BeamlineVisitor &visitor) const =0
Apply visitor.
Interface for a marker.
Definition: Marker.h:32
Interface for general multipole.
Definition: Multipole.h:47
Definition: Offset.h:66
Definition: Probe.h:28
Definition: RBend.h:58
Interface for solenoids.
Definition: RBend3D.h:39
Ring describes a ring type geometry for tracking.
Definition: Ring.h:64
Definition: SBend.h:68
Definition: Septum.h:23
Interface for solenoids.
Definition: Solenoid.h:36
Definition: Source.h:30
std::list< const ELEM1 * > ElementList_t
static void apply(ElementList_t &, const ELEM2 &)
std::list< const ELEM * > ElementList_t
static void apply(ElementList_t &allElements, const ELEM &element)
virtual void execute()
Execute the algorithm on the attached beam line.
virtual void visitRing(const Ring &)
Apply the algorithm to a ring.
virtual void visitBeamline(const Beamline &)
Apply the algorithm to a beam line.
virtual void visitStripper(const Stripper &)
Apply the algorithm to a particle stripper.
virtual void visitVariableRFCavity(const VariableRFCavity &vcav)
Apply the algorithm to a variable RF cavity.
virtual void visitFlaggedElmPtr(const FlaggedElmPtr &)
Apply the algorithm to a FlaggedElmPtr.
virtual void visitMarker(const Marker &)
Apply the algorithm to a marker.
virtual void visitRFCavity(const RFCavity &)
Apply the algorithm to a RF cavity.
virtual void visitVacuum(const Vacuum &)
Apply the algorithm to a vacuum space.
ElementList_t::reference reference_t
virtual void visitVariableRFCavityFringeField(const VariableRFCavityFringeField &vcav)
Apply the algorithm to a variable RF cavity with Fringe Field..
virtual void visitMultipoleTCurvedConstRadius(const MultipoleTCurvedConstRadius &)
Apply the algorithm to an arbitrary curved multipole of constant radius.
virtual void visitSource(const Source &)
Apply the algorithm to a source.
virtual void visitMultipole(const Multipole &)
Apply the algorithm to a multipole.
SpecificElementVisitor(const Beamline &beamline)
virtual void visitMultipoleT(const MultipoleT &)
Apply the algorithm to an arbitrary multipole.
virtual void visitTravelingWave(const TravelingWave &)
Apply the algorithm to a traveling wave.
virtual void visitMultipoleTCurvedVarRadius(const MultipoleTCurvedVarRadius &)
Apply the algorithm to an arbitrary curved multipole of variable radius.
ElementList_t::const_iterator const_iterator_t
virtual void visitDegrader(const Degrader &)
Apply the algorithm to a degrader.
virtual void visitSolenoid(const Solenoid &)
Apply the algorithm to a solenoid.
virtual void visitCorrector(const Corrector &)
Apply the algorithm to a closed orbit corrector.
virtual void visitRBend(const RBend &)
Apply the algorithm to a rectangular bend.
ElementList_t::const_reference const_reference_t
virtual void visitCCollimator(const CCollimator &)
Apply the algorithm to a collimator.
virtual void visitMultipoleTStraight(const MultipoleTStraight &)
Apply the algorithm to an arbitrary straight multipole.
virtual void visitSeptum(const Septum &)
Apply the algorithm to a septum.
virtual void visitScalingFFAMagnet(const ScalingFFAMagnet &)
Apply the algorithm to a scaling FFA magnet.
virtual void visitCyclotron(const Cyclotron &)
Apply the algorithm to an cyclotron.
virtual void visitRBend3D(const RBend3D &)
Apply the algorithm to a rectangular bend.
virtual void visitProbe(const Probe &prob)
Apply the algorithm to a probe.
virtual void visitSBend3D(const SBend3D &)
Apply the algorithm to a sector bend with 3D field map.
ElementList_t::iterator iterator_t
virtual void visitFlexibleCollimator(const FlexibleCollimator &)
Apply the algorithm to a flexible collimator.
virtual void visitMonitor(const Monitor &)
Apply the algorithm to a beam position monitor.
virtual void visitSBend(const SBend &)
Apply the algorithm to a sector bend.
virtual void visitDrift(const Drift &)
Apply the algorithm to a drift.
std::list< const ELEM * > ElementList_t
virtual void visitComponent(const Component &)
Apply the algorithm to an arbitrary component.
virtual void visitVerticalFFAMagnet(const VerticalFFAMagnet &)
Apply the algorithm to a vertical FFA magnet.
virtual void visitOffset(const Offset &)
Apply the algorithm to an offset (placement).
Definition: Vacuum.h:61
An abstract sequence of beam line components.
Definition: Beamline.h:34
virtual void iterate(BeamlineVisitor &, bool reverse) const =0
Apply visitor to all elements of the line.
ElementBase * getElement() const
Get the element pointer.
Definition: ElmPtr.h:58
A section of a beam line.
Definition: FlaggedElmPtr.h:36