File indexing completed on 2025-09-18 09:15:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 #ifndef G4TDigiCollection_h
0041 #define G4TDigiCollection_h 1
0042
0043 #include "G4Allocator.hh"
0044 #include "G4VDigiCollection.hh"
0045 #include "globals.hh"
0046
0047 #include <vector>
0048
0049 class G4DigiCollection : public G4VDigiCollection
0050 {
0051 public:
0052
0053 using G4VDigiCollection::G4VDigiCollection;
0054 ~G4DigiCollection() override = default;
0055
0056 G4bool operator==(const G4DigiCollection& right) const { return (this == &right); }
0057
0058 protected:
0059
0060 void* theCollection = nullptr;
0061 };
0062
0063 #if defined G4DIGI_ALLOC_EXPORT
0064 extern G4DLLEXPORT G4Allocator<G4DigiCollection>*& aDCAllocator_G4MT_TLS_();
0065 #else
0066 extern G4DLLIMPORT G4Allocator<G4DigiCollection>*& aDCAllocator_G4MT_TLS_();
0067 #endif
0068
0069 template <class T>
0070 class G4TDigiCollection : public G4DigiCollection
0071 {
0072 public:
0073
0074 G4TDigiCollection();
0075 G4TDigiCollection(const G4String& detName, const G4String& colNam);
0076 ~G4TDigiCollection() override;
0077
0078 G4bool operator==(const G4TDigiCollection& right) const;
0079
0080 inline void* operator new(std::size_t);
0081 inline void operator delete(void* aDC);
0082
0083
0084 void DrawAllDigi() override;
0085
0086
0087 void PrintAllDigi() override;
0088
0089
0090
0091 inline T* operator[](std::size_t i) const { return (*((std::vector<T*>*)theCollection))[i]; }
0092
0093
0094 inline std::vector<T*>* GetVector() const { return (std::vector<T*>*)theCollection; }
0095
0096
0097
0098 inline std::size_t insert(T* aHit)
0099 {
0100 auto theDigiCollection = (std::vector<T*>*)theCollection;
0101 theDigiCollection->push_back(aHit);
0102 return theDigiCollection->size();
0103 }
0104
0105
0106 inline std::size_t entries() const
0107 {
0108 auto theDigiCollection = (std::vector<T*>*)theCollection;
0109 return theDigiCollection->size();
0110 }
0111
0112 G4VDigi* GetDigi(std::size_t i) const override { return (*((std::vector<T*>*)theCollection))[i]; }
0113
0114 std::size_t GetSize() const override { return ((std::vector<T*>*)theCollection)->size(); }
0115 };
0116
0117 template <class T>
0118 inline void* G4TDigiCollection<T>::operator new(std::size_t)
0119 {
0120 if (aDCAllocator_G4MT_TLS_() == nullptr) {
0121 aDCAllocator_G4MT_TLS_() = new G4Allocator<G4DigiCollection>;
0122 }
0123 return (void*)aDCAllocator_G4MT_TLS_()->MallocSingle();
0124 }
0125
0126 template <class T>
0127 inline void G4TDigiCollection<T>::operator delete(void* aDC)
0128 {
0129 aDCAllocator_G4MT_TLS_()->FreeSingle((G4DigiCollection*)aDC);
0130 }
0131
0132 template <class T>
0133 G4TDigiCollection<T>::G4TDigiCollection()
0134 {
0135 auto theDigiCollection = new std::vector<T*>;
0136 theCollection = (void*)theDigiCollection;
0137 }
0138
0139 template <class T>
0140 G4TDigiCollection<T>::G4TDigiCollection(const G4String& detName, const G4String& colNam)
0141 : G4DigiCollection(detName, colNam)
0142 {
0143 auto theDigiCollection = new std::vector<T*>;
0144 theCollection = (void*)theDigiCollection;
0145 }
0146
0147 template <class T>
0148 G4TDigiCollection<T>::~G4TDigiCollection()
0149 {
0150 auto theDigiCollection = (std::vector<T*>*)theCollection;
0151 for (const auto* digi : *theDigiCollection) {
0152 delete digi;
0153 }
0154 theDigiCollection->clear();
0155 delete theDigiCollection;
0156 }
0157
0158 template <class T>
0159 G4bool G4TDigiCollection<T>::operator==(const G4TDigiCollection<T>& right) const
0160 {
0161 return (collectionName == right.collectionName);
0162 }
0163
0164 template <class T>
0165 void G4TDigiCollection<T>::DrawAllDigi()
0166 {
0167 auto theDigiCollection = (std::vector<T*>*)theCollection;
0168 for (auto* digi : *theDigiCollection) {
0169 digi->Draw();
0170 }
0171 }
0172
0173 template <class T>
0174 void G4TDigiCollection<T>::PrintAllDigi()
0175 {
0176 auto theDigiCollection = (std::vector<T*>*)theCollection;
0177 for (auto* digi : *theDigiCollection) {
0178 digi->Print();
0179 }
0180 }
0181
0182 #endif