Import Geant4 10.7.0.beta source tree
This commit is contained in:
@@ -23,11 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// G4Allocator
|
||||
//
|
||||
// Class Description:
|
||||
//
|
||||
@@ -35,14 +31,13 @@
|
||||
// chunks organised as linked list. It's meant to be used by associating
|
||||
// it to the object to be allocated and defining for it new and delete
|
||||
// operators via MallocSingle() and FreeSingle() methods.
|
||||
|
||||
|
||||
// ---------------- G4Allocator ----------------
|
||||
//
|
||||
// Author: G.Cosmo (CERN), November 2000
|
||||
// ------------------------------------------------------------
|
||||
|
||||
#ifndef G4Allocator_h
|
||||
#define G4Allocator_h 1
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4Allocator_hh
|
||||
#define G4Allocator_hh 1
|
||||
|
||||
#include <cstddef>
|
||||
#include <typeinfo>
|
||||
@@ -51,118 +46,119 @@
|
||||
|
||||
class G4AllocatorBase
|
||||
{
|
||||
public:
|
||||
G4AllocatorBase();
|
||||
virtual ~G4AllocatorBase();
|
||||
virtual void ResetStorage()=0;
|
||||
virtual size_t GetAllocatedSize() const=0;
|
||||
virtual int GetNoPages() const=0;
|
||||
virtual size_t GetPageSize() const=0;
|
||||
virtual void IncreasePageSize( unsigned int sz )=0;
|
||||
virtual const char* GetPoolType() const=0;
|
||||
public:
|
||||
G4AllocatorBase();
|
||||
virtual ~G4AllocatorBase();
|
||||
virtual void ResetStorage() = 0;
|
||||
virtual std::size_t GetAllocatedSize() const = 0;
|
||||
virtual int GetNoPages() const = 0;
|
||||
virtual std::size_t GetPageSize() const = 0;
|
||||
virtual void IncreasePageSize(unsigned int sz) = 0;
|
||||
virtual const char* GetPoolType() const = 0;
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
class G4Allocator : public G4AllocatorBase
|
||||
{
|
||||
public: // with description
|
||||
public:
|
||||
G4Allocator() throw();
|
||||
~G4Allocator() throw();
|
||||
// Constructor & destructor
|
||||
|
||||
G4Allocator() throw();
|
||||
~G4Allocator() throw();
|
||||
// Constructor & destructor
|
||||
inline Type* MallocSingle();
|
||||
inline void FreeSingle(Type* anElement);
|
||||
// Malloc and Free methods to be used when overloading
|
||||
// new and delete operators in the client <Type> object
|
||||
|
||||
inline Type* MallocSingle();
|
||||
inline void FreeSingle(Type* anElement);
|
||||
// Malloc and Free methods to be used when overloading
|
||||
// new and delete operators in the client <Type> object
|
||||
inline void ResetStorage();
|
||||
// Returns allocated storage to the free store, resets allocator.
|
||||
// Note: contents in memory are lost using this call !
|
||||
|
||||
inline void ResetStorage();
|
||||
// Returns allocated storage to the free store, resets allocator.
|
||||
// Note: contents in memory are lost using this call !
|
||||
inline std::size_t GetAllocatedSize() const;
|
||||
// Returns the size of the total memory allocated
|
||||
inline int GetNoPages() const;
|
||||
// Returns the total number of allocated pages
|
||||
inline std::size_t GetPageSize() const;
|
||||
// Returns the current size of a page
|
||||
inline void IncreasePageSize(unsigned int sz);
|
||||
// Resets allocator and increases default page size of a given factor
|
||||
|
||||
inline size_t GetAllocatedSize() const;
|
||||
// Returns the size of the total memory allocated
|
||||
inline int GetNoPages() const;
|
||||
// Returns the total number of allocated pages
|
||||
inline size_t GetPageSize() const;
|
||||
// Returns the current size of a page
|
||||
inline void IncreasePageSize( unsigned int sz );
|
||||
// Resets allocator and increases default page size of a given factor
|
||||
inline const char* GetPoolType() const;
|
||||
// Returns the type_info Id of the allocated type in the pool
|
||||
|
||||
inline const char* GetPoolType() const;
|
||||
// Returns the type_info Id of the allocated type in the pool
|
||||
// This public section includes standard methods and types
|
||||
// required if the allocator is to be used as alternative
|
||||
// allocator for STL containers.
|
||||
// NOTE: the code below is a trivial implementation to make
|
||||
// this class an STL compliant allocator.
|
||||
// It is anyhow NOT recommended to use this class as
|
||||
// alternative allocator for STL containers !
|
||||
|
||||
public: // without description
|
||||
using value_type = Type;
|
||||
using size_type = std::size_t;
|
||||
using difference_type = ptrdiff_t;
|
||||
using pointer = Type*;
|
||||
using const_pointer = const Type*;
|
||||
using reference = Type&;
|
||||
using const_reference = const Type&;
|
||||
|
||||
// This public section includes standard methods and types
|
||||
// required if the allocator is to be used as alternative
|
||||
// allocator for STL containers.
|
||||
// NOTE: the code below is a trivial implementation to make
|
||||
// this class an STL compliant allocator.
|
||||
// It is anyhow NOT recommended to use this class as
|
||||
// alternative allocator for STL containers !
|
||||
template <class U>
|
||||
G4Allocator(const G4Allocator<U>& right) throw()
|
||||
: mem(right.mem)
|
||||
{}
|
||||
// Copy constructor
|
||||
|
||||
typedef Type value_type;
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef Type* pointer;
|
||||
typedef const Type* const_pointer;
|
||||
typedef Type& reference;
|
||||
typedef const Type& const_reference;
|
||||
pointer address(reference r) const { return &r; }
|
||||
const_pointer address(const_reference r) const { return &r; }
|
||||
// Returns the address of values
|
||||
|
||||
template <class U> G4Allocator(const G4Allocator<U>& right) throw()
|
||||
: mem(right.mem) {}
|
||||
// Copy constructor
|
||||
pointer allocate(size_type n, void* = 0)
|
||||
{
|
||||
// Allocates space for n elements of type Type, but does not initialise
|
||||
//
|
||||
Type* mem_alloc = 0;
|
||||
if(n == 1)
|
||||
mem_alloc = MallocSingle();
|
||||
else
|
||||
mem_alloc = static_cast<Type*>(::operator new(n * sizeof(Type)));
|
||||
return mem_alloc;
|
||||
}
|
||||
void deallocate(pointer p, size_type n)
|
||||
{
|
||||
// Deallocates n elements of type Type, but doesn't destroy
|
||||
//
|
||||
if(n == 1)
|
||||
FreeSingle(p);
|
||||
else
|
||||
::operator delete((void*) p);
|
||||
return;
|
||||
}
|
||||
|
||||
pointer address(reference r) const { return &r; }
|
||||
const_pointer address(const_reference r) const { return &r; }
|
||||
// Returns the address of values
|
||||
void construct(pointer p, const Type& val) { new((void*) p) Type(val); }
|
||||
// Initialises *p by val
|
||||
void destroy(pointer p) { p->~Type(); }
|
||||
// Destroy *p but doesn't deallocate
|
||||
|
||||
pointer allocate(size_type n, void* = 0)
|
||||
{
|
||||
// Allocates space for n elements of type Type, but does not initialise
|
||||
//
|
||||
Type* mem_alloc = 0;
|
||||
if (n == 1)
|
||||
mem_alloc = MallocSingle();
|
||||
else
|
||||
mem_alloc = static_cast<Type*>(::operator new(n*sizeof(Type)));
|
||||
return mem_alloc;
|
||||
}
|
||||
void deallocate(pointer p, size_type n)
|
||||
{
|
||||
// Deallocates n elements of type Type, but doesn't destroy
|
||||
//
|
||||
if (n == 1)
|
||||
FreeSingle(p);
|
||||
else
|
||||
::operator delete((void*)p);
|
||||
return;
|
||||
}
|
||||
size_type max_size() const throw()
|
||||
{
|
||||
// Returns the maximum number of elements that can be allocated
|
||||
//
|
||||
return 2147483647 / sizeof(Type);
|
||||
}
|
||||
|
||||
void construct(pointer p, const Type& val) { new((void*)p) Type(val); }
|
||||
// Initialises *p by val
|
||||
void destroy(pointer p) { p->~Type(); }
|
||||
// Destroy *p but doesn't deallocate
|
||||
template <class U>
|
||||
struct rebind
|
||||
{
|
||||
typedef G4Allocator<U> other;
|
||||
};
|
||||
// Rebind allocator to type U
|
||||
|
||||
size_type max_size() const throw()
|
||||
{
|
||||
// Returns the maximum number of elements that can be allocated
|
||||
//
|
||||
return 2147483647/sizeof(Type);
|
||||
}
|
||||
G4AllocatorPool mem;
|
||||
// Pool of elements of sizeof(Type)
|
||||
|
||||
template <class U>
|
||||
struct rebind { typedef G4Allocator<U> other; };
|
||||
// Rebind allocator to type U
|
||||
|
||||
G4AllocatorPool mem;
|
||||
// Pool of elements of sizeof(Type)
|
||||
|
||||
private:
|
||||
|
||||
const char* tname;
|
||||
// Type name identifier
|
||||
private:
|
||||
const char* tname;
|
||||
// Type name identifier
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------
|
||||
@@ -190,8 +186,7 @@ G4Allocator<Type>::G4Allocator() throw()
|
||||
//
|
||||
template <class Type>
|
||||
G4Allocator<Type>::~G4Allocator() throw()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
// ************************************************************
|
||||
// MallocSingle
|
||||
@@ -232,7 +227,7 @@ void G4Allocator<Type>::ResetStorage()
|
||||
// ************************************************************
|
||||
//
|
||||
template <class Type>
|
||||
size_t G4Allocator<Type>::GetAllocatedSize() const
|
||||
std::size_t G4Allocator<Type>::GetAllocatedSize() const
|
||||
{
|
||||
return mem.Size();
|
||||
}
|
||||
@@ -262,10 +257,10 @@ size_t G4Allocator<Type>::GetPageSize() const
|
||||
// ************************************************************
|
||||
//
|
||||
template <class Type>
|
||||
void G4Allocator<Type>::IncreasePageSize( unsigned int sz )
|
||||
void G4Allocator<Type>::IncreasePageSize(unsigned int sz)
|
||||
{
|
||||
ResetStorage();
|
||||
mem.GrowPageSize(sz);
|
||||
mem.GrowPageSize(sz);
|
||||
}
|
||||
|
||||
// ************************************************************
|
||||
@@ -283,7 +278,7 @@ const char* G4Allocator<Type>::GetPoolType() const
|
||||
// ************************************************************
|
||||
//
|
||||
template <class T1, class T2>
|
||||
bool operator== (const G4Allocator<T1>&, const G4Allocator<T2>&) throw()
|
||||
bool operator==(const G4Allocator<T1>&, const G4Allocator<T2>&) throw()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -293,7 +288,7 @@ bool operator== (const G4Allocator<T1>&, const G4Allocator<T2>&) throw()
|
||||
// ************************************************************
|
||||
//
|
||||
template <class T1, class T2>
|
||||
bool operator!= (const G4Allocator<T1>&, const G4Allocator<T2>&) throw()
|
||||
bool operator!=(const G4Allocator<T1>&, const G4Allocator<T2>&) throw()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -23,49 +23,40 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// G4AllocatorList
|
||||
//
|
||||
// Class Description:
|
||||
//
|
||||
// A class to store all G4Allocator objects in a thread for the sake
|
||||
// of cleanly deleting them.
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
|
||||
#ifndef G4AllocatorList_h
|
||||
#define G4AllocatorList_h 1
|
||||
// Authors: M.Asai (SLAC), G.Cosmo (CERN), June 2013
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4AllocatorList_hh
|
||||
#define G4AllocatorList_hh 1
|
||||
|
||||
#include <vector>
|
||||
#include "globals.hh"
|
||||
#include <vector>
|
||||
|
||||
class G4AllocatorBase;
|
||||
|
||||
class G4AllocatorList
|
||||
{
|
||||
public: // with description
|
||||
public:
|
||||
static G4AllocatorList* GetAllocatorList();
|
||||
static G4AllocatorList* GetAllocatorListIfExist();
|
||||
|
||||
static G4AllocatorList* GetAllocatorList();
|
||||
static G4AllocatorList* GetAllocatorListIfExist();
|
||||
~G4AllocatorList();
|
||||
void Register(G4AllocatorBase*);
|
||||
void Destroy(G4int nStat = 0, G4int verboseLevel = 0);
|
||||
G4int Size() const;
|
||||
|
||||
public:
|
||||
private:
|
||||
G4AllocatorList();
|
||||
|
||||
~G4AllocatorList();
|
||||
void Register(G4AllocatorBase*);
|
||||
void Destroy(G4int nStat=0, G4int verboseLevel=0);
|
||||
G4int Size() const;
|
||||
|
||||
private:
|
||||
|
||||
G4AllocatorList();
|
||||
|
||||
private:
|
||||
|
||||
static G4ThreadLocal G4AllocatorList* fAllocatorList;
|
||||
std::vector<G4AllocatorBase*> fList;
|
||||
private:
|
||||
static G4ThreadLocal G4AllocatorList* fAllocatorList;
|
||||
std::vector<G4AllocatorBase*> fList;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,11 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// G4AllocatorPool
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
@@ -41,69 +37,70 @@
|
||||
// -------------- G4AllocatorPool ----------------
|
||||
//
|
||||
// Author: G.Cosmo (CERN), November 2000
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
#ifndef G4AllocatorPool_h
|
||||
#define G4AllocatorPool_h 1
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4AllocatorPool_hh
|
||||
#define G4AllocatorPool_hh 1
|
||||
|
||||
class G4AllocatorPool
|
||||
{
|
||||
public:
|
||||
public:
|
||||
explicit G4AllocatorPool(unsigned int n = 0);
|
||||
// Create a pool of elements of size n
|
||||
~G4AllocatorPool();
|
||||
// Destructor. Return storage to the free store
|
||||
|
||||
explicit G4AllocatorPool( unsigned int n=0 );
|
||||
// Create a pool of elements of size n
|
||||
~G4AllocatorPool();
|
||||
// Destructor. Return storage to the free store
|
||||
G4AllocatorPool(const G4AllocatorPool& right);
|
||||
// Copy constructor
|
||||
G4AllocatorPool& operator=(const G4AllocatorPool& right);
|
||||
// Equality operator
|
||||
|
||||
G4AllocatorPool(const G4AllocatorPool& right);
|
||||
// Copy constructor
|
||||
G4AllocatorPool& operator= (const G4AllocatorPool& right);
|
||||
// Equality operator
|
||||
inline void* Alloc();
|
||||
// Allocate one element
|
||||
inline void Free(void* b);
|
||||
// Return an element back to the pool
|
||||
|
||||
inline void* Alloc();
|
||||
// Allocate one element
|
||||
inline void Free( void* b );
|
||||
// Return an element back to the pool
|
||||
inline unsigned int Size() const;
|
||||
// Return storage size
|
||||
void Reset();
|
||||
// Return storage to the free store
|
||||
|
||||
inline unsigned int Size() const;
|
||||
// Return storage size
|
||||
void Reset();
|
||||
// Return storage to the free store
|
||||
inline int GetNoPages() const;
|
||||
// Return the total number of allocated pages
|
||||
inline unsigned int GetPageSize() const;
|
||||
// Accessor for default page size
|
||||
inline void GrowPageSize(unsigned int factor);
|
||||
// Increase default page size by a given factor
|
||||
|
||||
inline int GetNoPages() const;
|
||||
// Return the total number of allocated pages
|
||||
inline unsigned int GetPageSize() const;
|
||||
// Accessor for default page size
|
||||
inline void GrowPageSize( unsigned int factor );
|
||||
// Increase default page size by a given factor
|
||||
|
||||
private:
|
||||
|
||||
struct G4PoolLink
|
||||
private:
|
||||
struct G4PoolLink
|
||||
{
|
||||
G4PoolLink* next;
|
||||
};
|
||||
class G4PoolChunk
|
||||
{
|
||||
public:
|
||||
explicit G4PoolChunk(unsigned int sz)
|
||||
: size(sz)
|
||||
, mem(new char[size])
|
||||
, next(0)
|
||||
{
|
||||
G4PoolLink* next;
|
||||
};
|
||||
class G4PoolChunk
|
||||
{
|
||||
public:
|
||||
explicit G4PoolChunk(unsigned int sz)
|
||||
: size(sz), mem(new char[size]), next(0) {;}
|
||||
~G4PoolChunk() { delete [] mem; }
|
||||
const unsigned int size;
|
||||
char* mem;
|
||||
G4PoolChunk* next;
|
||||
};
|
||||
;
|
||||
}
|
||||
~G4PoolChunk() { delete[] mem; }
|
||||
const unsigned int size;
|
||||
char* mem;
|
||||
G4PoolChunk* next;
|
||||
};
|
||||
|
||||
void Grow();
|
||||
// Make pool larger
|
||||
void Grow();
|
||||
// Make pool larger
|
||||
|
||||
private:
|
||||
|
||||
const unsigned int esize;
|
||||
unsigned int csize;
|
||||
G4PoolChunk* chunks;
|
||||
G4PoolLink* head;
|
||||
int nchunks;
|
||||
private:
|
||||
const unsigned int esize;
|
||||
unsigned int csize;
|
||||
G4PoolChunk* chunks = nullptr;
|
||||
G4PoolLink* head = nullptr;
|
||||
int nchunks = 0;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------
|
||||
@@ -114,12 +111,14 @@ class G4AllocatorPool
|
||||
// Alloc
|
||||
// ************************************************************
|
||||
//
|
||||
inline void*
|
||||
G4AllocatorPool::Alloc()
|
||||
inline void* G4AllocatorPool::Alloc()
|
||||
{
|
||||
if (head==0) { Grow(); }
|
||||
if(head == 0)
|
||||
{
|
||||
Grow();
|
||||
}
|
||||
G4PoolLink* p = head; // return first element
|
||||
head = p->next;
|
||||
head = p->next;
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -127,52 +126,38 @@ G4AllocatorPool::Alloc()
|
||||
// Free
|
||||
// ************************************************************
|
||||
//
|
||||
inline void
|
||||
G4AllocatorPool::Free( void* b )
|
||||
inline void G4AllocatorPool::Free(void* b)
|
||||
{
|
||||
G4PoolLink* p = static_cast<G4PoolLink*>(b);
|
||||
p->next = head; // put b back as first element
|
||||
head = p;
|
||||
p->next = head; // put b back as first element
|
||||
head = p;
|
||||
}
|
||||
|
||||
// ************************************************************
|
||||
// Size
|
||||
// ************************************************************
|
||||
//
|
||||
inline unsigned int
|
||||
G4AllocatorPool::Size() const
|
||||
{
|
||||
return nchunks*csize;
|
||||
}
|
||||
inline unsigned int G4AllocatorPool::Size() const { return nchunks * csize; }
|
||||
|
||||
// ************************************************************
|
||||
// GetNoPages
|
||||
// ************************************************************
|
||||
//
|
||||
inline int
|
||||
G4AllocatorPool::GetNoPages() const
|
||||
{
|
||||
return nchunks;
|
||||
}
|
||||
inline int G4AllocatorPool::GetNoPages() const { return nchunks; }
|
||||
|
||||
// ************************************************************
|
||||
// GetPageSize
|
||||
// ************************************************************
|
||||
//
|
||||
inline unsigned int
|
||||
G4AllocatorPool::GetPageSize() const
|
||||
{
|
||||
return csize;
|
||||
}
|
||||
inline unsigned int G4AllocatorPool::GetPageSize() const { return csize; }
|
||||
|
||||
// ************************************************************
|
||||
// GrowPageSize
|
||||
// ************************************************************
|
||||
//
|
||||
inline void
|
||||
G4AllocatorPool::GrowPageSize( unsigned int sz )
|
||||
inline void G4AllocatorPool::GrowPageSize(unsigned int sz)
|
||||
{
|
||||
csize = (sz) ? sz*csize : csize;
|
||||
csize = (sz) ? sz * csize : csize;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,19 +23,15 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4ApplicationState
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef G4APPLICATIONSTATE_H
|
||||
#define G4APPLICATIONSTATE_H 1
|
||||
|
||||
// Class Description:
|
||||
// Description:
|
||||
//
|
||||
// Specifies the state of the G4 application
|
||||
//
|
||||
// States:
|
||||
// G4State_PreInit
|
||||
// At the very begining of the Application. G4StateManager starts
|
||||
// At the very beginning of the Application. G4StateManager starts
|
||||
// with this state. G4Initializer changes this state to Init when
|
||||
// G4Initializer::Initialize() method starts. At the moment of
|
||||
// the state change of PreInit->Init, no material, geometrical,
|
||||
@@ -51,8 +47,8 @@
|
||||
// BeamOn() method, G4RunManager will reset the application state
|
||||
// to Idle after G4GeometryManager::OpenGeometry() is Done.
|
||||
// G4State_GeomClosed
|
||||
// G4 is in this state between G4GeometryManager::CloseGeometry()
|
||||
// and G4GeometryManager::OpenGeometry(), but no event is in
|
||||
// Geant4 is in this state between G4GeometryManager::CloseGeometry()
|
||||
// and G4GeometryManager::OpenGeometry(), but no event is in
|
||||
// progress. At the begining of each event (construction of a
|
||||
// G4Event object and primary particle generation), G4RunManager
|
||||
// changes this state to EventProc and resets to GeomClosed state
|
||||
@@ -60,10 +56,10 @@
|
||||
// G4State_EventProc
|
||||
// Processing an event.
|
||||
// G4State_Quit
|
||||
// G4 is in this state when the destructor of G4RunManager is invoked.
|
||||
// Geant4 is in this state when the destructor of G4RunManager is invoked.
|
||||
// G4State_Abort
|
||||
// G4 is in this state when G4Exception is invoked.
|
||||
//
|
||||
// Geant4 is in this state when G4Exception is invoked.
|
||||
//
|
||||
//
|
||||
// PreInit
|
||||
// |
|
||||
@@ -79,10 +75,18 @@
|
||||
// v|
|
||||
// EventProc (at each event)
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4APPLICATIONSTATE_HH
|
||||
#define G4APPLICATIONSTATE_HH 1
|
||||
|
||||
enum G4ApplicationState
|
||||
{G4State_PreInit, G4State_Init, G4State_Idle, G4State_GeomClosed,
|
||||
G4State_EventProc, G4State_Quit, G4State_Abort};
|
||||
|
||||
enum G4ApplicationState
|
||||
{
|
||||
G4State_PreInit,
|
||||
G4State_Init,
|
||||
G4State_Idle,
|
||||
G4State_GeomClosed,
|
||||
G4State_EventProc,
|
||||
G4State_Quit,
|
||||
G4State_Abort
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@@ -23,48 +23,50 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4AutoDelete
|
||||
//
|
||||
// ---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// Description:
|
||||
//
|
||||
// Class Description:
|
||||
// This function implements a simplified "garbage collection" mechanism
|
||||
// for G4-MT model. Objects are registered when created on the heap and they
|
||||
// will be deleted at the end of
|
||||
// the program (like they would be if marked as "static").
|
||||
//
|
||||
// for G4-MT model. Objects are registered when created on the heap and they
|
||||
// will be deleted at the end of the program (like they would be if marked
|
||||
// as "static").
|
||||
//
|
||||
// Limitation:
|
||||
// The registered object, should not
|
||||
// contain any G4ThreadLocal data member. Note that in general,
|
||||
// if object is to be thread-private it is unnecessary to mark
|
||||
// any data-member as G4ThreadLocal.
|
||||
// The registered object, should not contain any G4ThreadLocal data member.
|
||||
// Note that in general, if object is to be thread-private it is unnecessary
|
||||
// to mark any data-member as G4ThreadLocal.
|
||||
//
|
||||
// Performance issues:
|
||||
// This function uses G4ThreadLocalSingleton that on its own uses
|
||||
// locks and mutexes. Thus its use should be limited to only when
|
||||
// locks and mutexes. Thus its use should be limited to only when
|
||||
// really necessary.
|
||||
//
|
||||
// Example:
|
||||
// class G4SharedByThreads {
|
||||
// void calledByThreads() {
|
||||
// G4Something* anObject = new G4Something;
|
||||
// G4AutoDelete::Register( anObject );
|
||||
// class G4SharedByThreads
|
||||
// {
|
||||
// void calledByThreads()
|
||||
// {
|
||||
// G4Something* anObject = new G4Something;
|
||||
// G4AutoDelete::Register( anObject );
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// History:
|
||||
// 28 October 2013: A. Dotti - First implementation
|
||||
// }
|
||||
|
||||
// Author: A.Dotti (SLAC), 28 October 2013
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4AUTODELETE_HH
|
||||
#define G4AUTODELETE_HH
|
||||
|
||||
#include "G4ThreadLocalSingleton.hh"
|
||||
namespace G4AutoDelete {
|
||||
template<class T>
|
||||
void Register( T* inst ) {
|
||||
|
||||
namespace G4AutoDelete
|
||||
{
|
||||
template <class T>
|
||||
void Register(T* inst)
|
||||
{
|
||||
static G4ThreadLocalSingleton<T> container;
|
||||
container.Register(inst);
|
||||
}
|
||||
}
|
||||
} // namespace G4AutoDelete
|
||||
|
||||
#endif //G4AUTODELETE_HH
|
||||
#endif
|
||||
|
||||
@@ -23,9 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// G4Autolock
|
||||
//
|
||||
// Class Description:
|
||||
//
|
||||
@@ -82,8 +80,8 @@
|
||||
// UnprotectedCode();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Author: Andrea Dotti (15 Feb 2013): First Implementation
|
||||
//
|
||||
// Update: Jonathan Madsen (9 Feb 2018): Replaced custom implementation
|
||||
@@ -121,7 +119,7 @@
|
||||
// - explicit operator bool() const noexcept;
|
||||
// - unique_lock& operator=(unique_lock&& other);
|
||||
//
|
||||
// ---------------------------------------------------------------
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
// Note that G4AutoLock is defined also for a sequential Geant4 build but below
|
||||
// regarding implementation (also found in G4Threading.hh)
|
||||
@@ -257,16 +255,16 @@ int main()
|
||||
}
|
||||
|
||||
**/
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4AUTOLOCK_HH
|
||||
#define G4AUTOLOCK_HH
|
||||
|
||||
#include "G4Threading.hh"
|
||||
|
||||
#include <mutex>
|
||||
#include <chrono>
|
||||
#include <system_error>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include <system_error>
|
||||
|
||||
// Note: Note that G4TemplateAutoLock by itself is not thread-safe and
|
||||
// cannot be shared among threads due to the locked switch
|
||||
@@ -274,275 +272,303 @@ int main()
|
||||
template <typename _Mutex_t>
|
||||
class G4TemplateAutoLock : public std::unique_lock<_Mutex_t>
|
||||
{
|
||||
public:
|
||||
//------------------------------------------------------------------------//
|
||||
// Some useful typedefs
|
||||
//------------------------------------------------------------------------//
|
||||
typedef std::unique_lock<_Mutex_t> unique_lock_t;
|
||||
typedef G4TemplateAutoLock<_Mutex_t> this_type;
|
||||
typedef typename unique_lock_t::mutex_type mutex_type;
|
||||
public:
|
||||
//------------------------------------------------------------------------//
|
||||
// Some useful typedefs
|
||||
//------------------------------------------------------------------------//
|
||||
typedef std::unique_lock<_Mutex_t> unique_lock_t;
|
||||
typedef G4TemplateAutoLock<_Mutex_t> this_type;
|
||||
typedef typename unique_lock_t::mutex_type mutex_type;
|
||||
|
||||
public:
|
||||
//------------------------------------------------------------------------//
|
||||
// STL-consistent reference form constructors
|
||||
//------------------------------------------------------------------------//
|
||||
public:
|
||||
//------------------------------------------------------------------------//
|
||||
// STL-consistent reference form constructors
|
||||
//------------------------------------------------------------------------//
|
||||
|
||||
// reference form is consistent with STL lock_guard types
|
||||
// Locks the associated mutex by calling m.lock(). The behavior is
|
||||
// undefined if the current thread already owns the mutex except when
|
||||
// the mutex is recursive
|
||||
G4TemplateAutoLock(mutex_type& _mutex)
|
||||
// reference form is consistent with STL lock_guard types
|
||||
// Locks the associated mutex by calling m.lock(). The behavior is
|
||||
// undefined if the current thread already owns the mutex except when
|
||||
// the mutex is recursive
|
||||
G4TemplateAutoLock(mutex_type& _mutex)
|
||||
: unique_lock_t(_mutex, std::defer_lock)
|
||||
{
|
||||
// call termination-safe locking. if serial, this call has no effect
|
||||
_lock_deferred();
|
||||
}
|
||||
{
|
||||
// call termination-safe locking. if serial, this call has no effect
|
||||
_lock_deferred();
|
||||
}
|
||||
|
||||
// Tries to lock the associated mutex by calling
|
||||
// m.try_lock_for(_timeout_duration). Blocks until specified
|
||||
// _timeout_duration has elapsed or the lock is acquired, whichever comes
|
||||
// first. May block for longer than _timeout_duration.
|
||||
template <typename Rep, typename Period>
|
||||
G4TemplateAutoLock(mutex_type& _mutex,
|
||||
const std::chrono::duration<Rep, Period>&
|
||||
_timeout_duration)
|
||||
// Tries to lock the associated mutex by calling
|
||||
// m.try_lock_for(_timeout_duration). Blocks until specified
|
||||
// _timeout_duration has elapsed or the lock is acquired, whichever comes
|
||||
// first. May block for longer than _timeout_duration.
|
||||
template <typename Rep, typename Period>
|
||||
G4TemplateAutoLock(
|
||||
mutex_type& _mutex,
|
||||
const std::chrono::duration<Rep, Period>& _timeout_duration)
|
||||
: unique_lock_t(_mutex, std::defer_lock)
|
||||
{
|
||||
// call termination-safe locking. if serial, this call has no effect
|
||||
_lock_deferred(_timeout_duration);
|
||||
}
|
||||
{
|
||||
// call termination-safe locking. if serial, this call has no effect
|
||||
_lock_deferred(_timeout_duration);
|
||||
}
|
||||
|
||||
// Tries to lock the associated mutex by calling
|
||||
// m.try_lock_until(_timeout_time). Blocks until specified _timeout_time has
|
||||
// been reached or the lock is acquired, whichever comes first. May block
|
||||
// for longer than until _timeout_time has been reached.
|
||||
template<typename Clock, typename Duration>
|
||||
G4TemplateAutoLock(mutex_type& _mutex,
|
||||
const std::chrono::time_point<Clock, Duration>&
|
||||
_timeout_time)
|
||||
// Tries to lock the associated mutex by calling
|
||||
// m.try_lock_until(_timeout_time). Blocks until specified _timeout_time has
|
||||
// been reached or the lock is acquired, whichever comes first. May block
|
||||
// for longer than until _timeout_time has been reached.
|
||||
template <typename Clock, typename Duration>
|
||||
G4TemplateAutoLock(
|
||||
mutex_type& _mutex,
|
||||
const std::chrono::time_point<Clock, Duration>& _timeout_time)
|
||||
: unique_lock_t(_mutex, std::defer_lock)
|
||||
{
|
||||
// call termination-safe locking. if serial, this call has no effect
|
||||
_lock_deferred(_timeout_time);
|
||||
}
|
||||
{
|
||||
// call termination-safe locking. if serial, this call has no effect
|
||||
_lock_deferred(_timeout_time);
|
||||
}
|
||||
|
||||
// Does not lock the associated mutex.
|
||||
G4TemplateAutoLock(mutex_type& _mutex, std::defer_lock_t _lock) noexcept
|
||||
// Does not lock the associated mutex.
|
||||
G4TemplateAutoLock(mutex_type& _mutex, std::defer_lock_t _lock) noexcept
|
||||
: unique_lock_t(_mutex, _lock)
|
||||
{ }
|
||||
{}
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
|
||||
// Tries to lock the associated mutex without blocking by calling
|
||||
// m.try_lock(). The behavior is undefined if the current thread already
|
||||
// owns the mutex except when the mutex is recursive.
|
||||
G4TemplateAutoLock(mutex_type& _mutex, std::try_to_lock_t _lock)
|
||||
// Tries to lock the associated mutex without blocking by calling
|
||||
// m.try_lock(). The behavior is undefined if the current thread already
|
||||
// owns the mutex except when the mutex is recursive.
|
||||
G4TemplateAutoLock(mutex_type& _mutex, std::try_to_lock_t _lock)
|
||||
: unique_lock_t(_mutex, _lock)
|
||||
{ }
|
||||
{}
|
||||
|
||||
// Assumes the calling thread already owns m
|
||||
G4TemplateAutoLock(mutex_type& _mutex, std::adopt_lock_t _lock)
|
||||
// Assumes the calling thread already owns m
|
||||
G4TemplateAutoLock(mutex_type& _mutex, std::adopt_lock_t _lock)
|
||||
: unique_lock_t(_mutex, _lock)
|
||||
{ }
|
||||
{}
|
||||
|
||||
#else
|
||||
|
||||
// serial dummy version (initializes unique_lock but does not lock)
|
||||
G4TemplateAutoLock(mutex_type& _mutex, std::try_to_lock_t)
|
||||
// serial dummy version (initializes unique_lock but does not lock)
|
||||
G4TemplateAutoLock(mutex_type& _mutex, std::try_to_lock_t)
|
||||
: unique_lock_t(_mutex, std::defer_lock)
|
||||
{ }
|
||||
{}
|
||||
|
||||
// serial dummy version (initializes unique_lock but does not lock)
|
||||
G4TemplateAutoLock(mutex_type& _mutex, std::adopt_lock_t)
|
||||
// serial dummy version (initializes unique_lock but does not lock)
|
||||
G4TemplateAutoLock(mutex_type& _mutex, std::adopt_lock_t)
|
||||
: unique_lock_t(_mutex, std::defer_lock)
|
||||
{ }
|
||||
{}
|
||||
|
||||
#endif // defined(G4MULTITHREADED)
|
||||
#endif // defined(G4MULTITHREADED)
|
||||
|
||||
public:
|
||||
//------------------------------------------------------------------------//
|
||||
// Backwards compatibility versions (constructor with pointer to mutex)
|
||||
//------------------------------------------------------------------------//
|
||||
G4TemplateAutoLock(mutex_type* _mutex)
|
||||
public:
|
||||
//------------------------------------------------------------------------//
|
||||
// Backwards compatibility versions (constructor with pointer to mutex)
|
||||
//------------------------------------------------------------------------//
|
||||
G4TemplateAutoLock(mutex_type* _mutex)
|
||||
: unique_lock_t(*_mutex, std::defer_lock)
|
||||
{
|
||||
// call termination-safe locking. if serial, this call has no effect
|
||||
_lock_deferred();
|
||||
}
|
||||
{
|
||||
// call termination-safe locking. if serial, this call has no effect
|
||||
_lock_deferred();
|
||||
}
|
||||
|
||||
G4TemplateAutoLock(mutex_type* _mutex, std::defer_lock_t _lock) noexcept
|
||||
G4TemplateAutoLock(mutex_type* _mutex, std::defer_lock_t _lock) noexcept
|
||||
: unique_lock_t(*_mutex, _lock)
|
||||
{ }
|
||||
{}
|
||||
|
||||
#if defined(G4MULTITHREADED)
|
||||
|
||||
G4TemplateAutoLock(mutex_type* _mutex, std::try_to_lock_t _lock)
|
||||
G4TemplateAutoLock(mutex_type* _mutex, std::try_to_lock_t _lock)
|
||||
: unique_lock_t(*_mutex, _lock)
|
||||
{ }
|
||||
{}
|
||||
|
||||
G4TemplateAutoLock(mutex_type* _mutex, std::adopt_lock_t _lock)
|
||||
G4TemplateAutoLock(mutex_type* _mutex, std::adopt_lock_t _lock)
|
||||
: unique_lock_t(*_mutex, _lock)
|
||||
{ }
|
||||
{}
|
||||
|
||||
#else // NOT defined(G4MULTITHREADED) -- i.e. serial
|
||||
#else // NOT defined(G4MULTITHREADED) -- i.e. serial
|
||||
|
||||
G4TemplateAutoLock(mutex_type* _mutex, std::try_to_lock_t)
|
||||
G4TemplateAutoLock(mutex_type* _mutex, std::try_to_lock_t)
|
||||
: unique_lock_t(*_mutex, std::defer_lock)
|
||||
{ }
|
||||
{}
|
||||
|
||||
G4TemplateAutoLock(mutex_type* _mutex, std::adopt_lock_t)
|
||||
G4TemplateAutoLock(mutex_type* _mutex, std::adopt_lock_t)
|
||||
: unique_lock_t(*_mutex, std::defer_lock)
|
||||
{ }
|
||||
{}
|
||||
|
||||
#endif // defined(G4MULTITHREADED)
|
||||
#endif // defined(G4MULTITHREADED)
|
||||
|
||||
public:
|
||||
//------------------------------------------------------------------------//
|
||||
// Non-constructor overloads
|
||||
//------------------------------------------------------------------------//
|
||||
public:
|
||||
//------------------------------------------------------------------------//
|
||||
// Non-constructor overloads
|
||||
//------------------------------------------------------------------------//
|
||||
|
||||
#if defined(G4MULTITHREADED)
|
||||
|
||||
// overload nothing
|
||||
// overload nothing
|
||||
|
||||
#else // NOT defined(G4MULTITHREADED) -- i.e. serial
|
||||
#else // NOT defined(G4MULTITHREADED) -- i.e. serial
|
||||
|
||||
// override unique lock member functions to keep from locking/unlocking
|
||||
// but does not override in polymorphic usage
|
||||
void lock() { }
|
||||
void unlock() { }
|
||||
bool try_lock() { return true; }
|
||||
// override unique lock member functions to keep from locking/unlocking
|
||||
// but does not override in polymorphic usage
|
||||
void lock() {}
|
||||
void unlock() {}
|
||||
bool try_lock() { return true; }
|
||||
|
||||
template <typename Rep, typename Period>
|
||||
bool try_lock_for(const std::chrono::duration<Rep, Period>&)
|
||||
{ return true; }
|
||||
template <typename Rep, typename Period>
|
||||
bool try_lock_for(const std::chrono::duration<Rep, Period>&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename Clock, typename Duration>
|
||||
bool try_lock_until(const std::chrono::time_point<Clock, Duration>&)
|
||||
{ return true; }
|
||||
template <typename Clock, typename Duration>
|
||||
bool try_lock_until(const std::chrono::time_point<Clock, Duration>&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void swap(this_type& other) noexcept { std::swap(*this, other); }
|
||||
bool owns_lock() const noexcept { return false; }
|
||||
void swap(this_type& other) noexcept { std::swap(*this, other); }
|
||||
bool owns_lock() const noexcept { return false; }
|
||||
|
||||
// no need to overload
|
||||
//explicit operator bool() const noexcept;
|
||||
//this_type& operator=(this_type&& other);
|
||||
//mutex_type* release() noexcept;
|
||||
//mutex_type* mutex() const noexcept;
|
||||
// no need to overload
|
||||
// explicit operator bool() const noexcept;
|
||||
// this_type& operator=(this_type&& other);
|
||||
// mutex_type* release() noexcept;
|
||||
// mutex_type* mutex() const noexcept;
|
||||
|
||||
#endif // defined(G4MULTITHREADED)
|
||||
#endif // defined(G4MULTITHREADED)
|
||||
|
||||
private:
|
||||
// helpful macros
|
||||
#define _is_stand_mutex(_Tp) (std::is_same<_Tp, G4Mutex>::value)
|
||||
#define _is_recur_mutex(_Tp) (std::is_same<_Tp, G4RecursiveMutex>::value)
|
||||
#define _is_other_mutex(_Tp) (! _is_stand_mutex(_Tp) && ! _is_recur_mutex(_Tp) )
|
||||
private:
|
||||
// helpful macros
|
||||
#define _is_stand_mutex(_Tp) (std::is_same<_Tp, G4Mutex>::value)
|
||||
#define _is_recur_mutex(_Tp) (std::is_same<_Tp, G4RecursiveMutex>::value)
|
||||
#define _is_other_mutex(_Tp) (!_is_stand_mutex(_Tp) && !_is_recur_mutex(_Tp))
|
||||
|
||||
template <typename _Tp = _Mutex_t,
|
||||
typename std::enable_if<_is_stand_mutex(_Tp), int>::type = 0>
|
||||
std::string GetTypeString() { return "G4AutoLock<G4Mutex>"; }
|
||||
template <typename _Tp = _Mutex_t,
|
||||
typename std::enable_if<_is_stand_mutex(_Tp), int>::type = 0>
|
||||
std::string GetTypeString()
|
||||
{
|
||||
return "G4AutoLock<G4Mutex>";
|
||||
}
|
||||
|
||||
template <typename _Tp = _Mutex_t,
|
||||
typename std::enable_if<_is_recur_mutex(_Tp), int>::type = 0>
|
||||
std::string GetTypeString() { return "G4AutoLock<G4RecursiveMutex>"; }
|
||||
template <typename _Tp = _Mutex_t,
|
||||
typename std::enable_if<_is_recur_mutex(_Tp), int>::type = 0>
|
||||
std::string GetTypeString()
|
||||
{
|
||||
return "G4AutoLock<G4RecursiveMutex>";
|
||||
}
|
||||
|
||||
template <typename _Tp = _Mutex_t,
|
||||
typename std::enable_if<_is_other_mutex(_Tp), int>::type = 0>
|
||||
std::string GetTypeString() { return "G4AutoLock<UNKNOWN_MUTEX>"; }
|
||||
template <typename _Tp = _Mutex_t,
|
||||
typename std::enable_if<_is_other_mutex(_Tp), int>::type = 0>
|
||||
std::string GetTypeString()
|
||||
{
|
||||
return "G4AutoLock<UNKNOWN_MUTEX>";
|
||||
}
|
||||
|
||||
// pollution is bad
|
||||
#undef _is_stand_mutex
|
||||
#undef _is_recur_mutex
|
||||
#undef _is_other_mutex
|
||||
// pollution is bad
|
||||
#undef _is_stand_mutex
|
||||
#undef _is_recur_mutex
|
||||
#undef _is_other_mutex
|
||||
|
||||
// used in _lock_deferred chrono variants to avoid ununsed-variable warning
|
||||
template <typename _Tp>
|
||||
void suppress_unused_variable(const _Tp&) { }
|
||||
// used in _lock_deferred chrono variants to avoid ununsed-variable warning
|
||||
template <typename _Tp>
|
||||
void suppress_unused_variable(const _Tp&)
|
||||
{}
|
||||
|
||||
//========================================================================//
|
||||
// NOTE on _lock_deferred(...) variants:
|
||||
// a system_error in lock means that the mutex is unavailable
|
||||
// we want to throw the error that comes from locking an unavailable
|
||||
// mutex so that we know there is a memory leak
|
||||
// if the mutex is valid, this will hold until the other thread
|
||||
// finishes
|
||||
//========================================================================//
|
||||
// NOTE on _lock_deferred(...) variants:
|
||||
// a system_error in lock means that the mutex is unavailable
|
||||
// we want to throw the error that comes from locking an unavailable
|
||||
// mutex so that we know there is a memory leak
|
||||
// if the mutex is valid, this will hold until the other thread
|
||||
// finishes
|
||||
|
||||
// sometimes certain destructors use locks, this isn't an issue unless
|
||||
// the object is leaked. When this occurs, the application finalization
|
||||
// (i.e. the real or implied "return 0" part of main) will call destructors
|
||||
// on Geant4 object after some static mutex variables are deleted, leading
|
||||
// to the error code (typically on Clang compilers):
|
||||
// libc++abi.dylib: terminating with uncaught exception of type
|
||||
// std::__1::system_error: mutex lock failed: Invalid argument
|
||||
// this function protects against this failure until such a time that
|
||||
// these issues have been resolved
|
||||
// sometimes certain destructors use locks, this isn't an issue unless
|
||||
// the object is leaked. When this occurs, the application finalization
|
||||
// (i.e. the real or implied "return 0" part of main) will call destructors
|
||||
// on Geant4 object after some static mutex variables are deleted, leading
|
||||
// to the error code (typically on Clang compilers):
|
||||
// libc++abi.dylib: terminating with uncaught exception of type
|
||||
// std::__1::system_error: mutex lock failed: Invalid argument
|
||||
// this function protects against this failure until such a time that
|
||||
// these issues have been resolved
|
||||
|
||||
//========================================================================//
|
||||
// standard locking
|
||||
inline void _lock_deferred()
|
||||
//========================================================================//
|
||||
// standard locking
|
||||
inline void _lock_deferred()
|
||||
{
|
||||
#if defined(G4MULTITHREADED)
|
||||
try
|
||||
{
|
||||
#if defined(G4MULTITHREADED)
|
||||
try { this->unique_lock_t::lock(); }
|
||||
catch (std::system_error& e) { PrintLockErrorMessage(e); }
|
||||
#endif
|
||||
}
|
||||
|
||||
//========================================================================//
|
||||
// Tries to lock the associated mutex by calling
|
||||
// m.try_lock_for(_timeout_duration). Blocks until specified
|
||||
// _timeout_duration has elapsed or the lock is acquired, whichever comes
|
||||
// first. May block for longer than _timeout_duration.
|
||||
template <typename Rep, typename Period>
|
||||
void _lock_deferred(const std::chrono::duration<Rep, Period>&
|
||||
_timeout_duration)
|
||||
this->unique_lock_t::lock();
|
||||
} catch(std::system_error& e)
|
||||
{
|
||||
#if defined(G4MULTITHREADED)
|
||||
try { this->unique_lock_t::try_lock_for(_timeout_duration); }
|
||||
catch (std::system_error& e) { PrintLockErrorMessage(e); }
|
||||
#else
|
||||
suppress_unused_variable(_timeout_duration);
|
||||
#endif
|
||||
PrintLockErrorMessage(e);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//========================================================================//
|
||||
// Tries to lock the associated mutex by calling
|
||||
// m.try_lock_until(_timeout_time). Blocks until specified _timeout_time has
|
||||
// been reached or the lock is acquired, whichever comes first. May block
|
||||
// for longer than until _timeout_time has been reached.
|
||||
template<typename Clock, typename Duration>
|
||||
void _lock_deferred(const std::chrono::time_point<Clock, Duration>&
|
||||
_timeout_time)
|
||||
//========================================================================//
|
||||
// Tries to lock the associated mutex by calling
|
||||
// m.try_lock_for(_timeout_duration). Blocks until specified
|
||||
// _timeout_duration has elapsed or the lock is acquired, whichever comes
|
||||
// first. May block for longer than _timeout_duration.
|
||||
template <typename Rep, typename Period>
|
||||
void _lock_deferred(
|
||||
const std::chrono::duration<Rep, Period>& _timeout_duration)
|
||||
{
|
||||
#if defined(G4MULTITHREADED)
|
||||
try
|
||||
{
|
||||
#if defined(G4MULTITHREADED)
|
||||
try { this->unique_lock_t::try_lock_until(_timeout_time); }
|
||||
catch (std::system_error& e) { PrintLockErrorMessage(e); }
|
||||
#else
|
||||
suppress_unused_variable(_timeout_time);
|
||||
#endif
|
||||
}
|
||||
|
||||
//========================================================================//
|
||||
// the message for what mutex lock fails due to deleted static mutex
|
||||
// at termination
|
||||
void PrintLockErrorMessage(std::system_error& e)
|
||||
this->unique_lock_t::try_lock_for(_timeout_duration);
|
||||
} catch(std::system_error& e)
|
||||
{
|
||||
// use std::cout/std::endl to avoid include dependencies
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
// the error that comes from locking an unavailable mutex
|
||||
#if defined(G4VERBOSE)
|
||||
cout << "Non-critical error: mutex lock failure in "
|
||||
<< GetTypeString<mutex_type>() << ". "
|
||||
<< "If the app is terminating, Geant4 failed to "
|
||||
<< "delete an allocated resource and a Geant4 destructor is "
|
||||
<< "being called after the statics were destroyed. \n\t--> "
|
||||
<< "Exception: [code: " << e.code() << "] caught: "
|
||||
<< e.what() << endl;
|
||||
#else
|
||||
suppress_unused_variable(e);
|
||||
#endif
|
||||
PrintLockErrorMessage(e);
|
||||
}
|
||||
#else
|
||||
suppress_unused_variable(_timeout_duration);
|
||||
#endif
|
||||
}
|
||||
|
||||
//========================================================================//
|
||||
// Tries to lock the associated mutex by calling
|
||||
// m.try_lock_until(_timeout_time). Blocks until specified _timeout_time has
|
||||
// been reached or the lock is acquired, whichever comes first. May block
|
||||
// for longer than until _timeout_time has been reached.
|
||||
template <typename Clock, typename Duration>
|
||||
void _lock_deferred(
|
||||
const std::chrono::time_point<Clock, Duration>& _timeout_time)
|
||||
{
|
||||
#if defined(G4MULTITHREADED)
|
||||
try
|
||||
{
|
||||
this->unique_lock_t::try_lock_until(_timeout_time);
|
||||
} catch(std::system_error& e)
|
||||
{
|
||||
PrintLockErrorMessage(e);
|
||||
}
|
||||
#else
|
||||
suppress_unused_variable(_timeout_time);
|
||||
#endif
|
||||
}
|
||||
|
||||
//========================================================================//
|
||||
// the message for what mutex lock fails due to deleted static mutex
|
||||
// at termination
|
||||
void PrintLockErrorMessage(std::system_error& e)
|
||||
{
|
||||
// use std::cout/std::endl to avoid include dependencies
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
// the error that comes from locking an unavailable mutex
|
||||
#if defined(G4VERBOSE)
|
||||
cout << "Non-critical error: mutex lock failure in "
|
||||
<< GetTypeString<mutex_type>() << ". "
|
||||
<< "If the app is terminating, Geant4 failed to "
|
||||
<< "delete an allocated resource and a Geant4 destructor is "
|
||||
<< "being called after the statics were destroyed. \n\t--> "
|
||||
<< "Exception: [code: " << e.code() << "] caught: " << e.what()
|
||||
<< endl;
|
||||
#else
|
||||
suppress_unused_variable(e);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
@@ -553,11 +579,12 @@ private:
|
||||
//
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
||||
typedef G4TemplateAutoLock<G4Mutex> G4AutoLock;
|
||||
typedef G4TemplateAutoLock<G4RecursiveMutex> G4RecursiveAutoLock;
|
||||
using G4AutoLock = G4TemplateAutoLock<G4Mutex>;
|
||||
using G4RecursiveAutoLock = G4TemplateAutoLock<G4RecursiveMutex>;
|
||||
|
||||
// provide abbriviated type if another mutex type is desired to be used
|
||||
// aside from above
|
||||
template <typename _Tp> using G4TAutoLock = G4TemplateAutoLock<_Tp>;
|
||||
template <typename _Tp>
|
||||
using G4TAutoLock = G4TemplateAutoLock<_Tp>;
|
||||
|
||||
#endif //G4AUTOLOCK_HH
|
||||
#endif // G4AUTOLOCK_HH
|
||||
|
||||
@@ -23,11 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// G4BuffercoutDestination
|
||||
//
|
||||
// Class Description:
|
||||
//
|
||||
@@ -37,10 +33,10 @@
|
||||
|
||||
// ---------------- G4BuffercoutDestination ----------------
|
||||
//
|
||||
// Author: A.Dotti (SLAC), April 2017
|
||||
// Author: A.Dotti (SLAC), 14 April 2017
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4BUFFERCOUTDESTINATION_HH_
|
||||
#define G4BUFFERCOUTDESTINATION_HH_
|
||||
#ifndef G4BUFFERCOUTDESTINATION_HH
|
||||
#define G4BUFFERCOUTDESTINATION_HH
|
||||
|
||||
#include <sstream>
|
||||
|
||||
@@ -48,38 +44,36 @@
|
||||
|
||||
class G4BuffercoutDestination : public G4coutDestination
|
||||
{
|
||||
public:
|
||||
public:
|
||||
explicit G4BuffercoutDestination(std::size_t maxSize = 0);
|
||||
virtual ~G4BuffercoutDestination();
|
||||
|
||||
explicit G4BuffercoutDestination(size_t maxSize = 0);
|
||||
virtual ~G4BuffercoutDestination();
|
||||
virtual G4int ReceiveG4cout(const G4String& msg) override;
|
||||
virtual G4int ReceiveG4cerr(const G4String& msg) override;
|
||||
// Flush buffer to std output
|
||||
virtual G4int FlushG4cout();
|
||||
// Flush buffer to std error
|
||||
virtual G4int FlushG4cerr();
|
||||
// Flsuh both buffers
|
||||
|
||||
virtual G4int ReceiveG4cout(const G4String& msg) override;
|
||||
virtual G4int ReceiveG4cerr(const G4String& msg) override;
|
||||
// Flush buffer to std output
|
||||
virtual G4int FlushG4cout();
|
||||
// Flush buffer to std error
|
||||
virtual G4int FlushG4cerr();
|
||||
// Flsuh both buffers
|
||||
virtual void Finalize();
|
||||
|
||||
virtual void Finalize();
|
||||
// Set maximum size of buffer, when buffer grows to specified size,
|
||||
// it will trigger flush. Dimension in char
|
||||
void SetMaxSize(std::size_t max) { m_maxSize = max; }
|
||||
std::size_t GetMaxSize() const { return m_maxSize; }
|
||||
std::size_t GetCurrentSizeOut() const { return m_currentSize_out; }
|
||||
std::size_t GetCurrentSizeErr() const { return m_currentSize_err; }
|
||||
|
||||
// Set maximum size of buffer, when buffer grows to specified size,
|
||||
// it will trigger flush. Dimension in char
|
||||
void SetMaxSize(size_t max) { m_maxSize = max; }
|
||||
size_t GetMaxSize() const { return m_maxSize; }
|
||||
size_t GetCurrentSizeOut() const { return m_currentSize_out; }
|
||||
size_t GetCurrentSizeErr() const { return m_currentSize_err; }
|
||||
protected:
|
||||
void ResetCout();
|
||||
void ResetCerr();
|
||||
|
||||
protected:
|
||||
|
||||
void ResetCout();
|
||||
void ResetCerr();
|
||||
|
||||
std::ostringstream m_buffer_out;
|
||||
std::ostringstream m_buffer_err;
|
||||
size_t m_currentSize_out;
|
||||
size_t m_currentSize_err;
|
||||
size_t m_maxSize;
|
||||
std::ostringstream m_buffer_out;
|
||||
std::ostringstream m_buffer_err;
|
||||
std::size_t m_currentSize_out = 0;
|
||||
std::size_t m_currentSize_err = 0;
|
||||
std::size_t m_maxSize = 0;
|
||||
};
|
||||
|
||||
#endif /* G4BUFFERCOUTDESTINATION_HH_ */
|
||||
#endif
|
||||
|
||||
@@ -23,11 +23,10 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// G4Cache
|
||||
//
|
||||
// Class Description:
|
||||
//
|
||||
// Helper classes for Geant4 Multi-Threaded.
|
||||
// The classes defined in this header file provide a thread-private
|
||||
// cache to store a thread-local variable V in a class instance
|
||||
@@ -68,426 +67,422 @@
|
||||
//
|
||||
// See classes definition for details.
|
||||
|
||||
// History:
|
||||
// 21 October 2013: A. Dotti - First implementation
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
// Author: A.Dotti, 21 October 2013 - First implementation
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4CACHE_HH
|
||||
#define G4CACHE_HH
|
||||
|
||||
// Debug this code
|
||||
// #define g4cdebug 1
|
||||
|
||||
#include <system_error>
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
#include <system_error>
|
||||
|
||||
#include "G4AutoLock.hh"
|
||||
#include "G4CacheDetails.hh" // Thread Local storage details are here
|
||||
|
||||
// A templated cache to store a thread-private data of type VALTYPE.
|
||||
//
|
||||
template<class VALTYPE>
|
||||
template <class VALTYPE>
|
||||
class G4Cache
|
||||
{
|
||||
public:
|
||||
public:
|
||||
typedef VALTYPE value_type;
|
||||
// The stored type
|
||||
|
||||
typedef VALTYPE value_type;
|
||||
// The stored type
|
||||
|
||||
G4Cache();
|
||||
// Default constructor
|
||||
|
||||
G4Cache(const value_type& v);
|
||||
// Construct cache object with initial value
|
||||
G4Cache();
|
||||
// Default constructor
|
||||
|
||||
virtual ~G4Cache();
|
||||
// Default destructor
|
||||
|
||||
inline value_type& Get() const;
|
||||
// Gets reference to cached value of this threads
|
||||
|
||||
inline void Put( const value_type& val ) const;
|
||||
// Sets this thread cached value to val
|
||||
G4Cache(const value_type& v);
|
||||
// Construct cache object with initial value
|
||||
|
||||
inline value_type Pop();
|
||||
// Gets copy of cached value
|
||||
|
||||
G4Cache(const G4Cache& rhs);
|
||||
G4Cache& operator=(const G4Cache& rhs);
|
||||
virtual ~G4Cache();
|
||||
// Default destructor
|
||||
|
||||
protected:
|
||||
inline value_type& Get() const;
|
||||
// Gets reference to cached value of this threads
|
||||
|
||||
const G4int& GetId() const { return id; }
|
||||
inline void Put(const value_type& val) const;
|
||||
// Sets this thread cached value to val
|
||||
|
||||
private:
|
||||
inline value_type Pop();
|
||||
// Gets copy of cached value
|
||||
|
||||
G4int id;
|
||||
mutable G4CacheReference<value_type> theCache;
|
||||
static std::atomic<unsigned int> instancesctr;
|
||||
static std::atomic<unsigned int> dstrctr;
|
||||
G4Cache(const G4Cache& rhs);
|
||||
G4Cache& operator=(const G4Cache& rhs);
|
||||
|
||||
inline value_type& GetCache() const
|
||||
{
|
||||
theCache.Initialize(id);
|
||||
return theCache.GetCache(id);
|
||||
}
|
||||
protected:
|
||||
const G4int& GetId() const { return id; }
|
||||
|
||||
private:
|
||||
G4int id;
|
||||
mutable G4CacheReference<value_type> theCache;
|
||||
static std::atomic<unsigned int> instancesctr;
|
||||
static std::atomic<unsigned int> dstrctr;
|
||||
|
||||
inline value_type& GetCache() const
|
||||
{
|
||||
theCache.Initialize(id);
|
||||
return theCache.GetCache(id);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// A vector version of the cache. Implements vector interface.
|
||||
// Can be used directly as a std::vector would be used.
|
||||
//
|
||||
template<class VALTYPE>
|
||||
class G4VectorCache : public G4Cache< std::vector<VALTYPE> >
|
||||
template <class VALTYPE>
|
||||
class G4VectorCache : public G4Cache<std::vector<VALTYPE>>
|
||||
{
|
||||
public:
|
||||
public:
|
||||
// Some useful definitions
|
||||
//
|
||||
typedef VALTYPE value_type;
|
||||
typedef typename std::vector<value_type> vector_type;
|
||||
typedef typename vector_type::size_type size_type;
|
||||
typedef typename vector_type::iterator iterator;
|
||||
typedef typename vector_type::const_iterator const_iterator;
|
||||
|
||||
// Some useful definitions
|
||||
//
|
||||
typedef VALTYPE value_type;
|
||||
typedef typename std::vector<value_type> vector_type;
|
||||
typedef typename vector_type::size_type size_type;
|
||||
typedef typename vector_type::iterator iterator;
|
||||
typedef typename vector_type::const_iterator const_iterator;
|
||||
G4VectorCache();
|
||||
// Default constructor
|
||||
|
||||
G4VectorCache();
|
||||
// Default constructor
|
||||
|
||||
G4VectorCache( G4int nElems );
|
||||
// Creates a vector cache of nElems elements
|
||||
|
||||
G4VectorCache( G4int nElems , value_type* vals );
|
||||
// Creates a vector cache with elements from an array
|
||||
|
||||
virtual ~G4VectorCache();
|
||||
// Default destructor
|
||||
G4VectorCache(G4int nElems);
|
||||
// Creates a vector cache of nElems elements
|
||||
|
||||
// Interface with functionalities of similar name of std::vector
|
||||
//
|
||||
inline void Push_back( const value_type& val );
|
||||
inline value_type Pop_back();
|
||||
inline value_type& operator[](const G4int& idx);
|
||||
inline iterator Begin();
|
||||
inline iterator End();
|
||||
inline void Clear();
|
||||
inline size_type Size() { return G4Cache<vector_type>::Get().size(); }
|
||||
// Needs to be here for a VC9 compilation problem
|
||||
G4VectorCache(G4int nElems, value_type* vals);
|
||||
// Creates a vector cache with elements from an array
|
||||
|
||||
virtual ~G4VectorCache();
|
||||
// Default destructor
|
||||
|
||||
// Interface with functionalities of similar name of std::vector
|
||||
//
|
||||
inline void Push_back(const value_type& val);
|
||||
inline value_type Pop_back();
|
||||
inline value_type& operator[](const G4int& idx);
|
||||
inline iterator Begin();
|
||||
inline iterator End();
|
||||
inline void Clear();
|
||||
inline size_type Size() { return G4Cache<vector_type>::Get().size(); }
|
||||
// Needs to be here for a VC9 compilation problem
|
||||
};
|
||||
|
||||
|
||||
// a Map version of the cache. Implements std::map interface.
|
||||
// Can be used directly as a std::map would be used.
|
||||
// KEYTYPE being the key type and VALTYPE the value type.
|
||||
//
|
||||
template<class KEYTYPE, class VALTYPE>
|
||||
class G4MapCache : public G4Cache<std::map<KEYTYPE,VALTYPE> >
|
||||
template <class KEYTYPE, class VALTYPE>
|
||||
class G4MapCache : public G4Cache<std::map<KEYTYPE, VALTYPE>>
|
||||
{
|
||||
public:
|
||||
public:
|
||||
// Some useful definitions
|
||||
//
|
||||
typedef KEYTYPE key_type;
|
||||
typedef VALTYPE value_type;
|
||||
typedef typename std::map<key_type, value_type> map_type;
|
||||
typedef typename map_type::size_type size_type;
|
||||
typedef typename map_type::iterator iterator;
|
||||
typedef typename map_type::const_iterator const_iterator;
|
||||
|
||||
// Some useful definitions
|
||||
//
|
||||
typedef KEYTYPE key_type;
|
||||
typedef VALTYPE value_type;
|
||||
typedef typename std::map<key_type,value_type> map_type;
|
||||
typedef typename map_type::size_type size_type;
|
||||
typedef typename map_type::iterator iterator;
|
||||
typedef typename map_type::const_iterator const_iterator;
|
||||
virtual ~G4MapCache();
|
||||
// Default destructor
|
||||
|
||||
virtual ~G4MapCache();
|
||||
// Default destructor
|
||||
inline G4bool Has(const key_type& k);
|
||||
// Returns true if map contains element corresponding to key k
|
||||
|
||||
inline G4bool Has(const key_type& k );
|
||||
// Returns true if map contains element corresponding to key k
|
||||
|
||||
// Interface with functionalities of similar name of std::map
|
||||
//
|
||||
inline std::pair<iterator,G4bool> Insert( const key_type& k ,
|
||||
const value_type& v );
|
||||
inline iterator Begin();
|
||||
inline iterator End();
|
||||
inline iterator Find(const key_type& k );
|
||||
inline value_type& Get(const key_type& k );
|
||||
inline size_type Erase(const key_type& k );
|
||||
inline value_type& operator[](const key_type& k);
|
||||
inline size_type Size() { return G4Cache<map_type>::Get().size(); }
|
||||
// Needs to be here for a VC9 compilation problem
|
||||
// Interface with functionalities of similar name of std::map
|
||||
//
|
||||
inline std::pair<iterator, G4bool> Insert(const key_type& k,
|
||||
const value_type& v);
|
||||
inline iterator Begin();
|
||||
inline iterator End();
|
||||
inline iterator Find(const key_type& k);
|
||||
inline value_type& Get(const key_type& k);
|
||||
inline size_type Erase(const key_type& k);
|
||||
inline value_type& operator[](const key_type& k);
|
||||
inline size_type Size() { return G4Cache<map_type>::Get().size(); }
|
||||
// Needs to be here for a VC9 compilation problem
|
||||
};
|
||||
|
||||
|
||||
//========= Implementation: G4Cache<V> ====================================
|
||||
|
||||
template<class V>
|
||||
template <class V>
|
||||
G4Cache<V>::G4Cache()
|
||||
{
|
||||
G4AutoLock l(G4TypeMutex<G4Cache<V>>());
|
||||
id = instancesctr++;
|
||||
G4AutoLock l(G4TypeMutex<G4Cache<V>>());
|
||||
id = instancesctr++;
|
||||
#ifdef g4cdebug
|
||||
std::cout << "G4Cache id: " << id << std::endl;
|
||||
std::cout << "G4Cache id: " << id << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class V>
|
||||
template <class V>
|
||||
G4Cache<V>::G4Cache(const G4Cache<V>& rhs)
|
||||
{
|
||||
// Copy is special, we need to copy the content
|
||||
// of the cache, not the cache object
|
||||
// Copy is special, we need to copy the content
|
||||
// of the cache, not the cache object
|
||||
|
||||
if ( this == &rhs ) return;
|
||||
G4AutoLock l(G4TypeMutex<G4Cache<V>>());
|
||||
id = instancesctr++;
|
||||
if(this == &rhs)
|
||||
return;
|
||||
G4AutoLock l(G4TypeMutex<G4Cache<V>>());
|
||||
id = instancesctr++;
|
||||
|
||||
// Force copy of cached data
|
||||
//
|
||||
V aCopy = rhs.GetCache();
|
||||
Put( aCopy );
|
||||
// Force copy of cached data
|
||||
//
|
||||
V aCopy = rhs.GetCache();
|
||||
Put(aCopy);
|
||||
|
||||
#ifdef g4cdebug
|
||||
std::cout << "Copy constructor with id: " << id << std::endl;
|
||||
std::cout << "Copy constructor with id: " << id << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class V>
|
||||
template <class V>
|
||||
G4Cache<V>& G4Cache<V>::operator=(const G4Cache<V>& rhs)
|
||||
{
|
||||
if (this == &rhs) return *this;
|
||||
if(this == &rhs)
|
||||
return *this;
|
||||
|
||||
// Force copy of cached data
|
||||
//
|
||||
V aCopy = rhs.GetCache();
|
||||
Put(aCopy);
|
||||
// Force copy of cached data
|
||||
//
|
||||
V aCopy = rhs.GetCache();
|
||||
Put(aCopy);
|
||||
|
||||
#ifdef g4cdebug
|
||||
std::cout << "Assignement operator with id: " << id << std::endl;
|
||||
std::cout << "Assignement operator with id: " << id << std::endl;
|
||||
#endif
|
||||
return *this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class V>
|
||||
template <class V>
|
||||
G4Cache<V>::G4Cache(const V& v)
|
||||
{
|
||||
G4AutoLock l(G4TypeMutex<G4Cache<V>>());
|
||||
id = instancesctr++;
|
||||
Put(v);
|
||||
G4AutoLock l(G4TypeMutex<G4Cache<V>>());
|
||||
id = instancesctr++;
|
||||
Put(v);
|
||||
|
||||
#ifdef g4cdebug
|
||||
std::cout << "G4Cache id: " << id << std::endl;
|
||||
std::cout << "G4Cache id: " << id << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class V>
|
||||
template <class V>
|
||||
G4Cache<V>::~G4Cache()
|
||||
{
|
||||
#ifdef g4cdebug
|
||||
std::cout << "~G4Cache id: " << id << std::endl;
|
||||
std::cout << "~G4Cache id: " << id << std::endl;
|
||||
#endif
|
||||
// don't automatically lock --> wait until we can catch an error
|
||||
// without scoping the G4AutoLock
|
||||
//
|
||||
G4AutoLock l(G4TypeMutex<G4Cache<V>>(), std::defer_lock);
|
||||
// don't automatically lock --> wait until we can catch an error
|
||||
// without scoping the G4AutoLock
|
||||
//
|
||||
G4AutoLock l(G4TypeMutex<G4Cache<V>>(), std::defer_lock);
|
||||
|
||||
// sometimes the mutex is unavailable in destructors so
|
||||
// try to lock the associated mutex, but catch if it fails
|
||||
try
|
||||
{
|
||||
// a system_error in lock means that the mutex is unavailable
|
||||
// we want to throw the error that comes from locking an unavailable
|
||||
// mutex so that we know there is a memory leak
|
||||
// if the mutex is valid, this will hold until the other thread finishes
|
||||
//
|
||||
l.lock();
|
||||
}
|
||||
catch (std::system_error& e)
|
||||
{
|
||||
// the error that comes from locking an unavailable mutex
|
||||
// sometimes the mutex is unavailable in destructors so
|
||||
// try to lock the associated mutex, but catch if it fails
|
||||
try
|
||||
{
|
||||
// a system_error in lock means that the mutex is unavailable
|
||||
// we want to throw the error that comes from locking an unavailable
|
||||
// mutex so that we know there is a memory leak
|
||||
// if the mutex is valid, this will hold until the other thread finishes
|
||||
//
|
||||
l.lock();
|
||||
} catch(std::system_error& e)
|
||||
{
|
||||
// the error that comes from locking an unavailable mutex
|
||||
#ifdef G4VERBOSE
|
||||
G4cout << "Non-critical error: mutex lock failure in ~G4Cache<"
|
||||
<< typeid(V).name() << ">. " << G4endl
|
||||
<< "If the RunManagerKernel has been deleted, it failed to "
|
||||
<< "delete an allocated resource" << G4endl
|
||||
<< "and this destructor is being called after the statics "
|
||||
<< "were destroyed." << G4endl;
|
||||
G4cout << "Exception: [code: " << e.code() << "] caught: "
|
||||
<< e.what() << G4endl;
|
||||
G4cout << "Non-critical error: mutex lock failure in ~G4Cache<"
|
||||
<< typeid(V).name() << ">. " << G4endl
|
||||
<< "If the RunManagerKernel has been deleted, it failed to "
|
||||
<< "delete an allocated resource" << G4endl
|
||||
<< "and this destructor is being called after the statics "
|
||||
<< "were destroyed." << G4endl;
|
||||
G4cout << "Exception: [code: " << e.code() << "] caught: " << e.what()
|
||||
<< G4endl;
|
||||
#endif
|
||||
}
|
||||
++dstrctr;
|
||||
G4bool last = ( dstrctr == instancesctr );
|
||||
theCache.Destroy(id, last);
|
||||
if (last)
|
||||
{
|
||||
instancesctr.store(0);
|
||||
dstrctr.store(0);
|
||||
}
|
||||
}
|
||||
++dstrctr;
|
||||
G4bool last = (dstrctr == instancesctr);
|
||||
theCache.Destroy(id, last);
|
||||
if(last)
|
||||
{
|
||||
instancesctr.store(0);
|
||||
dstrctr.store(0);
|
||||
}
|
||||
}
|
||||
|
||||
template<class V>
|
||||
template <class V>
|
||||
V& G4Cache<V>::Get() const
|
||||
{ return GetCache(); }
|
||||
{
|
||||
return GetCache();
|
||||
}
|
||||
|
||||
template<class V>
|
||||
void G4Cache<V>::Put( const V& val ) const
|
||||
{ GetCache() = val; }
|
||||
template <class V>
|
||||
void G4Cache<V>::Put(const V& val) const
|
||||
{
|
||||
GetCache() = val;
|
||||
}
|
||||
|
||||
// Should here remove from cache element?
|
||||
template<class V>
|
||||
template <class V>
|
||||
V G4Cache<V>::Pop()
|
||||
{ return GetCache(); }
|
||||
{
|
||||
return GetCache();
|
||||
}
|
||||
|
||||
template<class V>
|
||||
template <class V>
|
||||
std::atomic<unsigned int> G4Cache<V>::instancesctr(0);
|
||||
|
||||
template<class V>
|
||||
template <class V>
|
||||
std::atomic<unsigned int> G4Cache<V>::dstrctr(0);
|
||||
|
||||
|
||||
//========== Implementation: G4VectorCache<V> ===========================
|
||||
|
||||
template<class V>
|
||||
template <class V>
|
||||
G4VectorCache<V>::G4VectorCache()
|
||||
{ }
|
||||
{}
|
||||
|
||||
template<class V>
|
||||
template <class V>
|
||||
G4VectorCache<V>::~G4VectorCache()
|
||||
{
|
||||
#ifdef g4cdebug
|
||||
std::cout << "~G4VectorCache "
|
||||
<< G4Cache<G4VectorCache<V>::vector_type>::GetId()
|
||||
<< " with size: " << Size() << "->";
|
||||
for ( size_type i = 0 ; i < Size() ; ++i )
|
||||
std::cout << operator[](i) << ",";
|
||||
std::cout << "<-" << std::endl;
|
||||
std::cout << "~G4VectorCache "
|
||||
<< G4Cache<G4VectorCache<V>::vector_type>::GetId()
|
||||
<< " with size: " << Size() << "->";
|
||||
for(size_type i = 0; i < Size(); ++i)
|
||||
std::cout << operator[](i) << ",";
|
||||
std::cout << "<-" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class V>
|
||||
G4VectorCache<V>::G4VectorCache(G4int nElems )
|
||||
template <class V>
|
||||
G4VectorCache<V>::G4VectorCache(G4int nElems)
|
||||
{
|
||||
vector_type& cc = G4Cache<vector_type>::Get();
|
||||
cc.resize(nElems);
|
||||
vector_type& cc = G4Cache<vector_type>::Get();
|
||||
cc.resize(nElems);
|
||||
}
|
||||
|
||||
template<class V>
|
||||
G4VectorCache<V>::G4VectorCache(G4int nElems , V* vals )
|
||||
template <class V>
|
||||
G4VectorCache<V>::G4VectorCache(G4int nElems, V* vals)
|
||||
{
|
||||
vector_type& cc = G4Cache<vector_type>::Get();
|
||||
cc.resize(nElems);
|
||||
for ( G4int idx = 0 ; idx < nElems ; ++idx )
|
||||
cc[idx]=vals[idx];
|
||||
vector_type& cc = G4Cache<vector_type>::Get();
|
||||
cc.resize(nElems);
|
||||
for(G4int idx = 0; idx < nElems; ++idx)
|
||||
cc[idx] = vals[idx];
|
||||
}
|
||||
|
||||
template<class V>
|
||||
void G4VectorCache<V>::Push_back( const V& val )
|
||||
template <class V>
|
||||
void G4VectorCache<V>::Push_back(const V& val)
|
||||
{
|
||||
G4Cache<vector_type>::Get().push_back( val );
|
||||
G4Cache<vector_type>::Get().push_back(val);
|
||||
}
|
||||
|
||||
template<class V>
|
||||
template <class V>
|
||||
V G4VectorCache<V>::Pop_back()
|
||||
{
|
||||
vector_type& cc = G4Cache<vector_type>::Get();
|
||||
value_type val = cc[cc.size()-1];
|
||||
cc.pop_back();
|
||||
return val;
|
||||
vector_type& cc = G4Cache<vector_type>::Get();
|
||||
value_type val = cc[cc.size() - 1];
|
||||
cc.pop_back();
|
||||
return val;
|
||||
}
|
||||
|
||||
template<class V>
|
||||
template <class V>
|
||||
V& G4VectorCache<V>::operator[](const G4int& idx)
|
||||
{
|
||||
vector_type& cc = G4Cache<vector_type>::Get();
|
||||
return cc[idx];
|
||||
vector_type& cc = G4Cache<vector_type>::Get();
|
||||
return cc[idx];
|
||||
}
|
||||
|
||||
template<class V>
|
||||
template <class V>
|
||||
typename G4VectorCache<V>::iterator G4VectorCache<V>::Begin()
|
||||
{
|
||||
return G4Cache<vector_type>::Get().begin();
|
||||
return G4Cache<vector_type>::Get().begin();
|
||||
}
|
||||
|
||||
template<class V>
|
||||
template <class V>
|
||||
typename G4VectorCache<V>::iterator G4VectorCache<V>::End()
|
||||
{
|
||||
return G4Cache<vector_type>::Get().end();
|
||||
return G4Cache<vector_type>::Get().end();
|
||||
}
|
||||
|
||||
template<class V>
|
||||
template <class V>
|
||||
void G4VectorCache<V>::Clear()
|
||||
{
|
||||
G4Cache<vector_type>::Get().clear();
|
||||
G4Cache<vector_type>::Get().clear();
|
||||
}
|
||||
|
||||
//template<class V>
|
||||
//typename G4VectorCache<V>::size_type G4VectorCache<V>::Size()
|
||||
// template<class V>
|
||||
// typename G4VectorCache<V>::size_type G4VectorCache<V>::Size()
|
||||
//{
|
||||
// return G4Cache<vector_type>::Get().size();
|
||||
//}
|
||||
|
||||
//======== Implementation: G4MapType<K,V> ===========================
|
||||
|
||||
template<class K, class V>
|
||||
G4MapCache<K,V>::~G4MapCache()
|
||||
template <class K, class V>
|
||||
G4MapCache<K, V>::~G4MapCache()
|
||||
{
|
||||
#ifdef g4cdebug
|
||||
std::cout << "~G4MacCache " << G4Cache<map_type>::GetId()
|
||||
<< " with size: " << Size() << "->";
|
||||
for ( iterator it = Begin() ; it != End() ; ++it )
|
||||
std::cout<<it->first << ":" << it->second << ",";
|
||||
std::cout << "<-" << std::endl;
|
||||
std::cout << "~G4MacCache " << G4Cache<map_type>::GetId()
|
||||
<< " with size: " << Size() << "->";
|
||||
for(iterator it = Begin(); it != End(); ++it)
|
||||
std::cout << it->first << ":" << it->second << ",";
|
||||
std::cout << "<-" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
std::pair<typename G4MapCache<K,V>::iterator,G4bool>
|
||||
G4MapCache<K,V>::Insert(const K& k, const V& v)
|
||||
template <class K, class V>
|
||||
std::pair<typename G4MapCache<K, V>::iterator, G4bool> G4MapCache<K, V>::Insert(
|
||||
const K& k, const V& v)
|
||||
{
|
||||
return G4Cache<map_type>::Get().insert(std::pair<key_type,value_type>(k,v));
|
||||
return G4Cache<map_type>::Get().insert(std::pair<key_type, value_type>(k, v));
|
||||
}
|
||||
|
||||
//template<class K, class V>
|
||||
//typename G4MapCache<K,V>::size_type G4MapCache<K,V>::Size()
|
||||
// template<class K, class V>
|
||||
// typename G4MapCache<K,V>::size_type G4MapCache<K,V>::Size()
|
||||
//{
|
||||
// return G4Cache<map_type>::Get().size();
|
||||
//}
|
||||
|
||||
template<class K, class V>
|
||||
typename G4MapCache<K,V>::iterator G4MapCache<K,V>::Begin()
|
||||
template <class K, class V>
|
||||
typename G4MapCache<K, V>::iterator G4MapCache<K, V>::Begin()
|
||||
{
|
||||
return G4Cache<map_type>::Get().begin();
|
||||
return G4Cache<map_type>::Get().begin();
|
||||
}
|
||||
template<class K, class V>
|
||||
typename G4MapCache<K,V>::iterator G4MapCache<K,V>::End()
|
||||
template <class K, class V>
|
||||
typename G4MapCache<K, V>::iterator G4MapCache<K, V>::End()
|
||||
{
|
||||
return G4Cache<map_type>::Get().end();
|
||||
return G4Cache<map_type>::Get().end();
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
typename G4MapCache<K,V>::iterator G4MapCache<K,V>::Find(const K& k )
|
||||
template <class K, class V>
|
||||
typename G4MapCache<K, V>::iterator G4MapCache<K, V>::Find(const K& k)
|
||||
{
|
||||
return G4Cache<map_type>::Get().find(k);
|
||||
return G4Cache<map_type>::Get().find(k);
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
G4bool G4MapCache<K,V>::Has(const K& k )
|
||||
template <class K, class V>
|
||||
G4bool G4MapCache<K, V>::Has(const K& k)
|
||||
{
|
||||
return ( Find(k) != End() );
|
||||
return (Find(k) != End());
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
V& G4MapCache<K,V>::Get(const K& k )
|
||||
template <class K, class V>
|
||||
V& G4MapCache<K, V>::Get(const K& k)
|
||||
{
|
||||
return Find(k)->second;
|
||||
return Find(k)->second;
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
typename G4MapCache<K,V>::size_type G4MapCache<K,V>::Erase(const K& k )
|
||||
template <class K, class V>
|
||||
typename G4MapCache<K, V>::size_type G4MapCache<K, V>::Erase(const K& k)
|
||||
{
|
||||
return G4Cache<map_type>::Get().erase(k);
|
||||
return G4Cache<map_type>::Get().erase(k);
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
V& G4MapCache<K,V>::operator[](const K& k)
|
||||
template <class K, class V>
|
||||
V& G4MapCache<K, V>::operator[](const K& k)
|
||||
{
|
||||
return (G4Cache<map_type>::Get())[k];
|
||||
return (G4Cache<map_type>::Get())[k];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,11 +23,9 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4CacheDetails
|
||||
//
|
||||
// ---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// Class Description:
|
||||
// Class description:
|
||||
//
|
||||
// The classes contained in this header files are used by
|
||||
// G4Cache to store a TLS instance of the cached object.
|
||||
@@ -52,205 +50,200 @@
|
||||
// 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".
|
||||
// ------------------------------------------------------------
|
||||
|
||||
// Author: A.Dotti, 21 October 2013 - First implementation
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4CacheDetails_hh
|
||||
#define G4CacheDetails_hh
|
||||
|
||||
#include <vector>
|
||||
#include "G4Threading.hh"
|
||||
#include "globals.hh"
|
||||
#include <vector>
|
||||
|
||||
// A TLS storage for a cache of type VALTYPE
|
||||
//
|
||||
template<class VALTYPE> class G4CacheReference
|
||||
template <class VALTYPE>
|
||||
class G4CacheReference
|
||||
{
|
||||
public:
|
||||
public:
|
||||
inline void Initialize(unsigned int id);
|
||||
// Initliaze TLS storage
|
||||
|
||||
inline void Initialize( unsigned int id );
|
||||
// Initliaze TLS storage
|
||||
inline void Destroy(unsigned int id, G4bool last);
|
||||
// Cleanup TLS storage for instance id. If last==true
|
||||
// destroy and cleanup object container
|
||||
|
||||
inline void Destroy( unsigned int id , G4bool last);
|
||||
// Cleanup TLS storage for instance id. If last==true
|
||||
// destroy and cleanup object container
|
||||
inline VALTYPE& GetCache(unsigned int id) const;
|
||||
// Returns cached value for instance id
|
||||
|
||||
inline VALTYPE& GetCache(unsigned int id) const;
|
||||
// Returns cached value for instance id
|
||||
private:
|
||||
using cache_container = std::vector<VALTYPE*>;
|
||||
// Implementation detail: the cached object is stored as a
|
||||
// pointer. Object is stored as a pointer to avoid too large
|
||||
// std::vector in case of stored objects and allow use of
|
||||
// specialized allocators
|
||||
|
||||
private:
|
||||
|
||||
typedef std::vector<VALTYPE*> cache_container;
|
||||
// Implementation detail: the cached object is stored as a
|
||||
// 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 cache_container*& cache();
|
||||
static cache_container*& cache();
|
||||
};
|
||||
|
||||
// Template specialization for pointers
|
||||
// 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*>
|
||||
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;
|
||||
public:
|
||||
inline void Initialize(unsigned int id);
|
||||
|
||||
private:
|
||||
typedef std::vector<VALTYPE*> cache_container;
|
||||
static cache_container*& cache();
|
||||
inline void Destroy(unsigned int id, G4bool last);
|
||||
|
||||
inline VALTYPE*& GetCache(unsigned int id) const;
|
||||
|
||||
private:
|
||||
using cache_container = std::vector<VALTYPE*>;
|
||||
static cache_container*& cache();
|
||||
};
|
||||
|
||||
// Template specialization for probably the most used case: double
|
||||
// Be more efficient avoiding unnecessary "new/delete"
|
||||
//
|
||||
template<> class G4CacheReference<G4double>
|
||||
template <>
|
||||
class G4CacheReference<G4double>
|
||||
{
|
||||
public:
|
||||
public:
|
||||
inline void Initialize(unsigned int id);
|
||||
|
||||
inline void Initialize( unsigned int id );
|
||||
|
||||
inline void Destroy( unsigned int id , G4bool last);
|
||||
|
||||
inline G4double& GetCache(unsigned int id) const;
|
||||
inline void Destroy(unsigned int id, G4bool last);
|
||||
|
||||
private:
|
||||
inline G4double& GetCache(unsigned int id) const;
|
||||
|
||||
typedef std::vector<G4double> cache_container;
|
||||
static G4GLOB_DLL cache_container*& cache();
|
||||
private:
|
||||
using cache_container = std::vector<G4double>;
|
||||
static G4GLOB_DLL cache_container*& cache();
|
||||
};
|
||||
|
||||
|
||||
//======= Implementation: G4CacheReference<V>
|
||||
//===========================================
|
||||
|
||||
template<class V>
|
||||
void G4CacheReference<V>::Initialize( unsigned int id )
|
||||
template <class V>
|
||||
void G4CacheReference<V>::Initialize(unsigned int id)
|
||||
{
|
||||
// Create cache container
|
||||
if ( cache() == 0 )
|
||||
if(cache() == nullptr)
|
||||
{
|
||||
#ifdef g4cdebug
|
||||
std::cout << "Generic template container..." << std::endl;
|
||||
#endif
|
||||
cache() = new cache_container;
|
||||
}
|
||||
if ( cache()->size() <= id )
|
||||
if(cache()->size() <= id)
|
||||
{
|
||||
cache()->resize(id+1,static_cast<V*>(0));
|
||||
cache()->resize(id + 1, static_cast<V*>(0));
|
||||
}
|
||||
if ( (*cache())[id] == 0 )
|
||||
if((*cache())[id] == 0)
|
||||
{
|
||||
(*cache())[id]=new V;
|
||||
(*cache())[id] = new V;
|
||||
}
|
||||
}
|
||||
|
||||
template<class V>
|
||||
void G4CacheReference<V>::Destroy( unsigned int id, G4bool last )
|
||||
template <class V>
|
||||
void G4CacheReference<V>::Destroy(unsigned int id, G4bool last)
|
||||
{
|
||||
if ( cache() )
|
||||
if(cache() != nullptr)
|
||||
{
|
||||
#ifdef g4cdebug
|
||||
std::cout << "V: Destroying element "<< id
|
||||
<< " is last? " << last << std::endl;
|
||||
std::cout << "V: Destroying element " << id << " is last? " << last
|
||||
<< std::endl;
|
||||
#endif
|
||||
if ( cache()->size() < id )
|
||||
if(cache()->size() < id)
|
||||
{
|
||||
G4ExceptionDescription msg;
|
||||
msg << "Internal fatal error. Invalid G4Cache size (requested id: "
|
||||
<< id << " but cache has size: "<< cache()->size();
|
||||
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);
|
||||
G4Exception("G4CacheReference<V>::Destroy", "Cache001", FatalException,
|
||||
msg);
|
||||
return;
|
||||
}
|
||||
if ( cache()->size() > id && (*cache())[id] )
|
||||
if(cache()->size() > id && (*cache())[id] != nullptr)
|
||||
{
|
||||
#ifdef g4cdebug
|
||||
std::cout << "V: Destroying element " << id
|
||||
<< " size: " << cache()->size() << std::endl;
|
||||
#endif
|
||||
delete (*cache())[id];
|
||||
(*cache())[id]=0;
|
||||
delete(*cache())[id];
|
||||
(*cache())[id] = nullptr;
|
||||
}
|
||||
if (last)
|
||||
if(last)
|
||||
{
|
||||
#ifdef g4cdebug
|
||||
std::cout << "V: Destroying LAST element!" << std::endl;
|
||||
#endif
|
||||
delete cache();
|
||||
cache() = 0;
|
||||
cache() = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class V>
|
||||
V& G4CacheReference<V>::GetCache( unsigned int id ) const
|
||||
template <class V>
|
||||
V& G4CacheReference<V>::GetCache(unsigned int id) const
|
||||
{
|
||||
return *(cache()->operator[](id));
|
||||
}
|
||||
|
||||
template<class V>
|
||||
typename G4CacheReference<V>::cache_container*&
|
||||
G4CacheReference<V>::cache()
|
||||
template <class V>
|
||||
typename G4CacheReference<V>::cache_container*& G4CacheReference<V>::cache()
|
||||
{
|
||||
G4ThreadLocalStatic cache_container* _instance = nullptr;
|
||||
return _instance;
|
||||
G4ThreadLocalStatic cache_container* _instance = nullptr;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
//======= Implementation: G4CacheReference<V*>
|
||||
//============================================
|
||||
|
||||
template<class V>
|
||||
void G4CacheReference<V*>::Initialize( unsigned int id )
|
||||
template <class V>
|
||||
void G4CacheReference<V*>::Initialize(unsigned int id)
|
||||
{
|
||||
if ( cache() == 0 )
|
||||
if(cache() == nullptr)
|
||||
{
|
||||
#ifdef g4cdebug
|
||||
std::cout << "Pointer template container..." << std::endl;
|
||||
#endif
|
||||
cache() = new cache_container;
|
||||
}
|
||||
if ( cache()->size() <= id )
|
||||
if(cache()->size() <= id)
|
||||
{
|
||||
cache()->resize(id+1,static_cast<V*>(0));
|
||||
cache()->resize(id + 1, static_cast<V*>(0));
|
||||
}
|
||||
}
|
||||
|
||||
template<class V>
|
||||
inline void G4CacheReference<V*>::Destroy( unsigned int id , G4bool last )
|
||||
template <class V>
|
||||
inline void G4CacheReference<V*>::Destroy(unsigned int id, G4bool last)
|
||||
{
|
||||
if ( cache() )
|
||||
if(cache() != nullptr)
|
||||
{
|
||||
#ifdef g4cdebug
|
||||
std::cout << "V*: Destroying element " << id << " is last? " << last
|
||||
<< std::endl;
|
||||
#endif
|
||||
if ( cache()->size() < id )
|
||||
if(cache()->size() < id)
|
||||
{
|
||||
G4ExceptionDescription msg;
|
||||
msg << "Internal fatal error. Invalid G4Cache size (requested id: "
|
||||
<< id << " but cache has size: " << cache()->size();
|
||||
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);
|
||||
G4Exception("G4CacheReference<V*>::Destroy", "Cache001", FatalException,
|
||||
msg);
|
||||
return;
|
||||
}
|
||||
if ( cache()->size() > id && (*cache())[id] )
|
||||
if(cache()->size() > id && (*cache())[id] != nullptr)
|
||||
{
|
||||
// Ownership is for client
|
||||
// delete (*cache())[id];
|
||||
@@ -258,61 +251,60 @@ inline void G4CacheReference<V*>::Destroy( unsigned int id , G4bool last )
|
||||
std::cout << "V*: Resetting element " << id
|
||||
<< " size: " << cache()->size() << std::endl;
|
||||
#endif
|
||||
(*cache())[id]=0;
|
||||
(*cache())[id] = nullptr;
|
||||
}
|
||||
if (last )
|
||||
if(last)
|
||||
{
|
||||
#ifdef g4cdebug
|
||||
std::cout << "V*: Deleting LAST element!" << std::endl;
|
||||
#endif
|
||||
delete cache();
|
||||
cache() = 0;
|
||||
cache() = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class V>
|
||||
template <class V>
|
||||
V*& G4CacheReference<V*>::GetCache(unsigned int id) const
|
||||
{
|
||||
return (cache()->operator[](id));
|
||||
}
|
||||
|
||||
template<class V>
|
||||
typename G4CacheReference<V*>::cache_container*&
|
||||
G4CacheReference<V*>::cache()
|
||||
template <class V>
|
||||
typename G4CacheReference<V*>::cache_container*& G4CacheReference<V*>::cache()
|
||||
{
|
||||
G4ThreadLocalStatic cache_container* _instance = nullptr;
|
||||
return _instance;
|
||||
G4ThreadLocalStatic cache_container* _instance = nullptr;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
//======= Implementation: G4CacheReference<double>
|
||||
//============================================
|
||||
|
||||
void G4CacheReference<G4double>::Initialize( unsigned int id )
|
||||
void G4CacheReference<G4double>::Initialize(unsigned int id)
|
||||
{
|
||||
if ( cache() == 0 )
|
||||
if(cache() == nullptr)
|
||||
{
|
||||
#ifdef g4cdebug
|
||||
std::cout << "Specialized template for G4double container..." << std::endl;
|
||||
#endif
|
||||
cache() = new cache_container;
|
||||
}
|
||||
if ( cache()->size() <= id )
|
||||
if(cache()->size() <= id)
|
||||
{
|
||||
cache()->resize(id+1,static_cast<G4double>(0));
|
||||
cache()->resize(id + 1, static_cast<G4double>(0));
|
||||
}
|
||||
}
|
||||
|
||||
void G4CacheReference<G4double>::Destroy( unsigned int /*id*/ , G4bool last)
|
||||
void G4CacheReference<G4double>::Destroy(unsigned int /*id*/, G4bool last)
|
||||
{
|
||||
if ( cache() && last )
|
||||
if(cache() != nullptr && last)
|
||||
{
|
||||
#ifdef g4cdebug
|
||||
std::cout << "DB: Destroying LAST element! Is it last? " << last
|
||||
<< std::endl;
|
||||
#endif
|
||||
delete cache();
|
||||
cache() = 0;
|
||||
cache() = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,74 +23,72 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4DataVector
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// ------------------------------------------------------------
|
||||
//
|
||||
// Class Description:
|
||||
//
|
||||
// Utility class providing similar behaviour of vector<G4double>.
|
||||
// It includes additional methods for compatibility with Rogue Wave
|
||||
// collection.
|
||||
//
|
||||
// Utility class providing similar behaviour of std::vector<G4double>.
|
||||
// It includes additional methods for compatibility with Rogue Wave
|
||||
// collection.
|
||||
|
||||
#ifndef G4DataVector_h
|
||||
#define G4DataVector_h 1
|
||||
// Author: H.Kurashige, 18 September 2001
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4DataVector_hh
|
||||
#define G4DataVector_hh 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include <vector>
|
||||
#include "G4ios.hh"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
class G4DataVector : public std::vector<G4double>
|
||||
#include "G4ios.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
class G4DataVector : public std::vector<G4double>
|
||||
{
|
||||
|
||||
public: // with description
|
||||
|
||||
public:
|
||||
G4DataVector();
|
||||
// Default constructor.
|
||||
// Default constructor.
|
||||
|
||||
G4DataVector(const G4DataVector&) = default;
|
||||
G4DataVector(G4DataVector&&) = default;
|
||||
// Default copy&move constructors.
|
||||
G4DataVector(G4DataVector&&) = default;
|
||||
// Default copy&move constructors.
|
||||
|
||||
explicit G4DataVector(size_t cap);
|
||||
// Constructor given a 'capacity' defining the initial number of elements.
|
||||
explicit G4DataVector(std::size_t cap);
|
||||
// Constructor given a 'capacity' defining the initial number of elements.
|
||||
|
||||
G4DataVector(size_t cap, G4double value);
|
||||
// Constructor given a 'capacity' defining the initial number of elements
|
||||
// and initialising them to 'value'.
|
||||
G4DataVector(std::size_t cap, G4double value);
|
||||
// Constructor given a 'capacity' defining the initial number of elements
|
||||
// and initialising them to 'value'.
|
||||
|
||||
virtual ~G4DataVector();
|
||||
// Empty destructor
|
||||
// Empty destructor
|
||||
|
||||
G4DataVector& operator=(const G4DataVector &) = default;
|
||||
G4DataVector& operator=(G4DataVector &&) = default;
|
||||
// Default copy&move assignment operators.
|
||||
G4DataVector& operator=(const G4DataVector&) = default;
|
||||
G4DataVector& operator=(G4DataVector&&) = default;
|
||||
// Default copy&move assignment operators.
|
||||
|
||||
inline void insertAt(size_t, const G4double&);
|
||||
// Insert an element at given position
|
||||
inline void insertAt(std::size_t, const G4double&);
|
||||
// Insert an element at given position
|
||||
|
||||
inline size_t index(const G4double&);
|
||||
// Returns back index of the element same as given value
|
||||
inline std::size_t index(const G4double&);
|
||||
// Returns back index of the element same as given value
|
||||
|
||||
inline G4bool contains(const G4double&) const;
|
||||
// Returns 'true' if it contains the element same as given value
|
||||
// Returns 'true' if it contains the element same as given value
|
||||
|
||||
inline G4bool remove(const G4double&);
|
||||
// Removes the first element same as given value
|
||||
// Removes the first element same as given value
|
||||
|
||||
inline size_t removeAll(const G4double&);
|
||||
// Remove all elements same as given value
|
||||
inline std::size_t removeAll(const G4double&);
|
||||
// Remove all elements same as given value
|
||||
|
||||
enum {T_G4DataVector = 100};
|
||||
enum
|
||||
{
|
||||
T_G4DataVector = 100
|
||||
};
|
||||
|
||||
G4bool Store(std::ofstream& fOut, G4bool ascii=false);
|
||||
G4bool Retrieve(std::ifstream& fIn, G4bool ascii=false);
|
||||
G4bool Store(std::ofstream& fOut, G4bool ascii = false);
|
||||
G4bool Retrieve(std::ifstream& fIn, G4bool ascii = false);
|
||||
// To store/retrieve persistent data to/from file streams.
|
||||
|
||||
friend std::ostream& operator<<(std::ostream&, const G4DataVector&);
|
||||
|
||||
@@ -23,50 +23,62 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// class G4DataVector inline implementation
|
||||
//
|
||||
//
|
||||
// Author: H.Kurashige, 18 September 2001
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline
|
||||
void G4DataVector::insertAt(size_t pos, const G4double& a)
|
||||
{
|
||||
iterator i = begin();
|
||||
for (size_t ptn=0; (ptn<pos)&&(i!=end()); i++,ptn++) {;}
|
||||
if (i!=end())
|
||||
{ insert(i,a); }
|
||||
else
|
||||
{ push_back(a); }
|
||||
}
|
||||
|
||||
inline
|
||||
size_t G4DataVector::index(const G4double& a)
|
||||
{
|
||||
size_t ptn = 0;
|
||||
for (iterator i=begin(); i!=end(); i++,ptn++)
|
||||
{ if (!(*i!=a)) { return ptn; } }
|
||||
|
||||
return (ptn=~(size_t)0);
|
||||
}
|
||||
|
||||
inline
|
||||
G4bool G4DataVector::contains(const G4double& a) const
|
||||
inline void G4DataVector::insertAt(std::size_t pos, const G4double& a)
|
||||
{
|
||||
for (const_iterator i=begin(); i!=end(); i++)
|
||||
{ if (!(*i!=a)) { return true; } }
|
||||
auto i = cbegin();
|
||||
for(std::size_t ptn = 0; (ptn < pos) && (i != cend()); ++i, ++ptn)
|
||||
{
|
||||
;
|
||||
}
|
||||
if(i != cend())
|
||||
{
|
||||
insert(i, a);
|
||||
}
|
||||
else
|
||||
{
|
||||
push_back(a);
|
||||
}
|
||||
}
|
||||
|
||||
inline std::size_t G4DataVector::index(const G4double& a)
|
||||
{
|
||||
std::size_t ptn = 0;
|
||||
for(auto i = cbegin(); i != cend(); ++i, ++ptn)
|
||||
{
|
||||
if(!(*i != a))
|
||||
{
|
||||
return ptn;
|
||||
}
|
||||
}
|
||||
|
||||
return (ptn = ~(std::size_t) 0);
|
||||
}
|
||||
|
||||
inline G4bool G4DataVector::contains(const G4double& a) const
|
||||
{
|
||||
for(auto i = cbegin(); i != cend(); ++i)
|
||||
{
|
||||
if(!(*i != a))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline
|
||||
G4bool G4DataVector::remove(const G4double& a)
|
||||
inline G4bool G4DataVector::remove(const G4double& a)
|
||||
{
|
||||
G4bool found = false;
|
||||
|
||||
for (iterator i=begin(); i!=end(); i++)
|
||||
for(auto i = cbegin(); i != cend(); ++i)
|
||||
{
|
||||
if (!(*i!=a))
|
||||
if(!(*i != a))
|
||||
{
|
||||
erase(i);
|
||||
found = true;
|
||||
@@ -76,19 +88,18 @@ G4bool G4DataVector::remove(const G4double& a)
|
||||
return found;
|
||||
}
|
||||
|
||||
inline
|
||||
size_t G4DataVector::removeAll(const G4double& a)
|
||||
inline std::size_t G4DataVector::removeAll(const G4double& a)
|
||||
{
|
||||
size_t ptn=0;
|
||||
std::size_t ptn = 0;
|
||||
|
||||
for (iterator i=begin(); i!=end(); i++)
|
||||
for(auto i = cbegin(); i != cend(); ++i)
|
||||
{
|
||||
if (!(*i!=a))
|
||||
if(!(*i != a))
|
||||
{
|
||||
erase(i);
|
||||
ptn++;
|
||||
i--;
|
||||
}
|
||||
++ptn;
|
||||
--i;
|
||||
}
|
||||
}
|
||||
return ptn;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// Global environment utility functions:
|
||||
//
|
||||
// G4GetEnv<T>
|
||||
@@ -36,78 +35,75 @@
|
||||
// G4PrintEnv
|
||||
// Provide a way for users to determine (and log) the environment
|
||||
// variables were used as settings in simulation
|
||||
//
|
||||
|
||||
// Author: Jonathan Madsen, 25 October 2018
|
||||
// ---------------------------------------------------------------------------
|
||||
#ifndef G4ENVIRONMENTUTILS_HH_
|
||||
#define G4ENVIRONMENTUTILS_HH_
|
||||
#ifndef G4ENVIRONMENTUTILS_HH
|
||||
#define G4ENVIRONMENTUTILS_HH
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "G4ios.hh"
|
||||
#include "G4String.hh"
|
||||
#include "G4Exception.hh"
|
||||
#include "G4ExceptionSeverity.hh"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
#include "G4String.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
class G4EnvSettings
|
||||
{
|
||||
// Static singleton class storing environment variables and
|
||||
// their values that were used by Geant4 in the simulation
|
||||
|
||||
public:
|
||||
typedef std::string string_t;
|
||||
typedef std::map<string_t, string_t> env_map_t;
|
||||
typedef std::pair<string_t, string_t> env_pair_t;
|
||||
public:
|
||||
using string_t = std::string;
|
||||
using env_map_t = std::map<string_t, string_t>;
|
||||
using env_pair_t = std::pair<string_t, string_t>;
|
||||
|
||||
public:
|
||||
static G4EnvSettings* GetInstance()
|
||||
static G4EnvSettings* GetInstance()
|
||||
{
|
||||
static G4EnvSettings* _instance = new G4EnvSettings();
|
||||
return _instance;
|
||||
}
|
||||
|
||||
template <typename _Tp>
|
||||
void insert(const std::string& env_id, _Tp val)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << val;
|
||||
// lock for MT mode, use C++ type not Geant4 because this file
|
||||
// is included by the those headers
|
||||
static std::mutex _mutex;
|
||||
_mutex.lock();
|
||||
m_env.insert(env_pair_t(env_id, ss.str()));
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
const env_map_t& get() const { return m_env; }
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const G4EnvSettings& env)
|
||||
{
|
||||
std::stringstream filler;
|
||||
filler.fill('#');
|
||||
filler << std::setw(90) << "";
|
||||
std::stringstream ss;
|
||||
ss << filler.str() << "\n# Environment settings:\n";
|
||||
for(const auto& itr : env.get())
|
||||
{
|
||||
static G4EnvSettings* _instance = new G4EnvSettings();
|
||||
return _instance;
|
||||
ss << "# " << std::setw(35) << std::right << itr.first << "\t = \t"
|
||||
<< std::left << itr.second << "\n";
|
||||
}
|
||||
ss << filler.str();
|
||||
os << ss.str() << std::endl;
|
||||
return os;
|
||||
}
|
||||
|
||||
public:
|
||||
template <typename _Tp>
|
||||
void insert(const std::string& env_id, _Tp val)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << val;
|
||||
// lock for MT mode, use C++ type not Geant4 because this file
|
||||
// is included by the those headers
|
||||
static std::mutex _mutex;
|
||||
_mutex.lock();
|
||||
m_env.insert(env_pair_t(env_id, ss.str()));
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
const env_map_t& get() const { return m_env; }
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const G4EnvSettings& env)
|
||||
{
|
||||
std::stringstream filler;
|
||||
filler.fill('#');
|
||||
filler << std::setw(90) << "";
|
||||
std::stringstream ss;
|
||||
ss << filler.str() << "\n# Environment settings:\n";
|
||||
for(const auto& itr : env.get())
|
||||
{
|
||||
ss << "# " << std::setw(35) << std::right << itr.first
|
||||
<< "\t = \t" << std::left << itr.second << "\n";
|
||||
}
|
||||
ss << filler.str();
|
||||
os << ss.str() << std::endl;
|
||||
return os;
|
||||
}
|
||||
|
||||
private:
|
||||
env_map_t m_env;
|
||||
private:
|
||||
env_map_t m_env;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -143,8 +139,8 @@ _Tp G4GetEnv(const std::string& env_id, _Tp _default = _Tp())
|
||||
// int num_threads =
|
||||
// GetEnv<int>("FORCENUMBEROFTHREADS",
|
||||
// std::thread::hardware_concurrency());
|
||||
template <> inline
|
||||
G4bool G4GetEnv(const std::string& env_id, bool _default)
|
||||
template <>
|
||||
inline G4bool G4GetEnv(const std::string& env_id, bool _default)
|
||||
{
|
||||
char* env_var = std::getenv(env_id.c_str());
|
||||
if(env_var)
|
||||
@@ -199,30 +195,29 @@ _Tp G4GetEnv(const std::string& env_id, _Tp _default, const std::string& msg)
|
||||
// FatalException,
|
||||
// "G4ENSDFSTATEDATA environment variable"
|
||||
// " must be set");
|
||||
inline G4String
|
||||
G4GetDataEnv(const std::string& env_id,
|
||||
const char* originOfException,
|
||||
const char* exceptionCode,
|
||||
G4ExceptionSeverity severity,
|
||||
const char* description)
|
||||
inline G4String G4GetDataEnv(const std::string& env_id,
|
||||
const char* originOfException,
|
||||
const char* exceptionCode,
|
||||
G4ExceptionSeverity severity,
|
||||
const char* description)
|
||||
{
|
||||
char* env_var = std::getenv(env_id.c_str());
|
||||
if(env_var)
|
||||
{
|
||||
std::string str_var = std::string(env_var);
|
||||
std::istringstream iss(str_var);
|
||||
G4String var = "";
|
||||
iss >> var;
|
||||
// record value defined by environment
|
||||
G4EnvSettings::GetInstance()->insert<G4String>(env_id, var);
|
||||
return var;
|
||||
}
|
||||
char* env_var = std::getenv(env_id.c_str());
|
||||
if(env_var)
|
||||
{
|
||||
std::string str_var = std::string(env_var);
|
||||
std::istringstream iss(str_var);
|
||||
G4String var = "";
|
||||
iss >> var;
|
||||
// record value defined by environment
|
||||
G4EnvSettings::GetInstance()->insert<G4String>(env_id, var);
|
||||
return var;
|
||||
}
|
||||
|
||||
// issue an exception
|
||||
G4Exception(originOfException, exceptionCode, severity, description);
|
||||
// issue an exception
|
||||
G4Exception(originOfException, exceptionCode, severity, description);
|
||||
|
||||
// return default initialized
|
||||
return "";
|
||||
// return default initialized
|
||||
return "";
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -230,9 +225,7 @@ G4GetDataEnv(const std::string& env_id,
|
||||
//
|
||||
inline void G4PrintEnv(std::ostream& os = G4cout)
|
||||
{
|
||||
os << (*G4EnvSettings::GetInstance());
|
||||
os << (*G4EnvSettings::GetInstance());
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#endif /* G4ENVIRONMENTUTILS_HH_ */
|
||||
#endif /* G4ENVIRONMENTUTILS_HH */
|
||||
|
||||
@@ -23,74 +23,72 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4ErrorPropagatorData
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
// Class Description:
|
||||
//
|
||||
// Utility class to provide access to mode, state, target
|
||||
// and manager verbosity for the error propagation classes.
|
||||
// Utility class to provide access to mode, state, target
|
||||
// and manager verbosity for the error propagation classes.
|
||||
|
||||
// - Created. P.Arce, 2004.
|
||||
// Author: P.Arce, 2004
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#ifndef G4ErrorPropagatorData_HH
|
||||
#define G4ErrorPropagatorData_HH
|
||||
#ifndef G4ErrorPropagatorData_hh
|
||||
#define G4ErrorPropagatorData_hh
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
enum G4ErrorMode { G4ErrorMode_PropForwards = 1,
|
||||
G4ErrorMode_PropBackwards,
|
||||
G4ErrorMode_PropTest };
|
||||
enum G4ErrorMode
|
||||
{
|
||||
G4ErrorMode_PropForwards = 1,
|
||||
G4ErrorMode_PropBackwards,
|
||||
G4ErrorMode_PropTest
|
||||
};
|
||||
|
||||
enum G4ErrorState { G4ErrorState_PreInit = 1,
|
||||
G4ErrorState_Init,
|
||||
G4ErrorState_Propagating,
|
||||
G4ErrorState_TargetCloserThanBoundary,
|
||||
G4ErrorState_StoppedAtTarget };
|
||||
enum G4ErrorState
|
||||
{
|
||||
G4ErrorState_PreInit = 1,
|
||||
G4ErrorState_Init,
|
||||
G4ErrorState_Propagating,
|
||||
G4ErrorState_TargetCloserThanBoundary,
|
||||
G4ErrorState_StoppedAtTarget
|
||||
};
|
||||
|
||||
enum G4ErrorStage { G4ErrorStage_Inflation = 1,
|
||||
G4ErrorStage_Deflation };
|
||||
enum G4ErrorStage
|
||||
{
|
||||
G4ErrorStage_Inflation = 1,
|
||||
G4ErrorStage_Deflation
|
||||
};
|
||||
|
||||
class G4ErrorTarget;
|
||||
|
||||
class G4ErrorPropagatorData
|
||||
class G4ErrorPropagatorData
|
||||
{
|
||||
|
||||
public: // with description
|
||||
|
||||
public:
|
||||
static G4ErrorPropagatorData* GetErrorPropagatorData();
|
||||
// Singleton instance
|
||||
// Singleton instance
|
||||
|
||||
// Get and Set methods
|
||||
G4ErrorMode GetMode() const;
|
||||
void SetMode( G4ErrorMode mode );
|
||||
inline G4ErrorMode GetMode() const;
|
||||
inline void SetMode(G4ErrorMode mode);
|
||||
|
||||
G4ErrorState GetState() const;
|
||||
void SetState( G4ErrorState sta );
|
||||
inline G4ErrorState GetState() const;
|
||||
inline void SetState(G4ErrorState sta);
|
||||
|
||||
G4ErrorStage GetStage() const;
|
||||
void SetStage( G4ErrorStage sta );
|
||||
inline G4ErrorStage GetStage() const;
|
||||
inline void SetStage(G4ErrorStage sta);
|
||||
|
||||
const G4ErrorTarget* GetTarget( G4bool mustExist = 0) const;
|
||||
void SetTarget( const G4ErrorTarget* target );
|
||||
inline const G4ErrorTarget* GetTarget(G4bool mustExist = false) const;
|
||||
inline void SetTarget(const G4ErrorTarget* target);
|
||||
|
||||
static G4int verbose();
|
||||
static void SetVerbose( G4int ver );
|
||||
|
||||
|
||||
private:
|
||||
static void SetVerbose(G4int ver);
|
||||
|
||||
private:
|
||||
G4ErrorPropagatorData();
|
||||
~G4ErrorPropagatorData();
|
||||
// constructor and destructor are private
|
||||
|
||||
private:
|
||||
// constructor and destructor are private
|
||||
|
||||
private:
|
||||
static G4ThreadLocal G4ErrorPropagatorData* fpInstance;
|
||||
|
||||
G4ErrorMode theMode;
|
||||
@@ -99,10 +97,9 @@ private:
|
||||
|
||||
G4ErrorStage theStage;
|
||||
|
||||
G4ErrorTarget* theTarget;
|
||||
G4ErrorTarget* theTarget = nullptr;
|
||||
|
||||
static G4ThreadLocal G4int theVerbosity;
|
||||
|
||||
};
|
||||
|
||||
#include "G4ErrorPropagatorData.icc"
|
||||
|
||||
@@ -23,64 +23,42 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// Class G4ErrorPropagatorData inline implementation
|
||||
//
|
||||
// Author: P.Arce, 2004
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline
|
||||
G4ErrorMode G4ErrorPropagatorData::GetMode() const
|
||||
{
|
||||
return theMode;
|
||||
}
|
||||
inline G4ErrorMode G4ErrorPropagatorData::GetMode() const { return theMode; }
|
||||
|
||||
inline
|
||||
void G4ErrorPropagatorData::SetMode( G4ErrorMode mode )
|
||||
{
|
||||
theMode = mode;
|
||||
}
|
||||
inline void G4ErrorPropagatorData::SetMode(G4ErrorMode mode) { theMode = mode; }
|
||||
|
||||
|
||||
inline
|
||||
void G4ErrorPropagatorData::SetState( G4ErrorState sta )
|
||||
inline void G4ErrorPropagatorData::SetState(G4ErrorState sta)
|
||||
{
|
||||
theState = sta;
|
||||
}
|
||||
|
||||
inline
|
||||
G4ErrorState G4ErrorPropagatorData::GetState() const
|
||||
{
|
||||
return theState;
|
||||
}
|
||||
inline G4ErrorState G4ErrorPropagatorData::GetState() const { return theState; }
|
||||
|
||||
inline
|
||||
void G4ErrorPropagatorData::SetStage( G4ErrorStage sta )
|
||||
inline void G4ErrorPropagatorData::SetStage(G4ErrorStage sta)
|
||||
{
|
||||
theStage = sta;
|
||||
}
|
||||
|
||||
inline
|
||||
G4ErrorStage G4ErrorPropagatorData::GetStage() const
|
||||
{
|
||||
return theStage;
|
||||
}
|
||||
inline G4ErrorStage G4ErrorPropagatorData::GetStage() const { return theStage; }
|
||||
|
||||
inline
|
||||
const G4ErrorTarget* G4ErrorPropagatorData::GetTarget( G4bool mustExist ) const
|
||||
inline const G4ErrorTarget* G4ErrorPropagatorData::GetTarget(
|
||||
G4bool mustExist) const
|
||||
{
|
||||
if( theTarget == 0 && mustExist )
|
||||
if(theTarget == nullptr && mustExist)
|
||||
{
|
||||
G4Exception("G4ErrorPropagatorData::GetTarget()",
|
||||
"InvalidSetup", FatalException,
|
||||
"G4ErrorPropagator defined but without final target!");
|
||||
G4Exception("G4ErrorPropagatorData::GetTarget()", "InvalidSetup",
|
||||
FatalException,
|
||||
"G4ErrorPropagator defined but without final target!");
|
||||
}
|
||||
return theTarget;
|
||||
}
|
||||
|
||||
inline
|
||||
void G4ErrorPropagatorData::SetTarget( const G4ErrorTarget* target )
|
||||
inline void G4ErrorPropagatorData::SetTarget(const G4ErrorTarget* target)
|
||||
{
|
||||
theTarget = const_cast<G4ErrorTarget*>(target);
|
||||
}
|
||||
|
||||
@@ -23,21 +23,15 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// G4Evaluator class, typedef to CLHEP Evaluator
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4EVALUATOR_HH
|
||||
#define G4EVALUATOR_HH
|
||||
|
||||
#include "globals.hh"
|
||||
#include <CLHEP/Evaluator/Evaluator.h>
|
||||
|
||||
typedef HepTool::Evaluator G4Evaluator;
|
||||
using G4Evaluator = HepTool::Evaluator;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,24 +23,21 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
// G4Exception
|
||||
//
|
||||
// Global error function prints string to G4cerr (or G4cout in case of
|
||||
// warning). May abort program according to severity.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// Authors: G.Cosmo, M.Asai - May 1999 - First implementation
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4EXCEPTION_HH
|
||||
#define G4EXCEPTION_HH
|
||||
|
||||
#include "G4ios.hh"
|
||||
#include "G4String.hh"
|
||||
#include "G4VExceptionHandler.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
typedef std::ostringstream G4ExceptionDescription;
|
||||
using G4ExceptionDescription = std::ostringstream;
|
||||
|
||||
inline const G4String G4ExceptionErrBannerStart()
|
||||
{
|
||||
@@ -61,19 +58,16 @@ inline const G4String G4ExceptionWarnBannerEnd()
|
||||
}
|
||||
|
||||
extern void G4Exception(const char* originOfException,
|
||||
const char* exceptionCode,
|
||||
G4ExceptionSeverity severity,
|
||||
const char* exceptionCode, G4ExceptionSeverity severity,
|
||||
const char* description);
|
||||
|
||||
extern void G4Exception(const char* originOfException,
|
||||
const char* exceptionCode,
|
||||
G4ExceptionSeverity severity,
|
||||
G4ExceptionDescription & description);
|
||||
const char* exceptionCode, G4ExceptionSeverity severity,
|
||||
G4ExceptionDescription& description);
|
||||
|
||||
extern void G4Exception(const char* originOfException,
|
||||
const char* exceptionCode,
|
||||
G4ExceptionSeverity severity,
|
||||
G4ExceptionDescription & description,
|
||||
const char* exceptionCode, G4ExceptionSeverity severity,
|
||||
G4ExceptionDescription& description,
|
||||
const char* comments);
|
||||
|
||||
#endif /* G4EXCEPTION_HH */
|
||||
#endif
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4ExceptionSeverity
|
||||
//
|
||||
//
|
||||
// Class Description:
|
||||
// Description:
|
||||
//
|
||||
// Specifies the severity of G4Exception
|
||||
//
|
||||
@@ -35,11 +35,11 @@
|
||||
//
|
||||
// FatalErrorInArgument
|
||||
// Fatal error caused by most likely the mis-use of interfaces
|
||||
// by the user's code. Program should be aborted and core dump
|
||||
// by the user's code. Program should be aborted and core dump
|
||||
// will be generated.
|
||||
//
|
||||
// RunMustBeAborted
|
||||
// Error happens at initialization of a run (ex. at the
|
||||
// Error happens at initialization of a run (ex. at the
|
||||
// moment of closing geometry), or some unpleasant situation
|
||||
// occurs during the event loop. Current run will be aborted
|
||||
// and the application returns to "Idle" state.
|
||||
@@ -50,17 +50,18 @@
|
||||
//
|
||||
// JustWarning
|
||||
// Just display messages.
|
||||
//
|
||||
|
||||
#ifndef G4ExceptionSeverity_H
|
||||
#define G4ExceptionSeverity_H 1
|
||||
|
||||
enum G4ExceptionSeverity
|
||||
{ FatalException,
|
||||
FatalErrorInArgument,
|
||||
RunMustBeAborted,
|
||||
EventMustBeAborted,
|
||||
JustWarning };
|
||||
// Author: M.Asai, 19 August 2002
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4ExceptionSeverity_hh
|
||||
#define G4ExceptionSeverity_hh 1
|
||||
|
||||
enum G4ExceptionSeverity
|
||||
{
|
||||
FatalException,
|
||||
FatalErrorInArgument,
|
||||
RunMustBeAborted,
|
||||
EventMustBeAborted,
|
||||
JustWarning
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@@ -23,55 +23,52 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4Exp
|
||||
//
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
// Class Description:
|
||||
// Class description:
|
||||
//
|
||||
// The basic idea is to exploit Pade polynomials.
|
||||
// A lot of ideas were inspired by the cephes math library
|
||||
// (by Stephen L. Moshier moshier@na-net.ornl.gov) as well as actual code.
|
||||
// (by Stephen L. Moshier moshier@na-net.ornl.gov) as well as actual code.
|
||||
// The Cephes library can be found here: http://www.netlib.org/cephes/
|
||||
// Code and algorithms for G4Exp have been extracted and adapted for Geant4
|
||||
// from the original implementation in the VDT mathematical library
|
||||
// (https://svnweb.cern.ch/trac/vdt), version 0.3.7.
|
||||
|
||||
// Original implementation created on: Jun 23, 2012
|
||||
// Author: Danilo Piparo, Thomas Hauth, Vincenzo Innocente
|
||||
// Authors: Danilo Piparo, Thomas Hauth, Vincenzo Innocente
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
/*
|
||||
/*
|
||||
* VDT is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4Exp_h
|
||||
#define G4Exp_h 1
|
||||
#ifndef G4Exp_hh
|
||||
#define G4Exp_hh 1
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#define G4Exp std::exp
|
||||
# define G4Exp std::exp
|
||||
|
||||
#else
|
||||
|
||||
#include <limits>
|
||||
#include <stdint.h>
|
||||
#include "G4Types.hh"
|
||||
# include "G4Types.hh"
|
||||
# include <limits>
|
||||
# include <stdint.h>
|
||||
|
||||
namespace G4ExpConsts
|
||||
{
|
||||
{
|
||||
const G4double EXP_LIMIT = 708;
|
||||
|
||||
const G4double PX1exp = 1.26177193074810590878E-4;
|
||||
@@ -82,20 +79,20 @@ namespace G4ExpConsts
|
||||
const G4double QX3exp = 2.27265548208155028766E-1;
|
||||
const G4double QX4exp = 2.00000000000000000009E0;
|
||||
|
||||
const G4double LOG2E = 1.4426950408889634073599; // 1/log(2)
|
||||
const G4double LOG2E = 1.4426950408889634073599; // 1/log(2)
|
||||
|
||||
const G4float MAXLOGF = 88.72283905206835f;
|
||||
const G4float MINLOGF = -88.f;
|
||||
|
||||
const G4float C1F = 0.693359375f;
|
||||
const G4float C2F = -2.12194440e-4f;
|
||||
const G4float C1F = 0.693359375f;
|
||||
const G4float C2F = -2.12194440e-4f;
|
||||
|
||||
const G4float PX1expf = 1.9875691500E-4f;
|
||||
const G4float PX2expf =1.3981999507E-3f;
|
||||
const G4float PX3expf =8.3334519073E-3f;
|
||||
const G4float PX4expf =4.1665795894E-2f;
|
||||
const G4float PX5expf =1.6666665459E-1f;
|
||||
const G4float PX6expf =5.0000001201E-1f;
|
||||
const G4float PX2expf = 1.3981999507E-3f;
|
||||
const G4float PX3expf = 8.3334519073E-3f;
|
||||
const G4float PX4expf = 4.1665795894E-2f;
|
||||
const G4float PX5expf = 1.6666665459E-1f;
|
||||
const G4float PX6expf = 5.0000001201E-1f;
|
||||
|
||||
const G4float LOG2EF = 1.44269504088896341f;
|
||||
|
||||
@@ -105,11 +102,11 @@ namespace G4ExpConsts
|
||||
//
|
||||
union ieee754
|
||||
{
|
||||
ieee754 () {};
|
||||
ieee754 (G4double thed) {d=thed;};
|
||||
ieee754 (uint64_t thell) {ll=thell;};
|
||||
ieee754 (G4float thef) {f[0]=thef;};
|
||||
ieee754 (uint32_t thei) {i[0]=thei;};
|
||||
ieee754(){};
|
||||
ieee754(G4double thed) { d = thed; };
|
||||
ieee754(uint64_t thell) { ll = thell; };
|
||||
ieee754(G4float thef) { f[0] = thef; };
|
||||
ieee754(uint32_t thei) { i[0] = thei; };
|
||||
G4double d;
|
||||
G4float f[2];
|
||||
uint32_t i[2];
|
||||
@@ -123,7 +120,7 @@ namespace G4ExpConsts
|
||||
inline G4double uint642dp(uint64_t ll)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.ll=ll;
|
||||
tmp.ll = ll;
|
||||
return tmp.d;
|
||||
}
|
||||
|
||||
@@ -133,7 +130,7 @@ namespace G4ExpConsts
|
||||
inline G4float uint322sp(G4int x)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.i[0]=x;
|
||||
tmp.i[0] = x;
|
||||
return tmp.f[0];
|
||||
}
|
||||
|
||||
@@ -143,84 +140,84 @@ namespace G4ExpConsts
|
||||
inline uint32_t sp2uint32(G4float x)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.f[0]=x;
|
||||
tmp.f[0] = x;
|
||||
return tmp.i[0];
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/**
|
||||
* A vectorisable floor implementation, not only triggered by fast-math.
|
||||
* These functions do not distinguish between -0.0 and 0.0, so are not IEC6509
|
||||
* These functions do not distinguish between -0.0 and 0.0, so are not IEC6509
|
||||
* compliant for argument -0.0
|
||||
**/
|
||||
**/
|
||||
inline G4double fpfloor(const G4double x)
|
||||
{
|
||||
// no problem since exp is defined between -708 and 708. Int is enough for it!
|
||||
int32_t ret = int32_t (x);
|
||||
ret-=(sp2uint32(x)>>31);
|
||||
// no problem since exp is defined between -708 and 708. Int is enough for
|
||||
// it!
|
||||
int32_t ret = int32_t(x);
|
||||
ret -= (sp2uint32(x) >> 31);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/**
|
||||
* A vectorisable floor implementation, not only triggered by fast-math.
|
||||
* These functions do not distinguish between -0.0 and 0.0, so are not IEC6509
|
||||
* These functions do not distinguish between -0.0 and 0.0, so are not IEC6509
|
||||
* compliant for argument -0.0
|
||||
**/
|
||||
**/
|
||||
inline G4float fpfloor(const G4float x)
|
||||
{
|
||||
int32_t ret = int32_t (x);
|
||||
ret-=(sp2uint32(x)>>31);
|
||||
int32_t ret = int32_t(x);
|
||||
ret -= (sp2uint32(x) >> 31);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
} // namespace G4ExpConsts
|
||||
|
||||
// Exp double precision --------------------------------------------------------
|
||||
|
||||
|
||||
/// Exponential Function double precision
|
||||
inline G4double G4Exp(G4double initial_x)
|
||||
{
|
||||
G4double x = initial_x;
|
||||
G4double px=G4ExpConsts::fpfloor(G4ExpConsts::LOG2E * x +0.5);
|
||||
|
||||
const int32_t n = int32_t(px);
|
||||
G4double x = initial_x;
|
||||
G4double px = G4ExpConsts::fpfloor(G4ExpConsts::LOG2E * x + 0.5);
|
||||
|
||||
x -= px * 6.93145751953125E-1;
|
||||
x -= px * 1.42860682030941723212E-6;
|
||||
const int32_t n = int32_t(px);
|
||||
|
||||
const G4double xx = x * x;
|
||||
x -= px * 6.93145751953125E-1;
|
||||
x -= px * 1.42860682030941723212E-6;
|
||||
|
||||
// px = x * P(x**2).
|
||||
px = G4ExpConsts::PX1exp;
|
||||
px *= xx;
|
||||
px += G4ExpConsts::PX2exp;
|
||||
px *= xx;
|
||||
px += G4ExpConsts::PX3exp;
|
||||
px *= x;
|
||||
const G4double xx = x * x;
|
||||
|
||||
// Evaluate Q(x**2).
|
||||
G4double qx = G4ExpConsts::QX1exp;
|
||||
qx *= xx;
|
||||
qx += G4ExpConsts::QX2exp;
|
||||
qx *= xx;
|
||||
qx += G4ExpConsts::QX3exp;
|
||||
qx *= xx;
|
||||
qx += G4ExpConsts::QX4exp;
|
||||
// px = x * P(x**2).
|
||||
px = G4ExpConsts::PX1exp;
|
||||
px *= xx;
|
||||
px += G4ExpConsts::PX2exp;
|
||||
px *= xx;
|
||||
px += G4ExpConsts::PX3exp;
|
||||
px *= x;
|
||||
|
||||
// e**x = 1 + 2x P(x**2)/( Q(x**2) - P(x**2) )
|
||||
x = px / (qx - px);
|
||||
x = 1.0 + 2.0 * x;
|
||||
// Evaluate Q(x**2).
|
||||
G4double qx = G4ExpConsts::QX1exp;
|
||||
qx *= xx;
|
||||
qx += G4ExpConsts::QX2exp;
|
||||
qx *= xx;
|
||||
qx += G4ExpConsts::QX3exp;
|
||||
qx *= xx;
|
||||
qx += G4ExpConsts::QX4exp;
|
||||
|
||||
// Build 2^n in double.
|
||||
x *= G4ExpConsts::uint642dp(( ((uint64_t)n) +1023)<<52);
|
||||
// e**x = 1 + 2x P(x**2)/( Q(x**2) - P(x**2) )
|
||||
x = px / (qx - px);
|
||||
x = 1.0 + 2.0 * x;
|
||||
|
||||
if (initial_x > G4ExpConsts::EXP_LIMIT)
|
||||
x = std::numeric_limits<G4double>::infinity();
|
||||
if (initial_x < -G4ExpConsts::EXP_LIMIT)
|
||||
x = 0.;
|
||||
// Build 2^n in double.
|
||||
x *= G4ExpConsts::uint642dp((((uint64_t) n) + 1023) << 52);
|
||||
|
||||
return x;
|
||||
if(initial_x > G4ExpConsts::EXP_LIMIT)
|
||||
x = std::numeric_limits<G4double>::infinity();
|
||||
if(initial_x < -G4ExpConsts::EXP_LIMIT)
|
||||
x = 0.;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
// Exp single precision --------------------------------------------------------
|
||||
@@ -228,44 +225,52 @@ inline G4double G4Exp(G4double initial_x)
|
||||
/// Exponential Function single precision
|
||||
inline G4float G4Expf(G4float initial_x)
|
||||
{
|
||||
G4float x = initial_x;
|
||||
G4float x = initial_x;
|
||||
|
||||
G4float z = G4ExpConsts::fpfloor( G4ExpConsts::LOG2EF * x +0.5f ); /* std::floor() truncates toward -infinity. */
|
||||
G4float z =
|
||||
G4ExpConsts::fpfloor(G4ExpConsts::LOG2EF * x +
|
||||
0.5f); /* std::floor() truncates toward -infinity. */
|
||||
|
||||
x -= z * G4ExpConsts::C1F;
|
||||
x -= z * G4ExpConsts::C2F;
|
||||
const int32_t n = int32_t ( z );
|
||||
x -= z * G4ExpConsts::C1F;
|
||||
x -= z * G4ExpConsts::C2F;
|
||||
const int32_t n = int32_t(z);
|
||||
|
||||
const G4float x2 = x * x;
|
||||
const G4float x2 = x * x;
|
||||
|
||||
z = x*G4ExpConsts::PX1expf;
|
||||
z += G4ExpConsts::PX2expf;
|
||||
z *= x;
|
||||
z += G4ExpConsts::PX3expf;
|
||||
z *= x;
|
||||
z += G4ExpConsts::PX4expf;
|
||||
z *= x;
|
||||
z += G4ExpConsts::PX5expf;
|
||||
z *= x;
|
||||
z += G4ExpConsts::PX6expf;
|
||||
z *= x2;
|
||||
z += x + 1.0f;
|
||||
z = x * G4ExpConsts::PX1expf;
|
||||
z += G4ExpConsts::PX2expf;
|
||||
z *= x;
|
||||
z += G4ExpConsts::PX3expf;
|
||||
z *= x;
|
||||
z += G4ExpConsts::PX4expf;
|
||||
z *= x;
|
||||
z += G4ExpConsts::PX5expf;
|
||||
z *= x;
|
||||
z += G4ExpConsts::PX6expf;
|
||||
z *= x2;
|
||||
z += x + 1.0f;
|
||||
|
||||
/* multiply by power of 2 */
|
||||
z *= G4ExpConsts::uint322sp((n+0x7f)<<23);
|
||||
/* multiply by power of 2 */
|
||||
z *= G4ExpConsts::uint322sp((n + 0x7f) << 23);
|
||||
|
||||
if (initial_x > G4ExpConsts::MAXLOGF) z=std::numeric_limits<G4float>::infinity();
|
||||
if (initial_x < G4ExpConsts::MINLOGF) z=0.f;
|
||||
if(initial_x > G4ExpConsts::MAXLOGF)
|
||||
z = std::numeric_limits<G4float>::infinity();
|
||||
if(initial_x < G4ExpConsts::MINLOGF)
|
||||
z = 0.f;
|
||||
|
||||
return z;
|
||||
return z;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void expv(const uint32_t size, G4double const * __restrict__ iarray, G4double* __restrict__ oarray);
|
||||
void G4Expv(const uint32_t size, G4double const * __restrict__ iarray, G4double* __restrict__ oarray);
|
||||
void expfv(const uint32_t size, G4float const * __restrict__ iarray, G4float* __restrict__ oarray);
|
||||
void G4Expfv(const uint32_t size, G4float const * __restrict__ iarray, G4float* __restrict__ oarray);
|
||||
void expv(const uint32_t size, G4double const* __restrict__ iarray,
|
||||
G4double* __restrict__ oarray);
|
||||
void G4Expv(const uint32_t size, G4double const* __restrict__ iarray,
|
||||
G4double* __restrict__ oarray);
|
||||
void expfv(const uint32_t size, G4float const* __restrict__ iarray,
|
||||
G4float* __restrict__ oarray);
|
||||
void G4Expfv(const uint32_t size, G4float const* __restrict__ iarray,
|
||||
G4float* __restrict__ oarray);
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
|
||||
@@ -23,238 +23,90 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4FPEDetection
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -*- C++ -*-
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// This global method should be used on LINUX/gcc or MacOS/clang platforms
|
||||
// for activating NaN detection and FPE signals, and forcing abortion of
|
||||
// the application at the time these are detected.
|
||||
// Meant to be used for debug purposes, can be activated by compiling the
|
||||
// "run" module with the flag G4FPE_DEBUG set in the environment.
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
#ifndef G4FPEDetection_h
|
||||
#define G4FPEDetection_h 1
|
||||
// Author: G.Cosmo, 14 July 2010 - First version
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4FPEDetection_hh
|
||||
#define G4FPEDetection_hh 1
|
||||
|
||||
#include <iostream>
|
||||
#include <stdlib.h> /* abort(), exit() */
|
||||
#include <stdlib.h> /* abort(), exit() */
|
||||
|
||||
#ifdef __linux__
|
||||
#if (defined(__GNUC__) && !defined(__clang__))
|
||||
#include <features.h>
|
||||
#include <fenv.h>
|
||||
#include <csignal>
|
||||
// for G4StackBacktrace()
|
||||
#include <execinfo.h>
|
||||
#include <cxxabi.h>
|
||||
# if(defined(__GNUC__) && !defined(__clang__))
|
||||
# include <csignal>
|
||||
# include <features.h>
|
||||
# include <fenv.h>
|
||||
// for G4StackBacktrace()
|
||||
# include <cxxabi.h>
|
||||
# include <execinfo.h>
|
||||
|
||||
struct sigaction termaction, oldaction;
|
||||
struct sigaction termaction, oldaction;
|
||||
|
||||
static void G4StackBackTrace()
|
||||
{
|
||||
// from http://linux.die.net/man/3/backtrace_symbols_fd
|
||||
#define BSIZE 50
|
||||
void * buffer[ BSIZE ];
|
||||
int nptrs = backtrace( buffer, BSIZE );
|
||||
char ** strings = backtrace_symbols( buffer, nptrs );
|
||||
if ( strings == NULL )
|
||||
{
|
||||
perror( "backtrace_symbols" );
|
||||
return;
|
||||
}
|
||||
std::cerr << std::endl<< "Call Stack:" << std::endl;
|
||||
for ( int j = 0; j < nptrs; j++ )
|
||||
{
|
||||
std::cerr << nptrs-j-1 <<": ";
|
||||
char * mangled_start = strchr( strings[j], '(' ) + 1;
|
||||
if (mangled_start) *(mangled_start-1) = '\0';
|
||||
char * mangled_end = strchr( mangled_start,'+' );
|
||||
if ( mangled_end ) *mangled_end = '\0';
|
||||
int status = 0;
|
||||
char *realname=0;
|
||||
if ( mangled_end && strlen(mangled_start) )
|
||||
realname = abi::__cxa_demangle( mangled_start, 0, 0, &status );
|
||||
if ( realname )
|
||||
{
|
||||
std::cerr << strings[j]<< " : " << realname << std::endl;
|
||||
free( realname );
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << strings[j] << std::endl;
|
||||
}
|
||||
}
|
||||
free( strings );
|
||||
// c++filt can demangle:
|
||||
// http://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
static void TerminationSignalHandler(int sig, siginfo_t* sinfo,
|
||||
void* /* context */)
|
||||
{
|
||||
std::cerr << "ERROR: " << sig;
|
||||
std::string message = "Floating-point exception (FPE).";
|
||||
|
||||
if (sinfo)
|
||||
{
|
||||
switch (sinfo->si_code)
|
||||
{
|
||||
#ifdef FPE_NOOP /* BUG: MacOS uses this instead of INTDIV */
|
||||
case FPE_NOOP:
|
||||
#endif
|
||||
case FPE_INTDIV:
|
||||
message = "Integer divide by zero.";
|
||||
break;
|
||||
case FPE_INTOVF:
|
||||
message = "Integer overflow.";
|
||||
break;
|
||||
case FPE_FLTDIV:
|
||||
message = "Floating point divide by zero.";
|
||||
break;
|
||||
case FPE_FLTOVF:
|
||||
message = "Floating point overflow.";
|
||||
break;
|
||||
case FPE_FLTUND:
|
||||
message = "Floating point underflow.";
|
||||
break;
|
||||
case FPE_FLTRES:
|
||||
message = "Floating point inexact result.";
|
||||
break;
|
||||
case FPE_FLTINV:
|
||||
message = "Floating point invalid operation.";
|
||||
break;
|
||||
case FPE_FLTSUB:
|
||||
message = "Subscript out of range.";
|
||||
break;
|
||||
default:
|
||||
message = "Unknown error.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::cerr << " - " << message << std::endl;
|
||||
G4StackBackTrace();
|
||||
::abort();
|
||||
}
|
||||
|
||||
static void InvalidOperationDetection()
|
||||
{
|
||||
std::cout << std::endl
|
||||
<< " "
|
||||
<< "############################################" << std::endl
|
||||
<< " "
|
||||
<< "!!! WARNING - FPE detection is activated !!!" << std::endl
|
||||
<< " "
|
||||
<< "############################################" << std::endl;
|
||||
|
||||
(void) feenableexcept( FE_DIVBYZERO );
|
||||
(void) feenableexcept( FE_INVALID );
|
||||
//(void) feenableexcept( FE_OVERFLOW );
|
||||
//(void) feenableexcept( FE_UNDERFLOW );
|
||||
|
||||
sigfillset(&termaction.sa_mask);
|
||||
sigdelset(&termaction.sa_mask,SIGFPE);
|
||||
termaction.sa_sigaction=TerminationSignalHandler;
|
||||
termaction.sa_flags=SA_SIGINFO;
|
||||
sigaction(SIGFPE, &termaction, &oldaction);
|
||||
}
|
||||
|
||||
#else /* Not GCC */
|
||||
|
||||
static void InvalidOperationDetection() {;}
|
||||
|
||||
#endif
|
||||
|
||||
#elif defined(__MACH__) /* MacOS */
|
||||
|
||||
#include <fenv.h>
|
||||
#include <signal.h>
|
||||
|
||||
//#define DEFINED_PPC (defined(__ppc__) || defined(__ppc64__))
|
||||
//#define DEFINED_INTEL (defined(__i386__) || defined(__x86_64__))
|
||||
|
||||
#if (defined(__ppc__) || defined(__ppc64__)) // PPC
|
||||
|
||||
#define FE_EXCEPT_SHIFT 22 // shift flags right to get masks
|
||||
#define FM_ALL_EXCEPT FE_ALL_EXCEPT >> FE_EXCEPT_SHIFT
|
||||
|
||||
static inline int feenableexcept (unsigned int excepts)
|
||||
{
|
||||
static fenv_t fenv;
|
||||
unsigned int new_excepts = (excepts & FE_ALL_EXCEPT) >> FE_EXCEPT_SHIFT,
|
||||
old_excepts; // all previous masks
|
||||
|
||||
if ( fegetenv (&fenv) ) { return -1; }
|
||||
old_excepts = (fenv & FM_ALL_EXCEPT) << FE_EXCEPT_SHIFT;
|
||||
fenv = (fenv & ~new_excepts) | new_excepts;
|
||||
|
||||
return ( fesetenv (&fenv) ? -1 : old_excepts );
|
||||
}
|
||||
|
||||
static inline int fedisableexcept (unsigned int excepts)
|
||||
{
|
||||
static fenv_t fenv;
|
||||
unsigned int still_on = ~((excepts & FE_ALL_EXCEPT) >> FE_EXCEPT_SHIFT),
|
||||
old_excepts; // previous masks
|
||||
|
||||
if ( fegetenv (&fenv) ) { return -1; }
|
||||
old_excepts = (fenv & FM_ALL_EXCEPT) << FE_EXCEPT_SHIFT;
|
||||
fenv &= still_on;
|
||||
|
||||
return ( fesetenv (&fenv) ? -1 : old_excepts );
|
||||
}
|
||||
|
||||
#elif (defined(__i386__) || defined(__x86_64__)) // INTEL
|
||||
|
||||
static inline int feenableexcept (unsigned int excepts)
|
||||
{
|
||||
static fenv_t fenv;
|
||||
unsigned int new_excepts = excepts & FE_ALL_EXCEPT,
|
||||
old_excepts; // previous masks
|
||||
|
||||
if ( fegetenv (&fenv) ) { return -1; }
|
||||
old_excepts = fenv.__control & FE_ALL_EXCEPT;
|
||||
|
||||
// unmask
|
||||
//
|
||||
fenv.__control &= ~new_excepts;
|
||||
fenv.__mxcsr &= ~(new_excepts << 7);
|
||||
|
||||
return ( fesetenv (&fenv) ? -1 : old_excepts );
|
||||
}
|
||||
|
||||
static inline int fedisableexcept (unsigned int excepts)
|
||||
{
|
||||
static fenv_t fenv;
|
||||
unsigned int new_excepts = excepts & FE_ALL_EXCEPT,
|
||||
old_excepts; // all previous masks
|
||||
|
||||
if ( fegetenv (&fenv) ) { return -1; }
|
||||
old_excepts = fenv.__control & FE_ALL_EXCEPT;
|
||||
|
||||
// mask
|
||||
//
|
||||
fenv.__control |= new_excepts;
|
||||
fenv.__mxcsr |= new_excepts << 7;
|
||||
|
||||
return ( fesetenv (&fenv) ? -1 : old_excepts );
|
||||
}
|
||||
|
||||
#endif /* PPC or INTEL enabling */
|
||||
|
||||
static void TerminationSignalHandler(int sig, siginfo_t* sinfo, void* /* context */)
|
||||
static void G4StackBackTrace()
|
||||
{
|
||||
// from http://linux.die.net/man/3/backtrace_symbols_fd
|
||||
# define BSIZE 50
|
||||
void* buffer[BSIZE];
|
||||
int nptrs = backtrace(buffer, BSIZE);
|
||||
char** strings = backtrace_symbols(buffer, nptrs);
|
||||
if(strings == NULL)
|
||||
{
|
||||
std::cerr << "ERROR: " << sig;
|
||||
std::string message = "Floating-point exception (FPE).";
|
||||
perror("backtrace_symbols");
|
||||
return;
|
||||
}
|
||||
std::cerr << std::endl << "Call Stack:" << std::endl;
|
||||
for(int j = 0; j < nptrs; j++)
|
||||
{
|
||||
std::cerr << nptrs - j - 1 << ": ";
|
||||
char* mangled_start = strchr(strings[j], '(') + 1;
|
||||
if(mangled_start)
|
||||
*(mangled_start - 1) = '\0';
|
||||
char* mangled_end = strchr(mangled_start, '+');
|
||||
if(mangled_end)
|
||||
*mangled_end = '\0';
|
||||
int status = 0;
|
||||
char* realname = 0;
|
||||
if(mangled_end && strlen(mangled_start))
|
||||
realname = abi::__cxa_demangle(mangled_start, 0, 0, &status);
|
||||
if(realname)
|
||||
{
|
||||
std::cerr << strings[j] << " : " << realname << std::endl;
|
||||
free(realname);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << strings[j] << std::endl;
|
||||
}
|
||||
}
|
||||
free(strings);
|
||||
// c++filt can demangle:
|
||||
// http://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
if (sinfo) {
|
||||
switch (sinfo->si_code) {
|
||||
#ifdef FPE_NOOP /* BUG: MacOS uses this instead of INTDIV */
|
||||
static void TerminationSignalHandler(int sig, siginfo_t* sinfo,
|
||||
void* /* context */)
|
||||
{
|
||||
std::cerr << "ERROR: " << sig;
|
||||
std::string message = "Floating-point exception (FPE).";
|
||||
|
||||
if(sinfo)
|
||||
{
|
||||
switch(sinfo->si_code)
|
||||
{
|
||||
# ifdef FPE_NOOP /* BUG: MacOS uses this instead of INTDIV */
|
||||
case FPE_NOOP:
|
||||
#endif
|
||||
# endif
|
||||
case FPE_INTDIV:
|
||||
message = "Integer divide by zero.";
|
||||
break;
|
||||
@@ -282,42 +134,206 @@
|
||||
default:
|
||||
message = "Unknown error.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << " - " << message << std::endl;
|
||||
|
||||
::abort();
|
||||
}
|
||||
std::cerr << " - " << message << std::endl;
|
||||
G4StackBackTrace();
|
||||
::abort();
|
||||
}
|
||||
|
||||
static void InvalidOperationDetection()
|
||||
static void InvalidOperationDetection()
|
||||
{
|
||||
std::cout << std::endl
|
||||
<< " "
|
||||
<< "############################################" << std::endl
|
||||
<< " "
|
||||
<< "!!! WARNING - FPE detection is activated !!!" << std::endl
|
||||
<< " "
|
||||
<< "############################################" << std::endl;
|
||||
|
||||
(void) feenableexcept(FE_DIVBYZERO);
|
||||
(void) feenableexcept(FE_INVALID);
|
||||
//(void) feenableexcept( FE_OVERFLOW );
|
||||
//(void) feenableexcept( FE_UNDERFLOW );
|
||||
|
||||
sigfillset(&termaction.sa_mask);
|
||||
sigdelset(&termaction.sa_mask, SIGFPE);
|
||||
termaction.sa_sigaction = TerminationSignalHandler;
|
||||
termaction.sa_flags = SA_SIGINFO;
|
||||
sigaction(SIGFPE, &termaction, &oldaction);
|
||||
}
|
||||
|
||||
# else /* Not GCC */
|
||||
|
||||
static void InvalidOperationDetection() { ; }
|
||||
|
||||
# endif
|
||||
|
||||
#elif defined(__MACH__) /* MacOS */
|
||||
|
||||
# include <fenv.h>
|
||||
# include <signal.h>
|
||||
|
||||
//#define DEFINED_PPC (defined(__ppc__) || defined(__ppc64__))
|
||||
//#define DEFINED_INTEL (defined(__i386__) || defined(__x86_64__))
|
||||
|
||||
# if(defined(__ppc__) || defined(__ppc64__)) // PPC
|
||||
|
||||
# define FE_EXCEPT_SHIFT 22 // shift flags right to get masks
|
||||
# define FM_ALL_EXCEPT FE_ALL_EXCEPT >> FE_EXCEPT_SHIFT
|
||||
|
||||
static inline int feenableexcept(unsigned int excepts)
|
||||
{
|
||||
static fenv_t fenv;
|
||||
unsigned int new_excepts = (excepts & FE_ALL_EXCEPT) >> FE_EXCEPT_SHIFT,
|
||||
old_excepts; // all previous masks
|
||||
|
||||
if(fegetenv(&fenv))
|
||||
{
|
||||
struct sigaction termaction, oldaction;
|
||||
return -1;
|
||||
}
|
||||
old_excepts = (fenv & FM_ALL_EXCEPT) << FE_EXCEPT_SHIFT;
|
||||
fenv = (fenv & ~new_excepts) | new_excepts;
|
||||
|
||||
std::cout << std::endl
|
||||
<< " "
|
||||
<< "############################################" << std::endl
|
||||
<< " "
|
||||
<< "!!! WARNING - FPE detection is activated !!!" << std::endl
|
||||
<< " "
|
||||
<< "############################################" << std::endl;
|
||||
return (fesetenv(&fenv) ? -1 : old_excepts);
|
||||
}
|
||||
|
||||
feenableexcept ( FE_DIVBYZERO );
|
||||
feenableexcept ( FE_INVALID );
|
||||
// fedisableexcept( FE_OVERFLOW );
|
||||
// fedisableexcept( FE_UNDERFLOW );
|
||||
static inline int fedisableexcept(unsigned int excepts)
|
||||
{
|
||||
static fenv_t fenv;
|
||||
unsigned int still_on = ~((excepts & FE_ALL_EXCEPT) >> FE_EXCEPT_SHIFT),
|
||||
old_excepts; // previous masks
|
||||
|
||||
sigfillset(&termaction.sa_mask);
|
||||
sigdelset(&termaction.sa_mask,SIGFPE);
|
||||
termaction.sa_sigaction=TerminationSignalHandler;
|
||||
termaction.sa_flags=SA_SIGINFO;
|
||||
sigaction(SIGFPE, &termaction, &oldaction);
|
||||
if(fegetenv(&fenv))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
old_excepts = (fenv & FM_ALL_EXCEPT) << FE_EXCEPT_SHIFT;
|
||||
fenv &= still_on;
|
||||
|
||||
return (fesetenv(&fenv) ? -1 : old_excepts);
|
||||
}
|
||||
|
||||
# elif(defined(__i386__) || defined(__x86_64__)) // INTEL
|
||||
|
||||
static inline int feenableexcept(unsigned int excepts)
|
||||
{
|
||||
static fenv_t fenv;
|
||||
unsigned int new_excepts = excepts & FE_ALL_EXCEPT,
|
||||
old_excepts; // previous masks
|
||||
|
||||
if(fegetenv(&fenv))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
old_excepts = fenv.__control & FE_ALL_EXCEPT;
|
||||
|
||||
// unmask
|
||||
//
|
||||
fenv.__control &= ~new_excepts;
|
||||
fenv.__mxcsr &= ~(new_excepts << 7);
|
||||
|
||||
return (fesetenv(&fenv) ? -1 : old_excepts);
|
||||
}
|
||||
|
||||
static inline int fedisableexcept(unsigned int excepts)
|
||||
{
|
||||
static fenv_t fenv;
|
||||
unsigned int new_excepts = excepts & FE_ALL_EXCEPT,
|
||||
old_excepts; // all previous masks
|
||||
|
||||
if(fegetenv(&fenv))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
old_excepts = fenv.__control & FE_ALL_EXCEPT;
|
||||
|
||||
// mask
|
||||
//
|
||||
fenv.__control |= new_excepts;
|
||||
fenv.__mxcsr |= new_excepts << 7;
|
||||
|
||||
return (fesetenv(&fenv) ? -1 : old_excepts);
|
||||
}
|
||||
|
||||
# endif /* PPC or INTEL enabling */
|
||||
|
||||
static void TerminationSignalHandler(int sig, siginfo_t* sinfo,
|
||||
void* /* context */)
|
||||
{
|
||||
std::cerr << "ERROR: " << sig;
|
||||
std::string message = "Floating-point exception (FPE).";
|
||||
|
||||
if(sinfo)
|
||||
{
|
||||
switch(sinfo->si_code)
|
||||
{
|
||||
# ifdef FPE_NOOP /* BUG: MacOS uses this instead of INTDIV */
|
||||
case FPE_NOOP:
|
||||
# endif
|
||||
case FPE_INTDIV:
|
||||
message = "Integer divide by zero.";
|
||||
break;
|
||||
case FPE_INTOVF:
|
||||
message = "Integer overflow.";
|
||||
break;
|
||||
case FPE_FLTDIV:
|
||||
message = "Floating point divide by zero.";
|
||||
break;
|
||||
case FPE_FLTOVF:
|
||||
message = "Floating point overflow.";
|
||||
break;
|
||||
case FPE_FLTUND:
|
||||
message = "Floating point underflow.";
|
||||
break;
|
||||
case FPE_FLTRES:
|
||||
message = "Floating point inexact result.";
|
||||
break;
|
||||
case FPE_FLTINV:
|
||||
message = "Floating point invalid operation.";
|
||||
break;
|
||||
case FPE_FLTSUB:
|
||||
message = "Subscript out of range.";
|
||||
break;
|
||||
default:
|
||||
message = "Unknown error.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#else /* Not Linux, nor MacOS ... */
|
||||
std::cerr << " - " << message << std::endl;
|
||||
|
||||
static void InvalidOperationDetection() {;}
|
||||
::abort();
|
||||
}
|
||||
|
||||
#endif /* Linux or MacOS */
|
||||
static void InvalidOperationDetection()
|
||||
{
|
||||
struct sigaction termaction, oldaction;
|
||||
|
||||
#endif /* G4FPEDetection_h */
|
||||
std::cout << std::endl
|
||||
<< " "
|
||||
<< "############################################" << std::endl
|
||||
<< " "
|
||||
<< "!!! WARNING - FPE detection is activated !!!" << std::endl
|
||||
<< " "
|
||||
<< "############################################" << std::endl;
|
||||
|
||||
feenableexcept(FE_DIVBYZERO);
|
||||
feenableexcept(FE_INVALID);
|
||||
// fedisableexcept( FE_OVERFLOW );
|
||||
// fedisableexcept( FE_UNDERFLOW );
|
||||
|
||||
sigfillset(&termaction.sa_mask);
|
||||
sigdelset(&termaction.sa_mask, SIGFPE);
|
||||
termaction.sa_sigaction = TerminationSignalHandler;
|
||||
termaction.sa_flags = SA_SIGINFO;
|
||||
sigaction(SIGFPE, &termaction, &oldaction);
|
||||
}
|
||||
|
||||
#else /* Not Linux, nor MacOS ... */
|
||||
|
||||
static void InvalidOperationDetection() { ; }
|
||||
|
||||
#endif /* Linux or MacOS */
|
||||
|
||||
#endif /* G4FPEDetection_hh */
|
||||
|
||||
@@ -23,67 +23,62 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4FastVector
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// History: first implementation, based on object model of
|
||||
// 2nd December 1995, G.Cosmo
|
||||
// ------------------------------------------------------------
|
||||
// Template class defining a vector of pointers,
|
||||
// not performing boundary checking.
|
||||
|
||||
#ifndef G4FastVector_h
|
||||
#define G4FastVector_h 1
|
||||
// Author: G.Cosmo, 2 December 1995
|
||||
// First implementation, based on object model
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4FastVector_hh
|
||||
#define G4FastVector_hh 1
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
template <class Type, G4int N>
|
||||
class G4FastVector
|
||||
class G4FastVector
|
||||
{
|
||||
// Template class defining a vector of pointers,
|
||||
// not performing boundary checking.
|
||||
public:
|
||||
G4FastVector() { ptr = &theArray[0]; }
|
||||
|
||||
public:
|
||||
~G4FastVector()
|
||||
{
|
||||
if(ptr != &theArray[0])
|
||||
delete[] ptr;
|
||||
}
|
||||
|
||||
G4FastVector() { ptr = &theArray[0]; }
|
||||
inline Type* operator[](G4int anIndex) const
|
||||
// Access operator to the array.
|
||||
{
|
||||
return ptr[anIndex];
|
||||
}
|
||||
|
||||
~G4FastVector()
|
||||
{
|
||||
if (ptr != &theArray[0]) delete [] ptr;
|
||||
}
|
||||
inline void Initialize(G4int items)
|
||||
// Normally the pointer ptr points to the stack-array
|
||||
// theArray; only when the number of items is greater
|
||||
// than N, memory is allocated dynamically.
|
||||
{
|
||||
if(ptr != &theArray[0])
|
||||
delete[] ptr;
|
||||
if(items > N)
|
||||
ptr = new Type*[items];
|
||||
else
|
||||
ptr = &theArray[0];
|
||||
}
|
||||
|
||||
inline Type* operator[](G4int anIndex) const
|
||||
// Access operator to the array.
|
||||
{
|
||||
return ptr[anIndex];
|
||||
}
|
||||
inline void SetElement(G4int anIndex, Type* anElement)
|
||||
// To insert an element at the given position inside
|
||||
// the vector.
|
||||
{
|
||||
ptr[anIndex] = anElement;
|
||||
}
|
||||
|
||||
void Initialize(G4int items)
|
||||
// Normally the pointer ptr points to the stack-array
|
||||
// theArray; only when the number of items is greater
|
||||
// than N, memory is allocated dynamically.
|
||||
{
|
||||
if (ptr != &theArray[0])
|
||||
delete [] ptr;
|
||||
if (items > N)
|
||||
ptr = new Type*[items];
|
||||
else
|
||||
ptr = &theArray[0];
|
||||
}
|
||||
|
||||
inline void SetElement(G4int anIndex, Type *anElement)
|
||||
// To insert an element at the given position inside
|
||||
// the vector.
|
||||
{
|
||||
ptr[anIndex] = anElement;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Type *theArray[N];
|
||||
Type **ptr;
|
||||
private:
|
||||
Type* theArray[N];
|
||||
Type** ptr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -23,13 +23,9 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4FilecoutDestination
|
||||
//
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// Class Description:
|
||||
// Class description:
|
||||
//
|
||||
// Implements a cout destination to a file.
|
||||
|
||||
@@ -37,8 +33,8 @@
|
||||
//
|
||||
// Author: A.Dotti (SLAC), April 2017
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4FILECOUTDESTINATION_HH_
|
||||
#define G4FILECOUTDESTINATION_HH_
|
||||
#ifndef G4FILECOUTDESTINATION_HH
|
||||
#define G4FILECOUTDESTINATION_HH
|
||||
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
@@ -47,27 +43,28 @@
|
||||
|
||||
class G4FilecoutDestination : public G4coutDestination
|
||||
{
|
||||
public:
|
||||
public:
|
||||
explicit G4FilecoutDestination(
|
||||
const G4String& fname, std::ios_base::openmode mode = std::ios_base::app)
|
||||
: m_name(fname)
|
||||
, m_mode(mode)
|
||||
, m_output(nullptr)
|
||||
{}
|
||||
virtual ~G4FilecoutDestination();
|
||||
|
||||
explicit G4FilecoutDestination(const G4String& fname ,
|
||||
std::ios_base::openmode mode = std::ios_base::app )
|
||||
: m_name(fname), m_mode(mode), m_output(nullptr) {}
|
||||
virtual ~G4FilecoutDestination();
|
||||
void SetFileName(const G4String& fname) { m_name = fname; }
|
||||
|
||||
void SetFileName(const G4String& fname) { m_name = fname; }
|
||||
void Open(std::ios_base::openmode mode = std::ios_base::app);
|
||||
// By default append to existing file
|
||||
void Close();
|
||||
|
||||
void Open(std::ios_base::openmode mode=std::ios_base::app);
|
||||
// By default append to existing file
|
||||
void Close();
|
||||
virtual G4int ReceiveG4cout(const G4String& msg) override;
|
||||
virtual G4int ReceiveG4cerr(const G4String& msg) override;
|
||||
|
||||
virtual G4int ReceiveG4cout(const G4String& msg) override;
|
||||
virtual G4int ReceiveG4cerr(const G4String& msg) override;
|
||||
|
||||
private:
|
||||
|
||||
G4String m_name;
|
||||
std::ios_base::openmode m_mode;
|
||||
std::unique_ptr<std::ofstream> m_output;
|
||||
private:
|
||||
G4String m_name;
|
||||
std::ios_base::openmode m_mode;
|
||||
std::unique_ptr<std::ofstream> m_output;
|
||||
};
|
||||
|
||||
#endif /* G4FILECOUTDESTINATION_HH_ */
|
||||
#endif
|
||||
|
||||
@@ -23,12 +23,9 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4GeometryTolerance
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// Class Description:
|
||||
// Class description:
|
||||
//
|
||||
// A singleton class for computation and storage of the tolerance values
|
||||
// used by the geometry modeler for precision on boundaries.
|
||||
@@ -44,9 +41,8 @@
|
||||
|
||||
// ---------------- G4GeometryTolerance ----------------
|
||||
//
|
||||
// Author: G.Cosmo (CERN), October 2006
|
||||
// ------------------------------------------------------------
|
||||
|
||||
// Author: G.Cosmo (CERN), 30 October 2006
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4GeometryTolerance_hh
|
||||
#define G4GeometryTolerance_hh
|
||||
|
||||
@@ -56,42 +52,37 @@ class G4GeometryTolerance
|
||||
{
|
||||
friend class G4GeometryManager;
|
||||
|
||||
public: // with description
|
||||
public: // with description
|
||||
static G4GeometryTolerance* GetInstance();
|
||||
// Get a pointer to the unique G4GeometryTolerance,
|
||||
// creating it if necessary and setting the tolerances.
|
||||
G4double GetSurfaceTolerance() const;
|
||||
// Returns the current Cartesian tolerance of a surface.
|
||||
G4double GetAngularTolerance() const;
|
||||
// Returns the current angular tolerance.
|
||||
G4double GetRadialTolerance() const;
|
||||
// Returns the current radial tolerance.
|
||||
|
||||
static G4GeometryTolerance* GetInstance();
|
||||
// Get a pointer to the unique G4GeometryTolerance,
|
||||
// creating it if necessary and setting the tolerances.
|
||||
G4double GetSurfaceTolerance() const;
|
||||
// Returns the current Cartesian tolerance of a surface.
|
||||
G4double GetAngularTolerance() const;
|
||||
// Returns the current angular tolerance.
|
||||
G4double GetRadialTolerance() const;
|
||||
// Returns the current radial tolerance.
|
||||
public: // without description
|
||||
~G4GeometryTolerance();
|
||||
// Destructor.
|
||||
|
||||
public: // without description
|
||||
protected:
|
||||
void SetSurfaceTolerance(G4double worldExtent);
|
||||
// Sets the Cartesian and Radial surface tolerance to a value computed
|
||||
// from the maximum extent of the world volume. This method
|
||||
// can be called only once, and is done only through the
|
||||
// G4GeometryManager class.
|
||||
|
||||
~G4GeometryTolerance();
|
||||
// Destructor.
|
||||
G4GeometryTolerance();
|
||||
// Protected constructor.
|
||||
|
||||
protected:
|
||||
|
||||
void SetSurfaceTolerance(G4double worldExtent);
|
||||
// Sets the Cartesian and Radial surface tolerance to a value computed
|
||||
// from the maximum extent of the world volume. This method
|
||||
// can be called only once, and is done only through the
|
||||
// G4GeometryManager class.
|
||||
|
||||
G4GeometryTolerance();
|
||||
// Protected constructor.
|
||||
|
||||
private:
|
||||
|
||||
static G4ThreadLocal G4GeometryTolerance* fpInstance;
|
||||
G4double fCarTolerance;
|
||||
G4double fAngTolerance;
|
||||
G4double fRadTolerance;
|
||||
G4bool fInitialised;
|
||||
};
|
||||
|
||||
#endif // G4GeometryTolerance_hh
|
||||
private:
|
||||
static G4ThreadLocal G4GeometryTolerance* fpInstance;
|
||||
G4double fCarTolerance;
|
||||
G4double fAngTolerance;
|
||||
G4double fRadTolerance;
|
||||
G4bool fInitialised = false;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -41,10 +41,9 @@
|
||||
//! \brief Defined if Geant4 is built with additional verbosity in logging
|
||||
#cmakedefine G4VERBOSE
|
||||
|
||||
//! \def G4USE_STD11
|
||||
//! \brief Defined if the C++11 standard or newer is in use
|
||||
//! \deprecated Geant4 requires C++11 or later, so this should no longer be used
|
||||
#define G4USE_STD11
|
||||
//! \def GEANT4_USE_TBB
|
||||
//! \brief Defined if Geant4 built with TBB support
|
||||
#cmakedefine GEANT4_USE_TBB
|
||||
|
||||
//! \def GEANT4_USE_TIMEMORY
|
||||
//! \brief Defined if Geant4 built with TiMemory support
|
||||
|
||||
@@ -23,12 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Class G4LPhysicsFreeVector -- header file
|
||||
// G4LPhysicsFreeVector
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
@@ -38,38 +33,32 @@
|
||||
// who may wish to implement a free vector in a different way.
|
||||
// A subdivision method is used to find the energy|momentum bin.
|
||||
|
||||
// F.W. Jones, TRIUMF, 04-JUN-96
|
||||
// 11-NOV-00 H.Kurashige: use STL vector for dataVector and binVector
|
||||
// 02-APR-08 A.Bagulya: use GetValue() from base class
|
||||
// 02-OCT-13 V.Ivanchenko : Remove FindBinLocation method
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
#ifndef G4LPhysicsFreeVector_h
|
||||
#define G4LPhysicsFreeVector_h 1
|
||||
// Author: F.W. Jones (TRIUMF), 04-June-1996 - First implementation
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4LPhysicsFreeVector_hh
|
||||
#define G4LPhysicsFreeVector_hh 1
|
||||
|
||||
#include "G4PhysicsFreeVector.hh"
|
||||
|
||||
class G4LPhysicsFreeVector : public G4PhysicsFreeVector
|
||||
class G4LPhysicsFreeVector : public G4PhysicsFreeVector
|
||||
{
|
||||
|
||||
public: // with description
|
||||
|
||||
public:
|
||||
G4LPhysicsFreeVector();
|
||||
// the vector will be filled from external file using Retrieve method
|
||||
// The vector will be filled from external file using Retrieve method
|
||||
|
||||
G4LPhysicsFreeVector(size_t length, G4double emin=0.0, G4double emax=0.0);
|
||||
// the vector with 'length' elements will be filled using PutValues method
|
||||
// by default the vector is initialized with zeros
|
||||
G4LPhysicsFreeVector(std::size_t length, G4double emin = 0.,
|
||||
G4double emax = 0.);
|
||||
// The vector with 'length' elements will be filled using PutValues
|
||||
// method by default the vector is initialized with zeros
|
||||
|
||||
virtual ~G4LPhysicsFreeVector();
|
||||
|
||||
inline void PutValues(size_t index, G4double e, G4double dataValue);
|
||||
// user code is responsible for correct filling of all elements
|
||||
inline void PutValues(std::size_t index, G4double e, G4double dataValue);
|
||||
// User code is responsible for correct filling of all elements
|
||||
};
|
||||
|
||||
inline
|
||||
void G4LPhysicsFreeVector::PutValues(size_t index, G4double e, G4double value)
|
||||
inline void G4LPhysicsFreeVector::PutValues(std::size_t index, G4double e,
|
||||
G4double value)
|
||||
{
|
||||
G4PhysicsFreeVector::PutValue(index, e, value);
|
||||
}
|
||||
|
||||
@@ -23,13 +23,9 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4LockcoutDestination
|
||||
//
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// Class Description:
|
||||
// Class description:
|
||||
//
|
||||
// Implements a output destination to std::cout / std::cerr with a
|
||||
// mutex lock access to the shared resource.
|
||||
@@ -38,19 +34,18 @@
|
||||
//
|
||||
// Author: A.Dotti (SLAC), April 2017
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4LOCKCOUTDESTINATION_HH_
|
||||
#define G4LOCKCOUTDESTINATION_HH_
|
||||
#ifndef G4LOCKCOUTDESTINATION_HH
|
||||
#define G4LOCKCOUTDESTINATION_HH
|
||||
|
||||
#include "G4coutDestination.hh"
|
||||
|
||||
class G4LockcoutDestination : public G4coutDestination
|
||||
{
|
||||
public:
|
||||
|
||||
G4LockcoutDestination() = default;
|
||||
virtual ~G4LockcoutDestination();
|
||||
virtual G4int ReceiveG4cout(const G4String& msg) override;
|
||||
virtual G4int ReceiveG4cerr(const G4String& msg) override;
|
||||
public:
|
||||
G4LockcoutDestination() = default;
|
||||
virtual ~G4LockcoutDestination();
|
||||
virtual G4int ReceiveG4cout(const G4String& msg) override;
|
||||
virtual G4int ReceiveG4cerr(const G4String& msg) override;
|
||||
};
|
||||
|
||||
#endif /* G4LOCKCOUTDESTINATION_HH_ */
|
||||
#endif
|
||||
|
||||
@@ -23,17 +23,13 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4Log
|
||||
//
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
// Class Description:
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// The basic idea is to exploit Pade polynomials.
|
||||
// A lot of ideas were inspired by the cephes math library
|
||||
// (by Stephen L. Moshier moshier@na-net.ornl.gov) as well as actual code.
|
||||
// (by Stephen L. Moshier moshier@na-net.ornl.gov) as well as actual code.
|
||||
// The Cephes library can be found here: http://www.netlib.org/cephes/
|
||||
// Code and algorithms for G4Exp have been extracted and adapted for Geant4
|
||||
// from the original implementation in the VDT mathematical library
|
||||
@@ -43,33 +39,33 @@
|
||||
// Author: Danilo Piparo, Thomas Hauth, Vincenzo Innocente
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
/*
|
||||
/*
|
||||
* VDT is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4Log_h
|
||||
#define G4Log_h 1
|
||||
#ifndef G4Log_hh
|
||||
#define G4Log_hh 1
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#define G4Log std::log
|
||||
# define G4Log std::log
|
||||
|
||||
#else
|
||||
|
||||
#include <limits>
|
||||
#include <stdint.h>
|
||||
#include "G4Types.hh"
|
||||
# include "G4Types.hh"
|
||||
# include <limits>
|
||||
# include <stdint.h>
|
||||
|
||||
// local namespace for the constants/functions which are necessary only here
|
||||
//
|
||||
@@ -78,7 +74,7 @@ namespace G4LogConsts
|
||||
const G4double LOG_UPPER_LIMIT = 1e307;
|
||||
const G4double LOG_LOWER_LIMIT = 0;
|
||||
|
||||
const G4double SQRTH = 0.70710678118654752440;
|
||||
const G4double SQRTH = 0.70710678118654752440;
|
||||
const G4float MAXNUMF = 3.4028234663852885981170418348451692544e38f;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -87,11 +83,11 @@ namespace G4LogConsts
|
||||
//
|
||||
union ieee754
|
||||
{
|
||||
ieee754 () {};
|
||||
ieee754 (G4double thed) {d=thed;};
|
||||
ieee754 (uint64_t thell) {ll=thell;};
|
||||
ieee754 (G4float thef) {f[0]=thef;};
|
||||
ieee754 (uint32_t thei) {i[0]=thei;};
|
||||
ieee754(){};
|
||||
ieee754(G4double thed) { d = thed; };
|
||||
ieee754(uint64_t thell) { ll = thell; };
|
||||
ieee754(G4float thef) { f[0] = thef; };
|
||||
ieee754(uint32_t thei) { i[0] = thei; };
|
||||
G4double d;
|
||||
G4float f[2];
|
||||
uint32_t i[2];
|
||||
@@ -101,46 +97,46 @@ namespace G4LogConsts
|
||||
|
||||
inline G4double get_log_px(const G4double x)
|
||||
{
|
||||
const G4double PX1log = 1.01875663804580931796E-4;
|
||||
const G4double PX2log = 4.97494994976747001425E-1;
|
||||
const G4double PX3log = 4.70579119878881725854E0;
|
||||
const G4double PX4log = 1.44989225341610930846E1;
|
||||
const G4double PX5log = 1.79368678507819816313E1;
|
||||
const G4double PX6log = 7.70838733755885391666E0;
|
||||
const G4double PX1log = 1.01875663804580931796E-4;
|
||||
const G4double PX2log = 4.97494994976747001425E-1;
|
||||
const G4double PX3log = 4.70579119878881725854E0;
|
||||
const G4double PX4log = 1.44989225341610930846E1;
|
||||
const G4double PX5log = 1.79368678507819816313E1;
|
||||
const G4double PX6log = 7.70838733755885391666E0;
|
||||
|
||||
G4double px = PX1log;
|
||||
px *= x;
|
||||
px += PX2log;
|
||||
px *= x;
|
||||
px += PX3log;
|
||||
px *= x;
|
||||
px += PX4log;
|
||||
px *= x;
|
||||
px += PX5log;
|
||||
px *= x;
|
||||
px += PX6log;
|
||||
return px;
|
||||
G4double px = PX1log;
|
||||
px *= x;
|
||||
px += PX2log;
|
||||
px *= x;
|
||||
px += PX3log;
|
||||
px *= x;
|
||||
px += PX4log;
|
||||
px *= x;
|
||||
px += PX5log;
|
||||
px *= x;
|
||||
px += PX6log;
|
||||
return px;
|
||||
}
|
||||
|
||||
inline G4double get_log_qx(const G4double x)
|
||||
{
|
||||
const G4double QX1log = 1.12873587189167450590E1;
|
||||
const G4double QX2log = 4.52279145837532221105E1;
|
||||
const G4double QX3log = 8.29875266912776603211E1;
|
||||
const G4double QX4log = 7.11544750618563894466E1;
|
||||
const G4double QX5log = 2.31251620126765340583E1;
|
||||
const G4double QX1log = 1.12873587189167450590E1;
|
||||
const G4double QX2log = 4.52279145837532221105E1;
|
||||
const G4double QX3log = 8.29875266912776603211E1;
|
||||
const G4double QX4log = 7.11544750618563894466E1;
|
||||
const G4double QX5log = 2.31251620126765340583E1;
|
||||
|
||||
G4double qx = x;
|
||||
qx += QX1log;
|
||||
qx *=x;
|
||||
qx += QX2log;
|
||||
qx *=x;
|
||||
qx += QX3log;
|
||||
qx *=x;
|
||||
qx += QX4log;
|
||||
qx *=x;
|
||||
qx += QX5log;
|
||||
return qx;
|
||||
G4double qx = x;
|
||||
qx += QX1log;
|
||||
qx *= x;
|
||||
qx += QX2log;
|
||||
qx *= x;
|
||||
qx += QX3log;
|
||||
qx *= x;
|
||||
qx += QX4log;
|
||||
qx *= x;
|
||||
qx += QX5log;
|
||||
return qx;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -149,7 +145,7 @@ namespace G4LogConsts
|
||||
inline uint64_t dp2uint64(G4double x)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.d=x;
|
||||
tmp.d = x;
|
||||
return tmp.ll;
|
||||
}
|
||||
|
||||
@@ -159,7 +155,7 @@ namespace G4LogConsts
|
||||
inline G4double uint642dp(uint64_t ll)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.ll=ll;
|
||||
tmp.ll = ll;
|
||||
return tmp.d;
|
||||
}
|
||||
|
||||
@@ -169,7 +165,7 @@ namespace G4LogConsts
|
||||
inline G4float uint322sp(G4int x)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.i[0]=x;
|
||||
tmp.i[0] = x;
|
||||
return tmp.f[0];
|
||||
}
|
||||
|
||||
@@ -179,13 +175,13 @@ namespace G4LogConsts
|
||||
inline uint32_t sp2uint32(G4float x)
|
||||
{
|
||||
ieee754 tmp;
|
||||
tmp.f[0]=x;
|
||||
tmp.f[0] = x;
|
||||
return tmp.i[0];
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// Like frexp but vectorising and the exponent is a double.
|
||||
inline G4double getMantExponent(const G4double x, G4double & fe)
|
||||
inline G4double getMantExponent(const G4double x, G4double& fe)
|
||||
{
|
||||
uint64_t n = dp2uint64(x);
|
||||
|
||||
@@ -194,14 +190,15 @@ namespace G4LogConsts
|
||||
uint64_t le = (n >> 52);
|
||||
|
||||
// chop the head of the number: an int contains more than 11 bits (32)
|
||||
int32_t e = le; // This is important since sums on uint64_t do not vectorise
|
||||
fe = e-1023 ;
|
||||
int32_t e =
|
||||
le; // This is important since sums on uint64_t do not vectorise
|
||||
fe = e - 1023;
|
||||
|
||||
// This puts to 11 zeroes the exponent
|
||||
n &=0x800FFFFFFFFFFFFFULL;
|
||||
n &= 0x800FFFFFFFFFFFFFULL;
|
||||
// build a mask which is 0.5, i.e. an exponent equal to 1022
|
||||
// which means *2, see the above +1.
|
||||
const uint64_t p05 = 0x3FE0000000000000ULL; //dp2uint64(0.5);
|
||||
const uint64_t p05 = 0x3FE0000000000000ULL; // dp2uint64(0.5);
|
||||
n |= p05;
|
||||
|
||||
return uint642dp(n);
|
||||
@@ -209,59 +206,59 @@ namespace G4LogConsts
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// Like frexp but vectorising and the exponent is a float.
|
||||
inline G4float getMantExponentf(const G4float x, G4float & fe)
|
||||
inline G4float getMantExponentf(const G4float x, G4float& fe)
|
||||
{
|
||||
uint32_t n = sp2uint32(x);
|
||||
int32_t e = (n >> 23)-127;
|
||||
fe = e;
|
||||
int32_t e = (n >> 23) - 127;
|
||||
fe = e;
|
||||
|
||||
// fractional part
|
||||
const uint32_t p05f = 0x3f000000; // //sp2uint32(0.5);
|
||||
n &= 0x807fffff;// ~0x7f800000;
|
||||
const uint32_t p05f = 0x3f000000; // //sp2uint32(0.5);
|
||||
n &= 0x807fffff; // ~0x7f800000;
|
||||
n |= p05f;
|
||||
|
||||
return uint322sp(n);
|
||||
}
|
||||
}
|
||||
} // namespace G4LogConsts
|
||||
|
||||
// Log double precision --------------------------------------------------------
|
||||
|
||||
inline G4double G4Log(G4double x)
|
||||
{
|
||||
const G4double original_x = x;
|
||||
const G4double original_x = x;
|
||||
|
||||
/* separate mantissa from exponent */
|
||||
G4double fe;
|
||||
x = G4LogConsts::getMantExponent(x,fe);
|
||||
/* separate mantissa from exponent */
|
||||
G4double fe;
|
||||
x = G4LogConsts::getMantExponent(x, fe);
|
||||
|
||||
// blending
|
||||
x > G4LogConsts::SQRTH? fe+=1. : x+=x ;
|
||||
x -= 1.0;
|
||||
// blending
|
||||
x > G4LogConsts::SQRTH ? fe += 1. : x += x;
|
||||
x -= 1.0;
|
||||
|
||||
/* rational form */
|
||||
G4double px = G4LogConsts::get_log_px(x);
|
||||
/* rational form */
|
||||
G4double px = G4LogConsts::get_log_px(x);
|
||||
|
||||
//for the final formula
|
||||
const G4double x2 = x*x;
|
||||
px *= x;
|
||||
px *= x2;
|
||||
// for the final formula
|
||||
const G4double x2 = x * x;
|
||||
px *= x;
|
||||
px *= x2;
|
||||
|
||||
const G4double qx = G4LogConsts::get_log_qx(x);
|
||||
const G4double qx = G4LogConsts::get_log_qx(x);
|
||||
|
||||
G4double res = px / qx ;
|
||||
G4double res = px / qx;
|
||||
|
||||
res -= fe * 2.121944400546905827679e-4;
|
||||
res -= 0.5 * x2 ;
|
||||
res -= fe * 2.121944400546905827679e-4;
|
||||
res -= 0.5 * x2;
|
||||
|
||||
res = x + res;
|
||||
res += fe * 0.693359375;
|
||||
res = x + res;
|
||||
res += fe * 0.693359375;
|
||||
|
||||
if (original_x > G4LogConsts::LOG_UPPER_LIMIT)
|
||||
res = std::numeric_limits<G4double>::infinity();
|
||||
if (original_x < G4LogConsts::LOG_LOWER_LIMIT) // THIS IS NAN!
|
||||
res = - std::numeric_limits<G4double>::quiet_NaN();
|
||||
if(original_x > G4LogConsts::LOG_UPPER_LIMIT)
|
||||
res = std::numeric_limits<G4double>::infinity();
|
||||
if(original_x < G4LogConsts::LOG_LOWER_LIMIT) // THIS IS NAN!
|
||||
res = -std::numeric_limits<G4double>::quiet_NaN();
|
||||
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
// Log single precision --------------------------------------------------------
|
||||
@@ -283,66 +280,70 @@ namespace G4LogConsts
|
||||
|
||||
inline G4float get_log_poly(const G4float x)
|
||||
{
|
||||
G4float y = x*PX1logf;
|
||||
y += PX2logf;
|
||||
y *= x;
|
||||
y += PX3logf;
|
||||
y *= x;
|
||||
y += PX4logf;
|
||||
y *= x;
|
||||
y += PX5logf;
|
||||
y *= x;
|
||||
y += PX6logf;
|
||||
y *= x;
|
||||
y += PX7logf;
|
||||
y *= x;
|
||||
y += PX8logf;
|
||||
y *= x;
|
||||
y += PX9logf;
|
||||
return y;
|
||||
G4float y = x * PX1logf;
|
||||
y += PX2logf;
|
||||
y *= x;
|
||||
y += PX3logf;
|
||||
y *= x;
|
||||
y += PX4logf;
|
||||
y *= x;
|
||||
y += PX5logf;
|
||||
y *= x;
|
||||
y += PX6logf;
|
||||
y *= x;
|
||||
y += PX7logf;
|
||||
y *= x;
|
||||
y += PX8logf;
|
||||
y *= x;
|
||||
y += PX9logf;
|
||||
return y;
|
||||
}
|
||||
|
||||
const G4float SQRTHF = 0.707106781186547524f;
|
||||
}
|
||||
} // namespace G4LogConsts
|
||||
|
||||
// Log single precision --------------------------------------------------------
|
||||
|
||||
inline G4float G4Logf( G4float x )
|
||||
inline G4float G4Logf(G4float x)
|
||||
{
|
||||
const G4float original_x = x;
|
||||
const G4float original_x = x;
|
||||
|
||||
G4float fe;
|
||||
x = G4LogConsts::getMantExponentf( x, fe);
|
||||
G4float fe;
|
||||
x = G4LogConsts::getMantExponentf(x, fe);
|
||||
|
||||
x > G4LogConsts::SQRTHF? fe+=1.f : x+=x ;
|
||||
x -= 1.0f;
|
||||
x > G4LogConsts::SQRTHF ? fe += 1.f : x += x;
|
||||
x -= 1.0f;
|
||||
|
||||
const G4float x2 = x*x;
|
||||
const G4float x2 = x * x;
|
||||
|
||||
G4float res = G4LogConsts::get_log_poly(x);
|
||||
res *= x2*x;
|
||||
G4float res = G4LogConsts::get_log_poly(x);
|
||||
res *= x2 * x;
|
||||
|
||||
res += -2.12194440e-4f * fe;
|
||||
res += -0.5f * x2;
|
||||
res += -2.12194440e-4f * fe;
|
||||
res += -0.5f * x2;
|
||||
|
||||
res= x + res;
|
||||
res = x + res;
|
||||
|
||||
res += 0.693359375f * fe;
|
||||
res += 0.693359375f * fe;
|
||||
|
||||
if (original_x > G4LogConsts::LOGF_UPPER_LIMIT)
|
||||
res = std::numeric_limits<G4float>::infinity();
|
||||
if (original_x < G4LogConsts::LOGF_LOWER_LIMIT)
|
||||
res = -std::numeric_limits<G4float>::quiet_NaN();
|
||||
if(original_x > G4LogConsts::LOGF_UPPER_LIMIT)
|
||||
res = std::numeric_limits<G4float>::infinity();
|
||||
if(original_x < G4LogConsts::LOGF_LOWER_LIMIT)
|
||||
res = -std::numeric_limits<G4float>::quiet_NaN();
|
||||
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void logv(const uint32_t size, G4double const * __restrict__ iarray, G4double* __restrict__ oarray);
|
||||
void G4Logv(const uint32_t size, G4double const * __restrict__ iarray, G4double* __restrict__ oarray);
|
||||
void logfv(const uint32_t size, G4float const * __restrict__ iarray, G4float* __restrict__ oarray);
|
||||
void G4Logfv(const uint32_t size, G4float const * __restrict__ iarray, G4float* __restrict__ oarray);
|
||||
void logv(const uint32_t size, G4double const* __restrict__ iarray,
|
||||
G4double* __restrict__ oarray);
|
||||
void G4Logv(const uint32_t size, G4double const* __restrict__ iarray,
|
||||
G4double* __restrict__ oarray);
|
||||
void logfv(const uint32_t size, G4float const* __restrict__ iarray,
|
||||
G4float* __restrict__ oarray);
|
||||
void G4Logfv(const uint32_t size, G4float const* __restrict__ iarray,
|
||||
G4float* __restrict__ oarray);
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
|
||||
@@ -23,18 +23,16 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4MTBarrier
|
||||
//
|
||||
// ---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// Class Description:
|
||||
// Class description:
|
||||
//
|
||||
// This class defines a synchronization point between threads: a master
|
||||
// and a pool of workers.
|
||||
// A barrier is a (shared) instance of this class. Master sets the number
|
||||
// of active threads to wait for, then it waits for workers to become ready
|
||||
// calling the method WaitForReadyWorkers(). The master thread will block on this
|
||||
// call.
|
||||
// calling the method WaitForReadyWorkers().
|
||||
// The master thread will block on this call.
|
||||
// Each of the workers calls ThisWorkerReady() when it is ready to continue.
|
||||
// It will block on this call.
|
||||
// When all worker threads have called ThisWorkerReady and are waiting the
|
||||
@@ -61,43 +59,41 @@
|
||||
// methods LoopWaitingWorkers and ResetCounterAndBroadcast methods in the
|
||||
// master. For examples of usage of this class see G4MTRunManager
|
||||
//
|
||||
// G4MTBarrier.hh
|
||||
//
|
||||
// Created on: Feb 10, 2016
|
||||
// Author: adotti
|
||||
//
|
||||
// =====================================
|
||||
// Barriers mechanism
|
||||
// =====================================
|
||||
// We want to implement barriers.
|
||||
// We define a barrier has a point in which threads synchronize.
|
||||
// When workers threads reach a barrier they wait for the master thread a
|
||||
// signal that they can continue. The master thread broadcast this signal
|
||||
// only when all worker threads have reached this point.
|
||||
// Currently only three points require this sync in the life-time of a G4 applicattion:
|
||||
// Just before and just after the for-loop controlling the thread event-loop.
|
||||
// Between runs.
|
||||
// Currently only three points require this sync in the life-time of a G4
|
||||
// application: just before and just after the for-loop controlling the
|
||||
// thread event-loop and between runs.
|
||||
//
|
||||
// The basic algorithm of each barrier works like this:
|
||||
// In the master:
|
||||
// WaitWorkers() {
|
||||
// WaitWorkers()
|
||||
// {
|
||||
// while (true)
|
||||
// {
|
||||
// G4AutoLock l(&counterMutex); || Mutex is locked (1)
|
||||
// if ( counter == nActiveThreads ) break;
|
||||
// G4CONDITIONWAIT( &conditionOnCounter, &counterMutex); || Mutex is atomically released and wait, upon return locked (2)
|
||||
// G4AutoLock l(&counterMutex); || Mutex is locked
|
||||
// (1) if ( counter == nActiveThreads ) break; G4CONDITIONWAIT(
|
||||
// &conditionOnCounter, &counterMutex); || Mutex is atomically released and
|
||||
// wait, upon return locked (2)
|
||||
// } || unlock mutex
|
||||
// G4AutoLock l(&counterMutex); || lock again mutex (3)
|
||||
// G4CONDITIONBROADCAST( &doSomethingCanStart ); || Here mutex is locked (4)
|
||||
// G4AutoLock l(&counterMutex); || lock again mutex
|
||||
// (3) G4CONDITIONBROADCAST( &doSomethingCanStart ); || Here mutex
|
||||
// is locked (4)
|
||||
// } || final unlock (5)
|
||||
// In the workers:
|
||||
// WaitSignalFromMaster() {
|
||||
// WaitSignalFromMaster()
|
||||
// {
|
||||
// G4AutoLock l(&counterMutex); || (6)
|
||||
// ++counter;
|
||||
// G4CONDITIONBROADCAST(&conditionOnCounter); || (7)
|
||||
// G4CONDITIONWAIT( &doSomethingCanStart , &counterMutex);|| (8)
|
||||
// }
|
||||
// Each barriers requires 2 conditions and one mutex, plus a counter.
|
||||
// Each barrier requires 2 conditions and one mutex, plus a counter.
|
||||
// Important note: the thread calling broadcast should hold the mutex
|
||||
// before calling broadcast to obtain predictible behavior
|
||||
// http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_cond_broadcast.html
|
||||
@@ -116,40 +112,48 @@
|
||||
// | End | 1 | -
|
||||
// Similarly for more than one worker threads or if worker starts
|
||||
|
||||
#ifndef G4MTBARRIER_HH_
|
||||
#define G4MTBARRIER_HH_
|
||||
// Author: A.Dotti (SLAC), 10 February 2016
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4MTBARRIER_HH
|
||||
#define G4MTBARRIER_HH
|
||||
|
||||
#include "G4Threading.hh"
|
||||
|
||||
class G4MTBarrier
|
||||
{
|
||||
public:
|
||||
G4MTBarrier() : G4MTBarrier(1) {}
|
||||
public:
|
||||
G4MTBarrier()
|
||||
: G4MTBarrier(1)
|
||||
{}
|
||||
virtual ~G4MTBarrier() {}
|
||||
G4MTBarrier(const G4MTBarrier&) = delete;
|
||||
G4MTBarrier& operator=(const G4MTBarrier&) = delete;
|
||||
//on explicitly defaulted move at
|
||||
//https://msdn.microsoft.com/en-us/library/dn457344.aspx
|
||||
//G4MTBarrier(G4MTBarrier&&) = default;
|
||||
//G4MTBarrier& operator=(G4MTBarrier&&) = default;
|
||||
G4MTBarrier( unsigned int numThreads );
|
||||
|
||||
// on explicitly defaulted move at
|
||||
// https://msdn.microsoft.com/en-us/library/dn457344.aspx
|
||||
// G4MTBarrier(G4MTBarrier&&) = default;
|
||||
// G4MTBarrier& operator=(G4MTBarrier&&) = default;
|
||||
|
||||
G4MTBarrier(unsigned int numThreads);
|
||||
void ThisWorkerReady();
|
||||
virtual void WaitForReadyWorkers();
|
||||
inline void SetActiveThreads( unsigned int val ) { m_numActiveThreads = val; }
|
||||
inline void SetActiveThreads(unsigned int val) { m_numActiveThreads = val; }
|
||||
void ResetCounter();
|
||||
unsigned int GetCounter();
|
||||
void Wait();
|
||||
void ReleaseBarrier();
|
||||
inline void Wait( unsigned int numt ) {
|
||||
SetActiveThreads( numt );
|
||||
inline void Wait(unsigned int numt)
|
||||
{
|
||||
SetActiveThreads(numt);
|
||||
Wait();
|
||||
}
|
||||
private:
|
||||
unsigned int m_numActiveThreads;
|
||||
unsigned int m_counter;
|
||||
|
||||
private:
|
||||
unsigned int m_numActiveThreads = 0;
|
||||
unsigned int m_counter = 0;
|
||||
G4Mutex m_mutex;
|
||||
G4Condition m_counterChanged;
|
||||
G4Condition m_continue;
|
||||
};
|
||||
|
||||
#endif /* G4MTBARRIER_HH_ */
|
||||
#endif
|
||||
|
||||
@@ -23,92 +23,86 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4MTcoutDestination
|
||||
//
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4MTcoutDestination.hh
|
||||
//
|
||||
// ---------------------------------------------------------------
|
||||
#ifndef G4MTcoutDestination_H
|
||||
#define G4MTcoutDestination_H
|
||||
// Handling of cout/cerr in multi-threaded mode
|
||||
|
||||
// Authors: M.Asai, A.Dotti (SLAC) - 23 May 2013
|
||||
// ---------------------------------------------------------------
|
||||
#ifndef G4MTcoutDestination_hh
|
||||
#define G4MTcoutDestination_hh
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4MulticoutDestination.hh"
|
||||
#include "G4StateManager.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
class G4LockcoutDestination;
|
||||
|
||||
class G4MTcoutDestination : public G4MulticoutDestination
|
||||
{
|
||||
public:
|
||||
public:
|
||||
explicit G4MTcoutDestination(const G4int& threadId);
|
||||
virtual ~G4MTcoutDestination();
|
||||
|
||||
explicit G4MTcoutDestination(const G4int& threadId);
|
||||
virtual ~G4MTcoutDestination();
|
||||
virtual void Reset();
|
||||
|
||||
virtual void Reset();
|
||||
void SetDefaultOutput(G4bool addMasterDestination = true,
|
||||
G4bool formatAlsoMaster = true);
|
||||
|
||||
void SetDefaultOutput( G4bool addMasterDestination = true ,
|
||||
G4bool formatAlsoMaster = true );
|
||||
void SetCoutFileName(const G4String& fileN = "G4cout.txt",
|
||||
G4bool ifAppend = true);
|
||||
void AddCoutFileName(const G4String& fileN = "G4cout.txt",
|
||||
G4bool ifAppend = true);
|
||||
void SetCerrFileName(const G4String& fileN = "G4cerr.txt",
|
||||
G4bool ifAppend = true);
|
||||
void AddCerrFileName(const G4String& fileN = "G4cerr.txt",
|
||||
G4bool ifAppend = true);
|
||||
|
||||
void SetCoutFileName(const G4String& fileN = "G4cout.txt",
|
||||
G4bool ifAppend = true);
|
||||
void AddCoutFileName(const G4String& fileN = "G4cout.txt",
|
||||
G4bool ifAppend = true);
|
||||
void SetCerrFileName(const G4String& fileN = "G4cerr.txt",
|
||||
G4bool ifAppend = true);
|
||||
void AddCerrFileName(const G4String& fileN = "G4cerr.txt",
|
||||
G4bool ifAppend = true);
|
||||
void EnableBuffering(G4bool flag = true);
|
||||
|
||||
void EnableBuffering(G4bool flag=true);
|
||||
inline void SetPrefixString(const G4String& wd = "G4WT") { prefix = wd; }
|
||||
|
||||
inline void SetPrefixString(const G4String& wd = "G4WT") { prefix = wd; }
|
||||
void SetIgnoreCout(G4int tid = 0);
|
||||
inline void SetIgnoreInit(G4bool val = true) { ignoreInit = val; }
|
||||
|
||||
void SetIgnoreCout(G4int tid = 0);
|
||||
inline void SetIgnoreInit(G4bool val=true) { ignoreInit = val; }
|
||||
inline G4String GetPrefixString() const { return prefix; }
|
||||
inline G4String GetFullPrefixString() const
|
||||
{
|
||||
std::stringstream os;
|
||||
os << prefix << id;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
inline G4String GetPrefixString() const { return prefix; }
|
||||
inline G4String GetFullPrefixString() const
|
||||
{
|
||||
std::stringstream os;
|
||||
os<<prefix<<id;
|
||||
return os.str();
|
||||
}
|
||||
protected:
|
||||
void AddMasterOutput(G4bool formatAlsoMaster);
|
||||
void HandleFileCout(G4String fileN, G4bool appendFlag,
|
||||
G4bool suppressDefault);
|
||||
void HandleFileCerr(G4String fileN, G4bool appendFlag,
|
||||
G4bool suppressDefault);
|
||||
|
||||
protected:
|
||||
private:
|
||||
void DumpBuffer();
|
||||
|
||||
void AddMasterOutput( G4bool formatAlsoMaster);
|
||||
void HandleFileCout( G4String fileN, G4bool appendFlag,
|
||||
G4bool suppressDefault);
|
||||
void HandleFileCerr( G4String fileN, G4bool appendFlag,
|
||||
G4bool suppressDefault);
|
||||
private:
|
||||
private:
|
||||
// Reference to the default destination
|
||||
G4coutDestination* ref_defaultOut = nullptr;
|
||||
|
||||
void DumpBuffer();
|
||||
|
||||
private:
|
||||
// Reference to the master destination
|
||||
G4coutDestination* ref_masterOut = nullptr;
|
||||
G4bool masterDestinationFlag = true;
|
||||
G4bool masterDestinationFmtFlag = true;
|
||||
|
||||
// Reference to the default destination
|
||||
G4coutDestination* ref_defaultOut;
|
||||
const G4int id;
|
||||
G4bool useBuffer = false;
|
||||
G4bool ignoreCout = false;
|
||||
G4bool ignoreInit = true;
|
||||
|
||||
// Reference to the master destination
|
||||
G4coutDestination* ref_masterOut;
|
||||
G4bool masterDestinationFlag;
|
||||
G4bool masterDestinationFmtFlag;
|
||||
|
||||
const G4int id;
|
||||
G4bool useBuffer;
|
||||
G4bool ignoreCout;
|
||||
G4bool ignoreInit;
|
||||
|
||||
G4String prefix;
|
||||
G4StateManager* stateMgr;
|
||||
G4String prefix = "G4WT";
|
||||
G4StateManager* stateMgr = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,11 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// G4MasterForwardcoutDestination
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
@@ -40,20 +36,19 @@
|
||||
//
|
||||
// Author: A.Dotti (SLAC), April 2017
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4MASTERFORWARDCOUTDESTINATION_HH_
|
||||
#define G4MASTERFORWARDCOUTDESTINATION_HH_
|
||||
#ifndef G4MASTERFORWARDCOUTDESTINATION_HH
|
||||
#define G4MASTERFORWARDCOUTDESTINATION_HH
|
||||
|
||||
#include <G4coutDestination.hh>
|
||||
|
||||
class G4MasterForwardcoutDestination : public G4coutDestination
|
||||
{
|
||||
public:
|
||||
public:
|
||||
G4MasterForwardcoutDestination() = default;
|
||||
|
||||
G4MasterForwardcoutDestination() = default;
|
||||
|
||||
virtual ~G4MasterForwardcoutDestination();
|
||||
virtual G4int ReceiveG4cout(const G4String& msg) override;
|
||||
virtual G4int ReceiveG4cerr(const G4String& msg) override;
|
||||
virtual ~G4MasterForwardcoutDestination();
|
||||
virtual G4int ReceiveG4cout(const G4String& msg) override;
|
||||
virtual G4int ReceiveG4cerr(const G4String& msg) override;
|
||||
};
|
||||
|
||||
#endif /* G4MASTERFORWARDCOUTDESTINATION_HH_ */
|
||||
#endif
|
||||
|
||||
@@ -22,13 +22,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4MulticoutDestination.hh
|
||||
// G4MulticoutDestination
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
@@ -52,44 +46,44 @@
|
||||
//
|
||||
// Author: A.Dotti (SLAC), April 2017
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4MULTICOUTDESTINATION_HH_
|
||||
#define G4MULTICOUTDESTINATION_HH_
|
||||
#ifndef G4MULTICOUTDESTINATION_HH
|
||||
#define G4MULTICOUTDESTINATION_HH
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "G4coutDestination.hh"
|
||||
|
||||
using G4coutDestinationUPtr = std::unique_ptr<G4coutDestination>;
|
||||
using G4coutDestinationUPtr = std::unique_ptr<G4coutDestination>;
|
||||
using G4coutDestinationVector = std::vector<G4coutDestinationUPtr>;
|
||||
|
||||
class G4MulticoutDestination : public G4coutDestination,
|
||||
public G4coutDestinationVector
|
||||
class G4MulticoutDestination
|
||||
: public G4coutDestination
|
||||
, public G4coutDestinationVector
|
||||
{
|
||||
public:
|
||||
public:
|
||||
G4MulticoutDestination() = default;
|
||||
virtual ~G4MulticoutDestination() {}
|
||||
|
||||
G4MulticoutDestination() = default;
|
||||
virtual ~G4MulticoutDestination() {}
|
||||
// Forward call to contained destination. Note that the message may have
|
||||
// been modified by formatters attached to this
|
||||
virtual G4int ReceiveG4cout(const G4String& msg) override
|
||||
{
|
||||
G4bool result = true;
|
||||
std::for_each(begin(), end(), [&](G4coutDestinationUPtr& e) {
|
||||
result &= (e->ReceiveG4cout_(msg) == 0);
|
||||
});
|
||||
return (result ? 0 : -1);
|
||||
}
|
||||
|
||||
// Forward call to contained destination. Note that the message may have
|
||||
// been modified by formatters attached to this
|
||||
virtual G4int ReceiveG4cout(const G4String& msg) override
|
||||
{
|
||||
G4bool result = true;
|
||||
std::for_each( begin(), end(),
|
||||
[&](G4coutDestinationUPtr& e) { result &= (e->ReceiveG4cout_(msg)==0); }
|
||||
);
|
||||
return ( result ? 0 : -1);
|
||||
}
|
||||
|
||||
virtual G4int ReceiveG4cerr(const G4String& msg) override
|
||||
{
|
||||
G4bool result = true;
|
||||
std::for_each( begin(), end(),
|
||||
[&](G4coutDestinationUPtr& e) { result &= (e->ReceiveG4cerr_(msg)==0); }
|
||||
);
|
||||
return ( result ? 0 : -1);
|
||||
}
|
||||
virtual G4int ReceiveG4cerr(const G4String& msg) override
|
||||
{
|
||||
G4bool result = true;
|
||||
std::for_each(begin(), end(), [&](G4coutDestinationUPtr& e) {
|
||||
result &= (e->ReceiveG4cerr_(msg) == 0);
|
||||
});
|
||||
return (result ? 0 : -1);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* G4MULTICOUTDESTINATION_HH_ */
|
||||
#endif
|
||||
|
||||
@@ -23,86 +23,46 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4OrderedTable
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// ------------------------------------------------------------
|
||||
// Sep. 1996 : M.Maire
|
||||
// Jan. 2001 : H.Kurashige
|
||||
// - G4ValVector is replaced with G4DataVector
|
||||
// - Migrated to std::vector<G4DataVector*>.
|
||||
// Sep. 2001 : H.Kurashige
|
||||
// - Add
|
||||
// G4bool Store(const G4String&, G4bool)
|
||||
// G4bool Retrieve(const G4String&, G4bool);
|
||||
// ostream& operator<<(ostream&, G4OrderedTable&)
|
||||
//
|
||||
// Class Description:
|
||||
//
|
||||
// Utility class, defining an ordered collection of vectors
|
||||
// of <G4double>.
|
||||
// Utility class, defining an ordered collection of vectors of <G4double>.
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// Author: M.Maire (LAPP), September 1996
|
||||
// Revisions: H.Kurashige (Kobe Univ.), January-September 2001
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4OrderedTable_hh
|
||||
#define G4OrderedTable_hh 1
|
||||
|
||||
#ifndef G4OrderedTable_h
|
||||
#define G4OrderedTable_h 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include <vector>
|
||||
class G4DataVector;
|
||||
|
||||
class G4OrderedTable : public std::vector<G4DataVector*>
|
||||
{
|
||||
|
||||
public: // with description
|
||||
|
||||
G4OrderedTable();
|
||||
// Deafult constructor.
|
||||
|
||||
explicit G4OrderedTable(size_t cap);
|
||||
// Constructor given a 'capacity' defining the initial
|
||||
// number of elements (NULL pointers are filled up)
|
||||
|
||||
virtual ~G4OrderedTable();
|
||||
// Empty Destructor
|
||||
|
||||
inline void clearAndDestroy();
|
||||
// Removes all elements and deletes all non-NULL pointers
|
||||
|
||||
G4bool Store(const G4String& filename, G4bool ascii=false);
|
||||
// Stores OrderedTable in a file (returns false in case of failure).
|
||||
|
||||
G4bool Retrieve(const G4String& filename, G4bool ascii=false);
|
||||
// Retrieves OrderedTable from a file (returns false in case of failure).
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& out, G4OrderedTable& table);
|
||||
|
||||
};
|
||||
|
||||
typedef G4OrderedTable::iterator G4OrderedTableIterator;
|
||||
|
||||
#include "G4DataVector.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
inline
|
||||
void G4OrderedTable::clearAndDestroy()
|
||||
class G4OrderedTable : public std::vector<G4DataVector*>
|
||||
{
|
||||
G4DataVector* a = 0;
|
||||
while (size()>0)
|
||||
{
|
||||
a = back();
|
||||
pop_back();
|
||||
for (iterator i=begin(); i!=end(); i++)
|
||||
{
|
||||
if (*i==a)
|
||||
{
|
||||
erase(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
if ( a ) { delete a; }
|
||||
}
|
||||
}
|
||||
public:
|
||||
G4OrderedTable();
|
||||
// Default constructor
|
||||
|
||||
explicit G4OrderedTable(std::size_t cap);
|
||||
// Constructor given a 'capacity' defining the initial
|
||||
// number of elements (NULL pointers are filled up)
|
||||
|
||||
virtual ~G4OrderedTable();
|
||||
// Empty Destructor
|
||||
|
||||
void clearAndDestroy();
|
||||
// Removes all elements and deletes all non-NULL pointers
|
||||
|
||||
G4bool Store(const G4String& filename, G4bool ascii = false);
|
||||
// Stores OrderedTable in a file (returns false in case of failure)
|
||||
|
||||
G4bool Retrieve(const G4String& filename, G4bool ascii = false);
|
||||
// Retrieves OrderedTable from a file (returns false in case of failure)
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& out, G4OrderedTable& table);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,39 +23,49 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4PhysicalConstants
|
||||
//
|
||||
// Import CLHEP constants on global namespace.
|
||||
// Restricted to internal use -only- in source code
|
||||
|
||||
// Author: G.Cosmo, CERN
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4PhysicalConstants_hh
|
||||
#define G4PhysicalConstants_hh 1
|
||||
|
||||
#include <CLHEP/Units/PhysicalConstants.h>
|
||||
|
||||
using CLHEP::pi;
|
||||
using CLHEP::twopi;
|
||||
using CLHEP::halfpi;
|
||||
using CLHEP::pi2;
|
||||
using CLHEP::alpha_rcl2;
|
||||
using CLHEP::amu;
|
||||
using CLHEP::amu_c2;
|
||||
using CLHEP::Avogadro;
|
||||
using CLHEP::Bohr_radius;
|
||||
using CLHEP::c_light;
|
||||
using CLHEP::c_squared;
|
||||
using CLHEP::classic_electr_radius;
|
||||
using CLHEP::e_squared;
|
||||
using CLHEP::electron_charge;
|
||||
using CLHEP::electron_Compton_length;
|
||||
using CLHEP::electron_mass_c2;
|
||||
using CLHEP::elm_coupling;
|
||||
using CLHEP::epsilon0;
|
||||
using CLHEP::fine_structure_const;
|
||||
using CLHEP::h_Planck;
|
||||
using CLHEP::halfpi;
|
||||
using CLHEP::hbar_Planck;
|
||||
using CLHEP::hbarc;
|
||||
using CLHEP::hbarc_squared;
|
||||
using CLHEP::electron_charge;
|
||||
using CLHEP::e_squared;
|
||||
using CLHEP::electron_mass_c2;
|
||||
using CLHEP::proton_mass_c2;
|
||||
using CLHEP::neutron_mass_c2;
|
||||
using CLHEP::amu_c2;
|
||||
using CLHEP::amu;
|
||||
using CLHEP::mu0;
|
||||
using CLHEP::epsilon0;
|
||||
using CLHEP::elm_coupling;
|
||||
using CLHEP::fine_structure_const;
|
||||
using CLHEP::classic_electr_radius;
|
||||
using CLHEP::electron_Compton_length;
|
||||
using CLHEP::Bohr_radius;
|
||||
using CLHEP::alpha_rcl2;
|
||||
using CLHEP::twopi_mc2_rcl2;
|
||||
using CLHEP::k_Boltzmann;
|
||||
using CLHEP::STP_Temperature;
|
||||
using CLHEP::STP_Pressure;
|
||||
using CLHEP::kGasThreshold;
|
||||
using CLHEP::mu0;
|
||||
using CLHEP::neutron_mass_c2;
|
||||
using CLHEP::pi;
|
||||
using CLHEP::pi2;
|
||||
using CLHEP::proton_mass_c2;
|
||||
using CLHEP::STP_Pressure;
|
||||
using CLHEP::STP_Temperature;
|
||||
using CLHEP::twopi;
|
||||
using CLHEP::twopi_mc2_rcl2;
|
||||
using CLHEP::universe_mean_density;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,154 +23,137 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4Physics2DVector
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4Physics2DVector.hh
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// A 2-dimentional vector with linear interpolation.
|
||||
// A 2-dimentional vector with linear interpolation.
|
||||
|
||||
// Author: Vladimir Ivanchenko
|
||||
//
|
||||
// Creation date: 25.09.2011
|
||||
//
|
||||
// Modified:
|
||||
// 16.05.2013 V.Ivanchenko removed cache; changed signature of
|
||||
// several methods; all run time methods become const;
|
||||
// the class become read only in run time
|
||||
//---------------------------------------------------------------
|
||||
// Author: Vladimir Ivanchenko, 25.09.2011
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4Physics2DVector_hh
|
||||
#define G4Physics2DVector_hh 1
|
||||
|
||||
#ifndef G4Physics2DVector_h
|
||||
#define G4Physics2DVector_h 1
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4ios.hh"
|
||||
#include "G4PhysicsVectorType.hh"
|
||||
#include "G4ios.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
typedef std::vector<G4double> G4PV2DDataVector;
|
||||
using G4PV2DDataVector = std::vector<G4double>;
|
||||
|
||||
class G4Physics2DVector
|
||||
class G4Physics2DVector
|
||||
{
|
||||
public: // with description
|
||||
|
||||
public:
|
||||
G4Physics2DVector();
|
||||
// Vector will be filled via Retrieve method
|
||||
|
||||
explicit G4Physics2DVector(size_t nx, size_t ny);
|
||||
explicit G4Physics2DVector(std::size_t nx, std::size_t ny);
|
||||
// Vector will be filled via Put methods
|
||||
|
||||
G4Physics2DVector(const G4Physics2DVector&);
|
||||
G4Physics2DVector& operator=(const G4Physics2DVector&);
|
||||
// Copy constructor and assignment operator.
|
||||
// Copy constructor and assignment operator
|
||||
|
||||
G4bool operator==(const G4Physics2DVector& right) const = delete;
|
||||
G4bool operator!=(const G4Physics2DVector& right) const = delete;
|
||||
|
||||
~G4Physics2DVector();
|
||||
// destructor
|
||||
|
||||
G4double Value(G4double x, G4double y,
|
||||
size_t& lastidx, size_t& lastidy) const;
|
||||
// Destructor
|
||||
|
||||
G4double Value(G4double x, G4double y, std::size_t& lastidx,
|
||||
std::size_t& lastidy) const;
|
||||
G4double Value(G4double x, G4double y) const;
|
||||
// Main method to interpolate 2D vector
|
||||
// Consumer class should provide initial values
|
||||
// lastidx and lastidy,
|
||||
// Consumer class should provide initial values of lastidx and lastidy
|
||||
|
||||
inline void PutX(size_t idx, G4double value);
|
||||
inline void PutY(size_t idy, G4double value);
|
||||
inline void PutValue(size_t idx, size_t idy, G4double value);
|
||||
inline void PutX(std::size_t idx, G4double value);
|
||||
inline void PutY(std::size_t idy, G4double value);
|
||||
inline void PutValue(std::size_t idx, std::size_t idy, G4double value);
|
||||
void PutVectors(const std::vector<G4double>& vecX,
|
||||
const std::vector<G4double>& vecY);
|
||||
// Methods to fill vector
|
||||
// Take note that the 'index' starts from '0'.
|
||||
const std::vector<G4double>& vecY);
|
||||
// Methods to fill vector
|
||||
// Take note that the 'index' starts from '0'
|
||||
|
||||
void ScaleVector(G4double factor);
|
||||
// Scale all values of the vector by factor,
|
||||
// This method may be applied
|
||||
// for example after Retrieve a vector from an external file to
|
||||
// convert values into Geant4 units
|
||||
// Scale all values of the vector by factor.
|
||||
// This method may be applied for example after Retrieve a vector
|
||||
// from an external file to convert values into Geant4 units
|
||||
|
||||
G4double
|
||||
FindLinearX(G4double rand, G4double y, size_t& lastidy) const;
|
||||
G4double FindLinearX(G4double rand, G4double y, std::size_t& lastidy) const;
|
||||
inline G4double FindLinearX(G4double rand, G4double y) const;
|
||||
// Find Y using linear interpolation for Y-vector
|
||||
// filled by cumulative probability function
|
||||
// value of rand should be between 0 and 1
|
||||
// Find Y using linear interpolation for Y-vector filled by cumulative
|
||||
// probability function value of rand should be between 0 and 1
|
||||
|
||||
inline G4double GetX(size_t index) const;
|
||||
inline G4double GetY(size_t index) const;
|
||||
inline G4double GetValue(size_t idx, size_t idy) const;
|
||||
inline G4double GetX(std::size_t index) const;
|
||||
inline G4double GetY(std::size_t index) const;
|
||||
inline G4double GetValue(std::size_t idx, std::size_t idy) const;
|
||||
// Returns simply the values of the vector by index
|
||||
// of the energy vector. The boundary check will not be done.
|
||||
// of the energy vector. The boundary check will not be done
|
||||
|
||||
inline size_t FindBinLocationX(G4double x, size_t lastidx) const;
|
||||
inline size_t FindBinLocationY(G4double y, size_t lastidy) const;
|
||||
// Find the bin# in which theEnergy belongs
|
||||
// Starting from 0
|
||||
inline std::size_t FindBinLocationX(const G4double x,
|
||||
const std::size_t lastidx) const;
|
||||
inline std::size_t FindBinLocationY(const G4double y,
|
||||
const std::size_t lastidy) const;
|
||||
// Find the bin# in which theEnergy belongs. Starting from 0
|
||||
|
||||
inline size_t GetLengthX() const;
|
||||
inline size_t GetLengthY() const;
|
||||
// Get the lengths of the vector.
|
||||
inline std::size_t GetLengthX() const;
|
||||
inline std::size_t GetLengthY() const;
|
||||
// Get the lengths of the vector
|
||||
|
||||
inline G4PhysicsVectorType GetType() const;
|
||||
// Get physics vector type
|
||||
|
||||
inline void SetBicubicInterpolation(G4bool);
|
||||
// Activate/deactivate bicubic interpolation.
|
||||
// Activate/deactivate bicubic interpolation
|
||||
|
||||
void Store(std::ofstream& fOut) const;
|
||||
G4bool Retrieve(std::ifstream& fIn);
|
||||
// To store/retrieve persistent data to/from file streams.
|
||||
// To store/retrieve persistent data to/from file streams
|
||||
|
||||
inline void SetVerboseLevel(G4int value);
|
||||
|
||||
protected:
|
||||
|
||||
protected:
|
||||
void PrepareVectors();
|
||||
|
||||
void ClearVectors();
|
||||
|
||||
void CopyData(const G4Physics2DVector& vec);
|
||||
|
||||
G4double BicubicInterpolation(G4double x, G4double y,
|
||||
size_t idx, size_t idy) const;
|
||||
// Bicubic interpolation of 2D vector
|
||||
G4double BicubicInterpolation(const G4double x, const G4double y,
|
||||
const std::size_t idx,
|
||||
const std::size_t idy) const;
|
||||
// Bicubic interpolation of 2D vector
|
||||
|
||||
size_t FindBinLocation(G4double z, const G4PV2DDataVector&) const;
|
||||
// Main method to local bin
|
||||
|
||||
inline size_t FindBin(G4double z, const G4PV2DDataVector&,
|
||||
size_t idz, size_t idzmax) const;
|
||||
|
||||
private:
|
||||
inline std::size_t FindBin(const G4double z, const G4PV2DDataVector&,
|
||||
const std::size_t idz,
|
||||
const std::size_t idzmax) const;
|
||||
|
||||
private:
|
||||
G4double InterpolateLinearX(G4PV2DDataVector& v, G4double rand) const;
|
||||
|
||||
inline G4double DerivativeX(size_t idx, size_t idy, G4double fac) const;
|
||||
inline G4double DerivativeY(size_t idx, size_t idy, G4double fac) const;
|
||||
inline G4double DerivativeXY(size_t idx, size_t idy, G4double fac) const;
|
||||
inline G4double DerivativeX(std::size_t idx, std::size_t idy,
|
||||
G4double fac) const;
|
||||
inline G4double DerivativeY(std::size_t idx, std::size_t idy,
|
||||
G4double fac) const;
|
||||
inline G4double DerivativeXY(std::size_t idx, std::size_t idy,
|
||||
G4double fac) const;
|
||||
// computation of derivatives
|
||||
|
||||
G4bool operator==(const G4Physics2DVector &right) const = delete;
|
||||
G4bool operator!=(const G4Physics2DVector &right) const = delete;
|
||||
G4PhysicsVectorType type = T_G4PhysicsFreeVector;
|
||||
// The type of PhysicsVector (enumerator)
|
||||
|
||||
G4PhysicsVectorType type; // The type of PhysicsVector (enumerator)
|
||||
std::size_t numberOfXNodes = 0;
|
||||
std::size_t numberOfYNodes = 0;
|
||||
|
||||
size_t numberOfXNodes;
|
||||
size_t numberOfYNodes;
|
||||
|
||||
G4PV2DDataVector xVector;
|
||||
G4PV2DDataVector yVector;
|
||||
G4PV2DDataVector xVector;
|
||||
G4PV2DDataVector yVector;
|
||||
std::vector<G4PV2DDataVector*> value;
|
||||
|
||||
G4int verboseLevel;
|
||||
G4bool useBicubic;
|
||||
G4int verboseLevel = 0;
|
||||
G4bool useBicubic = false;
|
||||
};
|
||||
|
||||
#include "G4Physics2DVector.icc"
|
||||
|
||||
@@ -23,147 +23,169 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4Physics2DVector inline implementation
|
||||
//
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class inline source file
|
||||
//
|
||||
// G4Physics2DVector.icc
|
||||
// Author: Vladimir Ivanchenko, 25.09.2011
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
inline
|
||||
G4double G4Physics2DVector::Value(G4double x, G4double y) const
|
||||
inline G4double G4Physics2DVector::Value(G4double x, G4double y) const
|
||||
{
|
||||
size_t idx = 0;
|
||||
size_t idy = 0;
|
||||
std::size_t idx = 0;
|
||||
std::size_t idy = 0;
|
||||
return Value(x, y, idx, idy);
|
||||
}
|
||||
|
||||
inline void G4Physics2DVector::PutX(size_t idx, G4double val)
|
||||
inline void G4Physics2DVector::PutX(std::size_t idx, G4double val)
|
||||
{
|
||||
xVector[idx] = val;
|
||||
}
|
||||
|
||||
inline void G4Physics2DVector::PutY(size_t idy, G4double val)
|
||||
inline void G4Physics2DVector::PutY(std::size_t idy, G4double val)
|
||||
{
|
||||
yVector[idy] = val;
|
||||
}
|
||||
|
||||
inline void
|
||||
G4Physics2DVector::PutValue(size_t idx, size_t idy, G4double val)
|
||||
inline void G4Physics2DVector::PutValue(std::size_t idx, std::size_t idy,
|
||||
G4double val)
|
||||
{
|
||||
(*(value[idy]))[idx] = val;
|
||||
}
|
||||
|
||||
inline G4double G4Physics2DVector::GetX(size_t index) const
|
||||
inline G4double G4Physics2DVector::GetX(std::size_t index) const
|
||||
{
|
||||
return xVector[index];
|
||||
}
|
||||
|
||||
inline G4double G4Physics2DVector::GetY(size_t index) const
|
||||
inline G4double G4Physics2DVector::GetY(std::size_t index) const
|
||||
{
|
||||
return yVector[index];
|
||||
}
|
||||
|
||||
inline
|
||||
G4double G4Physics2DVector::GetValue(size_t idx, size_t idy) const
|
||||
inline G4double G4Physics2DVector::GetValue(std::size_t idx,
|
||||
std::size_t idy) const
|
||||
{
|
||||
return (*(value[idy]))[idx];
|
||||
}
|
||||
|
||||
inline
|
||||
G4double G4Physics2DVector::FindLinearX(G4double rand, G4double y) const
|
||||
inline G4double G4Physics2DVector::FindLinearX(G4double rand, G4double y) const
|
||||
{
|
||||
size_t idy = 0;
|
||||
std::size_t idy = 0;
|
||||
return FindLinearX(rand, y, idy);
|
||||
}
|
||||
|
||||
inline size_t G4Physics2DVector::GetLengthX() const
|
||||
inline std::size_t G4Physics2DVector::GetLengthX() const
|
||||
{
|
||||
return numberOfXNodes;
|
||||
}
|
||||
|
||||
inline size_t G4Physics2DVector::GetLengthY() const
|
||||
inline std::size_t G4Physics2DVector::GetLengthY() const
|
||||
{
|
||||
return numberOfYNodes;
|
||||
}
|
||||
|
||||
inline G4PhysicsVectorType G4Physics2DVector::GetType() const
|
||||
{
|
||||
return type;
|
||||
}
|
||||
inline G4PhysicsVectorType G4Physics2DVector::GetType() const { return type; }
|
||||
|
||||
inline void G4Physics2DVector::SetBicubicInterpolation(G4bool val)
|
||||
{
|
||||
useBicubic = val;
|
||||
}
|
||||
|
||||
inline size_t G4Physics2DVector::FindBin(G4double z,
|
||||
const G4PV2DDataVector& v,
|
||||
size_t idx,
|
||||
size_t idxmax) const
|
||||
inline std::size_t G4Physics2DVector::FindBin(const G4double z,
|
||||
const G4PV2DDataVector& v,
|
||||
const std::size_t idx,
|
||||
const std::size_t idxmax) const
|
||||
{
|
||||
size_t id = idx;
|
||||
if(z < v[1]) {
|
||||
id = 0;
|
||||
} else if(z >= v[idxmax-2]) {
|
||||
id = idxmax - 2;
|
||||
} else if(idx > idxmax-2 || z < v[idx] || z >= v[idx+1]) {
|
||||
id = FindBinLocation(z, v);
|
||||
std::size_t id = idx;
|
||||
if(z <= v[1])
|
||||
{
|
||||
id = 0;
|
||||
}
|
||||
else if(z >= v[idxmax])
|
||||
{
|
||||
id = idxmax;
|
||||
}
|
||||
else if(idx > idxmax || z < v[idx] || z > v[idx + 1])
|
||||
{
|
||||
id = std::lower_bound(v.begin(), v.end(), z) - v.begin() - 1;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
inline size_t
|
||||
G4Physics2DVector::FindBinLocationX(G4double x, size_t lastidx) const
|
||||
inline std::size_t G4Physics2DVector::FindBinLocationX(
|
||||
const G4double x, const std::size_t idx) const
|
||||
{
|
||||
return FindBin(x, xVector, lastidx, numberOfXNodes);
|
||||
return FindBin(x, xVector, idx, numberOfXNodes - 2);
|
||||
}
|
||||
|
||||
inline size_t
|
||||
G4Physics2DVector::FindBinLocationY(G4double y, size_t lastidy) const
|
||||
inline std::size_t G4Physics2DVector::FindBinLocationY(
|
||||
const G4double y, const std::size_t idy) const
|
||||
{
|
||||
return FindBin(y, yVector, lastidy, numberOfYNodes);
|
||||
return FindBin(y, yVector, idy, numberOfYNodes - 2);
|
||||
}
|
||||
|
||||
inline void G4Physics2DVector::SetVerboseLevel(G4int val)
|
||||
{
|
||||
verboseLevel = val;
|
||||
verboseLevel = val;
|
||||
}
|
||||
|
||||
inline G4double
|
||||
G4Physics2DVector::DerivativeX(size_t idx, size_t idy, G4double fac) const
|
||||
inline G4double G4Physics2DVector::DerivativeX(std::size_t idx, std::size_t idy,
|
||||
G4double fac) const
|
||||
{
|
||||
size_t i1 = idx;
|
||||
if(i1 > 0) { --i1; }
|
||||
size_t i2 = idx;
|
||||
if(i2+1 < numberOfXNodes) { ++i2; }
|
||||
return fac*(GetValue(i2, idy) - GetValue(i1, idy))/(GetX(i2) - GetX(i1));
|
||||
std::size_t i1 = idx;
|
||||
if(i1 > 0)
|
||||
{
|
||||
--i1;
|
||||
}
|
||||
std::size_t i2 = idx;
|
||||
if(i2 + 1 < numberOfXNodes)
|
||||
{
|
||||
++i2;
|
||||
}
|
||||
return fac * (GetValue(i2, idy) - GetValue(i1, idy)) / (GetX(i2) - GetX(i1));
|
||||
}
|
||||
|
||||
inline G4double
|
||||
G4Physics2DVector::DerivativeY(size_t idx, size_t idy, G4double fac) const
|
||||
inline G4double G4Physics2DVector::DerivativeY(std::size_t idx, std::size_t idy,
|
||||
G4double fac) const
|
||||
{
|
||||
size_t i1 = idy;
|
||||
if(i1 > 0) { --i1; }
|
||||
size_t i2 = idy;
|
||||
if(i2+1 < numberOfYNodes) { ++i2; }
|
||||
return fac*(GetValue(idx, i2) - GetValue(idx, i1))/(GetY(i2) - GetY(i1));
|
||||
std::size_t i1 = idy;
|
||||
if(i1 > 0)
|
||||
{
|
||||
--i1;
|
||||
}
|
||||
std::size_t i2 = idy;
|
||||
if(i2 + 1 < numberOfYNodes)
|
||||
{
|
||||
++i2;
|
||||
}
|
||||
return fac * (GetValue(idx, i2) - GetValue(idx, i1)) / (GetY(i2) - GetY(i1));
|
||||
}
|
||||
|
||||
inline G4double
|
||||
G4Physics2DVector::DerivativeXY(size_t idx, size_t idy, G4double fac) const
|
||||
inline G4double G4Physics2DVector::DerivativeXY(std::size_t idx,
|
||||
std::size_t idy,
|
||||
G4double fac) const
|
||||
{
|
||||
size_t i1 = idx;
|
||||
if(i1 > 0) { --i1; }
|
||||
size_t i2 = idx;
|
||||
if(i2+1 < numberOfXNodes) { ++i2; }
|
||||
size_t j1 = idy;
|
||||
if(j1 > 0) { --j1; }
|
||||
size_t j2 = idy;
|
||||
if(j2+1 < numberOfYNodes) { ++j2; }
|
||||
return fac*(GetValue(i2, j2) - GetValue(i1, j2) - GetValue(i2, j1)
|
||||
+ GetValue(i1, j1))/((GetX(i2) - GetX(i1))*(GetY(j2) - GetY(j1)));
|
||||
std::size_t i1 = idx;
|
||||
if(i1 > 0)
|
||||
{
|
||||
--i1;
|
||||
}
|
||||
std::size_t i2 = idx;
|
||||
if(i2 + 1 < numberOfXNodes)
|
||||
{
|
||||
++i2;
|
||||
}
|
||||
std::size_t j1 = idy;
|
||||
if(j1 > 0)
|
||||
{
|
||||
--j1;
|
||||
}
|
||||
std::size_t j2 = idy;
|
||||
if(j2 + 1 < numberOfYNodes)
|
||||
{
|
||||
++j2;
|
||||
}
|
||||
return fac *
|
||||
(GetValue(i2, j2) - GetValue(i1, j2) - GetValue(i2, j1) +
|
||||
GetValue(i1, j1)) /
|
||||
((GetX(i2) - GetX(i1)) * (GetY(j2) - GetY(j1)));
|
||||
}
|
||||
|
||||
@@ -23,73 +23,74 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4PhysicsFreeVector
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4PhysicsFreeVector.hh
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// A physics vector which has values of energy-loss, cross-section,
|
||||
// and other physics values of a particle in matter in a given
|
||||
// range of the energy, momentum, etc. The scale of energy/momentum
|
||||
// bins is in free, ie. it is NOT need to be linear or log. Only
|
||||
// restrication is that bin values alway have to increase from
|
||||
// a lower bin to a higher bin. This is necessary for the binary
|
||||
// search to work correctly.
|
||||
// A physics vector which has values of energy-loss, cross-section,
|
||||
// and other physics values of a particle in matter in a given
|
||||
// range of the energy, momentum, etc. The scale of energy/momentum
|
||||
// bins is in free, i.e. it is NOT need to be linear or log. Only
|
||||
// restriction is that bin values alway have to increase from
|
||||
// a lower bin to a higher bin. This is necessary for the binary
|
||||
// search to work correctly.
|
||||
|
||||
// History:
|
||||
// 02 Dec. 1995, G.Cosmo : Structure created based on object model
|
||||
// 06 Jun. 1996, K.Amako : Implemented the 1st version
|
||||
// 01 Jul. 1996, K.Amako : Cache mechanism and hidden bin from the
|
||||
// user introduced
|
||||
// 26 Sep. 1996, K.Amako : Constructor with only 'bin size' added
|
||||
// 11 Nov. 2000, H.Kurashige : Use STL vector for dataVector and binVector
|
||||
// 02 Oct. 2013 V.Ivanchenko : Remove FindBinLocation method
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
// Authors:
|
||||
// - 02 Dec. 1995, G.Cosmo: Structure created based on object model
|
||||
// - 06 Jun. 1996, K.Amako: Implemented the 1st version
|
||||
// Revisions:
|
||||
// - 11 Nov. 2000, H.Kurashige: Use STL vector for dataVector and binVector
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4PhysicsFreeVector_hh
|
||||
#define G4PhysicsFreeVector_hh 1
|
||||
|
||||
#ifndef G4PhysicsFreeVector_h
|
||||
#define G4PhysicsFreeVector_h 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4PhysicsVector.hh"
|
||||
#include "G4DataVector.hh"
|
||||
#include "G4PhysicsVector.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
class G4PhysicsFreeVector : public G4PhysicsVector
|
||||
class G4PhysicsFreeVector : public G4PhysicsVector
|
||||
{
|
||||
public: // with description
|
||||
|
||||
public:
|
||||
G4PhysicsFreeVector();
|
||||
// the vector will be filled from external file using Retrieve method
|
||||
// The vector will be filled from external file using Retrieve() method
|
||||
|
||||
explicit G4PhysicsFreeVector(size_t length);
|
||||
// the vector with 'length' elements will be filled using PutValue method
|
||||
// by default the vector is initialized with zeros
|
||||
explicit G4PhysicsFreeVector(std::size_t length);
|
||||
// The vector with 'length' elements will be filled using PutValue()
|
||||
// method; by default the vector is initialized with zeros
|
||||
|
||||
G4PhysicsFreeVector(const G4DataVector& eVector,
|
||||
const G4DataVector& dataVector);
|
||||
// the vector is filled in this constructor
|
||||
G4PhysicsFreeVector(const G4DataVector& eVector,
|
||||
const G4DataVector& dataVector);
|
||||
// The vector is filled in this constructor.
|
||||
// 'eVector' and 'dataVector' need to have the same vector length
|
||||
// 'eVector' assumed to be ordered
|
||||
|
||||
|
||||
virtual ~G4PhysicsFreeVector();
|
||||
|
||||
inline void PutValue(size_t index, G4double energy, G4double dataValue);
|
||||
// user code is responsible for correct filling of all elements
|
||||
inline void PutValue(std::size_t index, G4double energy, G4double dValue);
|
||||
// User code is responsible for correct filling of all elements
|
||||
};
|
||||
|
||||
inline
|
||||
void G4PhysicsFreeVector::PutValue(size_t index, G4double e, G4double value)
|
||||
// -----------------------------
|
||||
// Inline methods implementation
|
||||
// -----------------------------
|
||||
|
||||
inline void G4PhysicsFreeVector::PutValue(std::size_t index, G4double e,
|
||||
G4double value)
|
||||
{
|
||||
if(index >= numberOfNodes) { PrintPutValueError(index); }
|
||||
binVector[index] = e;
|
||||
if(index >= numberOfNodes)
|
||||
{
|
||||
PrintPutValueError(index);
|
||||
}
|
||||
binVector[index] = e;
|
||||
dataVector[index] = value;
|
||||
if(index == 0) { edgeMin = e; }
|
||||
else if( numberOfNodes - 1 == index) { edgeMax = e; }
|
||||
if(index == 0)
|
||||
{
|
||||
edgeMin = e;
|
||||
}
|
||||
else if(numberOfNodes - 1 == index)
|
||||
{
|
||||
edgeMax = e;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,60 +23,45 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4PhysicsLinearVector
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4PhysicsLinearVector.hh
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// A physics vector which has values of energy-loss, cross-section,
|
||||
// and other physics values of a particle in matter in a given
|
||||
// range of the energy, momentum, etc. The scale of energy/momentum
|
||||
// bins is in linear.
|
||||
// A physics vector which has values of energy-loss, cross-section,
|
||||
// and other physics values of a particle in matter in a given
|
||||
// range of energy, momentum, etc. The scale of energy/momentum
|
||||
// bins is linear.
|
||||
|
||||
// History:
|
||||
// 02 Dec. 1995, G.Cosmo : Structure created based on object model
|
||||
// 03 Mar. 1996, K.Amako : Implemented the 1st version
|
||||
// 01 Jul. 1996, K.Amako : Cache mechanism and hidden bin from the
|
||||
// user introduced
|
||||
// 26 Sep. 1996, K.Amako : Constructor with only 'bin size' added
|
||||
// 11 Nov. 2000, H.Kurashige : Use STL vector for dataVector and binVector
|
||||
// 16 Aug. 2011 H.Kurashige : Move dBin, baseBin to the base class
|
||||
// 02 Oct. 2013 V.Ivanchenko : Remove FindBinLocation method
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
// Authors:
|
||||
// - 02 Dec. 1995, G.Cosmo: Structure created based on object model
|
||||
// - 03 Mar. 1996, K.Amako: Implemented the 1st version
|
||||
// Revisions:
|
||||
// - 11 Nov. 2000, H.Kurashige: Use STL vector for dataVector and binVector
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4PhysicsLinearVector_hh
|
||||
#define G4PhysicsLinearVector_hh 1
|
||||
|
||||
#ifndef G4PhysicsLinearVector_h
|
||||
#define G4PhysicsLinearVector_h 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4PhysicsVector.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
class G4PhysicsLinearVector : public G4PhysicsVector
|
||||
class G4PhysicsLinearVector : public G4PhysicsVector
|
||||
{
|
||||
public:// with description
|
||||
|
||||
public:
|
||||
G4PhysicsLinearVector();
|
||||
// the vector will be filled from external file using Retrieve method
|
||||
// The vector will be filled from external file using Retrieve() method
|
||||
|
||||
G4PhysicsLinearVector(G4double theEmin, G4double theEmax, size_t theNbin);
|
||||
// Energy vector will be computed and filled at construction,
|
||||
// number of elements 'theNbin+1'. Use PutValue() to fill the data vector
|
||||
G4PhysicsLinearVector(G4double Emin, G4double Emax, std::size_t Nbin);
|
||||
// Energy vector will be computed and filled at construction,
|
||||
// number of elements 'Nbin+1'. Use PutValue() to fill the data vector
|
||||
|
||||
virtual ~G4PhysicsLinearVector();
|
||||
|
||||
virtual G4bool Retrieve(std::ifstream& fIn, G4bool ascii) final;
|
||||
// To retrieve persistent data from a file stream.
|
||||
// To retrieve persistent data from a file stream
|
||||
|
||||
virtual void ScaleVector(G4double factorE, G4double factorV) final;
|
||||
// Scale all values of the vector and second derivatives
|
||||
// by factorV, energies - by vectorE.
|
||||
|
||||
// Scale all values of the vector and second derivatives
|
||||
// by factorV, energies - by vectorE
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,34 +23,23 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4PhysicsLnVector
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4PhysicsLnVector.hh
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// A physics vector which has values of energy-loss, cross-section,
|
||||
// and other physics values of a particle in matter in a given
|
||||
// range of the energy, momentum, etc. The scale of energy/momentum
|
||||
// bins is natural logarithmic.
|
||||
//
|
||||
// History:
|
||||
// 27 Apr. 1999, M.G. Pia: Created, copying from G4PhysicsLogVector
|
||||
// 11 Nov. 2000, H.Kurashige : Use STL vector for dataVector and binVector
|
||||
// 16 Aug. 2011 H.Kurashige : Move dBin, baseBin to the base class
|
||||
// 02 Oct. 2013 V.Ivanchenko : Remove FindBinLocation method
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
// A physics vector which has values of energy-loss, cross-section,
|
||||
// and other physics values of a particle in matter in a given
|
||||
// range of energy, momentum, etc. The scale of energy/momentum
|
||||
// bins is natural logarithmic.
|
||||
|
||||
#ifndef G4PhysicsLnVector_h
|
||||
#define G4PhysicsLnVector_h 1
|
||||
// Author:
|
||||
// - 27 April 1999, M.G. Pia: Created, copying from G4PhysicsLogVector
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4PhysicsLnVector_hh
|
||||
#define G4PhysicsLnVector_hh 1
|
||||
|
||||
#include "G4PhysicsLogVector.hh"
|
||||
|
||||
typedef G4PhysicsLogVector G4PhysicsLnVector;
|
||||
using G4PhysicsLnVector = G4PhysicsLogVector;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,62 +23,47 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4PhysicsLogVector
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4PhysicsLogVector.hh
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// A physics vector which has values of energy-loss, cross-section,
|
||||
// and other physics values of a particle in matter in a given
|
||||
// range of the energy, momentum, etc. The scale of energy/momentum
|
||||
// bins is in logarithmic.
|
||||
// A physics vector which has values of energy-loss, cross-section,
|
||||
// and other physics values of a particle in matter in a given
|
||||
// range of energy, momentum, etc. The scale of energy/momentum
|
||||
// bins is logarithmic.
|
||||
|
||||
// History:
|
||||
// 02 Dec. 1995, G.Cosmo : Structure created based on object model
|
||||
// 03 Mar. 1996, K.Amako : Implemented the 1st version
|
||||
// 27 Apr. 1996, K.Amako : Cache mechanism added
|
||||
// 01 Jul. 1996, K.Amako : Hidden bin from the user introduced
|
||||
// 26 Sep. 1996, K.Amako : Constructor with only 'bin size' added
|
||||
// 11 Nov. 2000, H.Kurashige : Use STL vector for dataVector and binVector
|
||||
// 16 Aug. 2011 H.Kurashige : Move dBin, baseBin to the base class
|
||||
// 02 Oct. 2013 V.Ivanchenko : Remove FindBinLocation method
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
// Authors:
|
||||
// - 02 Dec. 1995, G.Cosmo: Structure created based on object model
|
||||
// - 03 Mar. 1996, K.Amako: Implemented the 1st version
|
||||
// Revisions:
|
||||
// - 11 Nov. 2000, H.Kurashige : Use STL vector for dataVector and binVector
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4PhysicsLogVector_hh
|
||||
#define G4PhysicsLogVector_hh 1
|
||||
|
||||
#ifndef G4PhysicsLogVector_h
|
||||
#define G4PhysicsLogVector_h 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4PhysicsVector.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
class G4PhysicsLogVector : public G4PhysicsVector
|
||||
class G4PhysicsLogVector : public G4PhysicsVector
|
||||
{
|
||||
public:// with description
|
||||
|
||||
public:
|
||||
G4PhysicsLogVector();
|
||||
// the vector will be filled from external file using Retrieve method
|
||||
// The vector will be filled from external file using Retrieve() method
|
||||
|
||||
G4PhysicsLogVector(G4double theEmin, G4double theEmax, size_t theNbin);
|
||||
// Energy vector will be computed and filled at construction,
|
||||
// number of nodes 'theNbin+1'. Use PutValue() to fill the data vector
|
||||
//
|
||||
// Because of logarithmic scale, 'theEmin' has to be
|
||||
// greater than zero. No protection exists against this error.
|
||||
G4PhysicsLogVector(G4double Emin, G4double Emax, std::size_t Nbin);
|
||||
// Energy vector will be computed and filled at construction,
|
||||
// number of nodes 'Nbin+1'. Use PutValue() to fill the data vector
|
||||
// Because of logarithmic scale, 'Emin' has to be
|
||||
// greater than zero. No protection exists against this error
|
||||
|
||||
virtual ~G4PhysicsLogVector();
|
||||
|
||||
virtual G4bool Retrieve(std::ifstream& fIn, G4bool ascii) final;
|
||||
// To retrieve persistent data from a file stream.
|
||||
// To retrieve persistent data from a file stream
|
||||
|
||||
virtual void ScaleVector(G4double factorE, G4double factorV) final;
|
||||
// Scale all values of the vector and second derivatives
|
||||
// by factorV, energies - by vectorE.
|
||||
|
||||
// Scale all values of the vector and second derivatives
|
||||
// by factorV, energies - by vectorE
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,49 +23,40 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// -----------------------------------------------------------------
|
||||
//
|
||||
// ------------------- class G4PhysicsModelCatalog -----------------
|
||||
// G4PhysicsModelCatalog
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// Singleton, collection of physics models, to be used by models and G4Track.
|
||||
|
||||
#ifndef G4PhysicsModelCatalog_HH
|
||||
#define G4PhysicsModelCatalog_HH
|
||||
// Author: M.Asai (SLAC), 26 September 2013
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4PhysicsModelCatalog_hh
|
||||
#define G4PhysicsModelCatalog_hh
|
||||
|
||||
#include "globals.hh"
|
||||
#include <vector>
|
||||
#include "G4String.hh"
|
||||
|
||||
typedef std::vector<G4String> modelCatalog;
|
||||
#include "G4String.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
class G4PhysicsModelCatalog
|
||||
{
|
||||
private: // with description
|
||||
public:
|
||||
~G4PhysicsModelCatalog();
|
||||
G4PhysicsModelCatalog(const G4PhysicsModelCatalog&) = delete;
|
||||
G4PhysicsModelCatalog& operator=(const G4PhysicsModelCatalog&) = delete;
|
||||
|
||||
G4PhysicsModelCatalog();
|
||||
G4PhysicsModelCatalog(const G4PhysicsModelCatalog&);
|
||||
G4PhysicsModelCatalog& operator=(const G4PhysicsModelCatalog&);
|
||||
static G4int Register(const G4String&);
|
||||
static const G4String& GetModelName(G4int);
|
||||
|
||||
public: // with description
|
||||
|
||||
~G4PhysicsModelCatalog();
|
||||
static G4int Register(const G4String&);
|
||||
static const G4String& GetModelName(G4int);
|
||||
static G4int GetIndex(const G4String&);
|
||||
static G4int Entries();
|
||||
static void Destroy();
|
||||
|
||||
public: // without description
|
||||
|
||||
static G4int GetIndex(const G4String&);
|
||||
static G4int Entries();
|
||||
static void Destroy();
|
||||
|
||||
private:
|
||||
|
||||
static modelCatalog* catalog;
|
||||
private:
|
||||
G4PhysicsModelCatalog();
|
||||
|
||||
static std::vector<G4String>* theCatalog;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,119 +23,82 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// PhysicsOrderedFreeVector Class Definition
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// File: G4PhysicsOrderedFreeVector.hh
|
||||
// Created: 1996-08-13
|
||||
// Author: Juliet Armstrong
|
||||
// Updated: 1997-03-25 by Peter Gumplinger
|
||||
// > cosmetics (only)
|
||||
// 2000-11-11 by H.Kurashige
|
||||
// > use STL vector for dataVector and binVector
|
||||
// mail: gum@triumf.ca
|
||||
// G4PhysicsOrderedFreeVector
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// A physics ordered free vector inherits from G4PhysicsVector which
|
||||
// has values of energy-loss, cross-section, and other physics values
|
||||
// of a particle in matter in a given range of the energy, momentum,
|
||||
// etc.). In addition, the ordered free vector provides a method for
|
||||
// the user to insert energy/value pairs in sequence. Methods to
|
||||
// Retrieve the Max and Min energies and values from the vector are
|
||||
// also provided.
|
||||
// A physics ordered free vector inherits from G4PhysicsVector which
|
||||
// has values of energy-loss, cross-section, and other physics values
|
||||
// of a particle in matter in a given range of energy, momentum, etc.).
|
||||
// In addition, the ordered free vector provides a method for
|
||||
// the user to insert energy/value pairs in sequence. Methods to
|
||||
// retrieve the Max and Min energies and values from the vector are
|
||||
// also provided.
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef G4PhysicsOrderedFreeVector_h
|
||||
#define G4PhysicsOrderedFreeVector_h 1
|
||||
|
||||
/////////////
|
||||
// Includes
|
||||
/////////////
|
||||
// Author: Juliet Armstrong (TRIUMF), 13 August 1996
|
||||
// Revisions:
|
||||
// - 11.11.2000, H.Kurashige: use STL vector for dataVector and binVector
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4PhysicsOrderedFreeVector_hh
|
||||
#define G4PhysicsOrderedFreeVector_hh 1
|
||||
|
||||
#include "G4PhysicsVector.hh"
|
||||
|
||||
/////////////////////
|
||||
// Class Definition
|
||||
/////////////////////
|
||||
|
||||
class G4PhysicsOrderedFreeVector : public G4PhysicsVector
|
||||
class G4PhysicsOrderedFreeVector : public G4PhysicsVector
|
||||
{
|
||||
|
||||
public: // with description
|
||||
|
||||
////////////////////////////////
|
||||
// Constructors and Destructor
|
||||
////////////////////////////////
|
||||
|
||||
public:
|
||||
G4PhysicsOrderedFreeVector();
|
||||
// the vector will be filled from exteran file using Retrieve
|
||||
// or InsertValues methods
|
||||
// The vector will be filled from extern file using Retrieve()
|
||||
// or InsertValues() methods
|
||||
|
||||
G4PhysicsOrderedFreeVector(G4double* Energies,
|
||||
G4double* Values,
|
||||
size_t VectorLength);
|
||||
// the vector is filled in this constructor
|
||||
G4PhysicsOrderedFreeVector(G4double* Energies, G4double* Values,
|
||||
std::size_t VectorLength);
|
||||
// The vector is filled in this constructor.
|
||||
// 'Energies' and 'Values' need to have the same vector length
|
||||
// 'Energies' assumed to be ordered
|
||||
|
||||
virtual ~G4PhysicsOrderedFreeVector();
|
||||
|
||||
////////////
|
||||
// Methods
|
||||
////////////
|
||||
|
||||
void InsertValues(G4double energy, G4double value);
|
||||
|
||||
void InsertValues(G4double energy, G4double value);
|
||||
|
||||
G4double GetEnergy(G4double aValue);
|
||||
|
||||
inline G4double GetMaxValue();
|
||||
|
||||
|
||||
inline G4double GetMinValue();
|
||||
|
||||
|
||||
inline G4double GetMaxLowEdgeEnergy();
|
||||
|
||||
|
||||
inline G4double GetMinLowEdgeEnergy();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
size_t FindValueBinLocation(G4double aValue);
|
||||
|
||||
G4double LinearInterpolationOfEnergy(G4double aValue, size_t theLocBin);
|
||||
std::size_t FindValueBinLocation(G4double aValue);
|
||||
|
||||
G4double LinearInterpolationOfEnergy(G4double aValue, std::size_t locBin);
|
||||
};
|
||||
|
||||
inline
|
||||
G4double G4PhysicsOrderedFreeVector::GetMaxValue()
|
||||
// -----------------------------
|
||||
// Inline methods implementation
|
||||
// -----------------------------
|
||||
|
||||
inline G4double G4PhysicsOrderedFreeVector::GetMaxValue()
|
||||
{
|
||||
return dataVector.back();
|
||||
}
|
||||
|
||||
inline
|
||||
G4double G4PhysicsOrderedFreeVector::GetMinValue()
|
||||
inline G4double G4PhysicsOrderedFreeVector::GetMinValue()
|
||||
{
|
||||
return dataVector.front();
|
||||
}
|
||||
|
||||
inline
|
||||
G4double G4PhysicsOrderedFreeVector::GetMaxLowEdgeEnergy()
|
||||
inline G4double G4PhysicsOrderedFreeVector::GetMaxLowEdgeEnergy()
|
||||
{
|
||||
return binVector.back();
|
||||
}
|
||||
|
||||
inline
|
||||
G4double G4PhysicsOrderedFreeVector::GetMinLowEdgeEnergy()
|
||||
inline G4double G4PhysicsOrderedFreeVector::GetMinLowEdgeEnergy()
|
||||
{
|
||||
return binVector.front();
|
||||
}
|
||||
|
||||
#endif /* G4PhysicsOrderedFreeVector_h */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,11 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// G4PhysicsTable
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
@@ -39,108 +35,90 @@
|
||||
// The constructor given the 'capacity' of the table, pre-allocates
|
||||
// memory for the specified value by invoking the STL's reserve()
|
||||
// function, in order to avoid reallocation during insertions.
|
||||
// G4PhysicsTable has a vector of boolean which are used
|
||||
// as 'recalc-needed' flags when processes calculate physics tables.
|
||||
// ------------------------------------------------------------
|
||||
//
|
||||
// History:
|
||||
// -------
|
||||
// - First implementation, based on object model of
|
||||
// 2nd December 1995. G.Cosmo
|
||||
// - 1st March 1996, modified. K.Amako
|
||||
// - 24th February 2001, migration to STL vectors. H.Kurashige
|
||||
// - 9th March 2001, added Store/RetrievePhysicsTable. H.Kurashige
|
||||
// - 20th August 2004, added FlagArray and related methods H.Kurashige
|
||||
//-------------------------------------
|
||||
// G4PhysicsTable has a vector of Boolean which are used
|
||||
// as 'recalc-needed' flags when processes calculate physics tables.
|
||||
|
||||
#ifndef G4PhysicsTable_h
|
||||
#define G4PhysicsTable_h 1
|
||||
// Author: G.Cosmo, 2 December 1995
|
||||
// First implementation based on object model
|
||||
// Revisions:
|
||||
// - 1st March 1996, K.Amako: modified
|
||||
// - 24th February 2001, H.Kurashige: migration to STL vectors
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4PhysicsTable_hh
|
||||
#define G4PhysicsTable_hh 1
|
||||
|
||||
#include <vector>
|
||||
#include "globals.hh"
|
||||
#include "G4PhysicsVector.hh"
|
||||
#include "G4ios.hh"
|
||||
#include "globals.hh"
|
||||
#include <vector>
|
||||
|
||||
class G4PhysicsVector;
|
||||
|
||||
class G4PhysicsTable : public std::vector<G4PhysicsVector*>
|
||||
class G4PhysicsTable : public std::vector<G4PhysicsVector*>
|
||||
{
|
||||
using G4PhysCollection = std::vector<G4PhysicsVector*>;
|
||||
using G4FlagCollection = std::vector<G4bool>;
|
||||
|
||||
typedef std::vector<G4PhysicsVector*> G4PhysCollection;
|
||||
typedef std::vector<G4bool> G4FlagCollection;
|
||||
|
||||
public: // with description
|
||||
|
||||
public:
|
||||
G4PhysicsTable();
|
||||
// Default constructor.
|
||||
// Default constructor
|
||||
|
||||
explicit G4PhysicsTable(size_t cap);
|
||||
// Constructor with capacity. Reserves memory for the
|
||||
// specified capacity.
|
||||
// Constructor with capacity. Reserves memory for the specified capacity
|
||||
|
||||
virtual ~G4PhysicsTable();
|
||||
// Destructor.
|
||||
// Does not invoke deletion of contained pointed collections.
|
||||
|
||||
G4PhysicsVector*& operator()(size_t);
|
||||
G4PhysicsVector* const& operator()(size_t) const;
|
||||
// Access operators.
|
||||
|
||||
void clearAndDestroy();
|
||||
// Removes all items and deletes them at the same time.
|
||||
|
||||
void push_back( G4PhysicsVector* );
|
||||
void insert (G4PhysicsVector*);
|
||||
// Pushes new element to collection.
|
||||
|
||||
void insertAt (size_t, G4PhysicsVector*);
|
||||
// insert element at the specified position in the collection.
|
||||
|
||||
void resize(size_t, G4PhysicsVector* vec = (G4PhysicsVector*)(0));
|
||||
// resize collection
|
||||
|
||||
size_t entries() const;
|
||||
size_t length() const;
|
||||
// Return collection's size.
|
||||
|
||||
G4bool isEmpty() const;
|
||||
// Flags if collection is empty or not.
|
||||
|
||||
G4bool ExistPhysicsTable(const G4String& fileName) const;
|
||||
// Check if the specified file exists or not
|
||||
|
||||
G4bool StorePhysicsTable(const G4String& filename, G4bool ascii=false);
|
||||
// Stores PhysicsTable in a file (returns false in case of failure).
|
||||
|
||||
G4bool RetrievePhysicsTable(const G4String& filename, G4bool ascii=false);
|
||||
// Retrieves Physics from a file (returns false in case of failure).
|
||||
|
||||
void ResetFlagArray();
|
||||
// Reset the array of flags and all flags are set "true"
|
||||
// This flag is supposed to be used as "recalc-needed" flag
|
||||
// associated with each physics vector
|
||||
|
||||
G4bool GetFlag(size_t i) const;
|
||||
void ClearFlag(size_t i);
|
||||
// Get/Clear the flag for the 'i-th' physics vector
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& out, G4PhysicsTable& table);
|
||||
|
||||
protected:
|
||||
|
||||
G4PhysicsVector* CreatePhysicsVector(G4int type);
|
||||
G4FlagCollection vecFlag;
|
||||
|
||||
private:
|
||||
// Destructor. Does not invoke deletion of contained pointed collections
|
||||
|
||||
G4PhysicsTable(const G4PhysicsTable&) = delete;
|
||||
G4PhysicsTable& operator=(const G4PhysicsTable&) = delete;
|
||||
// Private copy constructor and assignment operator.
|
||||
|
||||
G4PhysicsVector*& operator()(std::size_t);
|
||||
G4PhysicsVector* const& operator()(std::size_t) const;
|
||||
// Access operators
|
||||
|
||||
void clearAndDestroy();
|
||||
// Removes all items and deletes them at the same time
|
||||
|
||||
void push_back(G4PhysicsVector*);
|
||||
void insert(G4PhysicsVector*);
|
||||
// Pushes new element to collection
|
||||
|
||||
void insertAt(std::size_t, G4PhysicsVector*);
|
||||
// Insert element at the specified position in the collection
|
||||
|
||||
void resize(std::size_t, G4PhysicsVector* vec = (G4PhysicsVector*) (0));
|
||||
// Resize collection
|
||||
|
||||
std::size_t entries() const;
|
||||
std::size_t length() const;
|
||||
// Return collection's size
|
||||
|
||||
G4bool isEmpty() const;
|
||||
// Flags if collection is empty or not
|
||||
|
||||
G4bool ExistPhysicsTable(const G4String& fileName) const;
|
||||
// Check if the specified file exists or not
|
||||
|
||||
G4bool StorePhysicsTable(const G4String& filename, G4bool ascii = false);
|
||||
// Stores PhysicsTable in a file (returns false in case of failure)
|
||||
|
||||
G4bool RetrievePhysicsTable(const G4String& filename, G4bool ascii = false);
|
||||
// Retrieves Physics from a file (returns false in case of failure)
|
||||
|
||||
void ResetFlagArray();
|
||||
// Reset the array of flags and all flags are set "true".
|
||||
// This flag is supposed to be used as "recalc-needed" flag
|
||||
// associated with each physics vector
|
||||
|
||||
G4bool GetFlag(std::size_t i) const;
|
||||
void ClearFlag(std::size_t i);
|
||||
// Get/Clear the flag for the 'i-th' physics vector
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& out, G4PhysicsTable& table);
|
||||
|
||||
protected:
|
||||
G4PhysicsVector* CreatePhysicsVector(G4int type);
|
||||
G4FlagCollection vecFlag;
|
||||
};
|
||||
|
||||
typedef G4PhysicsTable::iterator G4PhysicsTableIterator;
|
||||
|
||||
#include "G4PhysicsVector.hh"
|
||||
#include "G4PhysicsTable.icc"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,104 +23,93 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4PhysicsTable inline methods implementation
|
||||
//
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class inline implementation
|
||||
//
|
||||
// History: first implementation, based on object model of
|
||||
// 2nd December 1995, G.Cosmo
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// Author: G.Cosmo, 2 December 1995 - First implementation based on object model
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline
|
||||
void G4PhysicsTable::clearAndDestroy()
|
||||
inline void G4PhysicsTable::clearAndDestroy()
|
||||
{
|
||||
G4PhysicsVector* a=nullptr;
|
||||
while (size()>0)
|
||||
G4PhysicsVector* a = nullptr;
|
||||
while(size() > 0)
|
||||
{
|
||||
a = G4PhysCollection::back();
|
||||
G4PhysCollection::pop_back();
|
||||
if ( a ) { delete a; }
|
||||
}
|
||||
if(a != nullptr)
|
||||
{
|
||||
delete a;
|
||||
}
|
||||
}
|
||||
G4PhysCollection::clear();
|
||||
vecFlag.clear();
|
||||
}
|
||||
|
||||
inline
|
||||
G4PhysicsVector*& G4PhysicsTable::operator()(size_t i)
|
||||
inline G4PhysicsVector*& G4PhysicsTable::operator()(std::size_t i)
|
||||
{
|
||||
return (*this)[i];
|
||||
return (*this)[i];
|
||||
}
|
||||
|
||||
inline
|
||||
G4PhysicsVector* const& G4PhysicsTable::operator()(size_t i) const
|
||||
{
|
||||
return (*this)[i];
|
||||
inline G4PhysicsVector* const& G4PhysicsTable::operator()(std::size_t i) const
|
||||
{
|
||||
return (*this)[i];
|
||||
}
|
||||
|
||||
inline
|
||||
void G4PhysicsTable::push_back(G4PhysicsVector* pvec)
|
||||
inline void G4PhysicsTable::push_back(G4PhysicsVector* pvec)
|
||||
{
|
||||
G4PhysCollection::push_back(pvec);
|
||||
vecFlag.push_back(true);
|
||||
}
|
||||
|
||||
inline
|
||||
void G4PhysicsTable::insert(G4PhysicsVector* pvec)
|
||||
inline void G4PhysicsTable::insert(G4PhysicsVector* pvec)
|
||||
{
|
||||
G4PhysCollection::push_back(pvec);
|
||||
vecFlag.push_back(true);
|
||||
}
|
||||
|
||||
inline
|
||||
void G4PhysicsTable::insertAt (size_t idx, G4PhysicsVector* pvec)
|
||||
inline void G4PhysicsTable::insertAt(std::size_t idx, G4PhysicsVector* pvec)
|
||||
{
|
||||
if(idx > entries())
|
||||
{
|
||||
{
|
||||
G4ExceptionDescription ed;
|
||||
ed << "Sprcified index (" << idx << ") is larger than the size of the vector ("
|
||||
<< entries() << ").";
|
||||
G4Exception("G4PhysicsTable::insertAt()","Global_PhysTbl0001",
|
||||
FatalException,ed);
|
||||
ed << "Sprcified index (" << idx
|
||||
<< ") is larger than the size of the vector (" << entries() << ").";
|
||||
G4Exception("G4PhysicsTable::insertAt()", "Global_PhysTbl0001",
|
||||
FatalException, ed);
|
||||
}
|
||||
|
||||
G4PhysicsTableIterator itr=begin();
|
||||
for (size_t i=0; i<idx; ++i) { itr++; }
|
||||
auto itr = cbegin();
|
||||
for(std::size_t i = 0; i < idx; ++i)
|
||||
{
|
||||
++itr;
|
||||
}
|
||||
G4PhysCollection::insert(itr, pvec);
|
||||
|
||||
G4FlagCollection::iterator itrF=vecFlag.begin();
|
||||
for (size_t j=0; j<idx; ++j) { itrF++; }
|
||||
auto itrF = vecFlag.cbegin();
|
||||
for(std::size_t j = 0; j < idx; ++j)
|
||||
{
|
||||
++itrF;
|
||||
}
|
||||
vecFlag.insert(itrF, true);
|
||||
}
|
||||
|
||||
inline
|
||||
size_t G4PhysicsTable::entries() const
|
||||
inline std::size_t G4PhysicsTable::entries() const
|
||||
{
|
||||
return G4PhysCollection::size();
|
||||
}
|
||||
|
||||
inline
|
||||
size_t G4PhysicsTable::length() const
|
||||
inline std::size_t G4PhysicsTable::length() const
|
||||
{
|
||||
return G4PhysCollection::size();
|
||||
}
|
||||
|
||||
inline
|
||||
G4bool G4PhysicsTable::isEmpty() const
|
||||
inline G4bool G4PhysicsTable::isEmpty() const
|
||||
{
|
||||
return G4PhysCollection::empty();
|
||||
}
|
||||
|
||||
inline
|
||||
G4bool G4PhysicsTable::GetFlag(size_t i) const
|
||||
inline G4bool G4PhysicsTable::GetFlag(std::size_t i) const
|
||||
{
|
||||
return vecFlag[i];
|
||||
}
|
||||
|
||||
inline
|
||||
void G4PhysicsTable::ClearFlag(size_t i)
|
||||
{
|
||||
vecFlag[i] = false;
|
||||
}
|
||||
inline void G4PhysicsTable::ClearFlag(std::size_t i) { vecFlag[i] = false; }
|
||||
|
||||
@@ -23,233 +23,206 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4PhysicsVector
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4PhysicsVector.hh
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// A physics vector which has values of energy-loss, cross-section,
|
||||
// and other physics values of a particle in matter in a given
|
||||
// range of the energy, momentum, etc.
|
||||
// This class serves as the base class for a vector having various
|
||||
// energy scale, for example like 'log', 'linear', 'free', etc.
|
||||
// A physics vector which has values of energy-loss, cross-section,
|
||||
// and other physics values of a particle in matter in a given
|
||||
// range of energy, momentum, etc.
|
||||
// This class serves as the base class for a vector having various
|
||||
// energy scale, for example like 'log', 'linear', 'free', etc.
|
||||
|
||||
// History:
|
||||
// 02 Dec. 1995, G.Cosmo : Structure created based on object model
|
||||
// 03 Mar. 1996, K.Amako : Implemented the 1st version
|
||||
// 27 Apr. 1996, K.Amako : Cache mechanism added
|
||||
// 01 Jul. 1996, K.Amako : Now GetValue not virtual
|
||||
// 21 Sep. 1996, K.Amako : Added [] and () operators
|
||||
// 11 Nov. 2000, H.Kurashige : Use STL vector for dataVector and binVector
|
||||
// 09 Mar. 2001, H.Kurashige : Added G4PhysicsVectorType & Store/Retrieve()
|
||||
// 02 Apr. 2008, A.Bagulya : Added SplineInterpolation() and SetSpline()
|
||||
// 11 May 2009, V.Ivanchenko : Added ComputeSecondDerivatives
|
||||
// 19 Jun. 2009, V.Ivanchenko : Removed hidden bin
|
||||
// 22 Dec. 2009 H.Kurashige : Use pointers to G4PVDataVector
|
||||
// 04 May. 2010 H.Kurashige : Use G4PhysicsVectorCache
|
||||
// 28 May 2010 H.Kurashige : Stop using pointers to G4PVDataVector
|
||||
// 16 Aug. 2011 H.Kurashige : Add dBin, baseBin and verboseLevel
|
||||
// 02 Oct. 2013 V.Ivanchenko : FindBinLocation method become inlined;
|
||||
// instead of G4Pow G4Log is used
|
||||
// 15 Mar. 2019 M.Novak : added Value method with the known log-energy value
|
||||
// that can avoid the log call in case of log-vectors
|
||||
// 16 July 2019 M.Novak : special LogVectorValue method for log-vectors
|
||||
//---------------------------------------------------------------
|
||||
// Authors:
|
||||
// - 02 Dec. 1995, G.Cosmo: Structure created based on object model
|
||||
// - 03 Mar. 1996, K.Amako: Implemented the 1st version
|
||||
// Revisions:
|
||||
// - 11 Nov. 2000, H.Kurashige: Use STL vector for dataVector and binVector
|
||||
// - 02 Apr. 2008, A.Bagulya: Added SplineInterpolation() and SetSpline()
|
||||
// - 19 Jun. 2009, V.Ivanchenko: Removed hidden bin
|
||||
// - 15 Mar. 2019 M.Novak: added Value method with the known log-energy value
|
||||
// that can avoid the log call in case of log-vectors
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4PhysicsVector_hh
|
||||
#define G4PhysicsVector_hh 1
|
||||
|
||||
#ifndef G4PhysicsVector_h
|
||||
#define G4PhysicsVector_h 1
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4ios.hh"
|
||||
#include "G4PhysicsVectorType.hh"
|
||||
#include "G4Log.hh"
|
||||
#include "G4PhysicsVectorType.hh"
|
||||
#include "G4ios.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
typedef std::vector<G4double> G4PVDataVector;
|
||||
using G4PVDataVector = std::vector<G4double>;
|
||||
|
||||
class G4PhysicsVector
|
||||
class G4PhysicsVector
|
||||
{
|
||||
public:// with description
|
||||
public:
|
||||
explicit G4PhysicsVector(G4bool spline = false);
|
||||
// Default constructor - vector will be filled via Retrieve() method
|
||||
|
||||
explicit G4PhysicsVector(G4bool spline = false);
|
||||
// default constructor - vector will be filled via Retrieve() method
|
||||
G4PhysicsVector(const G4PhysicsVector&);
|
||||
G4PhysicsVector& operator=(const G4PhysicsVector&);
|
||||
// Copy constructor and assignment operator
|
||||
|
||||
G4PhysicsVector(const G4PhysicsVector&);
|
||||
G4PhysicsVector& operator=(const G4PhysicsVector&);
|
||||
// Copy constructor and assignment operator.
|
||||
G4bool operator==(const G4PhysicsVector& right) const;
|
||||
G4bool operator!=(const G4PhysicsVector& right) const;
|
||||
// Equality operators
|
||||
|
||||
virtual ~G4PhysicsVector();
|
||||
virtual ~G4PhysicsVector();
|
||||
|
||||
G4double Value(G4double theEnergy, size_t& lastidx) const;
|
||||
// Get the cross-section/energy-loss value corresponding to the
|
||||
// given energy. An appropriate interpolation is used to calculate
|
||||
// the value. Consumer code got changed index and may reuse it
|
||||
// for the next call to save CPU for bin location.
|
||||
G4double Value(G4double theEnergy, std::size_t& lastidx) const;
|
||||
// Get the cross-section/energy-loss value corresponding to the
|
||||
// given energy. An appropriate interpolation is used to calculate
|
||||
// the value. Consumer code gets changed index and may reuse it
|
||||
// for the next call to save CPU for bin location.
|
||||
|
||||
inline G4double LogVectorValue(const G4double theEnergy,
|
||||
const G4double theLogEnergy) const;
|
||||
// Same as the Value method above but specialised for log-vector type.
|
||||
// Note, unlike the general Value method above, this method will work
|
||||
// properly only in case of G4PhysicsLogVector-s.
|
||||
inline G4double LogVectorValue(const G4double theEnergy,
|
||||
const G4double theLogEnergy) const;
|
||||
// Same as the Value() method above but specialised for log-vector type.
|
||||
// Note, unlike the general Value() method above, this method will work
|
||||
// properly only in case of G4PhysicsLogVector-s.
|
||||
|
||||
inline G4double Value(G4double theEnergy) const;
|
||||
// Get the cross-section/energy-loss value corresponding to the
|
||||
// given energy. An appropriate interpolation is used to calculate
|
||||
// the value. This method is kept for backward compatibility reason,
|
||||
// it should be used instead of the previous method if bin location
|
||||
// cannot be kept thread safe
|
||||
inline G4double Value(G4double theEnergy) const;
|
||||
// Get the cross-section/energy-loss value corresponding to the
|
||||
// given energy. An appropriate interpolation is used to calculate
|
||||
// the value. This method is kept for backward compatibility reason,
|
||||
// it should be used instead of the previous method if bin location
|
||||
// cannot be kept thread safe
|
||||
|
||||
inline G4double GetValue(G4double theEnergy, G4bool& isOutRange) const;
|
||||
// Obsolete method to get value, isOutRange is not used anymore.
|
||||
// This method is kept for the compatibility reason.
|
||||
inline G4double GetValue(G4double theEnergy, G4bool& isOutRange) const;
|
||||
// Obsolete method to get value, 'isOutRange' is not used anymore.
|
||||
// This method is kept for the compatibility reason
|
||||
|
||||
G4bool operator==(const G4PhysicsVector &right) const ;
|
||||
G4bool operator!=(const G4PhysicsVector &right) const ;
|
||||
inline G4double operator[](const std::size_t index) const;
|
||||
// Returns the value for the specified index of the dataVector
|
||||
// The boundary check will not be done
|
||||
|
||||
inline G4double operator[](const size_t index) const ;
|
||||
// Returns the value for the specified index of the dataVector
|
||||
// The boundary check will not be done.
|
||||
inline G4double operator()(const std::size_t index) const;
|
||||
// Returns the value for the specified index of the dataVector
|
||||
// The boundary check will not be done
|
||||
|
||||
inline G4double operator()(const size_t index) const ;
|
||||
// Returns the value for the specified index of the dataVector
|
||||
// The boundary check will not be done.
|
||||
inline void PutValue(std::size_t index, G4double theValue);
|
||||
// Put 'theValue' into the dataVector specified by 'index'.
|
||||
// Take note that the 'index' starts from '0'.
|
||||
// To fill the vector, need to beforehand construct a vector
|
||||
// by the constructor with Emin, Emax, Nbin. 'theValue' should
|
||||
// be the cross-section/energy-loss value corresponding to the
|
||||
// energy of the index
|
||||
|
||||
inline void PutValue(size_t index, G4double theValue);
|
||||
// Put 'theValue' into the dataVector specified by 'index'.
|
||||
// Take note that the 'index' starts from '0'.
|
||||
// To fill the vector, you have beforehand to construct a vector
|
||||
// by the constructor with Emin, Emax, Nbin. 'theValue' should
|
||||
// be the crosssection/energyloss value corresponding to the
|
||||
// energy of the index.
|
||||
virtual void ScaleVector(G4double factorE, G4double factorV);
|
||||
// Scale all values of the vector and second derivatives
|
||||
// by factorV, energies by vectorE. This method may be applied
|
||||
// for example after retrieving a vector from an external file to
|
||||
// convert values into Geant4 units
|
||||
|
||||
virtual void ScaleVector(G4double factorE, G4double factorV);
|
||||
// Scale all values of the vector and second derivatives
|
||||
// by factorV, energies by vectorE. This method may be applied
|
||||
// for example after Retrieve a vector from an external file to
|
||||
// convert values into Geant4 units
|
||||
inline G4double Energy(std::size_t index) const;
|
||||
// Returns the value in the energy specified by 'index'
|
||||
// of the energy vector. The boundary check will not be done.
|
||||
// Use this function when compute cross-section or dEdx
|
||||
// before filling the vector by PutValue()
|
||||
|
||||
inline G4double Energy(size_t index) const;
|
||||
// Returns the value in the energy specified by 'index'
|
||||
// of the energy vector. The boundary check will not be done.
|
||||
// Use this function when compute cross section or dEdx
|
||||
// before filling the vector by PutValue(..).
|
||||
inline G4double GetMaxEnergy() const;
|
||||
// Returns the energy of the last point of the vector
|
||||
|
||||
inline G4double GetMaxEnergy() const;
|
||||
// Returns the energy of the last point of the vector
|
||||
G4double GetLowEdgeEnergy(std::size_t binNumber) const;
|
||||
// Obsolete method
|
||||
// Get the energy value at the low edge of the specified bin.
|
||||
// Take note that the 'binNumber' starts from '0'.
|
||||
// The boundary check will not be done
|
||||
|
||||
G4double GetLowEdgeEnergy(size_t binNumber) const;
|
||||
// Obsolete method
|
||||
// Get the energy value at the low edge of the specified bin.
|
||||
// Take note that the 'binNumber' starts from '0'.
|
||||
// The boundary check will not be done.
|
||||
inline std::size_t GetVectorLength() const;
|
||||
// Get the total length of the vector
|
||||
|
||||
inline size_t GetVectorLength() const;
|
||||
// Get the total length of the vector.
|
||||
inline std::size_t FindBin(const G4double energy,
|
||||
const std::size_t idx) const;
|
||||
// Find low edge index of a bin for given energy.
|
||||
// Min value 0, max value VectorLength-1.
|
||||
// idx is suggested bin number from user code
|
||||
|
||||
inline size_t FindBin(G4double energy, size_t idx) const;
|
||||
// find low edge index of a bin for given energy
|
||||
// min value 0, max value VectorLength-1
|
||||
// idx is suggested bin number from user code
|
||||
inline std::size_t ComputeLogVectorBin(const G4double logenergy) const;
|
||||
// Computes the lower index the energy bin in case of log-vector i.e.
|
||||
// in case of vectors with equal bin widths on log-scale
|
||||
|
||||
inline size_t ComputeLogVectorBin(const G4double logenergy) const;
|
||||
// Computes the lower index the energy bin in case of log-vector i.e.
|
||||
// in case of vectors with equal bin widths on log-scale.
|
||||
void FillSecondDerivatives();
|
||||
// Initialise second derivatives for Spline keeping
|
||||
// 3rd derivative continues - default algorithm.
|
||||
// Warning: this method should be called when the vector
|
||||
// is already filled
|
||||
|
||||
void FillSecondDerivatives();
|
||||
// Initialise second derivatives for spline keeping
|
||||
// 3d derivative continues - default algorithm
|
||||
// Warning: this method should be called when the vector
|
||||
// is already filled
|
||||
void ComputeSecDerivatives();
|
||||
// Initialise second derivatives for Spline using algorithm
|
||||
// which garantee only 1st derivative continues.
|
||||
// Warning: this method should be called when the vector
|
||||
// is already filled
|
||||
|
||||
void ComputeSecDerivatives();
|
||||
// Initialise second derivatives for spline using algorithm
|
||||
// which garantee only 1st derivative continues
|
||||
// Warning: this method should be called when the vector
|
||||
// is already filled
|
||||
void ComputeSecondDerivatives(G4double firstPointDerivative,
|
||||
G4double endPointDerivative);
|
||||
// Initialise second derivatives for Spline using
|
||||
// user defined 1st derivatives at edge points.
|
||||
// Warning: this method should be called when the vector
|
||||
// is already filled
|
||||
|
||||
void ComputeSecondDerivatives(G4double firstPointDerivative,
|
||||
G4double endPointDerivative);
|
||||
// Initialise second derivatives for spline using
|
||||
// user defined 1st derivatives at edge points
|
||||
// Warning: this method should be called when the vector
|
||||
// is already filled
|
||||
G4double FindLinearEnergy(G4double rand) const;
|
||||
// Find energy using linear interpolation for vector
|
||||
// filled by cumulative probability function
|
||||
// value of rand should be between 0 and 1
|
||||
|
||||
G4double FindLinearEnergy(G4double rand) const;
|
||||
// Find energy using linear interpolation for vector
|
||||
// filled by cumulative probability function
|
||||
// value of rand should be between 0 and 1
|
||||
inline G4bool IsFilledVectorExist() const;
|
||||
// Is non-empty physics vector already exist?
|
||||
|
||||
inline G4bool IsFilledVectorExist() const;
|
||||
// Is non-empty physics vector already exist?
|
||||
inline G4PhysicsVectorType GetType() const;
|
||||
// Get physics vector type
|
||||
|
||||
inline G4PhysicsVectorType GetType() const;
|
||||
// Get physics vector type
|
||||
|
||||
inline void SetSpline(G4bool);
|
||||
// Activate/deactivate Spline interpolation.
|
||||
inline void SetSpline(G4bool);
|
||||
// Activate/deactivate Spline interpolation
|
||||
|
||||
G4bool Store(std::ofstream& fOut, G4bool ascii=false) const;
|
||||
virtual G4bool Retrieve(std::ifstream& fIn, G4bool ascii=false);
|
||||
// To store/retrieve persistent data to/from file streams.
|
||||
G4bool Store(std::ofstream& fOut, G4bool ascii = false) const;
|
||||
virtual G4bool Retrieve(std::ifstream& fIn, G4bool ascii = false);
|
||||
// To store/retrieve persistent data to/from file streams.
|
||||
|
||||
friend std::ostream& operator<<(std::ostream&, const G4PhysicsVector&);
|
||||
void DumpValues(G4double unitE=1.0, G4double unitV=1.0) const;
|
||||
// print vector
|
||||
friend std::ostream& operator<<(std::ostream&, const G4PhysicsVector&);
|
||||
void DumpValues(G4double unitE = 1.0, G4double unitV = 1.0) const;
|
||||
// Print vector
|
||||
|
||||
inline void SetVerboseLevel(G4int value);
|
||||
inline void SetVerboseLevel(G4int value);
|
||||
|
||||
inline G4double Interpolation(size_t idx, G4double energy) const;
|
||||
protected:
|
||||
void DeleteData();
|
||||
void CopyData(const G4PhysicsVector& vec);
|
||||
// Internal methods for allowing copy of objects
|
||||
|
||||
protected:
|
||||
void PrintPutValueError(std::size_t index);
|
||||
|
||||
void DeleteData();
|
||||
void CopyData(const G4PhysicsVector& vec);
|
||||
// Internal methods for allowing copy of objects
|
||||
G4PhysicsVectorType type = T_G4PhysicsVector;
|
||||
// The type of PhysicsVector (enumerator)
|
||||
|
||||
void PrintPutValueError(size_t index);
|
||||
G4double edgeMin = 0.0; // Energy of first point
|
||||
G4double edgeMax = 0.0; // Energy of the last point
|
||||
|
||||
protected:
|
||||
G4double invdBin = 0.0; // 1/Bin width - useful only for fixed binning
|
||||
G4double baseBin = 0.0; // Set this in constructor for performance
|
||||
|
||||
G4PhysicsVectorType type; // The type of PhysicsVector (enumerator)
|
||||
G4int verboseLevel = 0;
|
||||
std::size_t numberOfNodes = 0;
|
||||
|
||||
G4double edgeMin; // Energy of first point
|
||||
G4double edgeMax; // Energy of the last point
|
||||
G4PVDataVector dataVector; // Vector to keep the crossection/energyloss
|
||||
G4PVDataVector binVector; // Vector to keep energy
|
||||
G4PVDataVector secDerivative; // Vector to keep second derivatives
|
||||
|
||||
size_t numberOfNodes;
|
||||
private:
|
||||
G4bool SplinePossible();
|
||||
|
||||
G4PVDataVector dataVector; // Vector to keep the crossection/energyloss
|
||||
G4PVDataVector binVector; // Vector to keep energy
|
||||
G4PVDataVector secDerivative; // Vector to keep second derivatives
|
||||
inline std::size_t FindBinLocation(const G4double theEnergy) const;
|
||||
// Find low edge index of a bin for given energy.
|
||||
// Min value 0, max value VectorLength-1
|
||||
|
||||
private:
|
||||
inline G4double Interpolation(const std::size_t idx,
|
||||
const G4double energy) const;
|
||||
|
||||
G4bool SplinePossible();
|
||||
|
||||
inline G4double LinearInterpolation(size_t idx, G4double energy) const;
|
||||
// Linear interpolation function
|
||||
inline G4double SplineInterpolation(size_t idx, G4double energy) const;
|
||||
// Spline interpolation function
|
||||
|
||||
inline size_t FindBinLocation(G4double theEnergy) const;
|
||||
// find low edge index of a bin for given energy
|
||||
// min value 0, max value VectorLength-1
|
||||
|
||||
G4bool useSpline;
|
||||
|
||||
protected:
|
||||
|
||||
G4double invdBin; // 1/Bin width - useful only for fixed binning
|
||||
G4double baseBin; // Set this in constructor for performance
|
||||
|
||||
G4int verboseLevel;
|
||||
G4bool useSpline = false;
|
||||
};
|
||||
|
||||
#include "G4PhysicsVector.icc"
|
||||
|
||||
@@ -23,267 +23,206 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4PhysicsVector inline methods implementation
|
||||
//
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class source file
|
||||
//
|
||||
// G4PhysicsVector.icc
|
||||
//
|
||||
// Description:
|
||||
// A physics vector which has values of energy-loss, cross-section,
|
||||
// and other physics values of a particle in matter in a given
|
||||
// range of the energy, momentum, etc.
|
||||
// This class serves as the base class for a vector having various
|
||||
// energy scale, for example like 'log', 'linear', 'free', etc.
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// Authors:
|
||||
// - 02 Dec. 1995, G.Cosmo: Structure created based on object model
|
||||
// - 03 Mar. 1996, K.Amako: Implemented the 1st version
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline
|
||||
G4double G4PhysicsVector::operator[](const size_t index) const
|
||||
{
|
||||
return dataVector[index];
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
inline
|
||||
G4double G4PhysicsVector::operator()(const size_t index) const
|
||||
inline G4double G4PhysicsVector::operator[](const std::size_t index) const
|
||||
{
|
||||
return dataVector[index];
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
inline
|
||||
G4double G4PhysicsVector::Energy(const size_t index) const
|
||||
inline G4double G4PhysicsVector::operator()(const std::size_t index) const
|
||||
{
|
||||
return dataVector[index];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
inline G4double G4PhysicsVector::Energy(const std::size_t index) const
|
||||
{
|
||||
return binVector[index];
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
inline
|
||||
G4double G4PhysicsVector::GetMaxEnergy() const
|
||||
{
|
||||
return edgeMax;
|
||||
}
|
||||
inline G4double G4PhysicsVector::GetMaxEnergy() const { return edgeMax; }
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
inline
|
||||
size_t G4PhysicsVector::GetVectorLength() const
|
||||
inline std::size_t G4PhysicsVector::GetVectorLength() const
|
||||
{
|
||||
return numberOfNodes;
|
||||
}
|
||||
|
||||
//------------------------------------------------
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
inline
|
||||
G4double G4PhysicsVector::LinearInterpolation(size_t idx, G4double e) const
|
||||
inline void G4PhysicsVector::PutValue(std::size_t index, G4double theValue)
|
||||
{
|
||||
// Linear interpolation is used to get the value. Before this method
|
||||
// is called it is ensured that the energy is inside the bin
|
||||
// 0 < idx < numberOfNodes-1
|
||||
|
||||
return dataVector[idx] +
|
||||
( dataVector[idx + 1]-dataVector[idx] ) * (e - binVector[idx])
|
||||
/( binVector[idx + 1]-binVector[idx] );
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
inline
|
||||
G4double G4PhysicsVector::SplineInterpolation(size_t idx, G4double e) const
|
||||
{
|
||||
// Spline interpolation is used to get the value. Before this method
|
||||
// is called it is ensured that the energy is inside the bin
|
||||
// 0 < idx < numberOfNodes-1
|
||||
|
||||
static const G4double onesixth = 1.0/6.0;
|
||||
|
||||
// check bin value
|
||||
G4double x1 = binVector[idx];
|
||||
G4double x2 = binVector[idx + 1];
|
||||
G4double delta = x2 - x1;
|
||||
|
||||
G4double a = (x2 - e)/delta;
|
||||
G4double b = (e - x1)/delta;
|
||||
|
||||
// Final evaluation of cubic spline polynomial for return
|
||||
G4double y1 = dataVector[idx];
|
||||
G4double y2 = dataVector[idx + 1];
|
||||
|
||||
G4double res = a*y1 + b*y2 +
|
||||
( (a*a*a - a)*secDerivative[idx] +
|
||||
(b*b*b - b)*secDerivative[idx + 1] )*delta*delta*onesixth;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
inline
|
||||
G4double G4PhysicsVector::Interpolation(size_t idx, G4double e) const
|
||||
{
|
||||
return useSpline ? SplineInterpolation(idx, e) : LinearInterpolation(idx, e);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
inline
|
||||
void G4PhysicsVector::PutValue(size_t index, G4double theValue)
|
||||
{
|
||||
if(index >= numberOfNodes) { PrintPutValueError(index); }
|
||||
if(index >= numberOfNodes)
|
||||
{
|
||||
PrintPutValueError(index);
|
||||
}
|
||||
dataVector[index] = theValue;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
inline
|
||||
G4bool G4PhysicsVector::IsFilledVectorExist() const
|
||||
inline G4bool G4PhysicsVector::IsFilledVectorExist() const
|
||||
{
|
||||
return (numberOfNodes > 0) ? true : false;
|
||||
return (numberOfNodes > 0);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
inline
|
||||
G4PhysicsVectorType G4PhysicsVector::GetType() const
|
||||
inline G4PhysicsVectorType G4PhysicsVector::GetType() const { return type; }
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
inline void G4PhysicsVector::SetSpline(G4bool val)
|
||||
{
|
||||
return type;
|
||||
}
|
||||
// Flag useSpline is "true" only if second derivatives are filled
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
// Flag useSpline is "true" only if second derivatives are filled
|
||||
inline
|
||||
void G4PhysicsVector::SetSpline(G4bool val)
|
||||
{
|
||||
if(val) {
|
||||
if(0 == secDerivative.size() && 0 < dataVector.size()) {
|
||||
FillSecondDerivatives();
|
||||
if(val)
|
||||
{
|
||||
if(0 == secDerivative.size() && 0 < dataVector.size())
|
||||
{
|
||||
FillSecondDerivatives();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
useSpline = false;
|
||||
secDerivative.clear();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
inline
|
||||
void G4PhysicsVector::SetVerboseLevel(G4int value)
|
||||
inline void G4PhysicsVector::SetVerboseLevel(G4int value)
|
||||
{
|
||||
verboseLevel = value;
|
||||
verboseLevel = value;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
/*
|
||||
inline
|
||||
G4int G4PhysicsVector::GetVerboseLevel() const
|
||||
{
|
||||
return verboseLevel;
|
||||
}
|
||||
*/
|
||||
//---------------------------------------------------------------
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
inline
|
||||
size_t G4PhysicsVector::FindBinLocation(G4double theEnergy) const
|
||||
inline std::size_t G4PhysicsVector::FindBinLocation(
|
||||
const G4double theEnergy) const
|
||||
{
|
||||
size_t bin;
|
||||
if(type == T_G4PhysicsLogVector) {
|
||||
bin = size_t(G4Log(theEnergy)*invdBin - baseBin);
|
||||
if(bin > 0 && theEnergy < binVector[bin]) { --bin; }
|
||||
else if(theEnergy > binVector[bin+1]) { ++bin; }
|
||||
} else if(type == T_G4PhysicsLinearVector) {
|
||||
bin = size_t( theEnergy*invdBin - baseBin );
|
||||
if(bin > 0 && theEnergy < binVector[bin]) { --bin; }
|
||||
else if(theEnergy > binVector[bin+1]) { ++bin; }
|
||||
} else {
|
||||
// Bin location proposed by K.Genser (FNAL)
|
||||
bin = std::lower_bound(binVector.begin(), binVector.end(), theEnergy)
|
||||
- binVector.begin() - 1;
|
||||
}
|
||||
return std::min(bin, numberOfNodes-2);
|
||||
std::size_t bin;
|
||||
if(type == T_G4PhysicsLogVector)
|
||||
{
|
||||
bin = size_t(std::max(G4Log(theEnergy) * invdBin - baseBin, 0.0));
|
||||
}
|
||||
else if(type == T_G4PhysicsLinearVector)
|
||||
{
|
||||
bin = size_t(std::max(theEnergy * invdBin - baseBin, 0.0));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Bin location proposed by K.Genser (FNAL)
|
||||
bin = std::lower_bound(binVector.begin(), binVector.end(), theEnergy) -
|
||||
binVector.begin() - 1;
|
||||
}
|
||||
return std::min(bin, numberOfNodes - 2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
inline size_t G4PhysicsVector::FindBin(G4double e, size_t idx) const
|
||||
inline std::size_t G4PhysicsVector::FindBin(const G4double e,
|
||||
const std::size_t idx) const
|
||||
{
|
||||
size_t id = idx;
|
||||
if(e < binVector[1]) {
|
||||
id = 0;
|
||||
} else if(e >= binVector[numberOfNodes-2]) {
|
||||
id = numberOfNodes - 2;
|
||||
} else if(idx >= numberOfNodes-2 || e < binVector[idx]
|
||||
|| e > binVector[idx+1]) {
|
||||
id = FindBinLocation(e);
|
||||
std::size_t id = idx;
|
||||
// it is not possible to drop this long if below before
|
||||
// PAI and diffuse elastic data models will not be improved
|
||||
if(e < binVector[1])
|
||||
{
|
||||
id = 0;
|
||||
}
|
||||
else if(e >= binVector[numberOfNodes - 2])
|
||||
{
|
||||
id = numberOfNodes - 2;
|
||||
}
|
||||
else if(idx > numberOfNodes - 2 || e < binVector[idx] ||
|
||||
e > binVector[idx + 1])
|
||||
{
|
||||
id = FindBinLocation(e);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
inline
|
||||
size_t G4PhysicsVector::ComputeLogVectorBin(const G4double loge) const
|
||||
inline std::size_t G4PhysicsVector::ComputeLogVectorBin(
|
||||
const G4double loge) const
|
||||
{
|
||||
return size_t(std::max(0., std::min(loge*invdBin-baseBin, numberOfNodes-2.)));
|
||||
return std::size_t(
|
||||
std::max(0., std::min(loge * invdBin - baseBin, numberOfNodes - 2.)));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
inline
|
||||
G4double G4PhysicsVector::Value(G4double theEnergy) const
|
||||
inline G4double G4PhysicsVector::Value(G4double theEnergy) const
|
||||
{
|
||||
size_t idx=0;
|
||||
std::size_t idx = 0;
|
||||
return Value(theEnergy, idx);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
inline
|
||||
G4double G4PhysicsVector::GetValue(G4double theEnergy, G4bool&) const
|
||||
inline G4double G4PhysicsVector::GetValue(G4double theEnergy, G4bool&) const
|
||||
{
|
||||
size_t idx=0;
|
||||
std::size_t idx = 0;
|
||||
return Value(theEnergy, idx);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
inline
|
||||
G4double G4PhysicsVector::LogVectorValue(const G4double theEnergy,
|
||||
const G4double theLogEnergy) const
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
inline G4double G4PhysicsVector::Interpolation(const std::size_t idx,
|
||||
const G4double e) const
|
||||
{
|
||||
// handle cases below/above the enrgy grid (by ek, idx that gives b=0/1)
|
||||
// ek = x[0] if e<=x[0] and idx will be 0 ^ b=0 => so y=y0
|
||||
// ek = x[N-1] if e>=x[N-1] and idx will be N-2 ^ b=1 => so y=y_{N-1}
|
||||
const G4double ek = std::max(binVector[0],
|
||||
std::min(binVector[numberOfNodes-1], theEnergy));
|
||||
// compute the lowerindex of the bin (idx \in [0,N-2] will be guaranted)
|
||||
const size_t idx = ComputeLogVectorBin(theLogEnergy);
|
||||
// perform the interpolation
|
||||
const G4double x1 = binVector[idx];
|
||||
const G4double x2 = binVector[idx+1];
|
||||
const G4double dl = x2-x1;
|
||||
const G4double dl = binVector[idx + 1] - x1;
|
||||
// note: all corner cases of the previous methods are covered and eventually
|
||||
// gives b=0/1 that results in y=y0\y_{N-1} if e<=x[0]/e>=x[N-1] or
|
||||
// y=y_i/y_{i+1} if e<x[i]/e>=x[i+1] due to small numerical errors
|
||||
const G4double b = std::max(0., std::min(1., (ek - x1)/dl));
|
||||
if (useSpline) { // spline interpolation
|
||||
const G4double os = 0.166666666667; // 1./6.
|
||||
const G4double a = 1.0 - b;
|
||||
const G4double c0 = (a*a*a-a)*secDerivative[idx];
|
||||
const G4double c1 = (b*b*b-b)*secDerivative[idx+1];
|
||||
return a*dataVector[idx] + b*dataVector[idx+1] + (c0+c1)*dl*dl*os;
|
||||
} else { // linear interpolation
|
||||
const G4double y1 = dataVector[idx];
|
||||
const G4double y2 = dataVector[idx+1];
|
||||
return y1 + b*(y2-y1);
|
||||
const G4double b = std::max(0., std::min(1., (e - x1) / dl));
|
||||
G4double res;
|
||||
if(useSpline) // spline interpolation
|
||||
{
|
||||
const G4double os = 0.166666666667; // 1./6.
|
||||
const G4double a = 1.0 - b;
|
||||
const G4double c0 = (a * a * a - a) * secDerivative[idx];
|
||||
const G4double c1 = (b * b * b - b) * secDerivative[idx + 1];
|
||||
res =
|
||||
a * dataVector[idx] + b * dataVector[idx + 1] + (c0 + c1) * dl * dl * os;
|
||||
}
|
||||
else // linear interpolation
|
||||
{
|
||||
const G4double y1 = dataVector[idx];
|
||||
const G4double y2 = dataVector[idx + 1];
|
||||
res = y1 + b * (y2 - y1);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
inline G4double G4PhysicsVector::LogVectorValue(
|
||||
const G4double theEnergy, const G4double theLogEnergy) const
|
||||
{
|
||||
// handle cases below/above the energy grid (by ek, idx that gives b=0/1)
|
||||
// ek = x[0] if e<=x[0] and idx will be 0 ^ b=0 => so y=y0
|
||||
// ek = x[N-1] if e>=x[N-1] and idx will be N-2 ^ b=1 => so y=y_{N-1}
|
||||
const G4double ek =
|
||||
std::max(binVector[0], std::min(binVector[numberOfNodes - 1], theEnergy));
|
||||
// compute the lowerindex of the bin (idx \in [0,N-2] will be guaranted)
|
||||
const std::size_t idx = ComputeLogVectorBin(theLogEnergy);
|
||||
return Interpolation(idx, ek);
|
||||
}
|
||||
|
||||
@@ -23,13 +23,9 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------
|
||||
//
|
||||
// G4PhysicsVectorType
|
||||
//
|
||||
// Class Description:
|
||||
// Description:
|
||||
//
|
||||
// Enumerator to define the physics vector type:
|
||||
// G4PhysicsVector - base
|
||||
@@ -40,14 +36,14 @@
|
||||
// G4PhysicsOrderedFreeVector
|
||||
// G4LPhysicsFreeVector
|
||||
|
||||
// Author: H.Kurashige, 9 March 2001
|
||||
// --------------------------------------------------------------
|
||||
|
||||
#ifndef G4PhysicsVectorType_h
|
||||
#define G4PhysicsVectorType_h
|
||||
#ifndef G4PhysicsVectorType_hh
|
||||
#define G4PhysicsVectorType_hh 1
|
||||
|
||||
enum G4PhysicsVectorType
|
||||
{
|
||||
T_G4PhysicsVector =0,
|
||||
T_G4PhysicsVector = 0,
|
||||
T_G4PhysicsLinearVector,
|
||||
T_G4PhysicsLogVector,
|
||||
T_G4PhysicsLnVector,
|
||||
|
||||
@@ -23,148 +23,137 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------
|
||||
//
|
||||
// Class G4Pow
|
||||
// G4Pow
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// Utility singleton class for the fast computation of log and pow
|
||||
// functions. Integer argument should in the interval 0-512, no
|
||||
// functions. Integer argument should be in the interval 0-512, no
|
||||
// check is performed inside these methods for performance reasons.
|
||||
// For factorial integer argument should be in the interval 0-170
|
||||
// Computations with double arguments are fast for the interval
|
||||
// 0.002-511.5 for all functions except exponent, which is computed
|
||||
// 0.002-511.5 for all functions except exponent, which is computed
|
||||
// for the interval 0-84.4, standard library is used in the opposite case
|
||||
|
||||
// Author: Vladimir Ivanchenko
|
||||
//
|
||||
// Creation date: 23.05.2009
|
||||
// -------------------------------------------------------------------
|
||||
// Author: Vladimir Ivanchenko, 23.05.2009
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4Pow_hh
|
||||
#define G4Pow_hh 1
|
||||
|
||||
#ifndef G4Pow_h
|
||||
#define G4Pow_h 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4Log.hh"
|
||||
#include "G4Exp.hh"
|
||||
#include "G4DataVector.hh"
|
||||
#include "G4Exp.hh"
|
||||
#include "G4Log.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
class G4Pow
|
||||
{
|
||||
public:
|
||||
static G4Pow* GetInstance();
|
||||
~G4Pow();
|
||||
|
||||
public:
|
||||
// Fast computation of Z^1/3
|
||||
//
|
||||
inline G4double Z13(G4int Z) const;
|
||||
G4double A13(G4double A) const;
|
||||
|
||||
static G4Pow* GetInstance();
|
||||
~G4Pow();
|
||||
// Fast computation of Z^2/3
|
||||
//
|
||||
inline G4double Z23(G4int Z) const;
|
||||
inline G4double A23(G4double A) const;
|
||||
|
||||
// Fast computation of Z^1/3
|
||||
//
|
||||
inline G4double Z13(G4int Z) const;
|
||||
G4double A13(G4double A) const;
|
||||
// Fast computation of log(Z)
|
||||
//
|
||||
inline G4double logZ(G4int Z) const;
|
||||
inline G4double logA(G4double A) const;
|
||||
inline G4double logX(G4double x) const;
|
||||
|
||||
// Fast computation of Z^2/3
|
||||
//
|
||||
inline G4double Z23(G4int Z) const;
|
||||
inline G4double A23(G4double A) const;
|
||||
// Fast computation of log10(Z)
|
||||
//
|
||||
inline G4double log10Z(G4int Z) const;
|
||||
inline G4double log10A(G4double A) const;
|
||||
|
||||
// Fast computation of log(Z)
|
||||
//
|
||||
inline G4double logZ(G4int Z) const;
|
||||
inline G4double logA(G4double A) const;
|
||||
inline G4double logX(G4double x) const;
|
||||
// Fast computation of exp(X)
|
||||
//
|
||||
inline G4double expA(G4double A) const;
|
||||
|
||||
// Fast computation of log10(Z)
|
||||
//
|
||||
inline G4double log10Z(G4int Z) const;
|
||||
inline G4double log10A(G4double A) const;
|
||||
// Fast computation of pow(Z,X)
|
||||
//
|
||||
inline G4double powZ(G4int Z, G4double y) const;
|
||||
inline G4double powA(G4double A, G4double y) const;
|
||||
G4double powN(G4double x, G4int n) const;
|
||||
|
||||
// Fast computation of exp(X)
|
||||
//
|
||||
inline G4double expA(G4double A) const;
|
||||
// Fast factorial
|
||||
//
|
||||
inline G4double factorial(G4int Z) const;
|
||||
inline G4double logfactorial(G4int Z) const;
|
||||
|
||||
// Fast computation of pow(Z,X)
|
||||
//
|
||||
inline G4double powZ(G4int Z, G4double y) const;
|
||||
inline G4double powA(G4double A, G4double y) const;
|
||||
G4double powN(G4double x, G4int n) const;
|
||||
private:
|
||||
G4Pow();
|
||||
|
||||
// Fast factorial
|
||||
//
|
||||
inline G4double factorial(G4int Z) const;
|
||||
inline G4double logfactorial(G4int Z) const;
|
||||
G4double A13Low(const G4double, const G4bool) const;
|
||||
G4double A13High(const G4double, const G4bool) const;
|
||||
|
||||
private:
|
||||
inline G4double logBase(G4double x) const;
|
||||
|
||||
G4Pow();
|
||||
static G4Pow* fpInstance;
|
||||
|
||||
G4double A13Low(const G4double, const bool) const;
|
||||
G4double A13High(const G4double, const bool) const;
|
||||
const G4double onethird = 1.0 / 3.0;
|
||||
const G4int max2 = 5;
|
||||
|
||||
inline G4double logBase(G4double x) const;
|
||||
G4double maxA;
|
||||
G4double maxLowA;
|
||||
G4double maxA2;
|
||||
G4double maxAexp;
|
||||
|
||||
static G4Pow* fpInstance;
|
||||
|
||||
const G4double onethird;
|
||||
const G4int max2;
|
||||
|
||||
G4double maxA;
|
||||
G4double maxLowA;
|
||||
G4double maxA2;
|
||||
G4double maxAexp;
|
||||
|
||||
G4DataVector ener;
|
||||
G4DataVector logen;
|
||||
G4DataVector pz13;
|
||||
G4DataVector lowa13;
|
||||
G4DataVector lz;
|
||||
G4DataVector lz2;
|
||||
G4DataVector fexp;
|
||||
G4DataVector fact;
|
||||
G4DataVector logfact;
|
||||
G4DataVector ener;
|
||||
G4DataVector logen;
|
||||
G4DataVector pz13;
|
||||
G4DataVector lowa13;
|
||||
G4DataVector lz;
|
||||
G4DataVector lz2;
|
||||
G4DataVector fexp;
|
||||
G4DataVector fact;
|
||||
G4DataVector logfact;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// -----------------------------
|
||||
// Inline methods implementation
|
||||
// -----------------------------
|
||||
|
||||
inline G4double G4Pow::Z13(G4int Z) const
|
||||
{
|
||||
return pz13[Z];
|
||||
}
|
||||
inline G4double G4Pow::Z13(G4int Z) const { return pz13[Z]; }
|
||||
|
||||
inline G4double G4Pow::Z23(G4int Z) const
|
||||
{
|
||||
G4double x = Z13(Z);
|
||||
return x*x;
|
||||
return x * x;
|
||||
}
|
||||
|
||||
inline G4double G4Pow::A23(G4double A) const
|
||||
{
|
||||
G4double x = A13(A);
|
||||
return x*x;
|
||||
return x * x;
|
||||
}
|
||||
|
||||
inline G4double G4Pow::logZ(G4int Z) const
|
||||
{
|
||||
return lz[Z];
|
||||
}
|
||||
inline G4double G4Pow::logZ(G4int Z) const { return lz[Z]; }
|
||||
|
||||
inline G4double G4Pow::logBase(G4double a) const
|
||||
{
|
||||
G4double res;
|
||||
if(a <= maxA2)
|
||||
if(a <= maxA2)
|
||||
{
|
||||
G4int i = G4int(max2*(a - 1) + 0.5);
|
||||
if(i > max2) { i = max2; }
|
||||
G4double x = a/(G4double(i)/max2 + 1) - 1;
|
||||
res = lz2[i] + x*(1.0 - (0.5 - onethird*x)*x);
|
||||
G4int i = G4int(max2 * (a - 1) + 0.5);
|
||||
if(i > max2)
|
||||
{
|
||||
i = max2;
|
||||
}
|
||||
G4double x = a / (G4double(i) / max2 + 1) - 1;
|
||||
res = lz2[i] + x * (1.0 - (0.5 - onethird * x) * x);
|
||||
}
|
||||
else if(a <= maxA)
|
||||
{
|
||||
G4int i = G4int(a + 0.5);
|
||||
G4double x = a/G4double(i) - 1;
|
||||
res = lz[i] + x*(1.0 - (0.5 - onethird*x)*x);
|
||||
G4int i = G4int(a + 0.5);
|
||||
G4double x = a / G4double(i) - 1;
|
||||
res = lz[i] + x * (1.0 - (0.5 - onethird * x) * x);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -175,44 +164,41 @@ inline G4double G4Pow::logBase(G4double a) const
|
||||
|
||||
inline G4double G4Pow::logA(G4double A) const
|
||||
{
|
||||
return (1.0 <= A ? logBase(A) : -logBase(1./A));
|
||||
return (1.0 <= A ? logBase(A) : -logBase(1. / A));
|
||||
}
|
||||
|
||||
inline G4double G4Pow::logX(G4double x) const
|
||||
{
|
||||
G4double res = 0.0;
|
||||
G4double a = (1.0 <= x) ? x : 1.0/x;
|
||||
G4double a = (1.0 <= x) ? x : 1.0 / x;
|
||||
|
||||
if(a <= maxA)
|
||||
if(a <= maxA)
|
||||
{
|
||||
res = logBase(a);
|
||||
}
|
||||
else if(a <= ener[2])
|
||||
{
|
||||
res = logen[1] + logBase(a/ener[1]);
|
||||
res = logen[1] + logBase(a / ener[1]);
|
||||
}
|
||||
else if(a <= ener[3])
|
||||
{
|
||||
res = logen[2] + logBase(a/ener[2]);
|
||||
res = logen[2] + logBase(a / ener[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
res = G4Log(a);
|
||||
}
|
||||
|
||||
if(1.0 > x) { res = -res; }
|
||||
if(1.0 > x)
|
||||
{
|
||||
res = -res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
inline G4double G4Pow::log10Z(G4int Z) const
|
||||
{
|
||||
return lz[Z]/lz[10];
|
||||
}
|
||||
inline G4double G4Pow::log10Z(G4int Z) const { return lz[Z] / lz[10]; }
|
||||
|
||||
inline G4double G4Pow::log10A(G4double A) const
|
||||
{
|
||||
return logX(A)/lz[10];
|
||||
}
|
||||
inline G4double G4Pow::log10A(G4double A) const { return logX(A) / lz[10]; }
|
||||
|
||||
inline G4double G4Pow::expA(G4double A) const
|
||||
{
|
||||
@@ -221,38 +207,33 @@ inline G4double G4Pow::expA(G4double A) const
|
||||
|
||||
if(a <= maxAexp)
|
||||
{
|
||||
G4int i = G4int(2*a + 0.5);
|
||||
G4double x = a - i*0.5;
|
||||
res = fexp[i]*(1.0 + x*(1.0 + 0.5*(1.0 + onethird*x)*x));
|
||||
G4int i = G4int(2 * a + 0.5);
|
||||
G4double x = a - i * 0.5;
|
||||
res = fexp[i] * (1.0 + x * (1.0 + 0.5 * (1.0 + onethird * x) * x));
|
||||
}
|
||||
else
|
||||
{
|
||||
res = G4Exp(a);
|
||||
}
|
||||
if(0.0 > A) { res = 1.0/res; }
|
||||
if(0.0 > A)
|
||||
{
|
||||
res = 1.0 / res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
inline G4double G4Pow::powZ(G4int Z, G4double y) const
|
||||
{
|
||||
return expA(y*lz[Z]);
|
||||
return expA(y * lz[Z]);
|
||||
}
|
||||
|
||||
inline G4double G4Pow::powA(G4double A, G4double y) const
|
||||
{
|
||||
return (0.0 == A ? 0.0 : expA(y*logX(A)));
|
||||
return (0.0 == A ? 0.0 : expA(y * logX(A)));
|
||||
}
|
||||
|
||||
inline G4double G4Pow::factorial(G4int Z) const
|
||||
{
|
||||
return fact[Z];
|
||||
}
|
||||
inline G4double G4Pow::factorial(G4int Z) const { return fact[Z]; }
|
||||
|
||||
inline G4double G4Pow::logfactorial(G4int Z) const
|
||||
{
|
||||
return logfact[Z];
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
inline G4double G4Pow::logfactorial(G4int Z) const { return logfact[Z]; }
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,10 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// Class G4ReferenceCountedHandle
|
||||
// G4ReferenceCountedHandle
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
@@ -47,248 +44,242 @@
|
||||
// Trying to 'delete' a smart pointer object will generate a compilation
|
||||
// error (since we're dealing with objects, not pointers!).
|
||||
|
||||
// Author: Radovan Chytracek, CERN (Radovan.Chytracek@cern.ch)
|
||||
// Date: November 2001
|
||||
// ----------------------------------------------------------------------
|
||||
#ifndef _G4REFERENCECOUNTEDHANDLE_H_
|
||||
#define _G4REFERENCECOUNTEDHANDLE_H_ 1
|
||||
// Author: Radovan Chytracek, CERN - November 2001
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4REFERENCECOUNTEDHANDLE_HH
|
||||
#define G4REFERENCECOUNTEDHANDLE_HH 1
|
||||
|
||||
#include "G4Types.hh"
|
||||
#include "G4Allocator.hh"
|
||||
#include "G4Types.hh"
|
||||
|
||||
template <class X> class G4CountedObject;
|
||||
template <class X>
|
||||
class G4CountedObject;
|
||||
|
||||
template <class X>
|
||||
class G4ReferenceCountedHandle
|
||||
{
|
||||
public:
|
||||
inline G4ReferenceCountedHandle(X* rep = nullptr);
|
||||
// Constructor.
|
||||
|
||||
public: // with description
|
||||
|
||||
inline G4ReferenceCountedHandle( X* rep = 0 );
|
||||
// Constructor.
|
||||
|
||||
inline G4ReferenceCountedHandle( const G4ReferenceCountedHandle<X>& right );
|
||||
// Copy constructor.
|
||||
inline G4ReferenceCountedHandle(const G4ReferenceCountedHandle<X>& right);
|
||||
// Copy constructor.
|
||||
|
||||
inline ~G4ReferenceCountedHandle();
|
||||
// Destructor.
|
||||
|
||||
inline G4ReferenceCountedHandle<X>& operator =( const G4ReferenceCountedHandle<X>& right );
|
||||
// Assignment operator by reference.
|
||||
|
||||
inline G4ReferenceCountedHandle<X>& operator =( X* objPtr );
|
||||
// Assignment operator by pointer.
|
||||
|
||||
// Destructor.
|
||||
|
||||
inline G4ReferenceCountedHandle<X>& operator=(
|
||||
const G4ReferenceCountedHandle<X>& right);
|
||||
// Assignment operator by reference.
|
||||
|
||||
inline G4ReferenceCountedHandle<X>& operator=(X* objPtr);
|
||||
// Assignment operator by pointer.
|
||||
|
||||
inline unsigned int Count() const;
|
||||
// Forward to Counter class.
|
||||
|
||||
inline X* operator ->() const;
|
||||
// Operator -> allowing the access to counted object.
|
||||
// The check for 0-ness is left out for performance reasons,
|
||||
// see operator () below.
|
||||
// May be called on initialised smart-pointer only!
|
||||
|
||||
inline G4bool operator !() const;
|
||||
// Validity test operator.
|
||||
|
||||
// Forward to Counter class.
|
||||
|
||||
inline X* operator->() const;
|
||||
// Operator -> allowing the access to counted object.
|
||||
// The check for 0-ness is left out for performance reasons,
|
||||
// see operator () below.
|
||||
// May be called on initialised smart-pointer only!
|
||||
|
||||
inline G4bool operator!() const;
|
||||
// Validity test operator.
|
||||
|
||||
inline operator bool() const;
|
||||
// Boolean operator.
|
||||
|
||||
inline X* operator ()() const;
|
||||
// Functor operator (for convenience).
|
||||
|
||||
// There is no provision that this class is subclassed.
|
||||
// If it is subclassed & new data members are added then the
|
||||
// following "new" & "delete" will fail and give errors.
|
||||
//
|
||||
inline void* operator new( size_t );
|
||||
// Operator new defined for G4Allocator.
|
||||
|
||||
inline void operator delete( void *pObj );
|
||||
// Operator delete defined for G4Allocator.
|
||||
// Boolean operator.
|
||||
|
||||
private:
|
||||
inline X* operator()() const;
|
||||
// Functor operator (for convenience).
|
||||
|
||||
G4CountedObject<X>* fObj;
|
||||
// The object subject to reference counting.
|
||||
};
|
||||
|
||||
extern G4GLOB_DLL
|
||||
G4Allocator<G4ReferenceCountedHandle<void>>*& aRCHAllocator();
|
||||
|
||||
template <class X>
|
||||
class G4CountedObject
|
||||
{
|
||||
|
||||
friend class G4ReferenceCountedHandle<X>;
|
||||
|
||||
public: // with description
|
||||
|
||||
G4CountedObject( X* pObj = 0 );
|
||||
// Constructor.
|
||||
|
||||
~G4CountedObject();
|
||||
// Destructor.
|
||||
|
||||
inline void AddRef();
|
||||
// Increase the count.
|
||||
|
||||
inline void Release();
|
||||
// Decrease the count and if zero destroy itself.
|
||||
|
||||
// There is no provision that this class is subclassed.
|
||||
// If it is subclassed & new data members are added then the
|
||||
// following "new" & "delete" will fail and give errors.
|
||||
//
|
||||
inline void* operator new( size_t );
|
||||
// Operator new defined for G4Allocator.
|
||||
inline void* operator new(std::size_t);
|
||||
// Operator new defined for G4Allocator.
|
||||
|
||||
inline void operator delete( void *pObj );
|
||||
// operator delete defined for G4Allocator.
|
||||
inline void operator delete(void* pObj);
|
||||
// Operator delete defined for G4Allocator.
|
||||
|
||||
private:
|
||||
|
||||
unsigned int fCount;
|
||||
// Reference counter.
|
||||
X* fRep;
|
||||
// The counted object.
|
||||
private:
|
||||
G4CountedObject<X>* fObj = nullptr;
|
||||
// The object subject to reference counting.
|
||||
};
|
||||
|
||||
extern G4GLOB_DLL
|
||||
G4Allocator<G4CountedObject<void>>*& aCountedObjectAllocator();
|
||||
extern G4GLOB_DLL G4Allocator<G4ReferenceCountedHandle<void>>*& aRCHAllocator();
|
||||
|
||||
template <class X>
|
||||
class G4CountedObject
|
||||
{
|
||||
friend class G4ReferenceCountedHandle<X>;
|
||||
|
||||
public:
|
||||
G4CountedObject(X* pObj = nullptr);
|
||||
// Constructor.
|
||||
|
||||
~G4CountedObject();
|
||||
// Destructor.
|
||||
|
||||
inline void AddRef();
|
||||
// Increase the count.
|
||||
|
||||
inline void Release();
|
||||
// Decrease the count and if zero destroy itself.
|
||||
|
||||
// There is no provision that this class is subclassed.
|
||||
// If it is subclassed & new data members are added then the
|
||||
// following "new" & "delete" will fail and give errors.
|
||||
//
|
||||
inline void* operator new(std::size_t);
|
||||
// Operator new defined for G4Allocator.
|
||||
|
||||
inline void operator delete(void* pObj);
|
||||
// operator delete defined for G4Allocator.
|
||||
|
||||
private:
|
||||
unsigned int fCount = 0;
|
||||
// Reference counter.
|
||||
X* fRep = nullptr;
|
||||
// The counted object.
|
||||
};
|
||||
|
||||
extern G4GLOB_DLL G4Allocator<G4CountedObject<void>>*&
|
||||
aCountedObjectAllocator();
|
||||
|
||||
// --------- G4CountedObject<X> Inline function definitions ---------
|
||||
|
||||
template <class X>
|
||||
G4CountedObject<X>::G4CountedObject( X* pObj )
|
||||
: fCount(0), fRep( pObj )
|
||||
G4CountedObject<X>::G4CountedObject(X* pObj)
|
||||
: fRep(pObj)
|
||||
{
|
||||
if( pObj != 0 ) fCount = 1;
|
||||
if(pObj != nullptr)
|
||||
fCount = 1;
|
||||
}
|
||||
|
||||
template <class X>
|
||||
G4CountedObject<X>::~G4CountedObject()
|
||||
{
|
||||
delete fRep;
|
||||
}
|
||||
|
||||
template <class X>
|
||||
void G4CountedObject<X>::AddRef()
|
||||
{
|
||||
++fCount;
|
||||
}
|
||||
|
||||
template <class X>
|
||||
void G4CountedObject<X>::Release()
|
||||
{
|
||||
if( --fCount == 0 ) delete this;
|
||||
delete fRep;
|
||||
}
|
||||
|
||||
template <class X>
|
||||
void* G4CountedObject<X>::operator new( size_t )
|
||||
void G4CountedObject<X>::AddRef()
|
||||
{
|
||||
if (!aCountedObjectAllocator())
|
||||
aCountedObjectAllocator() = new G4Allocator<G4CountedObject<void>>;
|
||||
return( (void *)aCountedObjectAllocator()->MallocSingle() );
|
||||
++fCount;
|
||||
}
|
||||
|
||||
|
||||
template <class X>
|
||||
void G4CountedObject<X>::operator delete( void *pObj )
|
||||
void G4CountedObject<X>::Release()
|
||||
{
|
||||
aCountedObjectAllocator()->FreeSingle( (G4CountedObject<void>*)pObj );
|
||||
if(--fCount == 0)
|
||||
delete this;
|
||||
}
|
||||
|
||||
template <class X>
|
||||
void* G4CountedObject<X>::operator new(std::size_t)
|
||||
{
|
||||
if(aCountedObjectAllocator() == nullptr)
|
||||
aCountedObjectAllocator() = new G4Allocator<G4CountedObject<void>>;
|
||||
return ((void*) aCountedObjectAllocator()->MallocSingle());
|
||||
}
|
||||
|
||||
template <class X>
|
||||
void G4CountedObject<X>::operator delete(void* pObj)
|
||||
{
|
||||
aCountedObjectAllocator()->FreeSingle((G4CountedObject<void>*) pObj);
|
||||
}
|
||||
|
||||
// --------- G4ReferenceCountedHandle<X> Inline function definitions ---------
|
||||
|
||||
template <class X>
|
||||
G4ReferenceCountedHandle<X>::
|
||||
G4ReferenceCountedHandle( X* rep )
|
||||
: fObj( 0 )
|
||||
G4ReferenceCountedHandle<X>::G4ReferenceCountedHandle(X* rep)
|
||||
{
|
||||
if( rep != 0 )
|
||||
fObj = new G4CountedObject<X>( rep );
|
||||
if(rep != nullptr)
|
||||
fObj = new G4CountedObject<X>(rep);
|
||||
}
|
||||
|
||||
template <class X>
|
||||
G4ReferenceCountedHandle<X>::
|
||||
G4ReferenceCountedHandle( const G4ReferenceCountedHandle<X>& right )
|
||||
: fObj( right.fObj )
|
||||
G4ReferenceCountedHandle<X>::G4ReferenceCountedHandle(
|
||||
const G4ReferenceCountedHandle<X>& right)
|
||||
: fObj(right.fObj)
|
||||
{
|
||||
fObj->AddRef();
|
||||
fObj->AddRef();
|
||||
}
|
||||
|
||||
|
||||
template <class X>
|
||||
G4ReferenceCountedHandle<X>::~G4ReferenceCountedHandle()
|
||||
{
|
||||
if( fObj ) fObj->Release();
|
||||
if(fObj != nullptr)
|
||||
fObj->Release();
|
||||
}
|
||||
|
||||
|
||||
template <class X>
|
||||
G4ReferenceCountedHandle<X>& G4ReferenceCountedHandle<X>::
|
||||
operator =( const G4ReferenceCountedHandle<X>& right )
|
||||
G4ReferenceCountedHandle<X>& G4ReferenceCountedHandle<X>::operator=(
|
||||
const G4ReferenceCountedHandle<X>& right)
|
||||
{
|
||||
if( fObj != right.fObj )
|
||||
{
|
||||
if( fObj )
|
||||
fObj->Release();
|
||||
this->fObj = right.fObj;
|
||||
fObj->AddRef();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class X>
|
||||
G4ReferenceCountedHandle<X>& G4ReferenceCountedHandle<X>::
|
||||
operator =( X* objPtr )
|
||||
{
|
||||
if( fObj )
|
||||
if(fObj != right.fObj)
|
||||
{
|
||||
if(fObj != nullptr)
|
||||
fObj->Release();
|
||||
this->fObj = new G4CountedObject<X>( objPtr );
|
||||
return *this;
|
||||
this->fObj = right.fObj;
|
||||
fObj->AddRef();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template <class X>
|
||||
G4ReferenceCountedHandle<X>& G4ReferenceCountedHandle<X>::operator=(X* objPtr)
|
||||
{
|
||||
if(fObj != nullptr)
|
||||
fObj->Release();
|
||||
this->fObj = new G4CountedObject<X>(objPtr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class X>
|
||||
unsigned int G4ReferenceCountedHandle<X>::Count() const
|
||||
{
|
||||
return( fObj ? fObj->fCount : 0 );
|
||||
return ((fObj != nullptr) ? fObj->fCount : 0);
|
||||
}
|
||||
|
||||
|
||||
template <class X>
|
||||
X* G4ReferenceCountedHandle<X>::operator ->() const
|
||||
X* G4ReferenceCountedHandle<X>::operator->() const
|
||||
{
|
||||
return( fObj ? fObj->fRep : 0 );
|
||||
return ((fObj != nullptr) ? fObj->fRep : 0);
|
||||
}
|
||||
|
||||
|
||||
template <class X>
|
||||
G4bool G4ReferenceCountedHandle<X>::operator !() const
|
||||
G4bool G4ReferenceCountedHandle<X>::operator!() const
|
||||
{
|
||||
return( ( !fObj ) ? true : false );
|
||||
return ((fObj == nullptr) ? true : false);
|
||||
}
|
||||
|
||||
|
||||
template <class X>
|
||||
G4ReferenceCountedHandle<X>::operator bool() const
|
||||
{
|
||||
return( ( fObj ) ? true : false );
|
||||
}
|
||||
|
||||
template <class X>
|
||||
X* G4ReferenceCountedHandle<X>::operator ()() const
|
||||
{
|
||||
return( fObj ? fObj->fRep : 0 );
|
||||
}
|
||||
|
||||
template <class X>
|
||||
void* G4ReferenceCountedHandle<X>::operator new( size_t )
|
||||
{
|
||||
if (!aRCHAllocator())
|
||||
aRCHAllocator() = new G4Allocator<G4ReferenceCountedHandle<void> >;
|
||||
return( (void *)aRCHAllocator()->MallocSingle() );
|
||||
}
|
||||
|
||||
template <class X>
|
||||
void G4ReferenceCountedHandle<X>::operator delete( void *pObj )
|
||||
{
|
||||
aRCHAllocator()->FreeSingle( (G4ReferenceCountedHandle<void>*)pObj );
|
||||
return ((fObj != nullptr) ? true : false);
|
||||
}
|
||||
|
||||
#endif // _G4REFERENCECOUNTEDHANDLE_H_
|
||||
template <class X>
|
||||
X* G4ReferenceCountedHandle<X>::operator()() const
|
||||
{
|
||||
return ((fObj != nullptr) ? fObj->fRep : nullptr);
|
||||
}
|
||||
|
||||
template <class X>
|
||||
void* G4ReferenceCountedHandle<X>::operator new(std::size_t)
|
||||
{
|
||||
if(aRCHAllocator() == nullptr)
|
||||
aRCHAllocator() = new G4Allocator<G4ReferenceCountedHandle<void>>;
|
||||
return ((void*) aRCHAllocator()->MallocSingle());
|
||||
}
|
||||
|
||||
template <class X>
|
||||
void G4ReferenceCountedHandle<X>::operator delete(void* pObj)
|
||||
{
|
||||
aRCHAllocator()->FreeSingle((G4ReferenceCountedHandle<void>*) pObj);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,23 +23,18 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// G4RotationMatrix class, typedef to CLHEP HepRotation
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
// G4RotationMatrix, a typedef to CLHEP HepRotation
|
||||
|
||||
// Author: G.Cosmo (CERN), 1997
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4ROTATIONMATRIX_HH
|
||||
#define G4ROTATIONMATRIX_HH
|
||||
#define G4ROTATIONMATRIX_HH 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4ThreeVector.hh"
|
||||
#include "globals.hh"
|
||||
#include <CLHEP/Vector/Rotation.h>
|
||||
|
||||
typedef CLHEP::HepRotation G4RotationMatrix;
|
||||
typedef CLHEP::HepRep3x3 G4Rep3x3;
|
||||
using G4RotationMatrix = CLHEP::HepRotation;
|
||||
using G4Rep3x3 = CLHEP::HepRep3x3;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,113 +23,94 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4SIunits
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
// Description:
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// This file is a modified version of SystemOfUnits.h
|
||||
// It is provided for checking the overall 'units coherence' of the
|
||||
// Geant4 kernel.
|
||||
// -------
|
||||
// Warning: if you use it, do not forget to recompile the whole Geant4 kernel
|
||||
// -------
|
||||
// This file is a modified version of CLHEP SystemOfUnits.h
|
||||
// It is provided for checking the overall 'units coherence' in Geant4.
|
||||
// The basic units are those of the International System:
|
||||
//
|
||||
// meter
|
||||
// second
|
||||
// kilogram
|
||||
// ampere
|
||||
// degree kelvin
|
||||
// meter
|
||||
// second
|
||||
// kilogram
|
||||
// ampere
|
||||
// degree kelvin
|
||||
// the amount of substance (mole)
|
||||
// luminous intensity (candela)
|
||||
// radian
|
||||
// steradian
|
||||
//
|
||||
// radian
|
||||
// steradian
|
||||
//
|
||||
// The SI numerical value of the positron charge is defined here,
|
||||
// as it is needed for conversion factor : positron charge = e_SI (coulomb)
|
||||
//
|
||||
// The others physical constants are defined in the header file :
|
||||
// PhysicalConstants.h
|
||||
// as it is needed for conversion factor: positron charge = e_SI (coulomb)
|
||||
//
|
||||
// The others physical constants are defined in the CLHEP header file
|
||||
// for PhysicalConstants.
|
||||
|
||||
// Authors: M.Maire, S.Giani
|
||||
//
|
||||
// History:
|
||||
//
|
||||
// 10.03.99 created
|
||||
// 01.03.01 parsec
|
||||
// 11.06.15 upgrate. Equivalent to SystemOfUnits.h
|
||||
// 08.08.15 add decimeter, liter (mma)
|
||||
// 12.01.16 added symbols for microsecond (us) and picosecond (ps) (mma)
|
||||
|
||||
// Authors: M.Maire, S.Giani - 10.03.1999
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef SI_SYSTEM_OF_UNITS_HH
|
||||
#define SI_SYSTEM_OF_UNITS_HH
|
||||
#define SI_SYSTEM_OF_UNITS_HH 1
|
||||
|
||||
static constexpr double pi = 3.14159265358979323846;
|
||||
static constexpr double twopi = 2 * pi;
|
||||
static constexpr double halfpi = pi / 2;
|
||||
static constexpr double pi2 = pi * pi;
|
||||
//
|
||||
//
|
||||
//
|
||||
static constexpr double pi = 3.14159265358979323846;
|
||||
static constexpr double twopi = 2*pi;
|
||||
static constexpr double halfpi = pi/2;
|
||||
static constexpr double pi2 = pi*pi;
|
||||
//
|
||||
// Length [L]
|
||||
//
|
||||
static constexpr double meter = 1.;
|
||||
static constexpr double meter2 = meter*meter;
|
||||
static constexpr double meter3 = meter*meter*meter;
|
||||
static constexpr double meter = 1.;
|
||||
static constexpr double meter2 = meter * meter;
|
||||
static constexpr double meter3 = meter * meter * meter;
|
||||
|
||||
static constexpr double millimeter = 0.001*meter;
|
||||
static constexpr double millimeter2 = millimeter*millimeter;
|
||||
static constexpr double millimeter3 = millimeter*millimeter*millimeter;
|
||||
static constexpr double millimeter = 0.001 * meter;
|
||||
static constexpr double millimeter2 = millimeter * millimeter;
|
||||
static constexpr double millimeter3 = millimeter * millimeter * millimeter;
|
||||
|
||||
static constexpr double centimeter = 10.*millimeter;
|
||||
static constexpr double centimeter2 = centimeter*centimeter;
|
||||
static constexpr double centimeter3 = centimeter*centimeter*centimeter;
|
||||
|
||||
static constexpr double kilometer = 1000.*meter;
|
||||
static constexpr double kilometer2 = kilometer*kilometer;
|
||||
static constexpr double kilometer3 = kilometer*kilometer*kilometer;
|
||||
static constexpr double centimeter = 10. * millimeter;
|
||||
static constexpr double centimeter2 = centimeter * centimeter;
|
||||
static constexpr double centimeter3 = centimeter * centimeter * centimeter;
|
||||
|
||||
static constexpr double parsec = 3.0856775807e+16*meter;
|
||||
static constexpr double kilometer = 1000. * meter;
|
||||
static constexpr double kilometer2 = kilometer * kilometer;
|
||||
static constexpr double kilometer3 = kilometer * kilometer * kilometer;
|
||||
|
||||
static constexpr double micrometer = 1.e-6 *meter;
|
||||
static constexpr double nanometer = 1.e-9 *meter;
|
||||
static constexpr double angstrom = 1.e-10*meter;
|
||||
static constexpr double fermi = 1.e-15*meter;
|
||||
static constexpr double parsec = 3.0856775807e+16 * meter;
|
||||
|
||||
static constexpr double barn = 1.e-28*meter2;
|
||||
static constexpr double millibarn = 1.e-3 *barn;
|
||||
static constexpr double microbarn = 1.e-6 *barn;
|
||||
static constexpr double nanobarn = 1.e-9 *barn;
|
||||
static constexpr double picobarn = 1.e-12*barn;
|
||||
static constexpr double micrometer = 1.e-6 * meter;
|
||||
static constexpr double nanometer = 1.e-9 * meter;
|
||||
static constexpr double angstrom = 1.e-10 * meter;
|
||||
static constexpr double fermi = 1.e-15 * meter;
|
||||
|
||||
static constexpr double barn = 1.e-28 * meter2;
|
||||
static constexpr double millibarn = 1.e-3 * barn;
|
||||
static constexpr double microbarn = 1.e-6 * barn;
|
||||
static constexpr double nanobarn = 1.e-9 * barn;
|
||||
static constexpr double picobarn = 1.e-12 * barn;
|
||||
|
||||
// symbols
|
||||
static constexpr double nm = nanometer;
|
||||
static constexpr double um = micrometer;
|
||||
static constexpr double nm = nanometer;
|
||||
static constexpr double um = micrometer;
|
||||
|
||||
static constexpr double mm = millimeter;
|
||||
static constexpr double mm = millimeter;
|
||||
static constexpr double mm2 = millimeter2;
|
||||
static constexpr double mm3 = millimeter3;
|
||||
|
||||
static constexpr double cm = centimeter;
|
||||
static constexpr double cm = centimeter;
|
||||
static constexpr double cm2 = centimeter2;
|
||||
static constexpr double cm3 = centimeter3;
|
||||
|
||||
static constexpr double liter = 1.e+3*cm3;
|
||||
static constexpr double L = liter;
|
||||
static constexpr double dL = 1.e-1*liter;
|
||||
static constexpr double cL = 1.e-2*liter;
|
||||
static constexpr double mL = 1.e-3*liter;
|
||||
|
||||
static constexpr double m = meter;
|
||||
static constexpr double liter = 1.e+3 * cm3;
|
||||
static constexpr double L = liter;
|
||||
static constexpr double dL = 1.e-1 * liter;
|
||||
static constexpr double cL = 1.e-2 * liter;
|
||||
static constexpr double mL = 1.e-3 * liter;
|
||||
|
||||
static constexpr double m = meter;
|
||||
static constexpr double m2 = meter2;
|
||||
static constexpr double m3 = meter3;
|
||||
|
||||
static constexpr double km = kilometer;
|
||||
static constexpr double km = kilometer;
|
||||
static constexpr double km2 = kilometer2;
|
||||
static constexpr double km3 = kilometer3;
|
||||
|
||||
@@ -138,14 +119,14 @@ static constexpr double pc = parsec;
|
||||
//
|
||||
// Angle
|
||||
//
|
||||
static constexpr double radian = 1.;
|
||||
static constexpr double milliradian = 1.e-3*radian;
|
||||
static constexpr double degree = (pi/180.0)*radian;
|
||||
static constexpr double radian = 1.;
|
||||
static constexpr double milliradian = 1.e-3 * radian;
|
||||
static constexpr double degree = (pi / 180.0) * radian;
|
||||
|
||||
static constexpr double steradian = 1.;
|
||||
|
||||
static constexpr double steradian = 1.;
|
||||
|
||||
// symbols
|
||||
static constexpr double rad = radian;
|
||||
static constexpr double rad = radian;
|
||||
static constexpr double mrad = milliradian;
|
||||
static constexpr double sr = steradian;
|
||||
static constexpr double deg = degree;
|
||||
@@ -154,18 +135,18 @@ static constexpr double deg = degree;
|
||||
// Time [T]
|
||||
//
|
||||
static constexpr double second = 1.;
|
||||
static constexpr double nanosecond = 1.e-9 *second;
|
||||
static constexpr double millisecond = 1.e-3 *second;
|
||||
static constexpr double microsecond = 1.e-6 *second;
|
||||
static constexpr double picosecond = 1.e-12*second;
|
||||
static constexpr double nanosecond = 1.e-9 * second;
|
||||
static constexpr double millisecond = 1.e-3 * second;
|
||||
static constexpr double microsecond = 1.e-6 * second;
|
||||
static constexpr double picosecond = 1.e-12 * second;
|
||||
|
||||
static constexpr double hertz = 1./second;
|
||||
static constexpr double kilohertz = 1.e+3*hertz;
|
||||
static constexpr double megahertz = 1.e+6*hertz;
|
||||
static constexpr double hertz = 1. / second;
|
||||
static constexpr double kilohertz = 1.e+3 * hertz;
|
||||
static constexpr double megahertz = 1.e+6 * hertz;
|
||||
|
||||
// symbols
|
||||
static constexpr double ns = nanosecond;
|
||||
static constexpr double s = second;
|
||||
static constexpr double ns = nanosecond;
|
||||
static constexpr double s = second;
|
||||
static constexpr double ms = millisecond;
|
||||
static constexpr double us = microsecond;
|
||||
static constexpr double ps = picosecond;
|
||||
@@ -173,45 +154,45 @@ static constexpr double ps = picosecond;
|
||||
//
|
||||
// Mass [E][T^2][L^-2]
|
||||
//
|
||||
static constexpr double kilogram = 1.;
|
||||
static constexpr double gram = 1.e-3*kilogram;
|
||||
static constexpr double milligram = 1.e-3*gram;
|
||||
static constexpr double kilogram = 1.;
|
||||
static constexpr double gram = 1.e-3 * kilogram;
|
||||
static constexpr double milligram = 1.e-3 * gram;
|
||||
|
||||
// symbols
|
||||
static constexpr double kg = kilogram;
|
||||
static constexpr double g = gram;
|
||||
static constexpr double mg = milligram;
|
||||
static constexpr double kg = kilogram;
|
||||
static constexpr double g = gram;
|
||||
static constexpr double mg = milligram;
|
||||
|
||||
//
|
||||
// Electric current [Q][T^-1]
|
||||
//
|
||||
static constexpr double ampere = 1.;
|
||||
static constexpr double milliampere = 1.e-3*ampere;
|
||||
static constexpr double microampere = 1.e-6*ampere;
|
||||
static constexpr double nanoampere = 1.e-9*ampere;
|
||||
static constexpr double ampere = 1.;
|
||||
static constexpr double milliampere = 1.e-3 * ampere;
|
||||
static constexpr double microampere = 1.e-6 * ampere;
|
||||
static constexpr double nanoampere = 1.e-9 * ampere;
|
||||
|
||||
//
|
||||
// Electric charge [Q]
|
||||
//
|
||||
static constexpr double coulomb = ampere*second;
|
||||
static constexpr double e_SI = 1.602176487e-19; // positron charge in coulomb
|
||||
static constexpr double eplus = e_SI*coulomb ; // positron charge
|
||||
static constexpr double coulomb = ampere * second;
|
||||
static constexpr double e_SI = 1.602176487e-19; // positron charge in coulomb
|
||||
static constexpr double eplus = e_SI * coulomb; // positron charge
|
||||
|
||||
//
|
||||
// Energy [E]
|
||||
//
|
||||
static constexpr double joule = kg*m*m/(s*s);
|
||||
static constexpr double joule = kg * m * m / (s * s);
|
||||
|
||||
static constexpr double electronvolt = e_SI*joule;
|
||||
static constexpr double kiloelectronvolt = 1.e+3*electronvolt;
|
||||
static constexpr double megaelectronvolt = 1.e+6*electronvolt;
|
||||
static constexpr double gigaelectronvolt = 1.e+9*electronvolt;
|
||||
static constexpr double teraelectronvolt = 1.e+12*electronvolt;
|
||||
static constexpr double petaelectronvolt = 1.e+15*electronvolt;
|
||||
static constexpr double electronvolt = e_SI * joule;
|
||||
static constexpr double kiloelectronvolt = 1.e+3 * electronvolt;
|
||||
static constexpr double megaelectronvolt = 1.e+6 * electronvolt;
|
||||
static constexpr double gigaelectronvolt = 1.e+9 * electronvolt;
|
||||
static constexpr double teraelectronvolt = 1.e+12 * electronvolt;
|
||||
static constexpr double petaelectronvolt = 1.e+15 * electronvolt;
|
||||
|
||||
// symbols
|
||||
static constexpr double MeV = megaelectronvolt;
|
||||
static constexpr double eV = electronvolt;
|
||||
static constexpr double eV = electronvolt;
|
||||
static constexpr double keV = kiloelectronvolt;
|
||||
static constexpr double GeV = gigaelectronvolt;
|
||||
static constexpr double TeV = teraelectronvolt;
|
||||
@@ -220,59 +201,66 @@ static constexpr double PeV = petaelectronvolt;
|
||||
//
|
||||
// Power [E][T^-1]
|
||||
//
|
||||
static constexpr double watt = joule/second; // watt = 6.24150 e+3 * MeV/ns
|
||||
static constexpr double watt = joule / second; // watt = 6.24150 e+3 * MeV/ns
|
||||
|
||||
//
|
||||
// Force [E][L^-1]
|
||||
//
|
||||
static constexpr double newton = joule/meter; // newton = 6.24150 e+9 * MeV/mm
|
||||
static constexpr double newton =
|
||||
joule / meter; // newton = 6.24150 e+9 * MeV/mm
|
||||
|
||||
//
|
||||
// Pressure [E][L^-3]
|
||||
//
|
||||
#define pascal hep_pascal // a trick to avoid warnings
|
||||
static constexpr double hep_pascal = newton/m2; // pascal = 6.24150 e+3 * MeV/mm3
|
||||
static constexpr double bar = 100000*pascal; // bar = 6.24150 e+8 * MeV/mm3
|
||||
static constexpr double atmosphere = 101325*pascal; // atm = 6.32420 e+8 * MeV/mm3
|
||||
#define pascal hep_pascal // a trick to avoid warnings
|
||||
static constexpr double hep_pascal =
|
||||
newton / m2; // pascal = 6.24150 e+3 * MeV/mm3
|
||||
static constexpr double bar = 100000 * pascal; // bar = 6.24150 e+8 * MeV/mm3
|
||||
static constexpr double atmosphere =
|
||||
101325 * pascal; // atm = 6.32420 e+8 * MeV/mm3
|
||||
|
||||
//
|
||||
// Electric potential [E][Q^-1]
|
||||
//
|
||||
static constexpr double megavolt = megaelectronvolt/eplus;
|
||||
static constexpr double kilovolt = 1.e-3*megavolt;
|
||||
static constexpr double volt = 1.e-6*megavolt;
|
||||
static constexpr double megavolt = megaelectronvolt / eplus;
|
||||
static constexpr double kilovolt = 1.e-3 * megavolt;
|
||||
static constexpr double volt = 1.e-6 * megavolt;
|
||||
|
||||
//
|
||||
// Electric resistance [E][T][Q^-2]
|
||||
//
|
||||
static constexpr double ohm = volt/ampere; // ohm = 1.60217e-16*(MeV/eplus)/(eplus/ns)
|
||||
static constexpr double ohm =
|
||||
volt / ampere; // ohm = 1.60217e-16*(MeV/eplus)/(eplus/ns)
|
||||
|
||||
//
|
||||
// Electric capacitance [Q^2][E^-1]
|
||||
//
|
||||
static constexpr double farad = coulomb/volt; // farad = 6.24150e+24 * eplus/Megavolt
|
||||
static constexpr double millifarad = 1.e-3*farad;
|
||||
static constexpr double microfarad = 1.e-6*farad;
|
||||
static constexpr double nanofarad = 1.e-9*farad;
|
||||
static constexpr double picofarad = 1.e-12*farad;
|
||||
static constexpr double farad =
|
||||
coulomb / volt; // farad = 6.24150e+24 * eplus/Megavolt
|
||||
static constexpr double millifarad = 1.e-3 * farad;
|
||||
static constexpr double microfarad = 1.e-6 * farad;
|
||||
static constexpr double nanofarad = 1.e-9 * farad;
|
||||
static constexpr double picofarad = 1.e-12 * farad;
|
||||
|
||||
//
|
||||
// Magnetic Flux [T][E][Q^-1]
|
||||
//
|
||||
static constexpr double weber = volt*second; // weber = 1000*megavolt*ns
|
||||
static constexpr double weber = volt * second; // weber = 1000*megavolt*ns
|
||||
|
||||
//
|
||||
// Magnetic Field [T][E][Q^-1][L^-2]
|
||||
//
|
||||
static constexpr double tesla = volt*second/meter2; // tesla =0.001*megavolt*ns/mm2
|
||||
static constexpr double tesla =
|
||||
volt * second / meter2; // tesla =0.001*megavolt*ns/mm2
|
||||
|
||||
static constexpr double gauss = 1.e-4*tesla;
|
||||
static constexpr double kilogauss = 1.e-1*tesla;
|
||||
static constexpr double gauss = 1.e-4 * tesla;
|
||||
static constexpr double kilogauss = 1.e-1 * tesla;
|
||||
|
||||
//
|
||||
// Inductance [T^2][E][Q^-2]
|
||||
//
|
||||
static constexpr double henry = weber/ampere; // henry = 1.60217e-7*MeV*(ns/eplus)**2
|
||||
static constexpr double henry =
|
||||
weber / ampere; // henry = 1.60217e-7*MeV*(ns/eplus)**2
|
||||
|
||||
//
|
||||
// Temperature
|
||||
@@ -287,28 +275,28 @@ static constexpr double mole = 1.;
|
||||
//
|
||||
// Activity [T^-1]
|
||||
//
|
||||
static constexpr double becquerel = 1./second ;
|
||||
static constexpr double curie = 3.7e+10 * becquerel;
|
||||
static constexpr double kilobecquerel = 1.e+3*becquerel;
|
||||
static constexpr double megabecquerel = 1.e+6*becquerel;
|
||||
static constexpr double gigabecquerel = 1.e+9*becquerel;
|
||||
static constexpr double millicurie = 1.e-3*curie;
|
||||
static constexpr double microcurie = 1.e-6*curie;
|
||||
static constexpr double Bq = becquerel;
|
||||
static constexpr double kBq = kilobecquerel;
|
||||
static constexpr double MBq = megabecquerel;
|
||||
static constexpr double GBq = gigabecquerel;
|
||||
static constexpr double Ci = curie;
|
||||
static constexpr double mCi = millicurie;
|
||||
static constexpr double uCi = microcurie;
|
||||
static constexpr double becquerel = 1. / second;
|
||||
static constexpr double curie = 3.7e+10 * becquerel;
|
||||
static constexpr double kilobecquerel = 1.e+3 * becquerel;
|
||||
static constexpr double megabecquerel = 1.e+6 * becquerel;
|
||||
static constexpr double gigabecquerel = 1.e+9 * becquerel;
|
||||
static constexpr double millicurie = 1.e-3 * curie;
|
||||
static constexpr double microcurie = 1.e-6 * curie;
|
||||
static constexpr double Bq = becquerel;
|
||||
static constexpr double kBq = kilobecquerel;
|
||||
static constexpr double MBq = megabecquerel;
|
||||
static constexpr double GBq = gigabecquerel;
|
||||
static constexpr double Ci = curie;
|
||||
static constexpr double mCi = millicurie;
|
||||
static constexpr double uCi = microcurie;
|
||||
|
||||
//
|
||||
// Absorbed dose [L^2][T^-2]
|
||||
//
|
||||
static constexpr double gray = joule/kilogram;
|
||||
static constexpr double kilogray = 1.e+3*gray;
|
||||
static constexpr double milligray = 1.e-3*gray;
|
||||
static constexpr double microgray = 1.e-6*gray;
|
||||
static constexpr double gray = joule / kilogram;
|
||||
static constexpr double kilogray = 1.e+3 * gray;
|
||||
static constexpr double milligray = 1.e-3 * gray;
|
||||
static constexpr double microgray = 1.e-6 * gray;
|
||||
|
||||
//
|
||||
// Luminous intensity [I]
|
||||
@@ -318,19 +306,18 @@ static constexpr double candela = 1.;
|
||||
//
|
||||
// Luminous flux [I]
|
||||
//
|
||||
static constexpr double lumen = candela*steradian;
|
||||
static constexpr double lumen = candela * steradian;
|
||||
|
||||
//
|
||||
// Illuminance [I][L^-2]
|
||||
//
|
||||
static constexpr double lux = lumen/meter2;
|
||||
static constexpr double lux = lumen / meter2;
|
||||
|
||||
//
|
||||
// Miscellaneous
|
||||
//
|
||||
static constexpr double perCent = 0.01 ;
|
||||
static constexpr double perCent = 0.01;
|
||||
static constexpr double perThousand = 0.001;
|
||||
static constexpr double perMillion = 0.000001;
|
||||
|
||||
|
||||
#endif /* SI_SYSTEM_OF_UNITS_HH */
|
||||
#endif
|
||||
|
||||
@@ -23,11 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
// Class G4SliceTimer
|
||||
// G4SliceTimer
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
@@ -37,99 +33,80 @@
|
||||
// Note: Uses <sys/times.h> & <unistd.h> - POSIX.1 defined
|
||||
// If used, this header must be included in the source (.cc) file
|
||||
// and it must be the first header file to be included!
|
||||
//
|
||||
// Member functions:
|
||||
//
|
||||
// G4SliceTimer()
|
||||
// Construct a timer object
|
||||
// Start()
|
||||
// Start timing
|
||||
// Stop()
|
||||
// Stop timing
|
||||
// Clear()
|
||||
// Clear accumulated times
|
||||
// G4bool IsValid()
|
||||
// Return true if have a valid time (ie start() and stop() called)
|
||||
// G4double GetRealElapsed()
|
||||
// Return the elapsed real time between last calling start() and stop()
|
||||
// G4double GetSystemElapsed()
|
||||
// Return the elapsed system time between last calling start() and stop()
|
||||
// G4double GetUserElapsed()
|
||||
// Return the elapsed user time between last calling start() and stop()
|
||||
//
|
||||
// Operators:
|
||||
//
|
||||
// std::ostream& operator << (std::ostream& os, const G4SliceTimer& t);
|
||||
// Print the elapsed real,system and usertimes on os. Prints **s for times
|
||||
// if !IsValid
|
||||
//
|
||||
// Member data:
|
||||
//
|
||||
// G4bool fValidTimes
|
||||
// True after start and stop have both been called more than once and
|
||||
// an equal number of times
|
||||
// clock_t fStartRealTime,fEndRealTime
|
||||
// Real times (arbitrary time 0)
|
||||
// tms fStartTimes,fEndTimes
|
||||
// Timing structures (see times(2)) for start and end times
|
||||
|
||||
// History:
|
||||
// 23.10.06 - M.Asai - Derived from G4Timer implementation
|
||||
// ----------------------------------------------------------------------
|
||||
// Author: M.Asai, 23.10.06 - Derived from G4Timer implementation
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4SLICE_TIMER_HH
|
||||
#define G4SLICE_TIMER_HH
|
||||
#define G4SLICE_TIMER_HH 1
|
||||
|
||||
#ifndef WIN32
|
||||
# include <unistd.h>
|
||||
# include <sys/times.h>
|
||||
# include <unistd.h>
|
||||
#else
|
||||
# include <time.h>
|
||||
# define _SC_CLK_TCK 1
|
||||
# define _SC_CLK_TCK 1
|
||||
|
||||
extern "C" {
|
||||
int sysconf(int);
|
||||
};
|
||||
extern "C"
|
||||
{
|
||||
int sysconf(int);
|
||||
};
|
||||
|
||||
// Structure returned by times()
|
||||
|
||||
struct tms {
|
||||
clock_t tms_utime; /* user time */
|
||||
clock_t tms_stime; /* system time */
|
||||
clock_t tms_cutime; /* user time, children */
|
||||
clock_t tms_cstime; /* system time, children */
|
||||
};
|
||||
// Structure returned by times()
|
||||
//
|
||||
struct tms
|
||||
{
|
||||
clock_t tms_utime; /* user time */
|
||||
clock_t tms_stime; /* system time */
|
||||
clock_t tms_cutime; /* user time, children */
|
||||
clock_t tms_cstime; /* system time, children */
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
extern clock_t times(struct tms *);
|
||||
};
|
||||
#endif /* WIN32 */
|
||||
extern "C"
|
||||
{
|
||||
extern clock_t times(struct tms*);
|
||||
};
|
||||
#endif /* WIN32 */
|
||||
|
||||
#include "G4Types.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
class G4SliceTimer
|
||||
{
|
||||
public:
|
||||
public:
|
||||
G4SliceTimer();
|
||||
// Construct a timer object
|
||||
|
||||
G4SliceTimer();
|
||||
inline void Start();
|
||||
// Start timing
|
||||
inline void Stop();
|
||||
// Stop timing
|
||||
inline void Clear();
|
||||
// Clear accumulated times
|
||||
inline G4bool IsValid() const;
|
||||
// Return true if have a valid time (ie start() and stop() called)
|
||||
G4double GetRealElapsed() const;
|
||||
// Return the elapsed real time between last calling start() and stop()
|
||||
G4double GetSystemElapsed() const;
|
||||
// Return the elapsed system time between last calling start() and stop()
|
||||
G4double GetUserElapsed() const;
|
||||
// Return the elapsed user time between last calling start() and stop()
|
||||
|
||||
inline void Start();
|
||||
inline void Stop();
|
||||
inline void Clear();
|
||||
inline G4bool IsValid() const;
|
||||
G4double GetRealElapsed() const;
|
||||
G4double GetSystemElapsed() const;
|
||||
G4double GetUserElapsed() const;
|
||||
private:
|
||||
clock_t fStartRealTime, fEndRealTime;
|
||||
// Real times (arbitrary time 0)
|
||||
tms fStartTimes, fEndTimes;
|
||||
// Timing structures (see times(2)) for start and end times
|
||||
|
||||
private:
|
||||
G4double fRealElapsed = 0.0, fSystemElapsed = 0.0, fUserElapsed = 0.0;
|
||||
|
||||
G4bool fValidTimes;
|
||||
clock_t fStartRealTime,fEndRealTime;
|
||||
tms fStartTimes,fEndTimes;
|
||||
G4double fRealElapsed,fSystemElapsed,fUserElapsed;
|
||||
G4bool fValidTimes = true;
|
||||
// True after start and stop have both been called more than once and
|
||||
// an equal number of times
|
||||
};
|
||||
|
||||
std::ostream& operator << (std::ostream& os, const G4SliceTimer& t);
|
||||
std::ostream& operator<<(std::ostream& os, const G4SliceTimer& t);
|
||||
// Print the elapsed real,system and usertimes on os. Prints **s for times
|
||||
// if !IsValid
|
||||
|
||||
#include "G4SliceTimer.icc"
|
||||
|
||||
|
||||
@@ -23,40 +23,31 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4SliceTimer inline methods implementation
|
||||
//
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class inline implementation
|
||||
// ------------------------------------------------------------
|
||||
// Author: M.Asai, 23.10.06 - Derived from G4Timer implementation
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline
|
||||
void G4SliceTimer::Start()
|
||||
inline void G4SliceTimer::Start()
|
||||
{
|
||||
fValidTimes=false;
|
||||
fStartRealTime=times(&fStartTimes);
|
||||
fValidTimes = false;
|
||||
fStartRealTime = times(&fStartTimes);
|
||||
}
|
||||
|
||||
inline
|
||||
void G4SliceTimer::Stop()
|
||||
inline void G4SliceTimer::Stop()
|
||||
{
|
||||
fEndRealTime=times(&fEndTimes);
|
||||
fRealElapsed += fEndRealTime-fStartRealTime;
|
||||
fSystemElapsed += fEndTimes.tms_stime-fStartTimes.tms_stime;
|
||||
fUserElapsed += fEndTimes.tms_utime-fStartTimes.tms_utime;
|
||||
fValidTimes=true;
|
||||
fEndRealTime = times(&fEndTimes);
|
||||
fRealElapsed += fEndRealTime - fStartRealTime;
|
||||
fSystemElapsed += fEndTimes.tms_stime - fStartTimes.tms_stime;
|
||||
fUserElapsed += fEndTimes.tms_utime - fStartTimes.tms_utime;
|
||||
fValidTimes = true;
|
||||
}
|
||||
|
||||
inline
|
||||
void G4SliceTimer::Clear()
|
||||
inline void G4SliceTimer::Clear()
|
||||
{
|
||||
fRealElapsed = 0.;
|
||||
fRealElapsed = 0.;
|
||||
fSystemElapsed = 0.;
|
||||
fUserElapsed = 0.;
|
||||
fUserElapsed = 0.;
|
||||
}
|
||||
|
||||
inline
|
||||
G4bool G4SliceTimer::IsValid() const
|
||||
{
|
||||
return fValidTimes;
|
||||
}
|
||||
inline G4bool G4SliceTimer::IsValid() const { return fValidTimes; }
|
||||
|
||||
@@ -23,20 +23,9 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4StateManager
|
||||
//
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
//
|
||||
// ---------------- G4StateManager ----------------
|
||||
//
|
||||
// Authors: G.Cosmo, M.Asai - November 1996
|
||||
//
|
||||
// -------------------------------------------------------------
|
||||
//
|
||||
// Class Description:
|
||||
// Class description:
|
||||
//
|
||||
// Class responsible for handling and updating the running state
|
||||
// of the Geant4 application during its different phases.
|
||||
@@ -45,84 +34,81 @@
|
||||
//
|
||||
// States of Geant4 are defined in G4ApplicationState.
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// Authors: G.Cosmo, M.Asai - November 1996
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4StateManager_hh
|
||||
#define G4StateManager_hh 1
|
||||
|
||||
#ifndef G4StateManager_h
|
||||
#define G4StateManager_h 1
|
||||
|
||||
#include <vector>
|
||||
#include "G4Types.hh"
|
||||
#include "G4String.hh"
|
||||
#include "G4ApplicationState.hh"
|
||||
#include "G4VStateDependent.hh"
|
||||
#include "G4String.hh"
|
||||
#include "G4Types.hh"
|
||||
#include "G4VExceptionHandler.hh"
|
||||
#include "G4VStateDependent.hh"
|
||||
#include <vector>
|
||||
|
||||
class G4StateManager
|
||||
{
|
||||
public:
|
||||
static G4StateManager* GetStateManager();
|
||||
// The G4StateManager class is a singleton class and the pointer
|
||||
// to the only one existing object can be obtained by this static
|
||||
// method.
|
||||
|
||||
public: // with description
|
||||
~G4StateManager();
|
||||
|
||||
static G4StateManager* GetStateManager();
|
||||
// The G4StateManager class is a singleton class and the pointer
|
||||
// to the only one existing object can be obtained by this static
|
||||
// method.
|
||||
G4StateManager(const G4StateManager&) = delete;
|
||||
G4StateManager& operator=(const G4StateManager&) = delete;
|
||||
G4bool operator==(const G4StateManager&) const = delete;
|
||||
G4bool operator!=(const G4StateManager&) const = delete;
|
||||
|
||||
~G4StateManager();
|
||||
const G4ApplicationState& GetCurrentState() const;
|
||||
// Returns the current state
|
||||
const G4ApplicationState& GetPreviousState() const;
|
||||
// Returns the previous state
|
||||
G4bool SetNewState(const G4ApplicationState& requestedState);
|
||||
// Set Geant4 to a new state.
|
||||
// In case the request is illegal, false will be returned
|
||||
// and the state of Geant4 will not be changed
|
||||
G4bool SetNewState(const G4ApplicationState& requestedState, const char* msg);
|
||||
// Set Geant4 to a new state.
|
||||
// In case the request is illegal, false will be returned
|
||||
// and the state of Geant4 will not be changed.
|
||||
// "msg" is the information associated to the state change
|
||||
G4bool RegisterDependent(G4VStateDependent* aDependent,
|
||||
G4bool bottom = false);
|
||||
// Register a concrete class of G4VStateDependent.
|
||||
// Registered concrete classes will be notified via
|
||||
// G4VStateDependent::Notify() method when the state of Geant4 changes.
|
||||
// False will be returned if registration fails
|
||||
G4bool DeregisterDependent(G4VStateDependent* aDependent);
|
||||
// Remove the registration.
|
||||
// False will be returned if aDependent has not been registered
|
||||
G4VStateDependent* RemoveDependent(const G4VStateDependent* aDependent);
|
||||
// Remove the registration.
|
||||
// Removed pointer is returned
|
||||
G4String GetStateString(const G4ApplicationState& aState) const;
|
||||
// Utility method which returns a string of the state name
|
||||
|
||||
const G4ApplicationState& GetCurrentState() const;
|
||||
// Returns the current state
|
||||
const G4ApplicationState& GetPreviousState() const;
|
||||
// Returns the previous state
|
||||
G4bool SetNewState(const G4ApplicationState& requestedState);
|
||||
// Set Geant4 to a new state.
|
||||
// In case the request is irregal, false will be returned
|
||||
// and the state of Geant4 will not be changed.
|
||||
G4bool SetNewState(const G4ApplicationState& requestedState,
|
||||
const char* msg);
|
||||
// Set Geant4 to a new state.
|
||||
// In case the request is irregal, false will be returned
|
||||
// and the state of Geant4 will not be changed.
|
||||
// "msg" is information associating to this state change
|
||||
G4bool RegisterDependent(G4VStateDependent* aDependent,G4bool bottom=false);
|
||||
// Register a concrete class of G4VStateDependent.
|
||||
// Registered concrete classes will be notified via
|
||||
// G4VStateDependent::Notify() method when the state of Geant4 changes.
|
||||
// False will be returned if registration fails.
|
||||
G4bool DeregisterDependent(G4VStateDependent* aDependent);
|
||||
// Remove the registration.
|
||||
// False will be returned if aDependent has not been registered.
|
||||
G4VStateDependent* RemoveDependent(const G4VStateDependent* aDependent);
|
||||
// Remove the registration.
|
||||
// Removed pointer is returned.
|
||||
G4String GetStateString(const G4ApplicationState& aState) const;
|
||||
// Utility method which returns a string of the state name.
|
||||
inline void SetSuppressAbortion(G4int i);
|
||||
inline G4int GetSuppressAbortion() const;
|
||||
inline const char* GetMessage() const;
|
||||
inline void SetExceptionHandler(G4VExceptionHandler* eh);
|
||||
inline G4VExceptionHandler* GetExceptionHandler() const;
|
||||
static void SetVerboseLevel(G4int val);
|
||||
|
||||
inline void SetSuppressAbortion(G4int i);
|
||||
inline G4int GetSuppressAbortion() const;
|
||||
inline const char* GetMessage() const;
|
||||
inline void SetExceptionHandler(G4VExceptionHandler* eh);
|
||||
inline G4VExceptionHandler* GetExceptionHandler() const;
|
||||
static void SetVerboseLevel(G4int val);
|
||||
private:
|
||||
G4StateManager();
|
||||
|
||||
private:
|
||||
|
||||
G4StateManager();
|
||||
G4StateManager(const G4StateManager &right);
|
||||
G4StateManager& operator=(const G4StateManager &right);
|
||||
G4bool operator==(const G4StateManager &right) const;
|
||||
G4bool operator!=(const G4StateManager &right) const;
|
||||
|
||||
private:
|
||||
|
||||
static G4ThreadLocal G4StateManager* theStateManager;
|
||||
G4ApplicationState theCurrentState;
|
||||
G4ApplicationState thePreviousState;
|
||||
std::vector<G4VStateDependent*> theDependentsList;
|
||||
G4VStateDependent* theBottomDependent;
|
||||
G4int suppressAbortion;
|
||||
const char* msgptr;
|
||||
G4VExceptionHandler* exceptionHandler;
|
||||
static G4int verboseLevel;
|
||||
private:
|
||||
static G4ThreadLocal G4StateManager* theStateManager;
|
||||
G4ApplicationState theCurrentState = G4State_PreInit;
|
||||
G4ApplicationState thePreviousState = G4State_PreInit;
|
||||
std::vector<G4VStateDependent*> theDependentsList;
|
||||
G4VStateDependent* theBottomDependent = nullptr;
|
||||
G4int suppressAbortion = 0;
|
||||
const char* msgptr = nullptr;
|
||||
G4VExceptionHandler* exceptionHandler = nullptr;
|
||||
static G4int verboseLevel;
|
||||
};
|
||||
|
||||
#include "G4StateManager.icc"
|
||||
|
||||
@@ -23,39 +23,29 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4StateManager inline methods implementation
|
||||
//
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class inline implementation
|
||||
// ------------------------------------------------------------
|
||||
// Authors: G.Cosmo, M.Asai - November 1996
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline
|
||||
void G4StateManager::SetSuppressAbortion(G4int i)
|
||||
inline void G4StateManager::SetSuppressAbortion(G4int i)
|
||||
{
|
||||
suppressAbortion = i;
|
||||
}
|
||||
|
||||
inline
|
||||
G4int G4StateManager::GetSuppressAbortion() const
|
||||
inline G4int G4StateManager::GetSuppressAbortion() const
|
||||
{
|
||||
return suppressAbortion;
|
||||
}
|
||||
|
||||
inline
|
||||
const char* G4StateManager::GetMessage() const
|
||||
{
|
||||
return msgptr;
|
||||
}
|
||||
inline const char* G4StateManager::GetMessage() const { return msgptr; }
|
||||
|
||||
inline
|
||||
void G4StateManager::SetExceptionHandler(G4VExceptionHandler* eh)
|
||||
inline void G4StateManager::SetExceptionHandler(G4VExceptionHandler* eh)
|
||||
{
|
||||
exceptionHandler = eh;
|
||||
}
|
||||
|
||||
inline
|
||||
G4VExceptionHandler* G4StateManager::GetExceptionHandler() const
|
||||
inline G4VExceptionHandler* G4StateManager::GetExceptionHandler() const
|
||||
{
|
||||
return exceptionHandler;
|
||||
}
|
||||
|
||||
@@ -23,67 +23,68 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4String
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4String
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// Definition of a Geant4 string.
|
||||
// Derived from the Rogue Wave implementation of RWCString;
|
||||
// it uses intrinsically STL string.
|
||||
// Definition of a Geant4 string.
|
||||
// Derived from the Rogue Wave implementation of RWCString;
|
||||
// it uses intrinsically STL std::string.
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
#ifndef __G4String
|
||||
#define __G4String
|
||||
// Author: G.Cosmo, 11 November 1999
|
||||
//---------------------------------------------------------------------
|
||||
#ifndef G4String_hh
|
||||
#define G4String_hh 1
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
#include "G4Types.hh"
|
||||
#include <iostream>
|
||||
|
||||
#ifdef WIN32
|
||||
#define strcasecmp _stricmp
|
||||
# define strcasecmp _stricmp
|
||||
#endif
|
||||
|
||||
typedef std::string::size_type str_size;
|
||||
using str_size = std::string::size_type;
|
||||
|
||||
class G4String : public std::string
|
||||
{
|
||||
using std_string = std::string;
|
||||
|
||||
typedef std::string std_string;
|
||||
public:
|
||||
enum caseCompare
|
||||
{
|
||||
exact,
|
||||
ignoreCase
|
||||
};
|
||||
enum stripType
|
||||
{
|
||||
leading,
|
||||
trailing,
|
||||
both
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
enum caseCompare { exact, ignoreCase };
|
||||
enum stripType { leading, trailing, both };
|
||||
|
||||
inline G4String ();
|
||||
inline G4String ( char );
|
||||
inline G4String ( const char * );
|
||||
inline G4String ( const char *, str_size );
|
||||
inline G4String ( const G4String& );
|
||||
inline G4String ( const std::string & );
|
||||
inline G4String ( G4String&& ) = default;
|
||||
~G4String () {}
|
||||
inline G4String();
|
||||
inline G4String(char);
|
||||
inline G4String(const char*);
|
||||
inline G4String(const char*, str_size);
|
||||
inline G4String(const G4String&);
|
||||
inline G4String(const std::string&);
|
||||
inline G4String(G4String&&) = default;
|
||||
~G4String() {}
|
||||
|
||||
inline G4String& operator=(const G4String&);
|
||||
inline G4String& operator=(const std::string &);
|
||||
inline G4String& operator=(const std::string&);
|
||||
inline G4String& operator=(const char*);
|
||||
inline G4String& operator=(G4String&&) = default;
|
||||
|
||||
inline char operator () (str_size) const;
|
||||
inline char& operator () (str_size);
|
||||
inline char operator()(str_size) const;
|
||||
inline char& operator()(str_size);
|
||||
|
||||
inline G4String& operator+=(const char*);
|
||||
inline G4String& operator+=(const std::string &);
|
||||
inline G4String& operator+=(const std::string&);
|
||||
inline G4String& operator+=(const char&);
|
||||
inline G4bool operator==(const G4String&) const;
|
||||
inline G4bool operator==(const char*) const;
|
||||
@@ -93,16 +94,16 @@ public:
|
||||
inline operator const char*() const;
|
||||
inline G4String operator()(str_size, str_size);
|
||||
|
||||
inline G4int compareTo(const char*, caseCompare mode=exact) const;
|
||||
inline G4int compareTo(const G4String&, caseCompare mode=exact) const;
|
||||
inline G4int compareTo(const char*, caseCompare mode = exact) const;
|
||||
inline G4int compareTo(const G4String&, caseCompare mode = exact) const;
|
||||
|
||||
inline G4String& prepend (const char*);
|
||||
inline G4String& append (const G4String&);
|
||||
inline G4String& prepend(const char*);
|
||||
inline G4String& append(const G4String&);
|
||||
|
||||
inline std::istream& readLine (std::istream&, G4bool skipWhite=true);
|
||||
|
||||
inline G4String& replace (unsigned int, unsigned int,
|
||||
const char*, unsigned int );
|
||||
inline std::istream& readLine(std::istream&, G4bool skipWhite = true);
|
||||
|
||||
inline G4String& replace(unsigned int, unsigned int, const char*,
|
||||
unsigned int);
|
||||
inline G4String& replace(str_size, str_size, const char*);
|
||||
|
||||
inline G4String& remove(str_size);
|
||||
@@ -118,22 +119,22 @@ public:
|
||||
// stripType = 1 end
|
||||
// stripType = 2 both
|
||||
//
|
||||
inline G4String strip (G4int strip_Type=trailing, char c=' ');
|
||||
inline G4String strip(G4int strip_Type = trailing, char c = ' ');
|
||||
|
||||
inline void toLower ();
|
||||
inline void toUpper ();
|
||||
inline void toLower();
|
||||
inline void toUpper();
|
||||
|
||||
inline G4bool isNull() const;
|
||||
|
||||
inline str_size index (const char*, G4int pos=0) const;
|
||||
inline str_size index (char, G4int pos=0) const;
|
||||
inline str_size index (const G4String&, str_size, str_size, caseCompare) const;
|
||||
inline str_size index(const char*, G4int pos = 0) const;
|
||||
inline str_size index(char, G4int pos = 0) const;
|
||||
inline str_size index(const G4String&, str_size, str_size, caseCompare) const;
|
||||
|
||||
inline const char* data() const;
|
||||
|
||||
inline G4int strcasecompare(const char*, const char*) const;
|
||||
|
||||
inline unsigned int hash( caseCompare cmp = exact ) const;
|
||||
inline unsigned int hash(caseCompare cmp = exact) const;
|
||||
inline unsigned int stlhash() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,40 +23,43 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4String inline methods implementation
|
||||
//
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class implementation file
|
||||
//
|
||||
// G4String
|
||||
//---------------------------------------------------------------
|
||||
// Author: G.Cosmo, 11 November 1999
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
inline G4String::G4String () {}
|
||||
inline G4String::G4String() {}
|
||||
|
||||
inline G4String::G4String ( const char * astring )
|
||||
: std_string ( astring ) {}
|
||||
inline G4String::G4String(const char* astring)
|
||||
: std_string(astring)
|
||||
{}
|
||||
|
||||
inline G4String::G4String ( const char * astring, str_size len )
|
||||
: std_string ( astring, len ) {}
|
||||
inline G4String::G4String(const char* astring, str_size len)
|
||||
: std_string(astring, len)
|
||||
{}
|
||||
|
||||
inline G4String::G4String ( char ch )
|
||||
inline G4String::G4String(char ch)
|
||||
{
|
||||
char str[2];
|
||||
str[0]=ch;
|
||||
str[1]='\0';
|
||||
str[0] = ch;
|
||||
str[1] = '\0';
|
||||
std_string::operator=(str);
|
||||
}
|
||||
|
||||
inline G4String::G4String ( const G4String& str )
|
||||
: std_string(str) {}
|
||||
inline G4String::G4String(const G4String& str)
|
||||
: std_string(str)
|
||||
{}
|
||||
|
||||
inline G4String::G4String ( const std::string& str )
|
||||
: std_string(str) {}
|
||||
inline G4String::G4String(const std::string& str)
|
||||
: std_string(str)
|
||||
{}
|
||||
|
||||
inline G4String& G4String::operator=(const G4String& str)
|
||||
{
|
||||
if (&str == this) { return *this; }
|
||||
if(&str == this)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
std_string::operator=(str);
|
||||
return *this;
|
||||
}
|
||||
@@ -73,24 +76,21 @@ inline G4String& G4String::operator=(const char* str)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// "cmp" optional parameter is NOT implemented !
|
||||
// "cmp" optional parameter is NOT implemented !
|
||||
// N.B.: The hash value returned is generally DIFFERENT from the
|
||||
// one returned by the original RW function.
|
||||
// Users should not rely on the specific return value.
|
||||
//
|
||||
inline char G4String::operator () (str_size i) const
|
||||
{
|
||||
return operator[](i);
|
||||
}
|
||||
inline char G4String::operator()(str_size i) const { return operator[](i); }
|
||||
|
||||
inline char& G4String::operator () (str_size i)
|
||||
inline char& G4String::operator()(str_size i)
|
||||
{
|
||||
return std_string::operator[](i);
|
||||
}
|
||||
|
||||
inline G4String G4String::operator()(str_size start, str_size extent)
|
||||
{
|
||||
return G4String(substr(start,extent));
|
||||
return G4String(substr(start, extent));
|
||||
}
|
||||
|
||||
inline G4String& G4String::operator+=(const char* str)
|
||||
@@ -113,7 +113,8 @@ inline G4String& G4String::operator+=(const char& ch)
|
||||
|
||||
inline G4bool G4String::operator==(const G4String& str) const
|
||||
{
|
||||
if (length() != str.length()) return false;
|
||||
if(length() != str.length())
|
||||
return false;
|
||||
return (std_string::compare(str) == 0);
|
||||
}
|
||||
|
||||
@@ -132,31 +133,31 @@ inline G4bool G4String::operator!=(const char* str) const
|
||||
return !(*this == str);
|
||||
}
|
||||
|
||||
inline G4String::operator const char*() const
|
||||
{
|
||||
return c_str();
|
||||
}
|
||||
inline G4String::operator const char*() const { return c_str(); }
|
||||
|
||||
inline G4int G4String::strcasecompare(const char* s1, const char* s2) const
|
||||
{
|
||||
char* buf1 = new char[strlen(s1)+1];
|
||||
char* buf2 = new char[strlen(s2)+1];
|
||||
char* buf1 = new char[strlen(s1) + 1];
|
||||
char* buf2 = new char[strlen(s2) + 1];
|
||||
|
||||
for (str_size i=0; i<=strlen(s1); i++)
|
||||
{ buf1[i] = tolower(char(s1[i])); }
|
||||
for (str_size j=0; j<=strlen(s2); j++)
|
||||
{ buf2[j] = tolower(char(s2[j])); }
|
||||
for(str_size i = 0; i <= strlen(s1); ++i)
|
||||
{
|
||||
buf1[i] = tolower(char(s1[i]));
|
||||
}
|
||||
for(str_size j = 0; j <= strlen(s2); ++j)
|
||||
{
|
||||
buf2[j] = tolower(char(s2[j]));
|
||||
}
|
||||
|
||||
G4int res = strcmp(buf1, buf2);
|
||||
delete [] buf1;
|
||||
delete [] buf2;
|
||||
delete[] buf1;
|
||||
delete[] buf2;
|
||||
return res;
|
||||
}
|
||||
|
||||
inline G4int G4String::compareTo(const char* str, caseCompare mode) const
|
||||
{
|
||||
return (mode==exact) ? strcmp(c_str(),str)
|
||||
: strcasecompare(c_str(),str);
|
||||
return (mode == exact) ? strcmp(c_str(), str) : strcasecompare(c_str(), str);
|
||||
}
|
||||
|
||||
inline G4int G4String::compareTo(const G4String& str, caseCompare mode) const
|
||||
@@ -164,9 +165,9 @@ inline G4int G4String::compareTo(const G4String& str, caseCompare mode) const
|
||||
return compareTo(str.c_str(), mode);
|
||||
}
|
||||
|
||||
inline G4String& G4String::prepend (const char* str)
|
||||
inline G4String& G4String::prepend(const char* str)
|
||||
{
|
||||
insert(0,str);
|
||||
insert(0, str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -176,58 +177,54 @@ inline G4String& G4String::append(const G4String& str)
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline std::istream&
|
||||
G4String::readLine (std::istream& strm, G4bool skipWhite)
|
||||
inline std::istream& G4String::readLine(std::istream& strm, G4bool skipWhite)
|
||||
{
|
||||
char tmp[1024];
|
||||
if ( skipWhite )
|
||||
if(skipWhite)
|
||||
{
|
||||
strm >> std::ws;
|
||||
strm.getline(tmp,1024);
|
||||
*this=tmp;
|
||||
strm.getline(tmp, 1024);
|
||||
*this = tmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
strm.getline(tmp,1024);
|
||||
*this=tmp;
|
||||
}
|
||||
strm.getline(tmp, 1024);
|
||||
*this = tmp;
|
||||
}
|
||||
return strm;
|
||||
}
|
||||
|
||||
inline G4String& G4String::replace (unsigned int start, unsigned int nbytes,
|
||||
const char* buff, unsigned int n2 )
|
||||
inline G4String& G4String::replace(unsigned int start, unsigned int nbytes,
|
||||
const char* buff, unsigned int n2)
|
||||
{
|
||||
std_string::replace ( start, nbytes, buff, n2 );
|
||||
return *this;
|
||||
}
|
||||
std_string::replace(start, nbytes, buff, n2);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline G4String& G4String::replace(str_size pos, str_size n, const char* str)
|
||||
{
|
||||
std_string::replace(pos,n,str);
|
||||
std_string::replace(pos, n, str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline G4String& G4String::remove(str_size n)
|
||||
{
|
||||
if(n<size()) { erase(n,size()-n); }
|
||||
if(n < size())
|
||||
{
|
||||
erase(n, size() - n);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline G4String& G4String::remove(str_size pos, str_size N)
|
||||
{
|
||||
erase(pos,N+pos);
|
||||
erase(pos, N + pos);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline std::size_t G4String::first(char ch) const
|
||||
{
|
||||
return find(ch);
|
||||
}
|
||||
inline std::size_t G4String::first(char ch) const { return find(ch); }
|
||||
|
||||
inline std::size_t G4String::last(char ch) const
|
||||
{
|
||||
return rfind(ch);
|
||||
}
|
||||
inline std::size_t G4String::last(char ch) const { return rfind(ch); }
|
||||
|
||||
inline G4bool G4String::contains(const std::string& str) const
|
||||
{
|
||||
@@ -239,108 +236,130 @@ inline G4bool G4String::contains(char ch) const
|
||||
return (std_string::find(ch) != std_string::npos);
|
||||
}
|
||||
|
||||
inline G4String G4String::strip (G4int strip_Type, char ch)
|
||||
inline G4String G4String::strip(G4int strip_Type, char ch)
|
||||
{
|
||||
G4String retVal = *this;
|
||||
if(length()==0) { return retVal; }
|
||||
str_size i=0;
|
||||
switch ( strip_Type ) {
|
||||
case leading:
|
||||
if(length() == 0)
|
||||
{
|
||||
return retVal;
|
||||
}
|
||||
str_size i = 0;
|
||||
switch(strip_Type)
|
||||
{
|
||||
case leading:
|
||||
{
|
||||
for(i=0;i<length();++i)
|
||||
{ if (std_string::operator[](i) != ch) { break; } }
|
||||
retVal = substr(i,length()-i);
|
||||
for(i = 0; i < length(); ++i)
|
||||
{
|
||||
if(std_string::operator[](i) != ch)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
retVal = substr(i, length() - i);
|
||||
}
|
||||
break;
|
||||
case trailing:
|
||||
case trailing:
|
||||
{
|
||||
G4int j=0;
|
||||
for(j=G4int(length()-1);j>=0;--j)
|
||||
{ if (std_string::operator[](j) != ch) { break; } }
|
||||
retVal = substr(0,j+1);
|
||||
G4int j = 0;
|
||||
for(j = G4int(length() - 1); j >= 0; --j)
|
||||
{
|
||||
if(std_string::operator[](j) != ch)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
retVal = substr(0, j + 1);
|
||||
}
|
||||
break;
|
||||
case both:
|
||||
{
|
||||
for(i=0;i<length();++i)
|
||||
{ if (std_string::operator[](i) != ch) { break; } }
|
||||
G4String tmp(substr(i,length()-i));
|
||||
G4int k=0;
|
||||
for(k=G4int(tmp.length()-1);k>=0;--k)
|
||||
{ if (tmp.std_string::operator[](k) != ch) { break; } }
|
||||
retVal = tmp.substr(0,k+1);
|
||||
case both:
|
||||
{
|
||||
for(i = 0; i < length(); ++i)
|
||||
{
|
||||
if(std_string::operator[](i) != ch)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
G4String tmp(substr(i, length() - i));
|
||||
G4int k = 0;
|
||||
for(k = G4int(tmp.length() - 1); k >= 0; --k)
|
||||
{
|
||||
if(tmp.std_string::operator[](k) != ch)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
retVal = tmp.substr(0, k + 1);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
inline void G4String::toLower ()
|
||||
inline void G4String::toLower()
|
||||
{
|
||||
for (str_size i=0; i<size();i++)
|
||||
for(str_size i = 0; i < size(); ++i)
|
||||
{
|
||||
//GB:HP-UX-aCC,Linux-KCC
|
||||
// GB:HP-UX-aCC,Linux-KCC
|
||||
std_string::operator[](i) = tolower(char(std_string::operator[](i)));
|
||||
//at(i) = tolower(at(i));
|
||||
}
|
||||
}
|
||||
|
||||
inline void G4String::toUpper ()
|
||||
{
|
||||
for (str_size i=0; i<size();i++)
|
||||
{
|
||||
//GB:HP-UX-aCC,Linux-KCC
|
||||
std_string::operator[](i) = toupper(char(std_string::operator[](i)));
|
||||
//at(i) = toupper(at(i));
|
||||
// at(i) = tolower(at(i));
|
||||
}
|
||||
}
|
||||
|
||||
inline G4bool G4String::isNull() const
|
||||
inline void G4String::toUpper()
|
||||
{
|
||||
return empty ();
|
||||
for(str_size i = 0; i < size(); ++i)
|
||||
{
|
||||
// GB:HP-UX-aCC,Linux-KCC
|
||||
std_string::operator[](i) = toupper(char(std_string::operator[](i)));
|
||||
// at(i) = toupper(at(i));
|
||||
}
|
||||
}
|
||||
|
||||
inline G4bool G4String::isNull() const { return empty(); }
|
||||
|
||||
// "caseCompare" optional parameter is NOT implemented !
|
||||
//
|
||||
inline str_size G4String::index( const G4String& str, str_size ln,
|
||||
str_size st, G4String::caseCompare ) const
|
||||
inline str_size G4String::index(const G4String& str, str_size ln, str_size st,
|
||||
G4String::caseCompare) const
|
||||
{
|
||||
return std_string::find( str.c_str(), st, ln );
|
||||
return std_string::find(str.c_str(), st, ln);
|
||||
}
|
||||
|
||||
inline str_size G4String::index (const char* str, G4int pos) const
|
||||
inline str_size G4String::index(const char* str, G4int pos) const
|
||||
{
|
||||
return std_string::find(str,pos);
|
||||
return std_string::find(str, pos);
|
||||
}
|
||||
|
||||
inline str_size G4String::index (char ch, G4int pos) const
|
||||
inline str_size G4String::index(char ch, G4int pos) const
|
||||
{
|
||||
return std_string::find(ch,pos);
|
||||
return std_string::find(ch, pos);
|
||||
}
|
||||
|
||||
inline const char* G4String::data() const
|
||||
{
|
||||
return c_str();
|
||||
}
|
||||
inline const char* G4String::data() const { return c_str(); }
|
||||
|
||||
inline unsigned int G4String::hash( caseCompare ) const
|
||||
inline unsigned int G4String::hash(caseCompare) const
|
||||
{
|
||||
const char* str=c_str();
|
||||
const char* str = c_str();
|
||||
unsigned long h = 0;
|
||||
for ( ; *str; ++str)
|
||||
{ h = 5*h + *str; }
|
||||
for(; *str; ++str)
|
||||
{
|
||||
h = 5 * h + *str;
|
||||
}
|
||||
|
||||
return str_size(h);
|
||||
}
|
||||
|
||||
inline unsigned int G4String::stlhash() const
|
||||
{
|
||||
const char* str=c_str();
|
||||
const char* str = c_str();
|
||||
unsigned long h = 0;
|
||||
for ( ; *str; ++str)
|
||||
{ h = 5*h + *str; }
|
||||
for(; *str; ++str)
|
||||
{
|
||||
h = 5 * h + *str;
|
||||
}
|
||||
|
||||
return str_size(h);
|
||||
}
|
||||
|
||||
@@ -23,125 +23,136 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4SystemOfUnits
|
||||
//
|
||||
// Import CLHEP units on global namespace.
|
||||
// Restricted to internal use -only- in source code
|
||||
|
||||
// Author: G.Cosmo, CERN
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4SystemOfUnits_hh
|
||||
#define G4SystemOfUnits_hh 1
|
||||
|
||||
#include <CLHEP/Units/SystemOfUnits.h>
|
||||
|
||||
using CLHEP::millimeter;
|
||||
using CLHEP::millimeter2;
|
||||
using CLHEP::millimeter3;
|
||||
using CLHEP::ampere;
|
||||
using CLHEP::angstrom;
|
||||
using CLHEP::atmosphere;
|
||||
using CLHEP::bar;
|
||||
using CLHEP::barn;
|
||||
using CLHEP::becquerel;
|
||||
using CLHEP::candela;
|
||||
using CLHEP::centimeter;
|
||||
using CLHEP::centimeter2;
|
||||
using CLHEP::centimeter3;
|
||||
using CLHEP::meter;
|
||||
using CLHEP::meter2;
|
||||
using CLHEP::meter3;
|
||||
using CLHEP::kilometer;
|
||||
using CLHEP::kilometer2;
|
||||
using CLHEP::kilometer3;
|
||||
using CLHEP::parsec;
|
||||
using CLHEP::micrometer;
|
||||
using CLHEP::nanometer;
|
||||
using CLHEP::angstrom;
|
||||
using CLHEP::fermi;
|
||||
using CLHEP::barn;
|
||||
using CLHEP::millibarn;
|
||||
using CLHEP::microbarn;
|
||||
using CLHEP::nanobarn;
|
||||
using CLHEP::picobarn;
|
||||
using CLHEP::mm;
|
||||
using CLHEP::um;
|
||||
using CLHEP::nm;
|
||||
using CLHEP::mm2;
|
||||
using CLHEP::mm3;
|
||||
using CLHEP::cL;
|
||||
using CLHEP::cm;
|
||||
using CLHEP::cm2;
|
||||
using CLHEP::cm3;
|
||||
using CLHEP::liter;
|
||||
using CLHEP::L;
|
||||
using CLHEP::coulomb;
|
||||
using CLHEP::curie;
|
||||
using CLHEP::deg;
|
||||
using CLHEP::degree;
|
||||
using CLHEP::dL;
|
||||
using CLHEP::cL;
|
||||
using CLHEP::mL;
|
||||
using CLHEP::m;
|
||||
using CLHEP::m2;
|
||||
using CLHEP::m3;
|
||||
using CLHEP::e_SI;
|
||||
using CLHEP::electronvolt;
|
||||
using CLHEP::eplus;
|
||||
using CLHEP::eV;
|
||||
using CLHEP::farad;
|
||||
using CLHEP::fermi;
|
||||
using CLHEP::g;
|
||||
using CLHEP::gauss;
|
||||
using CLHEP::GeV;
|
||||
using CLHEP::gigaelectronvolt;
|
||||
using CLHEP::gram;
|
||||
using CLHEP::gray;
|
||||
using CLHEP::henry;
|
||||
using CLHEP::hep_pascal;
|
||||
using CLHEP::hertz;
|
||||
using CLHEP::joule;
|
||||
using CLHEP::kelvin;
|
||||
using CLHEP::keV;
|
||||
using CLHEP::kg;
|
||||
using CLHEP::kiloelectronvolt;
|
||||
using CLHEP::kilogauss;
|
||||
using CLHEP::kilogram;
|
||||
using CLHEP::kilohertz;
|
||||
using CLHEP::kilometer;
|
||||
using CLHEP::kilometer2;
|
||||
using CLHEP::kilometer3;
|
||||
using CLHEP::kilovolt;
|
||||
using CLHEP::km;
|
||||
using CLHEP::km2;
|
||||
using CLHEP::km3;
|
||||
using CLHEP::pc;
|
||||
using CLHEP::radian;
|
||||
using CLHEP::milliradian;
|
||||
using CLHEP::degree;
|
||||
using CLHEP::steradian;
|
||||
using CLHEP::rad;
|
||||
using CLHEP::mrad;
|
||||
using CLHEP::sr;
|
||||
using CLHEP::deg;
|
||||
using CLHEP::nanosecond;
|
||||
using CLHEP::second;
|
||||
using CLHEP::millisecond;
|
||||
using CLHEP::microsecond;
|
||||
using CLHEP::picosecond;
|
||||
using CLHEP::hertz;
|
||||
using CLHEP::kilohertz;
|
||||
using CLHEP::megahertz;
|
||||
using CLHEP::ns;
|
||||
using CLHEP::s;
|
||||
using CLHEP::ms;
|
||||
using CLHEP::us;
|
||||
using CLHEP::ps;
|
||||
using CLHEP::eplus;
|
||||
using CLHEP::e_SI;
|
||||
using CLHEP::coulomb;
|
||||
using CLHEP::megaelectronvolt;
|
||||
using CLHEP::electronvolt;
|
||||
using CLHEP::kiloelectronvolt;
|
||||
using CLHEP::gigaelectronvolt;
|
||||
using CLHEP::teraelectronvolt;
|
||||
using CLHEP::petaelectronvolt;
|
||||
using CLHEP::joule;
|
||||
using CLHEP::MeV;
|
||||
using CLHEP::eV;
|
||||
using CLHEP::keV;
|
||||
using CLHEP::GeV;
|
||||
using CLHEP::TeV;
|
||||
using CLHEP::PeV;
|
||||
using CLHEP::kilogram;
|
||||
using CLHEP::gram;
|
||||
using CLHEP::milligram;
|
||||
using CLHEP::kg;
|
||||
using CLHEP::g;
|
||||
using CLHEP::mg;
|
||||
using CLHEP::watt;
|
||||
using CLHEP::newton;
|
||||
using CLHEP::hep_pascal;
|
||||
using CLHEP::bar;
|
||||
using CLHEP::atmosphere;
|
||||
using CLHEP::ampere;
|
||||
using CLHEP::milliampere;
|
||||
using CLHEP::microampere;
|
||||
using CLHEP::nanoampere;
|
||||
using CLHEP::megavolt;
|
||||
using CLHEP::kilovolt;
|
||||
using CLHEP::volt;
|
||||
using CLHEP::ohm;
|
||||
using CLHEP::farad;
|
||||
using CLHEP::millifarad;
|
||||
using CLHEP::microfarad;
|
||||
using CLHEP::nanofarad;
|
||||
using CLHEP::picofarad;
|
||||
using CLHEP::weber;
|
||||
using CLHEP::tesla;
|
||||
using CLHEP::gauss;
|
||||
using CLHEP::kilogauss;
|
||||
using CLHEP::henry;
|
||||
using CLHEP::kelvin;
|
||||
using CLHEP::mole;
|
||||
using CLHEP::becquerel;
|
||||
using CLHEP::curie;
|
||||
using CLHEP::gray;
|
||||
using CLHEP::candela;
|
||||
using CLHEP::L;
|
||||
using CLHEP::liter;
|
||||
using CLHEP::lumen;
|
||||
using CLHEP::lux;
|
||||
using CLHEP::m;
|
||||
using CLHEP::m2;
|
||||
using CLHEP::m3;
|
||||
using CLHEP::megaelectronvolt;
|
||||
using CLHEP::megahertz;
|
||||
using CLHEP::megavolt;
|
||||
using CLHEP::meter;
|
||||
using CLHEP::meter2;
|
||||
using CLHEP::meter3;
|
||||
using CLHEP::MeV;
|
||||
using CLHEP::mg;
|
||||
using CLHEP::microampere;
|
||||
using CLHEP::microbarn;
|
||||
using CLHEP::microfarad;
|
||||
using CLHEP::micrometer;
|
||||
using CLHEP::microsecond;
|
||||
using CLHEP::milliampere;
|
||||
using CLHEP::millibarn;
|
||||
using CLHEP::millifarad;
|
||||
using CLHEP::milligram;
|
||||
using CLHEP::millimeter;
|
||||
using CLHEP::millimeter2;
|
||||
using CLHEP::millimeter3;
|
||||
using CLHEP::milliradian;
|
||||
using CLHEP::millisecond;
|
||||
using CLHEP::mL;
|
||||
using CLHEP::mm;
|
||||
using CLHEP::mm2;
|
||||
using CLHEP::mm3;
|
||||
using CLHEP::mole;
|
||||
using CLHEP::mrad;
|
||||
using CLHEP::ms;
|
||||
using CLHEP::nanoampere;
|
||||
using CLHEP::nanobarn;
|
||||
using CLHEP::nanofarad;
|
||||
using CLHEP::nanometer;
|
||||
using CLHEP::nanosecond;
|
||||
using CLHEP::newton;
|
||||
using CLHEP::nm;
|
||||
using CLHEP::ns;
|
||||
using CLHEP::ohm;
|
||||
using CLHEP::parsec;
|
||||
using CLHEP::pc;
|
||||
using CLHEP::perCent;
|
||||
using CLHEP::perThousand;
|
||||
using CLHEP::perMillion;
|
||||
using CLHEP::perThousand;
|
||||
using CLHEP::petaelectronvolt;
|
||||
using CLHEP::PeV;
|
||||
using CLHEP::picobarn;
|
||||
using CLHEP::picofarad;
|
||||
using CLHEP::picosecond;
|
||||
using CLHEP::ps;
|
||||
using CLHEP::rad;
|
||||
using CLHEP::radian;
|
||||
using CLHEP::s;
|
||||
using CLHEP::second;
|
||||
using CLHEP::sr;
|
||||
using CLHEP::steradian;
|
||||
using CLHEP::teraelectronvolt;
|
||||
using CLHEP::tesla;
|
||||
using CLHEP::TeV;
|
||||
using CLHEP::um;
|
||||
using CLHEP::us;
|
||||
using CLHEP::volt;
|
||||
using CLHEP::watt;
|
||||
using CLHEP::weber;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,135 +23,132 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4TWorkspacePool
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// Class Description:
|
||||
// Class description:
|
||||
//
|
||||
// Create and hold a pointer to Workspace.
|
||||
// This class holds a thread-private static instance
|
||||
// of the template parameter workspace.
|
||||
// This class holds a thread-private static instance of the template
|
||||
// parameter workspace.
|
||||
//
|
||||
// The concrete implementation of workspace objects
|
||||
// are responsible for instantiating a singleton instance
|
||||
// of this pool.
|
||||
// The concrete implementation of workspace objects are responsible for
|
||||
// instantiating a singleton instance of this pool.
|
||||
//
|
||||
// Recycling of this pool can enable reuse among different
|
||||
// threads in task-based - or 'on-demand' - simulation.
|
||||
// Recycling of this pool can enable reuse among different threads in
|
||||
// task-based - or 'on-demand' - simulation.
|
||||
|
||||
// Authors: J.Apostolakis, A.Dotti - 24 October 2014
|
||||
// Revisions: G.Cosmo - 21 Obctober 2016, revised pool initialisation
|
||||
// ------------------------------------------------------------
|
||||
|
||||
#ifndef G4TWORKSPACEPOOL_HH
|
||||
#define G4TWORKSPACEPOOL_HH
|
||||
#define G4TWORKSPACEPOOL_HH 1
|
||||
|
||||
#include "tls.hh"
|
||||
#include "globals.hh"
|
||||
#include "tls.hh"
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
class G4TWorkspacePool
|
||||
{
|
||||
public:
|
||||
public:
|
||||
inline T* CreateWorkspace();
|
||||
// For use with simple MT mode - each thread gets a workspace
|
||||
// and uses it until end
|
||||
|
||||
inline T* CreateWorkspace();
|
||||
// For use with simple MT mode - each thread gets a workspace
|
||||
// and uses it until end
|
||||
|
||||
inline void CreateAndUseWorkspace();
|
||||
// Create it (as above) and use it
|
||||
|
||||
inline T* FindOrCreateWorkspace();
|
||||
// For use with 'dynamic' model of threading - workspaces can be recycled
|
||||
// Reuse an existing workspace - or create a new one if needed.
|
||||
// This will never fail, except if system is out of resources
|
||||
|
||||
inline T* GetWorkspace() { return fMyWorkspace; }
|
||||
// Give back the existing, active workspace for my thread / task
|
||||
|
||||
inline void Recycle( T * myWrkSpace );
|
||||
// Keep the unused Workspace - for recycling
|
||||
|
||||
inline void CleanUpAndDestroyAllWorkspaces();
|
||||
// To be called once at the end of the job
|
||||
inline void CreateAndUseWorkspace();
|
||||
// Create it (as above) and use it
|
||||
|
||||
public:
|
||||
inline T* FindOrCreateWorkspace();
|
||||
// For use with 'dynamic' model of threading - workspaces can be recycled
|
||||
// Reuse an existing workspace - or create a new one if needed.
|
||||
// This will never fail, except if system is out of resources
|
||||
|
||||
G4TWorkspacePool() {}
|
||||
~G4TWorkspacePool() {}
|
||||
|
||||
private:
|
||||
inline T* GetWorkspace() { return fMyWorkspace; }
|
||||
// Give back the existing, active workspace for my thread / task
|
||||
|
||||
static G4ThreadLocal T* fMyWorkspace;
|
||||
// The thread's workspace - if assigned
|
||||
inline void Recycle(T* myWrkSpace);
|
||||
// Keep the unused Workspace - for recycling
|
||||
|
||||
inline void CleanUpAndDestroyAllWorkspaces();
|
||||
// To be called once at the end of the job
|
||||
|
||||
G4TWorkspacePool() {}
|
||||
~G4TWorkspacePool() {}
|
||||
|
||||
private:
|
||||
static G4ThreadLocal T* fMyWorkspace;
|
||||
// The thread's workspace - if assigned
|
||||
};
|
||||
|
||||
template<typename T> G4ThreadLocal T* G4TWorkspacePool<T>::fMyWorkspace=0;
|
||||
template <typename T>
|
||||
G4ThreadLocal T* G4TWorkspacePool<T>::fMyWorkspace = nullptr;
|
||||
|
||||
template<class T>
|
||||
// -----------------------------
|
||||
// Inline methods implementation
|
||||
// -----------------------------
|
||||
|
||||
template <class T>
|
||||
T* G4TWorkspacePool<T>::CreateWorkspace()
|
||||
{
|
||||
T* wrk = 0;
|
||||
if ( !fMyWorkspace )
|
||||
T* wrk = nullptr;
|
||||
if(fMyWorkspace == nullptr)
|
||||
{
|
||||
wrk = new T;
|
||||
if(wrk == nullptr)
|
||||
{
|
||||
wrk = new T;
|
||||
if ( !wrk )
|
||||
{
|
||||
G4Exception("G4TWorspacePool<someType>::CreateWorkspace",
|
||||
"MemoryError", FatalException,
|
||||
"Failed to create workspace.");
|
||||
}
|
||||
else
|
||||
{
|
||||
fMyWorkspace = wrk;
|
||||
}
|
||||
G4Exception("G4TWorspacePool<someType>::CreateWorkspace()", "MemoryError",
|
||||
FatalException, "Failed to create workspace.");
|
||||
}
|
||||
else
|
||||
{
|
||||
G4Exception("ParticlesWorspacePool::CreateWorkspace",
|
||||
"InvalidCondition", FatalException,
|
||||
"Cannot create workspace twice for the same thread.");
|
||||
wrk = fMyWorkspace;
|
||||
fMyWorkspace = wrk;
|
||||
}
|
||||
return wrk;
|
||||
}
|
||||
else
|
||||
{
|
||||
G4Exception("ParticlesWorspacePool::CreateWorkspace()", "InvalidCondition",
|
||||
FatalException,
|
||||
"Cannot create workspace twice for the same thread.");
|
||||
wrk = fMyWorkspace;
|
||||
}
|
||||
return wrk;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
void G4TWorkspacePool<T>::CreateAndUseWorkspace()
|
||||
{
|
||||
(this->CreateWorkspace())->UseWorkspace();
|
||||
(this->CreateWorkspace())->UseWorkspace();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
T* G4TWorkspacePool<T>::FindOrCreateWorkspace()
|
||||
{
|
||||
T* wrk= fMyWorkspace;
|
||||
if( !wrk )
|
||||
{
|
||||
wrk= this->CreateWorkspace();
|
||||
}
|
||||
wrk->UseWorkspace();
|
||||
|
||||
fMyWorkspace= wrk; // assign it for use by this thread.
|
||||
return wrk;
|
||||
T* wrk = fMyWorkspace;
|
||||
if(wrk == nullptr)
|
||||
{
|
||||
wrk = this->CreateWorkspace();
|
||||
}
|
||||
wrk->UseWorkspace();
|
||||
|
||||
fMyWorkspace = wrk; // assign it for use by this thread.
|
||||
return wrk;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void G4TWorkspacePool<T>::Recycle( T * myWrkSpace )
|
||||
template <class T>
|
||||
void G4TWorkspacePool<T>::Recycle(T* myWrkSpace)
|
||||
{
|
||||
myWrkSpace->ReleaseWorkspace();
|
||||
delete myWrkSpace;
|
||||
myWrkSpace->ReleaseWorkspace();
|
||||
delete myWrkSpace;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
void G4TWorkspacePool<T>::CleanUpAndDestroyAllWorkspaces()
|
||||
{
|
||||
if (fMyWorkspace)
|
||||
{
|
||||
fMyWorkspace->DestroyWorkspace();
|
||||
delete fMyWorkspace;
|
||||
fMyWorkspace=0;
|
||||
}
|
||||
if(fMyWorkspace != nullptr)
|
||||
{
|
||||
fMyWorkspace->DestroyWorkspace();
|
||||
delete fMyWorkspace;
|
||||
fMyWorkspace = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // G4TWORKSPACEPOOL_HH
|
||||
#endif
|
||||
|
||||
@@ -23,101 +23,108 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4ThreadLocalSingleton
|
||||
//
|
||||
// ---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// Class description:
|
||||
//
|
||||
// Class Description:
|
||||
// This class implements a thread-private "singleton". Being thread
|
||||
// private the singleton is not a singleton in the term, but a different
|
||||
// instance existis for each thread.
|
||||
// This class is a wrapper around the real object that we need to
|
||||
// make singleton.
|
||||
// This class implements a thread-private "singleton". Being thread
|
||||
// private the singleton is not a singleton in the term, but a different
|
||||
// instance exists for each thread.
|
||||
// This class is a wrapper around the real object that we need to
|
||||
// make singleton.
|
||||
//
|
||||
// Limitation:
|
||||
// The object that is made thread-private singleton, should not
|
||||
// contain any G4ThreadLocal data member. Note that in general,
|
||||
// if object is to be thread-private it is unnecessary to mark
|
||||
// The object that is made thread-private singleton should not
|
||||
// contain any thread-local data member. Note that in general,
|
||||
// if an object is to be thread-private it is unnecessary to mark
|
||||
// any data-member as G4ThreadLocal.
|
||||
//
|
||||
//
|
||||
// Performance issues:
|
||||
// This class uses locks and mutexes.
|
||||
//
|
||||
// Example:
|
||||
// This is the singleton patter often found in G4 (sequential):
|
||||
// class G4Class {
|
||||
// private:
|
||||
// static G4Class* instance;
|
||||
// G4Class() { ... }
|
||||
// public:
|
||||
// static G4Class* GetInstance() {
|
||||
// static G4Class theInstance;
|
||||
// if ( instance == 0 ) instance = &theInstance;
|
||||
// return instance;
|
||||
// }
|
||||
// };
|
||||
// This is transformed to the following to implement a thread-local
|
||||
// singleton:
|
||||
// class G4Class {
|
||||
// private:
|
||||
// static G4ThreadLocal G4Class* instance;
|
||||
// G4Class() { ... }
|
||||
// public:
|
||||
// static G4Class* GetInstance() {
|
||||
// if ( instance == 0 ) instance = new G4Class;
|
||||
// return instance;
|
||||
// }
|
||||
// };
|
||||
// Note that this class also has a memory leak.
|
||||
// This is the singleton pattern often found in Geant4 (sequential):
|
||||
// class G4Class
|
||||
// {
|
||||
// private:
|
||||
// static G4Class* instance;
|
||||
// G4Class() { ... }
|
||||
// public:
|
||||
// static G4Class* GetInstance()
|
||||
// {
|
||||
// static G4Class theInstance;
|
||||
// if ( instance == nullptr ) instance = &theInstance;
|
||||
// return instance;
|
||||
// }
|
||||
// };
|
||||
// This is transformed to the following to implement a thread-local
|
||||
// singleton:
|
||||
// class G4Class
|
||||
// {
|
||||
// private:
|
||||
// static G4ThreadLocal G4Class* instance;
|
||||
// G4Class() { ... }
|
||||
// public:
|
||||
// static G4Class* GetInstance()
|
||||
// {
|
||||
// if ( instance == nullptr ) instance = new G4Class;
|
||||
// return instance;
|
||||
// }
|
||||
// };
|
||||
// Note that this class also has a memory leak.
|
||||
//
|
||||
// This class can be used as follows:
|
||||
// class G4Class {
|
||||
// friend class G4ThreadLocalSingleton<G4Class>;
|
||||
// private:
|
||||
// G4Class() { ... }
|
||||
// public:
|
||||
// static G4Class* GetInstance() {
|
||||
// static G4ThreadLocalSingleton<G4Class> instance;
|
||||
// return instance.Instance();
|
||||
// }
|
||||
// };
|
||||
// Each thread has its own instance of G4Class.
|
||||
// Deletion of G4Class instances is done at end of program.
|
||||
// Note the "friend" statement.
|
||||
//
|
||||
// History:
|
||||
// 28 October 2013: A. Dotti - First implementation
|
||||
// This class can be used as follows:
|
||||
// class G4Class
|
||||
// {
|
||||
// friend class G4ThreadLocalSingleton<G4Class>;
|
||||
// private:
|
||||
// G4Class() { ... }
|
||||
// public:
|
||||
// static G4Class* GetInstance()
|
||||
// {
|
||||
// static G4ThreadLocalSingleton<G4Class> instance;
|
||||
// return instance.Instance();
|
||||
// }
|
||||
// };
|
||||
// Each thread has its own instance of G4Class.
|
||||
// Deletion of G4Class instances is done at end of program.
|
||||
// Note the "friend" statement.
|
||||
|
||||
// Author: A.Dotti, 28 October 2013
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4TLSSINGLETON_HH
|
||||
#define G4TLSSINGLETON_HH
|
||||
#define G4TLSSINGLETON_HH 1
|
||||
|
||||
//Debug this code
|
||||
//#define g4tlssdebug 1
|
||||
|
||||
#include "G4Cache.hh"
|
||||
#include <list>
|
||||
|
||||
//Forward declaration. See G4AutoDelete.hh
|
||||
namespace G4AutoDelete {
|
||||
template<class T>
|
||||
#include "G4AutoLock.hh"
|
||||
#include "G4Cache.hh"
|
||||
|
||||
// Forward declaration. See G4AutoDelete.hh
|
||||
//
|
||||
namespace G4AutoDelete
|
||||
{
|
||||
template <class T>
|
||||
void Register(T*);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
class G4ThreadLocalSingleton : private G4Cache<T*> {
|
||||
template <class T>
|
||||
class G4ThreadLocalSingleton : private G4Cache<T*>
|
||||
{
|
||||
friend void G4AutoDelete::Register<T>(T*);
|
||||
public:
|
||||
|
||||
public:
|
||||
G4ThreadLocalSingleton();
|
||||
//Creates thread-local singleton manager
|
||||
// Creates thread-local singleton manager
|
||||
|
||||
~G4ThreadLocalSingleton();
|
||||
~G4ThreadLocalSingleton();
|
||||
|
||||
T* Instance() const;
|
||||
//Returns a pointer to a thread-private instance of T
|
||||
T* Instance() const;
|
||||
// Returns a pointer to a thread-private instance of T
|
||||
|
||||
private:
|
||||
G4ThreadLocalSingleton( G4ThreadLocalSingleton& rhs);// {}
|
||||
void Register(T* i) const;
|
||||
private:
|
||||
G4ThreadLocalSingleton(G4ThreadLocalSingleton& rhs);
|
||||
void Register(T* i) const;
|
||||
|
||||
void Clear();
|
||||
|
||||
@@ -125,52 +132,59 @@ private:
|
||||
mutable G4Mutex listm;
|
||||
};
|
||||
|
||||
//=============================================================
|
||||
// Inline methods implementation
|
||||
//=============================================================
|
||||
|
||||
//=============================================================
|
||||
// Implementation details follow
|
||||
//=============================================================
|
||||
#include "G4AutoLock.hh"
|
||||
template<class T>
|
||||
G4ThreadLocalSingleton<T>::G4ThreadLocalSingleton() : G4Cache<T*>() {
|
||||
template <class T>
|
||||
G4ThreadLocalSingleton<T>::G4ThreadLocalSingleton()
|
||||
: G4Cache<T*>()
|
||||
{
|
||||
G4MUTEXINIT(listm);
|
||||
G4Cache<T*>::Put(static_cast<T*>(0));
|
||||
G4Cache<T*>::Put(static_cast<T*>(0));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
G4ThreadLocalSingleton<T>::~G4ThreadLocalSingleton() {
|
||||
template <class T>
|
||||
G4ThreadLocalSingleton<T>::~G4ThreadLocalSingleton()
|
||||
{
|
||||
Clear();
|
||||
G4MUTEXDESTROY(listm);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* G4ThreadLocalSingleton<T>::Instance() const {
|
||||
T* instance = G4Cache<T*>::Get();
|
||||
if ( instance == static_cast<T*>(0) ) {
|
||||
instance = new T;
|
||||
G4Cache<T*>::Put( instance );
|
||||
Register(instance);
|
||||
}
|
||||
return instance;
|
||||
template <class T>
|
||||
T* G4ThreadLocalSingleton<T>::Instance() const
|
||||
{
|
||||
T* instance = G4Cache<T*>::Get();
|
||||
if(instance == static_cast<T*>(0))
|
||||
{
|
||||
instance = new T;
|
||||
G4Cache<T*>::Put(instance);
|
||||
Register(instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
G4ThreadLocalSingleton<T>::G4ThreadLocalSingleton( G4ThreadLocalSingleton&) {}
|
||||
template<class T>
|
||||
void G4ThreadLocalSingleton<T>::Register(T* i) const {
|
||||
template <class T>
|
||||
G4ThreadLocalSingleton<T>::G4ThreadLocalSingleton(G4ThreadLocalSingleton&)
|
||||
{}
|
||||
|
||||
template <class T>
|
||||
void G4ThreadLocalSingleton<T>::Register(T* i) const
|
||||
{
|
||||
G4AutoLock l(&listm);
|
||||
instances.push_back(i);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void G4ThreadLocalSingleton<T>::Clear() {
|
||||
G4AutoLock l(&listm);
|
||||
while ( ! instances.empty() )
|
||||
{
|
||||
T* thisinst = instances.front();
|
||||
instances.pop_front();
|
||||
if ( thisinst != 0 ) delete thisinst;
|
||||
}
|
||||
template <class T>
|
||||
void G4ThreadLocalSingleton<T>::Clear()
|
||||
{
|
||||
G4AutoLock l(&listm);
|
||||
while(!instances.empty())
|
||||
{
|
||||
T* thisinst = instances.front();
|
||||
instances.pop_front();
|
||||
delete thisinst;
|
||||
}
|
||||
}
|
||||
|
||||
#endif //G4TLSSINGLETON_HH
|
||||
#endif
|
||||
|
||||
@@ -23,41 +23,41 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4Threading
|
||||
//
|
||||
// ---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
// Description:
|
||||
//
|
||||
// Class Description:
|
||||
//
|
||||
// This file defines types and macros used to expose Geant4 threading model.
|
||||
// This unit defines types and macros used to expose Geant4 threading model.
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Author: Andrea Dotti (15 Feb 2013): First Implementation
|
||||
// ---------------------------------------------------------------
|
||||
// Author: Andrea Dotti, 15 February 2013 - First Implementation
|
||||
// Revision: Jonathan R. Madsen, 21 February 2018
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4Threading_hh
|
||||
#define G4Threading_hh
|
||||
#define G4Threading_hh 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4Types.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <future>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
// Macro to put current thread to sleep
|
||||
//
|
||||
#define G4THREADSLEEP(tick) \
|
||||
std::this_thread::sleep_for(std::chrono::seconds( tick ))
|
||||
#define G4THREADSLEEP(tick) \
|
||||
std::this_thread::sleep_for(std::chrono::seconds(tick))
|
||||
|
||||
// will be used in the future when migrating threading to task-based style
|
||||
template <typename _Tp> using G4Future = std::future<_Tp>;
|
||||
template <typename _Tp> using G4SharedFuture = std::shared_future<_Tp>;
|
||||
template <typename _Tp> using G4Promise = std::promise<_Tp>;
|
||||
// Will be used in the future when migrating threading to task-based style
|
||||
template <typename _Tp>
|
||||
using G4Future = std::future<_Tp>;
|
||||
template <typename _Tp>
|
||||
using G4SharedFuture = std::shared_future<_Tp>;
|
||||
template <typename _Tp>
|
||||
using G4Promise = std::promise<_Tp>;
|
||||
|
||||
//
|
||||
// NOTE ON GEANT4 SERIAL BUILDS AND MUTEX/UNIQUE_LOCK
|
||||
// ==================================================
|
||||
//
|
||||
@@ -76,185 +76,209 @@ template <typename _Tp> using G4Promise = std::promise<_Tp>;
|
||||
// member functions are not virtual, they will not retain the dummy locking
|
||||
// and unlocking behavior
|
||||
// --> An example of this behavior can be found in G4AutoLock.hh
|
||||
//
|
||||
// Jonathan R. Madsen (February 21, 2018)
|
||||
//
|
||||
|
||||
// global mutex types
|
||||
using G4Mutex = std::mutex;
|
||||
// Global mutex types
|
||||
using G4Mutex = std::mutex;
|
||||
using G4RecursiveMutex = std::recursive_mutex;
|
||||
|
||||
// mutex macros
|
||||
#define G4MUTEX_INITIALIZER {}
|
||||
#define G4MUTEXINIT(mutex) ;;
|
||||
#define G4MUTEXDESTROY(mutex) ;;
|
||||
// Mutex macros
|
||||
#define G4MUTEX_INITIALIZER \
|
||||
{}
|
||||
#define G4MUTEXINIT(mutex) \
|
||||
; \
|
||||
;
|
||||
#define G4MUTEXDESTROY(mutex) \
|
||||
; \
|
||||
;
|
||||
|
||||
// static functions: get_id(), sleep_for(...), sleep_until(...), yield(),
|
||||
namespace G4ThisThread { using namespace std::this_thread; }
|
||||
// Static functions: get_id(), sleep_for(...), sleep_until(...), yield(),
|
||||
namespace G4ThisThread
|
||||
{
|
||||
using namespace std::this_thread;
|
||||
}
|
||||
|
||||
// will be used in the future when migrating threading to task-based style
|
||||
// Will be used in the future when migrating threading to task-based style
|
||||
// and are currently used in unit tests
|
||||
template <typename _Tp> using G4Promise = std::promise<_Tp>;
|
||||
template <typename _Tp> using G4Future = std::future<_Tp>;
|
||||
template <typename _Tp> using G4SharedFuture = std::shared_future<_Tp>;
|
||||
template <typename _Tp>
|
||||
using G4Promise = std::promise<_Tp>;
|
||||
template <typename _Tp>
|
||||
using G4Future = std::future<_Tp>;
|
||||
template <typename _Tp>
|
||||
using G4SharedFuture = std::shared_future<_Tp>;
|
||||
|
||||
// Some useful types
|
||||
using G4ThreadFunReturnType = void*;
|
||||
using G4ThreadFunArgType = void*;
|
||||
using thread_lock = G4int(*)(G4Mutex*); // typedef G4int (*thread_lock)(G4Mutex*);
|
||||
using thread_unlock = G4int(*)(G4Mutex*); // typedef G4int (*thread_unlock)(G4Mutex*);
|
||||
using G4ThreadFunArgType = void*;
|
||||
using thread_lock =
|
||||
G4int (*)(G4Mutex*); // typedef G4int (*thread_lock)(G4Mutex*);
|
||||
using thread_unlock =
|
||||
G4int (*)(G4Mutex*); // typedef G4int (*thread_unlock)(G4Mutex*);
|
||||
|
||||
// Helper function for getting a unique static mutex for a specific
|
||||
// class or type
|
||||
// Usage example:
|
||||
// a template class "G4Cache<T>" that required a static
|
||||
// mutex for specific to type T:
|
||||
// G4AutoLock l(G4TypeMutex<G4Cache<T>>());
|
||||
// a template class "G4Cache<T>" that required a static
|
||||
// mutex for specific to type T:
|
||||
// G4AutoLock l(G4TypeMutex<G4Cache<T>>());
|
||||
template <typename _Tp>
|
||||
G4Mutex& G4TypeMutex(const unsigned int& _n = 0)
|
||||
{
|
||||
static G4Mutex* _mutex = new G4Mutex();
|
||||
if(_n == 0)
|
||||
return *_mutex;
|
||||
static G4Mutex* _mutex = new G4Mutex();
|
||||
if(_n == 0)
|
||||
return *_mutex;
|
||||
|
||||
static std::vector<G4Mutex*> _mutexes;
|
||||
if(_n > _mutexes.size())
|
||||
_mutexes.resize(_n, nullptr);
|
||||
if(!_mutexes[_n])
|
||||
_mutexes[_n] = new G4Mutex();
|
||||
return *(_mutexes[_n-1]);
|
||||
static std::vector<G4Mutex*> _mutexes;
|
||||
if(_n > _mutexes.size())
|
||||
_mutexes.resize(_n, nullptr);
|
||||
if(!_mutexes[_n])
|
||||
_mutexes[_n] = new G4Mutex();
|
||||
return *(_mutexes[_n - 1]);
|
||||
}
|
||||
|
||||
// Helper function for getting a unique static recursive_mutex for a
|
||||
// Helper function for getting a unique static recursive_mutex for a
|
||||
// specific class or type
|
||||
// Usage example:
|
||||
// a template class "G4Cache<T>" that required a static
|
||||
// recursive_mutex for specific to type T:
|
||||
// G4RecursiveAutoLock l(G4TypeRecursiveMutex<G4Cache<T>>());
|
||||
// a template class "G4Cache<T>" that required a static
|
||||
// recursive_mutex for specific to type T:
|
||||
// G4RecursiveAutoLock
|
||||
// l(G4TypeRecursiveMutex<G4Cache<T>>());
|
||||
template <typename _Tp>
|
||||
G4RecursiveMutex& G4TypeRecursiveMutex(const unsigned int& _n = 0)
|
||||
{
|
||||
static G4RecursiveMutex* _mutex = new G4RecursiveMutex();
|
||||
if(_n == 0)
|
||||
return *(_mutex);
|
||||
static G4RecursiveMutex* _mutex = new G4RecursiveMutex();
|
||||
if(_n == 0)
|
||||
return *(_mutex);
|
||||
|
||||
static std::vector<G4RecursiveMutex*> _mutexes;
|
||||
if(_n > _mutexes.size())
|
||||
_mutexes.resize(_n, nullptr);
|
||||
if(!_mutexes[_n])
|
||||
_mutexes[_n] = new G4RecursiveMutex();
|
||||
return *(_mutexes[_n-1]);
|
||||
static std::vector<G4RecursiveMutex*> _mutexes;
|
||||
if(_n > _mutexes.size())
|
||||
_mutexes.resize(_n, nullptr);
|
||||
if(!_mutexes[_n])
|
||||
_mutexes[_n] = new G4RecursiveMutex();
|
||||
return *(_mutexes[_n - 1]);
|
||||
}
|
||||
|
||||
#if defined(G4MULTITHREADED)
|
||||
//==========================================
|
||||
// G4MULTITHREADED is ON - threading enabled
|
||||
//==========================================
|
||||
//==========================================
|
||||
// G4MULTITHREADED is ON - threading enabled
|
||||
//==========================================
|
||||
|
||||
// global thread types
|
||||
using G4Thread = std::thread;
|
||||
using G4NativeThread = std::thread::native_handle_type;
|
||||
// global thread types
|
||||
using G4Thread = std::thread;
|
||||
using G4NativeThread = std::thread::native_handle_type;
|
||||
|
||||
// mutex macros
|
||||
#define G4MUTEXLOCK(mutex) { (mutex)->lock(); }
|
||||
#define G4MUTEXUNLOCK(mutex) { (mutex)->unlock(); }
|
||||
|
||||
// Macro to join thread
|
||||
#define G4THREADJOIN(worker) (worker).join()
|
||||
|
||||
// std::thread::id does not cast to integer
|
||||
using G4Pid_t = std::thread::id;
|
||||
|
||||
// Instead of previous macro taking one argument, define function taking
|
||||
// unlimited arguments
|
||||
template <typename _Worker, typename _Func, typename... _Args>
|
||||
void G4THREADCREATE(_Worker*& worker, _Func func, _Args... args)
|
||||
{
|
||||
*worker = G4Thread(func, std::forward<_Args>(args)...);
|
||||
// mutex macros
|
||||
# define G4MUTEXLOCK(mutex) \
|
||||
{ \
|
||||
(mutex)->lock(); \
|
||||
}
|
||||
# define G4MUTEXUNLOCK(mutex) \
|
||||
{ \
|
||||
(mutex)->unlock(); \
|
||||
}
|
||||
|
||||
// Conditions
|
||||
//
|
||||
// See G4MTRunManager for example on how to use these
|
||||
//
|
||||
using G4Condition = std::condition_variable;
|
||||
#define G4CONDITION_INITIALIZER {}
|
||||
#define G4CONDITIONWAIT(cond, lock) (cond)->wait(*lock);
|
||||
#define G4CONDITIONWAITLAMBDA(cond, lock, lambda) (cond)->wait(*lock, lambda);
|
||||
#define G4CONDITIONNOTIFY(cond) (cond)->notify_one();
|
||||
#define G4CONDITIONBROADCAST(cond) (cond)->notify_all();
|
||||
//
|
||||
// we don't define above globally so single-threaded code does not get
|
||||
// caught in condition with no other thread to wake it up
|
||||
//
|
||||
// Macro to join thread
|
||||
# define G4THREADJOIN(worker) (worker).join()
|
||||
|
||||
#else
|
||||
//==========================================
|
||||
// G4MULTITHREADED is OFF - Sequential build
|
||||
//==========================================
|
||||
// std::thread::id does not cast to integer
|
||||
using G4Pid_t = std::thread::id;
|
||||
|
||||
// implement a dummy thread class that acts like a thread
|
||||
class G4DummyThread
|
||||
{
|
||||
public:
|
||||
using native_handle_type = G4int;
|
||||
using id = std::thread::id;
|
||||
// Instead of previous macro taking one argument, define function taking
|
||||
// unlimited arguments
|
||||
template <typename _Worker, typename _Func, typename... _Args>
|
||||
void G4THREADCREATE(_Worker*& worker, _Func func, _Args... args)
|
||||
{
|
||||
*worker = G4Thread(func, std::forward<_Args>(args)...);
|
||||
}
|
||||
|
||||
public:
|
||||
// does nothing
|
||||
G4DummyThread()
|
||||
{ }
|
||||
// a std::thread-like constructor that execute upon construction
|
||||
template <typename _Func, typename... _Args>
|
||||
G4DummyThread(_Func func, _Args&&... _args)
|
||||
{
|
||||
func(std::forward<_Args>(_args)...);
|
||||
}
|
||||
// Conditions
|
||||
//
|
||||
// See G4MTRunManager for example on how to use these
|
||||
//
|
||||
using G4Condition = std::condition_variable;
|
||||
# define G4CONDITION_INITIALIZER \
|
||||
{}
|
||||
# define G4CONDITIONWAIT(cond, lock) (cond)->wait(*lock);
|
||||
# define G4CONDITIONWAITLAMBDA(cond, lock, lambda) (cond)->wait(*lock, lambda);
|
||||
# define G4CONDITIONNOTIFY(cond) (cond)->notify_one();
|
||||
# define G4CONDITIONBROADCAST(cond) (cond)->notify_all();
|
||||
//
|
||||
// we don't define above globally so single-threaded code does not get
|
||||
// caught in condition with no other thread to wake it up
|
||||
//
|
||||
|
||||
public:
|
||||
native_handle_type native_handle() const { return native_handle_type(); }
|
||||
bool joinable() const { return true; }
|
||||
id get_id() const noexcept { return std::this_thread::get_id(); }
|
||||
void swap(G4DummyThread&) { }
|
||||
void join() { }
|
||||
void detach() { }
|
||||
#else
|
||||
//==========================================
|
||||
// G4MULTITHREADED is OFF - Sequential build
|
||||
//==========================================
|
||||
|
||||
public:
|
||||
static unsigned int hardware_concurrency() noexcept
|
||||
{
|
||||
return std::thread::hardware_concurrency();
|
||||
}
|
||||
};
|
||||
// implement a dummy thread class that acts like a thread
|
||||
class G4DummyThread
|
||||
{
|
||||
public:
|
||||
using native_handle_type = G4int;
|
||||
using id = std::thread::id;
|
||||
|
||||
// global thread types
|
||||
using G4Thread = G4DummyThread;
|
||||
using G4NativeThread = G4DummyThread::native_handle_type;
|
||||
public:
|
||||
// does nothing
|
||||
G4DummyThread() {}
|
||||
// a std::thread-like constructor that execute upon construction
|
||||
template <typename _Func, typename... _Args>
|
||||
G4DummyThread(_Func func, _Args&&... _args)
|
||||
{
|
||||
func(std::forward<_Args>(_args)...);
|
||||
}
|
||||
|
||||
// mutex macros
|
||||
#define G4MUTEXLOCK(mutex) ;;
|
||||
#define G4MUTEXUNLOCK(mutex) ;;
|
||||
public:
|
||||
native_handle_type native_handle() const { return native_handle_type(); }
|
||||
G4bool joinable() const { return true; }
|
||||
id get_id() const noexcept { return std::this_thread::get_id(); }
|
||||
void swap(G4DummyThread&) {}
|
||||
void join() {}
|
||||
void detach() {}
|
||||
|
||||
// Macro to join thread
|
||||
#define G4THREADJOIN(worker) ;;
|
||||
public:
|
||||
static unsigned int hardware_concurrency() noexcept
|
||||
{
|
||||
return std::thread::hardware_concurrency();
|
||||
}
|
||||
};
|
||||
|
||||
using G4Pid_t = G4int;
|
||||
// global thread types
|
||||
using G4Thread = G4DummyThread;
|
||||
using G4NativeThread = G4DummyThread::native_handle_type;
|
||||
|
||||
// Instead of previous macro taking one argument, define function taking
|
||||
// unlimited arguments
|
||||
template <typename _Worker, typename _Func, typename... _Args>
|
||||
void G4THREADCREATE(_Worker*& worker, _Func func, _Args... args)
|
||||
{
|
||||
*worker = G4Thread(func, std::forward<_Args>(args)...);
|
||||
}
|
||||
// mutex macros
|
||||
# define G4MUTEXLOCK(mutex) \
|
||||
; \
|
||||
;
|
||||
# define G4MUTEXUNLOCK(mutex) \
|
||||
; \
|
||||
;
|
||||
|
||||
using G4Condition = G4int;
|
||||
#define G4CONDITION_INITIALIZER 1
|
||||
#define G4CONDITIONWAIT(cond, mutex) G4ConsumeParameters(cond, mutex);
|
||||
#define G4CONDITIONWAITLAMBDA(cond, mutex, lambda) G4ConsumeParameters(cond, mutex, lambda);
|
||||
#define G4CONDITIONNOTIFY(cond) G4ConsumeParameters(cond);
|
||||
#define G4CONDITIONBROADCAST(cond) G4ConsumeParameters(cond);
|
||||
// Macro to join thread
|
||||
# define G4THREADJOIN(worker) \
|
||||
; \
|
||||
;
|
||||
|
||||
#endif //G4MULTITHREADING
|
||||
using G4Pid_t = G4int;
|
||||
|
||||
// Instead of previous macro taking one argument, define function taking
|
||||
// unlimited arguments
|
||||
template <typename _Worker, typename _Func, typename... _Args>
|
||||
void G4THREADCREATE(_Worker*& worker, _Func func, _Args... args)
|
||||
{
|
||||
*worker = G4Thread(func, std::forward<_Args>(args)...);
|
||||
}
|
||||
|
||||
using G4Condition = G4int;
|
||||
# define G4CONDITION_INITIALIZER 1
|
||||
# define G4CONDITIONWAIT(cond, mutex) G4ConsumeParameters(cond, mutex);
|
||||
# define G4CONDITIONWAITLAMBDA(cond, mutex, lambda) \
|
||||
G4ConsumeParameters(cond, mutex, lambda);
|
||||
# define G4CONDITIONNOTIFY(cond) G4ConsumeParameters(cond);
|
||||
# define G4CONDITIONBROADCAST(cond) G4ConsumeParameters(cond);
|
||||
|
||||
#endif // G4MULTITHREADING
|
||||
|
||||
//============================================================================//
|
||||
|
||||
@@ -265,26 +289,26 @@ using G4ThreadId = G4Thread::id;
|
||||
|
||||
namespace G4Threading
|
||||
{
|
||||
enum
|
||||
{
|
||||
SEQUENTIAL_ID = -2,
|
||||
MASTER_ID = -1,
|
||||
WORKER_ID = 0,
|
||||
GENERICTHREAD_ID = -1000
|
||||
};
|
||||
enum
|
||||
{
|
||||
SEQUENTIAL_ID = -2,
|
||||
MASTER_ID = -1,
|
||||
WORKER_ID = 0,
|
||||
GENERICTHREAD_ID = -1000
|
||||
};
|
||||
|
||||
G4Pid_t G4GetPidId();
|
||||
G4int G4GetNumberOfCores();
|
||||
G4int G4GetThreadId();
|
||||
G4bool IsWorkerThread();
|
||||
G4bool IsMasterThread();
|
||||
void G4SetThreadId( G4int aNewValue );
|
||||
G4bool G4SetPinAffinity( G4int idx , G4NativeThread& at);
|
||||
void SetMultithreadedApplication(G4bool value);
|
||||
G4bool IsMultithreadedApplication();
|
||||
int WorkerThreadLeavesPool();
|
||||
int WorkerThreadJoinsPool();
|
||||
G4int GetNumberOfRunningWorkerThreads();
|
||||
}
|
||||
G4Pid_t G4GetPidId();
|
||||
G4int G4GetNumberOfCores();
|
||||
G4int G4GetThreadId();
|
||||
G4bool IsWorkerThread();
|
||||
G4bool IsMasterThread();
|
||||
void G4SetThreadId(G4int aNewValue);
|
||||
G4bool G4SetPinAffinity(G4int idx, G4NativeThread& at);
|
||||
void SetMultithreadedApplication(G4bool value);
|
||||
G4bool IsMultithreadedApplication();
|
||||
G4int WorkerThreadLeavesPool();
|
||||
G4int WorkerThreadJoinsPool();
|
||||
G4int GetNumberOfRunningWorkerThreads();
|
||||
} // namespace G4Threading
|
||||
|
||||
#endif //G4Threading_hh
|
||||
#endif // G4Threading_hh
|
||||
|
||||
@@ -23,21 +23,16 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// G4ThreeVector class, typedef to CLHEP Hep3Vector
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
// G4ThreeVector, a typedef to CLHEP Hep3Vector
|
||||
|
||||
// Author: G.Cosmo (CERN), 1997
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4THREEVECTOR_HH
|
||||
#define G4THREEVECTOR_HH
|
||||
#define G4THREEVECTOR_HH 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include <CLHEP/Vector/ThreeVector.h>
|
||||
|
||||
typedef CLHEP::Hep3Vector G4ThreeVector;
|
||||
using G4ThreeVector = CLHEP::Hep3Vector;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,21 +23,20 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
// G4TiMemory
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
// Provides empty macros when Geant4 is compiled with TiMemory disabled
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#ifndef g4timemory_hh_
|
||||
#define g4timemory_hh_
|
||||
// Author: Jonathan R. Madsen, 25 April 2019
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef g4timemory_hh
|
||||
#define g4timemory_hh 1
|
||||
|
||||
// Fundamental definitions
|
||||
#ifndef G4GMAKE
|
||||
# include "G4GlobalConfig.hh"
|
||||
# include "G4GlobalConfig.hh"
|
||||
#endif
|
||||
|
||||
#include "globals.hh"
|
||||
@@ -45,32 +44,30 @@
|
||||
//----------------------------------------------------------------------------//
|
||||
#ifdef GEANT4_USE_TIMEMORY
|
||||
|
||||
# include <timemory/timemory.hpp>
|
||||
# include <timemory/timemory.hpp>
|
||||
|
||||
using G4AutoTimer = tim::auto_timer;
|
||||
|
||||
#else
|
||||
|
||||
# include <ostream>
|
||||
# include <string>
|
||||
# include <ostream>
|
||||
# include <string>
|
||||
|
||||
namespace tim
|
||||
{
|
||||
template <typename... _Args>
|
||||
void timemory_init(_Args...)
|
||||
{
|
||||
}
|
||||
inline void timemory_finalize() {}
|
||||
inline void print_env() {}
|
||||
template <typename... _Args>
|
||||
void timemory_init(_Args...)
|
||||
{}
|
||||
inline void timemory_finalize() {}
|
||||
inline void print_env() {}
|
||||
|
||||
/// this provides "functionality" for *_HANDLE macros
|
||||
/// and can be omitted if these macros are not utilized
|
||||
struct dummy
|
||||
{
|
||||
/// this provides "functionality" for *_HANDLE macros
|
||||
/// and can be omitted if these macros are not utilized
|
||||
struct dummy
|
||||
{
|
||||
template <typename... _Args>
|
||||
dummy(_Args&&...)
|
||||
{
|
||||
}
|
||||
{}
|
||||
~dummy() = default;
|
||||
dummy(const dummy&) = default;
|
||||
dummy(dummy&&) = default;
|
||||
@@ -84,75 +81,76 @@ struct dummy
|
||||
void report_at_exit(bool) {}
|
||||
template <typename... _Args>
|
||||
void mark_begin(_Args&&...)
|
||||
{
|
||||
}
|
||||
{}
|
||||
template <typename... _Args>
|
||||
void mark_end(_Args&&...)
|
||||
{}
|
||||
friend std::ostream& operator<<(std::ostream& os, const dummy&)
|
||||
{
|
||||
return os;
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& os, const dummy&) { return os; }
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace tim
|
||||
|
||||
// startup/shutdown/configure
|
||||
# define TIMEMORY_INIT(...)
|
||||
# define TIMEMORY_FINALIZE()
|
||||
# define TIMEMORY_CONFIGURE(...)
|
||||
# define TIMEMORY_INIT(...)
|
||||
# define TIMEMORY_FINALIZE()
|
||||
# define TIMEMORY_CONFIGURE(...)
|
||||
|
||||
// label creation
|
||||
# define TIMEMORY_BASIC_LABEL(...) std::string("")
|
||||
# define TIMEMORY_LABEL(...) std::string("")
|
||||
# define TIMEMORY_JOIN(...) std::string("")
|
||||
# define TIMEMORY_BASIC_LABEL(...) std::string("")
|
||||
# define TIMEMORY_LABEL(...) std::string("")
|
||||
# define TIMEMORY_JOIN(...) std::string("")
|
||||
|
||||
// define an object
|
||||
# define TIMEMORY_BLANK_MARKER(...)
|
||||
# define TIMEMORY_BASIC_MARKER(...)
|
||||
# define TIMEMORY_MARKER(...)
|
||||
# define TIMEMORY_BLANK_MARKER(...)
|
||||
# define TIMEMORY_BASIC_MARKER(...)
|
||||
# define TIMEMORY_MARKER(...)
|
||||
|
||||
// define an unique pointer object
|
||||
# define TIMEMORY_BLANK_POINTER(...)
|
||||
# define TIMEMORY_BASIC_POINTER(...)
|
||||
# define TIMEMORY_POINTER(...)
|
||||
# define TIMEMORY_BLANK_POINTER(...)
|
||||
# define TIMEMORY_BASIC_POINTER(...)
|
||||
# define TIMEMORY_POINTER(...)
|
||||
|
||||
// define an object with a caliper reference
|
||||
# define TIMEMORY_BLANK_CALIPER(...)
|
||||
# define TIMEMORY_BASIC_CALIPER(...)
|
||||
# define TIMEMORY_CALIPER(...)
|
||||
# define TIMEMORY_BLANK_CALIPER(...)
|
||||
# define TIMEMORY_BASIC_CALIPER(...)
|
||||
# define TIMEMORY_CALIPER(...)
|
||||
|
||||
// define a static object with a caliper reference
|
||||
# define TIMEMORY_STATIC_BLANK_CALIPER(...)
|
||||
# define TIMEMORY_STATIC_BASIC_CALIPER(...)
|
||||
# define TIMEMORY_STATIC_CALIPER(...)
|
||||
# define TIMEMORY_STATIC_BLANK_CALIPER(...)
|
||||
# define TIMEMORY_STATIC_BASIC_CALIPER(...)
|
||||
# define TIMEMORY_STATIC_CALIPER(...)
|
||||
|
||||
// invoke member function on caliper reference or type within reference
|
||||
# define TIMEMORY_CALIPER_APPLY(...)
|
||||
# define TIMEMORY_CALIPER_TYPE_APPLY(...)
|
||||
# define TIMEMORY_CALIPER_APPLY(...)
|
||||
# define TIMEMORY_CALIPER_TYPE_APPLY(...)
|
||||
|
||||
// get an object
|
||||
# define TIMEMORY_BLANK_HANDLE(...) tim::dummy()
|
||||
# define TIMEMORY_BASIC_HANDLE(...) tim::dummy()
|
||||
# define TIMEMORY_HANDLE(...) tim::dummy()
|
||||
# define TIMEMORY_BLANK_HANDLE(...) tim::dummy()
|
||||
# define TIMEMORY_BASIC_HANDLE(...) tim::dummy()
|
||||
# define TIMEMORY_HANDLE(...) tim::dummy()
|
||||
|
||||
// get a pointer to an object
|
||||
# define TIMEMORY_BLANK_POINTER_HANDLE(...) nullptr
|
||||
# define TIMEMORY_BASIC_POINTER_HANDLE(...) nullptr
|
||||
# define TIMEMORY_POINTER_HANDLE(...) nullptr
|
||||
# define TIMEMORY_BLANK_POINTER_HANDLE(...) nullptr
|
||||
# define TIMEMORY_BASIC_POINTER_HANDLE(...) nullptr
|
||||
# define TIMEMORY_POINTER_HANDLE(...) nullptr
|
||||
|
||||
// debug only
|
||||
# define TIMEMORY_DEBUG_BLANK_MARKER(...)
|
||||
# define TIMEMORY_DEBUG_BASIC_MARKER(...)
|
||||
# define TIMEMORY_DEBUG_MARKER(...)
|
||||
# define TIMEMORY_DEBUG_BLANK_MARKER(...)
|
||||
# define TIMEMORY_DEBUG_BASIC_MARKER(...)
|
||||
# define TIMEMORY_DEBUG_MARKER(...)
|
||||
|
||||
// auto-timers
|
||||
# define TIMEMORY_BLANK_AUTO_TIMER(...)
|
||||
# define TIMEMORY_BASIC_AUTO_TIMER(...)
|
||||
# define TIMEMORY_AUTO_TIMER(...)
|
||||
# define TIMEMORY_BLANK_AUTO_TIMER_HANDLE(...)
|
||||
# define TIMEMORY_BASIC_AUTO_TIMER_HANDLE(...)
|
||||
# define TIMEMORY_AUTO_TIMER_HANDLE(...)
|
||||
# define TIMEMORY_DEBUG_BASIC_AUTO_TIMER(...)
|
||||
# define TIMEMORY_DEBUG_AUTO_TIMER(...)
|
||||
# define TIMEMORY_BLANK_AUTO_TIMER(...)
|
||||
# define TIMEMORY_BASIC_AUTO_TIMER(...)
|
||||
# define TIMEMORY_AUTO_TIMER(...)
|
||||
# define TIMEMORY_BLANK_AUTO_TIMER_HANDLE(...)
|
||||
# define TIMEMORY_BASIC_AUTO_TIMER_HANDLE(...)
|
||||
# define TIMEMORY_AUTO_TIMER_HANDLE(...)
|
||||
# define TIMEMORY_DEBUG_BASIC_AUTO_TIMER(...)
|
||||
# define TIMEMORY_DEBUG_AUTO_TIMER(...)
|
||||
|
||||
using G4AutoTimer = tim::dummy;
|
||||
|
||||
@@ -161,4 +159,3 @@ using G4AutoTimer = tim::dummy;
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -23,11 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
// Class G4Timer
|
||||
// G4Timer
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
@@ -70,38 +66,39 @@
|
||||
// tms fStartTimes,fEndTimes
|
||||
// Timing structures (see times(2)) for start and end times
|
||||
|
||||
// History:
|
||||
// 23.08.96 P.Kent Updated to also computed real elapsed time
|
||||
// 21.08.95 P.Kent
|
||||
// 29.04.97 G.Cosmo Added timings for Windows/NT
|
||||
|
||||
// Author: P.Kent, 21.08.95 - First implementation
|
||||
// Revision: G.Cosmo, 29.04.97 - Added timings for Windows
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4TIMER_HH
|
||||
#define G4TIMER_HH
|
||||
#define G4TIMER_HH 1
|
||||
|
||||
#ifndef WIN32
|
||||
# include <unistd.h>
|
||||
# include <sys/times.h>
|
||||
# include <unistd.h>
|
||||
#else
|
||||
# include <time.h>
|
||||
# define _SC_CLK_TCK 1
|
||||
# define _SC_CLK_TCK 1
|
||||
|
||||
extern "C" {
|
||||
int sysconf(int);
|
||||
};
|
||||
extern "C"
|
||||
{
|
||||
int sysconf(int);
|
||||
};
|
||||
|
||||
// Structure returned by times()
|
||||
|
||||
struct tms {
|
||||
clock_t tms_utime; /* user time */
|
||||
clock_t tms_stime; /* system time */
|
||||
clock_t tms_cutime; /* user time, children */
|
||||
clock_t tms_cstime; /* system time, children */
|
||||
};
|
||||
// Structure returned by times()
|
||||
|
||||
extern "C" {
|
||||
extern clock_t times(struct tms *);
|
||||
};
|
||||
#endif /* WIN32 */
|
||||
struct tms
|
||||
{
|
||||
clock_t tms_utime; /* user time */
|
||||
clock_t tms_stime; /* system time */
|
||||
clock_t tms_cutime; /* user time, children */
|
||||
clock_t tms_cstime; /* system time, children */
|
||||
};
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern clock_t times(struct tms*);
|
||||
};
|
||||
#endif /* WIN32 */
|
||||
|
||||
#include "G4Types.hh"
|
||||
#include "G4ios.hh"
|
||||
@@ -110,28 +107,26 @@
|
||||
|
||||
class G4Timer
|
||||
{
|
||||
typedef std::chrono::high_resolution_clock clock_type;
|
||||
using clock_type = std::chrono::high_resolution_clock;
|
||||
|
||||
public:
|
||||
public:
|
||||
G4Timer();
|
||||
|
||||
G4Timer();
|
||||
inline void Start();
|
||||
inline void Stop();
|
||||
inline G4bool IsValid() const;
|
||||
inline const char* GetClockTime() const;
|
||||
G4double GetRealElapsed() const;
|
||||
G4double GetSystemElapsed() const;
|
||||
G4double GetUserElapsed() const;
|
||||
|
||||
inline void Start();
|
||||
inline void Stop();
|
||||
inline G4bool IsValid() const;
|
||||
inline const char* GetClockTime() const;
|
||||
G4double GetRealElapsed() const;
|
||||
G4double GetSystemElapsed() const;
|
||||
G4double GetUserElapsed() const;
|
||||
|
||||
private:
|
||||
|
||||
G4bool fValidTimes;
|
||||
std::chrono::time_point<clock_type> fStartRealTime, fEndRealTime;
|
||||
tms fStartTimes,fEndTimes;
|
||||
private:
|
||||
G4bool fValidTimes;
|
||||
std::chrono::time_point<clock_type> fStartRealTime, fEndRealTime;
|
||||
tms fStartTimes, fEndTimes;
|
||||
};
|
||||
|
||||
std::ostream& operator << (std::ostream& os, const G4Timer& t);
|
||||
std::ostream& operator<<(std::ostream& os, const G4Timer& t);
|
||||
|
||||
#include "G4Timer.icc"
|
||||
|
||||
|
||||
@@ -23,41 +23,34 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4Timer inline methods implementations
|
||||
//
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class inline implementation
|
||||
// ------------------------------------------------------------
|
||||
// Author: P.Kent, 21.08.95 - First implementation
|
||||
// Revision: G.Cosmo, 29.04.97 - Added timings for Windows
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline
|
||||
void G4Timer::Start()
|
||||
inline void G4Timer::Start()
|
||||
{
|
||||
fValidTimes=false;
|
||||
fValidTimes = false;
|
||||
times(&fStartTimes);
|
||||
fStartRealTime = clock_type::now();
|
||||
}
|
||||
|
||||
inline
|
||||
void G4Timer::Stop()
|
||||
inline void G4Timer::Stop()
|
||||
{
|
||||
times(&fEndTimes);
|
||||
fEndRealTime = clock_type::now();
|
||||
fValidTimes=true;
|
||||
fValidTimes = true;
|
||||
}
|
||||
|
||||
inline
|
||||
G4bool G4Timer::IsValid() const
|
||||
{
|
||||
return fValidTimes;
|
||||
}
|
||||
inline G4bool G4Timer::IsValid() const { return fValidTimes; }
|
||||
|
||||
inline const char* G4Timer::GetClockTime() const
|
||||
{
|
||||
time_t rawtime;
|
||||
struct tm * timeinfo;
|
||||
struct tm* timeinfo;
|
||||
|
||||
time ( &rawtime );
|
||||
timeinfo = localtime ( &rawtime );
|
||||
return asctime (timeinfo);
|
||||
time(&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
return asctime(timeinfo);
|
||||
}
|
||||
|
||||
@@ -23,78 +23,78 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4Tokenizer
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4Tokenizer
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// String tokenizer.
|
||||
// It derives from the implementation of the Rogue Wave
|
||||
// RWTokenizer. It intrinsically uses STL string.
|
||||
// String tokenizer.
|
||||
// It derives from the implementation of the Rogue Wave RWTokenizer.
|
||||
// It intrinsically uses STL string.
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
#ifndef __G4Tokenizer
|
||||
#define __G4Tokenizer
|
||||
// Author: G.Cosmo, 11 October 2001
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4Tokenizer_hh
|
||||
#define G4Tokenizer_hh 1
|
||||
|
||||
#include "G4String.hh"
|
||||
|
||||
class G4Tokenizer
|
||||
class G4Tokenizer
|
||||
{
|
||||
public:
|
||||
G4Tokenizer(const G4String& stn):string2tokenize(stn),actual(0){}
|
||||
public:
|
||||
G4Tokenizer(const G4String& stn)
|
||||
: string2tokenize(stn)
|
||||
, actual(0)
|
||||
{}
|
||||
|
||||
G4String operator()(const char* str=" \t\n",size_t l=0)
|
||||
G4String operator()(const char* str = " \t\n", std::size_t l = 0)
|
||||
{
|
||||
std::size_t i, j, tmp;
|
||||
G4bool hasws = false;
|
||||
if(l == 0)
|
||||
l = strlen(str);
|
||||
|
||||
// Skip leading delimeters
|
||||
while(actual < string2tokenize.size())
|
||||
{
|
||||
size_t i,j,tmp;
|
||||
G4bool hasws=false;
|
||||
if(l==0) l=strlen(str);
|
||||
//Skip leading delimeters
|
||||
while(actual<string2tokenize.size())
|
||||
{
|
||||
|
||||
for(i=0;i<l;i++)
|
||||
if(string2tokenize[actual]==str[i]) hasws=true;
|
||||
if(hasws)
|
||||
{
|
||||
actual++;
|
||||
hasws=false;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
for(j=actual;j<string2tokenize.size();j++)
|
||||
{
|
||||
for(i=0;i<l;i++)
|
||||
if(string2tokenize[j]==str[i]) break;
|
||||
if(i<l) break;
|
||||
}
|
||||
if(j!=string2tokenize.size())
|
||||
{
|
||||
tmp=actual;
|
||||
actual=j+1;
|
||||
return string2tokenize(tmp,j-tmp);
|
||||
}
|
||||
for(i = 0; i < l; ++i)
|
||||
{
|
||||
if(string2tokenize[actual] == str[i])
|
||||
hasws = true;
|
||||
}
|
||||
if(hasws)
|
||||
{
|
||||
++actual;
|
||||
hasws = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp=actual;
|
||||
actual=j;
|
||||
return string2tokenize(tmp,j-tmp);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
private:
|
||||
for(j = actual; j < string2tokenize.size(); ++j)
|
||||
{
|
||||
for(i = 0; i < l; ++i)
|
||||
if(string2tokenize[j] == str[i])
|
||||
break;
|
||||
if(i < l)
|
||||
break;
|
||||
}
|
||||
if(j != string2tokenize.size())
|
||||
{
|
||||
tmp = actual;
|
||||
actual = j + 1;
|
||||
return string2tokenize(tmp, j - tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = actual;
|
||||
actual = j;
|
||||
return string2tokenize(tmp, j - tmp);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
G4String string2tokenize;
|
||||
size_t actual;
|
||||
|
||||
std::size_t actual;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -23,21 +23,16 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// G4TwoVector class, typedef to CLHEP Hep2Vector
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
// G4TwoVector, a typedef to CLHEP Hep2Vector
|
||||
|
||||
// Author: G.Cosmo (CERN), 1997
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4TWOVECTOR_HH
|
||||
#define G4TWOVECTOR_HH
|
||||
#define G4TWOVECTOR_HH 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include <CLHEP/Vector/TwoVector.h>
|
||||
|
||||
typedef CLHEP::Hep2Vector G4TwoVector;
|
||||
using G4TwoVector = CLHEP::Hep2Vector;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,49 +23,49 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4Types
|
||||
//
|
||||
//
|
||||
//
|
||||
// GEANT4 native types
|
||||
//
|
||||
// Definition of global GEANT4 native types
|
||||
|
||||
// Author: G.Cosmo (CERN), 1995
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4TYPES_HH
|
||||
#define G4TYPES_HH
|
||||
#define G4TYPES_HH 1
|
||||
|
||||
// Fundamental definitions
|
||||
#ifndef G4GMAKE
|
||||
#include "G4GlobalConfig.hh"
|
||||
# include "G4GlobalConfig.hh"
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
// Disable warning C4786 on WIN32 architectures:
|
||||
// identifier was truncated to '255' characters
|
||||
// in the debug information
|
||||
//
|
||||
#pragma warning ( disable : 4786 )
|
||||
//
|
||||
// Define DLL export macro for WIN32 systems for
|
||||
// importing/exporting external symbols to DLLs
|
||||
//
|
||||
#if defined G4LIB_BUILD_DLL && !defined G4MULTITHREADED
|
||||
#define G4DLLEXPORT __declspec( dllexport )
|
||||
#define G4DLLIMPORT __declspec( dllimport )
|
||||
#else
|
||||
#define G4DLLEXPORT
|
||||
#define G4DLLIMPORT
|
||||
#endif
|
||||
//
|
||||
// Unique identifier for global module
|
||||
//
|
||||
#if defined G4GLOB_ALLOC_EXPORT
|
||||
#define G4GLOB_DLL G4DLLEXPORT
|
||||
#else
|
||||
#define G4GLOB_DLL G4DLLIMPORT
|
||||
#endif
|
||||
// Disable warning C4786 on WIN32 architectures:
|
||||
// identifier was truncated to '255' characters
|
||||
// in the debug information
|
||||
//
|
||||
# pragma warning(disable : 4786)
|
||||
//
|
||||
// Define DLL export macro for WIN32 systems for
|
||||
// importing/exporting external symbols to DLLs
|
||||
//
|
||||
# if defined G4LIB_BUILD_DLL && !defined G4MULTITHREADED
|
||||
# define G4DLLEXPORT __declspec(dllexport)
|
||||
# define G4DLLIMPORT __declspec(dllimport)
|
||||
# else
|
||||
# define G4DLLEXPORT
|
||||
# define G4DLLIMPORT
|
||||
# endif
|
||||
//
|
||||
// Unique identifier for global module
|
||||
//
|
||||
# if defined G4GLOB_ALLOC_EXPORT
|
||||
# define G4GLOB_DLL G4DLLEXPORT
|
||||
# else
|
||||
# define G4GLOB_DLL G4DLLIMPORT
|
||||
# endif
|
||||
#else
|
||||
#define G4DLLEXPORT
|
||||
#define G4DLLIMPORT
|
||||
#define G4GLOB_DLL
|
||||
# define G4DLLEXPORT
|
||||
# define G4DLLIMPORT
|
||||
# define G4GLOB_DLL
|
||||
#endif
|
||||
|
||||
#include <complex>
|
||||
@@ -77,12 +77,12 @@
|
||||
// Typedefs to decouple from library classes
|
||||
// Typedefs for numeric types
|
||||
//
|
||||
typedef double G4double;
|
||||
typedef float G4float;
|
||||
typedef int G4int;
|
||||
typedef bool G4bool;
|
||||
typedef long G4long;
|
||||
typedef std::complex<G4double> G4complex;
|
||||
using G4double = double;
|
||||
using G4float = float;
|
||||
using G4int = int;
|
||||
using G4bool = bool;
|
||||
using G4long = long;
|
||||
using G4complex = std::complex<G4double>;
|
||||
|
||||
// Forward declation of void type argument for usage in direct object
|
||||
// persistency to define fake default constructors
|
||||
|
||||
@@ -23,17 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// -----------------------------------------------------------------
|
||||
//
|
||||
// ------------------- class G4UnitsTable -----------------
|
||||
//
|
||||
// 17-05-98: first version, M.Maire
|
||||
// 13-10-98: Units and symbols printed in fixed length, M.Maire
|
||||
// 18-01-00: BestUnit for three vector, M.Maire
|
||||
// 06-03-01: Migrated to STL vectors, G.Cosmo
|
||||
// G4UnitsTable
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
@@ -43,167 +33,154 @@
|
||||
// The Units are grouped by category. The TableOfUnits is a list of categories.
|
||||
// The class G4BestUnit allows to convert automaticaly a physical quantity
|
||||
// from its internal value into the most appropriate Unit of the same category.
|
||||
//
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
||||
// Author: M.Maire, 17.05.1998 - First version
|
||||
// Revisions: G.Cosmo, 06.03.2001 - Migrated to STL vectors
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4UnitsTable_hh
|
||||
#define G4UnitsTable_hh 1
|
||||
|
||||
#ifndef G4UnitsTable_HH
|
||||
#define G4UnitsTable_HH
|
||||
|
||||
#include "globals.hh"
|
||||
#include <vector>
|
||||
|
||||
#include "G4ThreeVector.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
class G4UnitsCategory;
|
||||
class G4UnitDefinition;
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
|
||||
class G4UnitsTable : public std::vector<G4UnitsCategory*>
|
||||
{
|
||||
public:
|
||||
using std::vector<G4UnitsCategory*>::vector;
|
||||
G4UnitsTable();
|
||||
~G4UnitsTable();
|
||||
public:
|
||||
using std::vector<G4UnitsCategory*>::vector;
|
||||
G4UnitsTable();
|
||||
~G4UnitsTable();
|
||||
|
||||
public:
|
||||
void Synchronize();
|
||||
G4bool Contains(const G4UnitDefinition*,const G4String&);
|
||||
public:
|
||||
void Synchronize();
|
||||
G4bool Contains(const G4UnitDefinition*, const G4String&);
|
||||
};
|
||||
#else
|
||||
typedef std::vector<G4UnitsCategory*> G4UnitsTable;
|
||||
|
||||
using G4UnitsTable = std::vector<G4UnitsCategory*>;
|
||||
|
||||
#endif
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
class G4UnitDefinition
|
||||
{
|
||||
public: // with description
|
||||
public:
|
||||
G4UnitDefinition(const G4String& name, const G4String& symbol,
|
||||
const G4String& category, G4double value);
|
||||
|
||||
G4UnitDefinition(const G4String& name, const G4String& symbol,
|
||||
const G4String& category, G4double value);
|
||||
~G4UnitDefinition();
|
||||
G4bool operator==(const G4UnitDefinition&) const;
|
||||
G4bool operator!=(const G4UnitDefinition&) const;
|
||||
|
||||
public: // without description
|
||||
inline const G4String& GetName() const;
|
||||
inline const G4String& GetSymbol() const;
|
||||
inline G4double GetValue() const;
|
||||
|
||||
~G4UnitDefinition();
|
||||
G4bool operator==(const G4UnitDefinition&) const;
|
||||
G4bool operator!=(const G4UnitDefinition&) const;
|
||||
void PrintDefinition();
|
||||
|
||||
public: // with description
|
||||
static void BuildUnitsTable();
|
||||
static void PrintUnitsTable();
|
||||
static void ClearUnitsTable();
|
||||
|
||||
inline const G4String& GetName() const;
|
||||
inline const G4String& GetSymbol() const;
|
||||
inline G4double GetValue() const;
|
||||
static G4UnitsTable& GetUnitsTable();
|
||||
|
||||
void PrintDefinition();
|
||||
static G4bool IsUnitDefined(const G4String&);
|
||||
static G4double GetValueOf(const G4String&);
|
||||
static G4String GetCategory(const G4String&);
|
||||
|
||||
static void BuildUnitsTable();
|
||||
static void PrintUnitsTable();
|
||||
static void ClearUnitsTable();
|
||||
private:
|
||||
G4UnitDefinition(const G4UnitDefinition&);
|
||||
G4UnitDefinition& operator=(const G4UnitDefinition&);
|
||||
|
||||
static G4UnitsTable& GetUnitsTable();
|
||||
private:
|
||||
G4String Name; // SI name
|
||||
G4String SymbolName; // SI symbol
|
||||
G4double Value = 0.0; // value in the internal system of units
|
||||
|
||||
static G4bool IsUnitDefined(const G4String&);
|
||||
static G4double GetValueOf (const G4String&);
|
||||
static G4String GetCategory(const G4String&);
|
||||
static G4ThreadLocal G4UnitsTable* pUnitsTable; // table of Units
|
||||
static G4ThreadLocal G4bool unitsTableDestroyed;
|
||||
|
||||
private:
|
||||
|
||||
G4UnitDefinition(const G4UnitDefinition&);
|
||||
G4UnitDefinition& operator=(const G4UnitDefinition&);
|
||||
|
||||
private:
|
||||
|
||||
G4String Name; // SI name
|
||||
G4String SymbolName; // SI symbol
|
||||
G4double Value; // value in the internal system of units
|
||||
|
||||
static G4ThreadLocal G4UnitsTable *pUnitsTable; // table of Units
|
||||
static G4ThreadLocal G4bool unitsTableDestroyed;
|
||||
|
||||
size_t CategoryIndex; // category index of this unit
|
||||
std::size_t CategoryIndex = 0; // category index of this unit
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
static G4UnitsTable *pUnitsTableShadow; // shadow of table of Units
|
||||
public:
|
||||
inline static G4UnitsTable& GetUnitsTableShadow()
|
||||
{return *pUnitsTableShadow;}
|
||||
static G4UnitsTable* pUnitsTableShadow; // shadow of table of Units
|
||||
|
||||
public:
|
||||
inline static G4UnitsTable& GetUnitsTableShadow()
|
||||
{
|
||||
return *pUnitsTableShadow;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
typedef std::vector<G4UnitDefinition*> G4UnitsContainer;
|
||||
using G4UnitsContainer = std::vector<G4UnitDefinition*>;
|
||||
|
||||
class G4UnitsCategory
|
||||
{
|
||||
public: // without description
|
||||
public:
|
||||
explicit G4UnitsCategory(const G4String& name);
|
||||
~G4UnitsCategory();
|
||||
G4bool operator==(const G4UnitsCategory&) const;
|
||||
G4bool operator!=(const G4UnitsCategory&) const;
|
||||
|
||||
explicit G4UnitsCategory(const G4String& name);
|
||||
~G4UnitsCategory();
|
||||
G4bool operator==(const G4UnitsCategory&) const;
|
||||
G4bool operator!=(const G4UnitsCategory&) const;
|
||||
inline const G4String& GetName() const;
|
||||
inline G4UnitsContainer& GetUnitsList();
|
||||
inline G4int GetNameMxLen() const;
|
||||
inline G4int GetSymbMxLen() const;
|
||||
inline void UpdateNameMxLen(G4int len);
|
||||
inline void UpdateSymbMxLen(G4int len);
|
||||
void PrintCategory();
|
||||
|
||||
public: // without description
|
||||
private:
|
||||
G4UnitsCategory(const G4UnitsCategory&);
|
||||
G4UnitsCategory& operator=(const G4UnitsCategory&);
|
||||
|
||||
inline const G4String& GetName() const;
|
||||
inline G4UnitsContainer& GetUnitsList();
|
||||
inline G4int GetNameMxLen() const;
|
||||
inline G4int GetSymbMxLen() const;
|
||||
inline void UpdateNameMxLen(G4int len);
|
||||
inline void UpdateSymbMxLen(G4int len);
|
||||
void PrintCategory();
|
||||
|
||||
private:
|
||||
|
||||
G4UnitsCategory(const G4UnitsCategory&);
|
||||
G4UnitsCategory& operator=(const G4UnitsCategory&);
|
||||
|
||||
private:
|
||||
|
||||
G4String Name; // dimensional family: Length,Volume,Energy
|
||||
G4UnitsContainer UnitsList; // List of units in this family
|
||||
G4int NameMxLen; // max length of the units name
|
||||
G4int SymbMxLen; // max length of the units symbol
|
||||
private:
|
||||
G4String Name; // dimensional family: Length,Volume,Energy
|
||||
G4UnitsContainer UnitsList; // List of units in this family
|
||||
G4int NameMxLen = 0; // max length of the units name
|
||||
G4int SymbMxLen = 0; // max length of the units symbol
|
||||
};
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
class G4BestUnit
|
||||
{
|
||||
public: // with description
|
||||
public:
|
||||
G4BestUnit(G4double internalValue, const G4String& category);
|
||||
G4BestUnit(const G4ThreeVector& internalValue, const G4String& category);
|
||||
// These constructors convert a physical quantity from its internalValue
|
||||
// into the most appropriate unit of the same category.
|
||||
// In practice it builds an object VU = (newValue, newUnit)
|
||||
|
||||
G4BestUnit(G4double internalValue, const G4String& category);
|
||||
G4BestUnit(const G4ThreeVector& internalValue, const G4String& category);
|
||||
// These constructors convert a physical quantity from its internalValue
|
||||
// into the most appropriate unit of the same category.
|
||||
// In practice it builds an object VU = (newValue, newUnit)
|
||||
~G4BestUnit();
|
||||
|
||||
~G4BestUnit();
|
||||
inline G4double* GetValue();
|
||||
inline const G4String& GetCategory() const;
|
||||
inline std::size_t GetIndexOfCategory() const;
|
||||
operator G4String() const; // Conversion to best string.
|
||||
|
||||
public: // without description
|
||||
friend std::ostream& operator<<(std::ostream&, G4BestUnit VU);
|
||||
// Default format to print the objet VU above.
|
||||
|
||||
inline G4double* GetValue();
|
||||
inline const G4String& GetCategory() const;
|
||||
inline size_t GetIndexOfCategory() const;
|
||||
operator G4String () const; // Conversion to best string.
|
||||
|
||||
public: // with description
|
||||
|
||||
friend std::ostream& operator<<(std::ostream&,G4BestUnit VU);
|
||||
// Default format to print the objet VU above.
|
||||
|
||||
private:
|
||||
|
||||
G4double Value[3]; // value in the internal system of units
|
||||
G4int nbOfVals; // G4double=1; G4ThreeVector=3
|
||||
G4String Category; // dimensional family: Length,Volume,Energy ...
|
||||
size_t IndexOfCategory; // position of Category in UnitsTable
|
||||
private:
|
||||
G4double Value[3]; // value in the internal system of units
|
||||
G4int nbOfVals = 0; // G4double=1; G4ThreeVector=3
|
||||
G4String Category; // dimensional family: Length,Volume,Energy ...
|
||||
std::size_t IndexOfCategory = 0; // position of Category in UnitsTable
|
||||
};
|
||||
|
||||
#include "G4UnitsTable.icc"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,89 +23,58 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4UnitsTable inline methods implementation
|
||||
//
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class inline implementation
|
||||
// ------------------------------------------------------------
|
||||
// Author: M.Maire, 17.05.1998 - First version
|
||||
// Revisions: G.Cosmo, 06.03.2001 - Migrated to STL vectors
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// --------------------
|
||||
// --- G4UnitDefinition
|
||||
// --------------------
|
||||
// ---------------------
|
||||
// --- G4UnitsDefinition
|
||||
// ---------------------
|
||||
|
||||
inline
|
||||
const G4String& G4UnitDefinition::GetName() const
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
inline const G4String& G4UnitDefinition::GetName() const { return Name; }
|
||||
|
||||
inline
|
||||
const G4String& G4UnitDefinition::GetSymbol() const
|
||||
inline const G4String& G4UnitDefinition::GetSymbol() const
|
||||
{
|
||||
return SymbolName;
|
||||
}
|
||||
|
||||
inline
|
||||
G4double G4UnitDefinition::GetValue() const
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
inline G4double G4UnitDefinition::GetValue() const { return Value; }
|
||||
|
||||
// -------------------
|
||||
// --- G4UnitsCategory
|
||||
// -------------------
|
||||
|
||||
inline
|
||||
const G4String& G4UnitsCategory::GetName() const
|
||||
inline const G4String& G4UnitsCategory::GetName() const { return Name; }
|
||||
|
||||
inline G4UnitsContainer& G4UnitsCategory::GetUnitsList() { return UnitsList; }
|
||||
|
||||
inline G4int G4UnitsCategory::GetNameMxLen() const { return NameMxLen; }
|
||||
|
||||
inline G4int G4UnitsCategory::GetSymbMxLen() const { return SymbMxLen; }
|
||||
|
||||
inline void G4UnitsCategory::UpdateNameMxLen(G4int len)
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
inline
|
||||
G4UnitsContainer& G4UnitsCategory::GetUnitsList()
|
||||
{
|
||||
return UnitsList;
|
||||
if(NameMxLen < len)
|
||||
{
|
||||
NameMxLen = len;
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
G4int G4UnitsCategory::GetNameMxLen() const
|
||||
inline void G4UnitsCategory::UpdateSymbMxLen(G4int len)
|
||||
{
|
||||
return NameMxLen;
|
||||
if(SymbMxLen < len)
|
||||
{
|
||||
SymbMxLen = len;
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
G4int G4UnitsCategory::GetSymbMxLen() const
|
||||
{
|
||||
return SymbMxLen;
|
||||
}
|
||||
inline G4double* G4BestUnit::GetValue() { return Value; }
|
||||
|
||||
inline
|
||||
void G4UnitsCategory::UpdateNameMxLen(G4int len)
|
||||
{
|
||||
if (NameMxLen<len) { NameMxLen=len; }
|
||||
}
|
||||
inline const G4String& G4BestUnit::GetCategory() const { return Category; }
|
||||
|
||||
inline
|
||||
void G4UnitsCategory::UpdateSymbMxLen(G4int len)
|
||||
{
|
||||
if (SymbMxLen<len) { SymbMxLen=len; }
|
||||
}
|
||||
|
||||
inline
|
||||
G4double* G4BestUnit::GetValue()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
|
||||
inline
|
||||
const G4String& G4BestUnit::GetCategory() const
|
||||
{
|
||||
return Category;
|
||||
}
|
||||
|
||||
inline
|
||||
size_t G4BestUnit::GetIndexOfCategory() const
|
||||
inline std::size_t G4BestUnit::GetIndexOfCategory() const
|
||||
{
|
||||
return IndexOfCategory;
|
||||
}
|
||||
|
||||
@@ -23,31 +23,27 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// class G4UserLimits
|
||||
// G4UserLimits
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// Simple placeholder for user Step limitations
|
||||
// In order to activate these limitations, users need to register
|
||||
// their "special" processes to each particle they want.
|
||||
// Sample processes below can be found under processes/transportation
|
||||
// their "special" processes to each particle wanted.
|
||||
// Sample processes below can be found under processes/transportation
|
||||
// MaxAllowedStep : UserStepLimit
|
||||
// other limitation : UserSpecialCuts
|
||||
// In addition, users can add their own Step limitations by creating
|
||||
// new class derived from G4UserLimits. In these case, fType member
|
||||
// is supposed to be used to identify class.
|
||||
//
|
||||
// Author: Paul Kent August 96
|
||||
//
|
||||
// 01-11-97: change GetMaxAllowedStep(), Hisaya Kurashige
|
||||
// 08-04-98: new data members, mma
|
||||
// 02-16-00: add fType member and accessors, Hisaya Kurashige
|
||||
//
|
||||
// In addition, users can add their own Step limitations by creating
|
||||
// a new class derived from G4UserLimits. In these case, 'fType' member
|
||||
// is supposed to be used to identify the class.
|
||||
|
||||
// Author: Paul Kent, August 1996
|
||||
// Revisions:
|
||||
// - 01-11-1997, H.Kurashige: changed GetMaxAllowedStep()
|
||||
// - 08-04-1998: M.Maire: new data members
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4USERLIMITS_HH
|
||||
#define G4USERLIMITS_HH
|
||||
#define G4USERLIMITS_HH 1
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
@@ -55,56 +51,46 @@ class G4Track;
|
||||
|
||||
class G4UserLimits
|
||||
{
|
||||
public: // with description
|
||||
|
||||
G4UserLimits(G4double ustepMax = DBL_MAX,
|
||||
G4double utrakMax = DBL_MAX,
|
||||
G4double utimeMax = DBL_MAX,
|
||||
G4double uekinMin = 0.,
|
||||
G4double urangMin = 0. );
|
||||
G4UserLimits(const G4String& type,
|
||||
G4double ustepMax = DBL_MAX,
|
||||
G4double utrakMax = DBL_MAX,
|
||||
G4double utimeMax = DBL_MAX,
|
||||
G4double uekinMin = 0.,
|
||||
G4double urangMin = 0. );
|
||||
public:
|
||||
G4UserLimits(G4double ustepMax = DBL_MAX, G4double utrakMax = DBL_MAX,
|
||||
G4double utimeMax = DBL_MAX, G4double uekinMin = 0.,
|
||||
G4double urangMin = 0.);
|
||||
G4UserLimits(const G4String& type, G4double ustepMax = DBL_MAX,
|
||||
G4double utrakMax = DBL_MAX, G4double utimeMax = DBL_MAX,
|
||||
G4double uekinMin = 0., G4double urangMin = 0.);
|
||||
virtual ~G4UserLimits();
|
||||
|
||||
public: // with description
|
||||
|
||||
virtual G4double GetMaxAllowedStep(const G4Track&);
|
||||
// If a Logical Volume has a G4UserLimits object, the Step length can
|
||||
// be limited as shorter than MaxAllowedStep in the volume.
|
||||
|
||||
//
|
||||
virtual G4double GetUserMaxTrackLength(const G4Track&) ;
|
||||
virtual G4double GetUserMaxTime (const G4Track&);
|
||||
virtual G4double GetMaxAllowedStep(const G4Track&);
|
||||
// If a logical volume has a G4UserLimits object, the Step length can
|
||||
// be limited as shorter than MaxAllowedStep in the volume
|
||||
|
||||
virtual G4double GetUserMaxTrackLength(const G4Track&);
|
||||
virtual G4double GetUserMaxTime(const G4Track&);
|
||||
virtual G4double GetUserMinEkine(const G4Track&);
|
||||
virtual G4double GetUserMinRange(const G4Track&);
|
||||
|
||||
virtual void SetMaxAllowedStep(G4double ustepMax);
|
||||
|
||||
virtual void SetMaxAllowedStep(G4double ustepMax);
|
||||
virtual void SetUserMaxTrackLength(G4double utrakMax);
|
||||
virtual void SetUserMaxTime(G4double utimeMax);
|
||||
virtual void SetUserMinEkine(G4double uekinMin);
|
||||
virtual void SetUserMinRange(G4double urangMin);
|
||||
|
||||
const G4String & GetType() const;
|
||||
void SetType(const G4String& type);
|
||||
const G4String& GetType() const;
|
||||
void SetType(const G4String& type);
|
||||
// Set/Get type name for UserLimits.
|
||||
// This type member is supposed to be used to check real class types for
|
||||
// each concrete instantiation of G4UserLimits. In other words, users who
|
||||
// use special classes derived from this base class should name their class
|
||||
// with a proper identifier.
|
||||
|
||||
protected: // with description
|
||||
// use special classes derived from this base class should name their
|
||||
// class with a proper identifier
|
||||
|
||||
G4double fMaxStep; // max allowed Step size in this volume
|
||||
G4double fMaxTrack; // max total track length
|
||||
G4double fMaxTime; // max time
|
||||
G4double fMinEkine; // min kinetic energy (only for charged particles)
|
||||
G4double fMinRange; // min remaining range (only for charged particles)
|
||||
protected:
|
||||
G4double fMaxStep = 0.; // max allowed Step size in this volume
|
||||
G4double fMaxTrack = 0.; // max total track length
|
||||
G4double fMaxTime = 0.; // max time
|
||||
G4double fMinEkine = 0.; // min kinetic energy (only for charged particles)
|
||||
G4double fMinRange = 0.; // min remaining range (only for charged particles)
|
||||
|
||||
G4String fType; // type name
|
||||
G4String fType; // type name
|
||||
};
|
||||
|
||||
#include "G4UserLimits.icc"
|
||||
|
||||
@@ -23,119 +23,116 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4UserLimits inline methods implementation
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// class G4UserLimits inline implementation
|
||||
//
|
||||
// 01-11-97: change GetMaxAllowedStep(), Hisaya Kurashige
|
||||
// 08-04-98: new data members, mma
|
||||
//
|
||||
// Author: Paul Kent, August 1996
|
||||
// Revisions:
|
||||
// - 01-11-1997, H.Kurashige: changed GetMaxAllowedStep()
|
||||
// - 08-04-1998: M.Maire: new data members
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
inline G4UserLimits::G4UserLimits(G4double ustepMax,
|
||||
G4double utrakMax,
|
||||
G4double utimeMax,
|
||||
G4double uekinMin,
|
||||
G4double urangMin)
|
||||
:fMaxStep (ustepMax),fMaxTrack(utrakMax),fMaxTime(utimeMax),
|
||||
fMinEkine(uekinMin),fMinRange(urangMin),fType("base")
|
||||
inline G4UserLimits::G4UserLimits(G4double ustepMax, G4double utrakMax,
|
||||
G4double utimeMax, G4double uekinMin,
|
||||
G4double urangMin)
|
||||
: fMaxStep(ustepMax)
|
||||
, fMaxTrack(utrakMax)
|
||||
, fMaxTime(utimeMax)
|
||||
, fMinEkine(uekinMin)
|
||||
, fMinRange(urangMin)
|
||||
, fType("base")
|
||||
{}
|
||||
|
||||
inline G4UserLimits::G4UserLimits(const G4String& type,
|
||||
G4double ustepMax,
|
||||
G4double utrakMax,
|
||||
G4double utimeMax,
|
||||
G4double uekinMin,
|
||||
G4double urangMin)
|
||||
:fMaxStep (ustepMax),fMaxTrack(utrakMax),fMaxTime(utimeMax),
|
||||
fMinEkine(uekinMin),fMinRange(urangMin),fType(type)
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline G4UserLimits::G4UserLimits(const G4String& type, G4double ustepMax,
|
||||
G4double utrakMax, G4double utimeMax,
|
||||
G4double uekinMin, G4double urangMin)
|
||||
: fMaxStep(ustepMax)
|
||||
, fMaxTrack(utrakMax)
|
||||
, fMaxTime(utimeMax)
|
||||
, fMinEkine(uekinMin)
|
||||
, fMinRange(urangMin)
|
||||
, fType(type)
|
||||
{}
|
||||
|
||||
inline const G4String& G4UserLimits::GetType() const
|
||||
{
|
||||
return fType;
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline void G4UserLimits::SetType(const G4String& type)
|
||||
{
|
||||
fType = type;
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
inline const G4String& G4UserLimits::GetType() const { return fType; }
|
||||
|
||||
inline G4UserLimits::~G4UserLimits(){}
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline void G4UserLimits::SetType(const G4String& type) { fType = type; }
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline G4UserLimits::~G4UserLimits() {}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
inline G4double G4UserLimits::GetMaxAllowedStep(const G4Track&)
|
||||
{
|
||||
return fMaxStep;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline G4double G4UserLimits::GetUserMaxTrackLength(const G4Track&)
|
||||
{
|
||||
return fMaxTrack;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline G4double G4UserLimits::GetUserMaxTime(const G4Track&)
|
||||
{
|
||||
return fMaxTime;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline G4double G4UserLimits::GetUserMinEkine(const G4Track&)
|
||||
{
|
||||
return fMinEkine;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline G4double G4UserLimits::GetUserMinRange(const G4Track&)
|
||||
{
|
||||
return fMinRange;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline void G4UserLimits::SetMaxAllowedStep(G4double ustepMax)
|
||||
{
|
||||
fMaxStep=ustepMax;
|
||||
fMaxStep = ustepMax;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline void G4UserLimits::SetUserMaxTrackLength(G4double utrakMax)
|
||||
{
|
||||
fMaxTrack=utrakMax;
|
||||
fMaxTrack = utrakMax;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline void G4UserLimits::SetUserMaxTime(G4double utimeMax)
|
||||
{
|
||||
fMaxTime=utimeMax;
|
||||
fMaxTime = utimeMax;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline void G4UserLimits::SetUserMinEkine(G4double uekinMin)
|
||||
{
|
||||
fMinEkine=uekinMin;
|
||||
fMinEkine = uekinMin;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
inline void G4UserLimits::SetUserMinRange(G4double urangMin)
|
||||
{
|
||||
fMinRange=urangMin;
|
||||
fMinRange = urangMin;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
@@ -23,60 +23,42 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
//
|
||||
// ---------------- G4VExceptionHandler ----------------
|
||||
//
|
||||
// Authors: M.Asai - August 2002
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// G4VExceptionHandler
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// Abstract base class which need to be notified when G4Exception occurs.
|
||||
// The concrete class object derived from this base class will be automatically
|
||||
// registered to G4StateManager and the virtual method Notify() will be invoked
|
||||
// when G4Exception occurs.
|
||||
// Abstract base class which needs to be notified when a G4Exception occurs.
|
||||
// The concrete class object derived from this base class will be
|
||||
// automatically registered to G4StateManager and the virtual method Notify()
|
||||
// will be invoked when the G4Exception occurs.
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// Author: M.Asai, August 2002
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4VExceptionHandler_hh
|
||||
#define G4VExceptionHandler_hh 1
|
||||
|
||||
#ifndef G4VExceptionHandler_h
|
||||
#define G4VExceptionHandler_h 1
|
||||
|
||||
#include "G4Types.hh"
|
||||
#include "G4ExceptionSeverity.hh"
|
||||
#include "G4Types.hh"
|
||||
|
||||
class G4VExceptionHandler
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
G4VExceptionHandler();
|
||||
virtual ~G4VExceptionHandler();
|
||||
G4bool operator==(const G4VExceptionHandler &right) const;
|
||||
G4bool operator!=(const G4VExceptionHandler &right) const;
|
||||
|
||||
public: // with description
|
||||
G4bool operator==(const G4VExceptionHandler& right) const;
|
||||
G4bool operator!=(const G4VExceptionHandler& right) const;
|
||||
|
||||
virtual G4bool Notify(const char* originOfException,
|
||||
const char* exceptionCode,
|
||||
G4ExceptionSeverity severity,
|
||||
const char* exceptionCode, G4ExceptionSeverity severity,
|
||||
const char* description) = 0;
|
||||
// Pure virtual method which will be invoked by G4StateManager when
|
||||
// G4Exception occurs.
|
||||
// If TRUE returned, core dump will be generated, while FALSE returned,
|
||||
// program execution continues.
|
||||
|
||||
private:
|
||||
|
||||
G4VExceptionHandler(const G4VExceptionHandler &right);
|
||||
G4VExceptionHandler& operator=(const G4VExceptionHandler &right);
|
||||
// Pure virtual method which will be invoked by G4StateManager when
|
||||
// a G4Exception occurs.
|
||||
// If TRUE is returned, a core dump will be generated,
|
||||
// while if FALSE is returned, program execution continues.
|
||||
|
||||
private:
|
||||
G4VExceptionHandler(const G4VExceptionHandler& right);
|
||||
G4VExceptionHandler& operator=(const G4VExceptionHandler& right);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,9 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
// class G4VNotifier
|
||||
// G4VNotifier
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
@@ -33,24 +31,22 @@
|
||||
// to be activated for example at registration/deregistration of objects
|
||||
// in stores.
|
||||
|
||||
// Author:
|
||||
// 01.09.04 G.Cosmo Initial version
|
||||
// Author: G.Cosmo, 01.09.2004 - Initial version
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4VNOTIFIER_HH
|
||||
#define G4VNOTIFIER_HH
|
||||
#define G4VNOTIFIER_HH 1
|
||||
|
||||
class G4VNotifier
|
||||
{
|
||||
public: // with description
|
||||
public:
|
||||
G4VNotifier();
|
||||
virtual ~G4VNotifier();
|
||||
// Constructor and destructor
|
||||
|
||||
G4VNotifier();
|
||||
virtual ~G4VNotifier();
|
||||
// Constructor and destructor.
|
||||
|
||||
virtual void NotifyRegistration() = 0;
|
||||
// Notification of object registration.
|
||||
virtual void NotifyDeRegistration() = 0;
|
||||
// Notification of object deregistration.
|
||||
virtual void NotifyRegistration() = 0;
|
||||
// Notification of object registration
|
||||
virtual void NotifyDeRegistration() = 0;
|
||||
// Notification of object deregistration
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,18 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
//
|
||||
// ---------------- G4VStateDependent ----------------
|
||||
//
|
||||
// Authors: G.Cosmo, M.Asai - November 1996
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// G4VStateDependent
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
@@ -43,38 +32,32 @@
|
||||
// this base class will be automatically registered to G4StateManager
|
||||
// and the virtual method Notify() will be invoked when the state changes.
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// Authors: G.Cosmo, M.Asai - November 1996
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4VStateDependent_hh
|
||||
#define G4VStateDependent_hh 1
|
||||
|
||||
#ifndef G4VStateDependent_h
|
||||
#define G4VStateDependent_h 1
|
||||
|
||||
#include "G4Types.hh"
|
||||
#include "G4ApplicationState.hh"
|
||||
#include "G4Types.hh"
|
||||
|
||||
class G4VStateDependent
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
explicit G4VStateDependent(G4bool bottom=false);
|
||||
public:
|
||||
explicit G4VStateDependent(G4bool bottom = false);
|
||||
virtual ~G4VStateDependent();
|
||||
G4bool operator==(const G4VStateDependent &right) const;
|
||||
G4bool operator!=(const G4VStateDependent &right) const;
|
||||
|
||||
public: // with description
|
||||
G4bool operator==(const G4VStateDependent& right) const;
|
||||
G4bool operator!=(const G4VStateDependent& right) const;
|
||||
|
||||
virtual G4bool Notify(G4ApplicationState requestedState) = 0;
|
||||
// Pure virtual method which will be invoked by G4StateManager.
|
||||
// In case state change must not be allowed by some reason of the
|
||||
// concrete class, false should be returned. But this scheme is
|
||||
// NOT recommended to use. All command which are state sensitive
|
||||
// MUST assign available state(s).
|
||||
|
||||
private:
|
||||
|
||||
G4VStateDependent(const G4VStateDependent &right);
|
||||
G4VStateDependent& operator=(const G4VStateDependent &right);
|
||||
// Pure virtual method which will be invoked by G4StateManager.
|
||||
// In case a state change must not be allowed by some reason of the
|
||||
// concrete class, false should be returned. But this scheme use is
|
||||
// NOT recommended. All commands which are state sensitive MUST assign
|
||||
// available state(s).
|
||||
|
||||
private:
|
||||
G4VStateDependent(const G4VStateDependent& right);
|
||||
G4VStateDependent& operator=(const G4VStateDependent& right);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,12 +23,12 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// Version information
|
||||
//
|
||||
// 26.09.05 K.Murakami - Created
|
||||
// Geant4 Version information
|
||||
|
||||
// Author: K.Murakami, 26.09.2005 - Created
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4VERSION_HH
|
||||
#define G4VERSION_HH
|
||||
#define G4VERSION_HH 1
|
||||
|
||||
// Numbering rule for "G4VERSION_NUMBER":
|
||||
// - The number is consecutive (i.e. 711) as an integer.
|
||||
@@ -40,23 +40,23 @@
|
||||
// |--> patch number
|
||||
|
||||
#ifndef G4VERSION_NUMBER
|
||||
#define G4VERSION_NUMBER 1062
|
||||
# define G4VERSION_NUMBER 1070
|
||||
#endif
|
||||
|
||||
#ifndef G4VERSION_TAG
|
||||
#define G4VERSION_TAG "$Name: geant4-10-06-patch-02 $"
|
||||
# define G4VERSION_TAG "$Name: geant4-10-07-beta-01 $"
|
||||
#endif
|
||||
|
||||
// as variables
|
||||
|
||||
#include "G4Types.hh"
|
||||
#include "G4String.hh"
|
||||
#include "G4Types.hh"
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
static const G4String G4Version = "$Name: geant4-10-06-patch-02 [MT]$";
|
||||
static const G4String G4Version = "$Name: geant4-10-07-beta-01 [MT]$";
|
||||
#else
|
||||
static const G4String G4Version = "$Name: geant4-10-06-patch-02 $";
|
||||
static const G4String G4Version = "$Name: geant4-10-07-beta-01 $";
|
||||
#endif
|
||||
static const G4String G4Date = "(29-May-2020)";
|
||||
static const G4String G4Date = "(26-June-2020)";
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,78 +23,73 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4coutDestination
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4coutDestination.hh
|
||||
//
|
||||
// Cout/cerr buffer containers
|
||||
|
||||
// Authors: H.Yoshida, M.Nagamatu - November 1998
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4COUTDESTINATION_HH
|
||||
#define G4COUTDESTINATION_HH
|
||||
#define G4COUTDESTINATION_HH 1
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
class G4coutDestination
|
||||
{
|
||||
public:
|
||||
public:
|
||||
G4coutDestination() = default;
|
||||
virtual ~G4coutDestination();
|
||||
// Note: limitation on ICC for MIC cannot use 'default'
|
||||
|
||||
G4coutDestination() = default;
|
||||
virtual ~G4coutDestination();
|
||||
// Note: limitation on ICC for MIC cannot use 'default';
|
||||
// The type of the functions defining a transformation of the message.
|
||||
// The function manipulates the input message, for example, to add a
|
||||
// prefix:
|
||||
// G4coutDestination::AddCoutTransformer(
|
||||
// [](G4String& msg) -> G4bool { msg="PREFIX "+msg; return true; }
|
||||
// );
|
||||
// Function should return false if message should not be processed
|
||||
// anymore and discarded
|
||||
//
|
||||
using Transformer = std::function<G4bool(G4String&)>;
|
||||
void AddCoutTransformer(const Transformer& t)
|
||||
{
|
||||
transformersCout.push_back(t);
|
||||
}
|
||||
void AddCoutTransformer(Transformer&& t) { transformersCout.push_back(t); }
|
||||
void AddCerrTransformer(const Transformer& t)
|
||||
{
|
||||
transformersCerr.push_back(t);
|
||||
}
|
||||
void AddCerrTransformer(Transformer&& t) { transformersCerr.push_back(t); }
|
||||
virtual void ResetTransformers();
|
||||
|
||||
// The type of the functions defining a transformation of the message.
|
||||
// The function manipulates the input message, for example, to add a prefix:
|
||||
// G4coutDestination::AddCoutTransformer(
|
||||
// [](G4String& msg) -> G4bool { msg="PREFIX "+msg; return true; }
|
||||
// );
|
||||
// Function should return false if message should not be processed
|
||||
// anymore and discarded
|
||||
//
|
||||
using Transformer=std::function<G4bool(G4String&)>;
|
||||
void AddCoutTransformer(const Transformer& t)
|
||||
{ transformersCout.push_back(t); }
|
||||
void AddCoutTransformer( Transformer&& t)
|
||||
{ transformersCout.push_back(t); }
|
||||
void AddCerrTransformer(const Transformer& t)
|
||||
{ transformersCerr.push_back(t); }
|
||||
void AddCerrTransformer( Transformer&& t)
|
||||
{ transformersCerr.push_back(t); }
|
||||
virtual void ResetTransformers();
|
||||
virtual G4int ReceiveG4cout(const G4String& msg);
|
||||
virtual G4int ReceiveG4cerr(const G4String& msg);
|
||||
// Derived class implements here handling of message.
|
||||
// For example, streaming on std::cout or file.
|
||||
// Return 0 for success, -1 otherwise
|
||||
|
||||
// Derived class implements here handling of message.
|
||||
// For example, streaming on std::cout or file.
|
||||
// Return 0 for success, -1 otherwise
|
||||
//
|
||||
virtual G4int ReceiveG4cout(const G4String& msg);
|
||||
virtual G4int ReceiveG4cerr(const G4String& msg);
|
||||
G4int ReceiveG4cout_(const G4String& msg);
|
||||
// Method called by G4strbuf when need to handle a message
|
||||
|
||||
// Methods called by G4strbuf when need to handle a message
|
||||
//
|
||||
G4int ReceiveG4cout_(const G4String& msg);
|
||||
G4int ReceiveG4cerr_(const G4String& msg);
|
||||
// Transformers cannot remove an error message from stream
|
||||
|
||||
// Transformers cannot remove an error message from stream
|
||||
//
|
||||
G4int ReceiveG4cerr_(const G4String& msg);
|
||||
protected:
|
||||
G4coutDestination* masterG4coutDestination = nullptr;
|
||||
// For MT: if master G4coutDestination derived class wants to
|
||||
// intercept the thread outputs, derived class should set this pointer.
|
||||
// Needed for some G4UIsession like GUIs
|
||||
|
||||
protected:
|
||||
|
||||
// For MT: if master G4coutDestination derived
|
||||
// class wants to intercept the thread outputs
|
||||
// derived class should set this pointer.
|
||||
// Needed for some G4UIsession like GUIs
|
||||
//
|
||||
G4coutDestination* masterG4coutDestination = nullptr;
|
||||
|
||||
std::vector<Transformer> transformersCout;
|
||||
std::vector<Transformer> transformersCerr;
|
||||
std::vector<Transformer> transformersCout;
|
||||
std::vector<Transformer> transformersCerr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,13 +23,9 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4coutFormatters
|
||||
//
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 header file
|
||||
//
|
||||
// Class Description:
|
||||
// Description:
|
||||
//
|
||||
// Utilities to handle transformations of cout/cerr streams
|
||||
|
||||
@@ -38,15 +34,15 @@
|
||||
// Author: A.Dotti (SLAC), April 2017
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4COUTFORMATTERS_HH
|
||||
#define G4COUTFORMATTERS_HH
|
||||
#define G4COUTFORMATTERS_HH 1
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include <functional>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "G4String.hh"
|
||||
#include "G4ios.hh"
|
||||
@@ -57,10 +53,11 @@ namespace G4coutFormatters
|
||||
// Static definitions of provided formatters
|
||||
namespace ID
|
||||
{
|
||||
static const G4String SYSLOG = "syslog";
|
||||
static const G4String DEFAULT= "default";
|
||||
}
|
||||
static const G4String SYSLOG = "syslog";
|
||||
static const G4String DEFAULT = "default";
|
||||
} // namespace ID
|
||||
|
||||
using SetupStyle_f = std::function<G4int(G4coutDestination*)>;
|
||||
// A function that set ups a style for the destination
|
||||
// Example for a style that set to all capital the messages
|
||||
// to G4cerr:
|
||||
@@ -71,27 +68,26 @@ namespace G4coutFormatters
|
||||
// return true; }
|
||||
// );
|
||||
// };
|
||||
using SetupStyle_f = std::function<G4int(G4coutDestination*)>;
|
||||
|
||||
using String_V=std::vector<G4String>;
|
||||
using String_V = std::vector<G4String>;
|
||||
|
||||
// Return list of formatter names
|
||||
String_V Names();
|
||||
// Return list of formatter names
|
||||
|
||||
G4int HandleStyle(G4coutDestination* dest, const G4String& style);
|
||||
// Setup style (by name) to destination
|
||||
G4int HandleStyle( G4coutDestination* dest , const G4String& style );
|
||||
|
||||
// Set name of the style for the master thread
|
||||
void SetMasterStyle(const G4String& );
|
||||
void SetMasterStyle(const G4String&);
|
||||
G4String GetMasterStyle();
|
||||
// Set/get name of the style for the master thread
|
||||
|
||||
void SetupStyleGlobally(const G4String& news);
|
||||
// This function should be called in user application main function
|
||||
// to setup the style just after setting up RunManager
|
||||
void SetupStyleGlobally(const G4String& news);
|
||||
|
||||
void RegisterNewStyle(const G4String& name, SetupStyle_f& formatter);
|
||||
// To be used by user to register by name a new formatter.
|
||||
// So it can be used via one of the previous functions
|
||||
void RegisterNewStyle( const G4String& name , SetupStyle_f& formatter);
|
||||
}
|
||||
} // namespace G4coutFormatters
|
||||
|
||||
#endif // G4COUTFORMATTERS_HH
|
||||
#endif
|
||||
|
||||
@@ -23,17 +23,14 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4ios
|
||||
//
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------------
|
||||
// GEANT 4 class header file
|
||||
//
|
||||
// G4ios.hh
|
||||
//
|
||||
// ---------------------------------------------------------------
|
||||
#ifndef included_G4ios
|
||||
#define included_G4ios
|
||||
// Global types for cout/cerr streaming
|
||||
|
||||
// Authors: H.Yoshida, M.Nagamatu - November 1998
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4ios_hh
|
||||
#define G4ios_hh 1
|
||||
|
||||
#include "G4Types.hh"
|
||||
|
||||
@@ -41,15 +38,15 @@
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
|
||||
extern G4GLOB_DLL std::ostream*& _G4cout_p();
|
||||
extern G4GLOB_DLL std::ostream*& _G4cerr_p();
|
||||
#define G4cout (*_G4cout_p())
|
||||
#define G4cerr (*_G4cerr_p())
|
||||
extern G4GLOB_DLL std::ostream*& _G4cout_p();
|
||||
extern G4GLOB_DLL std::ostream*& _G4cerr_p();
|
||||
# define G4cout (*_G4cout_p())
|
||||
# define G4cerr (*_G4cerr_p())
|
||||
|
||||
#else // Sequential
|
||||
|
||||
extern G4GLOB_DLL std::ostream G4cout;
|
||||
extern G4GLOB_DLL std::ostream G4cerr;
|
||||
extern G4GLOB_DLL std::ostream G4cout;
|
||||
extern G4GLOB_DLL std::ostream G4cerr;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -23,64 +23,64 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4strstreambuf
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// ====================================================================
|
||||
//
|
||||
// G4strstreambuf
|
||||
//
|
||||
// ====================================================================
|
||||
#ifndef G4_STR_STREAM_BUF_HH
|
||||
#define G4_STR_STREAM_BUF_HH
|
||||
// Buffer for cout/cerr streaming
|
||||
|
||||
// Authors: H.Yoshida, M.Nagamatu - November 1998
|
||||
// Revisions: G.Cosmo, 1998-2013
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4STRSTREAMBUF_HH
|
||||
#define G4STRSTREAMBUF_HH 1
|
||||
|
||||
#include <streambuf>
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4coutDestination.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
class G4strstreambuf;
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
|
||||
extern G4GLOB_DLL G4strstreambuf*& _G4coutbuf_p();
|
||||
extern G4GLOB_DLL G4strstreambuf*& _G4cerrbuf_p();
|
||||
#define G4coutbuf (*_G4coutbuf_p())
|
||||
#define G4cerrbuf (*_G4cerrbuf_p())
|
||||
extern G4GLOB_DLL G4strstreambuf*& _G4coutbuf_p();
|
||||
extern G4GLOB_DLL G4strstreambuf*& _G4cerrbuf_p();
|
||||
# define G4coutbuf (*_G4coutbuf_p())
|
||||
# define G4cerrbuf (*_G4cerrbuf_p())
|
||||
|
||||
#else // Sequential
|
||||
|
||||
extern G4GLOB_DLL G4strstreambuf G4coutbuf;
|
||||
extern G4GLOB_DLL G4strstreambuf G4cerrbuf;
|
||||
extern G4GLOB_DLL G4strstreambuf G4coutbuf;
|
||||
extern G4GLOB_DLL G4strstreambuf G4cerrbuf;
|
||||
|
||||
#endif
|
||||
|
||||
class G4strstreambuf : public std::basic_streambuf<char>
|
||||
{
|
||||
public:
|
||||
public:
|
||||
G4strstreambuf();
|
||||
~G4strstreambuf();
|
||||
|
||||
G4strstreambuf();
|
||||
~G4strstreambuf();
|
||||
|
||||
virtual G4int overflow(G4int c=EOF);
|
||||
virtual G4int sync();
|
||||
virtual G4int overflow(G4int c = EOF);
|
||||
virtual G4int sync();
|
||||
|
||||
#ifdef WIN32
|
||||
virtual G4int underflow();
|
||||
virtual G4int underflow();
|
||||
#endif
|
||||
|
||||
void SetDestination(G4coutDestination* dest);
|
||||
inline G4coutDestination* GetDestination() const;
|
||||
inline G4int ReceiveString ();
|
||||
|
||||
private:
|
||||
void SetDestination(G4coutDestination* dest);
|
||||
inline G4coutDestination* GetDestination() const;
|
||||
inline G4int ReceiveString();
|
||||
|
||||
char* buffer;
|
||||
G4int count, size;
|
||||
G4coutDestination* destination;
|
||||
private:
|
||||
char* buffer = nullptr;
|
||||
G4int count = 0, size = 0;
|
||||
G4coutDestination* destination = nullptr;
|
||||
|
||||
// hidden...
|
||||
G4strstreambuf(const G4strstreambuf&);
|
||||
G4strstreambuf& operator=(const G4strstreambuf&);
|
||||
// hidden...
|
||||
G4strstreambuf(const G4strstreambuf&);
|
||||
G4strstreambuf& operator=(const G4strstreambuf&);
|
||||
};
|
||||
|
||||
#include "G4strstreambuf.icc"
|
||||
|
||||
@@ -23,133 +23,114 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4strstreambuf inline methods implementation
|
||||
//
|
||||
// ====================================================================
|
||||
// G4strstreambuf.icc
|
||||
//
|
||||
// ====================================================================
|
||||
// Authors: H.Yoshida, M.Nagamatu - November 1998
|
||||
// Revisions: G.Cosmo, 1998-2013
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
///////////////////////////////////////
|
||||
// --------------------------------------------------------------------
|
||||
inline G4strstreambuf::G4strstreambuf()
|
||||
: std::basic_streambuf<char>(),
|
||||
count(0), destination(0)
|
||||
///////////////////////////////////////
|
||||
: std::basic_streambuf<char>()
|
||||
{
|
||||
size= 4095;
|
||||
buffer= new char[size+1];
|
||||
size = 4095;
|
||||
buffer = new char[size + 1];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// --------------------------------------------------------------------
|
||||
inline G4strstreambuf::~G4strstreambuf()
|
||||
////////////////////////////////////////
|
||||
{
|
||||
// flushing buffer...
|
||||
// std::cout is used because destination object may not be alive.
|
||||
if(count !=0) std::cout << buffer;
|
||||
if(count != 0)
|
||||
std::cout << buffer;
|
||||
|
||||
delete [] buffer;
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// --------------------------------------------------------------------
|
||||
inline G4strstreambuf::G4strstreambuf(const G4strstreambuf& right)
|
||||
: std::basic_streambuf<char>(),
|
||||
buffer(right.buffer),
|
||||
count(right.count), size(right.size),
|
||||
destination(right.destination)
|
||||
//////////////////////////////////////////////////////////////////
|
||||
{
|
||||
}
|
||||
: std::basic_streambuf<char>()
|
||||
, buffer(right.buffer)
|
||||
, count(right.count)
|
||||
, size(right.size)
|
||||
, destination(right.destination)
|
||||
{}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// --------------------------------------------------------------------
|
||||
inline G4strstreambuf& G4strstreambuf::operator=(const G4strstreambuf& right)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
{
|
||||
if(&right==this) return *this;
|
||||
|
||||
destination= right.destination;
|
||||
buffer= right.buffer;
|
||||
count= right.count;
|
||||
size= right.size;
|
||||
if(&right == this)
|
||||
return *this;
|
||||
|
||||
destination = right.destination;
|
||||
buffer = right.buffer;
|
||||
count = right.count;
|
||||
size = right.size;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// --------------------------------------------------------------------
|
||||
inline G4int G4strstreambuf::overflow(G4int c)
|
||||
//////////////////////////////////////////////
|
||||
{
|
||||
G4int result= 0;
|
||||
if(count>=size) result= sync();
|
||||
G4int result = 0;
|
||||
if(count >= size)
|
||||
result = sync();
|
||||
|
||||
buffer[count]= c;
|
||||
buffer[count] = c;
|
||||
count++;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
///////////////////////////////////
|
||||
// --------------------------------------------------------------------
|
||||
inline G4int G4strstreambuf::sync()
|
||||
///////////////////////////////////
|
||||
{
|
||||
buffer[count] = '\0';
|
||||
count= 0;
|
||||
count = 0;
|
||||
return ReceiveString();
|
||||
}
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
////////////////////////////////////////
|
||||
inline G4int G4strstreambuf::underflow()
|
||||
////////////////////////////////////////
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
inline G4int G4strstreambuf::underflow() { return 0; }
|
||||
#endif
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// --------------------------------------------------------------------
|
||||
inline void G4strstreambuf::SetDestination(G4coutDestination* dest)
|
||||
///////////////////////////////////////////////////////////////////
|
||||
{
|
||||
destination= dest;
|
||||
destination = dest;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
inline G4coutDestination* G4strstreambuf::GetDestination() const
|
||||
{
|
||||
return destination;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////////
|
||||
inline G4int G4strstreambuf::ReceiveString ()
|
||||
/////////////////////////////////////////////
|
||||
// --------------------------------------------------------------------
|
||||
inline G4int G4strstreambuf::ReceiveString()
|
||||
{
|
||||
G4String stringToSend(buffer);
|
||||
G4int result= 0;
|
||||
G4int result = 0;
|
||||
|
||||
if(this == &G4coutbuf && destination != 0)
|
||||
if(this == &G4coutbuf && destination != nullptr)
|
||||
{
|
||||
result= destination-> ReceiveG4cout_(stringToSend);
|
||||
result = destination->ReceiveG4cout_(stringToSend);
|
||||
}
|
||||
else if(this == &G4cerrbuf && destination != 0)
|
||||
else if(this == &G4cerrbuf && destination != nullptr)
|
||||
{
|
||||
result= destination-> ReceiveG4cerr_(stringToSend);
|
||||
result = destination->ReceiveG4cerr_(stringToSend);
|
||||
}
|
||||
else if(this == &G4coutbuf && destination == 0)
|
||||
else if(this == &G4coutbuf && destination == nullptr)
|
||||
{
|
||||
std::cout << stringToSend << std::flush;
|
||||
result= 0;
|
||||
result = 0;
|
||||
}
|
||||
else if(this == &G4cerrbuf && destination == 0)
|
||||
else if(this == &G4cerrbuf && destination == nullptr)
|
||||
{
|
||||
std::cerr << stringToSend << std::flush;
|
||||
result= 0;
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -23,35 +23,22 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// Global Constants and typedefs
|
||||
//
|
||||
// History:
|
||||
// 30.06.95 P.Kent - Created
|
||||
// 16.02.96 G.Cosmo - Added inclusion of "templates.hh"
|
||||
// 03.03.96 M.Maire - Added inclusion of "G4PhysicalConstants.hh"
|
||||
// 08.11.96 G.Cosmo - Added cbrt() definition and G4ApplicationState enum type
|
||||
// 29.11.96 G.Cosmo - Added typedef of HepBoolean to G4bool
|
||||
// 22.10.97 M.Maire - Moved PhysicalConstants at the end of the file
|
||||
// 04.12.97 G.Cosmo,E.Tcherniaev - Migrated to CLHEP
|
||||
// 26.08.98 J.Allison,E.Tcherniaev - Introduced min/max/sqr/abs functions
|
||||
// 22.09.98 G.Cosmo - Removed min/max/sqr/abs functions and replaced with
|
||||
// inclusion of CLHEP/config/TemplateFunctions.h for CLHEP-1.3
|
||||
// 15.12.99 G.Garcia - Included min, max definitions for NT with ISO standard
|
||||
// 15.06.01 G.Cosmo - Removed cbrt() definition
|
||||
|
||||
// Author: P.Kent, 30.06.1995 - Created
|
||||
// Revisions:
|
||||
// - 1996 to present - G.Cosmo
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef GLOBALS_HH
|
||||
#define GLOBALS_HH
|
||||
#define GLOBALS_HH 1
|
||||
|
||||
#include "G4ios.hh"
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
# define FALSE 0
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
# define TRUE 1
|
||||
#endif
|
||||
|
||||
#include <algorithm> // Retrieve definitions of min/max
|
||||
|
||||
@@ -23,42 +23,22 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// -*- C++ -*-
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// This file should define some platform dependent features and some
|
||||
// useful utilities.
|
||||
// -----------------------------------------------------------------------
|
||||
// Module defining platform dependent features and some useful utilities.
|
||||
|
||||
// =======================================================================
|
||||
// Gabriele Cosmo - Created: 5th September 1995
|
||||
// Gabriele Cosmo - Minor change: 08/02/1996
|
||||
// Gabriele Cosmo - Added DBL_MIN, FLT_MIN, DBL_DIG,
|
||||
// DBL_MAX, FLT_DIG, FLT_MAX : 12/04/1996
|
||||
// Gabriele Cosmo - Removed boolean enum definition : 29/11/1996
|
||||
// Gunter Folger - Added G4SwapPtr() and G4SwapObj() : 31/07/1997
|
||||
// Gabriele Cosmo - Adapted signatures of min(), max() to
|
||||
// STL's ones, thanks to E.Tcherniaev : 31/07/1997
|
||||
// Gabriele Cosmo,
|
||||
// Evgueni Tcherniaev - Migrated to CLHEP: 04/12/1997
|
||||
// =======================================================================
|
||||
// Author: Gabriele Cosmo, 5 September 1995 - Created
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef templates_hh
|
||||
#define templates_hh 1
|
||||
|
||||
#ifndef templates_h
|
||||
#define templates_h 1
|
||||
|
||||
#include <limits>
|
||||
#include <climits>
|
||||
#include <limits>
|
||||
|
||||
//
|
||||
// If HIGH_PRECISION is defined to TRUE (ie. != 0) then the type "Float"
|
||||
// is typedefed to "double". If it is FALSE (ie. 0) it is typedefed
|
||||
// to "float".
|
||||
//
|
||||
#ifndef HIGH_PRECISION
|
||||
#define HIGH_PRECISION 1
|
||||
# define HIGH_PRECISION 1
|
||||
#endif
|
||||
|
||||
#if HIGH_PRECISION
|
||||
@@ -70,52 +50,52 @@ typedef float Float;
|
||||
// Following values have been taken from limits.h
|
||||
// and temporarly defined for portability on HP-UX.
|
||||
|
||||
#ifndef DBL_MIN /* Min decimal value of a double */
|
||||
#define DBL_MIN std::numeric_limits<double>::min() // 2.2250738585072014e-308
|
||||
#ifndef DBL_MIN /* Min decimal value of a double */
|
||||
# define DBL_MIN std::numeric_limits<double>::min() // 2.2250738585072014e-308
|
||||
#endif
|
||||
|
||||
#ifndef DBL_DIG /* Digits of precision of a double */
|
||||
#define DBL_DIG std::numeric_limits<double>::digits10 // 15
|
||||
#ifndef DBL_DIG /* Digits of precision of a double */
|
||||
# define DBL_DIG std::numeric_limits<double>::digits10 // 15
|
||||
#endif
|
||||
|
||||
#ifndef DBL_MAX /* Max decimal value of a double */
|
||||
#define DBL_MAX std::numeric_limits<double>::max() // 1.7976931348623157e+308
|
||||
#ifndef DBL_MAX /* Max decimal value of a double */
|
||||
# define DBL_MAX std::numeric_limits<double>::max() // 1.7976931348623157e+308
|
||||
#endif
|
||||
|
||||
#ifndef DBL_EPSILON
|
||||
#define DBL_EPSILON std::numeric_limits<double>::epsilon()
|
||||
#endif // 2.2204460492503131e-16
|
||||
# define DBL_EPSILON std::numeric_limits<double>::epsilon()
|
||||
#endif // 2.2204460492503131e-16
|
||||
|
||||
#ifndef FLT_MIN /* Min decimal value of a float */
|
||||
#define FLT_MIN std::numeric_limits<float>::min() // 1.17549435e-38F
|
||||
#ifndef FLT_MIN /* Min decimal value of a float */
|
||||
# define FLT_MIN std::numeric_limits<float>::min() // 1.17549435e-38F
|
||||
#endif
|
||||
|
||||
#ifndef FLT_DIG /* Digits of precision of a float */
|
||||
#define FLT_DIG std::numeric_limits<float>::digits10 // 6
|
||||
#ifndef FLT_DIG /* Digits of precision of a float */
|
||||
# define FLT_DIG std::numeric_limits<float>::digits10 // 6
|
||||
#endif
|
||||
|
||||
#ifndef FLT_MAX /* Max decimal value of a float */
|
||||
#define FLT_MAX std::numeric_limits<float>::max() // 3.40282347e+38F
|
||||
#ifndef FLT_MAX /* Max decimal value of a float */
|
||||
# define FLT_MAX std::numeric_limits<float>::max() // 3.40282347e+38F
|
||||
#endif
|
||||
|
||||
#ifndef FLT_EPSILON
|
||||
#define FLT_EPSILON std::numeric_limits<float>::epsilon()
|
||||
#endif // 1.192092896e-07F
|
||||
# define FLT_EPSILON std::numeric_limits<float>::epsilon()
|
||||
#endif // 1.192092896e-07F
|
||||
|
||||
#ifndef MAXFLOAT /* Max decimal value of a float */
|
||||
#define MAXFLOAT std::numeric_limits<float>::max() // 3.40282347e+38F
|
||||
#ifndef MAXFLOAT /* Max decimal value of a float */
|
||||
# define MAXFLOAT std::numeric_limits<float>::max() // 3.40282347e+38F
|
||||
#endif
|
||||
|
||||
#ifndef INT_MAX /* Max decimal value of a int */
|
||||
#define INT_MAX std::numeric_limits<int>::max() // 2147483647
|
||||
#ifndef INT_MAX /* Max decimal value of a int */
|
||||
# define INT_MAX std::numeric_limits<int>::max() // 2147483647
|
||||
#endif
|
||||
|
||||
#ifndef INT_MIN /* Min decimal value of a int */
|
||||
#define INT_MIN std::numeric_limits<int>::min() // -2147483648
|
||||
#ifndef INT_MIN /* Min decimal value of a int */
|
||||
# define INT_MIN std::numeric_limits<int>::min() // -2147483648
|
||||
#endif
|
||||
|
||||
#ifndef LOG_EKIN_MIN /* Min value of the natural logarithm of kin. energy. */
|
||||
#define LOG_EKIN_MIN -30
|
||||
#ifndef LOG_EKIN_MIN /* Min value of the natural logarithm of kin. energy. */
|
||||
# define LOG_EKIN_MIN -30
|
||||
#endif
|
||||
|
||||
//---------------------------------
|
||||
@@ -123,47 +103,47 @@ typedef float Float;
|
||||
template <class T>
|
||||
inline void G4SwapPtr(T*& a, T*& b)
|
||||
{
|
||||
T* tmp= a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
T* tmp = a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void G4SwapObj(T* a, T* b)
|
||||
{
|
||||
T tmp= *a;
|
||||
*a = *b;
|
||||
*b = tmp;
|
||||
T tmp = *a;
|
||||
*a = *b;
|
||||
*b = tmp;
|
||||
}
|
||||
|
||||
//-----------------------------
|
||||
|
||||
#ifndef G4_SQR_DEFINED
|
||||
#define G4_SQR_DEFINED
|
||||
#ifdef sqr
|
||||
#undef sqr
|
||||
#endif
|
||||
# define G4_SQR_DEFINED
|
||||
# ifdef sqr
|
||||
# undef sqr
|
||||
# endif
|
||||
|
||||
template <class T>
|
||||
inline T sqr(const T& x)
|
||||
{
|
||||
return x*x;
|
||||
return x * x;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline int G4lrint(double ad)
|
||||
{
|
||||
return (ad>0) ? static_cast<int>(ad+.5) : static_cast<int>(ad-.5);
|
||||
return (ad > 0) ? static_cast<int>(ad + .5) : static_cast<int>(ad - .5);
|
||||
}
|
||||
|
||||
inline int G4lint(double ad)
|
||||
{
|
||||
return (ad>0) ? static_cast<int>(ad) : static_cast<int>(ad-1.);
|
||||
return (ad > 0) ? static_cast<int>(ad) : static_cast<int>(ad - 1.);
|
||||
}
|
||||
|
||||
inline int G4rint(double ad)
|
||||
{
|
||||
return (ad>0) ? static_cast<int>(ad+1) : static_cast<int>(ad);
|
||||
return (ad > 0) ? static_cast<int>(ad + 1) : static_cast<int>(ad);
|
||||
}
|
||||
|
||||
//-----------------------------
|
||||
@@ -205,6 +185,6 @@ inline int G4rint(double ad)
|
||||
//
|
||||
template <typename... _Args>
|
||||
inline void G4ConsumeParameters(_Args&&...)
|
||||
{ }
|
||||
{}
|
||||
|
||||
#endif // templates_h
|
||||
#endif // templates_hh
|
||||
|
||||
@@ -26,51 +26,55 @@
|
||||
//
|
||||
// Thread Local Storage typedefs
|
||||
|
||||
// History:
|
||||
// 01.10.2012 G.Cosmo - Created
|
||||
// Author: G.Cosmo, 01.10.2012 - Created
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// Fundamental definitions
|
||||
#ifndef G4GMAKE
|
||||
#include "G4GlobalConfig.hh"
|
||||
# include "G4GlobalConfig.hh"
|
||||
#endif
|
||||
|
||||
#ifndef G4_TLS
|
||||
#define G4_TLS
|
||||
# define G4_TLS 1
|
||||
|
||||
#if defined (G4MULTITHREADED)
|
||||
#if ( defined(__MACH__) && defined(__clang__) && defined(__x86_64__) ) || \
|
||||
( defined(__linux__) && defined(__clang__) )
|
||||
# define G4ThreadLocalStatic static thread_local
|
||||
# define G4ThreadLocal thread_local
|
||||
#elif ( (defined(__linux__) || defined(__MACH__)) && \
|
||||
!defined(__INTEL_COMPILER) && defined(__GNUC__) && (__GNUC__>=4 && __GNUC_MINOR__<9))
|
||||
# define G4ThreadLocalStatic static __thread
|
||||
# define G4ThreadLocal thread_local
|
||||
#elif ( (defined(__linux__) || defined(__MACH__)) && \
|
||||
!defined(__INTEL_COMPILER) && defined(__GNUC__) && (__GNUC__>=4 && __GNUC_MINOR__>=9) || __GNUC__>=5 )
|
||||
# define G4ThreadLocalStatic static thread_local
|
||||
# define G4ThreadLocal thread_local
|
||||
#elif ( (defined(__linux__) || defined(__MACH__)) && \
|
||||
defined(__INTEL_COMPILER) )
|
||||
#if __INTEL_COMPILER>=1500
|
||||
# define G4ThreadLocalStatic static thread_local
|
||||
# define G4ThreadLocal thread_local
|
||||
#else
|
||||
# define G4ThreadLocalStatic static __thread
|
||||
# define G4ThreadLocal __thread
|
||||
#endif
|
||||
#elif defined(_AIX)
|
||||
# define G4ThreadLocalStatic static thread_local
|
||||
# define G4ThreadLocal thread_local
|
||||
#elif defined(WIN32)
|
||||
# define G4ThreadLocalStatic static thread_local
|
||||
# define G4ThreadLocal thread_local
|
||||
#else
|
||||
# error "No Thread Local Storage (TLS) technology supported for this platform. Use sequential build !"
|
||||
#endif
|
||||
#else
|
||||
# define G4ThreadLocalStatic static
|
||||
# define G4ThreadLocal
|
||||
#endif
|
||||
# if defined(G4MULTITHREADED)
|
||||
# if(defined(__MACH__) && defined(__clang__) && defined(__x86_64__)) || \
|
||||
(defined(__linux__) && defined(__clang__))
|
||||
# define G4ThreadLocalStatic static thread_local
|
||||
# define G4ThreadLocal thread_local
|
||||
# elif((defined(__linux__) || defined(__MACH__)) && \
|
||||
!defined(__INTEL_COMPILER) && defined(__GNUC__) && \
|
||||
(__GNUC__ >= 4 && __GNUC_MINOR__ < 9))
|
||||
# define G4ThreadLocalStatic static __thread
|
||||
# define G4ThreadLocal thread_local
|
||||
# elif((defined(__linux__) || defined(__MACH__)) && \
|
||||
!defined(__INTEL_COMPILER) && defined(__GNUC__) && \
|
||||
(__GNUC__ >= 4 && __GNUC_MINOR__ >= 9) || \
|
||||
__GNUC__ >= 5)
|
||||
# define G4ThreadLocalStatic static thread_local
|
||||
# define G4ThreadLocal thread_local
|
||||
# elif((defined(__linux__) || defined(__MACH__)) && \
|
||||
defined(__INTEL_COMPILER))
|
||||
# if __INTEL_COMPILER >= 1500
|
||||
# define G4ThreadLocalStatic static thread_local
|
||||
# define G4ThreadLocal thread_local
|
||||
# else
|
||||
# define G4ThreadLocalStatic static __thread
|
||||
# define G4ThreadLocal __thread
|
||||
# endif
|
||||
# elif defined(_AIX)
|
||||
# define G4ThreadLocalStatic static thread_local
|
||||
# define G4ThreadLocal thread_local
|
||||
# elif defined(WIN32)
|
||||
# define G4ThreadLocalStatic static thread_local
|
||||
# define G4ThreadLocal thread_local
|
||||
# else
|
||||
# error \
|
||||
"No Thread Local Storage (TLS) technology supported for this platform. Use sequential build !"
|
||||
# endif
|
||||
# else
|
||||
# define G4ThreadLocalStatic static
|
||||
# define G4ThreadLocal
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,22 +23,21 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// GEANT 4 class header file
|
||||
// Description:
|
||||
//
|
||||
// Class Description:
|
||||
//
|
||||
// This file includes protections from Windows declarations in the
|
||||
// This file includes protections from Windows kits declarations in the
|
||||
// global scope that may cause trouble in compilation.
|
||||
|
||||
// Author: G.Cosmo, 2019
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef windefs_hh
|
||||
#define windefs_hh
|
||||
#define windefs_hh 1
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if defined (ABSOLUTE)
|
||||
#undef ABSOLUTE
|
||||
#undef RELATIVE
|
||||
#endif
|
||||
#endif // _WIN32
|
||||
# if defined(ABSOLUTE)
|
||||
# undef ABSOLUTE
|
||||
# undef RELATIVE
|
||||
# endif
|
||||
#endif // _WIN32
|
||||
|
||||
#endif // windefs_hh
|
||||
#endif // windefs_hh
|
||||
|
||||
@@ -1,29 +1,11 @@
|
||||
#------------------------------------------------------------------------------
|
||||
# sources.cmake
|
||||
# Module : G4globman
|
||||
# Package: Geant4.src.G4global.G4globman
|
||||
#
|
||||
# Sources description for a library.
|
||||
# Lists the sources and headers of the code explicitely.
|
||||
# Lists include paths needed.
|
||||
# Lists the internal granular and global dependencies of the library.
|
||||
# Source specific properties should be added at the end.
|
||||
#
|
||||
# Generated on : 24/9/2010
|
||||
#
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
# List external includes needed.
|
||||
include_directories(${CLHEP_INCLUDE_DIRS})
|
||||
|
||||
# List internal includes needed.
|
||||
|
||||
# Configure header for preprocessor symbols
|
||||
#
|
||||
# Convert CMake variables -> #cmakedefine symbols here for now
|
||||
# Could be done in cmake category as well, but it's here we control
|
||||
# the actual names of the definitions
|
||||
# Convert CMake variables -> #cmakedefine symbols
|
||||
set(G4MULTITHREADED ${GEANT4_BUILD_MULTITHREADED})
|
||||
set(G4_STORE_TRAJECTORY ${GEANT4_BUILD_STORE_TRAJECTORY})
|
||||
set(G4VERBOSE ${GEANT4_BUILD_VERBOSE_CODE})
|
||||
@@ -42,136 +24,138 @@ set_property(GLOBAL APPEND
|
||||
#
|
||||
# Define the Geant4 Module.
|
||||
#
|
||||
include(Geant4MacroDefineModule)
|
||||
GEANT4_DEFINE_MODULE(NAME G4globman
|
||||
HEADERS
|
||||
${CMAKE_CURRENT_BINARY_DIR}/include/G4GlobalConfig.hh
|
||||
globals.hh
|
||||
templates.hh
|
||||
tls.hh
|
||||
windefs.hh
|
||||
G4Allocator.hh
|
||||
G4AutoDelete.hh
|
||||
G4ios.hh
|
||||
G4coutDestination.hh
|
||||
G4coutFormatters.hh
|
||||
G4strstreambuf.hh
|
||||
G4strstreambuf.icc
|
||||
G4AllocatorPool.hh
|
||||
G4AllocatorList.hh
|
||||
G4ApplicationState.hh
|
||||
G4AutoLock.hh
|
||||
G4BuffercoutDestination.hh
|
||||
G4Cache.hh
|
||||
G4CacheDetails.hh
|
||||
G4DataVector.hh
|
||||
G4DataVector.icc
|
||||
G4EnvironmentUtils.hh
|
||||
G4ErrorPropagatorData.hh
|
||||
G4ErrorPropagatorData.icc
|
||||
G4Evaluator.hh
|
||||
G4Exception.hh
|
||||
G4ExceptionSeverity.hh
|
||||
G4Exp.hh
|
||||
G4FilecoutDestination.hh
|
||||
G4FPEDetection.hh
|
||||
G4FastVector.hh
|
||||
G4GeometryTolerance.hh
|
||||
G4LockcoutDestination.hh
|
||||
G4Log.hh
|
||||
G4LPhysicsFreeVector.hh
|
||||
G4MasterForwardcoutDestination.hh
|
||||
G4MTBarrier.hh
|
||||
G4MTcoutDestination.hh
|
||||
G4MulticoutDestination.hh
|
||||
G4OrderedTable.hh
|
||||
G4PhysicalConstants.hh
|
||||
G4PhysicsFreeVector.hh
|
||||
G4PhysicsLinearVector.hh
|
||||
G4PhysicsLnVector.hh
|
||||
G4PhysicsLogVector.hh
|
||||
G4PhysicsModelCatalog.hh
|
||||
G4PhysicsOrderedFreeVector.hh
|
||||
G4PhysicsTable.hh
|
||||
G4PhysicsTable.icc
|
||||
G4PhysicsVector.hh
|
||||
G4PhysicsVector.icc
|
||||
G4PhysicsVectorType.hh
|
||||
G4Physics2DVector.hh
|
||||
G4Physics2DVector.icc
|
||||
G4Pow.hh
|
||||
G4ReferenceCountedHandle.hh
|
||||
G4RotationMatrix.hh
|
||||
G4SIunits.hh
|
||||
G4SliceTimer.hh
|
||||
G4SliceTimer.icc
|
||||
G4StateManager.hh
|
||||
G4StateManager.icc
|
||||
G4String.hh
|
||||
G4String.icc
|
||||
G4SystemOfUnits.hh
|
||||
G4Threading.hh
|
||||
G4ThreadLocalSingleton.hh
|
||||
G4ThreeVector.hh
|
||||
G4TiMemory.hh
|
||||
G4Timer.hh
|
||||
G4Timer.icc
|
||||
G4Tokenizer.hh
|
||||
G4TWorkspacePool.hh
|
||||
G4TwoVector.hh
|
||||
G4Types.hh
|
||||
G4UnitsTable.hh
|
||||
G4UnitsTable.icc
|
||||
G4UserLimits.hh
|
||||
G4UserLimits.icc
|
||||
G4Version.hh
|
||||
G4VExceptionHandler.hh
|
||||
G4VNotifier.hh
|
||||
G4VStateDependent.hh
|
||||
SOURCES
|
||||
G4Allocator.cc
|
||||
G4AllocatorPool.cc
|
||||
G4AllocatorList.cc
|
||||
G4BuffercoutDestination.cc
|
||||
G4CacheDetails.cc
|
||||
G4coutDestination.cc
|
||||
G4coutFormatters.cc
|
||||
G4DataVector.cc
|
||||
G4ErrorPropagatorData.cc
|
||||
G4Exception.cc
|
||||
G4FilecoutDestination.cc
|
||||
G4GeometryTolerance.cc
|
||||
G4ios.cc
|
||||
G4LockcoutDestination.cc
|
||||
G4LPhysicsFreeVector.cc
|
||||
G4MasterForwardcoutDestination.cc
|
||||
G4MTBarrier.cc
|
||||
G4MTcoutDestination.cc
|
||||
G4OrderedTable.cc
|
||||
G4PhysicsFreeVector.cc
|
||||
G4PhysicsLinearVector.cc
|
||||
G4PhysicsLogVector.cc
|
||||
G4PhysicsModelCatalog.cc
|
||||
G4PhysicsOrderedFreeVector.cc
|
||||
G4PhysicsTable.cc
|
||||
G4PhysicsVector.cc
|
||||
G4Physics2DVector.cc
|
||||
G4Pow.cc
|
||||
G4ReferenceCountedHandle.cc
|
||||
G4SliceTimer.cc
|
||||
G4StateManager.cc
|
||||
G4Threading.cc
|
||||
G4Timer.cc
|
||||
G4UnitsTable.cc
|
||||
G4VExceptionHandler.cc
|
||||
G4VNotifier.cc
|
||||
G4VStateDependent.cc
|
||||
GRANULAR_DEPENDENCIES
|
||||
GLOBAL_DEPENDENCIES
|
||||
LINK_LIBRARIES
|
||||
${CLHEP_LIBRARIES}
|
||||
${timemory_LIBRARIES}
|
||||
geant4_define_module(NAME G4globman
|
||||
HEADERS
|
||||
${CMAKE_CURRENT_BINARY_DIR}/include/G4GlobalConfig.hh
|
||||
globals.hh
|
||||
templates.hh
|
||||
tls.hh
|
||||
windefs.hh
|
||||
G4Allocator.hh
|
||||
G4AutoDelete.hh
|
||||
G4ios.hh
|
||||
G4coutDestination.hh
|
||||
G4coutFormatters.hh
|
||||
G4strstreambuf.hh
|
||||
G4strstreambuf.icc
|
||||
G4AllocatorPool.hh
|
||||
G4AllocatorList.hh
|
||||
G4ApplicationState.hh
|
||||
G4AutoLock.hh
|
||||
G4BuffercoutDestination.hh
|
||||
G4Cache.hh
|
||||
G4CacheDetails.hh
|
||||
G4DataVector.hh
|
||||
G4DataVector.icc
|
||||
G4EnvironmentUtils.hh
|
||||
G4ErrorPropagatorData.hh
|
||||
G4ErrorPropagatorData.icc
|
||||
G4Evaluator.hh
|
||||
G4Exception.hh
|
||||
G4ExceptionSeverity.hh
|
||||
G4Exp.hh
|
||||
G4FilecoutDestination.hh
|
||||
G4FPEDetection.hh
|
||||
G4FastVector.hh
|
||||
G4GeometryTolerance.hh
|
||||
G4LockcoutDestination.hh
|
||||
G4Log.hh
|
||||
G4LPhysicsFreeVector.hh
|
||||
G4MasterForwardcoutDestination.hh
|
||||
G4MTBarrier.hh
|
||||
G4MTcoutDestination.hh
|
||||
G4MulticoutDestination.hh
|
||||
G4OrderedTable.hh
|
||||
G4PhysicalConstants.hh
|
||||
G4PhysicsFreeVector.hh
|
||||
G4PhysicsLinearVector.hh
|
||||
G4PhysicsLnVector.hh
|
||||
G4PhysicsLogVector.hh
|
||||
G4PhysicsModelCatalog.hh
|
||||
G4PhysicsOrderedFreeVector.hh
|
||||
G4PhysicsTable.hh
|
||||
G4PhysicsTable.icc
|
||||
G4PhysicsVector.hh
|
||||
G4PhysicsVector.icc
|
||||
G4PhysicsVectorType.hh
|
||||
G4Physics2DVector.hh
|
||||
G4Physics2DVector.icc
|
||||
G4Pow.hh
|
||||
G4ReferenceCountedHandle.hh
|
||||
G4RotationMatrix.hh
|
||||
G4SIunits.hh
|
||||
G4SliceTimer.hh
|
||||
G4SliceTimer.icc
|
||||
G4StateManager.hh
|
||||
G4StateManager.icc
|
||||
G4String.hh
|
||||
G4String.icc
|
||||
G4SystemOfUnits.hh
|
||||
G4Threading.hh
|
||||
G4ThreadLocalSingleton.hh
|
||||
G4ThreeVector.hh
|
||||
G4TiMemory.hh
|
||||
G4Timer.hh
|
||||
G4Timer.icc
|
||||
G4Tokenizer.hh
|
||||
G4TWorkspacePool.hh
|
||||
G4TwoVector.hh
|
||||
G4Types.hh
|
||||
G4UnitsTable.hh
|
||||
G4UnitsTable.icc
|
||||
G4UserLimits.hh
|
||||
G4UserLimits.icc
|
||||
G4Version.hh
|
||||
G4VExceptionHandler.hh
|
||||
G4VNotifier.hh
|
||||
G4VStateDependent.hh
|
||||
SOURCES
|
||||
G4Allocator.cc
|
||||
G4AllocatorPool.cc
|
||||
G4AllocatorList.cc
|
||||
G4BuffercoutDestination.cc
|
||||
G4CacheDetails.cc
|
||||
G4coutDestination.cc
|
||||
G4coutFormatters.cc
|
||||
G4DataVector.cc
|
||||
G4ErrorPropagatorData.cc
|
||||
G4Exception.cc
|
||||
G4FilecoutDestination.cc
|
||||
G4GeometryTolerance.cc
|
||||
G4ios.cc
|
||||
G4LockcoutDestination.cc
|
||||
G4LPhysicsFreeVector.cc
|
||||
G4MasterForwardcoutDestination.cc
|
||||
G4MTBarrier.cc
|
||||
G4MTcoutDestination.cc
|
||||
G4OrderedTable.cc
|
||||
G4PhysicsFreeVector.cc
|
||||
G4PhysicsLinearVector.cc
|
||||
G4PhysicsLogVector.cc
|
||||
G4PhysicsModelCatalog.cc
|
||||
G4PhysicsOrderedFreeVector.cc
|
||||
G4PhysicsTable.cc
|
||||
G4PhysicsVector.cc
|
||||
G4Physics2DVector.cc
|
||||
G4Pow.cc
|
||||
G4ReferenceCountedHandle.cc
|
||||
G4SliceTimer.cc
|
||||
G4StateManager.cc
|
||||
G4Threading.cc
|
||||
G4Timer.cc
|
||||
G4UnitsTable.cc
|
||||
G4VExceptionHandler.cc
|
||||
G4VNotifier.cc
|
||||
G4VStateDependent.cc
|
||||
LINK_LIBRARIES
|
||||
${CLHEP_LIBRARIES}
|
||||
${timemory_LIBRARIES}
|
||||
)
|
||||
|
||||
# List any source specific properties here
|
||||
|
||||
# For new system, must explicitly add path for generated header
|
||||
if(GEANT4_USE_NEW_CMAKE)
|
||||
geant4_module_include_directories(G4globman
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -23,16 +23,19 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4Allocator/G4AllocatorBase class implementation
|
||||
//
|
||||
//
|
||||
//
|
||||
// Author: G.Cosmo (CERN), November 2000
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4Allocator.hh"
|
||||
#include "G4AllocatorList.hh"
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4AllocatorBase::G4AllocatorBase()
|
||||
{
|
||||
G4AllocatorList::GetAllocatorList()->Register(this);
|
||||
}
|
||||
|
||||
G4AllocatorBase::~G4AllocatorBase() {;}
|
||||
// --------------------------------------------------------------------
|
||||
G4AllocatorBase::~G4AllocatorBase() {}
|
||||
|
||||
@@ -23,91 +23,91 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4AllocatorList class implementation
|
||||
//
|
||||
//
|
||||
//
|
||||
// Authors: M.Asai (SLAC), G.Cosmo (CERN), June 2013
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
#include "G4AllocatorList.hh"
|
||||
#include "G4Allocator.hh"
|
||||
#include "G4AllocatorList.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
G4ThreadLocal G4AllocatorList* G4AllocatorList::fAllocatorList=0;
|
||||
G4ThreadLocal G4AllocatorList* G4AllocatorList::fAllocatorList = nullptr;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4AllocatorList* G4AllocatorList::GetAllocatorList()
|
||||
{
|
||||
if(!fAllocatorList)
|
||||
if(fAllocatorList == nullptr)
|
||||
{
|
||||
fAllocatorList = new G4AllocatorList;
|
||||
}
|
||||
return fAllocatorList;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4AllocatorList* G4AllocatorList::GetAllocatorListIfExist()
|
||||
{
|
||||
return fAllocatorList;
|
||||
}
|
||||
|
||||
G4AllocatorList::G4AllocatorList()
|
||||
{
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
G4AllocatorList::G4AllocatorList() {}
|
||||
|
||||
G4AllocatorList::~G4AllocatorList()
|
||||
{
|
||||
fAllocatorList = 0;
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
G4AllocatorList::~G4AllocatorList() { fAllocatorList = nullptr; }
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
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, tmem=0;
|
||||
if(verboseLevel>0)
|
||||
auto itr = fList.cbegin();
|
||||
G4int i = 0, j = 0;
|
||||
G4double mem = 0, tmem = 0;
|
||||
if(verboseLevel > 0)
|
||||
{
|
||||
G4cout << "================== Deleting memory pools ==================="
|
||||
<< G4endl;
|
||||
}
|
||||
for(; itr!=fList.end();++itr)
|
||||
for(; itr != fList.cend(); ++itr)
|
||||
{
|
||||
mem = (*itr)->GetAllocatedSize();
|
||||
if(i<nStat)
|
||||
if(i < nStat)
|
||||
{
|
||||
i++;
|
||||
++i;
|
||||
tmem += mem;
|
||||
(*itr)->ResetStorage();
|
||||
continue;
|
||||
}
|
||||
j++;
|
||||
++j;
|
||||
tmem += mem;
|
||||
if(verboseLevel>1)
|
||||
if(verboseLevel > 1)
|
||||
{
|
||||
G4cout << "Pool ID '" << (*itr)->GetPoolType() << "', size : "
|
||||
<< std::setprecision(3) << mem/1048576
|
||||
G4cout << "Pool ID '" << (*itr)->GetPoolType()
|
||||
<< "', size : " << std::setprecision(3) << mem / 1048576
|
||||
<< std::setprecision(6) << " MB" << G4endl;
|
||||
}
|
||||
(*itr)->ResetStorage();
|
||||
delete *itr;
|
||||
delete *itr;
|
||||
}
|
||||
if(verboseLevel>0)
|
||||
if(verboseLevel > 0)
|
||||
{
|
||||
G4cout << "Number of memory pools allocated: " << Size()
|
||||
<< "; of which, static: " << i << G4endl;
|
||||
G4cout << "Dynamic pools deleted: " << j
|
||||
G4cout << "Dynamic pools deleted: " << j
|
||||
<< " / Total memory freed: " << std::setprecision(2)
|
||||
<< tmem/1048576 << std::setprecision(6) << " MB" << G4endl;
|
||||
<< tmem / 1048576 << std::setprecision(6) << " MB" << G4endl;
|
||||
G4cout << "============================================================"
|
||||
<< G4endl;
|
||||
}
|
||||
fList.clear();
|
||||
}
|
||||
|
||||
G4int G4AllocatorList::Size() const
|
||||
{
|
||||
return fList.size();
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
G4int G4AllocatorList::Size() const { return fList.size(); }
|
||||
|
||||
@@ -23,16 +23,10 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
// G4AllocatorPool
|
||||
//
|
||||
// Implementation file
|
||||
// G4AllocatorPool class implementation
|
||||
//
|
||||
// Author: G.Cosmo, November 2000
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4AllocatorPool.hh"
|
||||
|
||||
@@ -40,31 +34,33 @@
|
||||
// G4AllocatorPool constructor
|
||||
// ************************************************************
|
||||
//
|
||||
G4AllocatorPool::G4AllocatorPool( unsigned int sz )
|
||||
: esize(sz<sizeof(G4PoolLink) ? sizeof(G4PoolLink) : sz),
|
||||
csize(sz<1024/2-16 ? 1024-16 : sz*10-16),
|
||||
chunks(0), head(0), nchunks(0)
|
||||
{
|
||||
}
|
||||
G4AllocatorPool::G4AllocatorPool(unsigned int sz)
|
||||
: esize(sz < sizeof(G4PoolLink) ? sizeof(G4PoolLink) : sz)
|
||||
, csize(sz < 1024 / 2 - 16 ? 1024 - 16 : sz * 10 - 16)
|
||||
{}
|
||||
|
||||
// ************************************************************
|
||||
// G4AllocatorPool copy constructor
|
||||
// ************************************************************
|
||||
//
|
||||
G4AllocatorPool::G4AllocatorPool(const G4AllocatorPool& right)
|
||||
: esize(right.esize), csize(right.csize),
|
||||
chunks(right.chunks), head(right.head), nchunks(right.nchunks)
|
||||
{
|
||||
}
|
||||
: esize(right.esize)
|
||||
, csize(right.csize)
|
||||
, chunks(right.chunks)
|
||||
, head(right.head)
|
||||
, nchunks(right.nchunks)
|
||||
{}
|
||||
|
||||
// ************************************************************
|
||||
// G4AllocatorPool operator=
|
||||
// ************************************************************
|
||||
//
|
||||
G4AllocatorPool&
|
||||
G4AllocatorPool::operator= (const G4AllocatorPool& right)
|
||||
G4AllocatorPool& G4AllocatorPool::operator=(const G4AllocatorPool& right)
|
||||
{
|
||||
if (&right == this) { return *this; }
|
||||
if(&right == this)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
chunks = right.chunks;
|
||||
head = right.head;
|
||||
nchunks = right.nchunks;
|
||||
@@ -75,10 +71,7 @@ G4AllocatorPool::operator= (const G4AllocatorPool& right)
|
||||
// G4AllocatorPool destructor
|
||||
// ************************************************************
|
||||
//
|
||||
G4AllocatorPool::~G4AllocatorPool()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
G4AllocatorPool::~G4AllocatorPool() { Reset(); }
|
||||
|
||||
// ************************************************************
|
||||
// Reset
|
||||
@@ -89,15 +82,15 @@ void G4AllocatorPool::Reset()
|
||||
// Free all chunks
|
||||
//
|
||||
G4PoolChunk* n = chunks;
|
||||
G4PoolChunk* p = 0;
|
||||
while (n)
|
||||
G4PoolChunk* p = nullptr;
|
||||
while(n)
|
||||
{
|
||||
p = n;
|
||||
n = n->next;
|
||||
delete p;
|
||||
}
|
||||
head = 0;
|
||||
chunks = 0;
|
||||
head = nullptr;
|
||||
chunks = nullptr;
|
||||
nchunks = 0;
|
||||
}
|
||||
|
||||
@@ -111,18 +104,18 @@ void G4AllocatorPool::Grow()
|
||||
// elements of size 'esize'
|
||||
//
|
||||
G4PoolChunk* n = new G4PoolChunk(csize);
|
||||
n->next = chunks;
|
||||
chunks = n;
|
||||
nchunks++;
|
||||
n->next = chunks;
|
||||
chunks = n;
|
||||
++nchunks;
|
||||
|
||||
const int nelem = csize/esize;
|
||||
char* start = n->mem;
|
||||
char* last = &start[(nelem-1)*esize];
|
||||
for (char* p=start; p<last; p+=esize)
|
||||
const int nelem = csize / esize;
|
||||
char* start = n->mem;
|
||||
char* last = &start[(nelem - 1) * esize];
|
||||
for(char* p = start; p < last; p += esize)
|
||||
{
|
||||
reinterpret_cast<G4PoolLink*>(p)->next
|
||||
= reinterpret_cast<G4PoolLink*>(p+esize);
|
||||
reinterpret_cast<G4PoolLink*>(p)->next =
|
||||
reinterpret_cast<G4PoolLink*>(p + esize);
|
||||
}
|
||||
reinterpret_cast<G4PoolLink*>(last)->next = 0;
|
||||
reinterpret_cast<G4PoolLink*>(last)->next = nullptr;
|
||||
head = reinterpret_cast<G4PoolLink*>(start);
|
||||
}
|
||||
|
||||
@@ -23,70 +23,86 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
/*
|
||||
* G4BuffercoutDestination.cc
|
||||
*
|
||||
* Created on: Apr 14, 2017
|
||||
* Author: adotti
|
||||
*/
|
||||
// G4BuffercoutDestination class implementation
|
||||
//
|
||||
// Author: A.Dotti (SLAC), 14 April 2017
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4BuffercoutDestination.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
#include <iostream>
|
||||
|
||||
#include "G4AutoLock.hh"
|
||||
#include "G4BuffercoutDestination.hh"
|
||||
|
||||
G4BuffercoutDestination::G4BuffercoutDestination(size_t max) :
|
||||
m_buffer_out("") , m_buffer_err(""), m_currentSize_out(0) ,
|
||||
m_currentSize_err(0), m_maxSize(max) {}
|
||||
// --------------------------------------------------------------------
|
||||
G4BuffercoutDestination::G4BuffercoutDestination(std::size_t max)
|
||||
: m_buffer_out("")
|
||||
, m_buffer_err("")
|
||||
, m_maxSize(max)
|
||||
{}
|
||||
|
||||
G4BuffercoutDestination::~G4BuffercoutDestination() {
|
||||
Finalize();
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
G4BuffercoutDestination::~G4BuffercoutDestination() { Finalize(); }
|
||||
|
||||
void G4BuffercoutDestination::Finalize() {
|
||||
// --------------------------------------------------------------------
|
||||
void G4BuffercoutDestination::Finalize()
|
||||
{
|
||||
FlushG4cerr();
|
||||
FlushG4cout();
|
||||
}
|
||||
|
||||
G4int G4BuffercoutDestination::ReceiveG4cout(const G4String& msg) {
|
||||
// --------------------------------------------------------------------
|
||||
G4int G4BuffercoutDestination::ReceiveG4cout(const G4String& msg)
|
||||
{
|
||||
m_currentSize_out += msg.size();
|
||||
m_buffer_out << msg;
|
||||
//If there is a max size and it has been reached, flush
|
||||
if ( m_maxSize>0 && m_currentSize_out >= m_maxSize ) {
|
||||
FlushG4cout();
|
||||
// If there is a max size and it has been reached, flush
|
||||
if(m_maxSize > 0 && m_currentSize_out >= m_maxSize)
|
||||
{
|
||||
FlushG4cout();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
G4int G4BuffercoutDestination::ReceiveG4cerr(const G4String& msg) {
|
||||
// --------------------------------------------------------------------
|
||||
G4int G4BuffercoutDestination::ReceiveG4cerr(const G4String& msg)
|
||||
{
|
||||
m_currentSize_err += msg.size();
|
||||
m_buffer_err << msg;
|
||||
//If there is a max size and it has been reached, flush
|
||||
if ( m_maxSize>0 && m_currentSize_err >= m_maxSize ) {
|
||||
FlushG4cerr();
|
||||
// If there is a max size and it has been reached, flush
|
||||
if(m_maxSize > 0 && m_currentSize_err >= m_maxSize)
|
||||
{
|
||||
FlushG4cerr();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
G4int G4BuffercoutDestination::FlushG4cout() {
|
||||
std::cout<<m_buffer_out.str()<<std::flush;
|
||||
// --------------------------------------------------------------------
|
||||
G4int G4BuffercoutDestination::FlushG4cout()
|
||||
{
|
||||
std::cout << m_buffer_out.str() << std::flush;
|
||||
ResetCout();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void G4BuffercoutDestination::ResetCout() {
|
||||
// --------------------------------------------------------------------
|
||||
void G4BuffercoutDestination::ResetCout()
|
||||
{
|
||||
m_buffer_out.str("");
|
||||
m_buffer_out.clear();
|
||||
m_currentSize_out = 0;
|
||||
}
|
||||
|
||||
G4int G4BuffercoutDestination::FlushG4cerr() {
|
||||
std::cerr<<m_buffer_err.str()<<std::flush;
|
||||
// --------------------------------------------------------------------
|
||||
G4int G4BuffercoutDestination::FlushG4cerr()
|
||||
{
|
||||
std::cerr << m_buffer_err.str() << std::flush;
|
||||
ResetCerr();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void G4BuffercoutDestination::ResetCerr() {
|
||||
// --------------------------------------------------------------------
|
||||
void G4BuffercoutDestination::ResetCerr()
|
||||
{
|
||||
m_buffer_err.str("");
|
||||
m_buffer_err.clear();
|
||||
m_currentSize_err = 0;
|
||||
|
||||
@@ -23,14 +23,19 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4CacheDetails class implementation
|
||||
//
|
||||
// Author: A.Dotti, 21 October 2013 - First implementation
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// Decalare needed static data member for fully specialized version of cache
|
||||
// Declare needed static data member for fully specialized version of cache
|
||||
//
|
||||
#include "G4CacheDetails.hh"
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4CacheReference<G4double>::cache_container*&
|
||||
G4CacheReference<G4double>::cache()
|
||||
{
|
||||
G4ThreadLocalStatic std::vector<G4double>* _instance = nullptr;
|
||||
return _instance;
|
||||
G4ThreadLocalStatic std::vector<G4double>* _instance = nullptr;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
@@ -23,79 +23,76 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4DataVector class implementation
|
||||
//
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------
|
||||
// GEANT 4 class implementation file
|
||||
//
|
||||
// G4DataVector.cc
|
||||
//
|
||||
// History:
|
||||
// 18 Sep. 2001, H.Kurashige : Structure created based on object model
|
||||
// --------------------------------------------------------------
|
||||
// Author: H.Kurashige, 18 September 2001
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4DataVector.hh"
|
||||
#include <iomanip>
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4DataVector::G4DataVector()
|
||||
: std::vector<G4double>()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
G4DataVector::G4DataVector(size_t cap)
|
||||
// --------------------------------------------------------------------
|
||||
G4DataVector::G4DataVector(std::size_t cap)
|
||||
: std::vector<G4double>(cap, 0.0)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
G4DataVector::G4DataVector(size_t cap, G4double value)
|
||||
// --------------------------------------------------------------------
|
||||
G4DataVector::G4DataVector(std::size_t cap, G4double value)
|
||||
: std::vector<G4double>(cap, value)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
G4DataVector::~G4DataVector()
|
||||
{
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
G4DataVector::~G4DataVector() {}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4bool G4DataVector::Store(std::ofstream& fOut, G4bool ascii)
|
||||
{
|
||||
// Ascii mode
|
||||
if (ascii)
|
||||
if(ascii)
|
||||
{
|
||||
fOut << *this;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Binary Mode
|
||||
G4int sizeV = G4int(size());
|
||||
fOut.write((char*)(&sizeV), sizeof sizeV);
|
||||
G4int sizeV = G4int(size());
|
||||
fOut.write((char*) (&sizeV), sizeof sizeV);
|
||||
|
||||
G4double* value = new G4double[sizeV];
|
||||
size_t i=0;
|
||||
for (const_iterator itr=begin(); itr!=end(); itr++, i++)
|
||||
std::size_t i = 0;
|
||||
for(auto itr = cbegin(); itr != cend(); ++itr, ++i)
|
||||
{
|
||||
value[i] = *itr;
|
||||
value[i] = *itr;
|
||||
}
|
||||
fOut.write((char*)(value), sizeV*(sizeof (G4double)) );
|
||||
delete [] value;
|
||||
|
||||
fOut.write((char*) (value), sizeV * (sizeof(G4double)));
|
||||
delete[] value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4bool G4DataVector::Retrieve(std::ifstream& fIn, G4bool ascii)
|
||||
{
|
||||
clear();
|
||||
G4int sizeV=0;
|
||||
|
||||
G4int sizeV = 0;
|
||||
|
||||
// retrieve in ascii mode
|
||||
if (ascii)
|
||||
if(ascii)
|
||||
{
|
||||
// contents
|
||||
fIn >> sizeV;
|
||||
if (fIn.fail()) { return false; }
|
||||
if (sizeV<=0)
|
||||
if(fIn.fail())
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
return false;
|
||||
}
|
||||
if(sizeV <= 0)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
G4cerr << "G4DataVector::Retrieve():";
|
||||
G4cerr << " Invalid vector size: " << sizeV << G4endl;
|
||||
#endif
|
||||
@@ -103,40 +100,44 @@ G4bool G4DataVector::Retrieve(std::ifstream& fIn, G4bool ascii)
|
||||
}
|
||||
|
||||
reserve(sizeV);
|
||||
for(G4int i = 0; i < sizeV ; i++)
|
||||
for(G4int i = 0; i < sizeV; ++i)
|
||||
{
|
||||
G4double vData=0.0;
|
||||
G4double vData = 0.0;
|
||||
fIn >> vData;
|
||||
if (fIn.fail()) { return false; }
|
||||
if(fIn.fail())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
push_back(vData);
|
||||
}
|
||||
return true ;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// retrieve in binary mode
|
||||
fIn.read((char*)(&sizeV), sizeof sizeV);
|
||||
|
||||
fIn.read((char*) (&sizeV), sizeof sizeV);
|
||||
|
||||
G4double* value = new G4double[sizeV];
|
||||
fIn.read((char*)(value), sizeV*(sizeof(G4double)) );
|
||||
if (G4int(fIn.gcount()) != G4int(sizeV*(sizeof(G4double))) )
|
||||
fIn.read((char*) (value), sizeV * (sizeof(G4double)));
|
||||
if(G4int(fIn.gcount()) != G4int(sizeV * (sizeof(G4double))))
|
||||
{
|
||||
delete [] value;
|
||||
delete[] value;
|
||||
return false;
|
||||
}
|
||||
|
||||
reserve(sizeV);
|
||||
for(G4int i = 0; i < sizeV; i++)
|
||||
for(G4int i = 0; i < sizeV; ++i)
|
||||
{
|
||||
push_back(value[i]);
|
||||
}
|
||||
delete [] value;
|
||||
delete[] value;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
std::ostream& operator<<(std::ostream& out, const G4DataVector& pv)
|
||||
{
|
||||
out << pv.size() << std::setprecision(12) << G4endl;
|
||||
for(size_t i = 0; i < pv.size(); i++)
|
||||
out << pv.size() << std::setprecision(12) << G4endl;
|
||||
for(std::size_t i = 0; i < pv.size(); ++i)
|
||||
{
|
||||
out << pv[i] << G4endl;
|
||||
}
|
||||
@@ -144,4 +145,3 @@ std::ostream& operator<<(std::ostream& out, const G4DataVector& pv)
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,48 +23,45 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4ErrorPropagatorData class implementation
|
||||
//
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class implementation file
|
||||
// Author: P.Arce, 2004
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4ErrorPropagatorData.hh"
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
G4ThreadLocal G4ErrorPropagatorData* G4ErrorPropagatorData::fpInstance = 0;
|
||||
G4ThreadLocal G4ErrorPropagatorData* G4ErrorPropagatorData::fpInstance =
|
||||
nullptr;
|
||||
G4ThreadLocal G4int G4ErrorPropagatorData::theVerbosity = 0;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
G4ErrorPropagatorData::G4ErrorPropagatorData()
|
||||
: theMode(G4ErrorMode_PropTest), theState(G4ErrorState_PreInit),
|
||||
theStage(G4ErrorStage_Inflation), theTarget(0)
|
||||
{
|
||||
}
|
||||
: theMode(G4ErrorMode_PropTest)
|
||||
, theState(G4ErrorState_PreInit)
|
||||
, theStage(G4ErrorStage_Inflation)
|
||||
{}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4ErrorPropagatorData::~G4ErrorPropagatorData()
|
||||
{
|
||||
delete fpInstance; fpInstance = 0;
|
||||
delete fpInstance;
|
||||
fpInstance = nullptr;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4ErrorPropagatorData* G4ErrorPropagatorData::GetErrorPropagatorData()
|
||||
{
|
||||
if (fpInstance == 0)
|
||||
if(fpInstance == nullptr)
|
||||
{
|
||||
fpInstance = new G4ErrorPropagatorData;
|
||||
}
|
||||
return fpInstance;
|
||||
}
|
||||
|
||||
G4int G4ErrorPropagatorData::verbose()
|
||||
{
|
||||
return theVerbosity;
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
G4int G4ErrorPropagatorData::verbose() { return theVerbosity; }
|
||||
|
||||
void G4ErrorPropagatorData::SetVerbose( G4int ver )
|
||||
{
|
||||
theVerbosity = ver;
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
void G4ErrorPropagatorData::SetVerbose(G4int ver) { theVerbosity = ver; }
|
||||
|
||||
@@ -23,28 +23,25 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4Exception implementation
|
||||
//
|
||||
//
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
// G4Exception
|
||||
// ----------------------------------------------------------------------
|
||||
// Authors: G.Cosmo, M.Asai - May 1999 - First implementation
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4Exception.hh"
|
||||
#include "G4StateManager.hh"
|
||||
|
||||
void G4Exception(const char* originOfException,
|
||||
const char* exceptionCode,
|
||||
G4ExceptionSeverity severity,
|
||||
const char* description)
|
||||
// --------------------------------------------------------------------
|
||||
void G4Exception(const char* originOfException, const char* exceptionCode,
|
||||
G4ExceptionSeverity severity, const char* description)
|
||||
{
|
||||
G4VExceptionHandler* exceptionHandler
|
||||
= G4StateManager::GetStateManager()->GetExceptionHandler();
|
||||
G4VExceptionHandler* exceptionHandler =
|
||||
G4StateManager::GetStateManager()->GetExceptionHandler();
|
||||
G4bool toBeAborted = true;
|
||||
if(exceptionHandler)
|
||||
if(exceptionHandler != nullptr)
|
||||
{
|
||||
toBeAborted = exceptionHandler
|
||||
->Notify(originOfException,exceptionCode,severity,description);
|
||||
toBeAborted = exceptionHandler->Notify(originOfException, exceptionCode,
|
||||
severity, description);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -59,59 +56,58 @@ void G4Exception(const char* originOfException,
|
||||
<< 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;
|
||||
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;
|
||||
}
|
||||
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)
|
||||
// --------------------------------------------------------------------
|
||||
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)
|
||||
// --------------------------------------------------------------------
|
||||
void G4Exception(const char* originOfException, const char* exceptionCode,
|
||||
G4ExceptionSeverity severity,
|
||||
G4ExceptionDescription& description, const char* comments)
|
||||
{
|
||||
description << comments << G4endl;
|
||||
G4Exception(originOfException, exceptionCode, severity, description);
|
||||
|
||||
@@ -23,10 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
// G4FilecoutDestination.cc
|
||||
// G4FilecoutDestination class implementation
|
||||
//
|
||||
// Author: A.Dotti (SLAC), April 2017
|
||||
// --------------------------------------------------------------------
|
||||
@@ -35,43 +32,52 @@
|
||||
|
||||
#include <ios>
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4FilecoutDestination::~G4FilecoutDestination()
|
||||
{
|
||||
Close();
|
||||
if ( m_output ) m_output.reset();
|
||||
if(m_output)
|
||||
m_output.reset();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void G4FilecoutDestination::Open(std::ios_base::openmode mode)
|
||||
{
|
||||
if ( m_name.isNull() )
|
||||
if(m_name.isNull())
|
||||
{
|
||||
#ifndef __MIC
|
||||
// Cannot use G4Exception, because G4cout/G4cerr is not setup
|
||||
throw std::ios_base::failure("No output file name specified");
|
||||
// Cannot use G4Exception, because G4cout/G4cerr is not setup
|
||||
throw std::ios_base::failure("No output file name specified");
|
||||
#endif
|
||||
}
|
||||
if ( m_output != nullptr && m_output->is_open() ) Close();
|
||||
m_output.reset( new std::ofstream(m_name , std::ios_base::out|mode) );
|
||||
if(m_output != nullptr && m_output->is_open())
|
||||
Close();
|
||||
m_output.reset(new std::ofstream(m_name, std::ios_base::out | mode));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void G4FilecoutDestination::Close()
|
||||
{
|
||||
if ( m_output && m_output->is_open() )
|
||||
if(m_output && m_output->is_open())
|
||||
{
|
||||
m_output->close();
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4int G4FilecoutDestination::ReceiveG4cout(const G4String& msg)
|
||||
{
|
||||
if ( m_output == nullptr || ! m_output->is_open() ) Open(m_mode);
|
||||
if(m_output == nullptr || !m_output->is_open())
|
||||
Open(m_mode);
|
||||
*m_output << msg;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4int G4FilecoutDestination::ReceiveG4cerr(const G4String& msg)
|
||||
{
|
||||
if ( m_output == nullptr || ! m_output->is_open() ) Open(m_mode);
|
||||
if(m_output == nullptr || !m_output->is_open())
|
||||
Open(m_mode);
|
||||
*m_output << msg;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -23,46 +23,38 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4GeometryTolerance class implementation
|
||||
//
|
||||
//
|
||||
// class G4GeometryTolerance
|
||||
//
|
||||
// Implementation
|
||||
//
|
||||
// Author:
|
||||
// 30.10.06 - G.Cosmo, first implementation
|
||||
// Author: G.Cosmo (CERN), 30 October 2006
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4GeometryTolerance.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
#include "G4AutoDelete.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
// Static class instance
|
||||
// ***************************************************************************
|
||||
//
|
||||
G4ThreadLocal G4GeometryTolerance* G4GeometryTolerance::fpInstance = 0;
|
||||
G4ThreadLocal G4GeometryTolerance* G4GeometryTolerance::fpInstance = nullptr;
|
||||
|
||||
// ***************************************************************************
|
||||
// Constructor.
|
||||
// ***************************************************************************
|
||||
//
|
||||
G4GeometryTolerance::G4GeometryTolerance() : fInitialised(false)
|
||||
G4GeometryTolerance::G4GeometryTolerance()
|
||||
{
|
||||
fCarTolerance = 1E-9*mm;
|
||||
fAngTolerance = 1E-9*rad;
|
||||
fRadTolerance = 1E-9*mm;
|
||||
fCarTolerance = 1E-9 * mm;
|
||||
fAngTolerance = 1E-9 * rad;
|
||||
fRadTolerance = 1E-9 * mm;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
// Empty destructor.
|
||||
// ***************************************************************************
|
||||
//
|
||||
G4GeometryTolerance::~G4GeometryTolerance()
|
||||
{
|
||||
}
|
||||
G4GeometryTolerance::~G4GeometryTolerance() {}
|
||||
|
||||
// ***************************************************************************
|
||||
// Returns the instance of the singleton.
|
||||
@@ -71,12 +63,12 @@ G4GeometryTolerance::~G4GeometryTolerance()
|
||||
//
|
||||
G4GeometryTolerance* G4GeometryTolerance::GetInstance()
|
||||
{
|
||||
if (fpInstance == 0)
|
||||
if(fpInstance == nullptr)
|
||||
{
|
||||
fpInstance = new G4GeometryTolerance;
|
||||
fpInstance = new G4GeometryTolerance;
|
||||
G4AutoDelete::Register(fpInstance);
|
||||
}
|
||||
return fpInstance;
|
||||
return fpInstance;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
@@ -105,18 +97,17 @@ G4double G4GeometryTolerance::GetRadialTolerance() const
|
||||
//
|
||||
void G4GeometryTolerance::SetSurfaceTolerance(G4double worldExtent)
|
||||
{
|
||||
if (!fInitialised)
|
||||
if(!fInitialised)
|
||||
{
|
||||
fCarTolerance = fRadTolerance = worldExtent*1E-11;
|
||||
fInitialised = true;
|
||||
fCarTolerance = fRadTolerance = worldExtent * 1E-11;
|
||||
fInitialised = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
G4cout << "WARNING - G4GeometryTolerance::SetSurfaceTolerance()" << G4endl
|
||||
<< " Tolerance can only be set once. Currently set to: "
|
||||
<< fCarTolerance/mm << " mm." << G4endl;
|
||||
G4Exception("G4GeometryTolerance::SetSurfaceTolerance()",
|
||||
"NotApplicable", JustWarning,
|
||||
"The tolerance has been already set!");
|
||||
<< fCarTolerance / mm << " mm." << G4endl;
|
||||
G4Exception("G4GeometryTolerance::SetSurfaceTolerance()", "NotApplicable",
|
||||
JustWarning, "The tolerance has been already set!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,39 +23,23 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4LPhysicsFreeVector class implementation
|
||||
//
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// Class G4LPhysicsFreeVector
|
||||
// Derived from base class G4PhysicsVector
|
||||
// This is a free vector for Low Energy Physics cross section data
|
||||
//
|
||||
// F.W. Jones, TRIUMF, 04-JUN-96
|
||||
//
|
||||
// Modified:
|
||||
// 19 Jun. 2009, V.Ivanchenko : removed hidden bin
|
||||
// 19 Jun. 2009, V.Ivanchenko : removed FindBinLocation
|
||||
//
|
||||
// Author: F.W. Jones (TRIUMF), 04-June-1996 - First implementation
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4LPhysicsFreeVector.hh"
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
G4LPhysicsFreeVector::G4LPhysicsFreeVector()
|
||||
: G4PhysicsFreeVector()
|
||||
: G4PhysicsFreeVector()
|
||||
{}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
G4LPhysicsFreeVector::G4LPhysicsFreeVector(size_t length, G4double, G4double)
|
||||
G4LPhysicsFreeVector::G4LPhysicsFreeVector(std::size_t length, G4double,
|
||||
G4double)
|
||||
: G4PhysicsFreeVector(length)
|
||||
{}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
G4LPhysicsFreeVector::~G4LPhysicsFreeVector()
|
||||
{}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4LPhysicsFreeVector::~G4LPhysicsFreeVector() {}
|
||||
|
||||
@@ -23,10 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
// G4LockcoutDestination.cc
|
||||
// G4LockcoutDestination class implementation
|
||||
//
|
||||
// Author: A.Dotti (SLAC), April 2017
|
||||
// --------------------------------------------------------------------
|
||||
@@ -39,18 +36,19 @@ namespace
|
||||
G4Mutex out_mutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
G4LockcoutDestination::~G4LockcoutDestination()
|
||||
{
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
G4LockcoutDestination::~G4LockcoutDestination() {}
|
||||
|
||||
G4int G4LockcoutDestination::ReceiveG4cout(const G4String& msg )
|
||||
// --------------------------------------------------------------------
|
||||
G4int G4LockcoutDestination::ReceiveG4cout(const G4String& msg)
|
||||
{
|
||||
G4AutoLock l(&out_mutex);
|
||||
// Forward call to base class
|
||||
return G4coutDestination::ReceiveG4cout(msg);
|
||||
}
|
||||
|
||||
G4int G4LockcoutDestination::ReceiveG4cerr(const G4String& msg )
|
||||
// --------------------------------------------------------------------
|
||||
G4int G4LockcoutDestination::ReceiveG4cerr(const G4String& msg)
|
||||
{
|
||||
G4AutoLock l(&out_mutex);
|
||||
return G4coutDestination::ReceiveG4cerr(msg);
|
||||
|
||||
@@ -22,69 +22,80 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4MTBarrier class implementation
|
||||
//
|
||||
// ---------------------------------------------------------------
|
||||
/*
|
||||
* G4MTBarrier.cc
|
||||
*
|
||||
* Created on: Feb 10, 2016
|
||||
* Author: adotti
|
||||
* Updated on: Feb 9, 2018
|
||||
* Author: jmadsen
|
||||
*/
|
||||
// Author: A.Dotti (SLAC), 10 February 2016
|
||||
// Revision: J.Madsen (NERSC), 09 February 2018
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4MTBarrier.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
G4MTBarrier::G4MTBarrier(unsigned int numThreads ) :
|
||||
m_numActiveThreads(numThreads),
|
||||
m_counter(0)
|
||||
// --------------------------------------------------------------------
|
||||
G4MTBarrier::G4MTBarrier(unsigned int numThreads)
|
||||
: m_numActiveThreads(numThreads)
|
||||
{}
|
||||
|
||||
void G4MTBarrier::ThisWorkerReady() {
|
||||
//Step-1: Worker acquires lock on shared resource (the counter)
|
||||
// --------------------------------------------------------------------
|
||||
void G4MTBarrier::ThisWorkerReady()
|
||||
{
|
||||
// Step-1: Worker acquires lock on shared resource (the counter)
|
||||
G4AutoLock lock(&m_mutex);
|
||||
//Step-2: Worker increases counter
|
||||
// Step-2: Worker increases counter
|
||||
++m_counter;
|
||||
//Step-3: Worker broadcasts that the counter has changed
|
||||
// Step-3: Worker broadcasts that the counter has changed
|
||||
G4CONDITIONBROADCAST(&m_counterChanged);
|
||||
//Step-4: Worker waits on condition to continue
|
||||
G4CONDITIONWAIT(&m_continue,&lock);
|
||||
// Step-4: Worker waits on condition to continue
|
||||
G4CONDITIONWAIT(&m_continue, &lock);
|
||||
}
|
||||
|
||||
void G4MTBarrier::Wait() {
|
||||
while (true)
|
||||
// --------------------------------------------------------------------
|
||||
void G4MTBarrier::Wait()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
//Step-2: Acquires lock on shared resource (the counter)
|
||||
G4AutoLock lock(&m_mutex);
|
||||
//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
|
||||
G4CONDITIONWAIT(&m_counterChanged,&lock);
|
||||
// Step-2: Acquires lock on shared resource (the counter)
|
||||
G4AutoLock lock(&m_mutex);
|
||||
// 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
|
||||
G4CONDITIONWAIT(&m_counterChanged, &lock);
|
||||
}
|
||||
}
|
||||
|
||||
void G4MTBarrier::ReleaseBarrier() {
|
||||
//Step-4: re-aquire lock and re-set shared resource for future re-use
|
||||
// --------------------------------------------------------------------
|
||||
void G4MTBarrier::ReleaseBarrier()
|
||||
{
|
||||
// Step-4: re-aquire lock and re-set shared resource for future re-use
|
||||
G4AutoLock lock(&m_mutex);
|
||||
m_counter = 0;
|
||||
G4CONDITIONBROADCAST(&m_continue);
|
||||
}
|
||||
|
||||
void G4MTBarrier::WaitForReadyWorkers() {
|
||||
//Step-1: Master enters a loop to wait all workers to be ready
|
||||
// --------------------------------------------------------------------
|
||||
void G4MTBarrier::WaitForReadyWorkers()
|
||||
{
|
||||
// Step-1: Master enters a loop to wait all workers to be ready
|
||||
Wait();
|
||||
//Done, all workers are ready, broadcast a continue signal
|
||||
// Done, all workers are ready, broadcast a continue signal
|
||||
ReleaseBarrier();
|
||||
}
|
||||
|
||||
void G4MTBarrier::ResetCounter() {
|
||||
// --------------------------------------------------------------------
|
||||
void G4MTBarrier::ResetCounter()
|
||||
{
|
||||
G4AutoLock l(&m_mutex);
|
||||
m_counter = 0;
|
||||
}
|
||||
|
||||
unsigned int G4MTBarrier::GetCounter() {
|
||||
// --------------------------------------------------------------------
|
||||
unsigned int G4MTBarrier::GetCounter()
|
||||
{
|
||||
G4AutoLock l(&m_mutex);
|
||||
const unsigned int result = m_counter;
|
||||
return result;
|
||||
|
||||
@@ -23,121 +23,126 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// G4MTcoutDestination class implementation
|
||||
//
|
||||
// G4MTcoutDestination.cc
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// Authors: M.Asai, A.Dotti (SLAC) - 23 May 2013
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
#include <sstream>
|
||||
#include <assert.h>
|
||||
#include <sstream>
|
||||
|
||||
#include "G4MTcoutDestination.hh"
|
||||
#include "G4LockcoutDestination.hh"
|
||||
#include "G4MasterForwardcoutDestination.hh"
|
||||
#include "G4FilecoutDestination.hh"
|
||||
#include "G4BuffercoutDestination.hh"
|
||||
#include "G4strstreambuf.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
#include "G4BuffercoutDestination.hh"
|
||||
#include "G4FilecoutDestination.hh"
|
||||
#include "G4LockcoutDestination.hh"
|
||||
#include "G4MTcoutDestination.hh"
|
||||
#include "G4MasterForwardcoutDestination.hh"
|
||||
#include "G4strstreambuf.hh"
|
||||
|
||||
namespace
|
||||
{
|
||||
G4String empty = "";
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4MTcoutDestination::G4MTcoutDestination(const G4int& threadId)
|
||||
: ref_defaultOut(nullptr), ref_masterOut(nullptr),
|
||||
masterDestinationFlag(true),masterDestinationFmtFlag(true),
|
||||
id(threadId), useBuffer(false), ignoreCout(false), ignoreInit(true),
|
||||
prefix("G4WT")
|
||||
: id(threadId)
|
||||
{
|
||||
// TODO: Move these two out of here and in the caller
|
||||
G4coutbuf.SetDestination(this);
|
||||
G4cerrbuf.SetDestination(this);
|
||||
|
||||
stateMgr=G4StateManager::GetStateManager();
|
||||
SetDefaultOutput(masterDestinationFlag,masterDestinationFmtFlag);
|
||||
stateMgr = G4StateManager::GetStateManager();
|
||||
SetDefaultOutput(masterDestinationFlag, masterDestinationFmtFlag);
|
||||
}
|
||||
|
||||
void G4MTcoutDestination::SetDefaultOutput( G4bool addmasterDestination ,
|
||||
G4bool formatAlsoMaster )
|
||||
// --------------------------------------------------------------------
|
||||
void G4MTcoutDestination::SetDefaultOutput(G4bool addmasterDestination,
|
||||
G4bool formatAlsoMaster)
|
||||
{
|
||||
masterDestinationFlag = addmasterDestination;
|
||||
masterDestinationFlag = addmasterDestination;
|
||||
masterDestinationFmtFlag = formatAlsoMaster;
|
||||
// Formatter: add prefix to each thread
|
||||
const auto f = [this](G4String& msg)->G4bool {
|
||||
const auto f = [this](G4String& msg) -> G4bool {
|
||||
std::ostringstream str;
|
||||
str<<prefix;
|
||||
if ( id!=G4Threading::GENERICTHREAD_ID ) str<<id;
|
||||
str<<" > "<<msg;
|
||||
str << prefix;
|
||||
if(id != G4Threading::GENERICTHREAD_ID)
|
||||
str << id;
|
||||
str << " > " << msg;
|
||||
msg = str.str();
|
||||
return true;
|
||||
};
|
||||
// Block cout if not in correct state
|
||||
const auto filter_out = [this](G4String&)->G4bool {
|
||||
if (this->ignoreCout ||
|
||||
( this->ignoreInit &&
|
||||
this->stateMgr->GetCurrentState() == G4State_Init ) )
|
||||
{ return false; }
|
||||
const auto filter_out = [this](G4String&) -> G4bool {
|
||||
if(this->ignoreCout ||
|
||||
(this->ignoreInit && this->stateMgr->GetCurrentState() == G4State_Init))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
// Default behavior, add a destination that uses cout and uses a mutex
|
||||
auto output = G4coutDestinationUPtr( new G4LockcoutDestination );
|
||||
auto output = G4coutDestinationUPtr(new G4LockcoutDestination);
|
||||
ref_defaultOut = output.get();
|
||||
output->AddCoutTransformer(filter_out);
|
||||
output->AddCoutTransformer(f);
|
||||
output->AddCerrTransformer(f);
|
||||
push_back( std::move(output) );
|
||||
if ( addmasterDestination )
|
||||
push_back(std::move(output));
|
||||
if(addmasterDestination)
|
||||
{
|
||||
AddMasterOutput(formatAlsoMaster);
|
||||
AddMasterOutput(formatAlsoMaster);
|
||||
}
|
||||
}
|
||||
|
||||
void G4MTcoutDestination::AddMasterOutput(G4bool formatAlsoMaster )
|
||||
// --------------------------------------------------------------------
|
||||
void G4MTcoutDestination::AddMasterOutput(G4bool formatAlsoMaster)
|
||||
{
|
||||
// Add a destination, that forwards the message to the master thread
|
||||
auto forwarder = G4coutDestinationUPtr( new G4MasterForwardcoutDestination );
|
||||
ref_masterOut = forwarder.get();
|
||||
const auto filter_out = [this](G4String&)->G4bool {
|
||||
if (this->ignoreCout ||
|
||||
( this->ignoreInit &&
|
||||
this->stateMgr->GetCurrentState() == G4State_Idle ) )
|
||||
{ return false; }
|
||||
auto forwarder = G4coutDestinationUPtr(new G4MasterForwardcoutDestination);
|
||||
ref_masterOut = forwarder.get();
|
||||
const auto filter_out = [this](G4String&) -> G4bool {
|
||||
if(this->ignoreCout ||
|
||||
(this->ignoreInit && this->stateMgr->GetCurrentState() == G4State_Idle))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
forwarder->AddCoutTransformer(filter_out);
|
||||
if ( formatAlsoMaster )
|
||||
if(formatAlsoMaster)
|
||||
{
|
||||
// Formatter: add prefix to each thread
|
||||
const auto f = [this](G4String& msg)->G4bool {
|
||||
std::ostringstream str;
|
||||
str<<prefix;
|
||||
if ( id!=G4Threading::GENERICTHREAD_ID ) str<<id;
|
||||
str<<" > "<<msg;
|
||||
msg = str.str();
|
||||
return true;
|
||||
};
|
||||
forwarder->AddCoutTransformer(f);
|
||||
forwarder->AddCerrTransformer(f);
|
||||
// Formatter: add prefix to each thread
|
||||
const auto f = [this](G4String& msg) -> G4bool {
|
||||
std::ostringstream str;
|
||||
str << prefix;
|
||||
if(id != G4Threading::GENERICTHREAD_ID)
|
||||
str << id;
|
||||
str << " > " << msg;
|
||||
msg = str.str();
|
||||
return true;
|
||||
};
|
||||
forwarder->AddCoutTransformer(f);
|
||||
forwarder->AddCerrTransformer(f);
|
||||
}
|
||||
push_back( std::move(forwarder ) );
|
||||
|
||||
push_back(std::move(forwarder));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4MTcoutDestination::~G4MTcoutDestination()
|
||||
{
|
||||
if ( useBuffer ) DumpBuffer();
|
||||
if(useBuffer)
|
||||
DumpBuffer();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void G4MTcoutDestination::Reset()
|
||||
{
|
||||
clear();
|
||||
SetDefaultOutput(masterDestinationFlag,masterDestinationFmtFlag);
|
||||
SetDefaultOutput(masterDestinationFlag, masterDestinationFmtFlag);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void G4MTcoutDestination::HandleFileCout(G4String fileN, G4bool ifAppend,
|
||||
G4bool suppressDefault)
|
||||
{
|
||||
@@ -145,104 +150,124 @@ void G4MTcoutDestination::HandleFileCout(G4String fileN, G4bool ifAppend,
|
||||
// stream and should discard everything in G4cerr.
|
||||
// First we create the destination with the appropriate open mode
|
||||
|
||||
std::ios_base::openmode mode = (ifAppend ? std::ios_base::app
|
||||
: std::ios_base::trunc);
|
||||
auto output = G4coutDestinationUPtr( new G4FilecoutDestination(fileN,mode));
|
||||
std::ios_base::openmode mode =
|
||||
(ifAppend ? std::ios_base::app : std::ios_base::trunc);
|
||||
auto output = G4coutDestinationUPtr(new G4FilecoutDestination(fileN, mode));
|
||||
|
||||
// This reacts only to G4cout, so let's make a filter that removes everything
|
||||
// from G4cerr
|
||||
output->AddCerrTransformer( [](G4String&) { return false;} );
|
||||
output->AddCerrTransformer([](G4String&) { return false; });
|
||||
push_back(std::move(output));
|
||||
// Silence G4cout from default formatter
|
||||
if ( suppressDefault )
|
||||
if(suppressDefault)
|
||||
{
|
||||
ref_defaultOut->AddCoutTransformer( [](G4String&) { return false; } );
|
||||
if ( ref_masterOut )
|
||||
ref_masterOut->AddCoutTransformer( [](G4String&) { return false; } );
|
||||
ref_defaultOut->AddCoutTransformer([](G4String&) { return false; });
|
||||
if(ref_masterOut)
|
||||
ref_masterOut->AddCoutTransformer([](G4String&) { return false; });
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void G4MTcoutDestination::HandleFileCerr(G4String fileN, G4bool ifAppend,
|
||||
G4bool suppressDefault)
|
||||
{
|
||||
// See HandleFileCout for explanation, switching cout with cerr
|
||||
|
||||
std::ios_base::openmode mode = (ifAppend ? std::ios_base::app
|
||||
: std::ios_base::trunc);
|
||||
auto output = G4coutDestinationUPtr( new G4FilecoutDestination(fileN,mode));
|
||||
output->AddCoutTransformer( [](G4String&) { return false;} );
|
||||
std::ios_base::openmode mode =
|
||||
(ifAppend ? std::ios_base::app : std::ios_base::trunc);
|
||||
auto output = G4coutDestinationUPtr(new G4FilecoutDestination(fileN, mode));
|
||||
output->AddCoutTransformer([](G4String&) { return false; });
|
||||
push_back(std::move(output));
|
||||
if ( suppressDefault )
|
||||
if(suppressDefault)
|
||||
{
|
||||
ref_defaultOut->AddCerrTransformer( [](G4String&) { return false; } );
|
||||
if ( ref_masterOut )
|
||||
ref_masterOut->AddCerrTransformer( [](G4String&) { return false; } );
|
||||
ref_defaultOut->AddCerrTransformer([](G4String&) { return false; });
|
||||
if(ref_masterOut)
|
||||
ref_masterOut->AddCerrTransformer([](G4String&) { return false; });
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void G4MTcoutDestination::SetCoutFileName(const G4String& fileN,
|
||||
G4bool ifAppend)
|
||||
G4bool ifAppend)
|
||||
{
|
||||
// First let's go back to the default
|
||||
Reset();
|
||||
if ( fileN != "**Screen**" )
|
||||
if(fileN != "**Screen**")
|
||||
{
|
||||
HandleFileCout(fileN,ifAppend,true);
|
||||
HandleFileCout(fileN, ifAppend, true);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void G4MTcoutDestination::EnableBuffering(G4bool flag)
|
||||
{
|
||||
// I was using buffered output and now I want to turn it off, dump current
|
||||
// buffer content and reset output
|
||||
if ( useBuffer && !flag )
|
||||
if(useBuffer && !flag)
|
||||
{
|
||||
DumpBuffer();
|
||||
Reset();
|
||||
DumpBuffer();
|
||||
Reset();
|
||||
}
|
||||
else if ( useBuffer && flag ) { /* do nothing: already using */ }
|
||||
else if ( !useBuffer && !flag ) { /* do nothing: not using */ }
|
||||
else if ( !useBuffer && flag )
|
||||
else if(useBuffer && flag)
|
||||
{ /* do nothing: already using */
|
||||
}
|
||||
else if(!useBuffer && !flag)
|
||||
{ /* do nothing: not using */
|
||||
}
|
||||
else if(!useBuffer && flag)
|
||||
{
|
||||
// Remove everything, in this case also removing the forward to the master
|
||||
// thread, we want everything to be dumpled to a file
|
||||
clear();
|
||||
const size_t infiniteSize = 0;
|
||||
push_back(G4coutDestinationUPtr(new G4BuffercoutDestination(infiniteSize)));
|
||||
// Remove everything, in this case also removing the forward to the master
|
||||
// thread, we want everything to be dumpled to a file
|
||||
clear();
|
||||
const size_t infiniteSize = 0;
|
||||
push_back(G4coutDestinationUPtr(new G4BuffercoutDestination(infiniteSize)));
|
||||
}
|
||||
else // Should never happen
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
else { assert(false); } // Should never happen
|
||||
useBuffer = flag;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void G4MTcoutDestination::AddCoutFileName(const G4String& fileN,
|
||||
G4bool ifAppend)
|
||||
G4bool ifAppend)
|
||||
{
|
||||
// This is like the equivalent SetCoutFileName, but in this case we do not
|
||||
// remove or silence what is already exisiting
|
||||
HandleFileCout(fileN,ifAppend,false);
|
||||
HandleFileCout(fileN, ifAppend, false);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void G4MTcoutDestination::SetCerrFileName(const G4String& fileN,
|
||||
G4bool ifAppend)
|
||||
G4bool ifAppend)
|
||||
{
|
||||
// See SetCoutFileName for explanation
|
||||
Reset();
|
||||
if ( fileN != "**Screen**")
|
||||
if(fileN != "**Screen**")
|
||||
{
|
||||
HandleFileCerr(fileN,ifAppend,true);
|
||||
HandleFileCerr(fileN, ifAppend, true);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void G4MTcoutDestination::AddCerrFileName(const G4String& fileN,
|
||||
G4bool ifAppend)
|
||||
G4bool ifAppend)
|
||||
{
|
||||
HandleFileCerr(fileN,ifAppend,false);
|
||||
HandleFileCerr(fileN, ifAppend, false);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void G4MTcoutDestination::SetIgnoreCout(G4int tid)
|
||||
{
|
||||
if (tid<0) { ignoreCout = false; }
|
||||
else { ignoreCout = (tid!=id); }
|
||||
if(tid < 0)
|
||||
{
|
||||
ignoreCout = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
ignoreCout = (tid != id);
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
@@ -250,6 +275,7 @@ namespace
|
||||
G4Mutex coutm = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
void G4MTcoutDestination::DumpBuffer()
|
||||
{
|
||||
G4AutoLock l(&coutm);
|
||||
@@ -258,30 +284,42 @@ void G4MTcoutDestination::DumpBuffer()
|
||||
msg << "cout buffer(s) for worker with ID:" << id << std::endl;
|
||||
G4coutDestination::ReceiveG4cout(msg.str());
|
||||
G4bool sep = false;
|
||||
std::for_each( begin() , end(),
|
||||
[this,&sep](G4coutDestinationUPtr& el) {
|
||||
auto cout = dynamic_cast<G4BuffercoutDestination*>(el.get());
|
||||
if ( cout != nullptr ) {
|
||||
cout->FlushG4cout();
|
||||
if ( sep ) { G4coutDestination::ReceiveG4cout("==========\n"); }
|
||||
else { sep = true; }
|
||||
}
|
||||
} );
|
||||
std::for_each(begin(), end(), [this, &sep](G4coutDestinationUPtr& el) {
|
||||
auto cout = dynamic_cast<G4BuffercoutDestination*>(el.get());
|
||||
if(cout != nullptr)
|
||||
{
|
||||
cout->FlushG4cout();
|
||||
if(sep)
|
||||
{
|
||||
G4coutDestination::ReceiveG4cout("==========\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
sep = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
sep = false;
|
||||
msg.str("");
|
||||
msg.clear();
|
||||
msg << "=======================\n";
|
||||
msg << "cerr buffer(s) for worker with ID:" << id
|
||||
<< " (goes to std error)" << std::endl;
|
||||
msg << "cerr buffer(s) for worker with ID:" << id << " (goes to std error)"
|
||||
<< std::endl;
|
||||
G4coutDestination::ReceiveG4cout(msg.str());
|
||||
std::for_each( begin() , end(),
|
||||
[this,&sep](G4coutDestinationUPtr& el) {
|
||||
auto cout = dynamic_cast<G4BuffercoutDestination*>(el.get());
|
||||
if ( cout != nullptr ) {
|
||||
cout->FlushG4cerr();
|
||||
if (sep ) { G4coutDestination::ReceiveG4cout("==========\n"); }
|
||||
else { sep = true; }
|
||||
}
|
||||
} );
|
||||
std::for_each(begin(), end(), [this, &sep](G4coutDestinationUPtr& el) {
|
||||
auto cout = dynamic_cast<G4BuffercoutDestination*>(el.get());
|
||||
if(cout != nullptr)
|
||||
{
|
||||
cout->FlushG4cerr();
|
||||
if(sep)
|
||||
{
|
||||
G4coutDestination::ReceiveG4cout("==========\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
sep = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
G4coutDestination::ReceiveG4cout("=======================\n");
|
||||
}
|
||||
|
||||
@@ -23,10 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
//
|
||||
// G4MasterForwardcoutDestination.cc
|
||||
// G4MasterForwardcoutDestination class implementation
|
||||
//
|
||||
// Author: A.Dotti (SLAC), April 2017
|
||||
// --------------------------------------------------------------------
|
||||
@@ -39,30 +36,31 @@ namespace
|
||||
G4Mutex out_mutex = G4MUTEX_INITIALIZER;
|
||||
}
|
||||
|
||||
G4MasterForwardcoutDestination::~G4MasterForwardcoutDestination()
|
||||
{
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
G4MasterForwardcoutDestination::~G4MasterForwardcoutDestination() {}
|
||||
|
||||
G4int G4MasterForwardcoutDestination::ReceiveG4cout(const G4String& msg )
|
||||
// --------------------------------------------------------------------
|
||||
G4int G4MasterForwardcoutDestination::ReceiveG4cout(const G4String& msg)
|
||||
{
|
||||
// If a master destination is set check that we are not in a recursive
|
||||
// situation, send the message to the master, using a lock to serialize calls
|
||||
// Master is probably a (G)UI that is not thread-safe
|
||||
|
||||
if ( masterG4coutDestination && this!=masterG4coutDestination)
|
||||
if(masterG4coutDestination && this != masterG4coutDestination)
|
||||
{
|
||||
G4AutoLock l(&out_mutex);
|
||||
return masterG4coutDestination->ReceiveG4cout_(msg);
|
||||
G4AutoLock l(&out_mutex);
|
||||
return masterG4coutDestination->ReceiveG4cout_(msg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
G4int G4MasterForwardcoutDestination::ReceiveG4cerr(const G4String& msg )
|
||||
// --------------------------------------------------------------------
|
||||
G4int G4MasterForwardcoutDestination::ReceiveG4cerr(const G4String& msg)
|
||||
{
|
||||
if ( masterG4coutDestination && this!=masterG4coutDestination)
|
||||
if(masterG4coutDestination && this != masterG4coutDestination)
|
||||
{
|
||||
G4AutoLock l(&out_mutex);
|
||||
return masterG4coutDestination->ReceiveG4cerr_(msg);
|
||||
G4AutoLock l(&out_mutex);
|
||||
return masterG4coutDestination->ReceiveG4cerr_(msg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -23,51 +23,74 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4OrderedTable class implementation
|
||||
//
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// GEANT 4 class implementation
|
||||
//
|
||||
// G4OrderedTable
|
||||
//
|
||||
// ------------------------------------------------------------
|
||||
// Author: M.Maire (LAPP), September 1996
|
||||
// Revisions: H.Kurashige (Kobe Univ.), January-September 2001
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#include "G4DataVector.hh"
|
||||
#include "G4OrderedTable.hh"
|
||||
#include <iostream>
|
||||
#include "G4DataVector.hh"
|
||||
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4OrderedTable::G4OrderedTable()
|
||||
: std::vector<G4DataVector*>()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
G4OrderedTable::G4OrderedTable(size_t cap)
|
||||
: std::vector<G4DataVector*>(cap, (G4DataVector*)(0) )
|
||||
{
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
G4OrderedTable::G4OrderedTable(std::size_t cap)
|
||||
: std::vector<G4DataVector*>(cap, (G4DataVector*) (0))
|
||||
{}
|
||||
|
||||
G4OrderedTable::~G4OrderedTable()
|
||||
{
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
G4OrderedTable::~G4OrderedTable() {}
|
||||
|
||||
G4bool G4OrderedTable::Store(const G4String& fileName,
|
||||
G4bool ascii)
|
||||
// --------------------------------------------------------------------
|
||||
void G4OrderedTable::clearAndDestroy()
|
||||
{
|
||||
std::ofstream fOut;
|
||||
|
||||
// open output file //
|
||||
if (!ascii)
|
||||
{ fOut.open(fileName, std::ios::out|std::ios::binary); }
|
||||
else
|
||||
{ fOut.open(fileName, std::ios::out); }
|
||||
|
||||
// check if the file has been opened successfully
|
||||
if (!fOut)
|
||||
G4DataVector* a = nullptr;
|
||||
while(size() > 0)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
a = back();
|
||||
pop_back();
|
||||
for(auto i = cbegin(); i != cend(); ++i)
|
||||
{
|
||||
if(*i == a)
|
||||
{
|
||||
erase(i);
|
||||
--i;
|
||||
}
|
||||
}
|
||||
if(a != nullptr)
|
||||
{
|
||||
delete a;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
G4bool G4OrderedTable::Store(const G4String& fileName, G4bool ascii)
|
||||
{
|
||||
std::ofstream fOut;
|
||||
|
||||
// open output file //
|
||||
if(!ascii)
|
||||
{
|
||||
fOut.open(fileName, std::ios::out | std::ios::binary);
|
||||
}
|
||||
else
|
||||
{
|
||||
fOut.open(fileName, std::ios::out);
|
||||
}
|
||||
|
||||
// check if the file has been opened successfully
|
||||
if(!fOut)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
G4cerr << "G4OrderedTable::::Store():";
|
||||
G4cerr << " Cannot open file: " << fileName << G4endl;
|
||||
#endif
|
||||
@@ -75,51 +98,51 @@ G4bool G4OrderedTable::Store(const G4String& fileName,
|
||||
return false;
|
||||
}
|
||||
|
||||
// Number of elements
|
||||
G4int tableSize = G4int(size());
|
||||
if (!ascii)
|
||||
G4int tableSize = G4int(size()); // Number of elements
|
||||
if(!ascii)
|
||||
{
|
||||
fOut.write( (char*)(&tableSize), sizeof tableSize);
|
||||
fOut.write((char*) (&tableSize), sizeof tableSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
fOut << tableSize << G4endl;
|
||||
}
|
||||
|
||||
// Data Vector
|
||||
G4int vType = G4DataVector::T_G4DataVector;
|
||||
for (G4OrderedTableIterator itr=begin(); itr!=end(); ++itr)
|
||||
G4int vType = G4DataVector::T_G4DataVector; // Data Vector
|
||||
for(auto itr = cbegin(); itr != cend(); ++itr)
|
||||
{
|
||||
if (!ascii)
|
||||
if(!ascii)
|
||||
{
|
||||
fOut.write( (char*)(&vType), sizeof vType);
|
||||
fOut.write((char*) (&vType), sizeof vType);
|
||||
}
|
||||
else
|
||||
{
|
||||
fOut << vType << G4endl;
|
||||
}
|
||||
(*itr)->Store(fOut,ascii);
|
||||
(*itr)->Store(fOut, ascii);
|
||||
}
|
||||
fOut.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
G4bool G4OrderedTable::Retrieve(const G4String& fileName,
|
||||
G4bool ascii)
|
||||
// --------------------------------------------------------------------
|
||||
G4bool G4OrderedTable::Retrieve(const G4String& fileName, G4bool ascii)
|
||||
{
|
||||
std::ifstream fIn;
|
||||
std::ifstream fIn;
|
||||
// open input file //
|
||||
if (!ascii)
|
||||
{ fIn.open(fileName,std::ios::in|std::ios::binary); }
|
||||
else
|
||||
{ fIn.open(fileName,std::ios::in); }
|
||||
|
||||
// check if the file has been opened successfully
|
||||
if (!fIn)
|
||||
if(!ascii)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
fIn.open(fileName, std::ios::in | std::ios::binary);
|
||||
}
|
||||
else
|
||||
{
|
||||
fIn.open(fileName, std::ios::in);
|
||||
}
|
||||
|
||||
// check if the file has been opened successfully
|
||||
if(!fIn)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
G4cerr << "G4OrderedTable::Retrieve():";
|
||||
G4cerr << " Cannot open file: " << fileName << G4endl;
|
||||
#endif
|
||||
@@ -127,62 +150,62 @@ G4bool G4OrderedTable::Retrieve(const G4String& fileName,
|
||||
return false;
|
||||
}
|
||||
|
||||
// clear
|
||||
// clear
|
||||
clearAndDestroy();
|
||||
|
||||
|
||||
// Number of elements
|
||||
G4int tableSize=0;
|
||||
if (!ascii)
|
||||
G4int tableSize = 0;
|
||||
if(!ascii)
|
||||
{
|
||||
fIn.read((char*)(&tableSize), sizeof tableSize);
|
||||
fIn.read((char*) (&tableSize), sizeof tableSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
fIn >> tableSize;
|
||||
}
|
||||
if (tableSize<=0)
|
||||
if(tableSize <= 0)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
#ifdef G4VERBOSE
|
||||
G4cerr << "G4OrderedTable::Retrieve():";
|
||||
G4cerr << " Invalid table size: " << tableSize << G4endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
reserve(tableSize);
|
||||
reserve(tableSize);
|
||||
|
||||
// Physics Vector
|
||||
for (G4int idx=0; idx<tableSize; ++idx)
|
||||
for(G4int idx = 0; idx < tableSize; ++idx)
|
||||
{
|
||||
G4int vType=0;
|
||||
if (!ascii)
|
||||
G4int vType = 0;
|
||||
if(!ascii)
|
||||
{
|
||||
fIn.read( (char*)(&vType), sizeof vType);
|
||||
fIn.read((char*) (&vType), sizeof vType);
|
||||
}
|
||||
else
|
||||
{
|
||||
fIn >> vType;
|
||||
fIn >> vType;
|
||||
}
|
||||
if (vType != G4DataVector::T_G4DataVector)
|
||||
if(vType != G4DataVector::T_G4DataVector)
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
#ifdef G4VERBOSE
|
||||
G4cerr << "G4OrderedTable::Retrieve():";
|
||||
G4cerr << " Illegal Data Vector type: " << vType << " in ";
|
||||
G4cerr << fileName << G4endl;
|
||||
#endif
|
||||
#endif
|
||||
fIn.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
G4DataVector* pVec = new G4DataVector;
|
||||
|
||||
if (! (pVec->Retrieve(fIn,ascii)) )
|
||||
if(!(pVec->Retrieve(fIn, ascii)))
|
||||
{
|
||||
#ifdef G4VERBOSE
|
||||
#ifdef G4VERBOSE
|
||||
G4cerr << "G4OrderedTable::Retrieve(): ";
|
||||
G4cerr << " Error in retreiving " << idx
|
||||
<< "-th Physics Vector from file: ";
|
||||
G4cerr << fileName << G4endl;
|
||||
#endif
|
||||
#endif
|
||||
fIn.close();
|
||||
delete pVec;
|
||||
return false;
|
||||
@@ -190,23 +213,23 @@ G4bool G4OrderedTable::Retrieve(const G4String& fileName,
|
||||
|
||||
// add a PhysicsVector to this OrderedTable
|
||||
push_back(pVec);
|
||||
}
|
||||
}
|
||||
fIn.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out,
|
||||
G4OrderedTable& right)
|
||||
// --------------------------------------------------------------------
|
||||
std::ostream& operator<<(std::ostream& out, G4OrderedTable& right)
|
||||
{
|
||||
// Printout Data Vector
|
||||
size_t i=0;
|
||||
for (G4OrderedTableIterator itr=right.begin(); itr!=right.end(); ++itr)
|
||||
std::size_t i = 0;
|
||||
for(auto itr = right.cbegin(); itr != right.cend(); ++itr)
|
||||
{
|
||||
out << std::setw(8) << i << "-th Vector ";
|
||||
out << ": Type " << G4DataVector::T_G4DataVector << G4endl;
|
||||
out << *(*itr);
|
||||
i +=1;
|
||||
i += 1;
|
||||
}
|
||||
out << G4endl;
|
||||
return out;
|
||||
return out;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user