SHiP Field Service
Framework-agnostic C++20 library exposing SHiP magnetic field maps.
Loading...
Searching...
No Matches
FieldMapIO.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 CERN for the benefit of the SHiP Collaboration
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4#pragma once
5
6// Reader and writer for the SHiP field-map format (docs/field_map_format.md),
7// a ROOT RNTuple named "field_maps" with one entry per map. Part of the MapIO
8// component (SHiP::FieldServiceMapIO), which depends on ROOT; the core
9// library does not.
10
13
14#include <array>
15#include <cstdint>
16#include <memory>
17#include <span>
18#include <string>
19#include <vector>
20
21namespace SHiP {
22
25inline constexpr std::uint16_t kFieldMapFormatMajor = 1;
26inline constexpr std::uint16_t kFieldMapFormatMinor = 0;
27
29inline constexpr char const* kFieldMapNTupleName = "field_maps";
30
35 unsigned truncated_bits = 0;
36};
37
40[[nodiscard]] std::vector<FieldMap> readFieldMaps(std::string const& path);
41
43[[nodiscard]] FieldMap readFieldMap(std::string const& path, std::string const& name);
44
49void writeFieldMaps(std::string const& path, std::span<FieldMap const> maps,
50 FieldMapWriteOptions const& options = {});
51
55[[nodiscard]] std::shared_ptr<IFieldEvaluator> loadFieldMap(std::string const& file,
56 std::string const& map);
57
59class FieldMapSource final : public IFieldSource {
60 public:
61 struct MagnetConfig {
62 std::string name;
63 std::string volume_pattern;
64 std::string file;
65 std::string map;
69 std::array<double, 3> translation{};
70 };
71
72 explicit FieldMapSource(std::vector<MagnetConfig> magnets);
73
74 [[nodiscard]] std::vector<FieldRegion> const& regions() const override { return regions_; }
75
76 private:
77 std::vector<FieldRegion> regions_;
78};
79
81inline constexpr int kPlacementsFormatVersion = 1;
82
86 std::string geometry_package;
87 std::string geometry_version;
90 std::vector<FieldMapSource::MagnetConfig> magnets;
91};
92
98[[nodiscard]] FieldMapPlacements readFieldMapPlacements(std::string const& path);
99
100} // namespace SHiP
IFieldSource with one evaluator per magnet, read from field-map files.
Definition FieldMapIO.h:59
std::vector< FieldRegion > const & regions() const override
Idempotent. Ownership of the evaluators stays with the source.
Definition FieldMapIO.h:74
Source of one or more named field regions.
Definition IFieldSource.h:51
Definition ActsFieldAdapter.h:25
void writeFieldMaps(std::string const &path, std::span< FieldMap const > maps, FieldMapWriteOptions const &options={})
Write maps to a new file at path, replacing any existing file.
Definition FieldMapIO.cpp:132
constexpr int kPlacementsFormatVersion
Placement manifest version this library reads (docs/placements_format.md).
Definition FieldMapIO.h:81
constexpr std::uint16_t kFieldMapFormatMinor
Definition FieldMapIO.h:26
constexpr std::uint16_t kFieldMapFormatMajor
Format version written by this library.
Definition FieldMapIO.h:25
std::shared_ptr< IFieldEvaluator > loadFieldMap(std::string const &file, std::string const &map)
Evaluator for map map in file.
Definition FieldMapIO.cpp:200
FieldMapPlacements readFieldMapPlacements(std::string const &path)
Read the placement manifest at path, resolved as in resolveFieldMapPath (so a bare "placements....
Definition FieldMapPlacements.cpp:107
FieldMap readFieldMap(std::string const &path, std::string const &name)
Read the map called name from path; throws if there is none.
Definition FieldMapIO.cpp:125
constexpr char const * kFieldMapNTupleName
Name of the RNTuple holding the maps.
Definition FieldMapIO.h:29
std::vector< FieldMap > readFieldMaps(std::string const &path)
Read every map in path.
Definition FieldMapIO.cpp:121
Contents of a placement manifest: where each magnet's map sits, and the geometry version those positi...
Definition FieldMapIO.h:85
std::vector< FieldMapSource::MagnetConfig > magnets
One entry per magnet, in manifest order.
Definition FieldMapIO.h:90
std::string geometry_version
Definition FieldMapIO.h:87
std::string geometry_package
Definition FieldMapIO.h:86
Definition FieldMapIO.h:61
std::string volume_pattern
Definition FieldMapIO.h:63
std::string file
Definition FieldMapIO.h:64
std::array< double, 3 > translation
Global position (mm) of the map's local origin.
Definition FieldMapIO.h:69
std::string map
Definition FieldMapIO.h:65
std::string name
Definition FieldMapIO.h:62
Definition FieldMapIO.h:31
unsigned truncated_bits
Store field values with only this many bits (10 to 31) of each float, dropping low mantissa bits,...
Definition FieldMapIO.h:35
One field map: grid, symmetry, and per-node field components in Tesla, stored in FieldMapGrid::index ...
Definition FieldMap.h:66