G4tgrParameterMgr.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id: G4tgrParameterMgr.cc 69803 2013-05-15 15:24:50Z gcosmo $
00028 //
00029 //
00030 // class G4tgrParameterMgr
00031 
00032 // History:
00033 // - Created.                                 P.Arce, CIEMAT (November 2007)
00034 // -------------------------------------------------------------------------
00035 
00036 #include "G4tgrParameterMgr.hh"
00037 #include "G4tgrUtils.hh"
00038 #include "G4tgrMaterialFactory.hh"
00039 #include "G4tgrRotationMatrixFactory.hh"
00040 #include "G4tgrFileReader.hh"
00041 #include "G4tgrMessenger.hh"
00042 #include "G4UIcommand.hh"
00043 
00044 G4tgrParameterMgr* G4tgrParameterMgr::theInstance = 0;
00045 
00046 
00047 //-------------------------------------------------------------
00048 G4tgrParameterMgr::G4tgrParameterMgr()
00049 {
00050 }
00051 
00052 
00053 //-------------------------------------------------------------
00054 G4tgrParameterMgr::~G4tgrParameterMgr()
00055 {
00056   delete theInstance;
00057 }
00058 
00059 
00060 //-------------------------------------------------------------
00061 G4tgrParameterMgr* G4tgrParameterMgr::GetInstance()
00062 {
00063   if( !theInstance )
00064   {
00065     theInstance = new G4tgrParameterMgr;
00066   }
00067   return theInstance;
00068 }
00069 
00070 
00071 //-------------------------------------------------------------
00072 void G4tgrParameterMgr::AddParameterNumber( const std::vector<G4String>& wl,
00073                                                   G4bool mustBeNew  )
00074 {
00075   CheckIfNewParameter( wl, mustBeNew );
00076 
00077   //----- Convert third argument to double, but then store it as string
00078   //      for later use in CLHEP evaluator 
00079   G4float val = G4tgrUtils::GetDouble( wl[2] );
00080   theParameterList[ wl[1] ] = G4UIcommand::ConvertToString( val );
00081 
00082 #ifdef G4VERBOSE
00083   if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00084   {
00085     G4cout << " G4tgrParameterMgr::AddParameterNumber() -"
00086            << " parameter added " <<  wl[1]
00087            << " = " << theParameterList[ wl[1] ] << G4endl; 
00088   }
00089 #endif
00090 }
00091 
00092 
00093 //-------------------------------------------------------------
00094 void G4tgrParameterMgr::AddParameterString( const std::vector<G4String>& wl,
00095                                                   G4bool mustBeNew  )
00096 {
00097   CheckIfNewParameter( wl, mustBeNew );
00098 
00099   //----- Store parameter as string
00100   theParameterList[ wl[1] ] = wl[2];
00101 
00102 #ifdef G4VERBOSE
00103   if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00104   {
00105     G4cout << " G4tgrParameterMgr::AddParameterString() -"
00106            << " parameter added " <<  wl[1]
00107            << " = " << theParameterList[ wl[1] ] << G4endl; 
00108   }
00109 #endif
00110 }
00111 
00112 //-------------------------------------------------------------
00113 void G4tgrParameterMgr::CheckIfNewParameter( const std::vector<G4String>& wl,
00114                                                    G4bool mustBeNew  )
00115 {
00116   //---------- Find first if it exists already
00117   G4bool existsAlready;
00118   G4mapss::iterator sdite = theParameterList.find( wl[1] );
00119   if( sdite == theParameterList.end() )
00120   {
00121     existsAlready = false;
00122   }
00123   else
00124   {
00125     existsAlready = true;
00126   }
00127 
00128   if(existsAlready)
00129   {
00130     if( mustBeNew )
00131     {
00132       G4String ErrMessage = "Parameter already exists... " + wl[1];
00133       G4Exception("G4tgrParameterMgr::CheckParameter()",
00134                   "IllegalConstruct", FatalException, ErrMessage);
00135     }
00136     else
00137     {
00138       G4String WarMessage = "Parameter already exists... " + wl[1];
00139       G4Exception("G4tgrParameterMgr::CheckParameter()",
00140                   "NotRecommended", JustWarning, WarMessage);
00141     }
00142   }
00143   
00144   //---------- Check for miminum number of words read 
00145   G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_EQ, "Parameter::AddParameter");
00146 }
00147 
00148 
00149 //-------------------------------------------------------------
00150 G4String G4tgrParameterMgr::FindParameter( const G4String& name, G4bool exists )
00151 {
00152   G4String par = "";
00153   
00154   G4mapss::iterator sdite = theParameterList.find( name );
00155   if( sdite == theParameterList.end() )
00156   {
00157     if( exists )
00158     {
00159       DumpList();
00160       G4String ErrMessage = "Parameter not found in list: " + name;
00161       G4Exception("G4tgrParameterMgr::FindParameter()",
00162                   "InvalidSetup", FatalException, ErrMessage);
00163     }
00164   }
00165   else
00166   {
00167     exists = 1;
00168     par = ((*sdite).second);
00169 #ifdef G4VERBOSE
00170   if( G4tgrMessenger::GetVerboseLevel() >= 3 )
00171   {
00172     G4cout << " G4tgrParameterMgr::FindParameter() -"
00173            << " parameter found " << name << " = " << par << G4endl; 
00174   }
00175 #endif
00176   }
00177 
00178   return par;
00179 }
00180 
00181 
00182 //-------------------------------------------------------------
00183 void G4tgrParameterMgr::DumpList()
00184 {
00185   //---------- Dump number of objects of each class
00186   G4cout << " @@@@@@@@@@@@@@@@@@ Dumping parameter list " << G4endl;
00187   G4mapss::const_iterator cite;
00188   for( cite = theParameterList.begin();cite != theParameterList.end(); cite++ )
00189   {
00190     G4cout << (*cite).first << " = " << (*cite).second << G4endl;
00191   }
00192 }

Generated on Mon May 27 17:49:59 2013 for Geant4 by  doxygen 1.4.7