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 
17 
18 #include <fstream>
19 #include <map>
20 #include <mutex>
21 
22 // Convenience shorthand
23 
24 namespace Acts {
25 
31  public:
32  using SurfaceMaterialMap =
33  std::map<GeometryIdentifier, std::shared_ptr<const ISurfaceMaterial>>;
34 
35  using VolumeMaterialMap =
36  std::map<GeometryIdentifier, 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 jmConverter(rConfig);
47 
48  std::ifstream ifj(jFileName.c_str());
49  nlohmann::json jin;
50  ifj >> jin;
51 
52  auto maps = jmConverter.jsonToMaterialMaps(jin);
53  m_surfaceMaterialMap = maps.first;
54  m_volumeMaterialMap = maps.second;
55  }
56 
60  void decorate(Surface& surface) const final {
61  // Clear the material if registered to do so
63  surface.assignSurfaceMaterial(nullptr);
64  }
65  // Try to find the surface in the map
66  auto sMaterial = m_surfaceMaterialMap.find(surface.geometryId());
67  if (sMaterial != m_surfaceMaterialMap.end()) {
68  surface.assignSurfaceMaterial(sMaterial->second);
69  }
70  }
71 
75  void decorate(TrackingVolume& volume) const final {
76  // Clear the material if registered to do so
78  volume.assignVolumeMaterial(nullptr);
79  }
80  // Try to find the volume in the map
81  auto vMaterial = m_volumeMaterialMap.find(volume.geometryId());
82  if (vMaterial != m_volumeMaterialMap.end()) {
83  volume.assignVolumeMaterial(vMaterial->second);
84  }
85  }
86 
87  private:
91 
94 };
95 } // namespace Acts