File indexing completed on 2026-09-19 08:29:42
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsPlugins/Json/JsonMaterialDecorator.hpp"
0010
0011 namespace Acts {
0012
0013 JsonMaterialDecorator::JsonMaterialDecorator(
0014 const MaterialMapJsonConverter::Config& rConfig,
0015 const std::string& jFileName, Acts::Logging::Level level)
0016 : m_readerConfig(rConfig),
0017 m_logger{getDefaultLogger("JsonMaterialDecorator", level)} {
0018
0019 Acts::MaterialMapJsonConverter jmConverter(rConfig, level);
0020
0021 ACTS_VERBOSE("Reading JSON material description from: " << jFileName);
0022 std::ifstream ifj(jFileName.c_str());
0023 if (!ifj.good()) {
0024 throw std::runtime_error{"Unable to open input JSON material file: " +
0025 jFileName};
0026 }
0027 nlohmann::json jin;
0028
0029 if (jFileName.find(".cbor") != std::string::npos) {
0030 std::vector<std::uint8_t> iCbor((std::istreambuf_iterator<char>(ifj)),
0031 std::istreambuf_iterator<char>());
0032 jin = nlohmann::json::from_cbor(iCbor);
0033 } else {
0034 ifj >> jin;
0035 }
0036
0037 auto maps = jmConverter.jsonToMaterialMaps(jin);
0038 m_surfaceMaterialMap = maps.first;
0039 m_volumeMaterialMap = maps.second;
0040 ACTS_VERBOSE("JSON material description read complete");
0041 }
0042
0043 void JsonMaterialDecorator::decorate(Surface& surface) const {
0044 ACTS_VERBOSE("Processing surface: " << surface.geometryId());
0045
0046 auto sMaterial = m_surfaceMaterialMap.find(surface.geometryId());
0047 if (sMaterial != m_surfaceMaterialMap.end()) {
0048 ACTS_VERBOSE("-> Found material for surface, assigning");
0049 surface.assignSurfaceMaterial(sMaterial->second);
0050 }
0051 }
0052
0053
0054
0055
0056 void JsonMaterialDecorator::decorate(TrackingVolume& volume) const {
0057 ACTS_VERBOSE("Processing volume: " << volume.geometryId());
0058
0059
0060 auto vMaterial = m_volumeMaterialMap.find(volume.geometryId());
0061 if (vMaterial != m_volumeMaterialMap.end()) {
0062 ACTS_VERBOSE("-> Found material for volume, assigning");
0063 volume.assignVolumeMaterial(vMaterial->second);
0064 }
0065 }
0066 }