diff --git a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/variantHelpers.h b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/variantHelpers.h index ec6702d989cf90a3375aa5564273617151943619..d0808cbbadd1e103d79b9e79784ee50c8911d79d 100644 --- a/GeoModelCore/GeoModelHelpers/GeoModelHelpers/variantHelpers.h +++ b/GeoModelCore/GeoModelHelpers/GeoModelHelpers/variantHelpers.h @@ -1,4 +1,4 @@ -// Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration /* * This header file provides helper C++ functions used in GeoModel IO code. @@ -23,12 +23,10 @@ namespace GeoModelHelpers { - class variantHelper - { + class variantHelper { public: - - static void printStdVectorVariants(const std::vector<std::variant<int, long, float, double, std::string>> vec) - { + using VariantType_t = std::variant<int, long, float, double, std::string>; + static void printStdVectorVariants(const std::vector<VariantType_t>& vec) { for (const auto &item : vec) { if (std::holds_alternative<int>(item)) @@ -47,71 +45,57 @@ namespace GeoModelHelpers { std::cout << std::endl; } - static std::string getFromVariant_String(const std::variant<int, long, float, double, std::string> &record, std::string_view logMsg = "") - { - std::string_view type{"string"}; + static std::string getFromVariant_String(const VariantType_t &record, std::string_view logMsg = "") { + constexpr std::string_view type{"string"}; std::string ret; - try - { + try { ret = std::get<std::string>(record); - } - catch (std::bad_variant_access const &ex) - { - THROW_EXCEPTION(std::string(ex.what()) + ": '" + std::string(logMsg) + "' is not a '" + std::string(type) + "'! It's a '" + getFromVariant_Type(record) + "'."); + } catch (std::bad_variant_access const &ex){ + THROW_EXCEPTION(ex.what()<<": '"<<logMsg<<"' is not a '"<<type<<"'! It's a '" + <<getFromVariant_Type(record)<<"'."); } return ret; } - static int getFromVariant_Int(const std::variant<int, long, float, double, std::string> &record, std::string_view logMsg = "") - { + static int getFromVariant_Int(const VariantType_t &record, std::string_view logMsg = "") { std::string_view type{"int"}; - int ret; + int ret{0}; - try - { + try { ret = std::get<int>(record); } - catch (std::bad_variant_access const &ex) - { - THROW_EXCEPTION(std::string(ex.what()) + ": '" + std::string(logMsg) + "' is not a '" + std::string(type) + "'! It's a '" + getFromVariant_Type(record) + "'."); - + catch (std::bad_variant_access const &ex) { + THROW_EXCEPTION(ex.what()<<": '"<<logMsg<<"' is not a '"<<type<<"'! It's a '" + <<getFromVariant_Type(record)<<"'."); } return ret; } - static double getFromVariant_Double(const std::variant<int, long, float, double, std::string> &record, std::string_view logMsg = "") - { - std::string_view type{"double"}; - double ret; - try - { + static double getFromVariant_Double(const VariantType_t &record, std::string_view logMsg = "") { + constexpr std::string_view type{"double"}; + double ret{0.}; + try { ret = std::get<double>(record); } - catch (std::bad_variant_access const &ex) - { - THROW_EXCEPTION(std::string(ex.what()) + ": '" + std::string(logMsg) + "' is not a '" + std::string(type) + "'! It's a '" + getFromVariant_Type(record) + "'."); + catch (std::bad_variant_access const &ex) { + THROW_EXCEPTION(ex.what()<<": '"<<logMsg<<"' is not a '"<<type<<"'! It's a '" + <<getFromVariant_Type(record)<<"'."); } return ret; } - static std::string getFromVariant_Type(const std::variant<int, long, float, double, std::string> &record) - { + static std::string getFromVariant_Type(const VariantType_t &record) { std::string type; - if (std::holds_alternative<int>(record)) - { + if (std::holds_alternative<int>(record)) { type = "int"; } - else if (std::holds_alternative<long>(record)) - { + else if (std::holds_alternative<long>(record)) { type = "long"; } - else if (std::holds_alternative<float>(record)) - { + else if (std::holds_alternative<float>(record)) { type = "float"; } - else if (std::holds_alternative<double>(record)) - { + else if (std::holds_alternative<double>(record)){ type = "double"; } - else if (std::holds_alternative<std::string>(record)) - { + else if (std::holds_alternative<std::string>(record)) { type = "string"; } else { type = "UNKOWN"; diff --git a/GeoModelCore/GeoModelHelpers/src/defineWorld.cxx b/GeoModelCore/GeoModelHelpers/src/defineWorld.cxx index 2dcff72d1690e5c67dafe31725c7c706174eaa63..8d6d137ba22bd16f709902117fc0572f786adbfe 100644 --- a/GeoModelCore/GeoModelHelpers/src/defineWorld.cxx +++ b/GeoModelCore/GeoModelHelpers/src/defineWorld.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelHelpers/defineWorld.h" #include "GeoModelHelpers/cloneVolume.h" @@ -8,8 +8,6 @@ #include "GeoModelKernel/GeoBox.h" #include "GeoModelKernel/GeoPhysVol.h" #include "GeoModelKernel/GeoFullPhysVol.h" -#include "GeoModelKernel/GeoVolumeCursor.h" -#include "GeoModelKernel/GeoAlignableTransform.h" #include "GeoModelKernel/Units.h" GeoIntrusivePtr<GeoPhysVol> createGeoWorld(const double worldBoxX, @@ -22,13 +20,13 @@ GeoIntrusivePtr<GeoPhysVol> createGeoWorld(const double worldBoxX, constexpr double cm3 = GeoModelKernelUnits::cm3; // Define the chemical elements - GeoIntrusivePtr<GeoElement> Nitrogen{new GeoElement ("Nitrogen" ,"N" , 7.0 , 14.0031 *gr/mole)}; - GeoIntrusivePtr<GeoElement> Oxygen{new GeoElement ("Oxygen" ,"O" , 8.0 , 15.9949 *gr/mole)}; - GeoIntrusivePtr<GeoElement> Argon{new GeoElement ("Argon" ,"Ar" , 18.0 , 39.9624 *gr/mole)}; - GeoIntrusivePtr<GeoElement> Hydrogen{new GeoElement ("Hydrogen" ,"H" , 1.0 , 1.00782503081372 *gr/mole)}; + GeoIntrusivePtr<GeoElement> Nitrogen{make_intrusive<GeoElement>("Nitrogen" ,"N" , 7.0 , 14.0031 *gr/mole)}; + GeoIntrusivePtr<GeoElement> Oxygen{make_intrusive<GeoElement>("Oxygen" ,"O" , 8.0 , 15.9949 *gr/mole)}; + GeoIntrusivePtr<GeoElement> Argon{make_intrusive<GeoElement>("Argon" ,"Ar" , 18.0 , 39.9624 *gr/mole)}; + GeoIntrusivePtr<GeoElement> Hydrogen{make_intrusive<GeoElement>("Hydrogen" ,"H" , 1.0 , 1.00782503081372 *gr/mole)}; constexpr double densityOfAir=0.001290 *gr/cm3; - GeoIntrusivePtr<GeoMaterial> air{new GeoMaterial("GeoModelAir", densityOfAir)}; + GeoIntrusivePtr<GeoMaterial> air{make_intrusive<GeoMaterial>("GeoModelAir", densityOfAir)}; air->add(Nitrogen , 0.7494); air->add(Oxygen, 0.2369); air->add(Argon, 0.0129); @@ -36,9 +34,9 @@ GeoIntrusivePtr<GeoPhysVol> createGeoWorld(const double worldBoxX, air->lock(); - GeoIntrusivePtr<GeoBox> worldBox{new GeoBox(worldBoxX, worldBoxY, worldBoxZ)}; - GeoIntrusivePtr<GeoLogVol> worldLog{new GeoLogVol("WorldLog", worldBox, air)}; - GeoIntrusivePtr<GeoPhysVol> world{new GeoPhysVol(worldLog)}; + GeoIntrusivePtr<GeoBox> worldBox{make_intrusive<GeoBox>(worldBoxX, worldBoxY, worldBoxZ)}; + GeoIntrusivePtr<GeoLogVol> worldLog{make_intrusive<GeoLogVol>("WorldLog", worldBox, air)}; + GeoIntrusivePtr<GeoPhysVol> world{make_intrusive<GeoPhysVol>(worldLog)}; return world; } diff --git a/GeoModelTools/GMSTATISTICS/src/gmstatistics.cxx b/GeoModelTools/GMSTATISTICS/src/gmstatistics.cxx index 1dac430b430e20c120e94b65fe48c16bec16d4b6..dbafd01bd5e0806636a16d1902847fcba8c2e197 100644 --- a/GeoModelTools/GMSTATISTICS/src/gmstatistics.cxx +++ b/GeoModelTools/GMSTATISTICS/src/gmstatistics.cxx @@ -146,28 +146,28 @@ int main(int argc, char ** argv) { GeoGeometryPluginLoader loader; GeoVGeometryPlugin *factory=loader.load(plugin); if (!factory) { - std::cerr << "Could not load plugin " << plugin << std::endl; - std::cout.rdbuf(coutBuff); - return 5; + std::cerr << "Could not load plugin " << plugin << std::endl; + std::cout.rdbuf(coutBuff); + return 5; } unsigned int expand{0}; unsigned int net{0}; { - GeoIntrusivePtr<GeoVPhysVol> world{createGeoWorld()}; + GeoIntrusivePtr<GeoVPhysVol> world{createGeoWorld()}; - int before=snoop(); - factory->create(world); - net=snoop()-before; - std::cout.rdbuf(coutBuff); + int before=snoop(); + factory->create(world); + net=snoop()-before; + std::cout.rdbuf(coutBuff); - if (printTree) { - GeoInventoryGraphAction action(std::cout); - world->exec(&action); - } - expand=heapsize(); + if (printTree) { + GeoInventoryGraphAction action(std::cout); + world->exec(&action); + } + expand=heapsize(); } unsigned int contract=expand-heapsize(); - std::cout << basename((char *) plugin.c_str()) << " allocates " << net/factor << " MB" << " net GeoModel " << contract/1000000.0 << " MB" << std::endl; + std::cout <<factory->getName() << " allocates " << net/factor << " MB" << " net GeoModel " << contract/1000000.0 << " MB" << std::endl; delete factory; std::cout.rdbuf(fileBuff); }