Logo ROOT  
Reference Guide
TBufferIO.h
Go to the documentation of this file.
1 // @(#)root/io:$Id$
2 // Author: Sergey Linev 21/02/2018
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TBufferIO
13 #define ROOT_TBufferIO
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TBufferIO //
18 // //
19 // Direct subclass of TBuffer, implements common methods for //
20 // TBufferFile and TBufferText classes //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include "TBuffer.h"
25 
26 #include "TString.h"
27 
28 class TExMap;
29 
30 class TBufferIO : public TBuffer {
31 
32 protected:
33  enum { kNullTag = 0 }; ///< tag value for nullptr in objects map
34 
35  Int_t fMapCount{0}; ///< Number of objects or classes in map
36  Int_t fMapSize{0}; ///< Default size of map
37  Int_t fDisplacement{0}; ///< Value to be added to the map offsets
38  UShort_t fPidOffset{0}; ///< Offset to be added to the pid index in this key/buffer.
39  TExMap *fMap{nullptr}; ///< Map containing object,offset pairs for reading/writing
40  TExMap *fClassMap{nullptr}; ///< Map containing object,class pairs for reading
41 
42  static Int_t fgMapSize; ///< Default map size for all TBuffer objects
43 
44  TBufferIO() {} // NOLINT: not allowed to use = default because of TObject::kIsOnHeap detection, see ROOT-10300
45 
47  TBufferIO(TBuffer::EMode mode, Int_t bufsiz);
48  TBufferIO(TBuffer::EMode mode, Int_t bufsiz, void *buf, Bool_t adopt = kTRUE,
49  ReAllocCharFun_t reallocfunc = nullptr);
50 
51  ////////////////////////////////////////////////////////////////////////////////
52  /// Return hash value for provided object.
53  static R__ALWAYS_INLINE ULong_t Void_Hash(const void *ptr) { return TString::Hash(&ptr, sizeof(void *)); }
54 
55  // method used in TBufferFile, keep here for full compatibility
56  virtual void CheckCount(UInt_t) {}
57 
58  Long64_t GetObjectTag(const void *obj);
59 
60  virtual void WriteObjectClass(const void *actualObjStart, const TClass *actualClass, Bool_t cacheReuse) = 0;
61 
62 public:
63  enum { kMapSize = 503 }; ///< default objects map size
64 
65  enum EStatusBits {
66  kNotDecompressed = BIT(15), // indicates a weird buffer, used by TBasket
67  kTextBasedStreaming = BIT(18), // indicates if buffer used for XML/SQL object streaming
68 
69  kUser1 = BIT(21), // free for user
70  kUser2 = BIT(22), // free for user
71  kUser3 = BIT(23) // free for user
72  };
73 
74  virtual ~TBufferIO();
75 
76  Int_t GetVersionOwner() const override;
77 
78  // See comment in TBuffer::SetPidOffset
79  UShort_t GetPidOffset() const override { return fPidOffset; }
80  void SetPidOffset(UShort_t offset) override;
81  Int_t GetBufferDisplacement() const override { return fDisplacement; }
82  void SetBufferDisplacement() override { fDisplacement = 0; }
83  void SetBufferDisplacement(Int_t skipped) override { fDisplacement = (Int_t)(Length() - skipped); }
84 
85  // Utilities for objects map
86  void SetReadParam(Int_t mapsize) override;
87  void SetWriteParam(Int_t mapsize) override;
88  void InitMap() override;
89  void ResetMap() override;
90  void Reset() override;
91  Int_t GetMapCount() const override { return fMapCount; }
92  void MapObject(const TObject *obj, UInt_t offset = 1) override;
93  void MapObject(const void *obj, const TClass *cl, UInt_t offset = 1) override;
94  Bool_t CheckObject(const TObject *obj) override;
95  Bool_t CheckObject(const void *obj, const TClass *ptrClass) override;
96  void GetMappedObject(UInt_t tag, void *&ptr, TClass *&ClassPtr) const override;
97 
98  // Utilities for TStreamerInfo
99  void ForceWriteInfo(TVirtualStreamerInfo *info, Bool_t force) override;
100  void ForceWriteInfoClones(TClonesArray *a) override;
101  Int_t ReadClones(TClonesArray *a, Int_t nobjects, Version_t objvers) override;
102  Int_t WriteClones(TClonesArray *a, Int_t nobjects) override;
103  void TagStreamerInfo(TVirtualStreamerInfo *info) override;
104 
105  // Special basic ROOT objects and collections
106  TProcessID *GetLastProcessID(TRefTable *reftable) const override;
107  UInt_t GetTRefExecId() override;
108  TProcessID *ReadProcessID(UShort_t pidf) override;
109  UShort_t WriteProcessID(TProcessID *pid) override;
110 
111  Int_t WriteObjectAny(const void *obj, const TClass *ptrClass, Bool_t cacheReuse = kTRUE) override;
112  void WriteObject(const TObject *obj, Bool_t cacheReuse = kTRUE) override;
113  using TBuffer::WriteObject;
114 
115  static void SetGlobalReadParam(Int_t mapsize);
116  static void SetGlobalWriteParam(Int_t mapsize);
117  static Int_t GetGlobalReadParam();
118  static Int_t GetGlobalWriteParam();
119 
120  ClassDefOverride(TBufferIO, 0) // base class, share methods for TBufferFile and TBufferText
121 };
122 
123 #endif
TBufferIO::fPidOffset
UShort_t fPidOffset
Offset to be added to the pid index in this key/buffer.
Definition: TBufferIO.h:38
TBufferIO::WriteObject
void WriteObject(const TObject *obj, Bool_t cacheReuse=kTRUE) override
Write object to I/O buffer.
Definition: TBufferIO.cxx:530
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TBufferIO::ReadClones
Int_t ReadClones(TClonesArray *a, Int_t nobjects, Version_t objvers) override
Interface to TStreamerInfo::ReadBufferClones.
Definition: TBufferIO.cxx:372
Version_t
short Version_t
Definition: RtypesCore.h:65
TBufferIO::ForceWriteInfoClones
void ForceWriteInfoClones(TClonesArray *a) override
Make sure TStreamerInfo is not optimized, otherwise it will not be possible to support schema evoluti...
Definition: TBufferIO.cxx:341
TBufferIO::fgMapSize
static Int_t fgMapSize
Default map size for all TBuffer objects.
Definition: TBufferIO.h:42
TBufferIO::GetBufferDisplacement
Int_t GetBufferDisplacement() const override
Definition: TBufferIO.h:81
TBufferIO::CheckCount
virtual void CheckCount(UInt_t)
Definition: TBufferIO.h:56
UShort_t
unsigned short UShort_t
Definition: RtypesCore.h:40
TBufferIO::SetPidOffset
void SetPidOffset(UShort_t offset) override
This offset is used when a key (or basket) is transfered from one file to the other.
Definition: TBufferIO.cxx:319
TBufferIO::ResetMap
void ResetMap() override
Delete existing fMap and reset map counter.
Definition: TBufferIO.cxx:288
TBufferIO::SetBufferDisplacement
void SetBufferDisplacement(Int_t skipped) override
Definition: TBufferIO.h:83
TBufferIO::GetObjectTag
Long64_t GetObjectTag(const void *obj)
Returns tag for specified object from objects map (if exists) Returns 0 if object not included into o...
Definition: TBufferIO.cxx:277
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TBufferIO::WriteObjectAny
Int_t WriteObjectAny(const void *obj, const TClass *ptrClass, Bool_t cacheReuse=kTRUE) override
Write object to I/O buffer.
Definition: TBufferIO.cxx:492
TBuffer::WriteObject
virtual void WriteObject(const TObject *obj, Bool_t cacheReuse)=0
TProcessID
Definition: TProcessID.h:74
Int_t
int Int_t
Definition: RtypesCore.h:45
TBufferIO::CheckObject
Bool_t CheckObject(const TObject *obj) override
Check if the specified object is already in the buffer.
Definition: TBufferIO.cxx:225
TBuffer::EStatusBits
EStatusBits
Definition: TBuffer.h:74
TString::Hash
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
Definition: TString.cxx:638
TBufferIO::Reset
void Reset() override
Reset buffer object. Resets map and buffer offset.
Definition: TBufferIO.cxx:305
TBufferIO::MapObject
void MapObject(const TObject *obj, UInt_t offset=1) override
Add object to the fMap container.
Definition: TBufferIO.cxx:163
TBufferIO::SetGlobalWriteParam
static void SetGlobalWriteParam(Int_t mapsize)
Set the initial size of the map used to store object and class references during reading.
Definition: TBufferIO.cxx:564
ReAllocCharFun_t
char *(* ReAllocCharFun_t)(char *, size_t, size_t)
Definition: TStorage.h:30
TBuffer
Definition: TBuffer.h:43
TBufferIO::GetLastProcessID
TProcessID * GetLastProcessID(TRefTable *reftable) const override
Return the last TProcessID in the file.
Definition: TBufferIO.cxx:399
TBufferIO::TagStreamerInfo
void TagStreamerInfo(TVirtualStreamerInfo *info) override
Mark the classindex of the current file as using this TStreamerInfo.
Definition: TBufferIO.cxx:350
TBufferIO::InitMap
void InitMap() override
Create the fMap container and initialize them with the null object.
Definition: TBufferIO.cxx:129
TBufferIO::~TBufferIO
virtual ~TBufferIO()
destructor
Definition: TBufferIO.cxx:68
ClassDefOverride
#define ClassDefOverride(name, id)
Definition: Rtypes.h:329
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TString.h
TVirtualStreamerInfo
Definition: TVirtualStreamerInfo.h:37
TBufferIO::fMapSize
Int_t fMapSize
Default size of map.
Definition: TBufferIO.h:36
TBufferIO::kUser3
@ kUser3
Definition: TBufferIO.h:71
TBuffer::Length
Int_t Length() const
Definition: TBuffer.h:100
TBufferIO::kNullTag
@ kNullTag
Definition: TBufferIO.h:33
TBufferIO::WriteProcessID
UShort_t WriteProcessID(TProcessID *pid) override
Check if the ProcessID pid is already in the file.
Definition: TBufferIO.cxx:456
TBuffer.h
TBufferIO::kUser2
@ kUser2
Definition: TBufferIO.h:70
TBuffer::EMode
EMode
Definition: TBuffer.h:73
TBufferIO::kNotDecompressed
@ kNotDecompressed
Definition: TBufferIO.h:66
TBufferIO::GetGlobalWriteParam
static Int_t GetGlobalWriteParam()
Get default write map size.
Definition: TBufferIO.cxx:580
a
auto * a
Definition: textangle.C:12
TBufferIO::GetTRefExecId
UInt_t GetTRefExecId() override
Return the exec id stored in the current TStreamerInfo element.
Definition: TBufferIO.cxx:447
TBufferIO::GetGlobalReadParam
static Int_t GetGlobalReadParam()
Get default read map size.
Definition: TBufferIO.cxx:572
TBufferIO::SetReadParam
void SetReadParam(Int_t mapsize) override
Set the initial size of the map used to store object and class references during reading.
Definition: TBufferIO.cxx:97
TBufferIO::TBufferIO
TBufferIO()
Definition: TBufferIO.h:44
TBufferIO::ReadProcessID
TProcessID * ReadProcessID(UShort_t pidf) override
The TProcessID with number pidf is read from file.
Definition: TBufferIO.cxx:422
BIT
#define BIT(n)
Definition: Rtypes.h:85
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TBufferIO::fClassMap
TExMap * fClassMap
Map containing object,class pairs for reading.
Definition: TBufferIO.h:40
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TBufferIO::GetMapCount
Int_t GetMapCount() const override
Definition: TBufferIO.h:91
unsigned int
TBufferIO
Definition: TBufferIO.h:30
TRefTable
Definition: TRefTable.h:35
TBufferIO::WriteClones
Int_t WriteClones(TClonesArray *a, Int_t nobjects) override
Interface to TStreamerInfo::WriteBufferClones.
Definition: TBufferIO.cxx:385
TBufferIO::kMapSize
@ kMapSize
Definition: TBufferIO.h:63
TBufferIO::fDisplacement
Int_t fDisplacement
Value to be added to the map offsets.
Definition: TBufferIO.h:37
TClass
Definition: TClass.h:80
TBufferIO::kUser1
@ kUser1
Definition: TBufferIO.h:69
TObject
Definition: TObject.h:37
TBufferIO::SetGlobalReadParam
static void SetGlobalReadParam(Int_t mapsize)
Set the initial size of the map used to store object and class references during reading.
Definition: TBufferIO.cxx:548
TBufferIO::WriteObjectClass
virtual void WriteObjectClass(const void *actualObjStart, const TClass *actualClass, Bool_t cacheReuse)=0
TExMap
Definition: TExMap.h:33
TBufferIO::GetVersionOwner
Int_t GetVersionOwner() const override
Return the version number of the owner file.
Definition: TBufferIO.cxx:77
TBufferIO::SetBufferDisplacement
void SetBufferDisplacement() override
Definition: TBufferIO.h:82
TBufferIO::Void_Hash
static R__ALWAYS_INLINE ULong_t Void_Hash(const void *ptr)
Return hash value for provided object.
Definition: TBufferIO.h:53
TBufferIO::GetMappedObject
void GetMappedObject(UInt_t tag, void *&ptr, TClass *&ClassPtr) const override
Retrieve the object stored in the buffer's object map at 'tag' Set ptr and ClassPtr respectively to t...
Definition: TBufferIO.cxx:260
TBufferIO::GetPidOffset
UShort_t GetPidOffset() const override
Definition: TBufferIO.h:79
TBufferIO::fMapCount
Int_t fMapCount
Number of objects or classes in map.
Definition: TBufferIO.h:35
TClonesArray
Definition: TClonesArray.h:29
TBufferIO::kTextBasedStreaming
@ kTextBasedStreaming
Definition: TBufferIO.h:67
TBufferIO::fMap
TExMap * fMap
Map containing object,offset pairs for reading/writing.
Definition: TBufferIO.h:39
int
R__ALWAYS_INLINE
#define R__ALWAYS_INLINE
Definition: RConfig.hxx:570
TBufferIO::ForceWriteInfo
void ForceWriteInfo(TVirtualStreamerInfo *info, Bool_t force) override
force writing the TStreamerInfo to the file
Definition: TBufferIO.cxx:329
TBufferIO::SetWriteParam
void SetWriteParam(Int_t mapsize) override
Set the initial size of the hashtable used to store object and class references during writing.
Definition: TBufferIO.cxx:117