/scratch0/jsnuveri/BDSIM/BDSIMgit/bdsim/src/BDSMySQLTable.cc

00001 /* * BDSIM code.    Version 1.0
00002    * Author: Grahame A. Blair, Royal Holloway, Univ. of London.
00003    * Last modified 24.7.2002
00004    * Copyright (c) 2002 by G.A.Blair.  ALL RIGHTS RESERVED. 
00005 
00006 
00007    Author of this code: John C. Carter, Royal Holloway, Univ. of London.
00008    Last modified 12.10.2005
00009 */
00010 
00011 
00012 #include <cstdlib>
00013 #include <string>
00014 #include <vector>
00015 
00016 #include "BDSMySQLTable.hh"
00017 #include "BDSDebug.hh"
00018 
00019 BDSMySQLTable::BDSMySQLTable (G4String aTableName)
00020 {
00021 #ifdef BDSDEBUG
00022   G4cout << __METHOD_NAME__ << " - creating new table named: " << aTableName << G4endl;
00023 #endif
00024   SetValidVarTypes();
00025   itsTableName = aTableName;
00026   itsNVariables = 0;
00027 }
00028 
00029 void BDSMySQLTable::AddVariable(G4String aName, G4String aType){
00030   if(aName == ""){
00031     return;
00032   }
00033   if(!isValidVarType(aType)){
00034     return;
00035   }
00036 #ifdef BDSDEBUG
00037   G4cout << __METHOD_NAME__ << " - adding variable: " << aName << " " << aType << " to table " << GetName() << G4endl;
00038 #endif
00039   itsVar.push_back(new BDSMySQLVariable(aName,aType));
00040   itsNVariables++;
00041 #ifdef BDSDEBUG
00042   G4cout << __METHOD_NAME__ << " - nVariables = " << GetNVariables() << G4endl;
00043 #endif
00044 }
00045 
00046 void BDSMySQLTable::Print(){
00047   G4cout << __METHOD_NAME__ << G4endl;
00048   G4cout << GetName() << G4endl;
00049   for(int i=0; i<itsNVariables; i++){
00050     GetVariable(i)->Print();
00051   }
00052 }
00053 
00054 
00055 BDSMySQLVariable* BDSMySQLTable::GetVariable(G4String aVarName)
00056 {
00057   for (G4int i=0; i<(G4int)itsVar.size(); i++)
00058     {
00059       G4String::caseCompare cmpmode = G4String::ignoreCase;
00060       if( (itsVar[i])->GetName().compareTo(aVarName,cmpmode)==0) {
00061         return itsVar[i];
00062       }
00063     }
00064   return NULL; //if does not exist return null
00065 }
00066 
00067 BDSMySQLVariable* BDSMySQLTable::GetVariable(G4int aVarN)
00068 {
00069   return itsVar[aVarN];
00070 }
00071 
00072 void BDSMySQLTable::SetValidVarTypes(){
00073   _validVarTypes.push_back((G4String)"DOUBLE");
00074   _validVarTypes.push_back((G4String)"INTEGER");
00075   _validVarTypes.push_back((G4String)"STRING");
00076 
00077 }
00078 
00079 G4bool BDSMySQLTable::isValidVarType(G4String val){
00080   G4bool result = false;
00081   for(std::vector<G4String>::const_iterator iter = _validVarTypes.begin(); iter != _validVarTypes.end(); ++iter){
00082     if((*iter) == val) result = true;
00083   }
00084   return result;
00085 }
00086 
00087 BDSMySQLTable::~BDSMySQLTable()
00088 {
00089 }
00090 
00091 
00092 void BDSMySQLVariable::Print(){
00093   G4cout << __METHOD_NAME__ << G4endl;
00094   std::string varType=GetVarType();
00095   G4cout << GetName() << " " << GetVarType() << " " << G4endl;;
00096   for(int i=0; i<GetNVariables(); i++){
00097     if(varType=="DOUBLE") G4cout << GetDblValue(i) << G4endl;
00098     if(varType=="INTEGER")G4cout << GetIntValue(i) << G4endl;
00099     if(varType=="STRING")G4cout << GetStrValue(i) << G4endl;
00100   }
00101 }
00102 

Generated on 28 Jun 2015 for BDSIM by  doxygen 1.4.7