ATLAS Offline Software
Loading...
Searching...
No Matches
GeometryJsonDumper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6// GeometryJsonDumper.cxx, (c) ATLAS Detector software
8
9// Amg includes
11// Trk include
14#include "TrkGeometry/Layer.h"
15#include "TrkSurfaces/Surface.h"
17// output stream
18#include <sstream>
19
20// Gaudi
21#include "GaudiKernel/ITHistSvc.h"
22
23
25{
26 // open the file for writing
27 m_outputFile.open(m_outputFileName.value().c_str());
28 m_outputFile << "[";
29 m_outputFile << std::setiosflags(std::ios::fixed);
30 m_outputFile << std::setprecision(3);
31 // return the base::initialize() state
32 return Trk::RecursiveGeometryProcessor::initialize();
33}
34
36{
37 // close the file
38 m_outputFile << "]" << std::endl;
39 m_outputFile.close();
40 // return the base::finalize() state
41 return Trk::RecursiveGeometryProcessor::finalize();
42}
43
44
45
46StatusCode Trk::GeometryJsonDumper::processNode(const Trk::TrackingVolume& /*tvol*/, size_t /*level*/) const
47{
48 return StatusCode::SUCCESS;
49}
50
51
52StatusCode Trk::GeometryJsonDumper::processNode(const Trk::Layer& lay, size_t /*level*/) const
53{
54
55 ATH_MSG_VERBOSE("Dumping information for Layer with index " << lay.layerIndex().value());
56
57 if (lay.surfaceArray()){
58 size_t nSurfaces = lay.surfaceArray()->arrayObjects().size();
59 // the layer has a surface Array - go for it
60 // get the dimensions
61 const Trk::Surface* referenceSurface = lay.subSurfaceReference();
62 // the reference Surface exists
63 if (referenceSurface){
64 // dynamic_cast to RectangleBounds
65 const Trk::RectangleBounds* rBounds = dynamic_cast<const Trk::RectangleBounds*>(&(referenceSurface->bounds()));
66 // we have rBounds - go on for the moment
67 if (rBounds){
69 // the layer is defined
70 m_outputFile << "{\"Name\" : \"Layer " << lay.layerIndex().value() << "\", ";
71 m_outputFile << "\"Dimensions\" : [" << 2*rBounds->halflengthX() << "," << 2.*rBounds->halflengthY() << ", 1.0 ], ";
72 // count the surfaces
73 size_t is = 1;
74 // now loop of the surfaces and dumpt their position
75 m_outputFile << "\"Coords\": [";
76 for (const auto & sf : lay.surfaceArray()->arrayObjects()){
77 // get x,y,z
78 double cx = sf->center().x();
79 double cy = sf->center().y();
80 double cz = sf->center().z();
81 // get the euler angles
82 auto ea = sf->transform().rotation().eulerAngles(0, 1, 2);
83 double e0 = ea[0];
84 double e1 = ea[1];
85 double e2 = ea[2];
86 m_outputFile << "[" << cx << "," << cy << "," << cz << "],[" << e0 << "," << e1 << "," << e2 << "]";
87 if (is < nSurfaces) m_outputFile << ",";
88 ++is;
89 }
90 m_outputFile << "]}";
92 }
93 }
94 }
95 return StatusCode::SUCCESS;
96}
97
98
99StatusCode Trk::GeometryJsonDumper::processNode(const Trk::Surface& /*sf*/, size_t /*level*/) const
100{
101 ATH_MSG_VERBOSE("Dumping information for Surfaces.");
102
103 return StatusCode::SUCCESS;
104}
#define ATH_MSG_VERBOSE(x)
virtual std::span< T *const > arrayObjects()=0
Return all objects of the Array non-const we can still modify the T.
Gaudi::Property< std::string > m_outputFileName
StatusCode finalize()
AlgTool finalize method.
StatusCode initialize()
AlgTool initialize method.
StatusCode processNode(const TrackingVolume &tvol, size_t level=0) const
Current implementation: write root visualization to file stream.
int value() const
layerIndex expressed in an integer
Definition LayerIndex.h:71
Base Class for a Detector Layer in the Tracking realm.
Definition Layer.h:72
const SurfaceArray * surfaceArray() const
Return the entire SurfaceArray, returns nullptr if no SurfaceArray.
const LayerIndex & layerIndex() const
get the layerIndex
const Surface * subSurfaceReference(unsigned int idx=0) const
Return a reference sub surface of the layer, usually the first one in the array.
Definition Layer.cxx:117
Bounds for a rectangular, planar surface.
double halflengthX() const
for consistant naming
double halflengthY() const
for consitant naming
Abstract Base Class for tracking surfaces.
Definition Surface.h:79
virtual const SurfaceBounds & bounds() const =0
Surface Bounds method.
Full Volume description used in Tracking, it inherits from Volume to get the geometrical structure,...