BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSArrayOperatorIndex.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef BDSARRAYOPERATORINDEX_H
20#define BDSARRAYOPERATORINDEX_H
21#include "G4String.hh"
22#include "G4Types.hh"
23
24#include <array>
25
37{
38public:
39 BDSArrayOperatorIndex() = delete;
40 explicit BDSArrayOperatorIndex(const G4String& nameIn = "None"):
41 name(nameIn),
42 operatesOn{false, false, false, false}
43 {;}
44 virtual ~BDSArrayOperatorIndex(){;}
45
47 virtual G4String Name() const {return name;}
48
51 virtual void Apply(G4int& /*x*/,
52 G4int& /*y*/,
53 G4int& /*z*/,
54 G4int& /*t*/) const {;}
55 virtual void ApplyX(G4int& /*x*/) const {;}
56 virtual void ApplyY(G4int& /*y*/) const {;}
57 virtual void ApplyZ(G4int& /*z*/) const {;}
58 virtual void ApplyT(G4int& /*t*/) const {;}
59
61 virtual std::array<G4bool, 4> OperatesOnXYZT() const {return operatesOn;}
62
63 void Apply(G4int& x) const
64 {
65 G4int v[3] = {0,0,0};
66 return Apply(x, v[0], v[1], v[2]);
67 }
68
69 void Apply(G4int& x, G4int& y) const
70 {
71 G4int v[2] = {0,0};
72 return Apply(x, y, v[0], v[1]);
73 }
74
75 void Apply(G4int& x, G4int& y, G4int& z) const
76 {
77 G4int t = 0;
78 Apply(x, y, z, t);
79 }
80
81 virtual void TransformLimits(G4double& xMin, G4double& xMax,
82 G4double& yMin, G4double& yMax,
83 G4double& zMin, G4double& zMax,
84 G4double& tMin, G4double& tMax) const = 0;
85
86 void TransformLimits(G4double& xMin, G4double xMax) const
87 {
88 G4double v[6] = {0,0,0,0,0,0};
89 TransformLimits(xMin, xMax, v[0], v[1], v[2], v[3], v[4], v[5]);
90 }
91 void TransformLimits(G4double& xMin, G4double& xMax,
92 G4double& yMin, G4double& yMax) const
93 {
94 G4double v[4] = {0,0,0,0};
95 TransformLimits(xMin, xMax, yMin, yMax, v[0], v[1], v[2], v[3]);
96 }
97 void TransformLimits(G4double& xMin, G4double& xMax,
98 G4double& yMin, G4double& yMax,
99 G4double& zMin, G4double& zMax) const
100 {
101 G4double v[2] = {0, 0};
102 TransformLimits(xMin, xMax, yMin, yMax, zMin, zMax, v[0], v[1]);
103 }
104
105protected:
106 G4String name;
107 std::array<G4bool, 4> operatesOn;
108};
109
110#endif
Interface for modifying by reference array indices.
virtual G4String Name() const
Supply a name of this operator for feedback to the user in print out.
virtual void Apply(G4int &, G4int &, G4int &, G4int &) const
virtual std::array< G4bool, 4 > OperatesOnXYZT() const
Return which axes this object operates on overall.