Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
CaloGPUOutput.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 
7 #include "CaloGPUOutput.h"
8 
10 
11 #include <unordered_map>
12 
13 using namespace CaloRecGPU;
14 
15 CaloGPUOutput::CaloGPUOutput(const std::string & type, const std::string & name, const IInterface * parent):
16  base_class(type, name, parent),
17  m_constantDataSaved(false)
18 {
19 }
20 
21 StatusCode CaloGPUOutput::execute(const EventContext & ctx, const ConstantDataHolder & constant_data, EventDataHolder & event_data, void * /*temporary_buffer*/) const
22 {
23  if (!m_constantDataSaved.load())
24  {
25  std::lock_guard<std::mutex> lock_guard(m_mutex);
26  if (!m_constantDataSaved.load())
27  {
28  const auto err1 = StandaloneDataIO::save_constants_to_folder(std::string(m_savePath), constant_data.m_geometry_dev,
31  {
32  return StatusCode::FAILURE;
33  }
34  m_constantDataSaved.store(true);
35  }
36  }
37 
39 
40  if (m_onlyCellInfo)
41  {
42  const auto err2 = StandaloneDataIO::save_cell_info_to_folder(ctx.evt(), std::string(m_savePath), cell_info, m_filePrefix, m_fileSuffix, m_numWidth);
43 
45  {
46  return StatusCode::FAILURE;
47  }
48 
49  return StatusCode::SUCCESS;
50  }
51 
52 
55 
56  std::unordered_map<int, int> tag_map;
57 
59  {
60  std::vector<int> cluster_order(clusters->number);
61 
62  std::iota(cluster_order.begin(), cluster_order.end(), 0);
63 
64  std::sort(cluster_order.begin(), cluster_order.end(), [&](const int a, const int b)
65  {
66  if (clusters->seedCellID[a] < 0)
67  {
68  return false;
69  //This means that clusters with no cells
70  //(marked as invalid) always compare lower,
71  //so they appear in the end.
72  }
73  else if (clusters->seedCellID[b] < 0)
74  {
75  return true;
76  }
77  return clusters->clusterEt[a] > clusters->clusterEt[b];
78  } );
79 
80  int real_cluster_numbers = clusters->number;
81 
82  for (size_t i = 0; i < cluster_order.size(); ++i)
83  {
84  const int this_id = cluster_order[i];
85  if (clusters->seedCellID[this_id] < 0)
86  {
87  tag_map[this_id] = -1;
88  --real_cluster_numbers;
89  }
90  else
91  {
92  tag_map[this_id] = i;
93  }
94  }
95 
96  const Helpers::CPU_object<ClusterInfoArr> temp_clusters(clusters);
97 
98  clusters->number = real_cluster_numbers;
99 
100  for (int i = 0; i < temp_clusters->number; ++i)
101  {
102  clusters->clusterEnergy[i] = temp_clusters->clusterEnergy[cluster_order[i]];
103  clusters->clusterEt[i] = temp_clusters->clusterEt[cluster_order[i]];
104  clusters->clusterEta[i] = temp_clusters->clusterEta[cluster_order[i]];
105  clusters->clusterPhi[i] = temp_clusters->clusterPhi[cluster_order[i]];
106  clusters->seedCellID[i] = temp_clusters->seedCellID[cluster_order[i]];
107  }
108 
109  }
110  size_t shared_count = 0;
111  for (int i = 0; i < NCaloCells; ++i)
112  {
113  if (!cell_info->is_valid(i))
114  {
115  continue;
116  }
117  const ClusterTag this_tag = cell_state->clusterTag[i];
118  if (!this_tag.is_part_of_cluster())
119  {
120  cell_state->clusterTag[i] = ClusterTag::make_invalid_tag();
121  }
122  else if (this_tag.is_part_of_cluster() && m_sortedAndCutClusters)
123  {
124  const int old_idx = this_tag.cluster_index();
125  const int new_idx = tag_map[old_idx];
126  const int old_idx2 = this_tag.is_shared_between_clusters() ? this_tag.secondary_cluster_index() : -1;
127  const int new_idx2 = old_idx2 >= 0 ? tag_map[old_idx2] : -1;
128  if (new_idx < 0 && new_idx2 < 0)
129  {
130  cell_state->clusterTag[i] = ClusterTag::make_invalid_tag();
131  }
132  else if (new_idx < 0)
133  {
134  cell_state->clusterTag[i] = ClusterTag::make_tag(new_idx2);
135  }
136  else if (new_idx2 < 0)
137  {
138  cell_state->clusterTag[i] = ClusterTag::make_tag(new_idx);
139  }
140  else
141  {
142  ++shared_count;
143  cell_state->clusterTag[i] = ClusterTag::make_tag(new_idx, this_tag.secondary_cluster_weight(), new_idx2);
144  }
145  }
146  }
147 
148 
149  ATH_MSG_INFO("Clusters: " << clusters->number << " (" << tag_map.size() << " total)");
150  ATH_MSG_INFO("Shared Cells: " << shared_count);
151 
152 
153  const auto err2 = StandaloneDataIO::save_event_to_folder(ctx.evt(), std::string(m_savePath), cell_info, cell_state, clusters,
154  m_filePrefix, m_fileSuffix, m_numWidth);
155 
157  {
158  return StatusCode::FAILURE;
159  }
160 
161  return StatusCode::SUCCESS;
162 
163 
164 }
CaloGPUOutput.h
StandaloneDataIO::save_constants_to_folder
static ErrorState save_constants_to_folder(const std::filesystem::path &folder, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::GeometryArr > &geo, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellNoiseArr > &noise, const std::string &prefix="", const std::string &suffix="", const bool output_errors=true)
Definition: StandaloneDataIO.h:295
CaloRecGPU::ClusterTag::secondary_cluster_index
constexpr int32_t secondary_cluster_index() const
Definition: TagDefinitions.h:253
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloRecGPU::ClusterTag::is_shared_between_clusters
constexpr bool is_shared_between_clusters() const
Definition: TagDefinitions.h:273
CaloGPUOutput::execute
virtual StatusCode execute(const EventContext &ctx, const CaloRecGPU::ConstantDataHolder &constant_data, CaloRecGPU::EventDataHolder &event_data, void *temporary_buffer) const override
Definition: CaloGPUOutput.cxx:21
CaloRecGPU::Helpers::SimpleHolder
Holds one objects of type \T in memory context Context.
Definition: Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h:1067
CaloRecGPU::EventDataHolder::m_cell_state_dev
CaloRecGPU::Helpers::CUDA_object< CaloRecGPU::CellStateArr > m_cell_state_dev
Definition: DataHolders.h:89
CaloRecGPU::EventDataHolder::m_clusters_dev
CaloRecGPU::Helpers::CUDA_object< CaloRecGPU::ClusterInfoArr > m_clusters_dev
Definition: DataHolders.h:90
StandaloneDataIO::save_event_to_folder
static ErrorState save_event_to_folder(const size_t event_number, const std::filesystem::path &folder, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellInfoArr > &cell_info, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellStateArr > &cell_state, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::ClusterInfoArr > &clusters, const std::string &prefix="", const std::string &suffix="", const unsigned int num_width=9, const bool output_errors=true)
Definition: StandaloneDataIO.h:323
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
CaloRecGPU::ClusterTag
Definition: TagDefinitions.h:222
CaloRecGPU::EventDataHolder::m_cell_info_dev
CaloRecGPU::Helpers::CUDA_object< CaloRecGPU::CellInfoArr > m_cell_info_dev
Definition: DataHolders.h:88
CaloRecGPU::ClusterTag::cluster_index
constexpr int32_t cluster_index() const
Definition: TagDefinitions.h:243
StandaloneDataIO::ErrorState::OK
@ OK
CaloRecGPU::EventDataHolder
Definition: DataHolders.h:35
CaloGPUOutput::m_onlyCellInfo
Gaudi::Property< bool > m_onlyCellInfo
If true, only output cell info (useful for reducing disk usage when running the full standalone versi...
Definition: CaloGPUOutput.h:73
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CaloGPUOutput::m_numWidth
Gaudi::Property< unsigned int > m_numWidth
The number of digits to reserve for the events.
Definition: CaloGPUOutput.h:63
test_pyathena.parent
parent
Definition: test_pyathena.py:15
StandaloneDataIO.h
CaloRecGPU::NCaloCells
constexpr int NCaloCells
Definition: BaseDefinitions.h:13
CaloRecGPU::ConstantDataHolder::m_cell_noise_dev
CaloRecGPU::Helpers::CUDA_object< CaloRecGPU::CellNoiseArr > m_cell_noise_dev
Definition: DataHolders.h:30
CaloGPUOutput::m_savePath
Gaudi::Property< std::string > m_savePath
The path specifying the folder to which the files should be saved.
Definition: CaloGPUOutput.h:48
CaloRecGPU::ConstantDataHolder::m_geometry_dev
CaloRecGPU::Helpers::CUDA_object< CaloRecGPU::GeometryArr > m_geometry_dev
Definition: DataHolders.h:28
CaloGPUOutput::CaloGPUOutput
CaloGPUOutput(const std::string &type, const std::string &name, const IInterface *parent)
Definition: CaloGPUOutput.cxx:15
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
CaloGPUOutput::m_filePrefix
Gaudi::Property< std::string > m_filePrefix
The prefix of the saved files.
Definition: CaloGPUOutput.h:53
CaloRecGPU::ClusterTag::is_part_of_cluster
constexpr bool is_part_of_cluster() const
Definition: TagDefinitions.h:233
CaloGPUOutput::m_mutex
std::mutex m_mutex
This mutex is locked when saving the constant data on the first event to ensure thread safety.
Definition: CaloGPUOutput.h:84
StandaloneDataIO::save_cell_info_to_folder
static ErrorState save_cell_info_to_folder(const size_t event_number, const std::filesystem::path &folder, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellInfoArr > &cell_info, const std::string &prefix="", const std::string &suffix="", const unsigned int num_width=9, const bool output_errors=true)
Definition: StandaloneDataIO.h:391
a
TList * a
Definition: liststreamerinfos.cxx:10
CaloGPUOutput::m_constantDataSaved
std::atomic< bool > m_constantDataSaved
A flag to signal that the constant data has been adequately saved.
Definition: CaloGPUOutput.h:79
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
CaloRecGPU::ConstantDataHolder
Definition: DataHolders.h:19
CaloGPUOutput::m_fileSuffix
Gaudi::Property< std::string > m_fileSuffix
The suffix of the saved files.
Definition: CaloGPUOutput.h:58
CaloRecGPU
Definition: BaseDefinitions.h:11
CaloRecGPU::ClusterTag::secondary_cluster_weight
constexpr int32_t secondary_cluster_weight() const
Definition: TagDefinitions.h:263
CaloGPUOutput::m_sortedAndCutClusters
Gaudi::Property< bool > m_sortedAndCutClusters
If true, sort the clusters by transverse energy and compactify the tags to ensure sequentiality.
Definition: CaloGPUOutput.h:68