Import Geant4 11.3.0 source tree

This commit is contained in:
Gabriele Cosmo
2024-12-06 11:11:40 +01:00
parent e58e650b32
commit 32390e802b
1984 changed files with 98713 additions and 83996 deletions
@@ -23,9 +23,21 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4HCofThisEvent
//
// Class description:
//
// This is a class which stores hits collections generated at one event.
// This class is exclusively constructed by G4SDManager when the first
// hits collection of an event is passed to the manager, and this class
// object is deleted by G4RunManager when a G4Event class object is deleted.
// Almost all public methods must be used by Geant4 kernel classes and
// the user should not invoke them. The user can use two const methods,
// GetHC() and GetNumberOfCollections() for accessing to the stored hits
// collection(s).
//
// Author: Makoto Asai
// --------------------------------------------------------------------
#ifndef G4HCofThisEvent_h
#define G4HCofThisEvent_h 1
@@ -35,53 +47,44 @@
#include <vector>
// class description:
//
// This is a class which stores hits collections generated at one event.
// This class is exclusively constructed by G4SDManager when the first
// hits collection of an event is passed to the manager, and this class
// object is deleted by G4RunManager when a G4Event class object is deleted.
// Almost all public methods must be used by Geant4 kernel classes and
// the user should not invoke them. The user can use two const methods,
// GetHC() and GetNumberOfCollections() for accessing to the stored hits
// collection(s).
class G4HCofThisEvent
{
public:
G4HCofThisEvent();
explicit G4HCofThisEvent(G4int cap);
~G4HCofThisEvent();
G4HCofThisEvent(const G4HCofThisEvent&);
G4HCofThisEvent& operator=(const G4HCofThisEvent&);
public:
inline void* operator new(size_t);
inline void operator delete(void* anHCoTE);
G4HCofThisEvent();
explicit G4HCofThisEvent(G4int cap);
~G4HCofThisEvent();
G4HCofThisEvent(const G4HCofThisEvent&);
G4HCofThisEvent& operator=(const G4HCofThisEvent&);
void AddHitsCollection(G4int HCID, G4VHitsCollection* aHC);
inline void* operator new(std::size_t);
inline void operator delete(void* anHCoTE);
// Returns a pointer to a hits collection. Null will be returned
// if the particular collection is not stored at the current event.
// The integer argument is ID number which is assigned by G4SDManager
// and the number can be obtained by G4SDManager::GetHitsCollectionID()
// method.
inline G4VHitsCollection* GetHC(G4int i) { return (*HC)[i]; }
void AddHitsCollection(G4int HCID, G4VHitsCollection* aHC);
// Return number of hits collections which are stored in this class
// object.
inline G4int GetNumberOfCollections()
{
G4int n = 0;
for (const G4VHitsCollection* h : *HC) {
if (h != nullptr) n++;
// Returns a pointer to a hits collection. Null will be returned
// if the particular collection is not stored at the current event.
// The integer argument is ID number which is assigned by G4SDManager
// and the number can be obtained by G4SDManager::GetHitsCollectionID()
// method.
inline G4VHitsCollection* GetHC(G4int i) { return (*HC)[i]; }
// Return number of hits collections which are stored in this class
// object.
inline G4int GetNumberOfCollections()
{
G4int n = 0;
for (const G4VHitsCollection* h : *HC) {
if (h != nullptr) ++n;
}
return n;
}
return n;
}
inline size_t GetCapacity() { return HC->size(); }
inline std::size_t GetCapacity() { return HC->size(); }
private:
std::vector<G4VHitsCollection*>* HC;
private:
std::vector<G4VHitsCollection*>* HC;
};
#if defined G4DIGI_ALLOC_EXPORT
@@ -90,7 +93,7 @@ extern G4DLLEXPORT G4Allocator<G4HCofThisEvent>*& anHCoTHAllocator_G4MT_TLS_();
extern G4DLLIMPORT G4Allocator<G4HCofThisEvent>*& anHCoTHAllocator_G4MT_TLS_();
#endif
inline void* G4HCofThisEvent::operator new(size_t)
inline void* G4HCofThisEvent::operator new(std::size_t)
{
if (anHCoTHAllocator_G4MT_TLS_() == nullptr) {
anHCoTHAllocator_G4MT_TLS_() = new G4Allocator<G4HCofThisEvent>;
@@ -23,9 +23,20 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4THitsCollection & G4HitsCollection
//
// Class description:
//
// This is a template class of hits collection and parametrised by
// The concrete class of G4VHit. This is a uniform collection for
// a particular concrete hit class objects.
// An intermediate layer class G4HitsCollection appeared in this
// header file is used just for G4Allocator, because G4Allocator
// cannot be instantiated with a template class. Thus G4HitsCollection
// class MUST NOT be directly used by the user.
//
// Author: Makoto Asai
// --------------------------------------------------------------------
#ifndef G4THitsCollection_h
#define G4THitsCollection_h 1
@@ -35,25 +46,17 @@
#include <vector>
// class description:
//
// This is a template class of hits collection and parametrized by
// The concrete class of G4VHit. This is a uniform collection for
// a particular concrete hit class objects.
// An intermediate layer class G4HitsCollection appeared in this
// header file is used just for G4Allocator, because G4Allocator
// cannot be instansiated with a template class. Thus G4HitsCollection
// class MUST NOT be directly used by the user.
class G4HitsCollection : public G4VHitsCollection
{
public:
using G4VHitsCollection::G4VHitsCollection;
~G4HitsCollection() override = default;
G4bool operator==(const G4HitsCollection& right) const;
public:
protected:
void* theCollection = nullptr;
using G4VHitsCollection::G4VHitsCollection;
~G4HitsCollection() override = default;
G4bool operator==(const G4HitsCollection& right) const;
protected:
void* theCollection = nullptr;
};
#if defined G4DIGI_ALLOC_EXPORT
@@ -65,53 +68,54 @@ extern G4DLLIMPORT G4Allocator<G4HitsCollection>*& anHCAllocator_G4MT_TLS_();
template <class T>
class G4THitsCollection : public G4HitsCollection
{
public:
G4THitsCollection();
G4THitsCollection(G4String detName, G4String colNam);
~G4THitsCollection() override;
public:
G4bool operator==(const G4THitsCollection<T>& right) const;
G4THitsCollection();
G4THitsCollection(const G4String& detName, const G4String& colNam);
~G4THitsCollection() override;
inline void* operator new(size_t);
inline void operator delete(void* anHC);
G4bool operator==(const G4THitsCollection<T>& right) const;
// Invoke Draw() method on all hit objects in collection
void DrawAllHits() override;
inline void* operator new(std::size_t);
inline void operator delete(void* anHC);
// Invoke Print() method on all hit objects in collection
void PrintAllHits() override;
// Invoke Draw() method on all hit objects in collection
void DrawAllHits() override;
// Returns a pointer to the concrete hit object
// Returns pointer to the concrete hit object at given index
// Not bounds checked
inline T* operator[](size_t i) const { return (*((std::vector<T*>*)theCollection))[i]; }
// Invoke Print() method on all hit objects in collection
void PrintAllHits() override;
// Return pointer to hit collection
inline std::vector<T*>* GetVector() const { return (std::vector<T*>*)theCollection; }
// Returns a pointer to the concrete hit object
// Returns pointer to the concrete hit object at given index
// Not bounds checked
inline T* operator[](std::size_t i) const { return (*((std::vector<T*>*)theCollection))[i]; }
// Insert a hit object in the collection, taking onwenership
// Returns the total number of hit objects stored after insertion
inline size_t insert(T* aHit)
{
auto theHitsCollection = (std::vector<T*>*)theCollection;
theHitsCollection->push_back(aHit);
return theHitsCollection->size();
}
// Return pointer to hit collection
inline std::vector<T*>* GetVector() const { return (std::vector<T*>*)theCollection; }
// Returns the number of hit objects stored in this collection.
inline size_t entries() const
{
auto theHitsCollection = (std::vector<T*>*)theCollection;
return theHitsCollection->size();
}
// Insert a hit object in the collection, taking onwenership
// Returns the total number of hit objects stored after insertion
inline std::size_t insert(T* aHit)
{
auto theHitsCollection = (std::vector<T*>*)theCollection;
theHitsCollection->push_back(aHit);
return theHitsCollection->size();
}
G4VHit* GetHit(size_t i) const override { return (*((std::vector<T*>*)theCollection))[i]; }
// Returns the number of hit objects stored in this collection.
inline std::size_t entries() const
{
auto theHitsCollection = (std::vector<T*>*)theCollection;
return theHitsCollection->size();
}
size_t GetSize() const override { return ((std::vector<T*>*)theCollection)->size(); }
G4VHit* GetHit(std::size_t i) const override { return (*((std::vector<T*>*)theCollection))[i]; }
std::size_t GetSize() const override { return ((std::vector<T*>*)theCollection)->size(); }
};
template <class T>
inline void* G4THitsCollection<T>::operator new(size_t)
inline void* G4THitsCollection<T>::operator new(std::size_t)
{
if (anHCAllocator_G4MT_TLS_() == nullptr) {
anHCAllocator_G4MT_TLS_() = new G4Allocator<G4HitsCollection>;
@@ -133,7 +137,7 @@ G4THitsCollection<T>::G4THitsCollection()
}
template <class T>
G4THitsCollection<T>::G4THitsCollection(G4String detName, G4String colNam)
G4THitsCollection<T>::G4THitsCollection(const G4String& detName, const G4String& colNam)
: G4HitsCollection(detName, colNam)
{
auto theHitsCollection = new std::vector<T*>;
+40 -47
View File
@@ -23,8 +23,20 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4VTHitsMap, G4THitsMultiMap, G4THitsUnorderedMap & G4THitsUnorderedMultiMap
//
// Class description:
//
// This is a template class of hits map and parametrised by
// The concrete class of G4VHit. This is a uniform collection for
// a particular concrete hit class objects.
// An intermediate layer class G4HitsMap appeared in this
// header file is used just for G4Allocator, because G4Allocator
// cannot be instantiated with a template class. Thus G4HitsMap
// class MUST NOT be directly used by the user.
//
// Authors: Makoto Asai, Jonathan Madsen
// --------------------------------------------------------------------
#ifndef G4THitsMap_h
#define G4THitsMap_h 1
@@ -35,20 +47,11 @@
#include <unordered_map>
#include <type_traits>
// class description:
//
// This is a template class of hits map and parametrized by
// The concrete class of G4VHit. This is a uniform collection for
// a particular concrete hit class objects.
// An intermediate layer class G4HitsMap appeared in this
// header file is used just for G4Allocator, because G4Allocator
// cannot be instansiated with a template class. Thus G4HitsMap
// class MUST NOT be directly used by the user.
template <typename T, typename Map_t = std::map<G4int, T*>>
class G4VTHitsMap : public G4HitsCollection
{
private:
using mmap_t = std::multimap<G4int, T *>;
using pair_t = std::pair<G4int, T *>;
using uommap_t = std::unordered_multimap<G4int, T *>;
@@ -84,11 +87,10 @@ class G4VTHitsMap : public G4HitsCollection
using iterator = typename map_type::iterator;
using const_iterator = typename map_type::const_iterator;
public: // with description
// generic constructor
G4VTHitsMap();
// det + collection description constructor
G4VTHitsMap(G4String detName, G4String colNam);
G4VTHitsMap(const G4String& detName, const G4String& colNam);
// destructor
~G4VTHitsMap() override;
// equivalence operator
@@ -108,13 +110,11 @@ class G4VTHitsMap : public G4HitsCollection
}
//------------------------------------------------------------------------//
public: // with description
void DrawAllHits() override;
void PrintAllHits() override;
// These two methods invokes Draw() and Print() methods of all of
// hit objects stored in this map, respectively.
public:
// Generic iteration
inline Map_t* GetContainer() const { return (Map_t*)theCollection; }
@@ -147,20 +147,17 @@ class G4VTHitsMap : public G4HitsCollection
const_iterator cbegin() const { return GetContainer()->cbegin(); }
const_iterator cend() const { return GetContainer()->cend(); }
public: // with description
// Returns a pointer to a concrete hit object.
inline Map_t* GetMap() const { return (Map_t*)theCollection; }
// Overwrite a hit object. Total number of hit objects stored in this
// map is returned.
inline size_t entries() const { return ((Map_t*)theCollection)->size(); }
inline std::size_t entries() const { return ((Map_t*)theCollection)->size(); }
// Returns the number of hit objects stored in this map
inline void clear();
public:
G4VHit* GetHit(size_t) const override { return nullptr; }
size_t GetSize() const override { return ((Map_t*)theCollection)->size(); }
G4VHit* GetHit(std::size_t) const override { return nullptr; }
std::size_t GetSize() const override { return ((Map_t*)theCollection)->size(); }
public:
//------------------------------------------------------------------------//
// Add/Insert a hit object. Total number of hit objects stored in this
// map is returned.
@@ -171,7 +168,7 @@ class G4VTHitsMap : public G4HitsCollection
// and += adds to white (not correct)
template <typename U = T, typename MapU_t = Map_t,
enable_if_t<is_same_t(U, T) && ! is_mmap_t(MapU_t), G4int> = 0>
size_t add(const G4int& key, U*& aHit) const
std::size_t add(const G4int& key, U*& aHit) const
{
map_type* theHitsMap = GetMap();
if (theHitsMap->find(key) == theHitsMap->end())
@@ -185,7 +182,7 @@ class G4VTHitsMap : public G4HitsCollection
//------------------------------------------------------------------------//
template <typename U = T, typename MapU_t = Map_t,
enable_if_t<(is_same_t(U, T) && is_mmap_t(MapU_t)), G4int> = 0>
size_t add(const G4int& key, U*& aHit) const
std::size_t add(const G4int& key, U*& aHit) const
{
map_type* theHitsMap = GetMap();
theHitsMap->insert(pair_t(key, aHit));
@@ -197,7 +194,7 @@ class G4VTHitsMap : public G4HitsCollection
//------------------------------------------------------------------------//
template <typename U = T, typename MapU_t = Map_t,
enable_if_t<(! is_same_t(U, T) && is_mmap_t(MapU_t)), G4int> = 0>
size_t add(const G4int& key, U*& aHit) const
std::size_t add(const G4int& key, U*& aHit) const
{
map_type* theHitsMap = GetMap();
T* hit = allocate();
@@ -206,7 +203,6 @@ class G4VTHitsMap : public G4HitsCollection
return theHitsMap->size();
}
public:
//------------------------------------------------------------------------//
// Standard map overload for same type
// assumes type T has overload of += operator for U
@@ -215,7 +211,7 @@ class G4VTHitsMap : public G4HitsCollection
// and += adds to white (not correct)
template <typename U = T, typename MapU_t = Map_t,
enable_if_t<(is_same_t(U, T) && ! is_mmap_t(MapU_t)), G4int> = 0>
size_t add(const G4int& key, U& aHit) const
std::size_t add(const G4int& key, U& aHit) const
{
map_type* theHitsMap = GetMap();
if (theHitsMap->find(key) == theHitsMap->end())
@@ -230,7 +226,7 @@ class G4VTHitsMap : public G4HitsCollection
//------------------------------------------------------------------------//
template <typename U = T, typename MapU_t = Map_t,
enable_if_t<(! is_same_t(U, T) && ! is_mmap_t(MapU_t)), G4int> = 0>
size_t add(const G4int& key, U& aHit) const
std::size_t add(const G4int& key, U& aHit) const
{
map_type* theHitsMap = GetMap();
if (theHitsMap->find(key) == theHitsMap->end()) theHitsMap->insert(pair_t(key, allocate()));
@@ -242,7 +238,7 @@ class G4VTHitsMap : public G4HitsCollection
//------------------------------------------------------------------------//
template <typename U = T, typename MapU_t = Map_t,
enable_if_t<(is_same_t(U, T) && is_mmap_t(MapU_t)), G4int> = 0>
size_t add(const G4int& key, U& aHit) const
std::size_t add(const G4int& key, U& aHit) const
{
map_type* theHitsMap = GetMap();
theHitsMap->insert(pair_t(key, new T(aHit)));
@@ -254,7 +250,7 @@ class G4VTHitsMap : public G4HitsCollection
//------------------------------------------------------------------------//
template <typename U = T, typename MapU_t = Map_t,
enable_if_t<(! is_same_t(U, T) && is_mmap_t(MapU_t)), G4int> = 0>
size_t add(const G4int& key, U& aHit) const
std::size_t add(const G4int& key, U& aHit) const
{
map_type* theHitsMap = GetMap();
T* hit = allocate();
@@ -262,9 +258,7 @@ class G4VTHitsMap : public G4HitsCollection
theHitsMap->insert(pair_t(key, hit));
return theHitsMap->size();
}
//------------------------------------------------------------------------//
public:
//------------------------------------------------------------------------//
// Set a hit object. Total number of hit objects stored in this
// map is returned.
@@ -273,7 +267,7 @@ class G4VTHitsMap : public G4HitsCollection
//------------------------------------------------------------------------//
template <typename U = T, typename MapU_t = Map_t,
enable_if_t<(is_same_t(U, T) && ! is_mmap_t(MapU_t)), G4int> = 0>
inline size_t set(const G4int& key, U*& aHit) const
inline std::size_t set(const G4int& key, U*& aHit) const
{
map_type* theHitsMap = GetMap();
if (theHitsMap->find(key) != theHitsMap->end()) delete theHitsMap->find(key)->second;
@@ -285,7 +279,7 @@ class G4VTHitsMap : public G4HitsCollection
//------------------------------------------------------------------------//
template <typename U = T, typename MapU_t = Map_t,
enable_if_t<(is_same_t(U, T) && is_mmap_t(MapU_t)), G4int> = 0>
inline size_t set(const G4int& key, U*& aHit) const
inline std::size_t set(const G4int& key, U*& aHit) const
{
map_type* theHitsMap = GetMap();
if (theHitsMap->find(key) != theHitsMap->end())
@@ -301,7 +295,7 @@ class G4VTHitsMap : public G4HitsCollection
//------------------------------------------------------------------------//
template <typename U = T, typename MapU_t = Map_t,
enable_if_t<(! is_same_t(U, T) && ! is_mmap_t(MapU_t)), G4int> = 0>
inline size_t set(const G4int& key, U*& aHit) const
inline std::size_t set(const G4int& key, U*& aHit) const
{
map_type* theHitsMap = GetMap();
T* hit = nullptr;
@@ -317,7 +311,7 @@ class G4VTHitsMap : public G4HitsCollection
//------------------------------------------------------------------------//
template <typename U = T, typename MapU_t = Map_t,
enable_if_t<(! is_same_t(U, T) && is_mmap_t(MapU_t)), G4int> = 0>
inline size_t set(const G4int& key, U*& aHit) const
inline std::size_t set(const G4int& key, U*& aHit) const
{
map_type* theHitsMap = GetMap();
T* hit = allocate();
@@ -330,9 +324,7 @@ class G4VTHitsMap : public G4HitsCollection
}
return theHitsMap->size();
}
//------------------------------------------------------------------------//
public:
//------------------------------------------------------------------------//
// Set a hit object. Total number of hit objects stored in this
// map is returned.
@@ -341,7 +333,7 @@ class G4VTHitsMap : public G4HitsCollection
//------------------------------------------------------------------------//
template <typename U = T, typename MapU_t = Map_t,
enable_if_t<(is_same_t(U, T) && ! is_mmap_t(MapU_t)), G4int> = 0>
inline size_t set(const G4int& key, U& aHit) const
inline std::size_t set(const G4int& key, U& aHit) const
{
map_type* theHitsMap = GetMap();
T* hit = nullptr;
@@ -357,7 +349,7 @@ class G4VTHitsMap : public G4HitsCollection
//------------------------------------------------------------------------//
template <typename U = T, typename MapU_t = Map_t,
enable_if_t<(is_same_t(U, T) && is_mmap_t(MapU_t)), G4int> = 0>
inline size_t set(const G4int& key, U& aHit) const
inline std::size_t set(const G4int& key, U& aHit) const
{
map_type* theHitsMap = GetMap();
if (theHitsMap->find(key) != theHitsMap->end())
@@ -371,7 +363,7 @@ class G4VTHitsMap : public G4HitsCollection
//------------------------------------------------------------------------//
template <typename U = T, typename MapU_t = Map_t,
enable_if_t<(! is_same_t(U, T) && ! is_mmap_t(MapU_t)), G4int> = 0>
inline size_t set(const G4int& key, U& aHit) const
inline std::size_t set(const G4int& key, U& aHit) const
{
map_type* theHitsMap = GetMap();
T* hit = nullptr;
@@ -387,7 +379,7 @@ class G4VTHitsMap : public G4HitsCollection
//------------------------------------------------------------------------//
template <typename U = T, typename MapU_t = Map_t,
enable_if_t<(! is_same_t(U, T) && is_mmap_t(MapU_t)), G4int> = 0>
inline size_t set(const G4int& key, U& aHit) const
inline std::size_t set(const G4int& key, U& aHit) const
{
map_type* theHitsMap = GetMap();
T* hit = allocate();
@@ -398,9 +390,7 @@ class G4VTHitsMap : public G4HitsCollection
theHitsMap->insert(pair_t(key, hit));
return theHitsMap->size();
}
//------------------------------------------------------------------------//
public:
//------------------------------------------------------------------------//
// Enable bracket operator. Return pointer to data indexed by key or
// last occurring instance of pointer to data index by key in the
@@ -418,7 +408,7 @@ class G4VTHitsMap : public G4HitsCollection
T* operator[](G4int key) const
{
#ifdef G4VERBOSE
static bool _first = true;
static G4bool _first = true;
if (_first) {
_first = false;
G4Exception("G4THitsMap operator[]", "calling [] on multimap", JustWarning,
@@ -453,7 +443,7 @@ G4VTHitsMap<T, Map_t>::G4VTHitsMap()
//============================================================================//
template <typename T, typename Map_t>
G4VTHitsMap<T, Map_t>::G4VTHitsMap(G4String detName, G4String colNam)
G4VTHitsMap<T, Map_t>::G4VTHitsMap(const G4String& detName, const G4String& colNam)
: G4HitsCollection(detName, colNam)
{
theCollection = (void*)new Map_t;
@@ -564,7 +554,8 @@ class G4THitsMultiMap : public G4VTHitsMap<_Tp, std::multimap<G4int, _Tp*>>
public:
G4THitsMultiMap() : parent_type() {}
G4THitsMultiMap(G4String detName, G4String colName) : parent_type(detName, colName) {}
G4THitsMultiMap(const G4String& detName, const G4String& colName)
: parent_type(detName, colName) {}
using parent_type::operator+=;
using parent_type::operator==;
@@ -594,7 +585,8 @@ class G4THitsUnorderedMap : public G4VTHitsMap<_Tp, std::unordered_map<G4int, _T
public:
G4THitsUnorderedMap() : parent_type() {}
G4THitsUnorderedMap(G4String detName, G4String colName) : parent_type(detName, colName) {}
G4THitsUnorderedMap(const G4String& detName, const G4String& colName)
: parent_type(detName, colName) {}
using parent_type::operator+=;
using parent_type::operator==;
@@ -624,7 +616,8 @@ class G4THitsUnorderedMultiMap : public G4VTHitsMap<_Tp, std::unordered_multimap
public:
G4THitsUnorderedMultiMap() : parent_type() {}
G4THitsUnorderedMultiMap(G4String detName, G4String colName) : parent_type(detName, colName) {}
G4THitsUnorderedMultiMap(const G4String& detName, const G4String& colName)
: parent_type(detName, colName) {}
using parent_type::operator+=;
using parent_type::operator==;
@@ -23,8 +23,20 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4VTHitsVector, G4THitsVector & G4THitsDeque
//
// Class description:
//
// This is a template class of hits Vector and parametrised by
// The concrete class of G4VHit. This is a uniform collection for
// a particular concrete hit class objects.
// An intermediate layer class G4HitsVector appeared in this
// header file is used just for G4Allocator, because G4Allocator
// cannot be instantiated with a template class. Thus G4HitsVector
// class MUST NOT be directly used by the user.
//
// Author: Makoto Asai, Jonathan Madsen
// --------------------------------------------------------------------
#ifndef G4THitsVector_h
#define G4THitsVector_h 1
@@ -37,20 +49,11 @@
#include <unordered_map>
#include <vector>
// class description:
//
// This is a template class of hits Vector and parametrized by
// The concrete class of G4VHit. This is a uniform collection for
// a particular concrete hit class objects.
// An intermediate layer class G4HitsVector appeared in this
// header file is used just for G4Allocator, because G4Allocator
// cannot be instansiated with a template class. Thus G4HitsVector
// class MUST NOT be directly used by the user.
template <typename T, typename Vector_t = std::deque<T*>>
class G4VTHitsVector : public G4HitsCollection
{
public:
using this_type = G4VTHitsVector<T, Vector_t>;
using value_type = T;
using vector_type = Vector_t;
@@ -77,14 +80,15 @@ class G4VTHitsVector : public G4HitsCollection
#define is_pointer_t(_Tp) std::is_pointer<_Tp>::value
#define scast(_Tp) static_cast<_Tp>
template <bool _Bp, typename _Tp = void>
template <G4bool _Bp, typename _Tp = void>
using enable_if_t = typename std::enable_if<_Bp, _Tp>::type;
public:
// generic constructor
G4VTHitsVector(G4int init_size = 0);
// det + collection description constructor
G4VTHitsVector(G4String detName, G4String colNam, G4int init_size = 0);
G4VTHitsVector(const G4String& detName, const G4String& colNam, G4int init_size = 0);
// destructor
~G4VTHitsVector() override;
// equivalence operator
@@ -165,7 +169,6 @@ class G4VTHitsVector : public G4HitsCollection
inline map_t* GetMap() const;
public:
//------------------------------------------------------------------------//
// POINTER TYPE
//------------------------------------------------------------------------//
@@ -219,7 +222,6 @@ class G4VTHitsVector : public G4HitsCollection
return store_type();
}
public:
//------------------------------------------------------------------------//
// Generic operator += where add(...) overloads handle various
// U and VectorU_t types
@@ -269,7 +271,6 @@ class G4VTHitsVector : public G4HitsCollection
}
//------------------------------------------------------------------------//
public:
//------------------------------------------------------------------------//
// Insert a hit object. Total number of hit objects stored in this
// map is returned.
@@ -318,7 +319,6 @@ class G4VTHitsVector : public G4HitsCollection
}
//------------------------------------------------------------------------//
public:
//------------------------------------------------------------------------//
// Set a hit object. Total number of hit objects stored in this
// map is returned.
@@ -346,7 +346,6 @@ class G4VTHitsVector : public G4HitsCollection
}
//------------------------------------------------------------------------//
public:
//------------------------------------------------------------------------//
// Set a hit object. Total number of hit objects stored in this
// map is returned.
@@ -372,9 +371,7 @@ class G4VTHitsVector : public G4HitsCollection
_assign(theHitsVector, key, &aHit);
return theHitsVector->size();
}
//------------------------------------------------------------------------//
public:
//------------------------------------------------------------------------//
T* at(G4int key) const
{
@@ -392,6 +389,7 @@ class G4VTHitsVector : public G4HitsCollection
//------------------------------------------------------------------------//
protected:
template <typename U = store_type, enable_if_t<(is_pointer_t(U)), G4int> = 0>
void resize(vector_type*& theHitsVector, const G4int& key) const
{
@@ -557,7 +555,7 @@ G4VTHitsVector<T, Vector_t>::G4VTHitsVector(G4int init_size)
//============================================================================//
template <typename T, typename Vector_t>
G4VTHitsVector<T, Vector_t>::G4VTHitsVector(G4String detName, G4String colNam, G4int init_size)
G4VTHitsVector<T, Vector_t>::G4VTHitsVector(const G4String& detName, const G4String& colNam, G4int init_size)
: G4HitsCollection(detName, colNam)
{
theCollection = static_cast<void*>(new Vector_t);
@@ -590,7 +588,7 @@ G4bool G4VTHitsVector<T, Vector_t>::operator==(const G4VTHitsVector<T, Vector_t>
template <typename T, typename Vector_t>
typename G4VTHitsVector<T, Vector_t>::map_t* G4VTHitsVector<T, Vector_t>::GetMap() const
{
G4ThreadLocalStatic auto theHitsMap = new map_t();
G4ThreadLocalStatic auto theHitsMap = new map_t();
theHitsMap->clear();
vector_type* theHitsVector = GetVector();
for (std::size_t i = 0; i < theHitsVector->size(); ++i) {
@@ -654,7 +652,7 @@ class G4THitsVector : public G4VTHitsVector<_Tp, std::vector<_Tp*>>
public:
G4THitsVector(G4int init_size = 0) : parent_type(init_size) {}
G4THitsVector(G4String detName, G4String colName, G4int init_size = 0)
G4THitsVector(const G4String& detName, const G4String& colName, G4int init_size = 0)
: parent_type(detName, colName, init_size)
{}
@@ -687,7 +685,7 @@ class G4THitsDeque : public G4VTHitsVector<_Tp, std::deque<_Tp*>>
public:
G4THitsDeque(G4int init_size = 0) : parent_type(init_size) {}
G4THitsDeque(G4String detName, G4String colName, G4int init_size = 0)
G4THitsDeque(const G4String& detName, const G4String& colName, G4int init_size = 0)
: parent_type(detName, colName, init_size)
{}
+13 -11
View File
@@ -23,9 +23,18 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4VHit
//
// Class description:
//
// This is the base class of hit object. The user should derive this
// base class to make his/her own hit class. Two virtual method Draw()
// and Print() can be implemented if the user wants these functionalities.
// If a concrete hit class is used as a transient class, G4Allocator
// must be used.
//
// Author: Makoto Asai
// --------------------------------------------------------------------
#ifndef G4VHit_h
#define G4VHit_h 1
@@ -37,24 +46,17 @@
class G4AttDef;
class G4AttValue;
// class description:
//
// This is the base class of hit object. The user should derive this
// base class to make his/her own hit class. Two virtual method Draw()
// and Print() can be implemented if the user wants these functionarities.
// If a concrete hit class is used as a transient class, G4Allocator
// must be used.
class G4VHit
{
public:
G4VHit() = default;
virtual ~G4VHit() = default;
G4bool operator==(const G4VHit&) const { return false; }
virtual void Draw(){};
virtual void Print(){};
virtual void Draw() {}
virtual void Print() {}
// Returns pointer to map of attribute definitions for this hit
// Caller is responsible for checking validity of returned pointer.
@@ -23,29 +23,31 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4VHitsCollection
//
// Class description:
//
// This is the base class of hits collection. The user is advised to
// use G4THitsCollection template class in case his/her collection is
// transient. While, in case the collection is persistent,
// the concrete collection class can be directly derived from this
// class. Geant4 kernel will use this class methods.
//
// Author: Makoto Asai
// --------------------------------------------------------------------
#ifndef G4VHitsCollection_h
#define G4VHitsCollection_h 1
class G4VHit;
#include "globals.hh"
// class description:
//
// This is the base class of hits collection. The user is advised to
// use G4THitsCollection template class in case his/her collection is
// transient. While, in case the collection is persistent with ODBMS,
// the concrete collection class can be directly derived from this
// class.
// Geant4 kernel will use this class methods.
class G4VHit;
class G4VHitsCollection
{
public:
G4VHitsCollection() = default;
G4VHitsCollection(G4String detName, G4String colNam);
G4VHitsCollection(const G4String& detName, const G4String& colNam);
virtual ~G4VHitsCollection() = default;
G4bool operator==(const G4VHitsCollection& right) const;
@@ -60,10 +62,11 @@ class G4VHitsCollection
// GetHit and GetSize are given a default implementation here so
// that the template G4THitsCollection can be used, but they
// are re-implemented G4THitsCollection.
virtual G4VHit* GetHit(size_t) const { return nullptr; }
virtual size_t GetSize() const { return 0; };
virtual G4VHit* GetHit(std::size_t) const { return nullptr; }
virtual std::size_t GetSize() const { return 0; };
protected:
// Collection name
G4String collectionName = "Unknown";
G4String SDname = "Unknown";