ATLAS Offline Software
Loading...
Searching...
No Matches
HitCollectionMap Class Reference

Small wrapper around hit collection map to facilitate accessing the hit collection. More...

#include <HitCollectionMap.h>

Collaboration diagram for HitCollectionMap:

Public Types

using Storage = std::unordered_map<std::string, std::unique_ptr<HitsVectorBase>>
using StorageIterator = typename Storage::iterator

Public Member Functions

std::pair< StorageIterator, bool > Insert (std::string const &hitCollectionName, std::unique_ptr< HitsVectorBase > hitCollection)
 Insert the hit collection for a given SDs.
template<AthHitVec::isHitVectorBase HitCollectionT, class... CollectionArgs>
std::pair< StorageIterator, bool > Emplace (std::string const &hitCollectionName, CollectionArgs &&... args)
 Insert a container in the map with in-place construction.
template<AthHitVec::isHitVectorBase T>
T * Find (std::string const &hitCollectionName)
 Get the hit collection for a given SDs.
template<AthHitVec::isHitVectorBase T>
std::unique_ptr< T > Extract (std::string const &hitCollectionName)
 Extract the hit collection for a given SDs downcasted to the template parameter.
template<AthHitVec::isHitVectorBase T>
StatusCode Record (std::string const &sgKey, std::string const &hitCollectionName, EventContext const &ctx)
 Record the hit collection hitCollectionName to the StoreGate sgKey.
template<AthHitVec::isHitVectorBase T>
StatusCode Record (std::string const &hitCollectionName)
 Overload for Record with the same name for the SG key and hit collection name.
template<AthHitVec::isHitVectorBase T>
StatusCode TransformAndRecord (std::string const &sgKey, std::string const &hitCollectionName, EventContext const &ctx, std::function< void(T &)> transform)
 Record the hit collection hitCollectionName to the StoreGate sgKey, applying a transformation function to the hit collection before recording it.
template<AthHitVec::isHitVectorBase T>
StatusCode TransformAndRecord (std::string const &hitCollectionName, std::function< void(T &)> transform)
 Overload for TransformAndRecord with the same name for the SG key and hit collection name.

Private Member Functions

template<AthHitVec::isHitVectorBase T>
StatusCode recordExtracted (std::string const &sgKey, EventContext const &ctx, std::unique_ptr< T > hitColl)

Private Attributes

Storage m_outputCollections

Detailed Description

Small wrapper around hit collection map to facilitate accessing the hit collection.

Definition at line 22 of file HitCollectionMap.h.

Member Typedef Documentation

◆ Storage

using HitCollectionMap::Storage = std::unordered_map<std::string, std::unique_ptr<HitsVectorBase>>

Definition at line 25 of file HitCollectionMap.h.

◆ StorageIterator

using HitCollectionMap::StorageIterator = typename Storage::iterator

Definition at line 26 of file HitCollectionMap.h.

Member Function Documentation

◆ Emplace()

template<AthHitVec::isHitVectorBase HitCollectionT, class... CollectionArgs>
std::pair< StorageIterator, bool > HitCollectionMap::Emplace ( std::string const & hitCollectionName,
CollectionArgs &&... args )
inline

Insert a container in the map with in-place construction.

Definition at line 40 of file HitCollectionMap.h.

40 {
41 return m_outputCollections.emplace(
42 hitCollectionName, std::make_unique<HitCollectionT>(std::forward<CollectionArgs>(args)...));
43 }

◆ Extract()

std::unique_ptr< T > HitCollectionMap::Extract ( std::string const & hitCollectionName)
inline

Extract the hit collection for a given SDs downcasted to the template parameter.

Definition at line 62 of file HitCollectionMap.h.

62 {
63 auto it = m_outputCollections.find(hitCollectionName);
64 if (it == m_outputCollections.end()) {
65 return nullptr;
66 }
67
68 auto* baseCollection = it->second.release();
69 auto* collection = dynamic_cast<T*>(baseCollection);
70 if (!collection) {
71 it->second.reset(baseCollection);
72 return nullptr;
73 }
74
75 m_outputCollections.erase(it);
76 return std::unique_ptr<T>{collection};
77 }
unsigned long long T

◆ Find()

T * HitCollectionMap::Find ( std::string const & hitCollectionName)
inline

Get the hit collection for a given SDs.

Definition at line 49 of file HitCollectionMap.h.

49 {
50 auto it = m_outputCollections.find(hitCollectionName);
51 if (it != m_outputCollections.end()) {
52 return dynamic_cast<T*>(it->second.get());
53 }
54 return nullptr;
55 }

◆ Insert()

std::pair< StorageIterator, bool > HitCollectionMap::Insert ( std::string const & hitCollectionName,
std::unique_ptr< HitsVectorBase > hitCollection )
inline

Insert the hit collection for a given SDs.

Definition at line 31 of file HitCollectionMap.h.

31 {
32 // Store the hit collection in a map, using the hitCollectionName as key.
33 return m_outputCollections.insert({hitCollectionName, std::move(hitCollection)});
34 }

◆ Record() [1/2]

StatusCode HitCollectionMap::Record ( std::string const & hitCollectionName)
inline

Overload for Record with the same name for the SG key and hit collection name.

Definition at line 92 of file HitCollectionMap.h.

92 {
93 auto hitColl = Extract<T>(hitCollectionName);
94 return recordExtracted<T>(hitCollectionName, Gaudi::Hive::currentContext(), std::move(hitColl));
95 }
std::unique_ptr< T > Extract(std::string const &hitCollectionName)
Extract the hit collection for a given SDs downcasted to the template parameter.
StatusCode recordExtracted(std::string const &sgKey, EventContext const &ctx, std::unique_ptr< T > hitColl)

◆ Record() [2/2]

StatusCode HitCollectionMap::Record ( std::string const & sgKey,
std::string const & hitCollectionName,
EventContext const & ctx )
inline

Record the hit collection hitCollectionName to the StoreGate sgKey.

Definition at line 83 of file HitCollectionMap.h.

83 {
84 auto hitColl = Extract<T>(hitCollectionName);
85 return recordExtracted<T>(sgKey, ctx, std::move(hitColl));
86 }

◆ recordExtracted()

StatusCode HitCollectionMap::recordExtracted ( std::string const & sgKey,
EventContext const & ctx,
std::unique_ptr< T > hitColl )
inlineprivate

Definition at line 125 of file HitCollectionMap.h.

125 {
126 if (!hitColl) {
127 return StatusCode::FAILURE;
128 }
129
130 if constexpr (AthHitVec::isAuxStoreHitCollection<T>) {
131 SG::WriteHandle<typename T::container_type> handle{sgKey, ctx};
132 return handle.record(std::move(hitColl->container), std::move(hitColl->auxContainer));
133 } else {
134 SG::WriteHandle<T> handle{sgKey, ctx};
135 return handle.record(std::move(hitColl));
136 }
137 }
virtual void handle(const Incident &inc)
Handle end of run incidents to save the metadata at that point.

◆ TransformAndRecord() [1/2]

StatusCode HitCollectionMap::TransformAndRecord ( std::string const & hitCollectionName,
std::function< void(T &)> transform )
inline

Overload for TransformAndRecord with the same name for the SG key and hit collection name.

Definition at line 119 of file HitCollectionMap.h.

119 {
120 return TransformAndRecord(hitCollectionName, hitCollectionName, Gaudi::Hive::currentContext(), std::move(transform));
121 }
StatusCode TransformAndRecord(std::string const &sgKey, std::string const &hitCollectionName, EventContext const &ctx, std::function< void(T &)> transform)
Record the hit collection hitCollectionName to the StoreGate sgKey, applying a transformation functio...

◆ TransformAndRecord() [2/2]

StatusCode HitCollectionMap::TransformAndRecord ( std::string const & sgKey,
std::string const & hitCollectionName,
EventContext const & ctx,
std::function< void(T &)> transform )
inline

Record the hit collection hitCollectionName to the StoreGate sgKey, applying a transformation function to the hit collection before recording it.

Definition at line 102 of file HitCollectionMap.h.

106 {
107 auto hitColl = Extract<T>(hitCollectionName);
108 if (!hitColl) {
109 return StatusCode::FAILURE;
110 }
111 transform(*hitColl);
112 return recordExtracted<T>(sgKey, ctx, std::move(hitColl));
113 }
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.

Member Data Documentation

◆ m_outputCollections

Storage HitCollectionMap::m_outputCollections
private

Definition at line 140 of file HitCollectionMap.h.


The documentation for this class was generated from the following file: