Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 07:47:28

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Geometry/GeometryModuleLoader.hpp"
0010 
0011 #ifdef ACTS_HAVE_DD4HEP
0012 #include "ActsPlugins/DD4hep/GeometryModuleLoader.hpp"
0013 
0014 #include <DD4hep/Detector.h>
0015 #endif
0016 
0017 #include <cstdlib>
0018 #include <iostream>
0019 #include <string>
0020 
0021 #include <boost/program_options.hpp>
0022 
0023 namespace po = boost::program_options;
0024 
0025 int main(int argc, char* argv[]) {
0026   std::string modulePath;
0027 #ifdef ACTS_HAVE_DD4HEP
0028   std::string dd4hepXml;
0029 #endif
0030 
0031   po::options_description desc("Options");
0032   // clang-format off
0033   desc.add_options()
0034     ("help,h", "Show help")
0035     ("module", po::value<std::string>(&modulePath)->required(),
0036      "Path to geometry module shared library")
0037 #ifdef ACTS_HAVE_DD4HEP
0038     ("dd4hep", po::value<std::string>(&dd4hepXml),
0039      "Path to DD4hep compact XML file; activates DD4hep detector loading")
0040 #endif
0041     ;
0042   // clang-format on
0043 
0044   po::positional_options_description pos;
0045   pos.add("module", 1);
0046 
0047   po::variables_map vm;
0048   try {
0049     po::store(
0050         po::command_line_parser(argc, argv).options(desc).positional(pos).run(),
0051         vm);
0052     if (vm.count("help") != 0u) {
0053       std::cout << desc << std::endl;
0054       return EXIT_SUCCESS;
0055     }
0056     po::notify(vm);
0057   } catch (const po::error& e) {
0058     std::cerr << "Error: " << e.what() << "\n" << desc << std::endl;
0059     return EXIT_FAILURE;
0060   }
0061 
0062   try {
0063     auto logger =
0064         Acts::getDefaultLogger("LoadGeometryModule", Acts::Logging::VERBOSE);
0065 
0066     std::shared_ptr<Acts::TrackingGeometry> trackingGeometry;
0067 
0068 #ifdef ACTS_HAVE_DD4HEP
0069     if (vm.count("dd4hep") != 0u) {
0070       auto detector = dd4hep::Detector::make_unique("LoadGeometryModule");
0071       detector->fromCompact(dd4hepXml);
0072       detector->volumeManager();
0073       detector->apply("DD4hepVolumeManager", 0, nullptr);
0074       trackingGeometry =
0075           Acts::loadDD4hepGeometryModule(modulePath, *detector, *logger);
0076     } else
0077 #endif
0078     {
0079       trackingGeometry = Acts::loadGeometryModule(modulePath, *logger);
0080     }
0081 
0082     std::cout << "Geometry module loaded successfully" << std::endl;
0083     if (!trackingGeometry) {
0084       std::cerr << "Geometry module returned an invalid handle" << std::endl;
0085       return EXIT_FAILURE;
0086     }
0087   } catch (const std::exception& e) {
0088     std::cerr << "Unexpected failure while loading geometry module: "
0089               << e.what() << std::endl;
0090     return EXIT_FAILURE;
0091   }
0092 
0093   return EXIT_SUCCESS;
0094 }