BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSFieldLoaderBDSIM.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 BDSFIELDLOADERBDSIM_H
20#define BDSFIELDLOADERBDSIM_H
21
22#include "BDSDimensionType.hh"
23#include "BDSFieldValue.hh"
24
25#include "G4String.hh"
26
27#include <map>
28#include <string>
29#include <vector>
30
31#ifdef USE_GZSTREAM
32#include "src-external/gzstream/gzstream.h"
33#endif
34
39
53template <class T>
55{
56public:
59
60 BDSArray4DCoords* Load4D(const G4String& fileName);
61 BDSArray3DCoords* Load3D(const G4String& fileName);
62 BDSArray2DCoords* Load2D(const G4String& fileName);
63 BDSArray1DCoords* Load1D(const G4String& fileName);
64
65private:
67 void CleanUp();
68
70 void Terminate(const G4String& message = "");
71
73 void Load(const G4String& fileName,
74 const unsigned int nDim);
75
78 void ProcessData(const std::string& line,
79 const unsigned long xIndex,
80 const unsigned long yIndex = 0,
81 const unsigned long zIndex = 0);
82
85
87 unsigned long nColumns;
88 std::vector<G4float> lineData;
90 std::map<G4String, double> header;
92 G4String loopOrder;
93 const std::vector<G4String> headerMustBePositiveKeys;
94 unsigned long indexOfFirstFieldValue;
95
97 {
98 G4String number;
99 G4String min;
100 G4String max;
101 };
102 std::map<BDSDimensionType, DimensionKeys> dimKeyMap;
103};
104
105#endif
1D array with spatial mapping derived from BDSArray4DCoords.
2D array with spatial mapping derived from BDSArray4DCoords.
3D array with spatial mapping derived from BDSArray4DCoords.
Overlay of 4D array that provides uniform only spatial coordinate mapping.
Loader for BDSIM format fields.
std::map< G4String, double > header
Header keys and values.
BDSFieldValue fv
Temporary field value.
BDSArray3DCoords * Load3D(const G4String &fileName)
Load a 3D array.
BDSArray4DCoords * result
Resultant array from loading.
void CleanUp()
Ensure any member variables are reset between usages.
BDSArray4DCoords * Load4D(const G4String &fileName)
Load a 4D array.
BDSArray1DCoords * Load1D(const G4String &fileName)
Load a 1D array.
void Terminate(const G4String &message="")
Close file and exit program in case of an error.
void Load(const G4String &fileName, const unsigned int nDim)
General loader for any number of dimensions.
void ProcessData(const std::string &line, const unsigned long xIndex, const unsigned long yIndex=0, const unsigned long zIndex=0)
unsigned long nColumns
Number of columns to read.
std::vector< G4float > lineData
Vector to store line data during loading.
G4String loopOrder
String for looping order when loading.
BDSArray2DCoords * Load2D(const G4String &fileName)
Load a 2D array.
T file
Templated iostream for std::ifstream and gzstream as well.