ATLAS Offline Software
Loading...
Searching...
No Matches
IDCCacheCreatorBase.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef ViewAlgs_IDCCacheCreatorBase_h
6#define ViewAlgs_IDCCacheCreatorBase_h
7
9#include <atomic>
12
14 public:
16 IDCCacheCreatorBase(const std::string &name,ISvcLocator *pSvcLocator);
18 virtual ~IDCCacheCreatorBase()=default;
19protected:
20 template<bool checkKey = true, typename T>
21 StatusCode createContainer(const SG::WriteHandleKey<T>& , long unsigned int , const EventContext& ) const;
22 template<bool checkKey = true, typename T, typename X>
23 StatusCode createValueContainer(const SG::WriteHandleKey<T>& , long unsigned int , const EventContext&, const X& defaultValue ) const;
24 mutable std::atomic_flag m_disableWarningCheck ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT;
25 bool isInsideView(const EventContext&) const;
26 StatusCode checkInsideViewOnce(const EventContext&) const;
27};
28
29
30template<bool checkKey, typename T>
31StatusCode IDCCacheCreatorBase::createContainer(const SG::WriteHandleKey<T>& containerKey, long unsigned int size, const EventContext& ctx) const{
32 static_assert(std::is_base_of<EventContainers::IdentifiableCacheBase, T>::value, "Expects a IdentifiableCache Class" );
33 if constexpr (checkKey){
34 if(containerKey.key().empty()){
35 ATH_MSG_DEBUG( "Creation of container "<< containerKey.key() << " is disabled (no name specified)");
36 return StatusCode::SUCCESS;
37 }
38 }
39 SG::WriteHandle<T> ContainerCacheKey(containerKey, ctx);
40 ATH_CHECK( ContainerCacheKey.recordNonConst ( std::make_unique<T>(IdentifierHash(size), nullptr) ));
41 ATH_MSG_DEBUG( "Container "<< containerKey.key() << " created to hold " << size );
42 return StatusCode::SUCCESS;
43}
44
45template<bool checkKey, typename T, typename X>
46StatusCode IDCCacheCreatorBase::createValueContainer(const SG::WriteHandleKey<T>& containerKey, long unsigned int size, const EventContext& ctx, const X& defaultValue) const{
47 static_assert(std::is_base_of<IdentifiableValueCache<X>, T>::value, "Expects a IdentifiableValueCache Class" );
48 if constexpr (checkKey){
49 if(containerKey.key().empty()){
50 ATH_MSG_DEBUG( "Creation of container "<< containerKey.key() << " is disabled (no name specified)");
51 return StatusCode::SUCCESS;
52 }
53 }
54 SG::WriteHandle<T> ContainerCacheKey(containerKey, ctx);
55 ATH_CHECK( ContainerCacheKey.recordNonConst ( std::make_unique<T>(size, defaultValue) ));
56 ATH_MSG_DEBUG( "ValueContainer "<< containerKey.key() << " created to hold " << size );
57 return StatusCode::SUCCESS;
58}
59
60#endif
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
An algorithm that can be simultaneously executed in multiple threads.
StatusCode createValueContainer(const SG::WriteHandleKey< T > &, long unsigned int, const EventContext &, const X &defaultValue) const
std::atomic_flag m_disableWarningCheck ATLAS_THREAD_SAFE
IDCCacheCreatorBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
StatusCode checkInsideViewOnce(const EventContext &) const
bool isInsideView(const EventContext &) const
virtual ~IDCCacheCreatorBase()=default
Destructor.
StatusCode createContainer(const SG::WriteHandleKey< T > &, long unsigned int, const EventContext &) const
This is a "hash" representation of an Identifier.
const std::string & key() const
Return the StoreGate ID for the referenced object.
Property holding a SG store/key/clid from which a WriteHandle is made.
StatusCode recordNonConst(std::unique_ptr< T > data)
Record a non-const object to the store.