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 return StatusCode::SUCCESS;
87}
88
89StatusCode BasicGPUToAthenaImporter::convert (const EventContext & ctx,
90 const ConstantDataHolder &,
91 EventDataHolder & ed,
92 xAOD::CaloClusterContainer * cluster_container) const
93{
94 using clock_type = boost::chrono::thread_clock;
95 auto time_cast = [](const auto & before, const auto & after)
96 {
97 return boost::chrono::duration_cast<boost::chrono::microseconds>(after - before).count();
98 };
99
100 cluster_container->clear();
101
102 const auto start = clock_type::now();
103
104 SG::ReadHandle<CaloCellContainer> cell_collection(m_cellsKey, ctx);
105 if ( !cell_collection.isValid() )
106 {
107 ATH_MSG_ERROR( " Cannot retrieve CaloCellContainer: " << cell_collection.name() );
108 return StatusCode::FAILURE;
109 }
110 const DataLink<CaloCellContainer> cell_collection_link (cell_collection.name(), ctx);
111
112 ed.returnToCPU(MomentsOptionsArray::all(), false, false, true);
113
114 const auto after_send = clock_type::now();
115
116 size_t extra_times[5];
117
118 ed.exportClusters(cluster_container,
119 cell_collection_link,
121 true,
123 false,
125 m_measureTimes ? extra_times : nullptr);
126
127 const auto after_export = clock_type::now();
128
129 for (auto && cluster : *cluster_container)
130 {
131 cluster->setClusterSize(m_clusterSize);
132 }
133
134 const auto after_size = clock_type::now();
135
136 if (m_measureTimes)
137 {
138 record_times(ctx.evt(),
139 time_cast(start, after_send),
140 extra_times[0],
141 extra_times[1],
142 extra_times[2],
143 extra_times[3],
144 extra_times[4],
145 time_cast(after_export, after_size)
146 );
147 }
148
149 return StatusCode::SUCCESS;
150
151}
152
153
155{
156
157 if (m_measureTimes)
158 {
159 print_times("Transfer_from_GPU Cell_Link_Creation Cell_Adding Sorting Filling_Collection Moments Cluster_Size", 7);
160 }
161 return StatusCode::SUCCESS;
162}
#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.
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, const bool full_copy=false, const bool clear_GPU=false, const bool synchronize=false, CaloRecGPU::CUDA_Helpers::CUDAStreamPtrHolder stream={}, 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()