ATLAS Offline Software
Loading...
Searching...
No Matches
BasicGPUToAthenaImporter.cxx
Go to the documentation of this file.
1//
2// Copyright (C) 2002-2025 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;
44 SW_55ele,
45 SW_35ele,
46 SW_37ele,
47 SW_55gam,
48 SW_35gam,
49 SW_37gam,
50 SW_55Econv,
51 SW_35Econv,
52 SW_37Econv,
53 SW_softe,
54 Topo_420,
55 Topo_633,
56 SW_7_11,
57 SuperCluster,
58 Tower_01_01,
59 Tower_005_005,
60 Tower_fixed_area
61 )
62 )
63 //I know Topological Clustering only supports a subset of those,
64 //but this is supposed to be a general data exporting tool...
65 else
66 {
67 //failed = true;
69 }
70 };
71
72 bool size_failed = false;
73 m_clusterSize = get_option_from_string(m_clusterSizeString, size_failed);
74
76 {
77 ATH_MSG_ERROR("Invalid Cluster Size: " << m_clusterSizeString);
78 }
79
80 if (size_failed)
81 {
82 return StatusCode::FAILURE;
83 }
84
85 return StatusCode::SUCCESS;
86}
87
88StatusCode BasicGPUToAthenaImporter::convert (const EventContext & ctx,
89 const ConstantDataHolder &,
90 EventDataHolder & ed,
91 xAOD::CaloClusterContainer * cluster_container) const
92{
93 using clock_type = boost::chrono::thread_clock;
94 auto time_cast = [](const auto & before, const auto & after)
95 {
96 return boost::chrono::duration_cast<boost::chrono::microseconds>(after - before).count();
97 };
98
99 cluster_container->clear();
100
101 const auto start = clock_type::now();
102
103 SG::ReadHandle<CaloCellContainer> cell_collection(m_cellsKey, ctx);
104 if ( !cell_collection.isValid() )
105 {
106 ATH_MSG_ERROR( " Cannot retrieve CaloCellContainer: " << cell_collection.name() );
107 return StatusCode::FAILURE;
108 }
109 const DataLink<CaloCellContainer> cell_collection_link (cell_collection.name(), ctx);
110
111 ed.returnToCPU(MomentsOptionsArray::all(), false, false, true);
112
113 const auto after_send = clock_type::now();
114
115 size_t extra_times[5];
116
117 ed.exportClusters(cluster_container,
118 cell_collection_link,
120 true,
122 false,
124 m_measureTimes ? extra_times : nullptr);
125
126 const auto after_export = clock_type::now();
127
128 for (auto && cluster : *cluster_container)
129 {
130 cluster->setClusterSize(m_clusterSize);
131 }
132
133 const auto after_size = clock_type::now();
134
135 if (m_measureTimes)
136 {
137 record_times(ctx.evt(),
138 time_cast(start, after_send),
139 extra_times[0],
140 extra_times[1],
141 extra_times[2],
142 extra_times[3],
143 extra_times[4],
144 time_cast(after_export, after_size)
145 );
146 }
147
148 return StatusCode::SUCCESS;
149
150}
151
152
154{
155
156 if (m_measureTimes)
157 {
158 print_times("Transfer_from_GPU Cell_Link_Creation Cell_Adding Sorting Filling_Collection Moments Cluster_Size", 7);
159 }
160 return StatusCode::SUCCESS;
161}
#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 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()