Skip to content
Snippets Groups Projects
Commit ab136c5d authored by Adam Edward Barton's avatar Adam Edward Barton :speech_balloon:
Browse files

Merge branch 'proxyExact.StoreGate-20190522' into 'master'

StoreGate: Optimize ReadHandle SG lookup.

See merge request atlas/athena!23603
parents 4f0649d0 e3c48064
No related branches found
No related tags found
No related merge requests found
...@@ -189,6 +189,13 @@ public: ...@@ -189,6 +189,13 @@ public:
virtual StatusCode start(); virtual StatusCode start();
/**
* @brief Return the hashed StoreGate key.
*
* May be 0 if not yet initialized.
*/
SG::sgkey_t hashedKey() const;
private: private:
/// Set the owning handle. Only callable from VarHandleBase. /// Set the owning handle. Only callable from VarHandleBase.
friend class VarHandleBase; friend class VarHandleBase;
...@@ -228,6 +235,9 @@ private: ...@@ -228,6 +235,9 @@ private:
/// StoreGate key, that doesn't include the storename /// StoreGate key, that doesn't include the storename
std::string m_sgKey; std::string m_sgKey;
/// The hashed StoreGate key. May be 0 if not yet initialized.
SG::sgkey_t m_hashedKey = 0;
/// Cache test for whether we're referencing the event store. /// Cache test for whether we're referencing the event store.
bool m_isEventStore = false; bool m_isEventStore = false;
......
/* /*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/ */
// $Id$ // $Id$
/** /**
...@@ -72,5 +72,16 @@ StatusCode VarHandleKey::start() ...@@ -72,5 +72,16 @@ StatusCode VarHandleKey::start()
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
/**
* @brief Return the hashed StoreGate key.
*
* May be 0 if not yet initialized.
*/
inline
SG::sgkey_t VarHandleKey::hashedKey() const
{
return m_hashedKey;
}
} // namespace SG } // namespace SG
ApplicationMgr.ExtSvc={"StoreGateSvc/StoreGateSvc"};
ApplicationMgr.ExtSvc={"StoreGateSvc/OtherStore"}; ApplicationMgr.ExtSvc={"StoreGateSvc/OtherStore"};
OtherStore.ProxyProviderSvc=""; OtherStore.ProxyProviderSvc="";
...@@ -504,7 +504,11 @@ namespace SG { ...@@ -504,7 +504,11 @@ namespace SG {
if (store) m_store = store; if (store) m_store = store;
} }
StatusCode sc = this->setState(m_store->proxy(this->clid(), this->key())); SG::DataProxy* proxy = m_store->proxy_exact (m_key->hashedKey());
if (!proxy) {
proxy = m_store->proxy(this->clid(), this->key());
}
StatusCode sc = this->setState(proxy);
// Failure to find the proxy is ok in the case of a @c WriteHandle // Failure to find the proxy is ok in the case of a @c WriteHandle
// that has not yet been written to. // that has not yet been written to.
......
...@@ -112,6 +112,7 @@ StatusCode VarHandleKey::initialize (bool used /*= true*/) ...@@ -112,6 +112,7 @@ StatusCode VarHandleKey::initialize (bool used /*= true*/)
if (!used) { if (!used) {
Gaudi::DataHandle::updateKey ( "" ); Gaudi::DataHandle::updateKey ( "" );
m_sgKey = ""; m_sgKey = "";
m_hashedKey = 0;
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
...@@ -130,6 +131,8 @@ StatusCode VarHandleKey::initialize (bool used /*= true*/) ...@@ -130,6 +131,8 @@ StatusCode VarHandleKey::initialize (bool used /*= true*/)
return StatusCode::FAILURE; return StatusCode::FAILURE;
} }
m_hashedKey = m_storeHandle->stringToKey (m_sgKey, clid());
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
...@@ -216,6 +219,8 @@ void VarHandleKey::updateKey(const std::string& /*key*/) const ...@@ -216,6 +219,8 @@ void VarHandleKey::updateKey(const std::string& /*key*/) const
void VarHandleKey::parseKey (const std::string& key, void VarHandleKey::parseKey (const std::string& key,
const std::string& storeName) const std::string& storeName)
{ {
m_hashedKey = 0;
std::string sn; std::string sn;
// test if storeName has classname // test if storeName has classname
std::string::size_type sp = storeName.find("/"); std::string::size_type sp = storeName.find("/");
...@@ -296,6 +301,7 @@ void VarHandleKey::updateHandle (const std::string& name) ...@@ -296,6 +301,7 @@ void VarHandleKey::updateHandle (const std::string& name)
// Don't invalidate a stored pointer if the handle is already pointing // Don't invalidate a stored pointer if the handle is already pointing
// at the desired service. // at the desired service.
if (m_storeHandle.name() != name) { if (m_storeHandle.name() != name) {
m_hashedKey = 0;
m_storeHandle = ServiceHandle<IProxyDict>(name, "VarHandleKey"); m_storeHandle = ServiceHandle<IProxyDict>(name, "VarHandleKey");
m_isEventStore = (name == StoreID::storeName(StoreID::EVENT_STORE) || m_isEventStore = (name == StoreID::storeName(StoreID::EVENT_STORE) ||
name == StoreID::storeName(StoreID::PILEUP_STORE)); name == StoreID::storeName(StoreID::PILEUP_STORE));
......
/* /*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/ */
// $Id$ // $Id$
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#undef NDEBUG #undef NDEBUG
#include "AthenaKernel/ExtendedEventContext.h" #include "AthenaKernel/ExtendedEventContext.h"
#include "StoreGate/ReadHandle.h" #include "StoreGate/ReadHandle.h"
#include "StoreGate/StoreGateSvc.h"
#include "StoreGate/exceptions.h" #include "StoreGate/exceptions.h"
#include "SGTools/TestStore.h" #include "SGTools/TestStore.h"
#include "AthenaKernel/CLASS_DEF.h" #include "AthenaKernel/CLASS_DEF.h"
...@@ -21,6 +22,7 @@ ...@@ -21,6 +22,7 @@
#include "TestTools/expect_exception.h" #include "TestTools/expect_exception.h"
#include "AthenaKernel/errorcheck.h" #include "AthenaKernel/errorcheck.h"
#include "CxxUtils/unused.h" #include "CxxUtils/unused.h"
#include "boost/timer/timer.hpp"
#include <cassert> #include <cassert>
#include <iostream> #include <iostream>
...@@ -335,7 +337,40 @@ void test6() ...@@ -335,7 +337,40 @@ void test6()
} }
int main() //************************************************************************
unsigned int perftest (ISvcLocator* svcloc, unsigned int ntry)
{
StoreGateSvc* sg = nullptr;
assert (svcloc->service ("StoreGateSvc", sg).isSuccess());
assert (sg->record (std::make_unique<MyObj> (42), "MyObj", false).isSuccess());
SG::ReadHandleKey<MyObj> key ("MyObj");
assert (key.initialize().isSuccess());
EventContext ctx;
ctx.setExtension( Atlas::ExtendedEventContext(sg->hiveProxyDict()) );
unsigned int sum = 0;
boost::timer::cpu_timer timer;
for (unsigned int i=0; i < ntry; i++) {
SG::ReadHandle<MyObj> h (key, ctx);
sum += h->x;
}
timer.stop();
boost::timer::cpu_times times = timer.elapsed();
std::cout << ntry << " times: " << boost::timer::format(times);
std::cout << "Each: " << (float)times.user / ntry / 1000 << " us (user)\n";
return sum;
}
//************************************************************************
int main (int argc, char** argv)
{ {
errorcheck::ReportMessage::hideErrorLocus(); errorcheck::ReportMessage::hideErrorLocus();
ISvcLocator* svcloc; ISvcLocator* svcloc;
...@@ -344,6 +379,17 @@ int main() ...@@ -344,6 +379,17 @@ int main()
return 1; return 1;
} }
if (argc >= 2 && strncmp (argv[1], "--perf", 6) == 0) {
unsigned int ntry = 1000000;
const char* p = strchr (argv[1], '=');
if (p) {
ntry = atoi (p+1);
if (ntry < 1) ntry = 1;
}
perftest (svcloc, ntry);
return 0;
}
test1(); test1();
test2(); test2();
test3(); test3();
......
...@@ -40,11 +40,13 @@ void test1() ...@@ -40,11 +40,13 @@ void test1()
assert (k1.mode() == Gaudi::DataHandle::Reader); assert (k1.mode() == Gaudi::DataHandle::Reader);
assert (k1.storeHandle().name() == "StoreGateSvc"); assert (k1.storeHandle().name() == "StoreGateSvc");
assert (!k1.storeHandle().isSet()); assert (!k1.storeHandle().isSet());
assert (k1.hashedKey() == 0);
assert (k1.initialize().isSuccess()); assert (k1.initialize().isSuccess());
assert (k1.storeHandle().isSet()); assert (k1.storeHandle().isSet());
assert (k1.start().isSuccess()); assert (k1.start().isSuccess());
assert (!k1.isCondition()); assert (!k1.isCondition());
assert (!k1.empty()); assert (!k1.empty());
assert (k1.hashedKey() == 752331202);
k1 = "aab"; k1 = "aab";
assert (k1.clid() == 1234); assert (k1.clid() == 1234);
......
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