ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
CaloGPUOutput Class Reference

Standard tool to output the GPU data representation to the non-standard file format that we have been using for plotting and validation purposes. More...

#include <CaloGPUOutput.h>

Inheritance diagram for CaloGPUOutput:
Collaboration diagram for CaloGPUOutput:

Public Member Functions

 CaloGPUOutput (const std::string &type, const std::string &name, const IInterface *parent)
 
virtual StatusCode execute (const EventContext &ctx, const CaloRecGPU::ConstantDataHolder &constant_data, CaloRecGPU::EventDataHolder &event_data, void *temporary_buffer) const override
 
virtual ~CaloGPUOutput ()=default
 

Private Attributes

Gaudi::Property< std::string > m_savePath {this, "SavePath", "./saved_clusters", "Path to where the files should be saved"}
 The path specifying the folder to which the files should be saved. More...
 
Gaudi::Property< std::string > m_filePrefix {this, "FilePrefix", "", "Prefix of the saved files"}
 The prefix of the saved files. More...
 
Gaudi::Property< std::string > m_fileSuffix {this, "FileSuffix", "", "Suffix of the saved files"}
 The suffix of the saved files. More...
 
Gaudi::Property< unsigned int > m_numWidth {this, "NumberWidth", 9, "The number of digits to reserve for the events"}
 The number of digits to reserve for the events. More...
 
Gaudi::Property< bool > m_sortedAndCutClusters {this, "UseSortedAndCutClusters", true, "Sort the clusters by transverse energy, apply a cut and ensure contiguous tags"}
 If true, sort the clusters by transverse energy and compactify the tags to ensure sequentiality. More...
 
Gaudi::Property< bool > m_onlyCellInfo {this, "OnlyOutputCellInfo", false, "Only output cell info"}
 If true, only output cell info (useful for reducing disk usage when running the full standalone version of the algorithms). More...
 
std::atomic< bool > m_constantDataSaved
 A flag to signal that the constant data has been adequately saved. More...
 
std::mutex m_mutex
 This mutex is locked when saving the constant data on the first event to ensure thread safety. More...
 

Detailed Description

Standard tool to output the GPU data representation to the non-standard file format that we have been using for plotting and validation purposes.

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 There are likely more elegant/general/generic/portable solutions, some of which might even avoid Root too, but our workflow was built around this one...

Definition at line 27 of file CaloGPUOutput.h.

Constructor & Destructor Documentation

◆ CaloGPUOutput()

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

Definition at line 15 of file CaloGPUOutput.cxx.

15  :
16  base_class(type, name, parent),
17  m_constantDataSaved(false)
18 {
19 }

◆ ~CaloGPUOutput()

virtual CaloGPUOutput::~CaloGPUOutput ( )
virtualdefault

Member Function Documentation

◆ execute()

StatusCode CaloGPUOutput::execute ( const EventContext &  ctx,
const CaloRecGPU::ConstantDataHolder constant_data,
CaloRecGPU::EventDataHolder event_data,
void *  temporary_buffer 
) const
overridevirtual

Definition at line 21 of file CaloGPUOutput.cxx.

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,
155 
157  {
158  return StatusCode::FAILURE;
159  }
160 
161  return StatusCode::SUCCESS;
162 
163 
164 }

Member Data Documentation

◆ m_constantDataSaved

std::atomic<bool> CaloGPUOutput::m_constantDataSaved
mutableprivate

A flag to signal that the constant data has been adequately saved.

This is required for everything to work properly in a multi-threaded context...

Definition at line 79 of file CaloGPUOutput.h.

◆ m_filePrefix

Gaudi::Property<std::string> CaloGPUOutput::m_filePrefix {this, "FilePrefix", "", "Prefix of the saved files"}
private

The prefix of the saved files.

Empty string by default.

Definition at line 53 of file CaloGPUOutput.h.

◆ m_fileSuffix

Gaudi::Property<std::string> CaloGPUOutput::m_fileSuffix {this, "FileSuffix", "", "Suffix of the saved files"}
private

The suffix of the saved files.

Empty string by default.

Definition at line 58 of file CaloGPUOutput.h.

◆ m_mutex

std::mutex CaloGPUOutput::m_mutex
mutableprivate

This mutex is locked when saving the constant data on the first event to ensure thread safety.

Otherwise, it's unused.

Definition at line 84 of file CaloGPUOutput.h.

◆ m_numWidth

Gaudi::Property<unsigned int> CaloGPUOutput::m_numWidth {this, "NumberWidth", 9, "The number of digits to reserve for the events"}
private

The number of digits to reserve for the events.

9 by default.

Definition at line 63 of file CaloGPUOutput.h.

◆ m_onlyCellInfo

Gaudi::Property<bool> CaloGPUOutput::m_onlyCellInfo {this, "OnlyOutputCellInfo", false, "Only output cell info"}
private

If true, only output cell info (useful for reducing disk usage when running the full standalone version of the algorithms).

Definition at line 73 of file CaloGPUOutput.h.

◆ m_savePath

Gaudi::Property<std::string> CaloGPUOutput::m_savePath {this, "SavePath", "./saved_clusters", "Path to where the files should be saved"}
private

The path specifying the folder to which the files should be saved.

Default ./saved_clusters

Definition at line 48 of file CaloGPUOutput.h.

◆ m_sortedAndCutClusters

Gaudi::Property<bool> CaloGPUOutput::m_sortedAndCutClusters {this, "UseSortedAndCutClusters", true, "Sort the clusters by transverse energy, apply a cut and ensure contiguous tags"}
private

If true, sort the clusters by transverse energy and compactify the tags to ensure sequentiality.

Definition at line 68 of file CaloGPUOutput.h.


The documentation for this class was generated from the following files:
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
CaloRecGPU::Helpers::SimpleHolder
Holds one objects of type \T in memory context Context.
Definition: Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h:1074
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
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
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
CaloRecGPU::NCaloCells
constexpr int NCaloCells
Definition: BaseDefinitions.h:12
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
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:76
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
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623
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
CaloGPUOutput::m_fileSuffix
Gaudi::Property< std::string > m_fileSuffix
The suffix of the saved files.
Definition: CaloGPUOutput.h:58
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