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 "TBufferFile.h"
13#include "TClass.h"
14
15//___________________________________________________________________________
17 ISvcLocator* pSvcLocator) : base_class(name, pSvcLocator) {
18}
19
20//___________________________________________________________________________
23
24//___________________________________________________________________________
26 ATH_MSG_INFO("Initializing " << name());
27
28 // Load message handler dictionary to avoid crashes when reporting
29 // possible errors during event processing (ATR-25049)
30 TClass::GetClass("TMessageHandler");
31
32 return(StatusCode::SUCCESS);
33}
34
35//___________________________________________________________________________
36void* AthenaRootSerializeSvc::serialize(const void* object, const RootType& cltype, size_t& nbytes) const {
37 TBufferFile writeBuffer(TBuffer::kWrite);
38 writeBuffer.WriteObjectAny(object, cltype);
39 void* buffer = writeBuffer.Buffer();
40 nbytes = writeBuffer.Length();
41 writeBuffer.ResetBit(TBuffer::kIsOwner); writeBuffer.SetBuffer(nullptr);
42 return(buffer);
43}
44
45//___________________________________________________________________________
46void* AthenaRootSerializeSvc::deserialize(void* buffer, size_t& nbytes, const RootType& cltype) const {
47 void* obj = nullptr;
48 if (cltype.IsFundamental()) {
49 obj = new char[nbytes];
50 std::memcpy(obj, buffer, nbytes);
51 } else if (cltype.Name() == "Token") { // Token is C string
52 obj = new char[nbytes];
53 std::memcpy(obj, buffer, nbytes); static_cast<char*>(obj)[nbytes - 1] = 0;
54 } else {
55 TBufferFile readBuffer(TBuffer::kRead, nbytes, buffer, kFALSE);
56 obj = readBuffer.ReadObjectAny(cltype);
57 nbytes = readBuffer.Length();
58 }
59 return(obj);
60}
#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:
virtual void * deserialize(void *buffer, size_t &nbytes, const RootType &cltype) const override
virtual void * serialize(const void *object, const RootType &cltype, size_t &nbytes) const override
AthenaRootSerializeSvc(const std::string &name, ISvcLocator *pSvcLocator)
Standard Service Constructor.
virtual ~AthenaRootSerializeSvc()
Destructor.
Bool_t IsFundamental() const
Definition RootType.cxx:731
std::string Name(unsigned int mod=Reflex::SCOPED) const
Definition RootType.cxx:612