5#ifndef HITMANAGEMENT_HITCOLLECTIONMAP_H
6#define HITMANAGEMENT_HITCOLLECTIONMAP_H
11#include <unordered_map>
14#include <GaudiKernel/EventContext.h>
15#include <GaudiKernel/ThreadLocalContext.h>
23 using Storage = std::unordered_map<std::string, std::unique_ptr<HitsVectorBase>>;
29 std::pair<StorageIterator, bool>
Insert(std::string
const& hitCollectionName, std::unique_ptr<HitsVectorBase> hitCollection) {
37 template<
class HitCollectionT,
class... CollectionArgs>
38 std::pair<StorageIterator, bool>
Emplace(std::string
const& hitCollectionName, CollectionArgs&&... args) {
40 std::is_base_of_v<HitsVectorBase, HitCollectionT>,
41 "HitCollectionT must be derived from HitsVectorBase");
43 hitCollectionName, std::make_unique<HitCollectionT>(std::forward<CollectionArgs>(args)...));
50 T*
Find(std::string
const& hitCollectionName) {
52 std::is_base_of_v<HitsVectorBase, T>,
53 "T must be derived from HitsVectorBase");
56 return static_cast<T*
>(it->second.get());
66 std::unique_ptr<T>
Extract(std::string
const& hitCollectionName) {
68 std::is_base_of_v<HitsVectorBase, T>,
69 "T must be derived from HitsVectorBase");
73 return std::unique_ptr<T>(
static_cast<T*
>(handle.mapped().release()));
82 void Record(std::string
const& sgKey, std::string
const& hitCollectionName, EventContext
const& ctx) {
91 void Record(std::string
const& hitCollectionName) {
92 Record<T>(hitCollectionName, hitCollectionName, Gaudi::Hive::currentContext());
101 std::string
const& sgKey,
102 std::string
const& hitCollectionName,
103 EventContext
const& ctx,
104 std::function<
void(T&)> transform) {
108 handle = std::move(hitColl);
116 TransformAndRecord(hitCollectionName, hitCollectionName, Gaudi::Hive::currentContext(), std::move(transform));
Handle class for recording to StoreGate.
Small wrapper around hit collection map to facilitate accessing the hit collection.
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...
void Record(std::string const &sgKey, std::string const &hitCollectionName, EventContext const &ctx)
Record the hit collection hitCollectionName to the StoreGate sgKey.
Storage m_outputCollections
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.
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
std::pair< StorageIterator, bool > Emplace(std::string const &hitCollectionName, CollectionArgs &&... args)
Insert a container in the map with in-place construction.
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.
void Record(std::string const &hitCollectionName)
Overload for Record with the same name for the SG key and hit collection name.