G4SmartVoxelStat.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // --------------------------------------------------------------------
00030 // GEANT 4 class source file
00031 //
00032 // class G4SmartVoxelStat
00033 //
00034 // Stores information on the performance of the smart voxel algorithm
00035 // for an individual logical volume.
00036 //
00037 // Author: D.C.Williams, UCSC (davidw@scipp.ucsc.edu)
00038 //
00039 // --------------------------------------------------------------------
00040 
00041 #include "G4SmartVoxelStat.hh"
00042 #include "G4SmartVoxelHeader.hh"
00043 #include "G4SmartVoxelNode.hh"
00044 #include "G4SmartVoxelProxy.hh"
00045 
00046 //
00047 // Constructor
00048 //
00049 G4SmartVoxelStat::G4SmartVoxelStat( const G4LogicalVolume *theVolume,
00050                                     const G4SmartVoxelHeader *theVoxel,
00051                                           G4double theSysTime,
00052                                           G4double theUserTime )
00053     : volume(theVolume),
00054       voxel(theVoxel),
00055       sysTime(theSysTime),
00056       userTime(theUserTime),
00057       heads(1),
00058       nodes(0),
00059       pointers(0)
00060 {
00061   CountHeadsAndNodes( voxel );
00062 }
00063 
00064 
00065 //
00066 // Simple Accessors
00067 //
00068 const G4LogicalVolume *G4SmartVoxelStat::GetVolume() const
00069 {
00070   return volume;
00071 }
00072 
00073 const G4SmartVoxelHeader *G4SmartVoxelStat::GetVoxel() const
00074 {
00075   return voxel;
00076 }
00077 
00078 G4double G4SmartVoxelStat::GetSysTime() const
00079 {
00080   return sysTime;
00081 }
00082 
00083 G4double G4SmartVoxelStat::GetUserTime() const
00084 {
00085   return userTime;
00086 }
00087 
00088 G4double G4SmartVoxelStat::GetTotalTime() const
00089 {
00090   return sysTime + userTime;
00091 }
00092 
00093 G4long G4SmartVoxelStat::GetNumberHeads() const
00094 {
00095   return heads;
00096 }
00097 
00098 G4long G4SmartVoxelStat::GetNumberNodes() const
00099 {
00100   return nodes;
00101 }
00102 
00103 G4long G4SmartVoxelStat::GetNumberPointers() const
00104 {
00105   return pointers;
00106 }
00107 
00108 
00109 //
00110 // Return approximate memory use
00111 //
00112 G4long G4SmartVoxelStat::GetMemoryUse() const
00113 {
00114   static const G4long headSize = sizeof(G4SmartVoxelHeader)
00115                                + sizeof(G4SmartVoxelProxy);
00116 
00117   static const G4long nodeSize = sizeof(G4SmartVoxelNode)
00118                                + sizeof(G4SmartVoxelProxy);
00119 
00120   static const G4long pointerSize = sizeof(G4SmartVoxelProxy*);
00121   
00122   return nodes*nodeSize + heads*headSize + pointers*pointerSize;
00123 }
00124 
00125 
00126 
00127 //
00128 // CountHeadsAndNodes
00129 //
00130 // Recursively count the number of voxel headers and nodes,
00131 // updating class member variables heads and nodes on the way.
00132 //
00133 void G4SmartVoxelStat::CountHeadsAndNodes( const G4SmartVoxelHeader *head ) 
00134 {
00135   G4int numSlices = head->GetNoSlices();
00136   
00137   pointers += numSlices;
00138   
00139   const G4SmartVoxelProxy *lastProxy = 0;
00140   
00141   for(G4int i=0;i<numSlices;++i) {
00142     const G4SmartVoxelProxy *proxy = head->GetSlice(i);
00143     if (proxy == lastProxy) continue;
00144     
00145     lastProxy = proxy;
00146     
00147     if (proxy->IsNode()) {
00148       nodes++;
00149     }
00150     else {
00151       heads++;
00152       CountHeadsAndNodes(proxy->GetHeader());
00153     }
00154   }
00155 }

Generated on Mon May 27 17:49:51 2013 for Geant4 by  doxygen 1.4.7