ATLAS Offline Software
SGKeyResolver.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
13 #include "StoreGate/StoreGateSvc.h"
15 #include "boost/tokenizer.hpp"
16 
17 
18 namespace D3PD {
19 
20 
27 SGKeyResolver::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 
44 StatusCode SGKeyResolver::initialize (CLID clid, const std::string& typname)
45 {
46  m_clid = clid;
47  m_typname = typname;
48  return StatusCode::SUCCESS;
49 }
50 
51 
55 std::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
D3PD::SGKeyResolver::initialize
StatusCode initialize()
Initialize, from a type.
D3PD::SGKeyResolver::m_name
std::string m_name
The name of the tool/alg in which this is used.
Definition: SGKeyResolver.h:76
D3PD::SGKeyResolver::m_usedKey
std::string m_usedKey
The actual key we'll use.
Definition: SGKeyResolver.h:91
common.sgkey
def sgkey(tool)
Definition: common.py:1028
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
D3PD::SGKeyResolver::m_typname
std::string m_typname
The name of the desired type.
Definition: SGKeyResolver.h:85
beamspotman.tokens
tokens
Definition: beamspotman.py:1284
D3PD::SGKeyResolver::m_sgkey
std::string & m_sgkey
The requested SG key.
Definition: SGKeyResolver.h:88
D3PD::SGKeyResolver::m_sg
ServiceHandle< StoreGateSvc > & m_sg
The event storage service.
Definition: SGKeyResolver.h:79
D3PD
Block filler tool for noisy FEB information.
Definition: CaloCellDetailsFillerTool.cxx:29
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
SGKeyResolver.h
Helper to resolve the SG key to use.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
D3PD::SGKeyResolver::SGKeyResolver
SGKeyResolver(const std::string &name, ServiceHandle< StoreGateSvc > &sg, std::string &sgkey)
Constructor.
Definition: SGKeyResolver.cxx:27
REPORT_MESSAGE_WITH_CONTEXT
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:345
D3PD::SGKeyResolver::m_haveKey
bool m_haveKey
Flag that m_usedKey is valid.
Definition: SGKeyResolver.h:94
grepfile.sep
sep
Definition: grepfile.py:38
D3PD::SGKeyResolver::key
std::string key()
Return the SG key we should use.
Definition: SGKeyResolver.cxx:55
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
errorcheck.h
Helpers for checking error return status codes and reporting errors.
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
SG::DataProxy
Definition: DataProxy.h:44
StoreGateSvc.h
D3PD::SGKeyResolver::m_clid
CLID m_clid
The CLID of the desired type.
Definition: SGKeyResolver.h:82
ServiceHandle< StoreGateSvc >