BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSMySQLTable.cc
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#include "BDSDebug.hh"
19#include "BDSMySQLTable.hh"
20#include "BDSMySQLVariable.hh"
21
22#include "G4String.hh"
23#include "G4Version.hh"
24
25#include <cstdlib>
26#include <string>
27#include <vector>
28
29BDSMySQLTable::BDSMySQLTable (G4String aTableName)
30{
31#ifdef BDSDEBUG
32 G4cout << __METHOD_NAME__ << " - creating new table named: " << aTableName << G4endl;
33#endif
34 SetValidVarTypes();
35 itsTableName = aTableName;
36 itsNVariables = 0;
37}
38
39void BDSMySQLTable::AddVariable(G4String aName, G4String aType)
40{
41 if(aName.empty())
42 {return;}
43
44 if(!isValidVarType(aType))
45 {return;}
46#ifdef BDSDEBUG
47 G4cout << __METHOD_NAME__ << " - adding variable: " << aName << " " << aType << " to table " << GetName() << G4endl;
48#endif
49 itsVar.push_back(new BDSMySQLVariable(aName,aType));
50 itsNVariables++;
51#ifdef BDSDEBUG
52 G4cout << __METHOD_NAME__ << " - nVariables = " << GetNVariables() << G4endl;
53#endif
54}
55
56void BDSMySQLTable::Print()
57{
58 G4cout << GetName() << G4endl;
59 for(int i=0; i<itsNVariables; i++)
60 {GetVariable(i)->Print();}
61}
62
63BDSMySQLVariable* BDSMySQLTable::GetVariable(G4String aVarName)
64{
65 for (G4int i=0; i<(G4int)itsVar.size(); i++)
66 {
67#if G4VERSION_NUMBER > 1099
68 if (G4StrUtil::icompare(itsVar[i]->GetName(), aVarName) == 0)
69#else
70 G4String::caseCompare cmpmode = G4String::ignoreCase;
71 if( (itsVar[i])->GetName().compareTo(aVarName,cmpmode)==0)
72#endif
73 {return itsVar[i];}
74 }
75 return nullptr; //if does not exist return null
76}
77
78BDSMySQLVariable* BDSMySQLTable::GetVariable(G4int aVarN)
79{
80 return itsVar[aVarN];
81}
82
83void BDSMySQLTable::SetValidVarTypes(){
84 _validVarTypes.push_back((G4String)"DOUBLE");
85 _validVarTypes.push_back((G4String)"INTEGER");
86 _validVarTypes.push_back((G4String)"STRING");
87
88}
89
90G4bool BDSMySQLTable::isValidVarType(G4String val){
91 G4bool result = false;
92 for(std::vector<G4String>::const_iterator iter = _validVarTypes.begin(); iter != _validVarTypes.end(); ++iter){
93 if((*iter) == val) result = true;
94 }
95 return result;
96}
97
98BDSMySQLTable::~BDSMySQLTable()
99{
100}
101
102
103void BDSMySQLVariable::Print(){
104 G4cout << __METHOD_NAME__ << G4endl;
105 std::string varType=GetVarType();
106 G4cout << GetName() << " " << GetVarType() << " " << G4endl;
107 for(int i=0; i<GetNVariables(); i++){
108 if(varType=="DOUBLE") G4cout << GetDblValue(i) << G4endl;
109 if(varType=="INTEGER")G4cout << GetIntValue(i) << G4endl;
110 if(varType=="STRING")G4cout << GetStrValue(i) << G4endl;
111 }
112}
113
A variable representation for mysql loader.
G4int GetNVariables() const
Accessor.
G4String GetName() const
Accessor.
G4double GetDblValue(G4int itemN) const
Accessor.
G4String GetVarType() const
Accessor.
G4int GetIntValue(G4int itemN) const
Accessor.
G4String GetStrValue(G4int itemN) const
Accessor.