ATLAS Offline Software
Loading...
Searching...
No Matches
CondSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4#include "CondSvc.h"
6#include "GaudiKernel/EventIDBase.h"
9
10
11//---------------------------------------------------------------------------
12
13CondSvc::CondSvc( const std::string& name, ISvcLocator* svcLoc ):
14 base_class(name,svcLoc),
15 m_sgs("StoreGateSvc/ConditionStore", name)
16{
17}
18
19//---------------------------------------------------------------------------
20
21StatusCode
22CondSvc::validRanges( std::vector< EventIDRange >& ranges, const DataObjID& id ) const
23{
24 // Retrieve all conditions data and search
26 StatusCode sc = m_sgs->retrieve( cib, cie );
27 if ( sc.isSuccess() ) {
28 while ( cib != cie ) {
29 if ( cib->id() == id ) {
30 ranges = cib->ranges();
31 }
32 ++cib;
33 }
34 }
35
36 return sc;
37}
38
39//---------------------------------------------------------------------------
40
41StatusCode
43
44 ATH_CHECK( m_sgs.retrieve() );
45
46 return StatusCode::SUCCESS;
47
48}
49
50//---------------------------------------------------------------------------
51
52void
53CondSvc::dump(std::ostream& ost) const {
54
55 std::scoped_lock lock(m_lock);
56
57 ost << "CondSvc::dump()";
58
59 ost << "\ndumping id->alg map\n";
60 for (const auto& [id, alg] : m_idMap) {
61 ost << "\n + " << id << " : " << alg->name();
62 }
63
64 ost << "\n\ndumping ConditionStore:\n\n";
65
67 if (m_sgs->retrieve(cib,cie).isSuccess()) {
68 while (cib != cie) {
69 ost << " + ";
70 cib->list(ost);
71 ++cib;
72 }
73 }
74
75 ost << "\n";
76
77}
78
79//---------------------------------------------------------------------------
80
81StatusCode
83{
84 // Call this now, in case there is no CondInputLoader.
86 return StatusCode::SUCCESS;
87}
88
89
90StatusCode
92
93 ATH_MSG_DEBUG( "CondSvc::stop()" );
94
95 if (msgLvl(MSG::DEBUG)) {
96 std::ostringstream ost;
97 dump(ost);
98
99 ATH_MSG_DEBUG( ost.str() );
100 }
101
102 return StatusCode::SUCCESS;
103
104}
105
106//---------------------------------------------------------------------------
107
108StatusCode
109CondSvc::regHandle(IAlgorithm* alg, const Gaudi::DataHandle& dh) {
110
111 std::scoped_lock lock(m_lock);
112 return regHandle_i(alg, dh);
113
114}
115
116//---------------------------------------------------------------------------
117
118// separate implementation to avoid the use of a recursive mutex
119StatusCode
120CondSvc::regHandle_i(IAlgorithm* alg, const Gaudi::DataHandle& dh) {
121
122 ATH_MSG_DEBUG( "regHandle: alg: " << alg->name() << " id: "
123 << dh.fullKey() );
124
125 if (dh.mode() != Gaudi::DataHandle::Writer) {
126 ATH_MSG_DEBUG(dh.fullKey() << " is a ReadHandle. No need to register.");
127 return StatusCode::SUCCESS;
128 }
129
130 const auto [itr, success] = m_idMap.try_emplace(dh.fullKey(), alg);
131 if (!success) {
132 const IAlgorithm *ia = itr->second;
133 if (ia->name() != alg->name()) {
134 ATH_MSG_ERROR("WriteCondHandle " << dh.fullKey()
135 << " is already registered against a different Algorithm "
136 << ia->name()
137 << ". This is not allowed.");
138 return StatusCode::FAILURE;
139 }
140 }
141
142 m_condAlgs.emplace(alg);
143 m_condIDs.emplace( dh.fullKey() );
144
145 StatusCode sc{StatusCode::SUCCESS};
146
147 const CLID clid = dh.fullKey().clid();
148 const SG::BaseInfoBase* bib = SG::BaseInfoBase::find( clid );
149 if ( bib ) {
150 for (CLID clid2 : bib->get_bases()) {
151 if (clid2 != clid) {
152 SG::VarHandleKey vhk(clid2,dh.objKey(),Gaudi::DataHandle::Writer,
154 sc &= regHandle_i(alg, vhk);
155 }
156 }
157 }
158
159 return sc;
160}
161
162
163//---------------------------------------------------------------------------
164
165bool
166CondSvc::isValidID(const EventContext& ctx, const DataObjID& id) const {
167 // Don't take out the lock here.
168 // In many-thread jobs, a lock here becomes heavily contended.
169 // The only potential conflict is with setupDone(),
170 // which should only be called during START.
171
172 auto it = m_condConts.find (id);
173 if (it != m_condConts.end()) {
174 const bool valid = it->second->valid (ctx.eventID());
175 ATH_MSG_VERBOSE("CondSvc::isValidID: now: " << ctx.eventID() << " id : "
176 << id << (valid ? ": T" : ": F") );
177 return valid;
178 }
179 else {
180 ATH_MSG_ERROR( "Cannot find CondCont " << id );
181 }
182
183 return false;
184
185}
186
187//---------------------------------------------------------------------------
188
196{
197 std::scoped_lock lock(m_lock);
198
199 // CondHandleKeys always carry the store prefix. Prepend it to the raw key name.
200 const std::string& storePrefix = StoreID::storeName(StoreID::CONDITION_STORE) + "+";
201
203 if (m_sgs->retrieve(cib,cie).isSuccess()) {
204 while(cib != cie) {
205 // CLID of CondCont payload
206 CLID clid = cib->id().clid();
207 const SG::BaseInfoBase* bib = SG::BaseInfoBase::find(clid);
208 if ( !bib ) {
209 // If no bases, register type
210 m_condConts.try_emplace( DataObjID(clid, storePrefix + cib.key()), &*cib );
211 }
212 else {
213 // Otherwise register all bases (which includes itself)
214 for (CLID clid2 : bib->get_bases()) {
215 m_condConts.try_emplace( DataObjID(clid2, storePrefix + cib.key()), &*cib );
216 }
217 }
218 ++cib;
219 }
220 }
221
222 return StatusCode::SUCCESS;
223}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Hold mappings of ranges to condition objects.
Provide an interface for finding inheritance information at run time.
uint32_t CLID
The Class ID type.
static Double_t sc
virtual void dump(std::ostream &) const override
Definition CondSvc.cxx:53
DataObjIDColl m_condIDs
Definition CondSvc.h:73
ServiceHandle< StoreGateSvc > m_sgs
Definition CondSvc.h:70
virtual StatusCode regHandle(IAlgorithm *alg, const Gaudi::DataHandle &id) override
Definition CondSvc.cxx:109
CondSvc(const std::string &name, ISvcLocator *svc)
Definition CondSvc.cxx:13
std::mutex m_lock
Definition CondSvc.h:81
virtual StatusCode initialize() override
Definition CondSvc.cxx:42
StatusCode regHandle_i(IAlgorithm *alg, const Gaudi::DataHandle &id)
Definition CondSvc.cxx:120
std::unordered_map< DataObjID, IAlgorithm *, DataObjID_Hasher > m_idMap
Map from DataObjID to Algorithm to avoid duplicates.
Definition CondSvc.h:76
std::unordered_map< DataObjID, const CondContBase *, DataObjID_Hasher > m_condConts
Map from DataObjID to CondContBase (populated in setupDone)
Definition CondSvc.h:79
virtual StatusCode setupDone() override
To be called after changes to the set of conditions containers in the conditions store.
Definition CondSvc.cxx:195
virtual StatusCode start() override
Definition CondSvc.cxx:82
std::set< IAlgorithm * > m_condAlgs
Definition CondSvc.h:72
virtual StatusCode validRanges(std::vector< EventIDRange > &ranges, const DataObjID &id) const override
Definition CondSvc.cxx:22
virtual bool isValidID(const EventContext &, const DataObjID &) const override
Definition CondSvc.cxx:166
virtual StatusCode stop() override
Definition CondSvc.cxx:91
The non-template portion of the BaseInfo implementation.
static const BaseInfoBase * find(CLID clid)
Find the BaseInfoBase instance for clid.
Definition BaseInfo.cxx:570
const std::vector< CLID > & get_bases() const
Return the class IDs of all known bases of T (that have class IDs).
Definition BaseInfo.cxx:304
a const_iterator facade to DataHandle.
Definition SGIterator.h:164
A property holding a SG store/key/clid from which a VarHandle is made.
const std::string & key() const
Get the key string with which the current object was stored.
@ CONDITION_STORE
Definition StoreID.h:28
static const std::string & storeName(const StoreID::type &s)
Definition StoreID.cxx:77
-event-from-file