ATLAS Offline Software
Loading...
Searching...
No Matches
CondSvc Class Referencefinal

#include <CondSvc.h>

Inheritance diagram for CondSvc:
Collaboration diagram for CondSvc:

Public Member Functions

 CondSvc (const std::string &name, ISvcLocator *svc)
virtual StatusCode initialize () override
virtual StatusCode start () override
virtual StatusCode stop () override
virtual StatusCode regHandle (IAlgorithm *alg, const Gaudi::DataHandle &id) override
virtual bool isValidID (const EventContext &, const DataObjID &) const override
virtual const std::set< IAlgorithm * > & condAlgs () const override
virtual bool isRegistered (const DataObjID &id) const override
virtual bool isRegistered (IAlgorithm *ialg) const override
virtual const DataObjIDColl & conditionIDs () const override
virtual StatusCode validRanges (std::vector< EventIDRange > &ranges, const DataObjID &id) const override
virtual void dump (std::ostream &) const override
virtual StatusCode setupDone () override
 To be called after changes to the set of conditions containers in the conditions store.
virtual ConditionSlotFuture * startConditionSetup (const EventContext &) override
 unimplemented interfaces
virtual StatusCode registerConditionIOSvc (IConditionIOSvc *) override
 register an IConditionIOSvc (alternative to Algorithm processing of Conditions)

Private Member Functions

StatusCode regHandle_i (IAlgorithm *alg, const Gaudi::DataHandle &id)

Private Attributes

ServiceHandle< StoreGateSvcm_sgs
std::set< IAlgorithm * > m_condAlgs
DataObjIDColl m_condIDs
std::unordered_map< DataObjID, IAlgorithm *, DataObjID_Hasher > m_idMap
 Map from DataObjID to Algorithm to avoid duplicates.
std::unordered_map< DataObjID, const CondContBase *, DataObjID_Hasher > m_condConts
 Map from DataObjID to CondContBase (populated in setupDone)
std::mutex m_lock

Detailed Description

Definition at line 22 of file CondSvc.h.

Constructor & Destructor Documentation

◆ CondSvc()

CondSvc::CondSvc ( const std::string & name,
ISvcLocator * svc )

Definition at line 13 of file CondSvc.cxx.

13 :
14 base_class(name,svcLoc),
15 m_sgs("StoreGateSvc/ConditionStore", name)
16{
17}
ServiceHandle< StoreGateSvc > m_sgs
Definition CondSvc.h:70

Member Function Documentation

◆ condAlgs()

virtual const std::set< IAlgorithm * > & CondSvc::condAlgs ( ) const
inlineoverridevirtual

Definition at line 35 of file CondSvc.h.

35{ return m_condAlgs; }
std::set< IAlgorithm * > m_condAlgs
Definition CondSvc.h:72

◆ conditionIDs()

virtual const DataObjIDColl & CondSvc::conditionIDs ( ) const
inlineoverridevirtual

Definition at line 38 of file CondSvc.h.

38{ return m_condIDs; }
DataObjIDColl m_condIDs
Definition CondSvc.h:73

◆ dump()

void CondSvc::dump ( std::ostream & ost) const
overridevirtual

Definition at line 53 of file CondSvc.cxx.

53 {
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
66 SG::ConstIterator<CondContBase> cib,cie;
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}
std::mutex m_lock
Definition CondSvc.h:81
std::unordered_map< DataObjID, IAlgorithm *, DataObjID_Hasher > m_idMap
Map from DataObjID to Algorithm to avoid duplicates.
Definition CondSvc.h:76

◆ initialize()

StatusCode CondSvc::initialize ( )
overridevirtual

Definition at line 42 of file CondSvc.cxx.

42 {
43
44 ATH_CHECK( m_sgs.retrieve() );
45
46 return StatusCode::SUCCESS;
47
48}
#define ATH_CHECK
Evaluate an expression and check for errors.

◆ isRegistered() [1/2]

virtual bool CondSvc::isRegistered ( const DataObjID & id) const
inlineoverridevirtual

Definition at line 36 of file CondSvc.h.

36{ return m_condIDs.contains(id); }

◆ isRegistered() [2/2]

virtual bool CondSvc::isRegistered ( IAlgorithm * ialg) const
inlineoverridevirtual

Definition at line 37 of file CondSvc.h.

37{ return m_condAlgs.contains(ialg); }

◆ isValidID()

bool CondSvc::isValidID ( const EventContext & ctx,
const DataObjID & id ) const
overridevirtual

Definition at line 166 of file CondSvc.cxx.

166 {
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}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
std::unordered_map< DataObjID, const CondContBase *, DataObjID_Hasher > m_condConts
Map from DataObjID to CondContBase (populated in setupDone)
Definition CondSvc.h:79
list valid
Definition calibdata.py:44

◆ regHandle()

StatusCode CondSvc::regHandle ( IAlgorithm * alg,
const Gaudi::DataHandle & id )
overridevirtual

Definition at line 109 of file CondSvc.cxx.

109 {
110
111 std::scoped_lock lock(m_lock);
112 return regHandle_i(alg, dh);
113
114}
StatusCode regHandle_i(IAlgorithm *alg, const Gaudi::DataHandle &id)
Definition CondSvc.cxx:120

◆ regHandle_i()

StatusCode CondSvc::regHandle_i ( IAlgorithm * alg,
const Gaudi::DataHandle & id )
private

Definition at line 120 of file CondSvc.cxx.

120 {
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}
#define ATH_MSG_DEBUG(x)
uint32_t CLID
The Class ID type.
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
@ CONDITION_STORE
Definition StoreID.h:28
static const std::string & storeName(const StoreID::type &s)
Definition StoreID.cxx:77
::StatusCode StatusCode
StatusCode definition for legacy code.

◆ registerConditionIOSvc()

virtual StatusCode CondSvc::registerConditionIOSvc ( IConditionIOSvc * )
inlineoverridevirtual

register an IConditionIOSvc (alternative to Algorithm processing of Conditions)

Definition at line 60 of file CondSvc.h.

60 {
61 return StatusCode::FAILURE;
62 }

◆ setupDone()

StatusCode CondSvc::setupDone ( )
overridevirtual

To be called after changes to the set of conditions containers in the conditions store.

Create DataObjID -> CondCont map for usage in isValidID.

May not be called concurrently with any other methods of this class.

As some conditions are looked up via their base class, we need to register each CondCont key against all its possible bases.

Definition at line 195 of file CondSvc.cxx.

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
202 SG::ConstIterator<CondContBase> cib, cie;
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}
const std::string & key() const
Get the key string with which the current object was stored.

◆ start()

StatusCode CondSvc::start ( )
overridevirtual

Definition at line 82 of file CondSvc.cxx.

83{
84 // Call this now, in case there is no CondInputLoader.
86 return StatusCode::SUCCESS;
87}
virtual StatusCode setupDone() override
To be called after changes to the set of conditions containers in the conditions store.
Definition CondSvc.cxx:195

◆ startConditionSetup()

virtual ConditionSlotFuture * CondSvc::startConditionSetup ( const EventContext & )
inlineoverridevirtual

unimplemented interfaces

Asynchronously setup conditions

Definition at line 54 of file CondSvc.h.

54 {
55 return nullptr;
56 }

◆ stop()

StatusCode CondSvc::stop ( )
overridevirtual

Definition at line 91 of file CondSvc.cxx.

91 {
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}
virtual void dump(std::ostream &) const override
Definition CondSvc.cxx:53

◆ validRanges()

StatusCode CondSvc::validRanges ( std::vector< EventIDRange > & ranges,
const DataObjID & id ) const
overridevirtual

Definition at line 22 of file CondSvc.cxx.

23{
24 // Retrieve all conditions data and search
25 SG::ConstIterator< CondContBase > cib, cie;
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}

Member Data Documentation

◆ m_condAlgs

std::set<IAlgorithm*> CondSvc::m_condAlgs
private

Definition at line 72 of file CondSvc.h.

◆ m_condConts

std::unordered_map<DataObjID, const CondContBase*, DataObjID_Hasher> CondSvc::m_condConts
private

Map from DataObjID to CondContBase (populated in setupDone)

Definition at line 79 of file CondSvc.h.

◆ m_condIDs

DataObjIDColl CondSvc::m_condIDs
private

Definition at line 73 of file CondSvc.h.

◆ m_idMap

std::unordered_map<DataObjID, IAlgorithm*, DataObjID_Hasher> CondSvc::m_idMap
private

Map from DataObjID to Algorithm to avoid duplicates.

Definition at line 76 of file CondSvc.h.

◆ m_lock

std::mutex CondSvc::m_lock
mutableprivate

Definition at line 81 of file CondSvc.h.

◆ m_sgs

ServiceHandle<StoreGateSvc> CondSvc::m_sgs
private

Definition at line 70 of file CondSvc.h.


The documentation for this class was generated from the following files: