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 <map>
22 
23 #include <nlohmann/json.hpp>
24 
25 namespace Acts {
26 
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 
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 transfokeys = "tranformation";
122  std::string typekey = "type";
124  std::string datakey = "data";
126  std::string geometryidkey = "Geoid";
128  std::string surfacegeometryidkey = "SGeoid";
130  std::string mapkey = "mapMaterial";
132  std::string surfacetypekey = "stype";
134  std::string surfacepositionkey = "sposition";
136  std::string surfacerangekey = "srange";
138  std::shared_ptr<const Logger> logger;
140  std::string name = "";
141 
143  bool processSensitives = true;
145  bool processApproaches = true;
147  bool processRepresenting = true;
149  bool processBoundaries = true;
151  bool processVolumes = true;
153  bool processDenseVolumes = false;
155  bool processnonmaterial = false;
157  bool writeData = true;
158 
163  Config(const std::string& lname = "JsonGeometryConverter",
165  : logger(getDefaultLogger(lname, lvl)), name(lname) {}
166  };
167 
171  JsonGeometryConverter(const Config& cfg);
172 
174  ~JsonGeometryConverter() = default;
175 
179  std::pair<
180  std::map<GeometryIdentifier, std::shared_ptr<const ISurfaceMaterial>>,
181  std::map<GeometryIdentifier, std::shared_ptr<const IVolumeMaterial>>>
182  jsonToMaterialMaps(const nlohmann::json& materialmaps);
183 
188 
193 
194  private:
198  void convertToRep(DetectorRep& detRep, const TrackingVolume& tVolume);
199 
203  LayerRep convertToRep(const Layer& tLayer);
204 
209 
214 
219 
222 
225 
227  nlohmann::json detectorRepToJson(const DetectorRep& detRep);
228 
233 
238 
242  void addSurfaceToJson(nlohmann::json& sjson, const Surface* surface);
243 
248 
253 
256 
258  const Logger& logger() const { return *m_cfg.logger; }
259 };
260 
261 } // namespace Acts