Import Geant4 10.4.1 source tree

This commit is contained in:
Gabriele Cosmo
2018-03-02 09:34:30 +01:00
parent fc6af9e721
commit fe04dcb406
341 changed files with 18389 additions and 24522 deletions
+13
View File
@@ -17,6 +17,19 @@ committal in the SVN repository !
* Reverse chronological order (last date on top), please *
----------------------------------------------------------
February 12, 2018 G.Cosmo (global-V10-03-12)
- G4StateManager: move static method SetVerboseLevel() to be non inline.
February 9, 2018 M.Asai
- G4MTcoutDestination.cc blocks G4cout from worker threads while spplication
is in G4State_Init instead of G4State_Idle.
- G4StateManager has a new method to set verbosity and print the state change.
December 19, 2017 G.Cosmo
- Fixed self-consistency in G4ReferenceCountedHandle header (missing #include).
Added missing #ifdef guard in G4CacheDetails header; code formatting.
Thanks to Raphael Isemann for reporting these.
October 20, 2017 E.Tcherniaev (global-V10-03-11)
- Use more performant G.Marsaglia (1972) algorithm for G4RandomDirection.
Thanks to Kostas Savvidy for the suggestion.
+1 -4
View File
@@ -1,4 +1,4 @@
# $Id: GNUmakefile 66892 2013-01-17 10:57:59Z gunter $
# $Id: GNUmakefile 108486 2018-02-15 14:47:25Z gcosmo $
# --------------------------------------------------------------
# GNUmakefile for global management. Gabriele Cosmo, 26/9/96.
# --------------------------------------------------------------
@@ -12,8 +12,5 @@ endif
include $(G4INSTALL)/config/architecture.gmk
CPPFLAGS += -DG4GLOB_ALLOC_EXPORT
ifdef G4RF_DEBUG
CPPFLAGS += -DG4RF_DEBUG
endif
include $(G4INSTALL)/config/common.gmk
+138 -104
View File
@@ -29,16 +29,16 @@
// GEANT 4 class header file
//
// Class Description:
//
// The classes contained in this header files are used by
// G4Cache to store a TLS instance of the cached object.
// G4Cache to store a TLS instance of the cached object.
// These classes should not be used by client code, but
// are used by one of the G4Cache classes.
//
// This class is container of the cached value
// G4Cache is a container of the cached value.
// Not memory efficient, but CPU efficient (constant time access)
// A different version with a map instead of a vector should be
// memory efficient
// and less CPU efficient (log-time access).
// memory efficient and less CPU efficient (log-time access).
// If really a lot of these objects are used
// we may want to consider the map version to save some memory
//
@@ -53,29 +53,35 @@
// objects can be stored in the cache and this limitation is removed
// but explicit handling of memory (new/delete) of cached object becomes
// client responsibility.
//
// History:
// 21 Oct 2013: A. Dotti - First implementation
//
// Todos: - Understand if map based class can be more efficent than
// vector one
// - Evaluate use of specialized allocator for TLS "new"
// ------------------------------------------------------------
#ifndef G4CacheDetails_hh
#define G4CacheDetails_hh
#include <vector>
#include "G4Threading.hh"
#include "globals.hh"
#ifdef g4cdebug
#include <iostream>
#include <sstream>
using std::cout;
using std::endl;
#include <iostream>
#include <sstream>
using std::cout;
using std::endl;
#endif
// A TLS storage for a cache of type VALTYPE
template<class VALTYPE>
class G4CacheReference {
public:
//
template<class VALTYPE> class G4CacheReference
{
public:
inline void Initialize( unsigned int id );
// Initliaze TLS storage
@@ -85,47 +91,51 @@ public:
inline VALTYPE& GetCache(unsigned int id) const;
// Returns cached value for instance id
private:
private:
typedef std::vector<VALTYPE*> cache_container;
// Implementation detail: the cached object is stored as a
// pointer. See Note (1)
// pointer. Object is stored as a pointer to avoid too large
// std::vector in case of stored objects and allow use of
// specialized allocators
static G4ThreadLocal cache_container *cache;
};
// Note (1) : Object is stored as a pointer to avoid too large
// std::vector in case of stored objects and allow use
// of spcialized allocators
// Template specialization for pointers
// Note that objects are not owned by cache, for this
// version of the cache the explicit new/delete of the
// cached object
template<class VALTYPE>
class G4CacheReference<VALTYPE*> {
public:
// Note: Objects are not owned by cache, for this version of the cache
// the explicit new/delete of the cached object
//
template<class VALTYPE> class G4CacheReference<VALTYPE*>
{
public:
inline void Initialize( unsigned int id );
inline void Destroy( unsigned int id , G4bool last);
inline VALTYPE*& GetCache(unsigned int id) const;
private:
private:
typedef std::vector<VALTYPE*> cache_container;
static G4ThreadLocal cache_container *cache;
};
// Template specialization for probably the most used case: double
// Be more efficient avoiding unnecessary "new/delete"
template<>
class G4CacheReference<G4double> {
public:
//
template<> class G4CacheReference<G4double>
{
public:
inline void Initialize( unsigned int id );
inline void Destroy( unsigned int id , G4bool last);
inline G4double& GetCache(unsigned int id) const;
private:
private:
typedef std::vector<G4double> cache_container;
G4GLOB_DLL static G4ThreadLocal std::vector<G4double> *cache;
};
@@ -136,137 +146,161 @@ private:
//================================
//======= Implementation: G4CacheReference<V>
//===========================================
template<class V>
void G4CacheReference<V>::Initialize(unsigned int id)
void G4CacheReference<V>::Initialize( unsigned int id )
{
#ifdef g4cdebug
if ( cache == 0 )
cout<<"Generic template"<<endl;
if ( cache == 0 )
cout<<"Generic template"<<endl;
#endif
//Create cache container
if ( cache == 0 )
cache = new cache_container;
if ( cache->size() <= id )
cache->resize(id+1,static_cast<V*>(0));
if ( (*cache)[id] == 0 ) (*cache)[id]=new V;
// Create cache container
if ( cache == 0 )
cache = new cache_container;
if ( cache->size() <= id )
cache->resize(id+1,static_cast<V*>(0));
if ( (*cache)[id] == 0 )
(*cache)[id]=new V;
}
template<class V>
void G4CacheReference<V>::Destroy( unsigned int id, G4bool last )
{
if ( cache ) {
if ( cache )
{
#ifdef g4cdebug
cout<<"Destroying element"<<id<<" is last?"<<last<<endl;
cout<<"Destroying element"<<id<<" is last?"<<last<<endl;
#endif
if ( cache->size() < id ) {
G4ExceptionDescription msg;
msg<<"Internal fatal error. Invalid G4Cache size (requested id: "<<id<<" but cache has size: "<<cache->size();
msg<<" Possibly client created G4Cache object in a thread and tried to delete it from another thread!";
G4Exception("G4CacheReference<V>::Destroy","Cache001",FatalException,msg);
return;
}
if ( cache->size() > id && (*cache)[id] ) {
delete (*cache)[id];
(*cache)[id]=0;
}
if (last ) {
delete cache;
cache = 0;
}
if ( cache->size() < id )
{
G4ExceptionDescription msg;
msg << "Internal fatal error. Invalid G4Cache size (requested id: "
<< id << " but cache has size: "<<cache->size();
msg << " Possibly client created G4Cache object in a thread and"
<< " tried to delete it from another thread!";
G4Exception("G4CacheReference<V>::Destroy", "Cache001",
FatalException, msg);
return;
}
if ( cache->size() > id && (*cache)[id] )
{
delete (*cache)[id];
(*cache)[id]=0;
}
if (last)
{
delete cache;
cache = 0;
}
}
}
template<class V>
V& G4CacheReference<V>::GetCache(unsigned int id) const
V& G4CacheReference<V>::GetCache( unsigned int id ) const
{
return *(cache->operator[](id));
return *(cache->operator[](id));
}
template<class V>
G4ThreadLocal typename G4CacheReference<V>::cache_container * G4CacheReference<V>::cache = 0;
G4ThreadLocal typename
G4CacheReference<V>::cache_container * G4CacheReference<V>::cache = 0;
//======= Implementation: G4CacheReference<V*>
//============================================
template<class V>
void G4CacheReference<V*>::Initialize( unsigned int id )
{
#ifdef g4cdebug
if ( cache == 0 )
cout<<"Pointer template"<<endl;
if ( cache == 0 )
cout<<"Pointer template"<<endl;
#endif
if ( cache == 0 )
cache = new cache_container;
if ( cache->size() <= id )
cache->resize(id+1,static_cast<V*>(0));
//No need to create pointee
//if ( (*cache)[id] == 0 ) (*cache)[id]=new VALTYPE;
if ( cache == 0 )
cache = new cache_container;
if ( cache->size() <= id )
cache->resize(id+1,static_cast<V*>(0));
}
template<class V>
inline void G4CacheReference<V*>::Destroy( unsigned int id , G4bool last)
inline void G4CacheReference<V*>::Destroy( unsigned int id , G4bool last )
{
if ( cache ) {
if ( cache )
{
#ifdef g4cdebug
cout<<"Destroying element"<<id<<" is last?"<<last<<"-Pointer template specialization-"<<endl;
cout << "Destroying element" << id << " is last?" << last
<< "-Pointer template specialization-" << endl;
#endif
if ( cache->size() < id ) {
G4ExceptionDescription msg;
msg<<"Internal fatal error. Invalid G4Cache size (requested id: "<<id<<" but cache has size: "<<cache->size();
msg<<" Possibly client created G4Cache object in a thread and tried to delete it from another thread!";
G4Exception("G4CacheReference<V*>::Destroy","Cache001",FatalException,msg);
return;
}
if ( cache->size() > id && (*cache)[id] ) {
//Ownership is for client
//delete (*cache)[id];
(*cache)[id]=0;
}
if (last ) {
delete cache;
cache = 0;
}
if ( cache->size() < id )
{
G4ExceptionDescription msg;
msg << "Internal fatal error. Invalid G4Cache size (requested id: "
<< id << " but cache has size: " << cache->size();
msg << " Possibly client created G4Cache object in a thread and"
<< " tried to delete it from another thread!";
G4Exception("G4CacheReference<V*>::Destroy", "Cache001",
FatalException, msg);
return;
}
if ( cache->size() > id && (*cache)[id] )
{
// Ownership is for client
// delete (*cache)[id];
(*cache)[id]=0;
}
if (last )
{
delete cache;
cache = 0;
}
}
}
template<class V>
V*& G4CacheReference<V*>::GetCache(unsigned int id) const
{
return (cache->operator[](id));
return (cache->operator[](id));
}
template<class V>
G4ThreadLocal typename G4CacheReference<V*>::cache_container * G4CacheReference<V*>::cache=0;
G4ThreadLocal typename
G4CacheReference<V*>::cache_container * G4CacheReference<V*>::cache = 0;
//======= Implementation: G4CacheReference<double>
//============================================
void G4CacheReference<G4double>::Initialize( unsigned int id )
{
#ifdef g4cdebug
cout<<"Specialized template for G4double"<<endl;
cout<<"Specialized template for G4double"<<endl;
#endif
if ( cache == 0 )
cache = new cache_container;
if ( cache->size() <= id )
cache->resize(id+1,static_cast<G4double>(0));
if ( cache == 0 )
cache = new cache_container;
if ( cache->size() <= id )
cache->resize(id+1,static_cast<G4double>(0));
}
#ifdef g4cdebug
void G4CacheReference<G4double>::Destroy( unsigned int id , G4bool last) {
void G4CacheReference<G4double>::Destroy( unsigned int id , G4bool last)
#else
void G4CacheReference<G4double>::Destroy( unsigned int /*id*/ , G4bool last) {
void G4CacheReference<G4double>::Destroy( unsigned int /*id*/ , G4bool last)
#endif
if ( cache && last ) {
{
if ( cache && last )
{
#ifdef g4cdebug
cout<<"Destroying element"<<id<<" is last?"<<last<<"-Pointer template specialization-"<<endl;
cout << "Destroying element" << id << " is last?" << last
<< "-Pointer template specialization-" << endl;
#endif
delete cache;
cache = 0;
}
delete cache;
cache = 0;
}
}
G4double& G4CacheReference<G4double>::GetCache(unsigned int id) const {
return cache->operator[](id);
G4double& G4CacheReference<G4double>::GetCache(unsigned int id) const
{
return cache->operator[](id);
}
//G4ThreadLocal std::vector<G4double>* G4CacheReference<G4double>::cache = 0;
#endif
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4ReferenceCountedHandle.hh 67970 2013-03-13 10:10:06Z gcosmo $
// $Id: G4ReferenceCountedHandle.hh 108486 2018-02-15 14:47:25Z gcosmo $
//
//
// Class G4ReferenceCountedHandle
@@ -49,12 +49,12 @@
// error (since we're dealing with objects, not pointers!).
// Author: Radovan Chytracek, CERN (Radovan.Chytracek@cern.ch)
// Version: 3.0
// Date: November 2001
// ----------------------------------------------------------------------
#ifndef _G4REFERENCECOUNTEDHANDLE_H_
#define _G4REFERENCECOUNTEDHANDLE_H_ 1
#include "G4Types.hh"
#include "G4Allocator.hh"
template <class X> class G4CountedObject;
@@ -109,22 +109,14 @@ public: // with description
inline void operator delete( void *pObj );
// Operator delete defined for G4Allocator.
public:
#ifdef G4RF_DEBUG
void* operator new( size_t, void *pObj );
// This is required on some compilers (Windows/VC++, Linux/g++) when this
// class is used in the context of STL container. It generates a warning
// saying something about not existing correspondent delete...
#endif
private:
G4CountedObject<X>* fObj;
// The object subject to reference counting.
};
extern G4GLOB_DLL G4ThreadLocal G4Allocator<G4ReferenceCountedHandle<void> > *aRCHAllocator;
extern G4GLOB_DLL G4ThreadLocal
G4Allocator<G4ReferenceCountedHandle<void> > *aRCHAllocator;
template <class X>
class G4CountedObject
@@ -164,7 +156,8 @@ private:
// The counted object.
};
extern G4GLOB_DLL G4ThreadLocal G4Allocator<G4CountedObject<void> > *aCountedObjectAllocator;
extern G4GLOB_DLL G4ThreadLocal
G4Allocator<G4CountedObject<void> > *aCountedObjectAllocator;
// --------- G4CountedObject<X> Inline function definitions ---------
@@ -300,12 +293,4 @@ void G4ReferenceCountedHandle<X>::operator delete( void *pObj )
aRCHAllocator->FreeSingle( (G4ReferenceCountedHandle<void>*)pObj );
}
#ifdef G4RF_DEBUG
template <class X>
void* G4ReferenceCountedHandle<X>::operator new( size_t, void *pObj )
{
return pObj;
}
#endif
#endif // _G4REFERENCECOUNTEDHANDLE_H_
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4StateManager.hh 67970 2013-03-13 10:10:06Z gcosmo $
// $Id: G4StateManager.hh 108486 2018-02-15 14:47:25Z gcosmo $
//
//
// ------------------------------------------------------------
@@ -111,8 +111,7 @@ public:
inline const char* GetMessage() const;
inline void SetExceptionHandler(G4VExceptionHandler* eh);
inline G4VExceptionHandler* GetExceptionHandler() const;
public:
static void SetVerboseLevel(G4int val);
//void Pause();
//void Pause(const char* msg);
@@ -139,7 +138,7 @@ private:
G4int suppressAbortion;
const char* msgptr;
G4VExceptionHandler* exceptionHandler;
static G4int verboseLevel;
};
#include "G4StateManager.icc"
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4Version.hh 107861 2017-12-07 14:25:10Z gcosmo $
// $Id: G4Version.hh 108486 2018-02-15 14:47:25Z gcosmo $
// GEANT4 tag $Name:$
//
// Version information
@@ -46,11 +46,11 @@
// |--> patch number
#ifndef G4VERSION_NUMBER
#define G4VERSION_NUMBER 1040
#define G4VERSION_NUMBER 1041
#endif
#ifndef G4VERSION_TAG
#define G4VERSION_TAG "$Name: geant4-10-04 $"
#define G4VERSION_TAG "$Name: geant4-10-04-patch-01 $"
#endif
// as variables
@@ -58,10 +58,10 @@
#include "G4String.hh"
#ifdef G4MULTITHREADED
static const G4String G4Version = "$Name: geant4-10-04 [MT]$";
static const G4String G4Version = "$Name: geant4-10-04-patch-01 [MT]$";
#else
static const G4String G4Version = "$Name: geant4-10-04 $";
static const G4String G4Version = "$Name: geant4-10-04-patch-01 $";
#endif
static const G4String G4Date = "(08-December-2017)";
static const G4String G4Date = "(28-February-2018)";
#endif
@@ -79,7 +79,7 @@ void G4MTcoutDestination::SetDefaultOutput( G4bool addmasterDestination ,
const auto filter_out = [this](G4String&)->G4bool {
if (this->ignoreCout ||
( this->ignoreInit &&
this->stateMgr->GetCurrentState() == G4State_Idle ) )
this->stateMgr->GetCurrentState() == G4State_Init ) )
{ return false; }
return true;
};
+18 -2
View File
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: G4StateManager.cc 67970 2013-03-13 10:10:06Z gcosmo $
// $Id: G4StateManager.cc 108486 2018-02-15 14:47:25Z gcosmo $
//
//
// ------------------------------------------------------------
@@ -40,6 +40,7 @@
// Initialization of the static pointer of the single class instance
//
G4ThreadLocal G4StateManager* G4StateManager::theStateManager = 0;
G4int G4StateManager::verboseLevel = 0;
G4StateManager::G4StateManager()
: theCurrentState(G4State_PreInit),
@@ -205,6 +206,7 @@ G4StateManager::SetNewState(G4ApplicationState requestedState, const char* msg)
G4bool ack = true;
G4ApplicationState savedState = thePreviousState;
thePreviousState = theCurrentState;
while ((ack) && (i<theDependentsList.size()))
{
ack = theDependentsList[i]->Notify(requestedState);
@@ -218,7 +220,15 @@ G4StateManager::SetNewState(G4ApplicationState requestedState, const char* msg)
if(!ack)
{ thePreviousState = savedState; }
else
{ theCurrentState = requestedState; }
{
theCurrentState = requestedState;
if(verboseLevel>0)
{
G4cout<<"#### G4StateManager::SetNewState from "
<<GetStateString(thePreviousState)<<" to "
<<GetStateString(requestedState)<<G4endl;
}
}
msgptr = 0;
return ack;
}
@@ -269,6 +279,12 @@ G4StateManager::GetStateString(G4ApplicationState aState) const
return stateName;
}
void
G4StateManager::SetVerboseLevel(G4int val)
{
verboseLevel = val;
}
//void G4StateManager::Pause()
//{
// Pause("G4_pause> ");