5#ifndef HITMANAGEMENT_HITCOLLECTIONMAP_H
6#define HITMANAGEMENT_HITCOLLECTIONMAP_H
11#include <unordered_map>
14#include <GaudiKernel/EventContext.h>
15#include <GaudiKernel/StatusCode.h>
16#include <GaudiKernel/ThreadLocalContext.h>
25 using Storage = std::unordered_map<std::string, std::unique_ptr<HitsVectorBase>>;
31 std::pair<StorageIterator, bool>
Insert(std::string
const& hitCollectionName, std::unique_ptr<HitsVectorBase> hitCollection) {
40 std::pair<StorageIterator, bool>
Emplace(std::string
const& hitCollectionName, CollectionArgs&&... args) {
42 hitCollectionName, std::make_unique<HitCollectionT>(std::forward<CollectionArgs>(args)...));
48 template <AthHitVec::isHitVectorBase T>
49 T*
Find(std::string
const& hitCollectionName) {
52 return dynamic_cast<T*
>(it->second.get());
61 template <AthHitVec::isHitVectorBase T>
62 std::unique_ptr<T>
Extract(std::string
const& hitCollectionName) {
68 auto* baseCollection = it->second.release();
69 auto* collection =
dynamic_cast<T*
>(baseCollection);
71 it->second.reset(baseCollection);
76 return std::unique_ptr<T>{collection};
82 template <AthHitVec::isHitVectorBase T>
83 StatusCode
Record(std::string
const& sgKey, std::string
const& hitCollectionName, EventContext
const& ctx) {
91 template <AthHitVec::isHitVectorBase T>
92 StatusCode
Record(std::string
const& hitCollectionName) {
94 return recordExtracted<T>(hitCollectionName, Gaudi::Hive::currentContext(), std::move(hitColl));
101 template <AthHitVec::isHitVectorBase T>
103 std::string
const& sgKey,
104 std::string
const& hitCollectionName,
105 EventContext
const& ctx,
106 std::function<
void(T&)> transform) {
109 return StatusCode::FAILURE;
118 template <AthHitVec::isHitVectorBase T>
119 StatusCode
TransformAndRecord(std::string
const& hitCollectionName, std::function<
void(T&)> transform) {
120 return TransformAndRecord(hitCollectionName, hitCollectionName, Gaudi::Hive::currentContext(), std::move(transform));
124 template <AthHitVec::isHitVectorBase T>
125 StatusCode
recordExtracted(std::string
const& sgKey, EventContext
const& ctx, std::unique_ptr<T> hitColl) {
127 return StatusCode::FAILURE;
132 return handle.record(std::move(hitColl->container), std::move(hitColl->auxContainer));
135 return handle.record(std::move(hitColl));
Handle class for recording to StoreGate.
Small wrapper around hit collection map to facilitate accessing the hit collection.
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.
Storage m_outputCollections
StatusCode Record(std::string const &sgKey, std::string const &hitCollectionName, EventContext const &ctx)
Record the hit collection hitCollectionName to the StoreGate sgKey.
T * Find(std::string const &hitCollectionName)
Get the hit collection for a given SDs.
std::unique_ptr< T > Extract(std::string const &hitCollectionName)
Extract the hit collection for a given SDs downcasted to the template parameter.
StatusCode Record(std::string const &hitCollectionName)
Overload for Record with the same name for the SG key and hit collection name.
std::pair< StorageIterator, bool > Insert(std::string const &hitCollectionName, std::unique_ptr< HitsVectorBase > hitCollection)
Insert the hit collection for a given SDs.
std::unordered_map< std::string, std::unique_ptr< HitsVectorBase > > Storage
typename Storage::iterator StorageIterator
StatusCode recordExtracted(std::string const &sgKey, EventContext const &ctx, std::unique_ptr< T > hitColl)
std::pair< StorageIterator, bool > Emplace(std::string const &hitCollectionName, CollectionArgs &&... args)
Insert a container in the map with in-place construction.
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...
Define the concept for hit-collection carriers owning an xAOD container and its auxiliary store.
Define the concept that the struct needs to inherit from the HitsVectorBase.