ATLAS Offline Software
AthenaRootSerializeSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /* file contains the implementation for the AthenaRootSerializeSvc class.
6  * @author Peter van Gemmeren <gemmeren@anl.gov>
7  **/
8 
10 #include "DataModelRoot/RootType.h"
11 
12 #include "StorageSvc/DbReflex.h"
13 #include "TBufferFile.h"
14 #include "TClass.h"
15 
16 //___________________________________________________________________________
18  ISvcLocator* pSvcLocator) : base_class(name, pSvcLocator) {
19 }
20 
21 //___________________________________________________________________________
23 }
24 
25 //___________________________________________________________________________
27  ATH_MSG_INFO("Initializing " << name());
28 
29  // Load message handler dictionary to avoid crashes when reporting
30  // possible errors during event processing (ATR-25049)
31  TClass::GetClass("TMessageHandler");
32 
33  return(StatusCode::SUCCESS);
34 }
35 
36 //___________________________________________________________________________
37 void* AthenaRootSerializeSvc::serialize(const void* /*object*/, const std::string& /*name*/, size_t& /*nbytes*/) const {
38  return(nullptr);
39 }
40 
41 //___________________________________________________________________________
42 void* AthenaRootSerializeSvc::serialize(const void* object, const Guid& id, size_t& nbytes) const {
43  return(this->serialize(object, pool::DbReflex::forGuid(id), nbytes));
44 }
45 
46 //___________________________________________________________________________
47 void* AthenaRootSerializeSvc::serialize(const void* object, const RootType& cltype, size_t& nbytes) const {
48  TBufferFile writeBuffer(TBuffer::kWrite);
49  writeBuffer.WriteObjectAny(object, cltype);
50  void* buffer = writeBuffer.Buffer();
51  nbytes = writeBuffer.Length();
52  writeBuffer.ResetBit(TBuffer::kIsOwner); writeBuffer.SetBuffer(nullptr);
53  return(buffer);
54 }
55 
56 //___________________________________________________________________________
57 void* AthenaRootSerializeSvc::deserialize(void* /*buffer*/, size_t& /*nbytes*/, const std::string& /*name*/) const {
58  return(nullptr);
59 }
60 
61 //___________________________________________________________________________
62 void* AthenaRootSerializeSvc::deserialize(void* buffer, size_t& nbytes, const Guid& id) const {
63  return(this->deserialize(buffer, nbytes, pool::DbReflex::forGuid(id)));
64 }
65 
66 //___________________________________________________________________________
67 void* AthenaRootSerializeSvc::deserialize(void* buffer, size_t& nbytes, const RootType& cltype) const {
68  void* obj = nullptr;
69  if (cltype.IsFundamental()) {
70  obj = new char[nbytes];
71  std::memcpy(obj, buffer, nbytes);
72  } else if (cltype.Name() == "Token") { // Token is C string
73  obj = new char[nbytes];
74  std::memcpy(obj, buffer, nbytes); static_cast<char*>(obj)[nbytes - 1] = 0;
75  } else {
76  TBufferFile readBuffer(TBuffer::kRead, nbytes, buffer, kFALSE);
77  obj = readBuffer.ReadObjectAny(cltype);
78  nbytes = readBuffer.Length();
79  }
80  return(obj);
81 }
AthenaRootSerializeSvc::deserialize
virtual void * deserialize(void *buffer, size_t &nbytes, const std::string &name) const override
Definition: AthenaRootSerializeSvc.cxx:57
DbReflex.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthenaRootSerializeSvc::~AthenaRootSerializeSvc
virtual ~AthenaRootSerializeSvc()
Destructor.
Definition: AthenaRootSerializeSvc.cxx:22
pool::DbReflex::forGuid
static const TypeH forGuid(const Guid &info)
Access classes by Guid.
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthenaRootSerializeSvc.h
This file contains the class definition for the AthenaRootSerializeSvc class.
AthenaRootSerializeSvc::initialize
virtual StatusCode initialize() override
Gaudi Service Interface method implementations:
Definition: AthenaRootSerializeSvc.cxx:26
TScopeAdapter::Name
std::string Name(unsigned int mod=Reflex::SCOPED) const
Definition: RootType.cxx:607
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AthenaRootSerializeSvc::AthenaRootSerializeSvc
AthenaRootSerializeSvc(const std::string &name, ISvcLocator *pSvcLocator)
Standard Service Constructor.
Definition: AthenaRootSerializeSvc.cxx:17
TScopeAdapter::IsFundamental
Bool_t IsFundamental() const
Definition: RootType.cxx:726
Guid
This class provides a encapsulation of a GUID/UUID/CLSID/IID data structure (128 bit number).
Definition: Guid.h:20
RootType.h
python.PyAthena.obj
obj
Definition: PyAthena.py:132
AthenaRootSerializeSvc::serialize
virtual void * serialize(const void *object, const std::string &name, size_t &nbytes) const override
Definition: AthenaRootSerializeSvc.cxx:37
TScopeAdapter
Definition: RootType.h:119