Main Page | Compound List | File List | Compound Members | File Members | Related Pages

McObjectManager.cxx

Go to the documentation of this file.
00001 // File and Version Information:
00002 // $Header: /nfs/slac/g/glast/ground/cvs/mcRootData/src/McObjectManager.cxx,v 1.1 2007/02/15 19:25:24 usher Exp $
00003 //
00004 // Description: this utility singleton is used in various classes of G4Generator
00005 // to register new McParticle objects, retrive the actual McParticle (i.e. the
00006 // one that is actually creating hits in the sensitive detectors) and to finally
00007 // save the McParticle hierarchy in the TDS
00008 //      
00009 // Author(s):
00010 //      Am. Crazy
00011 
00012 #include "McObjectManager.h"
00013 
00014 // This is the singleton static pointer
00015 McObjectManager* McObjectManager::m_pointer = 0;
00016 
00017 // Define the pool for McParticles
00018 #define MCPOOLSIZE         1000
00019 #define MCMAXPOOLGROW      20000
00020 #define MCHITPOOLSIZE      1000
00021 #define MCHITMAXPOOLGROW   1000
00022 #define MCPOINTPOOLSIZE    5000
00023 #define MCPOINTMAXPOOLGROW 50000
00024 
00025 McObjectManager::McObjectManager() : m_mcPartPool(MCPOOLSIZE), 
00026                                      m_mcPosHitPool(MCHITPOOLSIZE), 
00027                                      m_mcIntHitPool(MCHITPOOLSIZE),
00028                                      m_mcTrajectoryPool(MCPOOLSIZE),
00029                                      m_mcTrajPointPool(MCPOINTPOOLSIZE)
00030 {
00031     m_mcPartPoolIdx       = m_mcPartPool.begin();
00032     m_mcPosHitPoolIdx     = m_mcPosHitPool.begin();
00033     m_mcIntHitPoolIdx     = m_mcIntHitPool.begin();
00034     m_mcTrajectoryPoolIdx = m_mcTrajectoryPool.begin();
00035     m_mcTrajPointPoolIdx  = m_mcTrajPointPool.begin();
00036 }
00037 
00038 McObjectManager* McObjectManager::getPointer()
00039 {
00040   // Purpose and Method: standard singleton method to retrive the unique pointer
00041   if(m_pointer == 0) m_pointer = new McObjectManager();
00042   return m_pointer;
00043 }
00044 
00045 McParticle* McObjectManager::getNewMcParticle()
00046 {
00047     McParticle* mcPart = 0;
00048 
00049     // If we have exceeded our pre-allocated list of McParticles then expand
00050     if (m_mcPartPoolIdx == m_mcPartPool.end())
00051     {
00052         // Add one more McParticle just before the end... this is really a 
00053         // trick to get a valid iterator at the end of the list
00054         m_mcPartPoolIdx = m_mcPartPool.insert(m_mcPartPoolIdx, McParticle());
00055 
00056         // Expand the pool by some reasonable amount
00057         int newSize = std::max((int)(2 * m_mcPartPool.size()), (int)MCMAXPOOLGROW);
00058 
00059         // For good measure expand the pool by our starting poolsize
00060         m_mcPartPool.insert(m_mcPartPool.end(), newSize, McParticle());
00061     }
00062 
00063     // Get the pointer to an available McParticle
00064     mcPart = &*m_mcPartPoolIdx++;
00065 
00066     return mcPart;
00067 }
00068 
00069 McPositionHit* McObjectManager::getNewMcPositionHit()
00070 {
00071     McPositionHit* posHit = 0;
00072 
00073     // If we have exceeded our pre-allocated list of McParticles then expand
00074     if (m_mcPosHitPoolIdx == m_mcPosHitPool.end())
00075     {
00076         // Add one more McPositionHit just before the end... this is really a 
00077         // trick to get a valid iterator at the end of the list
00078         m_mcPosHitPoolIdx = m_mcPosHitPool.insert(m_mcPosHitPoolIdx, McPositionHit());
00079 
00080         // Expand the pool by some reasonable amount
00081         int newSize = std::max((int)(2 * m_mcPosHitPool.size()), (int)MCHITMAXPOOLGROW);
00082 
00083         // For good measure expand the pool by our starting poolsize
00084         m_mcPosHitPool.insert(m_mcPosHitPool.end(), newSize, McPositionHit());
00085     }
00086 
00087     // Get the pointer to an available McParticle
00088     posHit = &*m_mcPosHitPoolIdx++;
00089 
00090     return posHit;
00091 }
00092 
00093 McIntegratingHit* McObjectManager::getNewMcIntegratingHit()
00094 {
00095     McIntegratingHit* intHit = 0;
00096 
00097     // If we have exceeded our pre-allocated list of McIntegratingHits then expand
00098     if (m_mcIntHitPoolIdx == m_mcIntHitPool.end())
00099     {
00100         // Add one more McIntegratingHit just before the end... this is really a 
00101         // trick to get a valid iterator at the end of the list
00102         m_mcIntHitPoolIdx = m_mcIntHitPool.insert(m_mcIntHitPoolIdx, McIntegratingHit());
00103 
00104         // Expand the pool by some reasonable amount
00105         int newSize = std::max((int)(2 * m_mcIntHitPool.size()), (int)MCHITMAXPOOLGROW);
00106 
00107         // For good measure expand the pool by our starting poolsize
00108         m_mcIntHitPool.insert(m_mcIntHitPool.end(), newSize, McIntegratingHit());
00109     }
00110 
00111     // Get the pointer to an available McParticle
00112     intHit = &*m_mcIntHitPoolIdx++;
00113 
00114     return intHit;
00115 }
00116 
00117 McTrajectory* McObjectManager::getNewMcTrajectory()
00118 {
00119     McTrajectory* traj = 0;
00120 
00121     // If we have exceeded our pre-allocated list of McIntegratingHits then expand
00122     if (m_mcTrajectoryPoolIdx == m_mcTrajectoryPool.end())
00123     {
00124         // Add one more McTrajectory just before the end... this is really a 
00125         // trick to get a valid iterator at the end of the list
00126         m_mcTrajectoryPoolIdx = m_mcTrajectoryPool.insert(m_mcTrajectoryPoolIdx, McTrajectory());
00127 
00128         // Expand the pool by some reasonable amount
00129         int newSize = std::max((int)(2 * m_mcTrajectoryPool.size()), (int)MCMAXPOOLGROW);
00130 
00131         // For good measure expand the pool by our starting poolsize
00132         m_mcTrajectoryPool.insert(m_mcTrajectoryPool.end(), newSize, McTrajectory());
00133     }
00134 
00135     // Get the pointer to an available McTrajectory
00136     traj = &*m_mcTrajectoryPoolIdx++;
00137 
00138     return traj;
00139 }
00140 
00141 McTrajectoryPoint* McObjectManager::getNewMcTrajectoryPoint()
00142 {
00143     McTrajectoryPoint* point = 0;
00144 
00145     // If we have exceeded our pre-allocated list of McIntegratingHits then expand
00146     if (m_mcTrajPointPoolIdx == m_mcTrajPointPool.end())
00147     {
00148         // Add one more McTrajectory just before the end... this is really a 
00149         // trick to get a valid iterator at the end of the list
00150         m_mcTrajPointPoolIdx = m_mcTrajPointPool.insert(m_mcTrajPointPoolIdx, McTrajectoryPoint());
00151 
00152         // Expand the pool by some reasonable amount
00153         int newSize = std::max((int)(2 * m_mcTrajPointPool.size()), (int)MCPOINTMAXPOOLGROW);
00154 
00155         // For good measure expand the pool by our starting poolsize
00156         m_mcTrajPointPool.insert(m_mcTrajPointPool.end(), newSize, McTrajectoryPoint());
00157     }
00158 
00159     // Get the pointer to an available McTrajectory
00160     point = &*m_mcTrajPointPoolIdx++;
00161 
00162     return point;
00163 }
00164 
00165 void McObjectManager::Delete()
00166 {
00167     // Keep all of the pools down to a reasonable size...
00168     // Start with McParticle pool
00169     if (m_mcPartPool.size() > 5*MCPOOLSIZE)
00170     {
00171         m_mcPartPool.resize(5*MCPOOLSIZE);
00172     }
00173 
00174     // Now the with McPositionHit pool
00175     if (m_mcPosHitPool.size() > 5*MCHITPOOLSIZE)
00176     {
00177         m_mcPosHitPool.resize(5*MCHITPOOLSIZE);
00178     }
00179 
00180     // Now the with McIntegratingHit pool
00181     if (m_mcIntHitPool.size() > 5*MCHITPOOLSIZE)
00182     {
00183         m_mcIntHitPool.resize(5*MCHITPOOLSIZE);
00184     }
00185 
00186     // Now the with McTrajectory pool
00187     if (m_mcTrajectoryPool.size() > 5*MCPOOLSIZE)
00188     {
00189         m_mcTrajectoryPool.resize(5*MCPOOLSIZE);
00190     }
00191 
00192     // Now the with McTrajectoryPoint pool
00193     if (m_mcTrajPointPool.size() > 5*MCPOINTPOOLSIZE)
00194     {
00195         m_mcTrajPointPool.resize(5*MCPOINTPOOLSIZE);
00196     }
00197 
00198     // Ok, reset iterators to first element of our pools
00199     m_mcPartPoolIdx       = m_mcPartPool.begin();
00200     m_mcPosHitPoolIdx     = m_mcPosHitPool.begin();
00201     m_mcIntHitPoolIdx     = m_mcIntHitPool.begin();
00202     m_mcTrajectoryPoolIdx = m_mcTrajectoryPool.begin();
00203     m_mcTrajPointPoolIdx  = m_mcTrajPointPool.begin();
00204 
00205     return;
00206 }
00207 
00208 
00209 

Generated on Tue Dec 11 16:28:53 2007 by doxygen 1.3.3