Import Geant4 11.3.0 source tree

This commit is contained in:
Gabriele Cosmo
2024-12-06 11:11:40 +01:00
parent e58e650b32
commit 32390e802b
1984 changed files with 98713 additions and 83996 deletions
@@ -105,3 +105,30 @@ void G4AllocatorList::Destroy(G4int nStat, G4int verboseLevel)
}
fList.clear();
}
void G4AllocatorList::Report(G4bool itemize) const
{
auto itr = fList.cbegin();
G4int j = 0;
G4double mem = 0, tmem = 0;
G4cout << "================== Current memory pools ==================="
<< G4endl;
for(; itr != fList.cend(); ++itr)
{
mem = (*itr)->GetAllocatedSize();
++j;
tmem += mem;
if(itemize)
{
G4cout << "Pool ID '" << (*itr)->GetPoolType()
<< "', size : " << std::setprecision(3) << mem / 1048576
<< std::setprecision(6) << " MB" << G4endl;
}
}
G4cout << "Number of memory pools allocated: " << Size() << G4endl;
G4cout << "Dynamic pools : " << j
<< " / Total memory : " << std::setprecision(2)
<< tmem / 1048576 << std::setprecision(6) << " MB" << G4endl;
G4cout << "============================================================"
<< G4endl;
}
@@ -42,7 +42,7 @@ class G4BuffercoutDestination::BufferImpl
public:
explicit BufferImpl(std::size_t maxSize) : m_maxSize(maxSize) {}
explicit BufferImpl(std::size_t maxSize, FlushFn_t&& f) : m_maxSize(maxSize), m_flushFn(f) {}
explicit BufferImpl(std::size_t maxSize, FlushFn_t&& f) : m_maxSize(maxSize), m_flushFn(std::move(f)) {}
~BufferImpl() = default;
+3 -3
View File
@@ -52,10 +52,10 @@ G4bool G4DataVector::Store(std::ofstream& fOut, G4bool ascii)
}
// Binary Mode
G4int sizeV = G4int(size());
auto sizeV = G4int(size());
fOut.write((char*) (&sizeV), sizeof sizeV);
G4double* value = new G4double[sizeV];
auto value = new G4double[sizeV];
std::size_t i = 0;
for(auto itr = cbegin(); itr != cend(); ++itr, ++i)
{
@@ -108,7 +108,7 @@ G4bool G4DataVector::Retrieve(std::ifstream& fIn, G4bool ascii)
// retrieve in binary mode
fIn.read((char*) (&sizeV), sizeof sizeV);
G4double* value = new G4double[sizeV];
auto value = new G4double[sizeV];
fIn.read((char*) (value), sizeV * (sizeof(G4double)));
if(G4int(fIn.gcount()) != G4int(sizeV * (sizeof(G4double))))
{
@@ -88,7 +88,7 @@ G4bool G4OrderedTable::Store(const G4String& fileName, G4bool ascii)
return false;
}
G4int tableSize = G4int(size()); // Number of elements
auto tableSize = G4int(size()); // Number of elements
if(!ascii)
{
fOut.write((char*) (&tableSize), sizeof tableSize);
@@ -71,7 +71,7 @@ G4bool G4PhysicsVector::Store(std::ofstream& fOut, G4bool ascii) const
std::size_t size = dataVector.size();
fOut.write((char*) (&size), sizeof size);
G4double* value = new G4double[2 * size];
auto value = new G4double[2 * size];
for (std::size_t i = 0; i < size; ++i)
{
value[2 * i] = binVector[i];
@@ -104,7 +104,7 @@ G4bool G4PhysicsVector::Retrieve(std::ifstream& fIn, G4bool ascii)
G4int siz0 = 0;
fIn >> siz0;
if (siz0 < 2) { return false; }
std::size_t siz = static_cast<std::size_t>(siz0);
auto siz = static_cast<std::size_t>(siz0);
if (fIn.fail() || siz != numberOfNodes)
{
return false;
@@ -140,7 +140,7 @@ G4bool G4PhysicsVector::Retrieve(std::ifstream& fIn, G4bool ascii)
std::size_t size;
fIn.read((char*) (&size), sizeof size);
G4double* value = new G4double[2 * size];
auto value = new G4double[2 * size];
fIn.read((char*) (value), 2 * size * (sizeof(G4double)));
if (static_cast<G4int>(fIn.gcount()) != static_cast<G4int>(2 * size * (sizeof(G4double))))
{
@@ -295,7 +295,7 @@ void G4PhysicsVector::ComputeSecDerivative1()
// World Scientific, 2000
{
std::size_t n = numberOfNodes - 1;
G4double* u = new G4double[n];
auto u = new G4double[n];
G4double p, sig;
u[1] = ((dataVector[2] - dataVector[1]) / (binVector[2] - binVector[1]) -
@@ -362,7 +362,7 @@ void G4PhysicsVector::ComputeSecDerivative2(G4double firstPointDerivative,
// Cambridge University Press, 1997.
{
std::size_t n = numberOfNodes - 1;
G4double* u = new G4double[n];
auto u = new G4double[n];
G4double p, sig, un;
u[0] = (6.0 / (binVector[1] - binVector[0])) *
+3 -3
View File
@@ -92,7 +92,7 @@ G4Pow::G4Pow()
for(G4int i = 1; i < maxZ; ++i)
{
G4double x = G4double(i);
auto x = G4double(i);
pz13[i] = std::pow(x, onethird);
lz[i] = G4Log(x);
if(i < maxZfact)
@@ -132,7 +132,7 @@ G4double G4Pow::A13High(const G4double a, const bool invert) const
G4double res;
if(a < maxA)
{
const G4int i = static_cast<G4int>(a + 0.5);
const auto i = static_cast<G4int>(a + 0.5);
const G4double x = (a / i - 1.) * onethird;
res = pz13[i] * (1. + x - x * x * (1. - 1.666667 * x));
}
@@ -149,7 +149,7 @@ G4double G4Pow::A13High(const G4double a, const bool invert) const
G4double G4Pow::A13Low(const G4double a, const G4bool invert) const
{
G4double res;
const G4int i = static_cast<G4int>(4. * (a + 0.125));
const auto i = static_cast<G4int>(4. * (a + 0.125));
const G4double y = 0.25 * i;
const G4double x = (a / y - 1.) * onethird;
res = lowa13[i] * (1. + x - x * x * (1. - 1.666667 * x));
@@ -43,11 +43,10 @@ namespace G4coutFormatters
G4String::size_type prev_pos = 0, pos = 0;
while((pos = input.find(separator, pos)) != G4String::npos)
{
G4String substr(input.substr(prev_pos, pos - prev_pos));
output.push_back(substr);
// TBR: shouldn't be worse than push_back+move
output.emplace_back(input.substr(prev_pos, pos - prev_pos));
prev_pos = ++pos;
}
// output.push_back( input.substr(prev_pos,pos-prev_pos));
return output;
}
+42 -15
View File
@@ -52,12 +52,6 @@ class G4strstreambuf : public std::basic_streambuf<char>
~G4strstreambuf() override
{
// flushing buffer...
// std::cout is used because destination object may not be alive.
if (count != 0) {
buffer[count] = '\0';
std::cout << buffer;
}
delete[] buffer;
}
@@ -219,6 +213,11 @@ void G4iosInitialization()
void G4iosFinalization()
{
// Reverse order
// --- Flush
_G4debug_p()->flush();
_G4cout_p()->flush();
_G4cerr_p()->flush();
// --- Streams
delete _G4debug_p();
_G4debug_p() = &std::cout;
@@ -240,17 +239,41 @@ void G4iosFinalization()
# define G4coutbuf (*_G4coutbuf_p())
# define G4cerrbuf (*_G4cerrbuf_p())
// These two functions are guaranteed to be called at load and
// unload of the library containing this code.
// We want to trigger initialization at load time and
// finalization at unloading time. Directly manipulating
// the `.init/.fini` section using the `__attribute__((constructor))`
// (beside that it does not work on Windows) does not work
// where Geant4 is built with static libraries but a downstream
// package is built with shared library and has also executable
// that are linking against those shared library and directly
// to the Geant4 static libraries (for example if the executable
// code calls Geant4 directly in addition to indirectly through
// the shared library).
// In this example, the explicit `.init/.fini` manipulations are
// added twice (because the linker is asked to link with this .o
// file twice and each time needs to add the init and finalization)
// This issue appear also for the initialization on an file static
// including those declared as function static in anonymous namespace.
// To get the behavior we need (where the G4iosFinalization
// and G4iosFinalization are called exactly once), we need to
// associate the initialization with a symbol and/or mechanism that
// the linker is told to de-duplicate even in the example described
// above. So we use an extern object that is guaranteed to be only
// initialized once.
namespace
{
# ifndef WIN32
void setupG4ioSystem() __attribute__((constructor));
void cleanupG4ioSystem() __attribute__((destructor));
# endif
void setupG4ioSystem() { G4iosInitialization(); }
void cleanupG4ioSystem() { G4iosFinalization(); }
struct RAII_G4iosSystem {
RAII_G4iosSystem() {
G4iosInitialization();
}
~RAII_G4iosSystem() {
G4iosFinalization();
}
};
} // namespace
// Extern but not user reachable (anonymous type)
// We want the linker to only create one of those.
extern "C" RAII_G4iosSystem RAII_G4iosSystemObj;
#else // Sequential
@@ -263,7 +286,11 @@ std::ostream G4cout(&G4coutbuf);
std::ostream G4cerr(&G4cerrbuf);
void G4iosInitialization() {}
void G4iosFinalization() {}
void G4iosFinalization() {
G4debug.flush();
G4cout.flush();
G4cerr.flush();
}
#endif