ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
Acts
ActsMaterial
src
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
5
#include "
JsonMaterialWriterTool.h
"
6
#include "
ActsInterop/Logger.h
"
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
16
void
ActsTrk::JsonMaterialWriterTool::writeMaterial
(
const
ActsTrk::GeometryContext
& gctx,
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
}
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
JsonMaterialWriterTool.h
Logger.h
makeActsAthenaLogger
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
ActsTrk::GeometryContext
Definition
GeometryContext.h:30
ActsTrk::GeometryContext::context
Acts::GeometryContext context() const
Definition
GeometryContext.h:48
ActsTrk::JsonMaterialWriterTool::writeMaterial
virtual void writeMaterial(const ActsTrk::GeometryContext &gctx, const Acts::TrackingGeometryMaterial &detMaterial) const override
Definition
JsonMaterialWriterTool.cxx:16
ActsTrk::JsonMaterialWriterTool::m_fileName
Gaudi::Property< std::string > m_fileName
The base name of the output file (without extension).
Definition
JsonMaterialWriterTool.h:28
ActsTrk::JsonMaterialWriterTool::m_writeCbor
Gaudi::Property< bool > m_writeCbor
Write out the map in Cbor format.
Definition
JsonMaterialWriterTool.h:32
ActsTrk::JsonMaterialWriterTool::m_writeJson
Gaudi::Property< bool > m_writeJson
Write out the map in Json format.
Definition
JsonMaterialWriterTool.h:30
logger
static Root::TMsgLogger logger("iLumiCalc")
Generated on
for ATLAS Offline Software by
1.17.0