ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JsonGeometryConverter.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file JsonGeometryConverter.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 
20 
21 #include <nlohmann/json.hpp>
22 
23 #include <map>
24 
25 namespace Acts {
26 
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 
38  using DetectorMaterialMaps = std::pair<SurfaceMaterialMap, VolumeMaterialMap>;
39 
40  using geo_id_value = uint64_t;
41 
42  using SurfaceMaterialRep = std::map<geo_id_value, const ISurfaceMaterial*>;
43  using SurfaceRep = std::map<geo_id_value, const Surface*>;
44  using VolumeMaterialRep = std::map<geo_id_value, const IVolumeMaterial*>;
45 
47  struct LayerRep {
48  // the layer id
50 
55  const ISurfaceMaterial* representing = nullptr;
56  const Surface* representingSurface = nullptr;
57 
59  operator bool() const {
60  return (!sensitives.empty() or !approaches.empty() or
61  representing != nullptr);
62  }
63  };
64 
66  struct VolumeRep {
67  // The geometry id
69 
71  std::string volumeName;
72 
73  std::map<geo_id_value, LayerRep> layers;
76  const IVolumeMaterial* material = nullptr;
77 
79  operator bool() const {
80  return (!layers.empty() or !boundaries.empty() or material != nullptr);
81  }
82  };
83 
85  struct DetectorRep {
86  std::map<geo_id_value, VolumeRep> volumes;
87  };
88 
91  class Config {
92  public:
94  std::string geoversion = "undefined";
96  std::string detkey = "detector";
98  std::string volkey = "volumes";
100  std::string namekey = "Name";
102  std::string boukey = "boundaries";
104  std::string laykey = "layers";
106  std::string matkey = "material";
108  std::string appkey = "approach";
110  std::string senkey = "sensitive";
112  std::string repkey = "representing";
114  std::string bin0key = "bin0";
116  std::string bin1key = "bin1";
118  std::string bin2key = "bin2";
120  std::string typekey = "type";
122  std::string datakey = "data";
124  std::string geoidkey = "Geoid";
126  std::string surfacegeoidkey = "SGeoid";
128  std::string mapkey = "matSurface";
130  std::string surfacetypekey = "stype";
132  std::string surfacepositionkey = "sposition";
134  std::string surfacerangekey = "srange";
136  std::shared_ptr<const Logger> logger;
138  std::string name = "";
139 
141  bool processSensitives = true;
143  bool processApproaches = true;
145  bool processRepresenting = true;
147  bool processBoundaries = true;
149  bool processVolumes = true;
151  bool processnonmaterial = false;
153  bool writeData = true;
154 
159  Config(const std::string& lname = "JsonGeometryConverter",
161  : logger(getDefaultLogger(lname, lvl)), name(lname) {}
162  };
163 
167  JsonGeometryConverter(const Config& cfg);
168 
170  ~JsonGeometryConverter() = default;
171 
175  std::pair<std::map<GeometryID, std::shared_ptr<const ISurfaceMaterial>>,
176  std::map<GeometryID, std::shared_ptr<const IVolumeMaterial>>>
177  jsonToMaterialMaps(const nlohmann::json& materialmaps);
178 
183 
188 
189  private:
193  void convertToRep(DetectorRep& detRep, const TrackingVolume& tVolume);
194 
198  LayerRep convertToRep(const Layer& tLayer);
199 
204 
209 
214 
217 
219  nlohmann::json detectorRepToJson(const DetectorRep& detRep);
220 
225 
230 
234  void addSurfaceToJson(nlohmann::json& sjson, const Surface* surface);
235 
240 
245 
248 
250  const Logger& logger() const { return *m_cfg.logger; }
251 };
252 
253 } // namespace Acts