ATLAS Offline Software
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;
19 protected:
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 
30 template<bool checkKey, typename T>
31 StatusCode 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 
45 template<bool checkKey, typename T, typename X>
46 StatusCode 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
IDCCacheCreatorBase::createContainer
StatusCode createContainer(const SG::WriteHandleKey< T > &, long unsigned int, const EventContext &) const
Definition: IDCCacheCreatorBase.h:31
IDCCacheCreatorBase::ATLAS_THREAD_SAFE
std::atomic_flag m_disableWarningCheck ATLAS_THREAD_SAFE
Definition: IDCCacheCreatorBase.h:24
IdentifiableCache.h
IDCCacheCreatorBase::checkInsideViewOnce
StatusCode checkInsideViewOnce(const EventContext &) const
Definition: IDCCacheCreatorBase.cxx:21
athena.value
value
Definition: athena.py:124
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
IdentifiableValueCache.h
Monitored::X
@ X
Definition: HistogramFillerUtils.h:24
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
IDCCacheCreatorBase::createValueContainer
StatusCode createValueContainer(const SG::WriteHandleKey< T > &, long unsigned int, const EventContext &, const X &defaultValue) const
Definition: IDCCacheCreatorBase.h:46
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
SG::WriteHandleKey
Property holding a SG store/key/clid from which a WriteHandle is made.
Definition: StoreGate/StoreGate/WriteHandleKey.h:40
SG::WriteHandle::recordNonConst
StatusCode recordNonConst(std::unique_ptr< T > data)
Record a non-const object to the store.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
IDCCacheCreatorBase::~IDCCacheCreatorBase
virtual ~IDCCacheCreatorBase()=default
Destructor.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthReentrantAlgorithm.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
IDCCacheCreatorBase::IDCCacheCreatorBase
IDCCacheCreatorBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: IDCCacheCreatorBase.cxx:15
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
IDCCacheCreatorBase
Definition: IDCCacheCreatorBase.h:13
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
IdentifiableValueCache
This class is to provide an event wide MT container for concurrent storing of basic types,...
Definition: IdentifiableValueCache.h:19
IDCCacheCreatorBase::isInsideView
bool isInsideView(const EventContext &) const
Definition: IDCCacheCreatorBase.cxx:8
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35