Import Geant4 10.5.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2018-06-29 10:58:11 +02:00
parent fe81a77428
commit 6aa23be517
1581 changed files with 124288 additions and 83758 deletions
@@ -28,4 +28,10 @@
// Decalare needed static data member for fully specialized version of cache
#include "G4CacheDetails.hh"
G4ThreadLocal std::vector<G4double>* G4CacheReference<G4double>::cache = 0;
G4CacheReference<G4double>::cache_container*&
G4CacheReference<G4double>::cache()
{
G4ThreadLocalStatic std::vector<G4double>* _instance = nullptr;
return _instance;
}
+2 -95
View File
@@ -24,104 +24,11 @@
// ********************************************************************
//
//
// $Id: G4Exception.cc 67970 2013-03-13 10:10:06Z gcosmo $
// $Id: G4Exception.cc 110286 2018-05-18 09:40:01Z gcosmo $
//
//
// ----------------------------------------------------------------------
// G4Exception
//
// Global error function prints string to G4cerr (or G4cout in case of
// warning). May abort program according to severity.
// ----------------------------------------------------------------------
#include "G4ios.hh"
#include "G4String.hh"
#include "G4StateManager.hh"
void G4Exception(const char* originOfException,
const char* exceptionCode,
G4ExceptionSeverity severity,
const char* description)
{
G4VExceptionHandler* exceptionHandler
= G4StateManager::GetStateManager()->GetExceptionHandler();
G4bool toBeAborted = true;
if(exceptionHandler)
{
toBeAborted = exceptionHandler
->Notify(originOfException,exceptionCode,severity,description);
}
else
{
static const G4String es_banner
= "\n-------- EEEE ------- G4Exception-START -------- EEEE -------\n";
static const G4String ee_banner
= "\n-------- EEEE -------- G4Exception-END --------- EEEE -------\n";
static const G4String ws_banner
= "\n-------- WWWW ------- G4Exception-START -------- WWWW -------\n";
static const G4String we_banner
= "\n-------- WWWW -------- G4Exception-END --------- WWWW -------\n";
std::ostringstream message;
message << "\n*** ExceptionHandler is not defined ***\n"
<< "*** G4Exception : " << exceptionCode << G4endl
<< " issued by : " << originOfException << G4endl
<< description << G4endl;
switch(severity)
{
case FatalException:
G4cerr << es_banner << message.str() << "*** Fatal Exception ***"
<< ee_banner << G4endl;
break;
case FatalErrorInArgument:
G4cerr << es_banner << message.str() << "*** Fatal Error In Argument ***"
<< ee_banner << G4endl;
break;
case RunMustBeAborted:
G4cerr << es_banner << message.str() << "*** Run Must Be Aborted ***"
<< ee_banner << G4endl;
break;
case EventMustBeAborted:
G4cerr << es_banner << message.str() << "*** Event Must Be Aborted ***"
<< ee_banner << G4endl;
break;
default:
G4cout << ws_banner << message.str()
<< "*** This is just a warning message. ***"
<< we_banner << G4endl;
toBeAborted = false;
break;
}
}
if(toBeAborted)
{
if(G4StateManager::GetStateManager()->SetNewState(G4State_Abort))
{
G4cerr << G4endl << "*** G4Exception: Aborting execution ***" << G4endl;
abort();
}
else
{
G4cerr << G4endl << "*** G4Exception: Abortion suppressed ***"
<< G4endl << "*** No guarantee for further execution ***" << G4endl;
}
}
}
void G4Exception(const char* originOfException,
const char* exceptionCode,
G4ExceptionSeverity severity,
G4ExceptionDescription & description)
{
G4String des = description.str();
G4Exception(originOfException, exceptionCode, severity, des.c_str());
}
void G4Exception(const char* originOfException,
const char* exceptionCode,
G4ExceptionSeverity severity,
G4ExceptionDescription & description,
const char* comments)
{
description << comments << G4endl;
G4Exception(originOfException, exceptionCode, severity, description);
}
#include "G4Exception.hh"
+6 -34
View File
@@ -30,6 +30,8 @@
*
* Created on: Feb 10, 2016
* Author: adotti
* Updated on: Feb 9, 2018
* Author: jmadsen
*/
#include "G4MTBarrier.hh"
@@ -37,60 +39,30 @@
G4MTBarrier::G4MTBarrier(unsigned int numThreads ) :
m_numActiveThreads(numThreads),
m_counter(0),
m_mutex(G4MUTEX_INITIALIZER),
m_counterChanged(G4CONDITION_INITIALIZER),
m_continue(G4CONDITION_INITIALIZER)
{
#if defined(WIN32)
InitializeCriticalSection( &cs1 );
InitializeCriticalSection( &cs2 );
#endif
}
m_counter(0)
{}
void G4MTBarrier::ThisWorkerReady() {
//Step-1: Worker acquires lock on shared resource (the counter)
#ifndef WIN32
G4AutoLock lock(&m_mutex);
#else
EnterCriticalSection( &cs1 );
#endif
//Step-2: Worker increases counter
++m_counter;
//Step-3: Worker broadcasts that the counter has changed
G4CONDITIONBROADCAST(&m_counterChanged);
//Step-4: Worker waits on condition to continue
#ifndef WIN32
G4CONDITIONWAIT(&m_continue,&m_mutex);
#else
# ifdef G4MULTITHREADED
G4CONDITIONWAIT(&m_continue,&cs1);
# endif
LeaveCriticalSection(&cs1);
#endif
G4CONDITIONWAIT(&m_continue,&lock);
}
void G4MTBarrier::Wait() {
while (true)
{
//Step-2: Acquires lock on shared resource (the counter)
#ifndef WIN32
G4AutoLock lock(&m_mutex);
#else
EnterCriticalSection(&cs2);
#endif
//If the counter equals active threads, all threads are ready, exit the loop
if ( m_counter == m_numActiveThreads ) { break; }
//Step-3: Not all workers are ready, wait for the number to change
//before repeating the check
#ifdef WIN32
# ifdef G4MULTITHREADED
G4CONDITIONWAIT(&m_counterChanged,&cs2);
# endif
LeaveCriticalSection(&cs2);
#else
G4CONDITIONWAIT(&m_counterChanged,&m_mutex);
#endif
G4CONDITIONWAIT(&m_counterChanged,&lock);
}
}
+52 -3
View File
@@ -23,7 +23,7 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4Pow.cc 93311 2015-10-16 10:16:37Z gcosmo $
// $Id: G4Pow.cc 109086 2018-03-26 08:20:25Z gcosmo $
//
// -------------------------------------------------------------------
//
@@ -40,6 +40,8 @@
// 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
// 23.03.2018 M.Novak increased accuracy of A13 on the most critical
// [1/4,4] interval by introducing a denser(0.25) grid
//
// -------------------------------------------------------------------
@@ -74,17 +76,20 @@ G4Pow::G4Pow()
"Attempt to instantiate G4Pow in worker thread!");
}
#endif
const G4int maxZ = 512;
const G4int maxZ = 512;
const G4int maxZfact = 170;
const G4int numLowA = 17;
maxA = -0.6 + maxZ;
maxA2 = 1.25 + max2*0.2;
maxLowA = 4.0;
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);
lowa13.resize(numLowA,0.0);
lz.resize(maxZ,0.0);
fexp.resize(maxZfact,0.0);
fact.resize(maxZfact,0.0);
@@ -116,6 +121,11 @@ G4Pow::G4Pow()
logf += lz[i];
logfact[i] = logf;
}
for (G4int i=4; i<numLowA; ++i) {
lowa13[i] = std::pow(0.25*i,onethird);
}
}
// -------------------------------------------------------------------
@@ -125,6 +135,45 @@ G4Pow::~G4Pow()
// -------------------------------------------------------------------
G4double G4Pow::A13(G4double A) const {
G4double res = 0.;
if (A>0.) {
const bool invert = (A<1.);
const G4double a = invert ? 1./A : A;
res = (a<maxLowA) ? A13Low(a, invert) : A13High(a, invert);
}
return res;
}
// -------------------------------------------------------------------
G4double G4Pow::A13High(const G4double a, const bool invert) const {
G4double res;
if (a<maxA) {
const G4int i = static_cast<G4int>(a+0.5);
const G4double x = (a/i-1.)*onethird;
res = pz13[i]*(1.+x-x*x*(1.-1.666667*x));
} else {
res = G4Exp(G4Log(a)*onethird);
}
res = invert ? 1./res : res;
return res;
}
// -------------------------------------------------------------------
G4double G4Pow::A13Low(const G4double a, const bool invert) const {
G4double res;
const G4int i = static_cast<G4int>(4.*(a+0.125));
const G4double y = 0.25*i;
const G4double x = (a/y-1.)*onethird;
res = lowa13[i]*(1.+x-x*x*(1.-1.666667*x));
res = invert ? 1./res : res;
return res;
}
// -------------------------------------------------------------------
G4double G4Pow::powN(G4double x, G4int n) const
{
if(0.0 == x) { return 0.0; }
@@ -37,5 +37,15 @@
#include "G4Types.hh"
#include "G4ReferenceCountedHandle.hh"
G4ThreadLocal G4Allocator<G4CountedObject<void> > *aCountedObjectAllocator = 0;
G4ThreadLocal G4Allocator<G4ReferenceCountedHandle<void> > *aRCHAllocator = 0;
G4Allocator<G4CountedObject<void>>*& aCountedObjectAllocator()
{
G4ThreadLocalStatic G4Allocator<G4CountedObject<void>>* _instance = nullptr;
return _instance;
}
G4Allocator<G4ReferenceCountedHandle<void>>*& aRCHAllocator()
{
G4ThreadLocalStatic G4Allocator<G4ReferenceCountedHandle<void>>*
_instance = nullptr;
return _instance;
}
+1 -3
View File
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4SliceTimer.cc 67970 2013-03-13 10:10:06Z gcosmo $
// $Id: G4SliceTimer.cc 110674 2018-06-07 10:30:11Z gcosmo $
//
//
// ----------------------------------------------------------------------
@@ -36,8 +36,6 @@
#include "G4SliceTimer.hh"
#include "G4ios.hh"
#undef times
#if defined(IRIX6_2)
# if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE_EXTENDED==1)
# define __vfork vfork
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4StateManager.cc 108486 2018-02-15 14:47:25Z gcosmo $
// $Id: G4StateManager.cc 108402 2018-02-12 10:31:27Z gcosmo $
//
//
// ------------------------------------------------------------
+33 -49
View File
@@ -58,31 +58,14 @@ namespace
}
G4Pid_t G4Threading::G4GetPidId()
{ // In multithreaded mode return Thread ID
#if defined(__MACH__)
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
uint64_t tid64;
pthread_threadid_np(NULL, &tid64);
return (pid_t)tid64;
#else
return syscall(SYS_thread_selfid);
#endif
#elif defined(WIN32)
return GetCurrentThreadId();
#else
return syscall(SYS_gettid);
#endif
{
// In multithreaded mode return Thread ID
return std::this_thread::get_id();
}
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
return std::thread::hardware_concurrency();
}
void G4Threading::G4SetThreadId(G4int value ) { G4ThreadID = value; }
@@ -90,38 +73,40 @@ G4int G4Threading::G4GetThreadId() { return G4ThreadID; }
G4bool G4Threading::IsWorkerThread() { return (G4ThreadID>=0); }
G4bool G4Threading::IsMasterThread() { return (G4ThreadID==MASTER_ID); }
#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
#if defined(__linux__) || defined(_AIX)
G4bool G4Threading::G4SetPinAffinity(G4int cpu, G4Thread& aT)
G4bool G4Threading::G4SetPinAffinity(G4int cpu, G4NativeThread& aT)
{
cpu_set_t* aset = new cpu_set_t;
G4AutoDelete::Register(aset);
CPU_ZERO(aset);
CPU_SET(cpu,aset);
return ( pthread_setaffinity_np(aT, sizeof(cpu_set_t), aset) == 0 );
cpu_set_t* aset = new cpu_set_t;
G4AutoDelete::Register(aset);
CPU_ZERO(aset);
CPU_SET(cpu, aset);
pthread_t& _aT = (pthread_t&) (aT);
return (pthread_setaffinity_np(_aT, sizeof(cpu_set_t), aset) == 0);
}
#else //Not available for Mac, WIN,...
G4bool G4Threading::G4SetPinAffinity(G4int, G4Thread&)
G4bool G4Threading::G4SetPinAffinity(G4int, G4NativeThread&)
{
G4Exception("G4Threading::G4SetPinAffinity()",
"NotImplemented", JustWarning,
"Affinity setting not available for this architecture, ignoring...");
return true;
G4Exception("G4Threading::G4SetPinAffinity()",
"NotImplemented", JustWarning,
"Affinity setting not available for this architecture, "
"ignoring...");
return true;
}
#endif
void G4Threading::SetMultithreadedApplication(G4bool value ) { isMTAppType = value; }
G4bool G4Threading::IsMultithreadedApplication() { return isMTAppType; }
void G4Threading::SetMultithreadedApplication(G4bool value)
{
isMTAppType = value;
}
G4bool G4Threading::IsMultithreadedApplication()
{
return isMTAppType;
}
namespace
{
std::atomic_int numActThreads(0);
std::atomic_int numActThreads(0);
}
int G4Threading::WorkerThreadLeavesPool() { return numActThreads--; }
int G4Threading::WorkerThreadJoinsPool() { return numActThreads++;}
@@ -129,15 +114,14 @@ G4int G4Threading::GetNumberOfRunningWorkerThreads() { return numActThreads.load
#else // Sequential mode
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)
{
// In sequential mode return Process ID and not Thread ID
#if defined(WIN32)
return GetCurrentProcessId();
#else
#else
return getpid();
#endif
#endif
}
G4int G4Threading::G4GetNumberOfCores() { return 1; }
@@ -146,7 +130,7 @@ G4bool G4Threading::IsWorkerThread() { return false; }
G4bool G4Threading::IsMasterThread() { return true; }
void G4Threading::G4SetThreadId(G4int) {}
G4bool G4Threading::G4SetPinAffinity(G4int,G4Thread&) { return true;}
G4bool G4Threading::G4SetPinAffinity(G4int, G4NativeThread&) { return true; }
void G4Threading::SetMultithreadedApplication(G4bool) {}
G4bool G4Threading::IsMultithreadedApplication() { return false; }
+25 -10
View File
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4Timer.cc 67970 2013-03-13 10:10:06Z gcosmo $
// $Id: G4Timer.cc 110674 2018-06-07 10:30:11Z gcosmo $
//
//
// ----------------------------------------------------------------------
@@ -36,7 +36,7 @@
#include "G4Timer.hh"
#include "G4ios.hh"
#undef times
#include <iomanip>
// Global error function
#include "G4ExceptionSeverity.hh"
@@ -86,16 +86,31 @@ void G4Exception(const char* originOfException,
// Print timer status n std::ostream
std::ostream& operator << (std::ostream& os, const G4Timer& t)
{
// so fixed doesn't propagate
std::stringstream ss;
ss << std::fixed;
if (t.IsValid())
{
ss << "User=" << t.GetUserElapsed()
<< "s Real=" << t.GetRealElapsed()
<< "s Sys=" << t.GetSystemElapsed() << "s";
#ifdef G4MULTITHREADED
// avoid possible FPE error
if(t.GetRealElapsed() > 1.0e-6)
{
os << "User=" << t.GetUserElapsed()
<< "s Real=" << t.GetRealElapsed()
<< "s Sys=" << t.GetSystemElapsed() << "s";
double cpu_util = (t.GetUserElapsed()+t.GetRealElapsed()) /
t.GetRealElapsed() * 100.0;
ss << std::setprecision(1);
ss << " [Cpu=" << std::setprecision(1) << cpu_util << "%]";
}
#endif
}
else
{
os << "User=****s Real=****s Sys=****s";
}
{
ss << "User=****s Real=****s Sys=****s";
}
os << ss.str();
return os;
}
@@ -111,8 +126,8 @@ G4double G4Timer::GetRealElapsed() const
G4Exception("G4Timer::GetRealElapsed()", "InvalidCondition",
FatalException, "Timer not stopped or times not recorded!");
}
G4double diff=fEndRealTime-fStartRealTime;
return diff/sysconf(_SC_CLK_TCK);
std::chrono::duration<double> diff=fEndRealTime-fStartRealTime;
return diff.count();
}
+56 -34
View File
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4ios.cc 78780 2014-01-23 13:55:15Z gcosmo $
// $Id: G4ios.cc 110251 2018-05-17 14:09:28Z gcosmo $
//
//
// --------------------------------------------------------------
@@ -36,53 +36,75 @@
#include "G4ios.hh"
#include "G4strstreambuf.hh"
#include <iostream>
#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);
}
G4strstreambuf*& _G4coutbuf_p()
{
G4ThreadLocalStatic G4strstreambuf* _instance = new G4strstreambuf();
return _instance;
}
void G4iosFinalization()
{
delete G4cout_p; G4cout_p = 0;
delete G4cerr_p; G4cerr_p = 0;
delete G4coutbuf_p; G4coutbuf_p = 0;
delete G4cerrbuf_p; G4cerrbuf_p = 0;
}
G4strstreambuf*& _G4cerrbuf_p()
{
G4ThreadLocalStatic G4strstreambuf* _instance = new G4strstreambuf();
return _instance;
}
// These two functions are guaranteed to be called at load and
// unload of the library containing this code.
namespace
{
std::ostream*& _G4cout_p()
{
G4ThreadLocalStatic std::ostream* _instance = new std::ostream(_G4coutbuf_p());
return _instance;
}
std::ostream*& _G4cerr_p()
{
G4ThreadLocalStatic std::ostream* _instance = new std::ostream(_G4cerrbuf_p());
return _instance;
}
#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() == &std::cout || _G4cout_p() == 0) _G4cout_p() = new std::ostream(_G4coutbuf_p());
if (_G4cerr_p() == &std::cerr || _G4cerr_p() == 0) _G4cerr_p() = new std::ostream(_G4cerrbuf_p());
}
void G4iosFinalization()
{
delete _G4cout_p(); _G4cout_p() = &std::cout;
delete _G4cerr_p(); _G4cerr_p() = &std::cerr;
delete _G4coutbuf_p(); _G4coutbuf_p() = nullptr;
delete _G4cerrbuf_p(); _G4cerrbuf_p() = nullptr;
}
// These two functions are guaranteed to be called at load and
// unload of the library containing this code.
namespace
{
#ifndef WIN32
void setupG4ioSystem(void) __attribute__ ((constructor));
void cleanupG4ioSystem(void) __attribute__((destructor));
#endif
void setupG4ioSystem(void) { G4iosInitialization(); }
void cleanupG4ioSystem(void) { G4iosFinalization(); }
}
}
#else // Sequential
G4strstreambuf G4coutbuf;
G4strstreambuf G4cerrbuf;
std::ostream G4cout(&G4coutbuf);
std::ostream G4cerr(&G4cerrbuf);
G4strstreambuf G4coutbuf;
G4strstreambuf G4cerrbuf;
std::ostream G4cout(&G4coutbuf);
std::ostream G4cerr(&G4cerrbuf);
void G4iosInitialization() {}
void G4iosFinalization() {}
void G4iosInitialization() {}
void G4iosFinalization() {}
#endif