Skip to content
Snippets Groups Projects
Commit 3ce02e05 authored by Vakhtang Tsulaia's avatar Vakhtang Tsulaia
Browse files

Merge branch 'isValidID.IOVSvc-20201111' into 'master'

IOVSvc: Remove locking from CondSvc::isValidID.

See merge request atlas/athena!38117
parents 352916d3 b1af5f8b
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "xAODEventInfo/EventInfo.h" #include "xAODEventInfo/EventInfo.h"
#include "AthenaKernel/BaseInfo.h" #include "AthenaKernel/BaseInfo.h"
#include "ICondSvcSetupDone.h"
#include "TClass.h" #include "TClass.h"
...@@ -265,6 +266,12 @@ CondInputLoader::start() ...@@ -265,6 +266,12 @@ CondInputLoader::start()
return StatusCode::FAILURE; return StatusCode::FAILURE;
} }
// Let the conditions service know that we've finished creating
// conditions containers.
ServiceHandle<ICondSvcSetupDone> condSvcDone ("CondSvc", name());
ATH_CHECK( condSvcDone.retrieve() );
ATH_CHECK( condSvcDone->setupDone() );
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
......
...@@ -130,6 +130,15 @@ CondSvc::finalize() { ...@@ -130,6 +130,15 @@ CondSvc::finalize() {
} }
StatusCode
CondSvc::start()
{
// Call this now, in case there's no CondInputLoader.
ATH_CHECK( setupDone() );
return StatusCode::SUCCESS;
}
StatusCode StatusCode
CondSvc::stop() { CondSvc::stop() {
...@@ -342,7 +351,10 @@ CondSvc::getValidIDs(const EventContext& ctx, DataObjIDColl& validIDs) { ...@@ -342,7 +351,10 @@ CondSvc::getValidIDs(const EventContext& ctx, DataObjIDColl& validIDs) {
bool bool
CondSvc::isValidID(const EventContext& ctx, const DataObjID& id) const { CondSvc::isValidID(const EventContext& ctx, const DataObjID& id) const {
std::lock_guard<mutex_t> lock(m_lock); // Don't take out the lock here.
// In many-thread jobs, a lock here becomes heavily contended.
// The only potential conflict is with startConditionSetup(),
// which should only be called during START.
EventIDBase now(ctx.eventID()); EventIDBase now(ctx.eventID());
...@@ -352,13 +364,15 @@ CondSvc::isValidID(const EventContext& ctx, const DataObjID& id) const { ...@@ -352,13 +364,15 @@ CondSvc::isValidID(const EventContext& ctx, const DataObjID& id) const {
sk.erase(0,15); sk.erase(0,15);
} }
if (m_sgs->contains<CondContBase>( sk ) ) { auto it = m_condConts.find (sk);
CondContBase *cib; if (it != m_condConts.end()) {
if (m_sgs->retrieve(cib, sk).isSuccess()) { bool valid = it->second->valid (now);
ATH_MSG_VERBOSE("CondSvc::isValidID: now: " << ctx.eventID() << " id : " ATH_MSG_VERBOSE("CondSvc::isValidID: now: " << ctx.eventID() << " id : "
<< id << (cib->valid(now) ? ": T" : ": F") ); << id << (valid ? ": T" : ": F") );
return cib->valid(now); return valid;
} }
else {
ATH_MSG_ERROR( "Cannot find CondCont " << id );
} }
ATH_MSG_DEBUG("CondSvc::isValidID: now: " << ctx.eventID() << " id: " ATH_MSG_DEBUG("CondSvc::isValidID: now: " << ctx.eventID() << " id: "
...@@ -396,3 +410,20 @@ CondSvc::conditionIDs() const { ...@@ -396,3 +410,20 @@ CondSvc::conditionIDs() const {
} }
//---------------------------------------------------------------------------
StatusCode CondSvc::setupDone()
{
std::lock_guard<mutex_t> lock(m_lock);
SG::ConstIterator<CondContBase> cib, cie;
if (m_sgs->retrieve(cib,cie).isSuccess()) {
while(cib != cie) {
m_condConts[cib.key()] = &*cib;
++cib;
}
}
return StatusCode::SUCCESS;
}
/* /*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/ */
#ifndef IOVSVC_CONDSVC_H #ifndef IOVSVC_CONDSVC_H
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
#include "AthenaBaseComps/AthService.h" #include "AthenaBaseComps/AthService.h"
#include "StoreGate/StoreGateSvc.h" #include "StoreGate/StoreGateSvc.h"
#include "AthenaBaseComps/AthService.h" #include "AthenaBaseComps/AthService.h"
#include "ICondSvcSetupDone.h"
#include <unordered_map>
#include <map> #include <map>
#include <set> #include <set>
#include <vector> #include <vector>
...@@ -19,38 +21,45 @@ ...@@ -19,38 +21,45 @@
class ConditionSlotFuture; class ConditionSlotFuture;
class ICondtionIOSvc; class ICondtionIOSvc;
class ATLAS_CHECK_THREAD_SAFETY CondSvc: public extends1<AthService, ICondSvc> { class ATLAS_CHECK_THREAD_SAFETY CondSvc: public extends<AthService, ICondSvc, ICondSvcSetupDone> {
public: public:
CondSvc(const std::string& name, ISvcLocator* svc); CondSvc(const std::string& name, ISvcLocator* svc);
~CondSvc(); ~CondSvc();
virtual StatusCode initialize(); virtual StatusCode initialize() override;
virtual StatusCode finalize(); virtual StatusCode finalize() override;
virtual StatusCode stop(); virtual StatusCode start() override;
virtual StatusCode stop() override;
// from ICondSvc // from ICondSvc
public: public:
virtual StatusCode regHandle(IAlgorithm* alg, const Gaudi::DataHandle& id); virtual StatusCode regHandle(IAlgorithm* alg, const Gaudi::DataHandle& id) override;
virtual bool getInvalidIDs(const EventContext&, DataObjIDColl& ids); virtual bool getInvalidIDs(const EventContext&, DataObjIDColl& ids);
virtual bool getValidIDs(const EventContext&, DataObjIDColl& ids); virtual bool getValidIDs(const EventContext&, DataObjIDColl& ids);
virtual bool getIDValidity(const EventContext&, DataObjIDColl& validIDs, virtual bool getIDValidity(const EventContext&, DataObjIDColl& validIDs,
DataObjIDColl& invalidIDs); DataObjIDColl& invalidIDs);
virtual bool isValidID(const EventContext&, const DataObjID&) const; virtual bool isValidID(const EventContext&, const DataObjID&) const override;
virtual const std::set<IAlgorithm*>& condAlgs() const { return m_condAlgs; } virtual const std::set<IAlgorithm*>& condAlgs() const override { return m_condAlgs; }
virtual bool isRegistered(const DataObjID&) const; virtual bool isRegistered(const DataObjID&) const override;
virtual bool isRegistered(IAlgorithm*) const; virtual bool isRegistered(IAlgorithm*) const override;
virtual const DataObjIDColl& conditionIDs() const; virtual const DataObjIDColl& conditionIDs() const override;
virtual StatusCode validRanges( std::vector<EventIDRange>& ranges, virtual StatusCode validRanges( std::vector<EventIDRange>& ranges,
const DataObjID& id ) const; const DataObjID& id ) const override;
// virtual void dump() const; // virtual void dump() const;
virtual void dump(std::ostream&) const; virtual void dump(std::ostream&) const override;
/// To be called after changes to the set of conditions containers
/// in the conditions store.
/// May not be called concurrently with any other methods of this class.
virtual StatusCode setupDone() override;
public: public:
// unimplemented interfaces // unimplemented interfaces
...@@ -62,7 +71,7 @@ public: ...@@ -62,7 +71,7 @@ public:
/// register an IConditionIOSvc (alternative to Algorithm processing of /// register an IConditionIOSvc (alternative to Algorithm processing of
/// Conditions) /// Conditions)
virtual StatusCode registerConditionIOSvc(IConditionIOSvc*) { virtual StatusCode registerConditionIOSvc(IConditionIOSvc*) override {
return StatusCode::FAILURE; return StatusCode::FAILURE;
} }
...@@ -103,6 +112,11 @@ private: ...@@ -103,6 +112,11 @@ private:
DataObjIDColl m_condIDs; DataObjIDColl m_condIDs;
// Map from keys to CondContBase instances.
// Populated by startConditionSetup().
typedef std::unordered_map<std::string, const CondContBase*> CondContMap_t;
CondContMap_t m_condConts;
typedef std::mutex mutex_t; typedef std::mutex mutex_t;
mutable mutex_t m_lock; mutable mutex_t m_lock;
......
// This file's extension implies that it's C, but it's really -*- C++ -*-.
/*
* Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
*/
/**
* @file IOVSvc/src/ICondSvcSetupDone.h
* @author scott snyder <snyder@bnl.gov>
* @date Nov, 2020
* @brief Interface to tell CondSvc to cache conditions containers.
*/
#ifndef IOVSVC_ICONDSVCSETUPDONE_H
#define IOVSVC_ICONDSVCSETUPDONE_H
#include "GaudiKernel/IInterface.h"
class ICondSvcSetupDone
: virtual public IInterface
{
public:
DeclareInterfaceID( ICondSvcSetupDone, 1, 0 );
/// To be called after creating conditions containers
/// in the conditions store.
virtual StatusCode setupDone() = 0;
};
#endif // not IOVSVC_ICONDSVCSETUPDONE_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment