EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JsonMaterialWriter.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file JsonMaterialWriter.cpp
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 
10 
13 
14 #include <fstream>
15 #include <ios>
16 #include <iostream>
17 #include <stdexcept>
18 
20  const Acts::JsonGeometryConverter::Config& cfg, const std::string& fileName)
21  : m_cfg(cfg), m_fileName(fileName) {
22  // Validate the configuration
23  if (m_cfg.name.empty()) {
24  throw std::invalid_argument("Missing service name");
25  }
26 }
27 
29 
31  const Acts::DetectorMaterialMaps& detMaterial) {
32  // Evoke the converter
33  Acts::JsonGeometryConverter jmConverter(m_cfg);
34  auto jout = jmConverter.materialMapsToJson(detMaterial);
35  // And write the file
36  std::ofstream ofj(m_fileName);
37  ofj << std::setw(4) << jout << std::endl;
38 }
39 
42  // Evoke the converter
43  Acts::JsonGeometryConverter jmConverter(m_cfg);
44  auto jout = jmConverter.trackingGeometryToJson(tGeometry);
45  // And write the file
46  std::ofstream ofj(m_fileName);
47  ofj << std::setw(4) << jout << std::endl;
48 }