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

#include <JSONDeviceDetectorDescriptionProviderSvc.h>

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

Public Member Functions

virtual StatusCode initialize () override
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 ()
StatusCode buildFromFile (std::pmr::memory_resource &hostMR, std::pmr::memory_resource &deviceMR, const vecmem::copy &copy, std::unique_ptr< traccc::detector_design_description::host > &hostDesign, std::unique_ptr< traccc::detector_conditions_description::host > &hostCond, std::unique_ptr< traccc::detector_design_description::buffer > &deviceDesign, std::unique_ptr< traccc::detector_conditions_description::buffer > &deviceCond)

Private Attributes

ServiceHandle< StoreGateSvcm_detStore {this, "DetectorStore", "StoreGateSvc/DetectorStore"}
ToolHandle< AthDevice::IMemoryResourceToolm_hostMR
ToolHandle< AthDevice::IMemoryResourceToolm_deviceMR
ToolHandle< AthDevice::ICopyToolm_copy
Gaudi::Property< std::string > m_geometryFile
Gaudi::Property< std::string > m_digitizationFile
Gaudi::Property< std::string > m_conditionsFile
Gaudi::Property< std::string > m_mapFile
Gaudi::Property< std::string > m_deviceDesignObjectName
Gaudi::Property< std::string > m_deviceCondObjectName
Gaudi::Property< std::string > m_hostDesignObjectName
Gaudi::Property< std::string > m_hostCondObjectName
std::unordered_map< uint64_t, Identifierm_detrayToAthena
std::unordered_map< Identifier, uint64_t > m_athenaToDetray

Detailed Description

Definition at line 32 of file JSONDeviceDetectorDescriptionProviderSvc.h.

Member Function Documentation

◆ athenaToDetrayMap()

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

Definition at line 56 of file JSONDeviceDetectorDescriptionProviderSvc.cxx.

56 {
57 return m_athenaToDetray;
58}

◆ buildFromFile()

StatusCode ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::buildFromFile ( std::pmr::memory_resource & hostMR,
std::pmr::memory_resource & deviceMR,
const vecmem::copy & copy,
std::unique_ptr< traccc::detector_design_description::host > & hostDesign,
std::unique_ptr< traccc::detector_conditions_description::host > & hostCond,
std::unique_ptr< traccc::detector_design_description::buffer > & deviceDesign,
std::unique_ptr< traccc::detector_conditions_description::buffer > & deviceCond )
private

Definition at line 108 of file JSONDeviceDetectorDescriptionProviderSvc.cxx.

116{
117 if (m_geometryFile.value().empty() ||
118 m_digitizationFile.value().empty() ||
119 m_conditionsFile.value().empty()) {
120 ATH_MSG_FATAL("GeometryFile, " << m_geometryFile.value() <<
121 ", DigitizationFile, " << m_digitizationFile.value() << " or ConditionsFile, " << m_conditionsFile.value() << ", is empty!");
122 return StatusCode::FAILURE;
123 }
124
125 ATH_MSG_INFO("Reading detector description from files:"
126 << " geometry: " << m_geometryFile.value()
127 << ", digitization: " << m_digitizationFile.value()
128 << ", conditions: " << m_conditionsFile.value());
129
130 hostDesign = std::make_unique<traccc::detector_design_description::host>(hostMR);
131 hostCond = std::make_unique<traccc::detector_conditions_description::host>(hostMR);
132
133 traccc::io::read_detector_description(
134 *hostDesign, *hostCond,
138 traccc::data_format::json);
139
140 ATH_MSG_DEBUG(hostDesign->size() << " design entries, "
141 << hostCond->size() << " conditions entries");
142
143 // Copy design to device
144 std::vector<unsigned int> sizes;
145 sizes.reserve(hostDesign->size());
146 for (std::size_t i = 0; i < hostDesign->size(); ++i) {
147 const auto& e = hostDesign->at(i);
148 sizes.push_back(static_cast<unsigned int>(
149 std::max(e.bin_edges_x().size(), e.bin_edges_y().size())));
150 }
151
152 deviceDesign =
153 std::make_unique<traccc::detector_design_description::buffer>(
154 sizes, deviceMR, &hostMR,
155 vecmem::data::buffer_type::resizable);
156 copy.setup(*deviceDesign)->wait();
157 copy(vecmem::get_data(*hostDesign), *deviceDesign)->wait();
158
159 // Copy conditions to device
160 deviceCond =
161 std::make_unique<traccc::detector_conditions_description::buffer>(
162 static_cast<traccc::detector_conditions_description::buffer::size_type>(
163 hostCond->size()),
164 deviceMR);
165 copy.setup(*deviceCond)->wait();
166 copy(vecmem::get_data(*hostCond), *deviceCond)->wait();
167
168 ATH_MSG_INFO("Detector description built from files");
169 return StatusCode::SUCCESS;
170}
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
bool copy
Definition calibdata.py:26

◆ detrayToAthenaMap()

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

Definition at line 52 of file JSONDeviceDetectorDescriptionProviderSvc.cxx.

52 {
53 return m_detrayToAthena;
54}

◆ initialize()

StatusCode ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::initialize ( )
overridevirtual

Definition at line 24 of file JSONDeviceDetectorDescriptionProviderSvc.cxx.

25{
26 ATH_MSG_DEBUG("Initializing device detector description provider service ");
27
28 ATH_CHECK(m_hostMR.retrieve());
29 ATH_CHECK(m_deviceMR.retrieve());
30 ATH_CHECK(m_copy.retrieve());
31
32 std::unique_ptr<traccc::detector_design_description::host> hostDesign;
33 std::unique_ptr<traccc::detector_conditions_description::host> hostCond;
34 std::unique_ptr<traccc::detector_design_description::buffer> deviceDesign;
35 std::unique_ptr<traccc::detector_conditions_description::buffer> deviceCond;
36
38 auto copy = m_copy->copy(EventContext{});
39 ATH_CHECK(buildFromFile(m_hostMR->mr(), m_deviceMR->mr(), *copy, hostDesign, hostCond, deviceDesign, deviceCond));
40
41 // Record device and host objects
42 // Host objects are needed for EDM conversions
43 ATH_CHECK(m_detStore->record(std::move(deviceDesign), m_deviceDesignObjectName.value()));
44 ATH_CHECK(m_detStore->record(std::move(deviceCond), m_deviceCondObjectName.value()));
45 ATH_CHECK(m_detStore->record(std::move(hostDesign), m_hostDesignObjectName.value()));
46 ATH_CHECK(m_detStore->record(std::move(hostCond), m_hostCondObjectName.value()));
47
48 ATH_MSG_DEBUG("Successfully initialized");
49 return StatusCode::SUCCESS;
50}
#define ATH_CHECK
Evaluate an expression and check for errors.
StatusCode buildFromFile(std::pmr::memory_resource &hostMR, std::pmr::memory_resource &deviceMR, const vecmem::copy &copy, std::unique_ptr< traccc::detector_design_description::host > &hostDesign, std::unique_ptr< traccc::detector_conditions_description::host > &hostCond, std::unique_ptr< traccc::detector_design_description::buffer > &deviceDesign, std::unique_ptr< traccc::detector_conditions_description::buffer > &deviceCond)

◆ loadIdMaps()

StatusCode ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::loadIdMaps ( )
private

Definition at line 60 of file JSONDeviceDetectorDescriptionProviderSvc.cxx.

61{
62 if (m_mapFile.value().empty()) {
63 ATH_MSG_FATAL("MapFile not set — detray<->Athena maps will be empty");
64 return StatusCode::FAILURE;
65 }
66
67 ATH_MSG_INFO("Loading detray<->Athena map from "
68 << m_mapFile.value());
69
70 std::ifstream mapFile(PathResolverFindCalibFile(m_mapFile.value()));
71 if (!mapFile.is_open()) {
72 ATH_MSG_FATAL("Cannot open map file: " << m_mapFile.value());
73 return StatusCode::FAILURE;
74 }
75
76 std::string line;
77 while (std::getline(mapFile, line)) {
78 if (line.empty()) continue;
79 std::stringstream ss(line);
80 std::string athenaStr, detrayStr;
81 if (!std::getline(ss, athenaStr, ',') ||
82 !std::getline(ss, detrayStr, ',')) continue;
83
84 if (athenaStr.empty()) {
85 ATH_MSG_ERROR("Empty Athena identifier string in map file — skipping");
86 return StatusCode::FAILURE;
87 }
88 Identifier athenaId;
89 athenaId.set(athenaStr);
90
91 uint64_t detrayId = 0;
92 try {
93 detrayId = std::stoull(detrayStr);
94 } catch (const std::exception& e) {
95 ATH_MSG_ERROR("Failed to parse detray identifier '" << detrayStr << "': " << e.what());
96 return StatusCode::FAILURE;
97 }
98
99 m_athenaToDetray[athenaId] = detrayId;
100 m_detrayToAthena[detrayId] = athenaId;
101 }
102
103 ATH_MSG_INFO("Loaded " << m_athenaToDetray.size()
104 << " detray<->Athena module mappings");
105 return StatusCode::SUCCESS;
106}
#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 94 of file JSONDeviceDetectorDescriptionProviderSvc.h.

◆ m_conditionsFile

Gaudi::Property<std::string> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_conditionsFile
private
Initial value:
{
this, "ConditionsFile", "",
"Traccc conditions config JSON file (required when PopulateFromFile=true)"}

Definition at line 64 of file JSONDeviceDetectorDescriptionProviderSvc.h.

64 {
65 this, "ConditionsFile", "",
66 "Traccc conditions config JSON file (required when PopulateFromFile=true)"};

◆ m_copy

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

Definition at line 54 of file JSONDeviceDetectorDescriptionProviderSvc.h.

54 {
55 this, "CopyProviderTool", "", "Vecmem copy provider tool"};

◆ m_detrayToAthena

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

Definition at line 93 of file JSONDeviceDetectorDescriptionProviderSvc.h.

◆ m_detStore

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

Definition at line 48 of file JSONDeviceDetectorDescriptionProviderSvc.h.

48{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 74 of file JSONDeviceDetectorDescriptionProviderSvc.h.

74 {
75 this, "DeviceConditionsObjectName", "",
76 "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 71 of file JSONDeviceDetectorDescriptionProviderSvc.h.

71 {
72 this, "DeviceDigitizationObjectName", "",
73 "Traccc device digitization object"};

◆ m_deviceMR

ToolHandle<AthDevice::IMemoryResourceTool> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_deviceMR
private
Initial value:
{
this, "DeviceMR", "", "Device memory resource tool"}

Definition at line 52 of file JSONDeviceDetectorDescriptionProviderSvc.h.

52 {
53 this, "DeviceMR", "", "Device memory resource tool"};

◆ m_digitizationFile

Gaudi::Property<std::string> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_digitizationFile
private
Initial value:
{
this, "DigitizationFile", "",
"Traccc digitization config JSON file (required when PopulateFromFile=true)"}

Definition at line 61 of file JSONDeviceDetectorDescriptionProviderSvc.h.

61 {
62 this, "DigitizationFile", "",
63 "Traccc digitization config JSON file (required when PopulateFromFile=true)"};

◆ m_geometryFile

Gaudi::Property<std::string> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_geometryFile
private
Initial value:
{
this, "GeometryFile", "",
"Detray geometry JSON file (required when PopulateFromFile=true)"}

Definition at line 58 of file JSONDeviceDetectorDescriptionProviderSvc.h.

58 {
59 this, "GeometryFile", "",
60 "Detray geometry JSON file (required when PopulateFromFile=true)"};

◆ m_hostCondObjectName

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

Definition at line 80 of file JSONDeviceDetectorDescriptionProviderSvc.h.

80 {
81 this, "HostConditionsObjectName", "",
82 "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 77 of file JSONDeviceDetectorDescriptionProviderSvc.h.

77 {
78 this, "HostDigitizationObjectName", "",
79 "Traccc host digitization object"};

◆ m_hostMR

ToolHandle<AthDevice::IMemoryResourceTool> ActsTrk::JSONDeviceDetectorDescriptionProviderSvc::m_hostMR
private
Initial value:
{
this, "HostMR", "", "Host memory resource tool"}

Definition at line 50 of file JSONDeviceDetectorDescriptionProviderSvc.h.

50 {
51 this, "HostMR", "", "Host memory resource tool"};

◆ 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 67 of file JSONDeviceDetectorDescriptionProviderSvc.h.

67 {
68 this, "MapFile", "",
69 "Path to the athena<->detray ID map CSV file"};

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