2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
5 #include "AthenaKernel/StoreID.h"
6 #include "GaudiKernel/System.h"
12 MetaHandleKey<T>::MetaHandleKey(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::METADATA_STORE), true),
17 m_store(StoreID::storeName(StoreID::METADATA_STORE),"MetaHandleKey"),
21 //------------------------------------------------------------------------
25 MetaHandleKey<T>::initialize() {
26 if (m_isInit) return StatusCode::SUCCESS;
28 if (VarHandleKey::initialize() != StatusCode::SUCCESS) {
29 return StatusCode::FAILURE;
31 if (empty()) return StatusCode::SUCCESS;
33 MsgStream msg(Athena::getMessageSvc(), "MetaHandleKey");
34 if (!m_store.isValid()) {
36 << "MetaHandleKey::initialize() :Unable to locate MetaDataStore "
39 return StatusCode::FAILURE;
42 if (mode() == DataHandle::Writer) {
43 if (m_store->contains< MetaCont<T> > (SG::VarHandleKey::key())) {
45 << StoreID::storeName( StoreID::METADATA_STORE )
46 << " already contains a MetaCont of type "
47 << Gaudi::DataHandle::fullKey()
49 return StatusCode::FAILURE;
52 m_cont = new MetaCont<T>();
53 if(m_store->record(m_cont,SG::VarHandleKey::key()).isFailure()) {
55 << "MetaHandleKey::init(): unable to record empty MetaCont of "
56 << Gaudi::DataHandle::fullKey() << " in "
57 << StoreID::storeName( StoreID::METADATA_STORE )
58 << " with key " << SG::VarHandleKey::key() << endmsg;
61 return StatusCode::FAILURE;
66 // lets see if we get lucky and the Write alg already created the
68 if (m_store->contains<MetaCont<T>>(SG::VarHandleKey::key()) ) {
69 if (m_store->retrieve(m_cont, SG::VarHandleKey::key()).isFailure()) {
71 << "MetaHandleKey::init(): unable to retrieve MetaCont of "
72 << Gaudi::DataHandle::fullKey() << " from "
73 << StoreID::storeName(StoreID::METADATA_STORE)
74 << " with key " << SG::VarHandleKey::key()
77 return StatusCode::FAILURE;
83 // Retrieve the guid/SID from the data header
84 const DataHeader* thisDH;
85 ServiceHandle<StoreGateSvc> instore("StoreGateSvc/InputMetaDataStore","MetaHandleKey");
86 if (instore.retrieve().isFailure()) return StatusCode::FAILURE;
87 if(instore->retrieve(thisDH)!=StatusCode::SUCCESS) {
88 msg << MSG::ERROR << "Unable to get DataHeader" << endmsg;
89 msg << instore->dump() << endmsg;
90 return StatusCode::FAILURE;
92 // Get string guid for SourceID
93 m_dbKey = thisDH->begin()->getToken()->dbID().toString();
95 // if you can't get the sid, then this won't work, so fail
96 if (m_dbKey.size()==0) {
97 msg << MSG::ERROR << "Unable to get source id from dataheader" << endmsg;
98 return StatusCode::FAILURE;
103 return StatusCode::SUCCESS;
107 //------------------------------------------------------------------------
111 MetaHandleKey<T>::getStore() const {
112 if (!m_store.isValid()) {
113 MsgStream msg(Athena::getMessageSvc(), "MetaHandleKey");
115 << "MetaHandleKey::getStore() : Unable to locate MetaDataStore"
120 return m_store.get();