ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
D3PD::SGKeyResolver Class Reference

Helper to resolve the SG key to use. More...

#include <SGKeyResolver.h>

Collaboration diagram for D3PD::SGKeyResolver:

Public Member Functions

 SGKeyResolver (const std::string &name, ServiceHandle< StoreGateSvc > &sg, std::string &sgkey)
 Constructor. More...
 
StatusCode initialize (CLID clid, const std::string &typname)
 Initialize. More...
 
template<typename T >
StatusCode initialize ()
 Initialize, from a type. More...
 
std::string key ()
 Return the SG key we should use. More...
 

Private Attributes

std::string m_name
 The name of the tool/alg in which this is used. More...
 
ServiceHandle< StoreGateSvc > & m_sg
 The event storage service. More...
 
CLID m_clid
 The CLID of the desired type. More...
 
std::string m_typname
 The name of the desired type. More...
 
std::string & m_sgkey
 The requested SG key. More...
 
std::string m_usedKey
 The actual key we'll use. More...
 
bool m_haveKey
 Flag that m_usedKey is valid. More...
 

Detailed Description

Helper to resolve the SG key to use.

For the D3PD maker, we allow SG keys to be a comma-separated list. When we first look up the object, we try each of these keys in order, and use the first one that actually exists in SG.

This simplifies configurations for multiple data formats.

This is a helper object to actually to the resolution.

Definition at line 39 of file SGKeyResolver.h.

Constructor & Destructor Documentation

◆ SGKeyResolver()

D3PD::SGKeyResolver::SGKeyResolver ( const std::string &  name,
ServiceHandle< StoreGateSvc > &  sg,
std::string &  sgkey 
)

Constructor.

Parameters
nameThe name of the tool/alg in which this is used.
sgThe event store service.
sgkeyThe property of the requested key.

Definition at line 27 of file SGKeyResolver.cxx.

30  : m_name (name),
31  m_sg (sg),
32  m_clid (CLID_NULL),
33  m_sgkey (sgkey),
34  m_haveKey (false)
35 {
36 }

Member Function Documentation

◆ initialize() [1/2]

template<typename T >
StatusCode D3PD::SGKeyResolver::initialize ( )

Initialize, from a type.

◆ initialize() [2/2]

StatusCode D3PD::SGKeyResolver::initialize ( CLID  clid,
const std::string &  typname 
)

Initialize.

Parameters
clidThe CLID of the desired type.
typenameThe name of the desired type.
clidThe CLID of the desired object.
typnameThe name of the desired type.

Definition at line 44 of file SGKeyResolver.cxx.

45 {
46  m_clid = clid;
47  m_typname = typname;
48  return StatusCode::SUCCESS;
49 }

◆ key()

std::string D3PD::SGKeyResolver::key ( )

Return the SG key we should use.

Definition at line 55 of file SGKeyResolver.cxx.

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 }

Member Data Documentation

◆ m_clid

CLID D3PD::SGKeyResolver::m_clid
private

The CLID of the desired type.

Definition at line 82 of file SGKeyResolver.h.

◆ m_haveKey

bool D3PD::SGKeyResolver::m_haveKey
private

Flag that m_usedKey is valid.

Definition at line 94 of file SGKeyResolver.h.

◆ m_name

std::string D3PD::SGKeyResolver::m_name
private

The name of the tool/alg in which this is used.

Definition at line 76 of file SGKeyResolver.h.

◆ m_sg

ServiceHandle<StoreGateSvc>& D3PD::SGKeyResolver::m_sg
private

The event storage service.

Definition at line 79 of file SGKeyResolver.h.

◆ m_sgkey

std::string& D3PD::SGKeyResolver::m_sgkey
private

The requested SG key.

Definition at line 88 of file SGKeyResolver.h.

◆ m_typname

std::string D3PD::SGKeyResolver::m_typname
private

The name of the desired type.

Definition at line 85 of file SGKeyResolver.h.

◆ m_usedKey

std::string D3PD::SGKeyResolver::m_usedKey
private

The actual key we'll use.

Definition at line 91 of file SGKeyResolver.h.


The documentation for this class was generated from the following files:
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
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
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
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:195
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
SG::DataProxy
Definition: DataProxy.h:44
D3PD::SGKeyResolver::m_clid
CLID m_clid
The CLID of the desired type.
Definition: SGKeyResolver.h:82