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<class 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<class T>
T * Find (std::string const &hitCollectionName)
 Get the hit collection for a given SDs.
template<class T>
std::unique_ptr< T > Extract (std::string const &hitCollectionName)
 Extract the hit collection for a given SDs downcasted to the template parameter.
template<class T>
void Record (std::string const &sgKey, std::string const &hitCollectionName, EventContext const &ctx)
 Record the hit collection hitCollectionName to the StoreGate sgKey.
template<class T>
void Record (std::string const &hitCollectionName)
 Overload for Record with the same name for the SG key and hit collection name.
template<class T>
void 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<class T>
void 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 Attributes

Storage m_outputCollections

Detailed Description

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

Definition at line 20 of file HitCollectionMap.h.

Member Typedef Documentation

◆ Storage

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

Definition at line 23 of file HitCollectionMap.h.

◆ StorageIterator

using HitCollectionMap::StorageIterator = typename Storage::iterator

Definition at line 24 of file HitCollectionMap.h.

Member Function Documentation

◆ Emplace()

template<class 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 38 of file HitCollectionMap.h.

38 {
39 static_assert(
40 std::is_base_of_v<HitsVectorBase, HitCollectionT>,
41 "HitCollectionT must be derived from HitsVectorBase");
42 return m_outputCollections.emplace(
43 hitCollectionName, std::make_unique<HitCollectionT>(std::forward<CollectionArgs>(args)...));
44 }

◆ Extract()

template<class T>
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 66 of file HitCollectionMap.h.

66 {
67 static_assert(
68 std::is_base_of_v<HitsVectorBase, T>,
69 "T must be derived from HitsVectorBase");
70 if (auto handle = m_outputCollections.extract(hitCollectionName)) {
71 // we can static cast, the caller must know the type of the hit collection
72 // for a given key
73 return std::unique_ptr<T>(static_cast<T*>(handle.mapped().release()));
74 }
75 return nullptr;
76 }
unsigned long long T

◆ Find()

template<class T>
T * HitCollectionMap::Find ( std::string const & hitCollectionName)
inline

Get the hit collection for a given SDs.

Definition at line 50 of file HitCollectionMap.h.

50 {
51 static_assert(
52 std::is_base_of_v<HitsVectorBase, T>,
53 "T must be derived from HitsVectorBase");
54 auto it = m_outputCollections.find(hitCollectionName);
55 if (it != m_outputCollections.end()) {
56 return static_cast<T*>(it->second.get());
57 }
58 return nullptr;
59 }

◆ 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 29 of file HitCollectionMap.h.

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

◆ Record() [1/2]

template<class T>
void 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 91 of file HitCollectionMap.h.

91 {
92 Record<T>(hitCollectionName, hitCollectionName, Gaudi::Hive::currentContext());
93 }
void Record(std::string const &sgKey, std::string const &hitCollectionName, EventContext const &ctx)
Record the hit collection hitCollectionName to the StoreGate sgKey.

◆ Record() [2/2]

template<class T>
void 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 82 of file HitCollectionMap.h.

82 {
83 SG::WriteHandle<T> handle(sgKey, ctx);
84 handle = Extract<T>(hitCollectionName);
85 }
std::unique_ptr< T > Extract(std::string const &hitCollectionName)
Extract the hit collection for a given SDs downcasted to the template parameter.

◆ TransformAndRecord() [1/2]

template<class T>
void 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 115 of file HitCollectionMap.h.

115 {
116 TransformAndRecord(hitCollectionName, hitCollectionName, Gaudi::Hive::currentContext(), std::move(transform));
117 }
void 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]

template<class T>
void 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 100 of file HitCollectionMap.h.

104 {
105 auto hitColl = Extract<T>(hitCollectionName);
106 transform(*hitColl);
107 SG::WriteHandle<T> handle(sgKey, ctx);
108 handle = std::move(hitColl);
109 }
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 121 of file HitCollectionMap.h.


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