ATLAS Offline Software
Loading...
Searching...
No Matches
SGKeyResolver.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
10
11
15#include "boost/tokenizer.hpp"
16
17
18namespace D3PD {
19
20
27SGKeyResolver::SGKeyResolver (const std::string& name,
29 std::string& sgkey)
30 : m_name (name),
31 m_sg (sg),
32 m_clid (CLID_NULL),
33 m_sgkey (sgkey),
34 m_haveKey (false)
35{
36}
37
38
44StatusCode SGKeyResolver::initialize (CLID clid, const std::string& typname)
45{
46 m_clid = clid;
47 m_typname = typname;
48 return StatusCode::SUCCESS;
49}
50
51
55std::string SGKeyResolver::key()
56{
57 if (m_haveKey)
58 return m_usedKey;
59
60 // Split the requested string into individual keys.
61 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
62 boost::char_separator<char> sep(" ,");
63 tokenizer tokens(m_sgkey, sep);
64 std::vector<std::string> keys (tokens.begin(), tokens.end());
65
66 // First see if any existing proxies match the keys.
67 std::vector<const SG::DataProxy*> proxies = m_sg->proxies();
68 for (const SG::DataProxy* & p : proxies) {
69 if (p->transientID (m_clid) &&
70 std::find (keys.begin(), keys.end(), p->name()) != keys.end())
71 {
72 if (!m_haveKey ||
73 std::find (keys.begin(), keys.end(), p->name()) <
74 std::find (keys.begin(), keys.end(), m_usedKey))
75 {
76 m_usedKey = p->name();
77 m_haveKey = true;
78 }
79 }
80 }
81
82 // If we haven't found one, try retrieving proxies individually.
83 // This can call to the proxy providers.
84 if (!m_haveKey) {
85 for (std::string& key : keys) {
86 m_usedKey = key;
87 if (m_sg->proxy (m_clid, m_usedKey)) {
88 m_haveKey = true;
89 break;
90 }
91 }
92 }
93
94 if (m_haveKey) {
96 << "Using StoreGate object: "
97 << m_typname << "(" << m_clid << ")/" << m_usedKey;
98 }
99
100 return m_usedKey;
101}
102
103
104} // namespace D3PD
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
uint32_t CLID
The Class ID type.
Helper to resolve the SG key to use.
ServiceHandle< StoreGateSvc > & m_sg
The event storage service.
bool m_haveKey
Flag that m_usedKey is valid.
std::string m_name
The name of the tool/alg in which this is used.
SGKeyResolver(const std::string &name, ServiceHandle< StoreGateSvc > &sg, std::string &sgkey)
Constructor.
CLID m_clid
The CLID of the desired type.
std::string m_typname
The name of the desired type.
std::string m_usedKey
The actual key we'll use.
std::string & m_sgkey
The requested SG key.
std::string key()
Return the SG key we should use.
StatusCode initialize()
Initialize, from a type.
Block filler tool for noisy FEB information.