OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
RangeSelector.cpp
Go to the documentation of this file.
1 //
2 // Class RangeSelector
3 // This abstract class runs through a beam line and calls the pure
4 // virtual methods RangeSelector::handleXXX() for each element or
5 // beamline in a range.
6 //
7 // Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
8 // All rights reserved
9 //
10 // This file is part of OPAL.
11 //
12 // OPAL is free software: you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation, either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
19 //
20 #include "Tables/RangeSelector.h"
24 #include "AbstractObjects/Object.h"
25 #include "Beamlines/Beamline.h"
27 
28 class Element;
29 
30 
31 RangeSelector::RangeSelector(const Beamline &beamline, const RangeRep &range):
32  DefaultVisitor(beamline, false, false), itsRange(range)
33 {}
34 
35 
37 {}
38 
39 
43 }
44 
45 
47  // Are we past the beginning of the range ?
48  itsRange.enter(fep);
49 
50  // Do the required operations on the beamline or element.
51  ElementBase *base = fep.getElement();
52 
53  if(dynamic_cast<Beamline *>(base)) {
54  handleBeamline(fep);
55  } else {
56  handleElement(fep);
57  }
58 
59  // Are we past the end of the range ?
60  itsRange.leave(fep);
61 }
62 
63 
66 }
67 
68 
70  // Default: delegate algorithm to the element, if in range.
71  if(itsRange.isActive()) {
73  }
74 }
Representation of a range within a beam line or sequence.
Definition: RangeRep.h:34
bool isActive() const
Test for active range.
Definition: RangeRep.cpp:65
void initialize()
Initialise data for search.
Definition: RangeRep.cpp:54
void leave(const FlaggedElmPtr &) const
Leave an element or line.
Definition: RangeRep.cpp:80
void enter(const FlaggedElmPtr &) const
Enter an element or line.
Definition: RangeRep.cpp:70
virtual void visitFlaggedElmPtr(const FlaggedElmPtr &)
Apply the algorithm to a FlaggedElmPtr.
virtual void execute()
Apply the algorithm to the top-level beamline.
An abstract sequence of beam line components.
Definition: Beamline.h:34
ElementBase * getElement() const
Get the element pointer.
Definition: ElmPtr.h:58
A section of a beam line.
Definition: FlaggedElmPtr.h:36
virtual void handleElement(const FlaggedElmPtr &)
The operation to be done for elements.
virtual ~RangeSelector()
virtual void visitFlaggedElmPtr(const FlaggedElmPtr &)
Apply the visitor to an FlaggedElmPtr.
virtual void handleBeamline(const FlaggedElmPtr &)
The operation to be done for beamlines.
virtual void execute()
Execute the algorithm.
RangeRep itsRange
Working data for range.
Definition: RangeSelector.h:55