ATLAS Offline Software
Loading...
Searching...
No Matches
MetaHandleKey.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "AthenaKernel/StoreID.h"
6#include "GaudiKernel/System.h"
7#include <typeinfo>
8
9namespace SG {
10
11 template <class T>
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"),
18 m_dbKey(dbKey)
19 {}
20
21 //------------------------------------------------------------------------
22
23 template <class T>
24 StatusCode
25 MetaHandleKey<T>::initialize() {
26 if (m_isInit) return StatusCode::SUCCESS;
27
28 if (VarHandleKey::initialize() != StatusCode::SUCCESS) {
29 return StatusCode::FAILURE;
30 }
31 if (empty()) return StatusCode::SUCCESS;
32
33 MsgStream msg(Athena::getMessageSvc(), "MetaHandleKey");
34 if (!m_store.isValid()) {
35 msg << MSG::ERROR
36 << "MetaHandleKey::initialize() :Unable to locate MetaDataStore "
37 << m_store.name()
38 << endmsg;
39 return StatusCode::FAILURE;
40 }
41
42 if (mode() == DataHandle::Writer) {
43 if (m_store->contains< MetaCont<T> > (SG::VarHandleKey::key())) {
44 msg << MSG::ERROR
45 << StoreID::storeName( StoreID::METADATA_STORE )
46 << " already contains a MetaCont of type "
47 << Gaudi::DataHandle::fullKey()
48 << endmsg;
49 return StatusCode::FAILURE;
50 }
51 else {
52 m_cont = new MetaCont<T>();
53 if(m_store->record(m_cont,SG::VarHandleKey::key()).isFailure()) {
54 msg << MSG::ERROR
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;
59 delete m_cont;
60 m_cont = nullptr;
61 return StatusCode::FAILURE;
62 }
63 }
64 }
65 else {
66 // lets see if we get lucky and the Write alg already created the
67 // container we want
68 if (m_store->contains<MetaCont<T>>(SG::VarHandleKey::key()) ) {
69 if (m_store->retrieve(m_cont, SG::VarHandleKey::key()).isFailure()) {
70 msg << MSG::ERROR
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()
75 << endmsg;
76 m_cont = 0;
77 return StatusCode::FAILURE;
78 }
79 }
80 }
81
82/*
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;
91 }
92 // Get string guid for SourceID
93 m_dbKey = thisDH->begin()->getToken()->dbID().toString();
94
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;
99 }
100*/
101 m_isInit = true;
102
103 return StatusCode::SUCCESS;
104
105 }
106
107 //------------------------------------------------------------------------
108
109 template <class T>
110 StoreGateSvc*
111 MetaHandleKey<T>::getStore() const {
112 if (!m_store.isValid()) {
113 MsgStream msg(Athena::getMessageSvc(), "MetaHandleKey");
114 msg << MSG::ERROR
115 << "MetaHandleKey::getStore() : Unable to locate MetaDataStore"
116 << endmsg;
117 return 0;
118 }
119
120 return m_store.get();
121 }
122
123
124}