Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4TAtomicHitsCollection.hh
이 파일의 문서화 페이지로 가기
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
28 //
29 //
30 // $Id: G4TAtomicHitsCollection.hh 93110 2015-11-05 08:37:42Z jmadsen $
31 //
32 //
41 //
42 //
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45 
46 
47 
48 
49 #ifndef G4TAtomicHitsCollection_h
50 #define G4TAtomicHitsCollection_h 1
51 
52 #include "G4VHitsCollection.hh"
53 #include "G4Allocator.hh"
54 #include "globals.hh"
55 #include "G4Threading.hh"
56 #include "G4AutoLock.hh"
57 #include "G4atomic.hh"
58 
59 #include <deque>
60 #include <type_traits>
61 
62 // class description:
63 //
64 // This is a template class of hits collection and parametrized by
65 // The concrete class of G4VHit. This is a uniform collection for
66 // a particular concrete hit class objects.
67 // An intermediate layer class G4HitsCollection appeared in this
68 // header file is used just for G4Allocator, because G4Allocator
69 // cannot be instansiated with a template class. Thus G4HitsCollection
70 // class MUST NOT be directly used by the user.
71 
72 /*class G4HitsCollection : public G4VHitsCollection
73 {
74  public:
75  G4HitsCollection();
76  G4HitsCollection(G4String detName,G4String colNam);
77  virtual ~G4HitsCollection();
78  G4int operator==(const G4HitsCollection &right) const;
79 
80  protected:
81  void* theCollection;
82 };*/
83 
84 
85 template <class T>
87 {
88 protected:
89  static_assert(std::is_fundamental<T>::value,
90  "G4TAtomicHitsCollection must use fundamental type");
91 
92 public:
93  typedef T base_type;
95  typedef typename std::deque<value_type*> container_type;
96 
97 public:
99 
100 public:
101  // with description
102  G4TAtomicHitsCollection(G4String detName, G4String colNam);
103 
104  // constructor.
105 public:
106  virtual ~G4TAtomicHitsCollection();
108 
109  //inline void *operator new(size_t);
110  //inline void operator delete(void* anHC);
111 
112 public: // with description
113  virtual void DrawAllHits();
114  virtual void PrintAllHits();
115  // These two methods invokes Draw() and Print() methods of all of
116  // hit objects stored in this collection, respectively.
117 
118 public: // with description
119  inline value_type* operator[](size_t i) const
120  {
121  return (*theCollection)[i];
122  }
123  // Returns a pointer to a concrete hit object.
124  inline container_type* GetVector() const
125  {
126  return theCollection;
127  }
128  // Returns a collection vector.
129  inline G4int insert(T* aHit)
130  {
131  G4AutoLock l(&fMutex);
132  theCollection->push_back(aHit);
133  return theCollection->size();
134  }
135  // Insert a hit object. Total number of hit objects stored in this
136  // collection is returned.
137  inline G4int entries() const
138  {
139  G4AutoLock l(&fMutex);
140  return theCollection->size();
141  }
142  // Returns the number of hit objects stored in this collection
143 
144 public:
145  virtual G4VHit* GetHit(size_t i) const
146  {
147  return (*theCollection)[i];
148  }
149  virtual size_t GetSize() const
150  {
151  G4AutoLock l(&fMutex);
152  return theCollection->size();
153  }
154 
155 protected:
158 
159 };
160 
161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
162 template <class T>
164  : theCollection(new container_type)
165 { }
166 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
167 template <class T>
169  G4String colNam)
170  : G4VHitsCollection(detName,colNam),
171  theCollection(new container_type)
172 { }
173 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
175 {
176  for(size_t i = 0; i < theCollection->size(); i++)
177  delete (*theCollection)[i];
178  theCollection->clear();
179  delete theCollection;
180 }
181 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
182 template <class T>
185 {
186  return (collectionName == right.collectionName);
187 }
188 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
189 template <class T>
191 {
192  G4AutoLock l(&fMutex);
193  for(size_t i = 0; i < theCollection->size(); i++)
194  (*theCollection)[i]->Draw();
195 }
196 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
197 template <class T>
199 {
200  G4AutoLock l(&fMutex);
201  for(size_t i = 0; i < theCollection->size(); i++)
202  (*theCollection)[i]->Print();
203 }
204 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
205 
206 #endif
virtual size_t GetSize() const
Definition: G4VHit.hh:48
const XML_Char int const XML_Char * value
Definition: expat.h:331
std::deque< value_type * > container_type
G4int operator==(const G4TAtomicHitsCollection< T > &right) const
int G4int
Definition: G4Types.hh:78
virtual G4VHit * GetHit(size_t i) const
_Tp G4atomic
Definition: G4atomic.hh:265
container_type * GetVector() const
value_type * operator[](size_t i) const
Definition of the G4atomic class.
std::mutex G4Mutex
Definition: G4Threading.hh:84