Geant4 Cross Reference |
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 // 26 // G4PVReplica 27 // 28 // Class description: 29 // 30 // Represents many touchable detector elements differing only in their 31 // positioning. The elements' positions are calculated by means of a simple 32 // linear formula, and the elements completely fill the containing mother 33 // volume. 34 // 35 // G4PVReplica(const G4String& pName, 36 // G4LogicalVolume *pLogical, 37 // G4LogicalVolume *pMother, 38 // const EAxis pAxis, 39 // const G4int nReplicas, 40 // const G4double width, 41 // const G4double offset=0); 42 // 43 // Replication may occur along: 44 // 45 // o Cartesian axes (kXAxis,kYAxis,kZAxis) 46 // 47 // The replications, of specified width have coordinates of 48 // form (-width*(nReplicas-1)*0.5+n*width,0,0) where n=0.. nReplicas-1 49 // for the case of kXAxis, and are unrotated. 50 // 51 // o Radial axis (cylindrical polar) (kRho) 52 // 53 // The replications are cons/tubs sections, centred on the origin 54 // and are unrotated. 55 // They have radii of width*n+offset to width*(n+1)+offset 56 // where n=0..nReplicas-1 57 // 58 // o Phi axis (cylindrical polar) (kPhi) 59 // The replications are `phi sections' or wedges, and of cons/tubs form 60 // They have phi of offset+n*width to offset+(n+1)*width where 61 // n=0..nReplicas-1 62 63 // 29.07.95 P.Kent - First non-stub version 64 // 13.01.13 G.Cosmo, A.Dotti - Modified for thread-safety for MT 65 // ---------------------------------------------------------------------- 66 #ifndef G4PVREPLICA_HH 67 #define G4PVREPLICA_HH 1 68 69 #include "G4VPhysicalVolume.hh" 70 #include "G4GeomSplitter.hh" 71 72 class G4ReplicaData 73 { 74 // Encapsulates the fields of the class G4PVReplica that may not be 75 // read-only. G4PVReplica inherits from the class G4VPhysicalVolume. 76 // The fields from the ancestor that may not be read-only are handled 77 // by the ancestor class. 78 79 public: 80 81 void initialize() {} 82 83 G4int fcopyNo = -1; 84 }; 85 86 using G4PVRManager = G4GeomSplitter<G4ReplicaData>; 87 // Implementation detail for use of G4ReplicaData objects 88 89 class G4PVReplica : public G4VPhysicalVolume 90 { 91 public: 92 93 G4PVReplica(const G4String& pName, 94 G4LogicalVolume* pLogical, 95 G4LogicalVolume* pMother, 96 const EAxis pAxis, 97 const G4int nReplicas, 98 const G4double width, 99 const G4double offset = 0.); 100 101 G4PVReplica(const G4String& pName, 102 G4LogicalVolume* pLogical, 103 G4VPhysicalVolume* pMother, 104 const EAxis pAxis, 105 const G4int nReplicas, 106 const G4double width, 107 const G4double offset = 0.); 108 109 G4PVReplica(__void__&); 110 // Fake default constructor for usage restricted to direct object 111 // persistency for clients requiring preallocation of memory for 112 // persistifiable objects. 113 114 G4PVReplica(const G4PVReplica&) = delete; 115 G4PVReplica& operator=(const G4PVReplica&) = delete; 116 // Copy constructor and assignment operator not allowed 117 118 ~G4PVReplica() override; 119 120 EVolume VolumeType() const override; 121 122 G4bool IsMany() const override; 123 G4bool IsReplicated() const override; 124 125 G4int GetCopyNo() const override; 126 void SetCopyNo(G4int CopyNo) override; 127 G4bool IsParameterised() const override; 128 G4VPVParameterisation* GetParameterisation() const override; 129 G4int GetMultiplicity() const override; 130 void GetReplicationData(EAxis& axis, 131 G4int& nReplicas, 132 G4double& width, 133 G4double& offset, 134 G4bool& consuming) const override; 135 136 virtual void SetRegularStructureId( G4int code ); 137 // This method must set a unique code for each type of regular structure. 138 // - It must be called only during detector construction. 139 // - It can also be used to prepare any corresponding special 140 // navigation 'conditions'. 141 142 G4bool IsRegularStructure() const override; 143 G4int GetRegularStructureId() const override; 144 // Accessors for specialised geometries 145 146 // Methods for handling of MT instances 147 148 inline G4int GetInstanceID() const { return instanceID; } 149 // Returns the instance ID. 150 151 static const G4PVRManager& GetSubInstanceManager(); 152 // Returns the private data instance manager. 153 154 void InitialiseWorker(G4PVReplica* pMasterObject); 155 // This method is similar to the constructor. It is used by each worker 156 // thread to achieve the partial effect as that of the master thread. 157 158 void TerminateWorker(G4PVReplica* pMasterObject); 159 // This method is similar to the destructor. It is used by each worker 160 // thread to achieve the partial effect as that of the master thread. 161 162 protected: 163 164 G4PVReplica(const G4String& pName, 165 G4int nReplicas, 166 EAxis pAxis, 167 G4LogicalVolume* pLogical, 168 G4LogicalVolume* pMotherLogical); 169 // Constructor for derived type(s): PVParameterised, PVDivision, ... 170 // Does not set mother or register in mother volume -- leaves it to 171 // derived type 172 173 private: 174 175 void CheckAndSetParameters(const EAxis pAxis, const G4int nReplicas, 176 const G4double width, const G4double offset); 177 178 void CheckOnlyDaughter(G4LogicalVolume* pMotherLogical); 179 // Check that this volume is the only daughter of its proposed mother 180 // volume 181 182 protected: 183 184 EAxis faxis; 185 G4int fnReplicas; 186 G4double fwidth, foffset; 187 188 private: 189 190 G4int fRegularVolsId = 0; 191 192 G4int instanceID; 193 // This new field is used as instance ID. 194 G4GEOM_DLL static G4PVRManager subInstanceManager; 195 // This new field helps to use the class G4PVRManager introduced above. 196 }; 197 198 // NOTE: 199 // The type G4PVRManager is introduced to encapsulate the methods used by 200 // both the master thread and worker threads to allocate memory space for 201 // the fields encapsulated by the class G4ReplicaData. When each thread 202 // initializes the value for these fields, it refers to them using a macro 203 // definition defined below. For every G4PVReplica instance, there is 204 // a corresponding G4ReplicaData instance. All G4ReplicaData instances are 205 // organized by the class G4PVRManager as an array. 206 // The field "int instanceID" is added to the class G4PVReplica. 207 // The value of this field in each G4LogicalVolume instance is the subscript 208 // of the corresponding G4ReplicaData instance. 209 // In order to use the class G4PVRManager, we add a static member in the 210 // class G4LogicalVolume as follows: "static G4PVRManager subInstanceManager". 211 // For the master thread, the array for G4ReplicaData instances grows 212 // dynamically along with G4PVReplica instances arecreated. 213 // For each worker thread, it copies the array of G4ReplicaData instances 214 // from the master thread. 215 // In addition, it invokes a method similiar to the constructor explicitly 216 // to achieve the partial effect for each instance in the array. 217 218 #endif 219