ATLAS Offline Software
Loading...
Searching...
No Matches
BasicGPUToAthenaImporter Class Reference

Standard tool to convert the GPU data representation back to CPU. More...

#include <BasicGPUToAthenaImporter.h>

Inheritance diagram for BasicGPUToAthenaImporter:
Collaboration diagram for BasicGPUToAthenaImporter:

Public Member Functions

 BasicGPUToAthenaImporter (const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode initialize () override
virtual StatusCode convert (const EventContext &ctx, const CaloRecGPU::ConstantDataHolder &constant_data, CaloRecGPU::EventDataHolder &event_data, xAOD::CaloClusterContainer *cluster_collection) const override
virtual StatusCode finalize () override
virtual ~BasicGPUToAthenaImporter ()=default

Protected Member Functions

void record_times (const size_t event_num, const std::vector< size_t > &times) const
template<class ... Args>
void record_times (const size_t event_num, const size_t &value) const
template<class ... Args>
void record_times (const size_t event_num, const size_t &value, Args &&... args) const
void print_times (const std::string &header, const size_t time_size) const

Protected Attributes

std::shared_mutex m_timeMutex
 Mutex that is locked when recording times.
std::vector< size_t > m_times ATLAS_THREAD_SAFE
 Vector to hold execution times to be recorded if necessary.
std::vector< size_t > m_eventNumbers ATLAS_THREAD_SAFE
 Vector to hold the event numbers to be recorded if necessary.
Gaudi::Property< bool > m_measureTimes
 If true, times are recorded to the file given by m_timeFileName.
Gaudi::Property< std::string > m_timeFileName
 File to which times should be saved.

Private Member Functions

void record_times_helper (const size_t) const
template<class Arg>
void record_times_helper (const size_t index, Arg &&arg) const
template<class ... Args>
void record_times_helper (size_t index, Args &&... args) const

Private Attributes

Gaudi::Property< bool > m_useCPUPropertiesCalculation {this, "UseCPUClusterPropertiesCalculation", false, "Use CaloClusterKineHelper::calculateKine instead of GPU-calculated cluster properties"}
 if set to true, cluster properties are (re-)calculated using CaloClusterKineHelper::calculateKine.
SG::ReadHandleKey< CaloCellContainer > m_cellsKey {this, "CellsName", "", "Name(s) of Cell Containers"}
 vector of names of the cell containers to use as input.
Gaudi::Property< std::string > m_clusterSizeString {this, "ClusterSize", "Topo_420", "The size/type of the clusters"}
 Cluster size. Should be set accordingly to the threshold.
xAOD::CaloCluster::ClusterSize m_clusterSize
Gaudi::Property< std::vector< int > > m_missingCellsToFill {this, "MissingCellsToFill", {}, "Force fill these cells as disabled on empty containers."}
 Cell indices to fill as disabled cells (useful if the cell vector is always missing the same cells).
const CaloCell_ID * m_calo_id {nullptr}
 Pointer to Calo ID Helper.
Gaudi::Property< bool > m_saveUncalibrated {this, "SaveUncalibratedSignalState", true, "Use CaloClusterKineHelper::calculateKine instead of GPU-calculated cluster properties"}
 if set to true, the uncalibrated state is saved when importing the clusters.
ToolHandle< AthCUDA::IStreamTool > m_streamTool {this, "StreamTool", "", "CUDA stream tool."}
 Tool providing the CUDA stream to use.

Detailed Description

Standard tool to convert the GPU data representation back to CPU.

Author
Nuno Fernandes nuno..nosp@m.dos..nosp@m.santo.nosp@m.s.fe.nosp@m.rnand.nosp@m.es@c.nosp@m.ern.c.nosp@m.h
Date
30 May 2022

Definition at line 31 of file BasicGPUToAthenaImporter.h.

Constructor & Destructor Documentation

◆ BasicGPUToAthenaImporter()

BasicGPUToAthenaImporter::BasicGPUToAthenaImporter ( const std::string & type,
const std::string & name,
const IInterface * parent )

Definition at line 25 of file BasicGPUToAthenaImporter.cxx.

25 :
26 base_class(type, name, parent),
27 CaloGPUTimed(this)
28{
29}
CaloGPUTimed(T *ptr)

◆ ~BasicGPUToAthenaImporter()

virtual BasicGPUToAthenaImporter::~BasicGPUToAthenaImporter ( )
virtualdefault

Member Function Documentation

◆ convert()

StatusCode BasicGPUToAthenaImporter::convert ( const EventContext & ctx,
const CaloRecGPU::ConstantDataHolder & constant_data,
CaloRecGPU::EventDataHolder & event_data,
xAOD::CaloClusterContainer * cluster_collection ) const
overridevirtual

Definition at line 91 of file BasicGPUToAthenaImporter.cxx.

95{
96 using clock_type = boost::chrono::thread_clock;
97 auto time_cast = [](const auto & before, const auto & after)
98 {
99 return boost::chrono::duration_cast<boost::chrono::microseconds>(after - before).count();
100 };
101
102 cluster_container->clear();
103
104 const auto start = clock_type::now();
105
106 SG::ReadHandle<CaloCellContainer> cell_collection(m_cellsKey, ctx);
107 if ( !cell_collection.isValid() )
108 {
109 ATH_MSG_ERROR( " Cannot retrieve CaloCellContainer: " << cell_collection.name() );
110 return StatusCode::FAILURE;
111 }
112 const DataLink<CaloCellContainer> cell_collection_link (cell_collection.name(), ctx);
113
114 ed.returnToCPU(MomentsOptionsArray::all(), m_streamTool->stream(ctx), false, false, true);
115
116 const auto after_send = clock_type::now();
117
118 size_t extra_times[5];
119
120 ed.exportClusters(cluster_container,
121 cell_collection_link,
123 true,
125 false,
127 m_measureTimes ? extra_times : nullptr);
128
129 const auto after_export = clock_type::now();
130
131 for (auto && cluster : *cluster_container)
132 {
133 cluster->setClusterSize(m_clusterSize);
134 }
135
136 const auto after_size = clock_type::now();
137
138 if (m_measureTimes)
139 {
140 record_times(ctx.evt(),
141 time_cast(start, after_send),
142 extra_times[0],
143 extra_times[1],
144 extra_times[2],
145 extra_times[3],
146 extra_times[4],
147 time_cast(after_export, after_size)
148 );
149 }
150
151 return StatusCode::SUCCESS;
152
153}
#define ATH_MSG_ERROR(x,...)
xAOD::CaloCluster::ClusterSize m_clusterSize
Gaudi::Property< std::vector< int > > m_missingCellsToFill
Cell indices to fill as disabled cells (useful if the cell vector is always missing the same cells).
Gaudi::Property< bool > m_saveUncalibrated
if set to true, the uncalibrated state is saved when importing the clusters.
SG::ReadHandleKey< CaloCellContainer > m_cellsKey
vector of names of the cell containers to use as input.
ToolHandle< AthCUDA::IStreamTool > m_streamTool
Tool providing the CUDA stream to use.
Gaudi::Property< bool > m_measureTimes
If true, times are recorded to the file given by m_timeFileName.
void record_times(const size_t event_num, const std::vector< size_t > &times) const
static MomentsOptionsArray all()

◆ finalize()

StatusCode BasicGPUToAthenaImporter::finalize ( )
overridevirtual

Definition at line 156 of file BasicGPUToAthenaImporter.cxx.

157{
158
159 if (m_measureTimes)
160 {
161 print_times("Transfer_from_GPU Cell_Link_Creation Cell_Adding Sorting Filling_Collection Moments Cluster_Size", 7);
162 }
163 return StatusCode::SUCCESS;
164}
void print_times(const std::string &header, const size_t time_size) const

◆ initialize()

StatusCode BasicGPUToAthenaImporter::initialize ( )
overridevirtual

Definition at line 33 of file BasicGPUToAthenaImporter.cxx.

34{
35 ATH_CHECK( m_cellsKey.initialize() );
36
37 ATH_CHECK( detStore()->retrieve(m_calo_id, "CaloCell_ID") );
38
39 auto get_option_from_string = [](const std::string & str, bool & failed)
40 {
41 failed = false;
42 //cppcheck-suppress syntaxError
45 SW_55ele,
46 SW_35ele,
47 SW_37ele,
48 SW_55gam,
49 SW_35gam,
50 SW_37gam,
51 SW_55Econv,
52 SW_35Econv,
53 SW_37Econv,
54 SW_softe,
55 Topo_420,
56 Topo_633,
57 SW_7_11,
58 SuperCluster,
59 Tower_01_01,
60 Tower_005_005,
61 Tower_fixed_area
62 )
63 )
64 //I know Topological Clustering only supports a subset of those,
65 //but this is supposed to be a general data exporting tool...
66 else
67 {
68 //failed = true;
70 }
71 };
72
73 bool size_failed = false;
74 m_clusterSize = get_option_from_string(m_clusterSizeString, size_failed);
75
77 {
78 ATH_MSG_ERROR("Invalid Cluster Size: " << m_clusterSizeString);
79 }
80
81 if (size_failed)
82 {
83 return StatusCode::FAILURE;
84 }
85
86 ATH_CHECK( m_streamTool.retrieve() );
87
88 return StatusCode::SUCCESS;
89}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define CRGPU_RECURSIVE_MACRO(...)
Expands recursive macros.
#define CRGPU_CHEAP_STRING_TO_ENUM(VAR, PREFIX, ONE,...)
Checks a string variable, VAR, for matching enum identifiers (ONE and the remaining variadic argument...
const CaloCell_ID * m_calo_id
Pointer to Calo ID Helper.
Gaudi::Property< std::string > m_clusterSizeString
Cluster size. Should be set accordingly to the threshold.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.

◆ print_times()

void CaloGPUTimed::print_times ( const std::string & header,
const size_t time_size ) const
inlineprotectedinherited

Definition at line 143 of file CaloGPUTimed.h.

144 {
145 std::shared_lock<std::shared_mutex> lock(m_timeMutex);
146
147 if (m_timeFileName.size() == 0)
148 {
149 return;
150 }
151
152 std::vector<size_t> indices(m_eventNumbers.size());
153
154 std::iota(indices.begin(), indices.end(), 0);
155 std::sort(indices.begin(), indices.end(), [&](size_t a, size_t b)
156 {
157 return m_eventNumbers[a] < m_eventNumbers[b];
158 }
159 );
160 std::ofstream out(m_timeFileName);
161
162 out << "Event_Number Total " << header << "\n";
163
164 for (const size_t idx : indices)
165 {
166 out << m_eventNumbers[idx] << " ";
167
168 size_t total = 0;
169
170 for (size_t i = 0; i < time_size; ++i)
171 {
172 total += m_times[idx * time_size + i];
173 }
174
175 out << total << " ";
176
177 for (size_t i = 0; i < time_size; ++i)
178 {
179 out << m_times[idx * time_size + i] << " ";
180 }
181 out << "\n";
182 }
183
184 out << std::endl;
185
186 out.close();
187 }
std::vector< std::vector< int64_t > > indices
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
static Double_t a
Gaudi::Property< std::string > m_timeFileName
File to which times should be saved.
std::shared_mutex m_timeMutex
Mutex that is locked when recording times.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.

◆ record_times() [1/3]

template<class ... Args>
void CaloGPUTimed::record_times ( const size_t event_num,
const size_t & value ) const
inlineprotectedinherited

Definition at line 105 of file CaloGPUTimed.h.

106 {
107 const size_t time_size = 1;
108
109 size_t old_size;
110
111 {
112 std::unique_lock<std::shared_mutex> lock(m_timeMutex);
113 old_size = m_times.size();
114 m_times.resize(old_size + time_size);
115 m_eventNumbers.push_back(event_num);
116 }
117 {
118 std::shared_lock<std::shared_mutex> lock(m_timeMutex);
119 record_times_helper(old_size, value);
120 }
121 }
void record_times_helper(const size_t) const

◆ record_times() [2/3]

template<class ... Args>
void CaloGPUTimed::record_times ( const size_t event_num,
const size_t & value,
Args &&... args ) const
inlineprotectedinherited

Definition at line 124 of file CaloGPUTimed.h.

125 {
126 const size_t time_size = sizeof...(args) + 1;
127
128 size_t old_size;
129
130 {
131 std::unique_lock<std::shared_mutex> lock(m_timeMutex);
132 old_size = m_times.size();
133 m_times.resize(old_size + time_size);
134 m_eventNumbers.push_back(event_num);
135 }
136 {
137 std::shared_lock<std::shared_mutex> lock(m_timeMutex);
138 record_times_helper(old_size, value, std::forward<Args>(args)...);
139 }
140
141 }

◆ record_times() [3/3]

void CaloGPUTimed::record_times ( const size_t event_num,
const std::vector< size_t > & times ) const
inlineprotectedinherited

Definition at line 86 of file CaloGPUTimed.h.

87 {
88 size_t old_size;
89 {
90 std::unique_lock<std::shared_mutex> lock(m_timeMutex);
91 old_size = m_times.size();
92 m_times.resize(old_size + times.size());
93 m_eventNumbers.push_back(event_num);
94 }
95 {
96 std::shared_lock<std::shared_mutex> lock(m_timeMutex);
97 for (size_t i = 0; i < times.size(); ++i)
98 {
99 m_times[old_size + i] = times[i];
100 }
101 }
102 }

◆ record_times_helper() [1/3]

template<class Arg>
void CaloGPUTimed::record_times_helper ( const size_t index,
Arg && arg ) const
inlineprivateinherited

Definition at line 70 of file CaloGPUTimed.h.

71 {
72 // coverity[missing_lock]
73 m_times[index] = std::forward<Arg>(arg);
74
75 //This is called within a function that holds the lock itself.
76 }
str index
Definition DeMoScan.py:362

◆ record_times_helper() [2/3]

void CaloGPUTimed::record_times_helper ( const size_t ) const
inlineprivateinherited

Definition at line 64 of file CaloGPUTimed.h.

65 {
66 //Do nothing
67 }

◆ record_times_helper() [3/3]

template<class ... Args>
void CaloGPUTimed::record_times_helper ( size_t index,
Args &&... args ) const
inlineprivateinherited

Definition at line 79 of file CaloGPUTimed.h.

80 {
81 (record_times_helper(index++, std::forward<Args>(args)), ...);
82 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE [1/2]

std::vector<size_t> m_eventNumbers CaloGPUTimed::ATLAS_THREAD_SAFE
mutableprotectedinherited

Vector to hold the event numbers to be recorded if necessary.

Definition at line 40 of file CaloGPUTimed.h.

◆ ATLAS_THREAD_SAFE [2/2]

std::vector<size_t> m_times CaloGPUTimed::ATLAS_THREAD_SAFE
mutableprotectedinherited

Vector to hold execution times to be recorded if necessary.

Definition at line 35 of file CaloGPUTimed.h.

◆ m_calo_id

const CaloCell_ID* BasicGPUToAthenaImporter::m_calo_id {nullptr}
private

Pointer to Calo ID Helper.

Definition at line 72 of file BasicGPUToAthenaImporter.h.

72{nullptr};

◆ m_cellsKey

SG::ReadHandleKey<CaloCellContainer> BasicGPUToAthenaImporter::m_cellsKey {this, "CellsName", "", "Name(s) of Cell Containers"}
private

vector of names of the cell containers to use as input.

Definition at line 58 of file BasicGPUToAthenaImporter.h.

58{this, "CellsName", "", "Name(s) of Cell Containers"};

◆ m_clusterSize

xAOD::CaloCluster::ClusterSize BasicGPUToAthenaImporter::m_clusterSize
private

Definition at line 63 of file BasicGPUToAthenaImporter.h.

◆ m_clusterSizeString

Gaudi::Property<std::string> BasicGPUToAthenaImporter::m_clusterSizeString {this, "ClusterSize", "Topo_420", "The size/type of the clusters"}
private

Cluster size. Should be set accordingly to the threshold.

Definition at line 61 of file BasicGPUToAthenaImporter.h.

61{this, "ClusterSize", "Topo_420", "The size/type of the clusters"};

◆ m_measureTimes

Gaudi::Property<bool> CaloGPUTimed::m_measureTimes
protectedinherited

If true, times are recorded to the file given by m_timeFileName.

Defaults to false.

Definition at line 46 of file CaloGPUTimed.h.

◆ m_missingCellsToFill

Gaudi::Property<std::vector<int> > BasicGPUToAthenaImporter::m_missingCellsToFill {this, "MissingCellsToFill", {}, "Force fill these cells as disabled on empty containers."}
private

Cell indices to fill as disabled cells (useful if the cell vector is always missing the same cells).

Definition at line 67 of file BasicGPUToAthenaImporter.h.

67{this, "MissingCellsToFill", {}, "Force fill these cells as disabled on empty containers."};

◆ m_saveUncalibrated

Gaudi::Property<bool> BasicGPUToAthenaImporter::m_saveUncalibrated {this, "SaveUncalibratedSignalState", true, "Use CaloClusterKineHelper::calculateKine instead of GPU-calculated cluster properties"}
private

if set to true, the uncalibrated state is saved when importing the clusters.

Default is true.

Definition at line 77 of file BasicGPUToAthenaImporter.h.

77{this, "SaveUncalibratedSignalState", true, "Use CaloClusterKineHelper::calculateKine instead of GPU-calculated cluster properties"};

◆ m_streamTool

ToolHandle<AthCUDA::IStreamTool> BasicGPUToAthenaImporter::m_streamTool {this, "StreamTool", "", "CUDA stream tool."}
private

Tool providing the CUDA stream to use.

Definition at line 80 of file BasicGPUToAthenaImporter.h.

80{this, "StreamTool", "", "CUDA stream tool."};

◆ m_timeFileName

Gaudi::Property<std::string> CaloGPUTimed::m_timeFileName
protectedinherited

File to which times should be saved.

Definition at line 50 of file CaloGPUTimed.h.

◆ m_timeMutex

std::shared_mutex CaloGPUTimed::m_timeMutex
mutableprotectedinherited

Mutex that is locked when recording times.

Definition at line 32 of file CaloGPUTimed.h.

◆ m_useCPUPropertiesCalculation

Gaudi::Property<bool> BasicGPUToAthenaImporter::m_useCPUPropertiesCalculation {this, "UseCPUClusterPropertiesCalculation", false, "Use CaloClusterKineHelper::calculateKine instead of GPU-calculated cluster properties"}
private

if set to true, cluster properties are (re-)calculated using CaloClusterKineHelper::calculateKine.

Else, the GPU-calculated values are used. Default is false.

Definition at line 53 of file BasicGPUToAthenaImporter.h.

53{this, "UseCPUClusterPropertiesCalculation", false, "Use CaloClusterKineHelper::calculateKine instead of GPU-calculated cluster properties"};

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