File indexing completed on 2025-01-30 09:15:17
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Plugins/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 bool clearSurfaceMaterial, bool clearVolumeMaterial)
0017 : m_readerConfig(rConfig),
0018 m_clearSurfaceMaterial(clearSurfaceMaterial),
0019 m_clearVolumeMaterial(clearVolumeMaterial),
0020 m_logger{getDefaultLogger("JsonMaterialDecorator", level)} {
0021
0022 Acts::MaterialMapJsonConverter jmConverter(rConfig, level);
0023
0024 ACTS_VERBOSE("Reading JSON material description from: " << jFileName);
0025 std::ifstream ifj(jFileName.c_str());
0026 if (!ifj.good()) {
0027 throw std::runtime_error{"Unable to open input JSON material file: " +
0028 jFileName};
0029 }
0030 nlohmann::json jin;
0031
0032 if (jFileName.find(".cbor") != std::string::npos) {
0033 std::vector<std::uint8_t> iCbor((std::istreambuf_iterator<char>(ifj)),
0034 std::istreambuf_iterator<char>());
0035 jin = nlohmann::json::from_cbor(iCbor);
0036 } else {
0037 ifj >> jin;
0038 }
0039
0040 auto maps = jmConverter.jsonToMaterialMaps(jin);
0041 m_surfaceMaterialMap = maps.first;
0042 m_volumeMaterialMap = maps.second;
0043 ACTS_VERBOSE("JSON material description read complete");
0044 }
0045
0046 void JsonMaterialDecorator::decorate(Surface& surface) const {
0047 ACTS_VERBOSE("Processing surface: " << surface.geometryId());
0048
0049 if (m_clearSurfaceMaterial) {
0050 ACTS_VERBOSE("-> Clearing surface material");
0051 surface.assignSurfaceMaterial(nullptr);
0052 }
0053
0054 auto sMaterial = m_surfaceMaterialMap.find(surface.geometryId());
0055 if (sMaterial != m_surfaceMaterialMap.end()) {
0056 ACTS_VERBOSE("-> Found material for surface, assigning");
0057 surface.assignSurfaceMaterial(sMaterial->second);
0058 }
0059 }
0060
0061
0062
0063
0064 void JsonMaterialDecorator::decorate(TrackingVolume& volume) const {
0065 ACTS_VERBOSE("Processing volume: " << volume.geometryId());
0066
0067 if (m_clearVolumeMaterial) {
0068 ACTS_VERBOSE("-> Clearing volume material");
0069 volume.assignVolumeMaterial(nullptr);
0070 }
0071
0072 auto vMaterial = m_volumeMaterialMap.find(volume.geometryId());
0073 if (vMaterial != m_volumeMaterialMap.end()) {
0074 ACTS_VERBOSE("-> Found material for volume, assigning");
0075 volume.assignVolumeMaterial(vMaterial->second);
0076 }
0077 }
0078 }