ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JsonMaterialDecorator.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file JsonMaterialDecorator.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
11 #include <fstream>
12 #include <map>
13 #include <mutex>
14 
21 
22 // Convenience shorthand
23 
24 namespace Acts {
25 
31  public:
32  using SurfaceMaterialMap =
33  std::map<GeometryID, std::shared_ptr<const ISurfaceMaterial>>;
34 
35  using VolumeMaterialMap =
36  std::map<GeometryID, std::shared_ptr<const IVolumeMaterial>>;
37 
39  const std::string& jFileName,
40  bool clearSurfaceMaterial = true,
41  bool clearVolumeMaterial = true)
42  : m_readerConfig(rConfig),
43  m_clearSurfaceMaterial(clearSurfaceMaterial),
44  m_clearVolumeMaterial(clearVolumeMaterial) {
45  // the material reader
46  Acts::JsonGeometryConverter::Config jmConverterCfg("JsonGeometryConverter",
48  Acts::JsonGeometryConverter jmConverter(jmConverterCfg);
49 
50  std::ifstream ifj(jFileName.c_str());
51  nlohmann::json jin;
52  ifj >> jin;
53 
54  auto maps = jmConverter.jsonToMaterialMaps(jin);
55  m_surfaceMaterialMap = maps.first;
56  m_volumeMaterialMap = maps.second;
57  }
58 
62  void decorate(Surface& surface) const final {
63  // Clear the material if registered to do so
65  surface.assignSurfaceMaterial(nullptr);
66  }
67  // Try to find the surface in the map
68  auto sMaterial = m_surfaceMaterialMap.find(surface.geoID());
69  if (sMaterial != m_surfaceMaterialMap.end()) {
70  surface.assignSurfaceMaterial(sMaterial->second);
71  }
72  }
73 
77  void decorate(TrackingVolume& volume) const final {
78  // Clear the material if registered to do so
80  volume.assignVolumeMaterial(nullptr);
81  }
82  // Try to find the volume in the map
83  auto vMaterial = m_volumeMaterialMap.find(volume.geoID());
84  if (vMaterial != m_volumeMaterialMap.end()) {
85  volume.assignVolumeMaterial(vMaterial->second);
86  }
87  }
88 
89  private:
93 
96 };
97 } // namespace Acts