2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5#include "AthenaKernel/StoreID.h"
6#include "GaudiKernel/System.h"
12 CondHandleKey<T>::CondHandleKey(const std::string& key,
13 const std::string& dbKey,
14 Gaudi::DataHandle::Mode mode ) :
15 VarHandleKey(ClassID_traits<T>::ID(), key, mode,
16 StoreID::storeName(StoreID::CONDITION_STORE), true),
17 m_cs(StoreID::storeName(StoreID::CONDITION_STORE),"CondHandleKey"),
20 CondCont<T>::registerBaseInit();
23 //---------------------------------------------------------------------------
27 CondHandleKey<T>::initialize(bool used /*= true*/) {
28 if (m_isInit) return StatusCode::SUCCESS;
31 if (VarHandleKey::initialize(used) != StatusCode::SUCCESS) {
32 return StatusCode::FAILURE;
34 if (empty()) return StatusCode::SUCCESS;
36 if (!m_cs.isValid()) {
37 MsgStream msg(Athena::getMessageSvc(), "CondHandleKey");
39 << "CondHandleKey::initialize() :Unable to locate ConditionStore "
42 return StatusCode::FAILURE;
46 if (mode() == DataHandle::Writer) {
47 if (m_cs->contains< CondCont<T> > (SG::VarHandleKey::key()) ) {
48 MsgStream msg(Athena::getMessageSvc(), "CondHandleKey");
50 << StoreID::storeName( StoreID::CONDITION_STORE )
51 << " already contains a CondCont of type "
52 << Gaudi::DataHandle::fullKey()
54 return StatusCode::FAILURE;
56 ServiceHandle<Athena::IRCUSvc> rcusvc ("Athena::RCUSvc", "CondHandleKey");
57 m_cc = new CondCont<T>(*rcusvc, Gaudi::DataHandle::fullKey());
58 if (m_cs->record(m_cc, SG::VarHandleKey::key()).isFailure()) {
59 MsgStream msg(Athena::getMessageSvc(), "CondHandleKey");
61 << "CondHandleKey::init(): unable to record empty CondCont of "
62 << Gaudi::DataHandle::fullKey() << " in "
63 << StoreID::storeName( StoreID::CONDITION_STORE )
64 << " with key " << SG::VarHandleKey::key() << endmsg;
67 return StatusCode::FAILURE;
71 // lets see if we get lucky and the Write alg already created the
73 if (m_cs->contains< CondCont<T> > (SG::VarHandleKey::key()) ) {
74 if (m_cs->retrieve(m_cc, SG::VarHandleKey::key()).isFailure()) {
75 MsgStream msg(Athena::getMessageSvc(), "CondHandleKey");
77 << "CondHandleKey::init(): unable to retrieve CondCont of "
78 << Gaudi::DataHandle::fullKey() << " from "
79 << StoreID::storeName(StoreID::CONDITION_STORE)
80 << " with key " << SG::VarHandleKey::key()
83 return StatusCode::FAILURE;
91 return StatusCode::SUCCESS;
97 CondHandleKey<T>::initialize(AllowEmptyEnum) {
99 return StatusCode::SUCCESS;
101 return initialize (true);
103//---------------------------------------------------------------------------
107 CondHandleKey<T>::getCS() const {
108 if (!m_cs.isValid()) {
109 MsgStream msg(Athena::getMessageSvc(), "CondHandleKey");
111 << "CondHandleKey::getCS() : Unable to locate ConditionStore"
120//---------------------------------------------------------------------------
124 * @brief Called by the owning algorithm during the START transition.
126 * AthAlgorithm and friends will call this during START. This allows
127 * for extra initialization that we can't do during initialize(), such
128 * as retrieving a conditions container from the store.
131 StatusCode CondHandleKey<T>::start()
133 if (m_isInit && m_cc == nullptr && mode() == DataHandle::Reader) {
134 // Try again to retrieve the conditions container from the store.
135 // If this is a conditions object that is read by CondInputLoader,
136 // then we will not have found this during initialize(),
137 // as CondInputLoader only records the object during start().
138 m_cc = m_cs->tryRetrieve< CondCont<T> > (SG::VarHandleKey::key());
140 return StatusCode::SUCCESS;