ATLAS Offline Software
Loading...
Searching...
No Matches
JsonMaterialWriterTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include "ActsPlugins/Json/MaterialMapJsonConverter.hpp"
8
9#include <fstream>
10#include <iomanip>
11#include <ios>
12#include <vector>
13
14#include <nlohmann/json.hpp>
15
17 const Acts::TrackingGeometryMaterial& detMaterial) const
18{
19 // Set up the Athena-backed Acts logger, and take its level for the converter
20 std::unique_ptr<const Acts::Logger> logger = makeActsAthenaLogger(this, "JsonMaterialWriterTool");
21
22 // Configure the Json converter
23 Acts::MaterialMapJsonConverter::Config converterCfg;
24 converterCfg.context = gctx.context();
25
26 Acts::MaterialMapJsonConverter converter(converterCfg, logger->level());
27
28 // Convert the surface and volume material maps to Json
29 nlohmann::json jOut = converter.materialMapsToJson(detMaterial);
30
31 if (m_writeJson.value()) {
32 const std::string fileName = m_fileName.value() + ".json";
33 ATH_MSG_INFO("Writing Json material map to '" << fileName << "'");
34 std::ofstream ofj(fileName);
35 ofj << std::setw(4) << jOut << std::endl;
36 }
37
38 if (m_writeCbor.value()) {
39 const std::vector<std::uint8_t> cborOut = nlohmann::json::to_cbor(jOut);
40 const std::string fileName = m_fileName.value() + ".cbor";
41 ATH_MSG_INFO("Writing Cbor material map to '" << fileName << "'");
42 std::ofstream ofj(fileName, std::ios::out | std::ios::binary);
43 ofj.write(reinterpret_cast<const char*>(cborOut.data()), cborOut.size());
44 }
45}
#define ATH_MSG_INFO(x,...)
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
Definition Logger.cxx:64
Acts::GeometryContext context() const
virtual void writeMaterial(const ActsTrk::GeometryContext &gctx, const Acts::TrackingGeometryMaterial &detMaterial) const override
Gaudi::Property< std::string > m_fileName
The base name of the output file (without extension).
Gaudi::Property< bool > m_writeCbor
Write out the map in Cbor format.
Gaudi::Property< bool > m_writeJson
Write out the map in Json format.
static Root::TMsgLogger logger("iLumiCalc")