ATLAS Offline Software
Loading...
Searching...
No Matches
ActsTrk::JSONDeviceDetectorDescriptionProviderSvc Class Reference

Service providing device detector description from JSON files. More...

#include <JSONDeviceDetectorDescriptionProviderSvc.h>

Inheritance diagram for ActsTrk::JSONDeviceDetectorDescriptionProviderSvc:
Collaboration diagram for ActsTrk::JSONDeviceDetectorDescriptionProviderSvc:

Public Member Functions

virtual StatusCode initialize () override
 Function initializing and executing the file loading.
Athena<->detray ID map accessors for EDM converters
virtual const std::unordered_map< uint64_t, Identifier > & detrayToAthenaMap () const override
virtual const std::unordered_map< Identifier, uint64_t > & athenaToDetrayMap () const override

Private Member Functions

StatusCode loadIdMaps ()
 Helper function to load Athena<->detray ID maps from csv.

Private Attributes

ServiceHandle< StoreGateSvcm_detStore {this, "DetectorStore", "StoreGateSvc/DetectorStore"}
std::unordered_map< uint64_t, Identifierm_detrayToAthena
std::unordered_map< Identifier, uint64_t > m_athenaToDetray
The host and device memory resources tool to use for memory allocations
ToolHandle< AthDevice::IMemoryResourcesToolm_MRs
ToolHandle< AthDevice::ICopyToolm_copy
 The copy tool used for copying data to device.
The input JSON file names, path resolved with PathResolver
Gaudi::Property< std::string > m_geometryFile
Gaudi::Property< std::string > m_digitizationFile
Gaudi::Property< std::string > m_conditionsFile
Gaudi::Property< std::string > m_mapFile
The output object names
Gaudi::Property< std::string > m_deviceDesignObjectName
Gaudi::Property< std::string > m_deviceCondObjectName
Gaudi::Property< std::string > m_hostDesignObjectName
Gaudi::Property< std::string > m_hostCondObjectName
Gaudi::Property< std::string > m_deviceDetectorName
Gaudi::Property< std::string > m_hostDetectorName

Detailed Description

Service providing device detector description from JSON files.

This service loads detector description data from JSON files, which are needed for executing track reconstruction on GPU. The service provides the following data:

  • JSON geometry file -> detray geometry (required)
  • JSON digitization file -> traccc digitization config (required)
  • JSON conditions file -> traccc conditions config (required)
  • CSV map file -> athena<->detray ID map (required)

To be added in the future (only needed in track reco on device):

  • JSON material file -> detray material (optional)
  • JSON surface grid file -> detray surface grid (optional)
  • CVF magnetic field -> covfie magnetic field (required)

All objects are recorded to detector store as pointers to device objects, apart from the athena<->detray ID map. Additionally the digitization and conditions objects are stored in detector store as host objects, which are needed for EDM conversions.

Author
Neža Ribarič neza..nosp@m.riba.nosp@m.ric@c.nosp@m.ern..nosp@m.ch

Definition at line 61 of file JSONDeviceDetectorDescriptionProviderSvc.h.

Member Function Documentation

◆ athenaToDetrayMap()

const std::unordered_map< Identifier, uint64_t > & ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::athenaToDetrayMap ( ) const
overridevirtual

Definition at line 122 of file JSONDeviceDetectorDescriptionProviderSvc.cxx.

122 {
123 return m_athenaToDetray;
124}

◆ detrayToAthenaMap()

const std::unordered_map< uint64_t, Identifier > & ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::detrayToAthenaMap ( ) const
overridevirtual

Definition at line 118 of file JSONDeviceDetectorDescriptionProviderSvc.cxx.

118 {
119 return m_detrayToAthena;
120}

◆ initialize()

StatusCode ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::initialize ( )
overridevirtual

Function initializing and executing the file loading.

Definition at line 26 of file JSONDeviceDetectorDescriptionProviderSvc.cxx.

27{
28 ATH_MSG_DEBUG("Initializing device detector description provider service ");
29
30 ATH_CHECK(m_MRs.retrieve());
31 ATH_CHECK(m_copy.retrieve());
33
34 auto hostDesign = std::make_unique<traccc::detector_design_description::host>(*m_MRs->hostMR());
35 auto hostCond = std::make_unique<traccc::detector_conditions_description::host>(*m_MRs->hostMR());
36
37 std::unique_ptr<traccc::detector_design_description::buffer> deviceDesign;
38 std::unique_ptr<traccc::detector_conditions_description::buffer> deviceCond;
39
40 auto copy = m_copy->copy(EventContext{});
41
42 if (m_geometryFile.value().empty() ||
43 m_digitizationFile.value().empty() ||
44 m_conditionsFile.value().empty()) {
45 ATH_MSG_FATAL("GeometryFile, " << m_geometryFile.value() <<
46 ", DigitizationFile, " << m_digitizationFile.value() << " or ConditionsFile, " << m_conditionsFile.value() << ", is empty!");
47 return StatusCode::FAILURE;
48 }
49
50 ATH_MSG_INFO("Reading detector description from files:"
51 << " geometry: " << m_geometryFile.value()
52 << ", digitization: " << m_digitizationFile.value()
53 << ", conditions: " << m_conditionsFile.value());
54
55 // Construct detector geometry
56 ATH_MSG_INFO("Loading traccc detector");
57 auto hostDetector = std::make_unique<traccc::host_detector>();
58 traccc::io::read_detector(
59 *hostDetector, *m_MRs->hostMR(),
61
62 auto deviceDetector =
63 std::make_unique<traccc::detector_buffer>(traccc::buffer_from_host_detector(*hostDetector, m_MRs->mainMR(), const_cast<vecmem::copy&>(*copy)));
64
65 // Construct detector description
66 traccc::io::read_detector_description(
67 *hostDesign, *hostCond,
71 traccc::data_format::json);
72
73 ATH_MSG_DEBUG(hostDesign->size() << " design entries, "
74 << hostCond->size() << " conditions entries");
75
76 // Copy design to device
77 std::vector<unsigned int> sizes;
78 sizes.reserve(hostDesign->size());
79 for (std::size_t i = 0; i < hostDesign->size(); ++i) {
80 const auto& e = hostDesign->at(i);
81 sizes.push_back(static_cast<unsigned int>(
82 std::max(e.bin_edges_x().size(), e.bin_edges_y().size())));
83 }
84
85 deviceDesign =
86 std::make_unique<traccc::detector_design_description::buffer>(
87 sizes, m_MRs->mainMR(), m_MRs->hostMR(),
88 vecmem::data::buffer_type::resizable);
89 (*copy).setup(*deviceDesign)->wait();
90 (*copy)(vecmem::get_data(*hostDesign), *deviceDesign)->wait();
91
92 // Copy conditions to device
93 deviceCond =
94 std::make_unique<traccc::detector_conditions_description::buffer>(
95 static_cast<traccc::detector_conditions_description::buffer::size_type>(
96 hostCond->size()),
97 m_MRs->mainMR());
98 (*copy).setup(*deviceCond)->wait();
99 (*copy)(vecmem::get_data(*hostCond), *deviceCond)->wait();
100
101 ATH_MSG_INFO("Detector description built from files");
102
103 // Record device and host objects
104 // Host objects are needed for EDM conversions
105 constexpr bool allowMods = false;
106 ATH_CHECK(m_detStore->record(std::move(deviceDesign), m_deviceDesignObjectName.value(), allowMods));
107 ATH_CHECK(m_detStore->record(std::move(deviceCond), m_deviceCondObjectName.value(), allowMods));
108 ATH_CHECK(m_detStore->record(std::move(hostDesign), m_hostDesignObjectName.value(), allowMods));
109 ATH_CHECK(m_detStore->record(std::move(hostCond), m_hostCondObjectName.value(), allowMods));
110
111 ATH_CHECK(m_detStore->record(std::move(deviceDetector), m_deviceDetectorName.value(), allowMods));
112 ATH_CHECK(m_detStore->record(std::move(hostDetector), m_hostDetectorName.value(), allowMods));
113
114 ATH_MSG_DEBUG("Successfully initialized");
115 return StatusCode::SUCCESS;
116}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
ToolHandle< AthDevice::ICopyTool > m_copy
The copy tool used for copying data to device.
StatusCode loadIdMaps()
Helper function to load Athena<->detray ID maps from csv.
bool copy
Definition calibdata.py:26

◆ loadIdMaps()

StatusCode ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::loadIdMaps ( )
private

Helper function to load Athena<->detray ID maps from csv.

Definition at line 126 of file JSONDeviceDetectorDescriptionProviderSvc.cxx.

127{
128 if (m_mapFile.value().empty()) {
129 ATH_MSG_FATAL("MapFile not set — detray<->Athena maps will be empty");
130 return StatusCode::FAILURE;
131 }
132
133 ATH_MSG_INFO("Loading detray<->Athena map from "
134 << m_mapFile.value());
135
136 std::ifstream mapFile(PathResolverFindCalibFile(m_mapFile.value()));
137 if (!mapFile.is_open()) {
138 ATH_MSG_FATAL("Cannot open map file: " << m_mapFile.value());
139 return StatusCode::FAILURE;
140 }
141
142 std::string line;
143 while (std::getline(mapFile, line)) {
144 if (line.empty()) continue;
145 std::stringstream ss(line);
146 std::string athenaStr, detrayStr;
147 if (!std::getline(ss, athenaStr, ',') ||
148 !std::getline(ss, detrayStr, ',')) continue;
149
150 if (athenaStr.empty()) {
151 ATH_MSG_ERROR("Empty Athena identifier string in map file — skipping");
152 return StatusCode::FAILURE;
153 }
154 Identifier athenaId;
155 athenaId.set(athenaStr);
156
157 uint64_t detrayId = 0;
158 try {
159 detrayId = std::stoull(detrayStr);
160 } catch (const std::exception& e) {
161 ATH_MSG_ERROR("Failed to parse detray identifier '" << detrayStr << "': " << e.what());
162 return StatusCode::FAILURE;
163 }
164
165 m_athenaToDetray[athenaId] = detrayId;
166 m_detrayToAthena[detrayId] = athenaId;
167 }
168
169 ATH_MSG_INFO("Loaded " << m_athenaToDetray.size()
170 << " detray<->Athena module mappings");
171 return StatusCode::SUCCESS;
172}
#define ATH_MSG_ERROR(x)
static Double_t ss
void set(std::string_view id)
build from a string form - hexadecimal

Member Data Documentation

◆ m_athenaToDetray

std::unordered_map<Identifier, uint64_t> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_athenaToDetray
private

Definition at line 133 of file JSONDeviceDetectorDescriptionProviderSvc.h.

◆ m_conditionsFile

Gaudi::Property<std::string> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_conditionsFile
private
Initial value:
{
this, "ConditionsFile", "",
"Traccc conditions config JSON file"}

Definition at line 99 of file JSONDeviceDetectorDescriptionProviderSvc.h.

99 {
100 this, "ConditionsFile", "",
101 "Traccc conditions config JSON file"};

◆ m_copy

ToolHandle<AthDevice::ICopyTool> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_copy
private
Initial value:
{
this, "CopyProviderTool", "", "Vecmem copy provider tool"}

The copy tool used for copying data to device.

Definition at line 88 of file JSONDeviceDetectorDescriptionProviderSvc.h.

88 {
89 this, "CopyProviderTool", "", "Vecmem copy provider tool"};

◆ m_detrayToAthena

std::unordered_map<uint64_t, Identifier> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_detrayToAthena
private

Definition at line 132 of file JSONDeviceDetectorDescriptionProviderSvc.h.

◆ m_detStore

ServiceHandle<StoreGateSvc> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_detStore {this, "DetectorStore", "StoreGateSvc/DetectorStore"}
private

Definition at line 81 of file JSONDeviceDetectorDescriptionProviderSvc.h.

81{this, "DetectorStore", "StoreGateSvc/DetectorStore"};

◆ m_deviceCondObjectName

Gaudi::Property<std::string> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_deviceCondObjectName
private
Initial value:
{
this, "DeviceConditionsObjectName", "",
"Traccc device conditions object"}

Definition at line 112 of file JSONDeviceDetectorDescriptionProviderSvc.h.

112 {
113 this, "DeviceConditionsObjectName", "",
114 "Traccc device conditions object"};

◆ m_deviceDesignObjectName

Gaudi::Property<std::string> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_deviceDesignObjectName
private
Initial value:
{
this, "DeviceDigitizationObjectName", "",
"Traccc device digitization object"}

Definition at line 109 of file JSONDeviceDetectorDescriptionProviderSvc.h.

109 {
110 this, "DeviceDigitizationObjectName", "",
111 "Traccc device digitization object"};

◆ m_deviceDetectorName

Gaudi::Property<std::string> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_deviceDetectorName
private
Initial value:
{
this, "DeviceDetectorName", "",
"Detray device detector object"}

Definition at line 121 of file JSONDeviceDetectorDescriptionProviderSvc.h.

121 {
122 this, "DeviceDetectorName", "",
123 "Detray device detector object"};

◆ m_digitizationFile

Gaudi::Property<std::string> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_digitizationFile
private
Initial value:
{
this, "DigitizationFile", "",
"Traccc digitization config JSON file"}

Definition at line 96 of file JSONDeviceDetectorDescriptionProviderSvc.h.

96 {
97 this, "DigitizationFile", "",
98 "Traccc digitization config JSON file"};

◆ m_geometryFile

Gaudi::Property<std::string> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_geometryFile
private
Initial value:
{
this, "GeometryFile", "",
"Detray geometry JSON file"}

Definition at line 93 of file JSONDeviceDetectorDescriptionProviderSvc.h.

93 {
94 this, "GeometryFile", "",
95 "Detray geometry JSON file"};

◆ m_hostCondObjectName

Gaudi::Property<std::string> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_hostCondObjectName
private
Initial value:
{
this, "HostConditionsObjectName", "",
"Traccc host conditions object"}

Definition at line 118 of file JSONDeviceDetectorDescriptionProviderSvc.h.

118 {
119 this, "HostConditionsObjectName", "",
120 "Traccc host conditions object"};

◆ m_hostDesignObjectName

Gaudi::Property<std::string> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_hostDesignObjectName
private
Initial value:
{
this, "HostDigitizationObjectName", "",
"Traccc host digitization object"}

Definition at line 115 of file JSONDeviceDetectorDescriptionProviderSvc.h.

115 {
116 this, "HostDigitizationObjectName", "",
117 "Traccc host digitization object"};

◆ m_hostDetectorName

Gaudi::Property<std::string> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_hostDetectorName
private
Initial value:
{
this, "HostDetectorName", "",
"Detray host detector object"}

Definition at line 124 of file JSONDeviceDetectorDescriptionProviderSvc.h.

124 {
125 this, "HostDetectorName", "",
126 "Detray host detector object"};

◆ m_mapFile

Gaudi::Property<std::string> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_mapFile
private
Initial value:
{
this, "MapFile", "",
"Path to the athena<->detray ID map CSV file"}

Definition at line 102 of file JSONDeviceDetectorDescriptionProviderSvc.h.

102 {
103 this, "MapFile", "",
104 "Path to the athena<->detray ID map CSV file"};

◆ m_MRs

ToolHandle<AthDevice::IMemoryResourcesTool> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_MRs
private
Initial value:
{
this, "MemoryResourcesTool", "",
"The memory resources tool to use for allocating memory on the device"}

Definition at line 83 of file JSONDeviceDetectorDescriptionProviderSvc.h.

83 {
84 this, "MemoryResourcesTool", "",
85 "The memory resources tool to use for allocating memory on the device"};

The documentation for this class was generated from the following files: