ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4TAtomicHitsCollection.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file 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 //
31 //
40 //
41 //
42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44 
45 
46 
47 
48 #ifndef G4TAtomicHitsCollection_h
49 #define G4TAtomicHitsCollection_h 1
50 
51 #include "G4VHitsCollection.hh"
52 #include "G4Allocator.hh"
53 #include "globals.hh"
54 #include "G4Threading.hh"
55 #include "G4AutoLock.hh"
56 #include "G4atomic.hh"
57 
58 #include <deque>
59 #include <type_traits>
60 
61 // class description:
62 //
63 // This is a template class of hits collection and parametrized by
64 // The concrete class of G4VHit. This is a uniform collection for
65 // a particular concrete hit class objects.
66 // An intermediate layer class G4HitsCollection appeared in this
67 // header file is used just for G4Allocator, because G4Allocator
68 // cannot be instansiated with a template class. Thus G4HitsCollection
69 // class MUST NOT be directly used by the user.
70 
71 /*class G4HitsCollection : public G4VHitsCollection
72 {
73  public:
74  G4HitsCollection();
75  G4HitsCollection(G4String detName,G4String colNam);
76  virtual ~G4HitsCollection();
77  G4bool operator==(const G4HitsCollection &right) const;
78 
79  protected:
80  void* theCollection;
81 };*/
82 
83 
84 template <class T>
86 {
87 protected:
88  static_assert(std::is_fundamental<T>::value,
89  "G4TAtomicHitsCollection must use fundamental type");
90 
91 public:
92  typedef T base_type;
94  typedef typename std::deque<value_type*> container_type;
95 
96 public:
98 
99 public:
100  // with description
101  G4TAtomicHitsCollection(G4String detName, G4String colNam);
102 
103  // constructor.
104 public:
105  virtual ~G4TAtomicHitsCollection();
107 
108  //inline void *operator new(size_t);
109  //inline void operator delete(void* anHC);
110 
111 public: // with description
112  virtual void DrawAllHits();
113  virtual void PrintAllHits();
114  // These two methods invokes Draw() and Print() methods of all of
115  // hit objects stored in this collection, respectively.
116 
117 public: // with description
118  inline value_type* operator[](size_t i) const
119  {
120  return (*theCollection)[i];
121  }
122  // Returns a pointer to a concrete hit object.
123  inline container_type* GetVector() const
124  {
125  return theCollection;
126  }
127  // Returns a collection vector.
128  inline G4int insert(T* aHit)
129  {
130  G4AutoLock l(&fMutex);
131  theCollection->push_back(aHit);
132  return theCollection->size();
133  }
134  // Insert a hit object. Total number of hit objects stored in this
135  // collection is returned.
136  inline G4int entries() const
137  {
138  G4AutoLock l(&fMutex);
139  return theCollection->size();
140  }
141  // Returns the number of hit objects stored in this collection
142 
143 public:
144  virtual G4VHit* GetHit(size_t i) const
145  {
146  return (*theCollection)[i];
147  }
148  virtual size_t GetSize() const
149  {
150  G4AutoLock l(&fMutex);
151  return theCollection->size();
152  }
153 
154 protected:
157 
158 };
159 
160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
161 template <class T>
163  : theCollection(new container_type)
164 { }
165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
166 template <class T>
168  G4String colNam)
169  : G4VHitsCollection(detName,colNam),
170  theCollection(new container_type)
171 { }
172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
174 {
175  for(size_t i = 0; i < theCollection->size(); i++)
176  delete (*theCollection)[i];
177  theCollection->clear();
178  delete theCollection;
179 }
180 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
181 template <class T>
184 {
185  return (collectionName == right.collectionName);
186 }
187 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
188 template <class T>
190 {
191  G4AutoLock l(&fMutex);
192  for(size_t i = 0; i < theCollection->size(); i++)
193  (*theCollection)[i]->Draw();
194 }
195 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
196 template <class T>
198 {
199  G4AutoLock l(&fMutex);
200  for(size_t i = 0; i < theCollection->size(); i++)
201  (*theCollection)[i]->Print();
202 }
203 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
204 
205 #endif