5 #ifndef HITMANAGEMENT_HITCOLLECTIONMAP_H
6 #define HITMANAGEMENT_HITCOLLECTIONMAP_H
10 #include <type_traits>
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) {
84 handle = Extract<T>(hitCollectionName);
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,
105 auto hitColl = Extract<T>(hitCollectionName);
108 handle = std::move(hitColl);