ATLAS Offline Software
TypelessWriteHandleKey.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration.
3  */
13 #include "StoreGate/exceptions.h"
15 #include "GaudiKernel/IClassIDSvc.h"
16 #include "GaudiKernel/ServiceHandle.h"
17 
18 
19 namespace SG {
20 
21 
33  const std::string& key /*= ""*/,
34  const std::string& storeName /*= "StoreGateSvc"*/)
35  : VarHandleKey (clid, key,
37  storeName)
38 {
39 }
40 
41 
51 {
52  if (assign (sgkey).isFailure()) {
53  throw SG::ExcBadHandleKey (sgkey);
54  }
55  return *this;
56 }
57 
58 
68 StatusCode TypelessWriteHandleKey::assign (const std::string& key_in)
69 {
70  std::string key = key_in;
71 
72  // Handle a possible class name.
73  std::string::size_type islash = key.find ('/');
74  if (islash != std::string::npos) {
75  std::string::size_type istart = key.find ('+');
76  if (istart == std::string::npos) {
77  istart = 0;
78  }
79  else {
80  ++istart;
81  }
82 
83  // Excise the class name part from the key.
84  std::string clname = key.substr (istart, islash-istart);
85  key.erase (istart, islash+1-istart);
86 
87  // Look up the class name with the CLID service.
88  ServiceHandle<IClassIDSvc> clidsvc ("ClassIDSvc", "TypelessWriteHandleKey");
89  CHECK( clidsvc.retrieve() );
90  CLID clid = CLID_NULL;
91  CHECK( clidsvc->getIDOfTypeName (clname, clid) );
92 
93  // Modify the CLID of this key.
94  Gaudi::DataHandle::setKey (DataObjID (clid, objKey()));
95  }
96 
97  // Change the key/store. Class name has been removed from the string
98  // by this point.
99  return VarHandleKey::assign (key);
100 }
101 
102 
103 } // namespace SG
common.sgkey
def sgkey(tool)
Definition: common.py:1028
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::TypelessWriteHandleKey::operator=
TypelessWriteHandleKey & operator=(const std::string &sgkey)
Change the key of the object to which we're referring.
Definition: TypelessWriteHandleKey.cxx:50
AthTPCnvSvc_test.clidsvc
clidsvc
Definition: AthTPCnvSvc_test.py:10
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::TypelessWriteHandleKey
Property holding a write key for which the type can be configured.
Definition: TypelessWriteHandleKey.h:35
exceptions.h
Exceptions that can be thrown from StoreGate.
SG::VarHandleKey::assign
virtual StatusCode assign(const std::string &sgkey)
Change the key of the object to which we're referring.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:88
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ExcBadHandleKey
Exception — Bad key format for VarHandleKey.
Definition: Control/StoreGate/StoreGate/exceptions.h:62
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
errorcheck.h
Helpers for checking error return status codes and reporting errors.
DataHandle
an iterator over instances of a given type in StoreGateSvc. It d-casts and caches locally the pointed...
Definition: DataHandle.h:42
SG::VarHandleKey::clid
CLID clid() const
Return the class ID for the referenced object.
Definition: StoreGate/src/VarHandleKey.cxx:177
SG::VarHandleKey
A property holding a SG store/key/clid from which a VarHandle is made.
Definition: StoreGate/StoreGate/VarHandleKey.h:62
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
LHEF::Writer
Pythia8::Writer Writer
Definition: Prophecy4fMerger.cxx:12
SG::TypelessWriteHandleKey::assign
virtual StatusCode assign(const std::string &key) override
Change the key of the object to which we're referring.
Definition: TypelessWriteHandleKey.cxx:68
TypelessWriteHandleKey.h
Property holding a write key for which the type can be configured.
SG::TypelessWriteHandleKey::TypelessWriteHandleKey
TypelessWriteHandleKey(CLID clid=CLID_NULL, const std::string &key="", const std::string &storeName=StoreID::storeName(StoreID::EVENT_STORE))
Constructor.
Definition: TypelessWriteHandleKey.cxx:32
ServiceHandle< IClassIDSvc >
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37