[831] | 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 | // |
---|
| 27 | // $Id: G4SmartVoxelStat.cc,v 1.3 2006/06/29 18:33:50 gunter Exp $ |
---|
[1058] | 28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $ |
---|
[831] | 29 | // |
---|
| 30 | // -------------------------------------------------------------------- |
---|
| 31 | // GEANT 4 class source file |
---|
| 32 | // |
---|
| 33 | // class G4SmartVoxelStat |
---|
| 34 | // |
---|
| 35 | // Stores information on the performance of the smart voxel algorithm |
---|
| 36 | // for an individual logical volume. |
---|
| 37 | // |
---|
| 38 | // Author: D.C.Williams, UCSC (davidw@scipp.ucsc.edu) |
---|
| 39 | // |
---|
| 40 | // -------------------------------------------------------------------- |
---|
| 41 | |
---|
| 42 | #include "G4SmartVoxelStat.hh" |
---|
| 43 | #include "G4SmartVoxelHeader.hh" |
---|
| 44 | #include "G4SmartVoxelNode.hh" |
---|
| 45 | #include "G4SmartVoxelProxy.hh" |
---|
| 46 | |
---|
| 47 | // |
---|
| 48 | // Constructor |
---|
| 49 | // |
---|
| 50 | G4SmartVoxelStat::G4SmartVoxelStat( const G4LogicalVolume *theVolume, |
---|
| 51 | const G4SmartVoxelHeader *theVoxel, |
---|
| 52 | G4double theSysTime, |
---|
| 53 | G4double theUserTime ) |
---|
| 54 | : volume(theVolume), |
---|
| 55 | voxel(theVoxel), |
---|
| 56 | sysTime(theSysTime), |
---|
| 57 | userTime(theUserTime), |
---|
| 58 | heads(1), |
---|
| 59 | nodes(0), |
---|
| 60 | pointers(0) |
---|
| 61 | { |
---|
| 62 | CountHeadsAndNodes( voxel ); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | // |
---|
| 67 | // Simple Accessors |
---|
| 68 | // |
---|
| 69 | const G4LogicalVolume *G4SmartVoxelStat::GetVolume() const |
---|
| 70 | { |
---|
| 71 | return volume; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | const G4SmartVoxelHeader *G4SmartVoxelStat::GetVoxel() const |
---|
| 75 | { |
---|
| 76 | return voxel; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | G4double G4SmartVoxelStat::GetSysTime() const |
---|
| 80 | { |
---|
| 81 | return sysTime; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | G4double G4SmartVoxelStat::GetUserTime() const |
---|
| 85 | { |
---|
| 86 | return userTime; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | G4double G4SmartVoxelStat::GetTotalTime() const |
---|
| 90 | { |
---|
| 91 | return sysTime + userTime; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | G4long G4SmartVoxelStat::GetNumberHeads() const |
---|
| 95 | { |
---|
| 96 | return heads; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | G4long G4SmartVoxelStat::GetNumberNodes() const |
---|
| 100 | { |
---|
| 101 | return nodes; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | G4long G4SmartVoxelStat::GetNumberPointers() const |
---|
| 105 | { |
---|
| 106 | return pointers; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | // |
---|
| 111 | // Return approximate memory use |
---|
| 112 | // |
---|
| 113 | G4long G4SmartVoxelStat::GetMemoryUse() const |
---|
| 114 | { |
---|
| 115 | static const G4long headSize = sizeof(G4SmartVoxelHeader) |
---|
| 116 | + sizeof(G4SmartVoxelProxy); |
---|
| 117 | |
---|
| 118 | static const G4long nodeSize = sizeof(G4SmartVoxelNode) |
---|
| 119 | + sizeof(G4SmartVoxelProxy); |
---|
| 120 | |
---|
| 121 | static const G4long pointerSize = sizeof(G4SmartVoxelProxy*); |
---|
| 122 | |
---|
| 123 | return nodes*nodeSize + heads*headSize + pointers*pointerSize; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | // |
---|
| 129 | // CountHeadsAndNodes |
---|
| 130 | // |
---|
| 131 | // Recursively count the number of voxel headers and nodes, |
---|
| 132 | // updating class member variables heads and nodes on the way. |
---|
| 133 | // |
---|
| 134 | void G4SmartVoxelStat::CountHeadsAndNodes( const G4SmartVoxelHeader *head ) |
---|
| 135 | { |
---|
| 136 | G4int numSlices = head->GetNoSlices(); |
---|
| 137 | |
---|
| 138 | pointers += numSlices; |
---|
| 139 | |
---|
| 140 | const G4SmartVoxelProxy *lastProxy = 0; |
---|
| 141 | |
---|
| 142 | for(G4int i=0;i<numSlices;++i) { |
---|
| 143 | const G4SmartVoxelProxy *proxy = head->GetSlice(i); |
---|
| 144 | if (proxy == lastProxy) continue; |
---|
| 145 | |
---|
| 146 | lastProxy = proxy; |
---|
| 147 | |
---|
| 148 | if (proxy->IsNode()) { |
---|
| 149 | nodes++; |
---|
| 150 | } |
---|
| 151 | else { |
---|
| 152 | heads++; |
---|
| 153 | CountHeadsAndNodes(proxy->GetHeader()); |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | } |
---|