Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:22:13

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2025 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 // Local include(s).
0009 #include "traccc/options/magnetic_field.hpp"
0010 
0011 // Project include(s).
0012 #include "traccc/examples/utils/printable.hpp"
0013 
0014 // System include(s).
0015 #include <format>
0016 #include <sstream>
0017 #include <stdexcept>
0018 
0019 namespace traccc::opts {
0020 
0021 /// Helper namespace for convenience
0022 namespace po = boost::program_options;
0023 
0024 /// Type alias for the data format enumeration
0025 using format_type = std::string;
0026 /// Name of the data format option
0027 static const char* format_option = "bfield-file-format";
0028 
0029 magnetic_field::magnetic_field() : interface("Magnetic Field Options") {
0030   m_desc.add_options()("read-bfield-from-file",
0031                        po::bool_switch(&read_from_file),
0032                        "Read the magnetic field from a file");
0033   m_desc.add_options()("bfield-file", po::value(&file)->default_value(file),
0034                        "Magnetic field file");
0035   m_desc.add_options()(format_option,
0036                        po::value<format_type>()->default_value("binary"),
0037                        "Format of the magnetic field file");
0038   m_desc.add_options()("bfield-value", po::value(&value)->default_value(value),
0039                        "Magnetic field value (when not reading from a file)");
0040 }
0041 
0042 void magnetic_field::read(const po::variables_map& vm) {
0043   // Decode the magnetic field file data format.
0044   if (vm.count(format_option)) {
0045     const std::string format_string = vm[format_option].as<format_type>();
0046     if (format_string == "csv") {
0047       format = data_format::csv;
0048     } else if (format_string == "binary") {
0049       format = data_format::binary;
0050     } else {
0051       throw std::invalid_argument("Unknown magnetic field data format");
0052     }
0053   }
0054 }
0055 
0056 std::unique_ptr<configuration_printable> magnetic_field::as_printable() const {
0057   auto cat = std::make_unique<configuration_category>(m_description);
0058 
0059   cat->add_child(std::make_unique<configuration_kv_pair>(
0060       "Read magnetic field from file", std::format("{}", read_from_file)));
0061   cat->add_child(
0062       std::make_unique<configuration_kv_pair>("Magnetic field file", file));
0063   std::ostringstream format_ss;
0064   format_ss << format;
0065   cat->add_child(std::make_unique<configuration_kv_pair>(
0066       "Magnetic field file format", format_ss.str()));
0067   cat->add_child(std::make_unique<configuration_kv_pair>(
0068       "Magnetic field value", std::format("{} T", value / unit<float>::T)));
0069 
0070   return cat;
0071 }
0072 
0073 }  // namespace traccc::opts