ATLAS Offline Software
Loading...
Searching...
No Matches
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
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//___________________________________________________________________________
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//___________________________________________________________________________
37void* AthenaRootSerializeSvc::serialize(const void* /*object*/, const std::string& /*name*/, size_t& /*nbytes*/) const {
38 return(nullptr);
39}
40
41//___________________________________________________________________________
42void* 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//___________________________________________________________________________
47void* 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//___________________________________________________________________________
57void* AthenaRootSerializeSvc::deserialize(void* /*buffer*/, size_t& /*nbytes*/, const std::string& /*name*/) const {
58 return(nullptr);
59}
60
61//___________________________________________________________________________
62void* AthenaRootSerializeSvc::deserialize(void* buffer, size_t& nbytes, const Guid& id) const {
63 return(this->deserialize(buffer, nbytes, pool::DbReflex::forGuid(id)));
64}
65
66//___________________________________________________________________________
67void* 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}
#define ATH_MSG_INFO(x)
This file contains the class definition for the AthenaRootSerializeSvc class.
TTypeAdapter RootType
Definition RootType.h:211
virtual StatusCode initialize() override
Gaudi Service Interface method implementations:
AthenaRootSerializeSvc(const std::string &name, ISvcLocator *pSvcLocator)
Standard Service Constructor.
virtual ~AthenaRootSerializeSvc()
Destructor.
virtual void * serialize(const void *object, const std::string &name, size_t &nbytes) const override
virtual void * deserialize(void *buffer, size_t &nbytes, const std::string &name) const override
This class provides a encapsulation of a GUID/UUID/CLSID/IID data structure (128 bit number).
Definition Guid.h:25
Bool_t IsFundamental() const
Definition RootType.cxx:731
std::string Name(unsigned int mod=Reflex::SCOPED) const
Definition RootType.cxx:612
static const TypeH forGuid(const Guid &info)
Access classes by Guid.