Import Geant4 11.3.0.beta source tree
This commit is contained in:
@@ -45,12 +45,12 @@
|
||||
#ifndef G4TAtomicHitsMap_h
|
||||
#define G4TAtomicHitsMap_h 1
|
||||
|
||||
#include "G4AutoLock.hh"
|
||||
#include "G4THitsCollection.hh"
|
||||
#include "G4THitsMap.hh"
|
||||
#include "globals.hh"
|
||||
#include "G4atomic.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
#include "G4atomic.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <map>
|
||||
#include <type_traits>
|
||||
@@ -65,141 +65,132 @@
|
||||
// cannot be instansiated with a template class. Thus G4HitsMap
|
||||
// class MUST NOT be directly used by the user.
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
class G4TAtomicHitsMap : public G4VHitsCollection
|
||||
{
|
||||
protected:
|
||||
static_assert(std::is_fundamental<T>::value,
|
||||
"G4TAtomicHitsMap must use fundamental type");
|
||||
protected:
|
||||
static_assert(std::is_fundamental<T>::value, "G4TAtomicHitsMap must use fundamental type");
|
||||
|
||||
public:
|
||||
typedef G4atomic<T> value_type;
|
||||
typedef value_type* mapped_type;
|
||||
typedef typename std::map<G4int, mapped_type> container_type;
|
||||
typedef typename container_type::iterator iterator;
|
||||
typedef typename container_type::const_iterator const_iterator;
|
||||
public:
|
||||
typedef G4atomic<T> value_type;
|
||||
typedef value_type* mapped_type;
|
||||
typedef typename std::map<G4int, mapped_type> container_type;
|
||||
typedef typename container_type::iterator iterator;
|
||||
typedef typename container_type::const_iterator const_iterator;
|
||||
|
||||
public:
|
||||
G4TAtomicHitsMap();
|
||||
public:
|
||||
G4TAtomicHitsMap();
|
||||
|
||||
public: // with description
|
||||
G4TAtomicHitsMap(G4String detName, G4String colNam);
|
||||
// constructor.
|
||||
public: // with description
|
||||
G4TAtomicHitsMap(G4String detName, G4String colNam);
|
||||
// constructor.
|
||||
|
||||
public:
|
||||
virtual ~G4TAtomicHitsMap();
|
||||
G4bool operator==(const G4TAtomicHitsMap<T>& right) const;
|
||||
G4TAtomicHitsMap<T>& operator+=(const G4TAtomicHitsMap<T>& right) const;
|
||||
G4TAtomicHitsMap<T>& operator+=(const G4THitsMap<T>& right) const;
|
||||
public:
|
||||
virtual ~G4TAtomicHitsMap();
|
||||
G4bool operator==(const G4TAtomicHitsMap<T>& right) const;
|
||||
G4TAtomicHitsMap<T>& operator+=(const G4TAtomicHitsMap<T>& right) const;
|
||||
G4TAtomicHitsMap<T>& operator+=(const G4THitsMap<T>& right) const;
|
||||
|
||||
public: // with description
|
||||
virtual void DrawAllHits();
|
||||
virtual void PrintAllHits();
|
||||
// These two methods invokes Draw() and Print() methods of all of
|
||||
// hit objects stored in this map, respectively.
|
||||
public: // with description
|
||||
virtual void DrawAllHits();
|
||||
virtual void PrintAllHits();
|
||||
// These two methods invokes Draw() and Print() methods of all of
|
||||
// hit objects stored in this map, respectively.
|
||||
|
||||
public: // with description
|
||||
inline value_type* operator[](G4int key) const;
|
||||
public: // with description
|
||||
inline value_type* operator[](G4int key) const;
|
||||
|
||||
// Returns a pointer to a concrete hit object.
|
||||
inline container_type* GetMap() const { return theCollection; }
|
||||
// Returns a collection map.
|
||||
inline G4int add(const G4int& key, value_type*& aHit) const;
|
||||
inline G4int add(const G4int& key, T& aHit) const;
|
||||
// Insert a hit object. Total number of hit objects stored in this
|
||||
// map is returned.
|
||||
inline G4int set(const G4int& key, value_type*& aHit) const;
|
||||
inline G4int set(const G4int& key, T& aHit) const;
|
||||
// Overwrite a hit object. Total number of hit objects stored in this
|
||||
// map is returned.
|
||||
inline G4int entries() const { return theCollection->size(); }
|
||||
// Returns the number of hit objects stored in this map
|
||||
inline void clear();
|
||||
// Returns a pointer to a concrete hit object.
|
||||
inline container_type* GetMap() const { return theCollection; }
|
||||
// Returns a collection map.
|
||||
inline G4int add(const G4int& key, value_type*& aHit) const;
|
||||
inline G4int add(const G4int& key, T& aHit) const;
|
||||
// Insert a hit object. Total number of hit objects stored in this
|
||||
// map is returned.
|
||||
inline G4int set(const G4int& key, value_type*& aHit) const;
|
||||
inline G4int set(const G4int& key, T& aHit) const;
|
||||
// Overwrite a hit object. Total number of hit objects stored in this
|
||||
// map is returned.
|
||||
inline G4int entries() const { return theCollection->size(); }
|
||||
// Returns the number of hit objects stored in this map
|
||||
inline void clear();
|
||||
|
||||
public:
|
||||
virtual G4VHit* GetHit(size_t) const { return 0; }
|
||||
virtual size_t GetSize() const { return theCollection->size(); }
|
||||
public:
|
||||
virtual G4VHit* GetHit(size_t) const { return 0; }
|
||||
virtual size_t GetSize() const { return theCollection->size(); }
|
||||
|
||||
virtual size_t size() const { return theCollection->size(); }
|
||||
virtual size_t size() const { return theCollection->size(); }
|
||||
|
||||
public:
|
||||
iterator begin() { return theCollection->begin(); }
|
||||
iterator end() { return theCollection->end(); }
|
||||
public:
|
||||
iterator begin() { return theCollection->begin(); }
|
||||
iterator end() { return theCollection->end(); }
|
||||
|
||||
const_iterator begin() const { return theCollection->begin(); }
|
||||
const_iterator end() const { return theCollection->end(); }
|
||||
const_iterator begin() const { return theCollection->begin(); }
|
||||
const_iterator end() const { return theCollection->end(); }
|
||||
|
||||
const_iterator cbegin() const { return theCollection->cbegin(); }
|
||||
const_iterator cend() const { return theCollection->cend(); }
|
||||
const_iterator cbegin() const { return theCollection->cbegin(); }
|
||||
const_iterator cend() const { return theCollection->cend(); }
|
||||
|
||||
iterator find(G4int p) { return theCollection->find(p); }
|
||||
const_iterator find(G4int p) const { return theCollection->find(p); }
|
||||
iterator find(G4int p) { return theCollection->find(p); }
|
||||
const_iterator find(G4int p) const { return theCollection->find(p); }
|
||||
|
||||
private:
|
||||
container_type* theCollection;
|
||||
mutable G4Mutex fMutex;
|
||||
private:
|
||||
container_type* theCollection;
|
||||
mutable G4Mutex fMutex;
|
||||
};
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
G4TAtomicHitsMap<T>::G4TAtomicHitsMap()
|
||||
: theCollection(new container_type)
|
||||
template<typename T>
|
||||
G4TAtomicHitsMap<T>::G4TAtomicHitsMap() : theCollection(new container_type)
|
||||
{}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
G4TAtomicHitsMap<T>::G4TAtomicHitsMap(G4String detName, G4String colNam)
|
||||
: G4VHitsCollection(detName, colNam)
|
||||
, theCollection(new container_type)
|
||||
: G4VHitsCollection(detName, colNam), theCollection(new container_type)
|
||||
{}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
G4TAtomicHitsMap<T>::~G4TAtomicHitsMap()
|
||||
{
|
||||
for(auto itr = theCollection->begin(); itr != theCollection->end(); itr++)
|
||||
for (auto itr = theCollection->begin(); itr != theCollection->end(); itr++)
|
||||
delete itr->second;
|
||||
|
||||
delete theCollection;
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
G4bool G4TAtomicHitsMap<T>::operator==(const G4TAtomicHitsMap<T>& right) const
|
||||
{
|
||||
return (collectionName == right.collectionName);
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
G4TAtomicHitsMap<T>& G4TAtomicHitsMap<T>::operator+=(
|
||||
const G4TAtomicHitsMap<T>& rhs) const
|
||||
template<typename T>
|
||||
G4TAtomicHitsMap<T>& G4TAtomicHitsMap<T>::operator+=(const G4TAtomicHitsMap<T>& rhs) const
|
||||
{
|
||||
for(auto itr = rhs.GetMap()->begin(); itr != rhs.GetMap()->end(); itr++)
|
||||
for (auto itr = rhs.GetMap()->begin(); itr != rhs.GetMap()->end(); itr++)
|
||||
add(itr->first, *(itr->second));
|
||||
|
||||
return (G4TAtomicHitsMap<T>&) (*this);
|
||||
return (G4TAtomicHitsMap<T>&)(*this);
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
G4TAtomicHitsMap<T>& G4TAtomicHitsMap<T>::operator+=(
|
||||
const G4THitsMap<T>& rhs) const
|
||||
template<typename T>
|
||||
G4TAtomicHitsMap<T>& G4TAtomicHitsMap<T>::operator+=(const G4THitsMap<T>& rhs) const
|
||||
{
|
||||
for(auto itr = rhs.GetMap()->begin(); itr != rhs.GetMap()->end(); itr++)
|
||||
for (auto itr = rhs.GetMap()->begin(); itr != rhs.GetMap()->end(); itr++)
|
||||
add(itr->first, *(itr->second));
|
||||
|
||||
return (G4TAtomicHitsMap<T>&) (*this);
|
||||
return (G4TAtomicHitsMap<T>&)(*this);
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
inline
|
||||
typename G4TAtomicHitsMap<T>::value_type* G4TAtomicHitsMap<T>::operator[](
|
||||
G4int key) const
|
||||
template<typename T>
|
||||
inline typename G4TAtomicHitsMap<T>::value_type* G4TAtomicHitsMap<T>::operator[](G4int key) const
|
||||
{
|
||||
if(theCollection->find(key) != theCollection->end())
|
||||
if (theCollection->find(key) != theCollection->end())
|
||||
return theCollection->find(key)->second;
|
||||
else
|
||||
{
|
||||
else {
|
||||
G4AutoLock l(&fMutex);
|
||||
if(theCollection->find(key) == theCollection->end())
|
||||
{
|
||||
value_type* ptr = new value_type;
|
||||
if (theCollection->find(key) == theCollection->end()) {
|
||||
value_type* ptr = new value_type;
|
||||
(*theCollection)[key] = ptr;
|
||||
return ptr;
|
||||
}
|
||||
@@ -208,13 +199,12 @@ inline
|
||||
}
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
inline G4int G4TAtomicHitsMap<T>::add(const G4int& key, value_type*& aHit) const
|
||||
{
|
||||
if(theCollection->find(key) != theCollection->end())
|
||||
if (theCollection->find(key) != theCollection->end())
|
||||
*(*theCollection)[key] += *aHit;
|
||||
else
|
||||
{
|
||||
else {
|
||||
G4AutoLock l(&fMutex);
|
||||
(*theCollection)[key] = aHit;
|
||||
}
|
||||
@@ -222,15 +212,14 @@ inline G4int G4TAtomicHitsMap<T>::add(const G4int& key, value_type*& aHit) const
|
||||
return theCollection->size();
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
inline G4int G4TAtomicHitsMap<T>::add(const G4int& key, T& aHit) const
|
||||
{
|
||||
if(theCollection->find(key) != theCollection->end())
|
||||
if (theCollection->find(key) != theCollection->end())
|
||||
*(*theCollection)[key] += aHit;
|
||||
else
|
||||
{
|
||||
else {
|
||||
value_type* hit = new value_type;
|
||||
*hit = aHit;
|
||||
*hit = aHit;
|
||||
G4AutoLock l(&fMutex);
|
||||
(*theCollection)[key] = hit;
|
||||
}
|
||||
@@ -238,49 +227,47 @@ inline G4int G4TAtomicHitsMap<T>::add(const G4int& key, T& aHit) const
|
||||
return theCollection->size();
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
inline G4int G4TAtomicHitsMap<T>::set(const G4int& key, value_type*& aHit) const
|
||||
{
|
||||
if(theCollection->find(key) != theCollection->end())
|
||||
delete(*theCollection)[key]->second;
|
||||
if (theCollection->find(key) != theCollection->end()) delete (*theCollection)[key]->second;
|
||||
|
||||
(*theCollection)[key] = aHit;
|
||||
G4AutoLock l(&fMutex);
|
||||
return theCollection->size();
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
inline G4int G4TAtomicHitsMap<T>::set(const G4int& key, T& aHit) const
|
||||
{
|
||||
if(theCollection->find(key) != theCollection->end())
|
||||
if (theCollection->find(key) != theCollection->end())
|
||||
*(*theCollection)[key] = aHit;
|
||||
else
|
||||
{
|
||||
value_type* hit = new value_type;
|
||||
*hit = aHit;
|
||||
else {
|
||||
value_type* hit = new value_type;
|
||||
*hit = aHit;
|
||||
(*theCollection)[key] = hit;
|
||||
}
|
||||
G4AutoLock l(&fMutex);
|
||||
return theCollection->size();
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
void G4TAtomicHitsMap<T>::DrawAllHits()
|
||||
{}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
void G4TAtomicHitsMap<T>::PrintAllHits()
|
||||
{
|
||||
G4cout << "G4TAtomicHitsMap " << SDname << " / " << collectionName << " --- "
|
||||
<< entries() << " entries" << G4endl;
|
||||
G4cout << "G4TAtomicHitsMap " << SDname << " / " << collectionName << " --- " << entries()
|
||||
<< " entries" << G4endl;
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
void G4TAtomicHitsMap<T>::clear()
|
||||
{
|
||||
G4AutoLock l(&fMutex);
|
||||
|
||||
for(auto itr = theCollection->begin(); itr != theCollection->end(); itr++)
|
||||
for (auto itr = theCollection->begin(); itr != theCollection->end(); itr++)
|
||||
delete itr->second;
|
||||
|
||||
theCollection->clear();
|
||||
|
||||
Reference in New Issue
Block a user