ATLAS Offline Software
Loading...
Searching...
No Matches
BasicGPUToAthenaImporter.cxx
Go to the documentation of this file.
1//
2// Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3//
4// Dear emacs, this is -*- c++ -*-
5//
6
8
10
12
13#include <vector>
14#include <algorithm>
15#include <memory>
16
19
20#include "boost/chrono/chrono.hpp"
21#include "boost/chrono/thread_clock.hpp"
22
23using namespace CaloRecGPU;
24
25BasicGPUToAthenaImporter::BasicGPUToAthenaImporter(const std::string & type, const std::string & name, const IInterface * parent):
26 base_class(type, name, parent),
27 CaloGPUTimed(this)
28{
29}
30
31#include "MacroHelpers.h"
32
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}
90
91StatusCode BasicGPUToAthenaImporter::convert (const EventContext & ctx,
92 const ConstantDataHolder &,
93 EventDataHolder & ed,
94 xAOD::CaloClusterContainer * cluster_container) const
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}
154
155
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
Definition of CaloDetDescrManager.
Helpers for checking error return status codes and reporting errors.
Contains some helpful macros to help with repetitive code...
#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.
xAOD::CaloCluster::ClusterSize m_clusterSize
BasicGPUToAthenaImporter(const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode initialize() override
virtual StatusCode finalize() override
Gaudi::Property< std::string > m_clusterSizeString
Cluster size. Should be set accordingly to the threshold.
virtual StatusCode convert(const EventContext &ctx, const CaloRecGPU::ConstantDataHolder &constant_data, CaloRecGPU::EventDataHolder &event_data, xAOD::CaloClusterContainer *cluster_collection) const override
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.
CaloGPUTimed(T *ptr)
void print_times(const std::string &header, const size_t time_size) const
void record_times(const size_t event_num, const std::vector< size_t > &times) const
Holds CPU and GPU versions of the geometry and cell noise information, which are assumed to be consta...
Definition DataHolders.h:27
Holds the mutable per-event information (clusters and cells) and provides utilities to convert betwee...
Definition DataHolders.h:73
void returnToCPU(const MomentsOptionsArray &moments_to_add, CaloRecGPU::CUDA_Helpers::CUDAStreamPtrHolder stream, const bool full_copy=false, const bool clear_GPU=false, const bool synchronize=false, const bool also_return_cells=false)
moments_to_add specifies which moments we will transfer from the GPU.
void exportClusters(void *cluster_collection, const void *cell_collection_link, const MomentsOptionsArray &moments_to_add, const bool sort_clusters=true, const bool save_uncalibrated=true, const bool output_extra_moments=false, const std::vector< int > &extra_cells_to_fill={}, size_t *time_measurements=nullptr)
We are using a void* for API to make this able to compile on the GPU without Athena-specific dependen...
void clear()
Erase all the elements in the collection.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const std::string & name() const
Return the StoreGate ID for the referenced object.
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
static MomentsOptionsArray all()