SpecificElementVisitor.h 17.7 KB
Newer Older
1 2 3 4 5 6 7 8 9
#ifndef SPECIFICELEMENTVISITOR_H
#define SPECIFICELEMENTVISITOR_H

#include <list>

#include "AbsBeamline/BeamlineVisitor.h"

#include "AbsBeamline/AlignWrapper.h"
#include "AbsBeamline/BeamBeam.h"
10
#include "AbsBeamline/CCollimator.h"
11 12 13 14 15 16
#include "AbsBeamline/Corrector.h"
#include "AbsBeamline/Cyclotron.h"
#include "AbsBeamline/Diagnostic.h"
#include "AbsBeamline/Drift.h"
#include "AbsBeamline/Degrader.h"
#include "AbsBeamline/ElementBase.h"
17
#include "AbsBeamline/FlexibleCollimator.h"
18 19 20 21 22
#include "AbsBeamline/Lambertson.h"
#include "AbsBeamline/Offset.h"
#include "AbsBeamline/Marker.h"
#include "AbsBeamline/Monitor.h"
#include "AbsBeamline/Multipole.h"
ext-rogers_c's avatar
ext-rogers_c committed
23
#include "AbsBeamline/MultipoleT.h"
24 25 26
#include "AbsBeamline/MultipoleTStraight.h"
#include "AbsBeamline/MultipoleTCurvedConstRadius.h"
#include "AbsBeamline/MultipoleTCurvedVarRadius.h"
27 28 29 30 31 32
#include "AbsBeamline/Patch.h"
#include "AbsBeamline/Probe.h"
#include "AbsBeamline/RBend.h"
#include "AbsBeamline/Ring.h"
#include "AbsBeamline/RFCavity.h"
#include "AbsBeamline/VariableRFCavity.h"
33
#include "AbsBeamline/VariableRFCavityFringeField.h"
34 35 36 37
#include "AbsBeamline/TravelingWave.h"
#include "AbsBeamline/RFQuadrupole.h"
#include "AbsBeamline/SBend.h"
#include "AbsBeamline/SBend3D.h"
ext-rogers_c's avatar
ext-rogers_c committed
38
#include "AbsBeamline/ScalingFFAMagnet.h"
39 40 41
#include "AbsBeamline/Separator.h"
#include "AbsBeamline/Septum.h"
#include "AbsBeamline/Solenoid.h"
42
#include "AbsBeamline/Source.h"
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#include "AbsBeamline/ParallelPlate.h"
#include "AbsBeamline/CyclotronValley.h"
#include "AbsBeamline/Stripper.h"

#include "Beamlines/FlaggedElmPtr.h"

#include "ComponentWrappers/CorrectorWrapper.h"
#include "ComponentWrappers/CyclotronWrapper.h"
#include "ComponentWrappers/MultipoleWrapper.h"
#include "ComponentWrappers/RBendWrapper.h"
#include "ComponentWrappers/SBendWrapper.h"

#include "Algorithms/MapIntegrator.h"
#include "Algorithms/TrackIntegrator.h"

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
template <class ELEM1, class ELEM2>
struct CastsTrait {
    typedef std::list<const ELEM1*> ElementList_t;

    static void apply(ElementList_t &, const ELEM2 &)
    { }
};

template <class ELEM>
struct CastsTrait<ELEM,ELEM> {
    typedef std::list<const ELEM*> ElementList_t;

    static void apply(ElementList_t &allElements, const ELEM &element)
    {
        allElements.push_back(dynamic_cast<const ELEM*>(&element));
    }
};

template <class ELEM>
77 78 79 80 81 82 83 84 85 86
class SpecificElementVisitor: public BeamlineVisitor {
public:
    SpecificElementVisitor(const Beamline &beamline);

    virtual void execute();

    /// Apply the algorithm to a beam-beam.
    virtual void visitBeamBeam(const BeamBeam &);

    /// Apply the algorithm to a collimator.
87
    virtual void visitCCollimator(const CCollimator &);
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

    /// Apply the algorithm to an arbitrary component.
    virtual void visitComponent(const Component &);

    /// Apply the algorithm to an cyclotron
    virtual void visitCyclotron(const Cyclotron &);

    /// Apply the algorithm to an opal ring..
    virtual void visitRing(const Ring &);

    /// Apply the algorithm to a corrector.
    virtual void visitCorrector(const Corrector &);

    /// Apply the algorithm to a drift.
    virtual void visitDegrader(const Degrader &);

    /// Apply the algorithm to a diagnostic.
    virtual void visitDiagnostic(const Diagnostic &);

    /// Apply the algorithm to a drift.
    virtual void visitDrift(const Drift &);

110 111 112
    /// Apply the algorithm to a flexible collimator
    virtual void visitFlexibleCollimator(const FlexibleCollimator &);

113 114 115 116 117 118 119 120 121 122 123 124
    /// Apply the algorithm to a Lambertson.
    virtual void visitLambertson(const Lambertson &);

    /// Apply the algorithm to a marker.
    virtual void visitMarker(const Marker &);

    /// Apply the algorithm to a monitor.
    virtual void visitMonitor(const Monitor &);

    /// Apply the algorithm to a multipole.
    virtual void visitMultipole(const Multipole &);

ext-rogers_c's avatar
ext-rogers_c committed
125 126 127
    /// Apply the algorithm to a multipoleT.
    virtual void visitMultipoleT(const MultipoleT &);

128 129 130 131 132 133 134 135 136
    /// Apply the algorithm to a multipoleTStraight.
    virtual void visitMultipoleTStraight(const MultipoleTStraight &);

    /// Apply the algorithm to a multipoleT.
    virtual void visitMultipoleTCurvedConstRadius(const MultipoleTCurvedConstRadius &);

    /// Apply the algorithm to a multipoleT.
    virtual void visitMultipoleTCurvedVarRadius(const MultipoleTCurvedVarRadius &);

137 138 139 140 141 142 143 144 145 146 147 148
    /// Apply the algorithm to an Offset.
    virtual void visitOffset(const Offset &);

    /// Apply the algorithm to a patch.
    virtual void visitPatch(const Patch &pat);

    /// Apply the algorithm to a probe.
    virtual void visitProbe(const Probe &prob);

    /// Apply the algorithm to a rectangular bend.
    virtual void visitRBend(const RBend &);

149 150 151
    /// Apply the algorithm to a rectangular bend.
    virtual void visitRBend3D(const RBend3D &);

152 153 154
    /// Apply the algorithm to a RF cavity.
    virtual void visitVariableRFCavity(const VariableRFCavity &vcav);

155 156 157 158
    /// Apply the algorithm to a RF cavity.
    virtual void visitVariableRFCavityFringeField
                                      (const VariableRFCavityFringeField &vcav);

159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
    /// Apply the algorithm to a RF cavity.
    virtual void visitRFCavity(const RFCavity &);

    /// Apply the algorithm to a RF cavity.
    virtual void visitTravelingWave(const TravelingWave &);

    /// Apply the algorithm to a RF quadrupole.
    virtual void visitRFQuadrupole(const RFQuadrupole &);

    /// Apply the algorithm to a sector bend.
    virtual void visitSBend(const SBend &);

    /// Apply the algorithm to a sector bend.
    virtual void visitSBend3D(const SBend3D &);

    /// Apply the algorithm to a separator.
    virtual void visitSeparator(const Separator &);

    /// Apply the algorithm to a septum.
    virtual void visitSeptum(const Septum &);

    /// Apply the algorithm to a solenoid.
    virtual void visitSolenoid(const Solenoid &);

183 184 185
    /// Apply the algorithm to a solenoid.
    virtual void visitSource(const Source &);

186
    /// Apply the algorithm to a spiral sector magnet.
ext-rogers_c's avatar
ext-rogers_c committed
187
    virtual void visitScalingFFAMagnet(const ScalingFFAMagnet &);
188

189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
    /// Apply the algorithm to a ParallelPlate.
    virtual void visitParallelPlate(const ParallelPlate &);

    /// Apply the algorithm to a CyclotronValley.
    virtual void visitCyclotronValley(const CyclotronValley &);

    /// Apply the algorithm to a charge stripper.
    virtual void visitStripper(const Stripper &);

    /// Apply the algorithm to a beam line.
    virtual void visitBeamline(const Beamline &);

    /// Apply the algorithm to a FlaggedElmPtr.
    virtual void visitFlaggedElmPtr(const FlaggedElmPtr &);


    /// Apply the algorithm to an align wrapper..
    virtual void visitAlignWrapper(const AlignWrapper &);

    /// Apply the algorithm to an corrector wrapper..
    virtual void visitCorrectorWrapper(const CorrectorWrapper &);

    /// Apply the algorithm to an cyclotron wrapper..
    virtual void visitCyclotronWrapper(const CyclotronWrapper &);

    /// Apply the algorithm to an multipole wrapper..
    virtual void visitMultipoleWrapper(const MultipoleWrapper &);

    /// Apply the algorithm to an RBend wrapper..
    virtual void visitRBendWrapper(const RBendWrapper &);

    /// Apply the algorithm to an SBend wrapper..
    virtual void visitSBendWrapper(const SBendWrapper &);


    /// Apply the algorithm to a generic integrator.
    virtual void visitIntegrator(const Integrator &);

    /// Apply the algorithm to an integrator capable of mapping.
    virtual void visitMapIntegrator(const MapIntegrator &);

    /// Apply the algorithm to an integrator capable of tracking.
    virtual void visitTrackIntegrator(const TrackIntegrator &);

    size_t size() const;

235
    typedef std::list<const ELEM*> ElementList_t;
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
    typedef typename ElementList_t::iterator iterator_t;
    typedef typename ElementList_t::const_iterator const_iterator_t;

    typedef typename ElementList_t::reference reference_t;
    typedef typename ElementList_t::const_reference const_reference_t;

    iterator_t begin();
    const_iterator_t begin() const;

    iterator_t end();
    const_iterator_t end() const;

    reference_t front();
    const_reference_t front() const;

private:
    ElementList_t allElementsOfTypeE;
};

template<class ELEM>
SpecificElementVisitor<ELEM>::SpecificElementVisitor(const Beamline &beamline):
    BeamlineVisitor(),
    allElementsOfTypeE()
259 260 261
{
    beamline.iterate(*this, false);
}
262 263

template<class ELEM>
264 265
void SpecificElementVisitor<ELEM>::execute()
{ }
266 267 268

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitBeamBeam(const BeamBeam &element) {
269
    CastsTrait<ELEM, BeamBeam>::apply(allElementsOfTypeE, element);
270 271 272
}

template<class ELEM>
273 274
void SpecificElementVisitor<ELEM>::visitCCollimator(const CCollimator &element) {
    CastsTrait<ELEM, CCollimator>::apply(allElementsOfTypeE, element);
275 276 277 278
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitComponent(const Component &element) {
279
    CastsTrait<ELEM, Component>::apply(allElementsOfTypeE, element);
280 281 282 283
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitCyclotron(const Cyclotron &element) {
284
    CastsTrait<ELEM, Cyclotron>::apply(allElementsOfTypeE, element);
285 286 287 288
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitRing(const Ring &element) {
289
    CastsTrait<ELEM, Ring>::apply(allElementsOfTypeE, element);
290 291 292 293
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitCorrector(const Corrector &element) {
294
    CastsTrait<ELEM, Corrector>::apply(allElementsOfTypeE, element);
295 296 297 298
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitDegrader(const Degrader &element) {
299
    CastsTrait<ELEM, Degrader>::apply(allElementsOfTypeE, element);
300 301 302 303
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitDiagnostic(const Diagnostic &element) {
304
    CastsTrait<ELEM, Diagnostic>::apply(allElementsOfTypeE, element);
305 306 307 308
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitDrift(const Drift &element) {
309
    CastsTrait<ELEM, Drift>::apply(allElementsOfTypeE, element);
310 311
}

312 313 314 315 316
template<class ELEM>
void SpecificElementVisitor<ELEM>::visitFlexibleCollimator(const FlexibleCollimator &element) {
    CastsTrait<ELEM, FlexibleCollimator>::apply(allElementsOfTypeE, element);
}

317 318
template<class ELEM>
void SpecificElementVisitor<ELEM>::visitLambertson(const Lambertson &element) {
319
    CastsTrait<ELEM, Lambertson>::apply(allElementsOfTypeE, element);
320 321 322 323
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitMarker(const Marker &element) {
324
    CastsTrait<ELEM, Marker>::apply(allElementsOfTypeE, element);
325 326 327 328
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitMonitor(const Monitor &element) {
329
    CastsTrait<ELEM, Monitor>::apply(allElementsOfTypeE, element);
330 331 332 333
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitMultipole(const Multipole &element) {
334
    CastsTrait<ELEM, Multipole>::apply(allElementsOfTypeE, element);
335 336
}

ext-rogers_c's avatar
ext-rogers_c committed
337 338 339
template<class ELEM>
void SpecificElementVisitor<ELEM>::visitMultipoleT(const MultipoleT &element) {
    CastsTrait<ELEM, MultipoleT>::apply(allElementsOfTypeE, element);
340 341
}

342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
template<class ELEM>
void SpecificElementVisitor<ELEM>::visitMultipoleTStraight(const MultipoleTStraight &element) {
    CastsTrait<ELEM, MultipoleTStraight>::apply(allElementsOfTypeE, element);
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitMultipoleTCurvedConstRadius(const MultipoleTCurvedConstRadius &element) {
    CastsTrait<ELEM, MultipoleTCurvedConstRadius>::apply(allElementsOfTypeE, element);
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitMultipoleTCurvedVarRadius(const MultipoleTCurvedVarRadius &element) {
    CastsTrait<ELEM, MultipoleTCurvedVarRadius>::apply(allElementsOfTypeE, element);
}

357 358
template<class ELEM>
void SpecificElementVisitor<ELEM>::visitOffset(const Offset &element) {
359
    CastsTrait<ELEM, Offset>::apply(allElementsOfTypeE, element);
360 361 362 363
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitPatch(const Patch &element) {
364
    CastsTrait<ELEM, Patch>::apply(allElementsOfTypeE, element);
365 366 367 368
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitProbe(const Probe &element) {
369
    CastsTrait<ELEM, Probe>::apply(allElementsOfTypeE, element);
370 371 372 373
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitRBend(const RBend &element) {
374
    CastsTrait<ELEM, RBend>::apply(allElementsOfTypeE, element);
375 376
}

377 378 379 380 381
template<class ELEM>
void SpecificElementVisitor<ELEM>::visitRBend3D(const RBend3D &element) {
    CastsTrait<ELEM, RBend3D>::apply(allElementsOfTypeE, element);
}

382
template<class ELEM>
383 384
void SpecificElementVisitor<ELEM>::visitVariableRFCavity
                                             (const VariableRFCavity &element) {
385
    CastsTrait<ELEM, VariableRFCavity>::apply(allElementsOfTypeE, element);
386 387 388
}

template<class ELEM>
389 390 391 392 393 394 395
void SpecificElementVisitor<ELEM>::visitVariableRFCavityFringeField
                                  (const VariableRFCavityFringeField &element) {
    CastsTrait<ELEM, VariableRFCavityFringeField>::apply(allElementsOfTypeE,
                                                         element);
}

template<class ELEM>
396
void SpecificElementVisitor<ELEM>::visitRFCavity(const RFCavity &element) {
397
    CastsTrait<ELEM, RFCavity>::apply(allElementsOfTypeE, element);
398 399 400 401
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitTravelingWave(const TravelingWave &element) {
402
    CastsTrait<ELEM, TravelingWave>::apply(allElementsOfTypeE, element);
403 404 405 406
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitRFQuadrupole(const RFQuadrupole &element) {
407
    CastsTrait<ELEM, RFQuadrupole>::apply(allElementsOfTypeE, element);
408 409 410 411
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitSBend(const SBend &element) {
412
    CastsTrait<ELEM, SBend>::apply(allElementsOfTypeE, element);
413 414 415 416
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitSBend3D(const SBend3D &element) {
417
    CastsTrait<ELEM, SBend3D>::apply(allElementsOfTypeE, element);
418 419
}

420
template<class ELEM>
ext-rogers_c's avatar
ext-rogers_c committed
421 422
void SpecificElementVisitor<ELEM>::visitScalingFFAMagnet(const ScalingFFAMagnet &element) {
    CastsTrait<ELEM, ScalingFFAMagnet>::apply(allElementsOfTypeE, element);
423 424
}

425 426
template<class ELEM>
void SpecificElementVisitor<ELEM>::visitSeparator(const Separator &element) {
427
    CastsTrait<ELEM, Separator>::apply(allElementsOfTypeE, element);
428 429 430 431
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitSeptum(const Septum &element) {
432
    CastsTrait<ELEM, Septum>::apply(allElementsOfTypeE, element);
433 434 435 436
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitSolenoid(const Solenoid &element) {
437
    CastsTrait<ELEM, Solenoid>::apply(allElementsOfTypeE, element);
438 439
}

440 441 442 443 444
template<class ELEM>
void SpecificElementVisitor<ELEM>::visitSource(const Source &element) {
    CastsTrait<ELEM, Source>::apply(allElementsOfTypeE, element);
}

445 446
template<class ELEM>
void SpecificElementVisitor<ELEM>::visitParallelPlate(const ParallelPlate &element) {
447
    CastsTrait<ELEM, ParallelPlate>::apply(allElementsOfTypeE, element);
448 449 450 451
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitCyclotronValley(const CyclotronValley &element) {
452
    CastsTrait<ELEM, CyclotronValley>::apply(allElementsOfTypeE, element);
453 454 455 456
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitStripper(const Stripper &element) {
457
    CastsTrait<ELEM, Stripper>::apply(allElementsOfTypeE, element);
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitBeamline(const Beamline &element) {
    element.iterate(*this, false);
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitFlaggedElmPtr(const FlaggedElmPtr &element) {
    const ElementBase* wrappedElement = element.getElement();
    wrappedElement->accept(*this);
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitAlignWrapper(const AlignWrapper &element) {
    const ElementBase* wrappedElement = element.getElement();
    wrappedElement->accept(*this);
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitCorrectorWrapper(const CorrectorWrapper &element) {
479
    CastsTrait<ELEM, CorrectorWrapper>::apply(allElementsOfTypeE, element);
480 481 482 483
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitCyclotronWrapper(const CyclotronWrapper &element) {
484
    CastsTrait<ELEM, CyclotronWrapper>::apply(allElementsOfTypeE, element);
485 486 487 488
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitMultipoleWrapper(const MultipoleWrapper &element) {
489
    CastsTrait<ELEM, MultipoleWrapper>::apply(allElementsOfTypeE, element);
490 491 492 493
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitRBendWrapper(const RBendWrapper &element) {
494
    CastsTrait<ELEM, RBendWrapper>::apply(allElementsOfTypeE, element);
495 496 497 498
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitSBendWrapper(const SBendWrapper &element) {
499
    CastsTrait<ELEM, SBendWrapper>::apply(allElementsOfTypeE, element);
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitIntegrator(const Integrator &element) {

}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitMapIntegrator(const MapIntegrator &element) {

}

template<class ELEM>
void SpecificElementVisitor<ELEM>::visitTrackIntegrator(const TrackIntegrator &element) {

}

template<class ELEM>
size_t SpecificElementVisitor<ELEM>::size() const{
    return allElementsOfTypeE.size();
}

template<class ELEM>
typename SpecificElementVisitor<ELEM>::iterator_t SpecificElementVisitor<ELEM>::begin(){
    return allElementsOfTypeE.begin();
}

template<class ELEM>
typename SpecificElementVisitor<ELEM>::const_iterator_t SpecificElementVisitor<ELEM>::begin() const{
    return allElementsOfTypeE.begin();
}

template<class ELEM>
typename SpecificElementVisitor<ELEM>::iterator_t SpecificElementVisitor<ELEM>::end(){
    return allElementsOfTypeE.end();
}

template<class ELEM>
typename SpecificElementVisitor<ELEM>::const_iterator_t SpecificElementVisitor<ELEM>::end() const{
    return allElementsOfTypeE.end();
}

template<class ELEM>
typename SpecificElementVisitor<ELEM>::reference_t SpecificElementVisitor<ELEM>::front() {
    return allElementsOfTypeE.front();
}

template<class ELEM>
typename SpecificElementVisitor<ELEM>::const_reference_t SpecificElementVisitor<ELEM>::front() const{
    return allElementsOfTypeE.front();
}

552
#endif