Back to home page

EIC code displayed by LXR

 
 

    


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

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/io/read_magnetic_field.hpp"
0010 
0011 #include "traccc/io/utils.hpp"
0012 
0013 // Project include(s).
0014 #include "traccc/bfield/magnetic_field_types.hpp"
0015 
0016 // System include(s).
0017 #include <format>
0018 #include <fstream>
0019 #include <stdexcept>
0020 
0021 namespace traccc::io {
0022 namespace binary {
0023 
0024 void read_magnetic_field(magnetic_field& bfield, std::string_view filename,
0025                          std::unique_ptr<const Logger> ilogger) {
0026   // Set up a local logger.
0027   TRACCC_LOCAL_LOGGER(std::move(ilogger));
0028 
0029   // Open the file.
0030   std::ifstream ifile{get_absolute_path(filename),
0031                       std::ios::binary | std::ios::in};
0032   if (!ifile.is_open()) {
0033     throw std::invalid_argument(
0034         std::format("Failed to open magnetic field file: {}", filename));
0035   }
0036 
0037   // Construct/fill the magnetic field from the file.
0038   TRACCC_INFO("Reading magnetic field from file: " << filename);
0039   bfield.set(covfie::field<host::inhom_bfield_backend_t<traccc::scalar>>(
0040       covfie::field<host::inhom_io_bfield_backend_t<traccc::scalar>>(ifile)));
0041 }
0042 
0043 }  // namespace binary
0044 
0045 void read_magnetic_field(magnetic_field& bfield, std::string_view filename,
0046                          data_format format,
0047                          std::unique_ptr<const Logger> ilogger) {
0048   switch (format) {
0049     case data_format::binary:
0050       binary::read_magnetic_field(bfield, filename, std::move(ilogger));
0051       break;
0052     default:
0053       throw std::invalid_argument("Unsupported data format");
0054   }
0055 }
0056 
0057 }  // namespace traccc::io