Import Geant4 10.0.0 source tree
This commit is contained in:
+6
-16
@@ -24,26 +24,16 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4DataVector.cc,v 1.12 2010-11-01 13:55:53 gcosmo Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id: G4Allocator.cc 66241 2012-12-13 18:34:42Z gunter $
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------
|
||||
// GEANT 4 class implementation file
|
||||
//
|
||||
// G4PhysicsVectorCache.cc
|
||||
//
|
||||
// --------------------------------------------------------------
|
||||
|
||||
#include "G4PhysicsVectorCache.hh"
|
||||
#include "G4Allocator.hh"
|
||||
#include "G4AllocatorList.hh"
|
||||
|
||||
G4Allocator<G4PhysicsVectorCache> aPVCacheAllocator;
|
||||
|
||||
G4PhysicsVectorCache::G4PhysicsVectorCache()
|
||||
: lastEnergy(-DBL_MAX), lastValue(0.), lastBin(0)
|
||||
G4AllocatorBase::G4AllocatorBase()
|
||||
{
|
||||
G4AllocatorList::GetAllocatorList()->Register(this);
|
||||
}
|
||||
|
||||
G4PhysicsVectorCache::~G4PhysicsVectorCache()
|
||||
{
|
||||
}
|
||||
G4AllocatorBase::~G4AllocatorBase() {;}
|
||||
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4AllocatorList.cc 66241 2012-12-13 18:34:42Z gunter $
|
||||
//
|
||||
//
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
#include "G4AllocatorList.hh"
|
||||
#include "G4Allocator.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
G4ThreadLocal G4AllocatorList* G4AllocatorList::fAllocatorList=0;
|
||||
|
||||
G4AllocatorList* G4AllocatorList::GetAllocatorList()
|
||||
{
|
||||
if(!fAllocatorList)
|
||||
{
|
||||
fAllocatorList = new G4AllocatorList;
|
||||
}
|
||||
return fAllocatorList;
|
||||
}
|
||||
|
||||
G4AllocatorList* G4AllocatorList::GetAllocatorListIfExist()
|
||||
{
|
||||
return fAllocatorList;
|
||||
}
|
||||
|
||||
G4AllocatorList::G4AllocatorList()
|
||||
{
|
||||
}
|
||||
|
||||
G4AllocatorList::~G4AllocatorList()
|
||||
{
|
||||
fAllocatorList = 0;
|
||||
}
|
||||
|
||||
void G4AllocatorList::Register(G4AllocatorBase* alloc)
|
||||
{
|
||||
fList.push_back(alloc);
|
||||
}
|
||||
|
||||
void G4AllocatorList::Destroy(G4int nStat, G4int verboseLevel)
|
||||
{
|
||||
std::vector<G4AllocatorBase*>::iterator itr=fList.begin();
|
||||
G4int i=0, j=0;
|
||||
G4double mem=0;
|
||||
for(; itr!=fList.end();++itr)
|
||||
{
|
||||
if(i<nStat)
|
||||
{
|
||||
i++;
|
||||
mem += (*itr)->GetAllocatedSize();
|
||||
(*itr)->ResetStorage();
|
||||
continue;
|
||||
}
|
||||
j++;
|
||||
mem += (*itr)->GetAllocatedSize();
|
||||
(*itr)->ResetStorage();
|
||||
delete *itr;
|
||||
}
|
||||
if(verboseLevel>0)
|
||||
{
|
||||
G4cout << "================== Deleting memory pools ==================="
|
||||
<< G4endl;
|
||||
G4cout << "Number of memory pools allocated: " << Size()
|
||||
<< "; of which, static: " << i << G4endl;
|
||||
G4cout << "Dynamic pools deleted: " << j
|
||||
<< " / Total memory freed: " << std::setprecision(2)
|
||||
<< mem/1048576 << std::setprecision(6) << " Mb" << G4endl;
|
||||
G4cout << "============================================================"
|
||||
<< G4endl;
|
||||
}
|
||||
fList.clear();
|
||||
}
|
||||
|
||||
G4int G4AllocatorList::Size() const
|
||||
{
|
||||
return fList.size();
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4AllocatorPool.cc 67970 2013-03-13 10:10:06Z gcosmo $
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
+4
-29
@@ -23,34 +23,9 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id:$
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
// --------------------------------------------------------------
|
||||
// GEANT 4 class implementation file
|
||||
//
|
||||
// G4Physics2DVectorCache.cc
|
||||
//
|
||||
// Author: Vladimir Ivanchenko
|
||||
// on base of Hisaya Kurashige 1D class
|
||||
//
|
||||
// Creation date: 25.09.2011
|
||||
// --------------------------------------------------------------
|
||||
|
||||
#include "G4Physics2DVectorCache.hh"
|
||||
|
||||
|
||||
G4Physics2DVectorCache::G4Physics2DVectorCache()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
G4Physics2DVectorCache::~G4Physics2DVectorCache()
|
||||
{
|
||||
}
|
||||
|
||||
void G4Physics2DVectorCache::Clear()
|
||||
{
|
||||
lastX = lastY = lastValue = 0.0;
|
||||
lastBinX = lastBinY = 0;
|
||||
}
|
||||
// Decalare needed static data member for fully specialized version of cache
|
||||
#include "G4CacheDetails.hh"
|
||||
G4ThreadLocal std::vector<G4double>* G4CacheReference<G4double>::cache = 0;
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4DataVector.cc 67970 2013-03-13 10:10:06Z gcosmo $
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4ErrorPropagatorData.cc 67970 2013-03-13 10:10:06Z gcosmo $
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
@@ -35,8 +35,8 @@
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
G4ErrorPropagatorData* G4ErrorPropagatorData::theErrorPropagatorData = 0;
|
||||
G4int G4ErrorPropagatorData::theVerbosity = 0;
|
||||
G4ThreadLocal G4ErrorPropagatorData* G4ErrorPropagatorData::fpInstance = 0;
|
||||
G4ThreadLocal G4int G4ErrorPropagatorData::theVerbosity = 0;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
@@ -48,16 +48,16 @@ G4ErrorPropagatorData::G4ErrorPropagatorData()
|
||||
|
||||
G4ErrorPropagatorData::~G4ErrorPropagatorData()
|
||||
{
|
||||
delete fpInstance; fpInstance = 0;
|
||||
}
|
||||
|
||||
G4ErrorPropagatorData* G4ErrorPropagatorData::GetErrorPropagatorData()
|
||||
{
|
||||
static G4ErrorPropagatorData errorPropagatorData;
|
||||
if( !theErrorPropagatorData )
|
||||
if (fpInstance == 0)
|
||||
{
|
||||
theErrorPropagatorData = &errorPropagatorData;
|
||||
fpInstance = new G4ErrorPropagatorData;
|
||||
}
|
||||
return theErrorPropagatorData;
|
||||
return fpInstance;
|
||||
}
|
||||
|
||||
G4int G4ErrorPropagatorData::verbose()
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4Exception.cc 67970 2013-03-13 10:10:06Z gcosmo $
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4GeometryTolerance.cc 70333 2013-05-29 08:56:45Z gcosmo $
|
||||
//
|
||||
// class G4GeometryTolerance
|
||||
//
|
||||
@@ -43,7 +43,7 @@
|
||||
// Static class data
|
||||
// ***************************************************************************
|
||||
//
|
||||
G4GeometryTolerance* G4GeometryTolerance::fInstance = 0;
|
||||
G4GeometryTolerance* G4GeometryTolerance::fpInstance = 0;
|
||||
G4bool G4GeometryTolerance::fInitialised = false;
|
||||
G4double G4GeometryTolerance::fCarTolerance = 1E-9*mm;
|
||||
G4double G4GeometryTolerance::fAngTolerance = 1E-9*rad;
|
||||
@@ -63,6 +63,7 @@ G4GeometryTolerance::G4GeometryTolerance()
|
||||
//
|
||||
G4GeometryTolerance::~G4GeometryTolerance()
|
||||
{
|
||||
delete fpInstance; fpInstance = 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
@@ -72,12 +73,11 @@ G4GeometryTolerance::~G4GeometryTolerance()
|
||||
//
|
||||
G4GeometryTolerance* G4GeometryTolerance::GetInstance()
|
||||
{
|
||||
static G4GeometryTolerance theToleranceManager;
|
||||
if (!fInstance)
|
||||
if (fpInstance == 0)
|
||||
{
|
||||
fInstance = &theToleranceManager;
|
||||
fpInstance = new G4GeometryTolerance;
|
||||
}
|
||||
return fInstance;
|
||||
return fpInstance;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4LPhysicsFreeVector.cc 74256 2013-10-02 14:24:02Z gcosmo $
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
@@ -36,6 +36,7 @@
|
||||
//
|
||||
// Modified:
|
||||
// 19 Jun. 2009, V.Ivanchenko : removed hidden bin
|
||||
// 19 Jun. 2009, V.Ivanchenko : removed FindBinLocation
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
@@ -89,26 +90,3 @@ void G4LPhysicsFreeVector::DumpValues()
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
size_t G4LPhysicsFreeVector::FindBinLocation(G4double theEnergy) const
|
||||
{
|
||||
G4int n1 = 0;
|
||||
G4int n2 = numberOfNodes/2;
|
||||
G4int n3 = numberOfNodes - 1;
|
||||
while (n1 != n3 - 1)
|
||||
{
|
||||
if (theEnergy > binVector[n2])
|
||||
{ n1 = n2; }
|
||||
else
|
||||
{ n3 = n2; }
|
||||
n2 = n1 + (n3 - n1 + 1)/2;
|
||||
}
|
||||
#ifdef G4VERBOSE
|
||||
if (verboseLevel > 1)
|
||||
{
|
||||
G4cout << "G4LPhysicsFreeVector::FindBinLocation: returning "
|
||||
<< n1 << G4endl;
|
||||
}
|
||||
#endif
|
||||
return (size_t)n1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4MTcoutDestination.cc 66241 2012-12-13 18:34:42Z gunter $
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
// G4MTcoutDestination
|
||||
//
|
||||
|
||||
#include "G4MTcoutDestination.hh"
|
||||
#include "G4strstreambuf.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
G4MTcoutDestination::G4MTcoutDestination(const G4int& threadId,
|
||||
std::ostream& co, std::ostream& ce)
|
||||
: finalcout(co), finalcerr(ce), id(threadId), useBuffer(false),
|
||||
threadCoutToFile(false), threadCerrToFile(false), ignoreCout(false)
|
||||
{
|
||||
G4coutbuf.SetDestination(this);
|
||||
G4cerrbuf.SetDestination(this);
|
||||
prefix = "G4WT";
|
||||
}
|
||||
|
||||
G4MTcoutDestination::~G4MTcoutDestination()
|
||||
{
|
||||
if( useBuffer ) DumpBuffer();
|
||||
if( threadCoutToFile ) CloseCoutFile();
|
||||
if( threadCerrToFile ) CloseCerrFile();
|
||||
}
|
||||
|
||||
namespace { G4Mutex coutm = G4MUTEX_INITIALIZER; }
|
||||
|
||||
G4int G4MTcoutDestination::ReceiveG4cout(const G4String& msg)
|
||||
{
|
||||
if( threadCoutToFile )
|
||||
{ coutFile<<msg<<std::flush; }
|
||||
else if( useBuffer )
|
||||
{ cout_buffer<<msg; }
|
||||
else if( !ignoreCout )
|
||||
{ G4AutoLock l(&coutm); finalcout<<prefix<<id<<" > "<<msg; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
G4int G4MTcoutDestination::ReceiveG4cerr(const G4String& msg)
|
||||
{
|
||||
if( threadCerrToFile )
|
||||
{ cerrFile<<msg<<std::flush; }
|
||||
if( useBuffer )
|
||||
{ cerr_buffer<<msg; }
|
||||
else
|
||||
{ G4AutoLock l(&coutm); finalcerr<<prefix<<id<<" > "<<msg; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
void G4MTcoutDestination::SetCoutFileName(const G4String& fileN, G4bool ifAppend)
|
||||
{
|
||||
if( threadCoutToFile ) CloseCoutFile();
|
||||
if( fileN == "**Screen**" ) return;
|
||||
if( ! coutFile.is_open() )
|
||||
{
|
||||
std::ios::openmode mode = std::ios::out;
|
||||
if ( ifAppend ) mode |= std::ios::app;
|
||||
coutFile.open(fileN,mode);
|
||||
}
|
||||
threadCoutToFile = true;
|
||||
}
|
||||
|
||||
void G4MTcoutDestination::SetCerrFileName(const G4String& fileN, G4bool ifAppend)
|
||||
{
|
||||
if( threadCerrToFile ) CloseCerrFile();
|
||||
if( fileN == "**Screen**" ) return;
|
||||
if( ! cerrFile.is_open() )
|
||||
{
|
||||
std::ios::openmode mode = std::ios::out;
|
||||
if ( ifAppend ) mode |= std::ios::app;
|
||||
cerrFile.open(fileN,mode);
|
||||
}
|
||||
threadCerrToFile = true;
|
||||
}
|
||||
|
||||
void G4MTcoutDestination::EnableBuffering(G4bool flag)
|
||||
{
|
||||
if(useBuffer && !flag) DumpBuffer();
|
||||
useBuffer = flag;
|
||||
}
|
||||
|
||||
void G4MTcoutDestination::SetPrefixString(const G4String& wd)
|
||||
{ prefix = wd; }
|
||||
|
||||
void G4MTcoutDestination::SetIgnoreCout(G4int tid)
|
||||
{
|
||||
if(tid<0)
|
||||
{ ignoreCout = false; }
|
||||
else
|
||||
{ ignoreCout = (tid!=id); }
|
||||
}
|
||||
|
||||
void G4MTcoutDestination::CloseCoutFile()
|
||||
{
|
||||
if( coutFile.is_open() ) coutFile.close();
|
||||
threadCoutToFile = false;
|
||||
}
|
||||
|
||||
void G4MTcoutDestination::CloseCerrFile()
|
||||
{
|
||||
if( cerrFile.is_open() ) cerrFile.close();
|
||||
threadCerrToFile = false;
|
||||
}
|
||||
|
||||
void G4MTcoutDestination::DumpBuffer()
|
||||
{
|
||||
G4AutoLock l(&coutm);
|
||||
finalcout<<"====================="<<std::endl;
|
||||
finalcout<<"cout buffer for worker with ID:"<<id<<std::endl;
|
||||
finalcout<<cout_buffer.str()<<std::endl;
|
||||
finalcerr<<"====================="<<std::endl;
|
||||
finalcerr<<"cerr buffer for worker with ID:"<<id<<std::endl;
|
||||
finalcerr<<cerr_buffer.str()<<std::endl;
|
||||
finalcerr<<"====================="<<std::endl;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4OrderedTable.cc 67970 2013-03-13 10:10:06Z gcosmo $
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
//
|
||||
//
|
||||
// $Id:$
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------
|
||||
@@ -39,18 +38,17 @@
|
||||
//
|
||||
// --------------------------------------------------------------
|
||||
|
||||
#include "G4Physics2DVector.hh"
|
||||
#include <iomanip>
|
||||
|
||||
#include "G4Physics2DVector.hh"
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
G4Physics2DVector::G4Physics2DVector()
|
||||
: type(T_G4PhysicsFreeVector),
|
||||
numberOfXNodes(0), numberOfYNodes(0),
|
||||
verboseLevel(0), useBicubic(false)
|
||||
{
|
||||
cache = new G4Physics2DVectorCache();
|
||||
}
|
||||
{}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
@@ -59,7 +57,6 @@ G4Physics2DVector::G4Physics2DVector(size_t nx, size_t ny)
|
||||
numberOfXNodes(nx), numberOfYNodes(ny),
|
||||
verboseLevel(0), useBicubic(false)
|
||||
{
|
||||
cache = new G4Physics2DVectorCache();
|
||||
PrepareVectors();
|
||||
}
|
||||
|
||||
@@ -67,7 +64,6 @@ G4Physics2DVector::G4Physics2DVector(size_t nx, size_t ny)
|
||||
|
||||
G4Physics2DVector::~G4Physics2DVector()
|
||||
{
|
||||
delete cache;
|
||||
ClearVectors();
|
||||
}
|
||||
|
||||
@@ -86,7 +82,6 @@ G4Physics2DVector::G4Physics2DVector(const G4Physics2DVector& right)
|
||||
xVector = right.xVector;
|
||||
yVector = right.yVector;
|
||||
|
||||
cache = new G4Physics2DVectorCache();
|
||||
PrepareVectors();
|
||||
CopyData(right);
|
||||
}
|
||||
@@ -106,7 +101,6 @@ G4Physics2DVector& G4Physics2DVector::operator=(const G4Physics2DVector& right)
|
||||
verboseLevel = right.verboseLevel;
|
||||
useBicubic = right.useBicubic;
|
||||
|
||||
cache->Clear();
|
||||
PrepareVectors();
|
||||
CopyData(right);
|
||||
|
||||
@@ -154,56 +148,50 @@ void G4Physics2DVector::CopyData(const G4Physics2DVector &right)
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
void G4Physics2DVector::ComputeValue(G4double xx, G4double yy)
|
||||
G4double G4Physics2DVector::Value(G4double xx, G4double yy,
|
||||
size_t& idx, size_t& idy) const
|
||||
{
|
||||
if(xx != cache->lastBinX) {
|
||||
if(xx <= xVector[0]) {
|
||||
cache->lastX = xVector[0];
|
||||
cache->lastBinX = 0;
|
||||
} else if(xx >= xVector[numberOfXNodes-1]) {
|
||||
cache->lastX = xVector[numberOfXNodes-1];
|
||||
cache->lastBinX = numberOfXNodes-2;
|
||||
} else {
|
||||
cache->lastX = xx;
|
||||
FindBinLocationX(xx);
|
||||
}
|
||||
G4double x = xx;
|
||||
G4double y = yy;
|
||||
|
||||
// no interpolation outside the table
|
||||
if(x < xVector[0]) {
|
||||
x = xVector[0];
|
||||
} else if(x > xVector[numberOfXNodes - 1]) {
|
||||
x = xVector[numberOfXNodes - 1];
|
||||
}
|
||||
if(yy != cache->lastBinY) {
|
||||
if(yy <= yVector[0]) {
|
||||
cache->lastY = yVector[0];
|
||||
cache->lastBinY = 0;
|
||||
} else if(yy >= yVector[numberOfYNodes-1]) {
|
||||
cache->lastY = yVector[numberOfYNodes-1];
|
||||
cache->lastBinY = numberOfYNodes-2;
|
||||
} else {
|
||||
cache->lastY = yy;
|
||||
FindBinLocationY(yy);
|
||||
}
|
||||
if(y < yVector[0]) {
|
||||
y = yVector[0];
|
||||
} else if(y > yVector[numberOfYNodes - 1]) {
|
||||
y = yVector[numberOfYNodes - 1];
|
||||
}
|
||||
size_t idx = cache->lastBinX;
|
||||
size_t idy = cache->lastBinY;
|
||||
|
||||
// find bins
|
||||
idx = FindBinLocationX(x, idx);
|
||||
idy = FindBinLocationY(y, idy);
|
||||
|
||||
// interpolate
|
||||
if(useBicubic) {
|
||||
BicubicInterpolation(idx, idy);
|
||||
return BicubicInterpolation(x, y, idx, idy);
|
||||
} else {
|
||||
G4double x1 = xVector[idx];
|
||||
G4double x2 = xVector[idx+1];
|
||||
G4double y1 = yVector[idy];
|
||||
G4double y2 = yVector[idy+1];
|
||||
G4double x = cache->lastX;
|
||||
G4double y = cache->lastY;
|
||||
G4double v11= GetValue(idx, idy);
|
||||
G4double v12= GetValue(idx+1, idy);
|
||||
G4double v21= GetValue(idx, idy+1);
|
||||
G4double v22= GetValue(idx+1, idy+1);
|
||||
cache->lastValue =
|
||||
((y2 - y)*(v11*(x2 - x) + v12*(x - x1)) +
|
||||
((y - y1)*(v21*(x2 - x) + v22*(x - x1))))/((x2 - x1)*(y2 - y1));
|
||||
return ((y2 - y)*(v11*(x2 - x) + v12*(x - x1)) +
|
||||
((y - y1)*(v21*(x2 - x) + v22*(x - x1))))/((x2 - x1)*(y2 - y1));
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
void G4Physics2DVector::BicubicInterpolation(size_t idx, size_t idy)
|
||||
G4double
|
||||
G4Physics2DVector::BicubicInterpolation(G4double x, G4double y,
|
||||
size_t idx, size_t idy) const
|
||||
{
|
||||
// Bicubic interpolation according to
|
||||
// 1. H.M. Antia, "Numerical Methods for Scientists and Engineers",
|
||||
@@ -214,8 +202,6 @@ void G4Physics2DVector::BicubicInterpolation(size_t idx, size_t idy)
|
||||
G4double x2 = xVector[idx+1];
|
||||
G4double y1 = yVector[idy];
|
||||
G4double y2 = yVector[idy+1];
|
||||
G4double x = cache->lastX;
|
||||
G4double y = cache->lastY;
|
||||
G4double f1 = GetValue(idx, idy);
|
||||
G4double f2 = GetValue(idx+1, idy);
|
||||
G4double f3 = GetValue(idx+1, idy+1);
|
||||
@@ -252,7 +238,7 @@ void G4Physics2DVector::BicubicInterpolation(size_t idx, size_t idy)
|
||||
G4double f3xy = DerivativeXY(idx+1, idy+1, dxy);
|
||||
G4double f4xy = DerivativeXY(idx, idy+1, dxy);
|
||||
|
||||
cache->lastValue =
|
||||
return
|
||||
f1 + f1y*h2 + (3*(f4-f1) - 2*f1y - f4y)*h22 + (2*(f1 - f4) + f1y + f4y)*h23
|
||||
+ f1x*h1 + f1xy*h1*h2 +(3*(f4x - f1x) - 2*f1xy - f4xy)*h1*h22
|
||||
+ (2*(f1x - f4x) + f1xy + f4xy)*h1*h23
|
||||
@@ -278,8 +264,6 @@ G4Physics2DVector::PutVectors(const std::vector<G4double>& vecX,
|
||||
numberOfXNodes = vecX.size();
|
||||
numberOfYNodes = vecY.size();
|
||||
PrepareVectors();
|
||||
if(!cache) { cache = new G4Physics2DVectorCache(); }
|
||||
cache->Clear();
|
||||
for(size_t i = 0; i<numberOfXNodes; ++i) {
|
||||
xVector[i] = vecX[i];
|
||||
}
|
||||
@@ -322,13 +306,14 @@ void G4Physics2DVector::Store(std::ofstream& out)
|
||||
G4bool G4Physics2DVector::Retrieve(std::ifstream& in)
|
||||
{
|
||||
// initialisation
|
||||
cache->Clear();
|
||||
ClearVectors();
|
||||
|
||||
// binning
|
||||
G4int k;
|
||||
in >> k >> numberOfXNodes >> numberOfYNodes;
|
||||
if (in.fail()) { return false; }
|
||||
if (in.fail() || 0 >= numberOfXNodes || 0 >= numberOfYNodes) {
|
||||
return false;
|
||||
}
|
||||
PrepareVectors();
|
||||
type = G4PhysicsVectorType(k);
|
||||
|
||||
@@ -371,7 +356,7 @@ G4Physics2DVector::ScaleVector(G4double factor)
|
||||
|
||||
size_t
|
||||
G4Physics2DVector::FindBinLocation(G4double z,
|
||||
const G4PV2DDataVector& v)
|
||||
const G4PV2DDataVector& v) const
|
||||
{
|
||||
size_t lowerBound = 0;
|
||||
size_t upperBound = v.size() - 2;
|
||||
@@ -387,3 +372,57 @@ G4Physics2DVector::FindBinLocation(G4double z,
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
G4double G4Physics2DVector::FindLinearX(G4double rand, G4double yy,
|
||||
size_t& idy) const
|
||||
{
|
||||
G4double y = yy;
|
||||
|
||||
// no interpolation outside the table
|
||||
if(y < yVector[0]) {
|
||||
y = yVector[0];
|
||||
} else if(y > yVector[numberOfYNodes - 1]) {
|
||||
y = yVector[numberOfYNodes - 1];
|
||||
}
|
||||
|
||||
// find bins
|
||||
idy = FindBinLocationY(y, idy);
|
||||
|
||||
G4double x1 = InterpolateLinearX(*(value[idy]), rand);
|
||||
G4double x2 = InterpolateLinearX(*(value[idy+1]), rand);
|
||||
G4double res = x1;
|
||||
G4double del = yVector[idy+1] - yVector[idy];
|
||||
if(del != 0.0) {
|
||||
res += (x2 - x1)*(y - yVector[idy])/del;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
G4double G4Physics2DVector::InterpolateLinearX(G4PV2DDataVector& v,
|
||||
G4double rand) const
|
||||
{
|
||||
size_t nn = v.size();
|
||||
if(1 >= nn) { return 0.0; }
|
||||
size_t n1 = 0;
|
||||
size_t n2 = nn/2;
|
||||
size_t n3 = nn - 1;
|
||||
G4double y = rand*v[n3];
|
||||
while (n1 + 1 != n3)
|
||||
{
|
||||
if (y > v[n2])
|
||||
{ n1 = n2; }
|
||||
else
|
||||
{ n3 = n2; }
|
||||
n2 = (n3 + n1 + 1)/2;
|
||||
}
|
||||
G4double res = xVector[n1];
|
||||
G4double del = v[n3] - v[n1];
|
||||
if(del > 0.0) {
|
||||
res += (y - v[n1])*(xVector[n3] - res)/del;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4PhysicsFreeVector.cc 74256 2013-10-02 14:24:02Z gcosmo $
|
||||
//
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
@@ -108,7 +108,7 @@ void G4PhysicsFreeVector::PutValue( size_t theBinNumber,
|
||||
edgeMin = binVector[0];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
size_t G4PhysicsFreeVector::FindBinLocation(G4double theEnergy) const
|
||||
{
|
||||
// For G4PhysicsFreeVector, FindBinLocation is implemented using
|
||||
@@ -135,3 +135,4 @@ size_t G4PhysicsFreeVector::FindBinLocation(G4double theEnergy) const
|
||||
|
||||
return upperBound;
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4PhysicsLinearVector.cc 74256 2013-10-02 14:24:02Z gcosmo $
|
||||
//
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
@@ -34,6 +34,7 @@
|
||||
//
|
||||
// 15 Feb 1996 - K.Amako : 1st version
|
||||
// 19 Jun 2009 - V.Ivanchenko : removed hidden bin
|
||||
// 02 Oct 2013 - V.Ivanchenko : removed FindBinLocation
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
@@ -112,18 +113,3 @@ void G4PhysicsLinearVector::ScaleVector(G4double factorE, G4double factorV)
|
||||
baseBin = theEmin/dBin;
|
||||
}
|
||||
|
||||
|
||||
size_t G4PhysicsLinearVector::FindBinLocation(G4double theEnergy) const
|
||||
{
|
||||
// For G4PhysicsLinearVector, FindBinLocation is implemented using
|
||||
// a simple arithmetic calculation.
|
||||
//
|
||||
// Because this is a virtual function, it is accessed through a
|
||||
// pointer to the G4PhyiscsVector object for most usages. In this
|
||||
// case, 'inline' will not be invoked. However, there is a possibility
|
||||
// that the user access to the G4PhysicsLinearVector object directly and
|
||||
// not through pointers or references. In this case, the 'inline' will
|
||||
// be invoked. (See R.B.Murray, "C++ Strategies and Tactics", Chap.6.6)
|
||||
|
||||
return size_t( theEnergy/dBin - baseBin );
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4PhysicsLnVector.cc 74256 2013-10-02 14:24:02Z gcosmo $
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------
|
||||
@@ -34,21 +34,23 @@
|
||||
//
|
||||
// 27 Apr 1999 - M.G.Pia: Created from G4PhysicsLogVector
|
||||
// 19 Jun 2009 - V.Ivanchenko : removed hidden bin
|
||||
// 02 Oct. 2013 V.Ivanchenko : Remove FindBinLocation method
|
||||
//
|
||||
// --------------------------------------------------------------
|
||||
|
||||
#include "G4PhysicsLnVector.hh"
|
||||
#include "G4Exp.hh"
|
||||
|
||||
G4PhysicsLnVector::G4PhysicsLnVector()
|
||||
: G4PhysicsVector()
|
||||
{
|
||||
type = T_G4PhysicsLnVector;
|
||||
type = T_G4PhysicsLogVector;
|
||||
}
|
||||
|
||||
G4PhysicsLnVector::G4PhysicsLnVector(size_t theNbin)
|
||||
: G4PhysicsVector()
|
||||
{
|
||||
type = T_G4PhysicsLnVector;
|
||||
type = T_G4PhysicsLogVector;
|
||||
|
||||
numberOfNodes = theNbin + 1;
|
||||
dataVector.reserve(numberOfNodes);
|
||||
@@ -67,8 +69,8 @@ G4PhysicsLnVector::G4PhysicsLnVector(G4double theEmin,
|
||||
{
|
||||
type = T_G4PhysicsLnVector;
|
||||
|
||||
dBin = std::log(theEmax/theEmin)/theNbin;
|
||||
baseBin = std::log(theEmin)/dBin;
|
||||
dBin = G4Log(theEmax/theEmin)/theNbin;
|
||||
baseBin = G4Log(theEmin)/dBin;
|
||||
numberOfNodes = theNbin + 1;
|
||||
dataVector.reserve(numberOfNodes);
|
||||
binVector.reserve(numberOfNodes);
|
||||
@@ -78,7 +80,7 @@ G4PhysicsLnVector::G4PhysicsLnVector(G4double theEmin,
|
||||
|
||||
for (size_t i=1; i<numberOfNodes-1; i++)
|
||||
{
|
||||
binVector.push_back(std::exp((baseBin+i)*dBin));
|
||||
binVector.push_back(G4Exp((baseBin+i)*dBin));
|
||||
dataVector.push_back(0.0);
|
||||
}
|
||||
binVector.push_back(theEmax);
|
||||
@@ -96,8 +98,8 @@ G4bool G4PhysicsLnVector::Retrieve(std::ifstream& fIn, G4bool ascii)
|
||||
if (success)
|
||||
{
|
||||
G4double theEmin = binVector[0];
|
||||
dBin = std::log(binVector[1]/theEmin);
|
||||
baseBin = std::log(theEmin)/dBin;
|
||||
dBin = G4Log(binVector[1]/theEmin);
|
||||
baseBin = G4Log(theEmin)/dBin;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
@@ -106,22 +108,7 @@ void G4PhysicsLnVector::ScaleVector(G4double factorE, G4double factorV)
|
||||
{
|
||||
G4PhysicsVector::ScaleVector(factorE, factorV);
|
||||
G4double theEmin = binVector[0];
|
||||
dBin = std::log(binVector[1]/theEmin);
|
||||
baseBin = std::log(theEmin)/dBin;
|
||||
dBin = G4Log(binVector[1]/theEmin);
|
||||
baseBin = G4Log(theEmin)/dBin;
|
||||
}
|
||||
|
||||
size_t G4PhysicsLnVector::FindBinLocation(G4double theEnergy) const
|
||||
{
|
||||
|
||||
// For G4PhysicsLnVector, FindBinLocation is implemented using
|
||||
// a simple arithmetic calculation.
|
||||
//
|
||||
// Because this is a virtual function, it is accessed through a
|
||||
// pointer to the G4PhyiscsVector object for most usages. In this
|
||||
// case, 'inline' will not be invoked. However, there is a possibility
|
||||
// that the user access to the G4PhysicsLnVector object directly and
|
||||
// not through pointers or references. In this case, the 'inline' will
|
||||
// be invoked. (See R.B.Murray, "C++ Strategies and Tactics", Chap.6.6)
|
||||
|
||||
return size_t( std::log(theEnergy)/dBin - baseBin );
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4PhysicsLogVector.cc 74256 2013-10-02 14:24:02Z gcosmo $
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------
|
||||
@@ -41,10 +41,12 @@
|
||||
// 9 Mar. 2001, H.Kurashige : added PhysicsVector type and Retrieve
|
||||
// 05 Sep. 2008, V.Ivanchenko : added protections for zero-length vector
|
||||
// 19 Jun. 2009, V.Ivanchenko : removed hidden bin
|
||||
// 02 Oct. 2013 V.Ivanchenko : Remove FindBinLocation method, use G4Log
|
||||
//
|
||||
// --------------------------------------------------------------
|
||||
|
||||
#include "G4PhysicsLogVector.hh"
|
||||
#include "G4Exp.hh"
|
||||
|
||||
G4PhysicsLogVector::G4PhysicsLogVector()
|
||||
: G4PhysicsVector()
|
||||
@@ -74,20 +76,19 @@ G4PhysicsLogVector::G4PhysicsLogVector(G4double theEmin,
|
||||
{
|
||||
type = T_G4PhysicsLogVector;
|
||||
|
||||
dBin = std::log10(theEmax/theEmin)/theNbin;
|
||||
baseBin = std::log10(theEmin)/dBin;
|
||||
dBin = G4Log(theEmax/theEmin)/theNbin;
|
||||
baseBin = G4Log(theEmin)/dBin;
|
||||
|
||||
numberOfNodes = theNbin + 1;
|
||||
dataVector.reserve(numberOfNodes);
|
||||
binVector.reserve(numberOfNodes);
|
||||
static const G4double g4log10 = std::log(10.);
|
||||
|
||||
binVector.push_back(theEmin);
|
||||
dataVector.push_back(0.0);
|
||||
|
||||
for (size_t i=1; i<numberOfNodes-1; i++)
|
||||
{
|
||||
binVector.push_back(std::exp(g4log10*(baseBin+i)*dBin));
|
||||
binVector.push_back(G4Exp((baseBin+i)*dBin));
|
||||
dataVector.push_back(0.0);
|
||||
}
|
||||
binVector.push_back(theEmax);
|
||||
@@ -107,8 +108,8 @@ G4bool G4PhysicsLogVector::Retrieve(std::ifstream& fIn, G4bool ascii)
|
||||
if (success)
|
||||
{
|
||||
G4double theEmin = binVector[0];
|
||||
dBin = std::log10(binVector[1]/theEmin);
|
||||
baseBin = std::log10(theEmin)/dBin;
|
||||
dBin = G4Log(binVector[1]/theEmin);
|
||||
baseBin = G4Log(theEmin)/dBin;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
@@ -117,23 +118,6 @@ void G4PhysicsLogVector::ScaleVector(G4double factorE, G4double factorV)
|
||||
{
|
||||
G4PhysicsVector::ScaleVector(factorE, factorV);
|
||||
G4double theEmin = binVector[0];
|
||||
dBin = std::log10(binVector[1]/theEmin);
|
||||
baseBin = std::log10(theEmin)/dBin;
|
||||
dBin = G4Log(binVector[1]/theEmin);
|
||||
baseBin = G4Log(theEmin)/dBin;
|
||||
}
|
||||
|
||||
size_t G4PhysicsLogVector::FindBinLocation(G4double theEnergy) const
|
||||
{
|
||||
// For G4PhysicsLogVector, FindBinLocation is implemented using
|
||||
// a simple arithmetic calculation.
|
||||
//
|
||||
// Because this is a virtual function, it is accessed through a
|
||||
// pointer to the G4PhyiscsVector object for most usages. In this
|
||||
// case, 'inline' will not be invoked. However, there is a possibility
|
||||
// that the user access to the G4PhysicsLogVector object directly and
|
||||
// not through pointers or references. In this case, the 'inline' will
|
||||
// be invoked. (See R.B.Murray, "C++ Strategies and Tactics", Chap.6.6)
|
||||
//G4cout << "G4PhysicsLogVector::FindBinLocation: e= " << theEnergy
|
||||
|
||||
return size_t( std::log10(theEnergy)/dBin - baseBin );
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4ios.cc 70004 2013-05-21 16:28:30Z adotti $
|
||||
//
|
||||
|
||||
#include "G4PhysicsModelCatalog.hh"
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
#include "G4Threading.hh"
|
||||
#endif
|
||||
|
||||
modelCatalog* G4PhysicsModelCatalog::catalog = 0;
|
||||
|
||||
G4PhysicsModelCatalog::G4PhysicsModelCatalog()
|
||||
{ catalog = new modelCatalog; }
|
||||
|
||||
G4PhysicsModelCatalog::~G4PhysicsModelCatalog()
|
||||
{ delete catalog; catalog = 0; }
|
||||
|
||||
G4int G4PhysicsModelCatalog::Register(G4String& name)
|
||||
{
|
||||
G4int idx = GetIndex(name);
|
||||
if(idx>=0) return idx;
|
||||
#ifdef G4MULTITHREADED
|
||||
if(G4Threading::IsWorkerThread()) return -1;
|
||||
#endif
|
||||
catalog->push_back(name);
|
||||
return catalog->size()-1;
|
||||
}
|
||||
|
||||
G4String& G4PhysicsModelCatalog::GetModelName(G4int idx)
|
||||
{
|
||||
static G4String undef = "Undefined";
|
||||
if(!catalog) new G4PhysicsModelCatalog;
|
||||
if(idx>=0 && idx<Entries()) return (*catalog)[idx];
|
||||
return undef;
|
||||
}
|
||||
|
||||
G4int G4PhysicsModelCatalog::GetIndex(G4String& name)
|
||||
{
|
||||
if(!catalog) new G4PhysicsModelCatalog;
|
||||
for(G4int idx=0;idx<Entries();idx++)
|
||||
{ if((*catalog)[idx]==name) return idx; }
|
||||
return -1;
|
||||
}
|
||||
|
||||
G4int G4PhysicsModelCatalog::Entries()
|
||||
{ return (catalog) ? G4int(catalog->size()) : -1; }
|
||||
|
||||
void G4PhysicsModelCatalog::Destroy()
|
||||
{
|
||||
#ifdef G4MULTITHREADED
|
||||
if(G4Threading::IsWorkerThread()) return;
|
||||
#endif
|
||||
if(catalog) delete catalog;
|
||||
catalog = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4PhysicsOrderedFreeVector.cc 74256 2013-10-02 14:24:02Z gcosmo $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// PhysicsOrderedFreeVector Class Implementation
|
||||
@@ -41,8 +41,9 @@
|
||||
// derived class constructors
|
||||
// 2000-11-11 by H.Kurashige
|
||||
// > use STL vector for dataVector and binVector
|
||||
// 19 Jun. 2009-06-19 by V.Ivanchenko
|
||||
// 2009-06-19 by V.Ivanchenko
|
||||
// > removed hidden bin
|
||||
// 2013-10-02 by V.Ivanchenko removed FindBinLocation
|
||||
//
|
||||
// mail: gum@triumf.ca
|
||||
//
|
||||
@@ -104,11 +105,6 @@ void G4PhysicsOrderedFreeVector::InsertValues(G4double energy, G4double value)
|
||||
edgeMax = binVector.back();
|
||||
}
|
||||
|
||||
G4double G4PhysicsOrderedFreeVector::GetLowEdgeEnergy(size_t binNumber) const
|
||||
{
|
||||
return binVector[binNumber];
|
||||
}
|
||||
|
||||
G4double G4PhysicsOrderedFreeVector::GetEnergy(G4double aValue)
|
||||
{
|
||||
|
||||
@@ -149,19 +145,3 @@ G4double G4PhysicsOrderedFreeVector::LinearInterpolationOfEnergy(G4double aValue
|
||||
( binVector[theLocBin+1]-binVector[theLocBin] ) * intplFactor;
|
||||
}
|
||||
|
||||
|
||||
size_t G4PhysicsOrderedFreeVector::FindBinLocation(G4double theEnergy) const
|
||||
{
|
||||
G4int n1 = 0;
|
||||
G4int n2 = numberOfNodes/2;
|
||||
G4int n3 = numberOfNodes - 1;
|
||||
while (n1 != n3 - 1)
|
||||
{
|
||||
if (theEnergy > binVector[n2])
|
||||
{ n1 = n2; }
|
||||
else
|
||||
{ n3 = n2; }
|
||||
n2 = n1 + (n3 - n1 + 1)/2;
|
||||
}
|
||||
return (size_t)n1;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4PhysicsTable.cc 67970 2013-03-13 10:10:06Z gcosmo $
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4PhysicsVector.cc 74256 2013-10-02 14:24:02Z gcosmo $
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------
|
||||
@@ -53,35 +53,36 @@
|
||||
// 16 Aug. 2011 H.Kurashige : Add dBin, baseBin and verboseLevel
|
||||
// --------------------------------------------------------------
|
||||
|
||||
#include "G4PhysicsVector.hh"
|
||||
#include <iomanip>
|
||||
#include "G4PhysicsVector.hh"
|
||||
|
||||
G4Allocator<G4PhysicsVector> aPVAllocator;
|
||||
G4ThreadLocal G4Allocator<G4PhysicsVector> *fpPVAllocator = 0;
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
G4PhysicsVector::G4PhysicsVector(G4bool spline)
|
||||
G4PhysicsVector::G4PhysicsVector(G4bool)
|
||||
: type(T_G4PhysicsVector),
|
||||
edgeMin(0.), edgeMax(0.), numberOfNodes(0),
|
||||
useSpline(spline),
|
||||
useSpline(false),
|
||||
dBin(0.), baseBin(0.),
|
||||
verboseLevel(0)
|
||||
{
|
||||
cache = new G4PhysicsVectorCache();
|
||||
if (!fpPVAllocator) fpPVAllocator = new G4Allocator<G4PhysicsVector>;
|
||||
// g4pow = G4Pow::GetInstance();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
G4PhysicsVector::~G4PhysicsVector()
|
||||
{
|
||||
delete cache; cache =0;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
G4PhysicsVector::G4PhysicsVector(const G4PhysicsVector& right)
|
||||
{
|
||||
cache = new G4PhysicsVectorCache();
|
||||
// g4pow = G4Pow::GetInstance();
|
||||
|
||||
dBin = right.dBin;
|
||||
baseBin = right.baseBin;
|
||||
verboseLevel = right.verboseLevel;
|
||||
@@ -122,6 +123,7 @@ G4int G4PhysicsVector::operator!=(const G4PhysicsVector &right) const
|
||||
|
||||
void G4PhysicsVector::DeleteData()
|
||||
{
|
||||
useSpline = false;
|
||||
secDerivative.clear();
|
||||
}
|
||||
|
||||
@@ -133,9 +135,6 @@ void G4PhysicsVector::CopyData(const G4PhysicsVector& vec)
|
||||
edgeMin = vec.edgeMin;
|
||||
edgeMax = vec.edgeMax;
|
||||
numberOfNodes = vec.numberOfNodes;
|
||||
cache->lastEnergy = vec.GetLastEnergy();
|
||||
cache->lastValue = vec.GetLastValue();
|
||||
cache->lastBin = vec.GetLastBin();
|
||||
useSpline = vec.useSpline;
|
||||
|
||||
size_t i;
|
||||
@@ -198,9 +197,6 @@ G4bool G4PhysicsVector::Store(std::ofstream& fOut, G4bool ascii)
|
||||
G4bool G4PhysicsVector::Retrieve(std::ifstream& fIn, G4bool ascii)
|
||||
{
|
||||
// clear properties;
|
||||
cache->lastEnergy=-DBL_MAX;
|
||||
cache->lastValue =0.;
|
||||
cache->lastBin =0;
|
||||
dataVector.clear();
|
||||
binVector.clear();
|
||||
secDerivative.clear();
|
||||
@@ -298,8 +294,6 @@ G4PhysicsVector::ScaleVector(G4double factorE, G4double factorV)
|
||||
|
||||
edgeMin *= factorE;
|
||||
edgeMax *= factorE;
|
||||
cache->lastEnergy = factorE*(cache->lastEnergy);
|
||||
cache->lastValue = factorV*(cache->lastValue);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
@@ -320,6 +314,8 @@ G4PhysicsVector::ComputeSecondDerivatives(G4double firstPointDerivative,
|
||||
|
||||
if(!SplinePossible()) { return; }
|
||||
|
||||
useSpline = true;
|
||||
|
||||
G4int n = numberOfNodes-1;
|
||||
|
||||
G4double* u = new G4double [n];
|
||||
@@ -372,7 +368,7 @@ void G4PhysicsVector::FillSecondDerivatives()
|
||||
// Computation of second derivatives using "Not-a-knot" endpoint conditions
|
||||
// B.I. Kvasov "Methods of shape-preserving spline approximation"
|
||||
// World Scientific, 2000
|
||||
{
|
||||
{
|
||||
if(5 > numberOfNodes) // cannot compute derivatives for less than 4 points
|
||||
{
|
||||
ComputeSecDerivatives();
|
||||
@@ -380,6 +376,8 @@ void G4PhysicsVector::FillSecondDerivatives()
|
||||
}
|
||||
|
||||
if(!SplinePossible()) { return; }
|
||||
|
||||
useSpline = true;
|
||||
|
||||
G4int n = numberOfNodes-1;
|
||||
|
||||
@@ -441,14 +439,16 @@ void
|
||||
G4PhysicsVector::ComputeSecDerivatives()
|
||||
// A simplified method of computation of second derivatives
|
||||
{
|
||||
if(!SplinePossible()) { return; }
|
||||
|
||||
if(3 > numberOfNodes) // cannot compute derivatives for less than 4 bins
|
||||
{
|
||||
useSpline = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if(!SplinePossible()) { return; }
|
||||
|
||||
useSpline = true;
|
||||
|
||||
size_t n = numberOfNodes-1;
|
||||
|
||||
for(size_t i=1; i<n; ++i)
|
||||
@@ -468,18 +468,22 @@ G4bool G4PhysicsVector::SplinePossible()
|
||||
// Initialise second derivative array. If neighbor energy coincide
|
||||
// or not ordered than spline cannot be applied
|
||||
{
|
||||
G4bool result = true;
|
||||
secDerivative.clear();
|
||||
if(!useSpline) { return useSpline; }
|
||||
secDerivative.reserve(numberOfNodes);
|
||||
for(size_t j=0; j<numberOfNodes; ++j)
|
||||
{
|
||||
secDerivative.push_back(0.0);
|
||||
if(j > 0)
|
||||
{
|
||||
if(binVector[j]-binVector[j-1] <= 0.) { useSpline = false; }
|
||||
if(binVector[j]-binVector[j-1] <= 0.) {
|
||||
result = false;
|
||||
secDerivative.clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return useSpline;
|
||||
return result;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
@@ -503,31 +507,46 @@ std::ostream& operator<<(std::ostream& out, const G4PhysicsVector& pv)
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
void G4PhysicsVector::ComputeValue(G4double theEnergy)
|
||||
G4double
|
||||
G4PhysicsVector::Value(G4double theEnergy, size_t& lastIdx) const
|
||||
{
|
||||
// Use cache for speed up - check if the value 'theEnergy' lies
|
||||
// between the last energy and low edge of of the
|
||||
// bin of last call, then the last bin location is used.
|
||||
|
||||
if( theEnergy < cache->lastEnergy
|
||||
&& theEnergy >= binVector[cache->lastBin]) {
|
||||
cache->lastEnergy = theEnergy;
|
||||
Interpolation(cache->lastBin);
|
||||
|
||||
} else if( theEnergy <= edgeMin ) {
|
||||
cache->lastBin = 0;
|
||||
cache->lastEnergy = edgeMin;
|
||||
cache->lastValue = dataVector[0];
|
||||
|
||||
} else if( theEnergy >= edgeMax ) {
|
||||
cache->lastBin = numberOfNodes-1;
|
||||
cache->lastEnergy = edgeMax;
|
||||
cache->lastValue = dataVector[cache->lastBin];
|
||||
|
||||
G4double y;
|
||||
if(theEnergy <= edgeMin) {
|
||||
lastIdx = 0;
|
||||
y = dataVector[0];
|
||||
} else if(theEnergy >= edgeMax) {
|
||||
lastIdx = numberOfNodes-1;
|
||||
y = dataVector[lastIdx];
|
||||
} else {
|
||||
cache->lastBin = FindBinLocation(theEnergy);
|
||||
cache->lastEnergy = theEnergy;
|
||||
Interpolation(cache->lastBin);
|
||||
lastIdx = FindBin(theEnergy, lastIdx);
|
||||
y = Interpolation(lastIdx, theEnergy);
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
G4double G4PhysicsVector::FindLinearEnergy(G4double rand) const
|
||||
{
|
||||
if(1 >= numberOfNodes) { return 0.0; }
|
||||
size_t n1 = 0;
|
||||
size_t n2 = numberOfNodes/2;
|
||||
size_t n3 = numberOfNodes - 1;
|
||||
G4double y = rand*dataVector[n3];
|
||||
while (n1 + 1 != n3)
|
||||
{
|
||||
if (y > dataVector[n2])
|
||||
{ n1 = n2; }
|
||||
else
|
||||
{ n3 = n2; }
|
||||
n2 = (n3 + n1 + 1)/2;
|
||||
}
|
||||
G4double res = binVector[n1];
|
||||
G4double del = dataVector[n3] - dataVector[n1];
|
||||
if(del > 0.0) {
|
||||
res += (y - dataVector[n1])*(binVector[n3] - res)/del;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4Pow.cc 74256 2013-10-02 14:24:02Z gcosmo $
|
||||
//
|
||||
// -------------------------------------------------------------------
|
||||
//
|
||||
@@ -38,50 +38,75 @@
|
||||
//
|
||||
// Modifications:
|
||||
// 08.01.2011 V.Ivanchenko extended maxZ from 256 to 512
|
||||
// 02.05.2013 V.Ivanchenko added expA and logX methods,
|
||||
// revised A13, logA, powZ, powA to improved accuracy
|
||||
//
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
#include "G4Pow.hh"
|
||||
#include "G4Threading.hh"
|
||||
|
||||
G4Pow* G4Pow::fInstance = 0;
|
||||
G4Pow* G4Pow::fpInstance = 0;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
G4Pow* G4Pow::GetInstance()
|
||||
{
|
||||
if (fInstance == 0)
|
||||
if (fpInstance == 0)
|
||||
{
|
||||
static G4Pow manager;
|
||||
fInstance = &manager;
|
||||
fpInstance = new G4Pow;
|
||||
}
|
||||
return fInstance;
|
||||
return fpInstance;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
G4Pow::G4Pow()
|
||||
: onethird(1.0/3.0), max2(5)
|
||||
{
|
||||
if(G4Threading::IsWorkerThread() == true) {
|
||||
G4Exception ("G4Pow::G4Pow()", "glob090", FatalException,
|
||||
"Attempt to instantiate G4Pow in worker thread");
|
||||
}
|
||||
|
||||
const G4int maxZ = 512;
|
||||
const G4int maxZfact = 170;
|
||||
|
||||
maxA = -0.6 + maxZ;
|
||||
maxA2 = 1.25 + max2*0.2;
|
||||
maxAexp = -0.76+ maxZfact*0.5;
|
||||
|
||||
ener.resize(max2+1,1.0);
|
||||
logen.resize(max2+1,0.0);
|
||||
lz2.resize(max2+1,0.0);
|
||||
pz13.resize(maxZ,0.0);
|
||||
lz.resize(maxZ,0.0);
|
||||
fexp.resize(maxZfact,0.0);
|
||||
fact.resize(maxZfact,0.0);
|
||||
logfact.resize(maxZ,0.0);
|
||||
|
||||
onethird = 1.0/3.0;
|
||||
G4double f = 1.0;
|
||||
G4double logf = 0.0;
|
||||
fact[0] = 1.0;
|
||||
fexp[0] = 1.0;
|
||||
|
||||
for(G4int i=1; i<=max2; ++i)
|
||||
{
|
||||
ener[i] = powN(500.,i);
|
||||
logen[i]= G4Log(ener[i]);
|
||||
lz2[i] = G4Log(1.0 + i*0.2);
|
||||
}
|
||||
|
||||
for(G4int i=1; i<maxZ; ++i)
|
||||
{
|
||||
G4double x = G4double(i);
|
||||
pz13[i] = std::pow(x,onethird);
|
||||
lz[i] = std::log(x);
|
||||
if(i < maxZfact) {
|
||||
lz[i] = G4Log(x);
|
||||
if(i < maxZfact)
|
||||
{
|
||||
f *= x;
|
||||
fact[i] = f;
|
||||
fexp[i] = G4Exp(0.5*i);
|
||||
}
|
||||
logf += lz[i];
|
||||
logfact[i] = logf;
|
||||
@@ -91,11 +116,13 @@ G4Pow::G4Pow()
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
G4Pow::~G4Pow()
|
||||
{}
|
||||
{
|
||||
delete fpInstance; fpInstance = 0;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
G4double G4Pow::powN(G4double x, G4int n)
|
||||
G4double G4Pow::powN(G4double x, G4int n) const
|
||||
{
|
||||
if(std::abs(n) > 8) { return std::pow(x, G4double(n)); }
|
||||
G4double res = 1.0;
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id:$
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
//
|
||||
// -------------------------------------------------------------------
|
||||
//
|
||||
@@ -38,5 +37,5 @@
|
||||
#include "G4Types.hh"
|
||||
#include "G4ReferenceCountedHandle.hh"
|
||||
|
||||
G4Allocator<G4CountedObject<void> > aCountedObjectAllocator;
|
||||
G4Allocator<G4ReferenceCountedHandle<void> > aRCHAllocator;
|
||||
G4ThreadLocal G4Allocator<G4CountedObject<void> > *aCountedObjectAllocator = 0;
|
||||
G4ThreadLocal G4Allocator<G4ReferenceCountedHandle<void> > *aRCHAllocator = 0;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4SliceTimer.cc 67970 2013-03-13 10:10:06Z gcosmo $
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4StateManager.cc 67970 2013-03-13 10:10:06Z gcosmo $
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
@@ -35,10 +35,11 @@
|
||||
// ------------------------------------------------------------
|
||||
|
||||
#include "G4StateManager.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
// Initialization of the static pointer of the single class instance
|
||||
//
|
||||
G4StateManager* G4StateManager::theStateManager = 0;
|
||||
G4ThreadLocal G4StateManager* G4StateManager::theStateManager = 0;
|
||||
|
||||
G4StateManager::G4StateManager()
|
||||
: theCurrentState(G4State_PreInit),
|
||||
@@ -48,6 +49,9 @@ G4StateManager::G4StateManager()
|
||||
msgptr(0),
|
||||
exceptionHandler(0)
|
||||
{
|
||||
#ifdef G4MULTITHREADED
|
||||
G4iosInitialization();
|
||||
#endif
|
||||
}
|
||||
|
||||
G4StateManager::~G4StateManager()
|
||||
@@ -72,6 +76,9 @@ G4StateManager::~G4StateManager()
|
||||
}
|
||||
if ( state ) { delete state; }
|
||||
}
|
||||
#ifdef G4MULTITHREADED_DEACTIVATE
|
||||
G4iosFinalization();
|
||||
#endif
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id:$
|
||||
//
|
||||
// --------------------------------------------------------------
|
||||
// GEANT 4 class implementation file
|
||||
//
|
||||
// G4Threading.cc
|
||||
//
|
||||
// ---------------------------------------------------------------
|
||||
// Author: Andrea Dotti (15 Feb 2013): First Implementation
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
#include "G4Threading.hh"
|
||||
#if defined (WIN32)
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/syscall.h>
|
||||
#endif
|
||||
|
||||
#if defined(G4MULTITHREADED)
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace {
|
||||
G4ThreadLocal G4int G4ThreadID = -1;
|
||||
}
|
||||
|
||||
G4Pid_t G4Threading::G4GetPidId()
|
||||
{ // In multithreaded mode return Thread ID
|
||||
#if defined(__MACH__)
|
||||
return syscall(SYS_thread_selfid);
|
||||
#elif defined(WIN32)
|
||||
return GetCurrentThreadId();
|
||||
#else
|
||||
return syscall(SYS_gettid);
|
||||
#endif
|
||||
}
|
||||
|
||||
G4int G4Threading::G4GetNumberOfCores()
|
||||
{
|
||||
#if defined(WIN32)
|
||||
SYSTEM_INFO sysinfo;
|
||||
GetSystemInfo( &sysinfo );
|
||||
return static_cast<G4int>( sysinfo.dwNumberOfProcessors );
|
||||
#else
|
||||
return static_cast<G4int>(sysconf( _SC_NPROCESSORS_ONLN ));
|
||||
#endif
|
||||
}
|
||||
|
||||
void G4Threading::G4SetThreadId(G4int value ) { G4ThreadID = value; }
|
||||
G4int G4Threading::G4GetThreadId() { return G4ThreadID; }
|
||||
G4bool G4Threading::IsWorkerThread() { return (G4ThreadID>=0); }
|
||||
|
||||
#if defined(WIN32) // WIN32 stuff needed for MT
|
||||
DWORD /*WINAPI*/ G4WaitForSingleObjectInf( __in G4Mutex m )
|
||||
{ return WaitForSingleObject( m , INFINITE); }
|
||||
BOOL G4ReleaseMutex( __in G4Mutex m)
|
||||
{ return ReleaseMutex(m); }
|
||||
#endif
|
||||
|
||||
#else // Sequential mode
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
G4int fake_mutex_lock_unlock( G4Mutex* ) { return 0; }
|
||||
|
||||
G4Pid_t G4Threading::G4GetPidId() // In sequential mode return Process ID and not Thread ID
|
||||
{
|
||||
#if defined(WIN32)
|
||||
return GetCurrentProcessId();
|
||||
#else
|
||||
return getpid();
|
||||
#endif
|
||||
}
|
||||
|
||||
G4int G4Threading::G4GetNumberOfCores() { return 1; }
|
||||
G4int G4Threading::G4GetThreadId() { return -2; }
|
||||
G4bool G4Threading::IsWorkerThread() { return false; }
|
||||
void G4Threading::G4SetThreadId(G4int) {}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4Timer.cc 67970 2013-03-13 10:10:06Z gcosmo $
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4UnitsTable.cc 67970 2013-03-13 10:10:06Z gcosmo $
|
||||
//
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//
|
||||
@@ -52,7 +52,7 @@
|
||||
#include "G4UnitsTable.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
|
||||
G4UnitsTable G4UnitDefinition::theUnitsTable;
|
||||
G4ThreadLocal G4UnitsTable *G4UnitDefinition::pUnitsTable = 0;
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
@@ -61,29 +61,32 @@ G4UnitDefinition::G4UnitDefinition(const G4String& name,
|
||||
const G4String& category, G4double value)
|
||||
: Name(name),SymbolName(symbol),Value(value)
|
||||
{
|
||||
if (!pUnitsTable) { pUnitsTable = new G4UnitsTable; }
|
||||
|
||||
// Does the Category objet already exist ?
|
||||
//
|
||||
size_t nbCat = theUnitsTable.size();
|
||||
size_t nbCat = pUnitsTable->size();
|
||||
size_t i = 0;
|
||||
while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) { i++; }
|
||||
while ((i<nbCat)&&((*pUnitsTable)[i]->GetName()!=category)) { i++; }
|
||||
if (i == nbCat)
|
||||
{ theUnitsTable.push_back( new G4UnitsCategory(category)); }
|
||||
{ pUnitsTable->push_back( new G4UnitsCategory(category)); }
|
||||
CategoryIndex = i;
|
||||
|
||||
// Insert this Unit in the Units table
|
||||
//
|
||||
(theUnitsTable[CategoryIndex]->GetUnitsList()).push_back(this);
|
||||
((*pUnitsTable)[CategoryIndex]->GetUnitsList()).push_back(this);
|
||||
|
||||
// Update string max length for name and symbol
|
||||
//
|
||||
theUnitsTable[i]->UpdateNameMxLen((G4int)name.length());
|
||||
theUnitsTable[i]->UpdateSymbMxLen((G4int)symbol.length());
|
||||
(*pUnitsTable)[i]->UpdateNameMxLen((G4int)name.length());
|
||||
(*pUnitsTable)[i]->UpdateSymbMxLen((G4int)symbol.length());
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
G4UnitDefinition::~G4UnitDefinition()
|
||||
{
|
||||
if (!pUnitsTable) { delete pUnitsTable; pUnitsTable = 0; }
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -125,8 +128,9 @@ G4int G4UnitDefinition::operator!=(const G4UnitDefinition &right) const
|
||||
|
||||
G4UnitsTable& G4UnitDefinition::GetUnitsTable()
|
||||
{
|
||||
if(theUnitsTable.size()==0) { BuildUnitsTable(); }
|
||||
return theUnitsTable;
|
||||
if (!pUnitsTable) { pUnitsTable = new G4UnitsTable; }
|
||||
if(pUnitsTable->size()==0) { BuildUnitsTable(); }
|
||||
return *pUnitsTable;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -136,7 +140,7 @@ G4double G4UnitDefinition::GetValueOf(const G4String& str)
|
||||
G4String name,symbol;
|
||||
for (size_t i=0;i<(GetUnitsTable()).size();i++)
|
||||
{
|
||||
G4UnitsContainer& units = theUnitsTable[i]->GetUnitsList();
|
||||
G4UnitsContainer& units = (*pUnitsTable)[i]->GetUnitsList();
|
||||
for (size_t j=0;j<units.size();j++)
|
||||
{
|
||||
name=units[j]->GetName(); symbol=units[j]->GetSymbol();
|
||||
@@ -158,12 +162,12 @@ G4String G4UnitDefinition::GetCategory(const G4String& str)
|
||||
G4String name,symbol;
|
||||
for (size_t i=0;i<(GetUnitsTable()).size();i++)
|
||||
{
|
||||
G4UnitsContainer& units = theUnitsTable[i]->GetUnitsList();
|
||||
G4UnitsContainer& units = (*pUnitsTable)[i]->GetUnitsList();
|
||||
for (size_t j=0;j<units.size();j++)
|
||||
{
|
||||
name=units[j]->GetName(); symbol=units[j]->GetSymbol();
|
||||
if(str==name||str==symbol)
|
||||
{ return theUnitsTable[i]->GetName(); }
|
||||
{ return (*pUnitsTable)[i]->GetName(); }
|
||||
}
|
||||
}
|
||||
std::ostringstream message;
|
||||
@@ -178,8 +182,8 @@ G4String G4UnitDefinition::GetCategory(const G4String& str)
|
||||
|
||||
void G4UnitDefinition::PrintDefinition()
|
||||
{
|
||||
G4int nameL = theUnitsTable[CategoryIndex]->GetNameMxLen();
|
||||
G4int symbL = theUnitsTable[CategoryIndex]->GetSymbMxLen();
|
||||
G4int nameL = (*pUnitsTable)[CategoryIndex]->GetNameMxLen();
|
||||
G4int symbL = (*pUnitsTable)[CategoryIndex]->GetSymbMxLen();
|
||||
G4cout << std::setw(nameL) << Name << " ("
|
||||
<< std::setw(symbL) << SymbolName << ") = " << Value << G4endl;
|
||||
}
|
||||
@@ -332,9 +336,10 @@ void G4UnitDefinition::BuildUnitsTable()
|
||||
void G4UnitDefinition::PrintUnitsTable()
|
||||
{
|
||||
G4cout << "\n ----- The Table of Units ----- \n";
|
||||
for(size_t i=0;i<theUnitsTable.size();i++)
|
||||
if (!pUnitsTable) { pUnitsTable = new G4UnitsTable; }
|
||||
for(size_t i=0;i<pUnitsTable->size();i++)
|
||||
{
|
||||
theUnitsTable[i]->PrintCategory();
|
||||
(*pUnitsTable)[i]->PrintCategory();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,11 +347,12 @@ void G4UnitDefinition::PrintUnitsTable()
|
||||
|
||||
void G4UnitDefinition::ClearUnitsTable()
|
||||
{
|
||||
for (size_t i=0;i<theUnitsTable.size();i++)
|
||||
if (!pUnitsTable) { pUnitsTable = new G4UnitsTable; }
|
||||
for (size_t i=0;i<pUnitsTable->size();i++)
|
||||
{
|
||||
delete theUnitsTable[i];
|
||||
delete (*pUnitsTable)[i];
|
||||
}
|
||||
theUnitsTable.clear();
|
||||
pUnitsTable->clear();
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4VExceptionHandler.cc 67970 2013-03-13 10:10:06Z gcosmo $
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4VNotifier.cc 67970 2013-03-13 10:10:06Z gcosmo $
|
||||
//
|
||||
// G4VNotifier
|
||||
//
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4VStateDependent.cc 67970 2013-03-13 10:10:06Z gcosmo $
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4coutDestination.cc 67970 2013-03-13 10:10:06Z gcosmo $
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id$
|
||||
// $Id: G4ios.cc 70021 2013-05-22 07:55:29Z gcosmo $
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------
|
||||
@@ -37,10 +37,40 @@
|
||||
#include "G4ios.hh"
|
||||
#include "G4strstreambuf.hh"
|
||||
|
||||
G4strstreambuf G4coutbuf;
|
||||
G4strstreambuf G4cerrbuf;
|
||||
std::ostream G4cout(&G4coutbuf);
|
||||
std::ostream G4cerr(&G4cerrbuf);
|
||||
#ifdef G4MULTITHREADED
|
||||
G4ThreadLocal G4strstreambuf *G4coutbuf_p = 0;
|
||||
G4ThreadLocal G4strstreambuf *G4cerrbuf_p = 0;
|
||||
G4ThreadLocal std::ostream *G4cout_p = 0;
|
||||
G4ThreadLocal std::ostream *G4cerr_p = 0;
|
||||
#define G4coutbuf (*G4coutbuf_p)
|
||||
#define G4cerrbuf (*G4cerrbuf_p)
|
||||
#define G4cout (*G4cout_p)
|
||||
#define G4cerr (*G4cerr_p)
|
||||
|
||||
void G4iosInitialization()
|
||||
{
|
||||
if (G4coutbuf_p == 0) G4coutbuf_p = new G4strstreambuf;
|
||||
if (G4cerrbuf_p == 0) G4cerrbuf_p = new G4strstreambuf;
|
||||
if (G4cout_p == 0) G4cout_p = new std::ostream(G4coutbuf_p);
|
||||
if (G4cerr_p == 0) G4cerr_p = new std::ostream(G4cerrbuf_p);
|
||||
}
|
||||
|
||||
void G4iosFinalization()
|
||||
{
|
||||
delete G4cout_p;
|
||||
delete G4cerr_p;
|
||||
delete G4coutbuf_p;
|
||||
delete G4cerrbuf_p;
|
||||
}
|
||||
|
||||
#else // Sequential
|
||||
|
||||
G4strstreambuf G4coutbuf;
|
||||
G4strstreambuf G4cerrbuf;
|
||||
std::ostream G4cout(&G4coutbuf);
|
||||
std::ostream G4cerr(&G4cerrbuf);
|
||||
|
||||
void G4iosInitialization() {}
|
||||
void G4iosFinalization() {}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4coutDestination.hh 66241 2014-05-16 00:00:42Z adotti $
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------------
|
||||
// GEANT 4 class cc file
|
||||
//
|
||||
// G4ofstreamDestination.cc
|
||||
//
|
||||
// ---------------------------------------------------------------
|
||||
#include "G4strstreambuf.hh"
|
||||
#include "G4ofstreamDestination.hh"
|
||||
#include <ios>
|
||||
|
||||
//TODO: make this that can be only cout / only cerr or both with a parameter,
|
||||
// default is both
|
||||
G4ofstreamDestinationBase::G4ofstreamDestinationBase(const G4String& fn ,
|
||||
G4bool append)
|
||||
: G4coutDestination(),
|
||||
fileName(fn),
|
||||
appendFlag(append)
|
||||
{
|
||||
}
|
||||
|
||||
G4ofstreamDestinationBase::~G4ofstreamDestinationBase()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
void G4ofstreamDestinationBase::SetFileName(const G4String& fn , G4bool append )
|
||||
{
|
||||
fileName = fn;
|
||||
appendFlag = append;
|
||||
}
|
||||
|
||||
void G4ofstreamDestinationBase::Open()
|
||||
{
|
||||
if ( ! g4file.is_open() )
|
||||
{
|
||||
std::ios::openmode mode = std::ios::out;
|
||||
if ( appendFlag )
|
||||
mode |= std::ios::app;
|
||||
g4file.open(fileName,mode);
|
||||
}
|
||||
}
|
||||
|
||||
void G4ofstreamDestinationBase::Close()
|
||||
{
|
||||
if ( g4file.is_open() )
|
||||
g4file.close();
|
||||
}
|
||||
|
||||
|
||||
//========================
|
||||
//Concrete implementations
|
||||
//========================
|
||||
G4CoutToFile::G4CoutToFile(const G4String& defaultName , G4bool append) :
|
||||
G4ofstreamDestinationBase(defaultName,append)
|
||||
{
|
||||
G4coutbuf.SetDestination(this);
|
||||
}
|
||||
|
||||
G4int G4CoutToFile::ReceiveG4cout(const G4String& msg)
|
||||
{
|
||||
if ( ! g4file.is_open() ) Open();
|
||||
g4file<<msg<<std::flush;
|
||||
return 0;
|
||||
}
|
||||
|
||||
G4CerrToFile::G4CerrToFile(const G4String& defaultName, G4bool append) :
|
||||
G4ofstreamDestinationBase(defaultName,append)
|
||||
{
|
||||
G4cerrbuf.SetDestination(this);
|
||||
}
|
||||
|
||||
G4int G4CerrToFile::ReceiveG4cerr(const G4String& msg)
|
||||
{
|
||||
if ( !g4file.is_open() ) Open();
|
||||
g4file<<msg<<std::flush;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user