BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSArrayOperatorIndexV.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 BDSARRAYOPERATORINDEXV_H
20#define BDSARRAYOPERATORINDEXV_H
21#include "BDSArrayOperatorIndex.hh"
22
23#include "G4Types.hh"
24
25#include <array>
26#include <vector>
27
35{
36public:
38 BDSArrayOperatorIndex("Vector( "){;}
40 {
41 for (auto op : operators)
42 {delete op;}
43 }
44
47 {
48 operators.push_back(operatorIn);
49 // update base class record of what this oeprates on
50 const std::array<G4bool, 4> ops = operatorIn->OperatesOnXYZT();
51 for (G4int i = 0; i < (G4int)ops.size(); i++)
52 {operatesOn[i] = operatesOn[i] || ops[i];}
53 }
54
56 virtual G4String Name() const
57 {
58 G4String result = "Vector(";
59 for (auto op : operators)
60 {result += op->Name() + " ";}
61 result += ")";
62 return result;
63 }
64
67 virtual void Apply(G4int& x,
68 G4int& y,
69 G4int& z,
70 G4int& t) const
71 {
72 for (auto op : operators)
73 {op->Apply(x,y,z,t);}
74 }
75 virtual void ApplyX(G4int& x) const
76 {
77 for (auto op : operators)
78 {op->ApplyX(x);}
79 }
80 virtual void ApplyY(G4int& y) const
81 {
82 for (auto op : operators)
83 {op->ApplyY(y);}
84 }
85 virtual void ApplyZ(G4int& z) const
86 {
87 for (auto op : operators)
88 {op->ApplyZ(z);}
89 }
90 virtual void ApplyT(G4int& t) const
91 {
92 for (auto op : operators)
93 {op->ApplyT(t);}
94 }
95
96 virtual void TransformLimits(G4double& xMin, G4double& xMax,
97 G4double& yMin, G4double& yMax,
98 G4double& zMin, G4double& zMax,
99 G4double& tMin, G4double& tMax) const
100 {
101 for (auto op : operators)
102 {op->TransformLimits(xMin, xMax, yMin, yMax, zMin, zMax, tMin, tMax);}
103 }
104
105 std::vector<BDSArrayOperatorIndex*> operators;
106};
107
108#endif
Vectorised version of BDSArrayOperatorIndex.
virtual void Apply(G4int &x, G4int &y, G4int &z, G4int &t) const
virtual G4String Name() const
Supply a name of this operator for feedback to the user in print out.
void push_back(BDSArrayOperatorIndex *operatorIn)
Append an operator to the vector.
Interface for modifying by reference array indices.
virtual std::array< G4bool, 4 > OperatesOnXYZT() const
Return which axes this object operates on overall.