ATLAS Offline Software
DecorKeyHelpers.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
3  */
13 #include "StoreGate/exceptions.h"
14 #include "StoreGate/VarHandleKey.h"
15 
16 
17 namespace SG {
18 
19 
26 std::string contKeyFromKey (const std::string& key)
27 {
28  std::string::size_type ipos = key.find ('.');
29  if (ipos == std::string::npos)
30  return key;
31  return key.substr (0, ipos);
32 }
33 
34 
41 std::string decorKeyFromKey (const std::string& key)
42 {
43  std::string::size_type ipos = key.find ('.');
44  if (ipos == std::string::npos)
45  return "";
46  return key.substr (ipos+1, std::string::npos);
47 }
48 
49 
58 std::string makeContDecorKey(const std::string& cont, const std::string& decor)
59 {
60  if (cont.empty()) return decor;
61  if (decor.empty()) return cont;
62  return cont + '.' + decor;
63 }
64 
65 
76 std::string makeContDecorKey(const VarHandleKey& contKey, const std::string& key)
77 {
78  if (key.empty() || key.ends_with ('+')) {
79  return "";
80  }
81  if (key.find('.') != std::string::npos) {
82  throw SG::ExcBadHandleKey(key + " (DecorHandleKey has been declared with a parent container. "
83  "Its value should not contain any container name.)");
84  }
85 
86  // Note: VHK::fullKey().key() contains the store prefix, key() does not.
87  return makeContDecorKey( contKey.fullKey().key(), key);
88 }
89 
90 
98 void removeContFromDecorKey(const VarHandleKey& contKey, std::string& key)
99 {
100  // Remove container name from key
101  const std::string toerase = contKey.fullKey().key() + ".";
102  const size_t pos = key.find(toerase);
103  if (pos != std::string::npos) {
104  key.erase(pos, toerase.size());
105  }
106 
107 }
108 
109 } // namespace SG
SG::contKeyFromKey
std::string contKeyFromKey(const std::string &key)
Extract the container part of key.
Definition: DecorKeyHelpers.cxx:26
VarHandleKey.h
A property holding a SG store/key/clid from which a VarHandle is made.
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::decorKeyFromKey
std::string decorKeyFromKey(const std::string &key)
Extract the decoration part of key.
Definition: DecorKeyHelpers.cxx:41
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
DecorKeyHelpers.h
Some common helper functions used by decoration handles.
exceptions.h
Exceptions that can be thrown from StoreGate.
SG::removeContFromDecorKey
void removeContFromDecorKey(const VarHandleKey &contKey, std::string &key)
Remove container name from decoration key.
Definition: DecorKeyHelpers.cxx:98
SG::ExcBadHandleKey
Exception — Bad key format for VarHandleKey.
Definition: Control/StoreGate/StoreGate/exceptions.h:62
SG::VarHandleKey
A property holding a SG store/key/clid from which a VarHandle is made.
Definition: StoreGate/StoreGate/VarHandleKey.h:62
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
SG::makeContDecorKey
std::string makeContDecorKey(const std::string &cont, const std::string &decor)
Make a StoreGate key from container and decoration name.
Definition: DecorKeyHelpers.cxx:58
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37