ATLAS Offline Software
Loading...
Searching...
No Matches
CondHandleKey.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "AthenaKernel/StoreID.h"
6#include "GaudiKernel/System.h"
7#include <typeinfo>
8
9namespace SG {
10
11 template <class T>
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"),
18 m_dbKey(dbKey)
19 {
20 CondCont<T>::registerBaseInit();
21 }
22
23 //---------------------------------------------------------------------------
24
25 template <class T>
26 StatusCode
27 CondHandleKey<T>::initialize(bool used /*= true*/) {
28 if (m_isInit) return StatusCode::SUCCESS;
29
30
31 if (VarHandleKey::initialize(used) != StatusCode::SUCCESS) {
32 return StatusCode::FAILURE;
33 }
34 if (empty()) return StatusCode::SUCCESS;
35
36 if (!m_cs.isValid()) {
37 MsgStream msg(Athena::getMessageSvc(), "CondHandleKey");
38 msg << MSG::ERROR
39 << "CondHandleKey::initialize() :Unable to locate ConditionStore "
40 << m_cs.name()
41 << endmsg;
42 return StatusCode::FAILURE;
43 }
44
45
46 if (mode() == DataHandle::Writer) {
47 if (m_cs->contains< CondCont<T> > (SG::VarHandleKey::key()) ) {
48 MsgStream msg(Athena::getMessageSvc(), "CondHandleKey");
49 msg << MSG::ERROR
50 << StoreID::storeName( StoreID::CONDITION_STORE )
51 << " already contains a CondCont of type "
52 << Gaudi::DataHandle::fullKey()
53 << endmsg;
54 return StatusCode::FAILURE;
55 } else {
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");
60 msg << MSG::ERROR
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;
65 delete m_cc;
66 m_cc = 0;
67 return StatusCode::FAILURE;
68 }
69 }
70 } else {
71 // lets see if we get lucky and the Write alg already created the
72 // container we want
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");
76 msg << MSG::ERROR
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()
81 << endmsg;
82 m_cc = 0;
83 return StatusCode::FAILURE;
84 }
85 }
86 }
87
88
89 m_isInit = true;
90
91 return StatusCode::SUCCESS;
92
93 }
94
95 template <class T>
96 StatusCode
97 CondHandleKey<T>::initialize(AllowEmptyEnum) {
98 if (key().empty()) {
99 return StatusCode::SUCCESS;
100 }
101 return initialize (true);
102 }
103//---------------------------------------------------------------------------
104
105 template <class T>
106 const StoreGateSvc*
107 CondHandleKey<T>::getCS() const {
108 if (!m_cs.isValid()) {
109 MsgStream msg(Athena::getMessageSvc(), "CondHandleKey");
110 msg << MSG::ERROR
111 << "CondHandleKey::getCS() : Unable to locate ConditionStore"
112 << endmsg;
113 return 0;
114 }
115
116 return m_cs.get();
117 }
118
119
120//---------------------------------------------------------------------------
121
122
123 /**
124 * @brief Called by the owning algorithm during the START transition.
125 *
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.
129 */
130 template <class T>
131 StatusCode CondHandleKey<T>::start()
132 {
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());
139 }
140 return StatusCode::SUCCESS;
141 }
142
143
144}