ATLAS Offline Software
Loading...
Searching...
No Matches
GeometryJsonDumper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 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
24// constructor
25Trk::GeometryJsonDumper::GeometryJsonDumper(const std::string& t, const std::string& n, const IInterface* p) :
27 m_outputFileName("TrackingGeometry.json"),
30{
31 declareProperty("OutputFileName", m_outputFileName);
32 declareProperty("OutputPrecision", m_outputPrecision);
33}
34
35// destructor
37= default;
38
39
41{
42 // open the file for writing
43 m_outputFile.open(m_outputFileName.c_str());
44 m_outputFile << "[";
45 m_outputFile << std::setiosflags(std::ios::fixed);
46 m_outputFile << std::setprecision(3);
47 // return the base::initialize() state
49}
50
52{
53 // close the file
54 m_outputFile << "]" << std::endl;
55 m_outputFile.close();
56 // return the base::finalize() state
58}
59
60
61
62StatusCode Trk::GeometryJsonDumper::processNode(const Trk::TrackingVolume& /*tvol*/, size_t /*level*/) const
63{
64 return StatusCode::SUCCESS;
65}
66
67
68StatusCode Trk::GeometryJsonDumper::processNode(const Trk::Layer& lay, size_t /*level*/) const
69{
70
71 ATH_MSG_VERBOSE("Dumping information for Layer with index " << lay.layerIndex().value());
72
73 if (lay.surfaceArray()){
74 size_t nSurfaces = lay.surfaceArray()->arrayObjects().size();
75 // the layer has a surface Array - go for it
76 // get the dimensions
77 const Trk::Surface* referenceSurface = lay.subSurfaceReference();
78 // the reference Surface exists
79 if (referenceSurface){
80 // dynamic_cast to RectangleBounds
81 const Trk::RectangleBounds* rBounds = dynamic_cast<const Trk::RectangleBounds*>(&(referenceSurface->bounds()));
82 // we have rBounds - go on for the moment
83 if (rBounds){
85 // the layer is defined
86 m_outputFile << "{\"Name\" : \"Layer " << lay.layerIndex().value() << "\", ";
87 m_outputFile << "\"Dimensions\" : [" << 2*rBounds->halflengthX() << "," << 2.*rBounds->halflengthY() << ", 1.0 ], ";
88 // count the surfaces
89 size_t is = 1;
90 // now loop of the surfaces and dumpt their position
91 m_outputFile << "\"Coords\": [";
92 for (const auto & sf : lay.surfaceArray()->arrayObjects()){
93 // get x,y,z
94 double cx = sf->center().x();
95 double cy = sf->center().y();
96 double cz = sf->center().z();
97 // get the euler angles
98 auto ea = sf->transform().rotation().eulerAngles(0, 1, 2);
99 double e0 = ea[0];
100 double e1 = ea[1];
101 double e2 = ea[2];
102 m_outputFile << "[" << cx << "," << cy << "," << cz << "],[" << e0 << "," << e1 << "," << e2 << "]";
103 if (is < nSurfaces) m_outputFile << ",";
104 ++is;
105 }
106 m_outputFile << "]}";
107 m_firstLayerWritten = true;
108 }
109 }
110 }
111 return StatusCode::SUCCESS;
112}
113
114
115StatusCode Trk::GeometryJsonDumper::processNode(const Trk::Surface& /*sf*/, size_t /*level*/) const
116{
117 ATH_MSG_VERBOSE("Dumping information for Surfaces.");
118
119 return StatusCode::SUCCESS;
120}
#define ATH_MSG_VERBOSE(x)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
virtual std::span< T *const > arrayObjects()=0
Return all objects of the Array non-const we can still modify the T.
StatusCode finalize()
AlgTool finalize method.
virtual ~GeometryJsonDumper()
Destructor.
std::string m_outputFileName
where the tree is written to
StatusCode initialize()
AlgTool initialize method.
GeometryJsonDumper(const std::string &, const std::string &, const IInterface *)
Constructor.
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
RecursiveGeometryProcessor(const std::string &, const std::string &, const IInterface *)
Constructor.
StatusCode initialize()
AlgTool initialize method.
StatusCode finalize()
AlgTool finalize method.
Abstract Base Class for tracking surfaces.
virtual const SurfaceBounds & bounds() const =0
Surface Bounds method.
Full Volume description used in Tracking, it inherits from Volume to get the geometrical structure,...
Ensure that the ATLAS eigen extensions are properly loaded.