2 Copyright (C) 2002-2019 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;
69 // std::cout << "recorded " << Gaudi::DataHandle::fullKey()
71 // << SG::VarHandleKey::key() << std::endl;
74 // lets see if we get lucky and the Write alg already created the
76 if (m_cs->contains< CondCont<T> > (SG::VarHandleKey::key()) ) {
77 if (m_cs->retrieve(m_cc, SG::VarHandleKey::key()).isFailure()) {
78 MsgStream msg(Athena::getMessageSvc(), "CondHandleKey");
80 << "CondHandleKey::init(): unable to retrieve CondCont of "
81 << Gaudi::DataHandle::fullKey() << " from "
82 << StoreID::storeName(StoreID::CONDITION_STORE)
83 << " with key " << SG::VarHandleKey::key()
86 return StatusCode::FAILURE;
94 return StatusCode::SUCCESS;
100 CondHandleKey<T>::initialize(AllowEmptyEnum) {
102 return StatusCode::SUCCESS;
104 return initialize (true);
106 //---------------------------------------------------------------------------
110 CondHandleKey<T>::getCS() const {
111 if (!m_cs.isValid()) {
112 MsgStream msg(Athena::getMessageSvc(), "CondHandleKey");
114 << "CondHandleKey::getCS() : Unable to locate ConditionStore"
123 //---------------------------------------------------------------------------
127 * @brief Called by the owning algorithm during the START transition.
129 * AthAlgorithm and friends will call this during START. This allows
130 * for extra initialization that we can't do during initialize(), such
131 * as retrieving a conditions container from the store.
134 StatusCode CondHandleKey<T>::start()
136 if (m_isInit && m_cc == nullptr && mode() == DataHandle::Reader) {
137 // Try again to retrieve the conditions container from the store.
138 // If this is a conditions object that is read by CondInputLoader,
139 // then we will not have found this during initialize(),
140 // as CondInputLoader only records the object during start().
141 m_cc = m_cs->tryRetrieve< CondCont<T> > (SG::VarHandleKey::key());
143 return StatusCode::SUCCESS;