BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldLoaderBDSIM.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef BDSFIELDLOADERBDSIM_H
19#define BDSFIELDLOADERBDSIM_H
20
21#include "BDSDimensionType.hh"
22#include "BDSFieldValue.hh"
23
24#include "G4String.hh"
25
26#include <map>
27#include <string>
28#include <vector>
29
30#ifdef USE_GZSTREAM
31#include "src-external/gzstream/gzstream.h"
32#endif
33
38
52template <class T>
54{
55public:
58
59 BDSArray4DCoords* Load4D(const G4String& fileName);
60 BDSArray3DCoords* Load3D(const G4String& fileName);
61 BDSArray2DCoords* Load2D(const G4String& fileName);
62 BDSArray1DCoords* Load1D(const G4String& fileName);
63
64private:
66 void CleanUp();
67
69 void Terminate(const G4String& message = "");
70
72 void Load(const G4String& fileName,
73 const unsigned int nDim);
74
77 void ProcessData(const std::string& line,
78 const unsigned long xIndex,
79 const unsigned long yIndex,
80 const unsigned long zIndex,
81 unsigned long long currentLineNumber);
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 std::map<BDSDimensionType, G4double> dimUnitsMap;
104};
105
106#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.
void ProcessData(const std::string &line, const unsigned long xIndex, const unsigned long yIndex, const unsigned long zIndex, unsigned long long currentLineNumber)
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.
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.