Logo ROOT   6.14/05
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() = default;
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  virtual Int_t GetVersionOwner() const;
77 
78  // See comment in TBuffer::SetPidOffset
79  virtual UShort_t GetPidOffset() const { return fPidOffset; }
80  virtual void SetPidOffset(UShort_t offset);
81  virtual Int_t GetBufferDisplacement() const { return fDisplacement; }
82  virtual void SetBufferDisplacement() { fDisplacement = 0; }
83  virtual void SetBufferDisplacement(Int_t skipped) { fDisplacement = (Int_t)(Length() - skipped); }
84 
85  // Utilities for objects map
86  virtual void SetReadParam(Int_t mapsize);
87  virtual void SetWriteParam(Int_t mapsize);
88  virtual void InitMap();
89  virtual void ResetMap();
90  virtual void Reset();
91  virtual Int_t GetMapCount() const { return fMapCount; }
92  virtual void MapObject(const TObject *obj, UInt_t offset = 1);
93  virtual void MapObject(const void *obj, const TClass *cl, UInt_t offset = 1);
94  virtual Bool_t CheckObject(const TObject *obj);
95  virtual Bool_t CheckObject(const void *obj, const TClass *ptrClass);
96  virtual void GetMappedObject(UInt_t tag, void *&ptr, TClass *&ClassPtr) const;
97 
98  // Utilities for TStreamerInfo
99  virtual void ForceWriteInfo(TVirtualStreamerInfo *info, Bool_t force);
100  virtual void ForceWriteInfoClones(TClonesArray *a);
101  virtual Int_t ReadClones(TClonesArray *a, Int_t nobjects, Version_t objvers);
102  virtual Int_t WriteClones(TClonesArray *a, Int_t nobjects);
103  virtual void TagStreamerInfo(TVirtualStreamerInfo *info);
104 
105  // Special basic ROOT objects and collections
106  virtual TProcessID *GetLastProcessID(TRefTable *reftable) const;
107  virtual UInt_t GetTRefExecId();
108  virtual TProcessID *ReadProcessID(UShort_t pidf);
109  virtual UShort_t WriteProcessID(TProcessID *pid);
110 
111  virtual Int_t WriteObjectAny(const void *obj, const TClass *ptrClass, Bool_t cacheReuse = kTRUE);
112  virtual void WriteObject(const TObject *obj, Bool_t cacheReuse = kTRUE);
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  ClassDef(TBufferIO, 0) // base class, share methods for TBufferFile and TBufferText
121 };
122 
123 #endif
virtual Int_t GetBufferDisplacement() const
Definition: TBufferIO.h:81
virtual void WriteObjectClass(const void *actualObjStart, const TClass *actualClass, Bool_t cacheReuse)=0
virtual void ResetMap()
Delete existing fMap and reset map counter.
Definition: TBufferIO.cxx:288
Int_t fMapSize
Default size of map.
Definition: TBufferIO.h:36
long long Long64_t
Definition: RtypesCore.h:69
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
#define R__ALWAYS_INLINE
Definition: RConfig.h:556
short Version_t
Definition: RtypesCore.h:61
unsigned short UShort_t
Definition: RtypesCore.h:36
#define BIT(n)
Definition: Rtypes.h:78
virtual void SetPidOffset(UShort_t offset)
This offset is used when a key (or basket) is transfered from one file to the other.
Definition: TBufferIO.cxx:319
char *(* ReAllocCharFun_t)(char *, size_t, size_t)
Definition: TStorage.h:30
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
static Int_t fgMapSize
Default map size for all TBuffer objects.
Definition: TBufferIO.h:42
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Int_t WriteClones(TClonesArray *a, Int_t nobjects)
Interface to TStreamerInfo::WriteBufferClones.
Definition: TBufferIO.cxx:385
virtual void InitMap()
Create the fMap container and initialize them with the null object.
Definition: TBufferIO.cxx:129
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
Definition: TString.cxx:626
TBufferIO()=default
virtual void CheckCount(UInt_t)
Definition: TBufferIO.h:56
Int_t Length() const
Definition: TBuffer.h:96
Int_t fMapCount
Number of objects or classes in map.
Definition: TBufferIO.h:35
#define ClassDef(name, id)
Definition: Rtypes.h:320
virtual TProcessID * GetLastProcessID(TRefTable *reftable) const
Return the last TProcessID in the file.
Definition: TBufferIO.cxx:399
virtual ~TBufferIO()
destructor
Definition: TBufferIO.cxx:68
static Int_t GetGlobalWriteParam()
Get default write map size.
Definition: TBufferIO.cxx:580
Int_t fDisplacement
Value to be added to the map offsets.
Definition: TBufferIO.h:37
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition: TProcessID.h:69
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
UShort_t fPidOffset
Offset to be added to the pid index in this key/buffer.
Definition: TBufferIO.h:38
virtual void ForceWriteInfoClones(TClonesArray *a)
Make sure TStreamerInfo is not optimized, otherwise it will not be possible to support schema evoluti...
Definition: TBufferIO.cxx:341
virtual TProcessID * ReadProcessID(UShort_t pidf)
The TProcessID with number pidf is read from file.
Definition: TBufferIO.cxx:422
virtual UShort_t GetPidOffset() const
Definition: TBufferIO.h:79
virtual void MapObject(const TObject *obj, UInt_t offset=1)
Add object to the fMap container.
Definition: TBufferIO.cxx:163
auto * a
Definition: textangle.C:12
virtual Int_t WriteObjectAny(const void *obj, const TClass *ptrClass, Bool_t cacheReuse=kTRUE)
Write object to I/O buffer.
Definition: TBufferIO.cxx:492
EStatusBits
Definition: TBuffer.h:71
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void SetBufferDisplacement(Int_t skipped)
Definition: TBufferIO.h:83
TExMap * fClassMap
Map containing object,class pairs for reading.
Definition: TBufferIO.h:40
virtual void GetMappedObject(UInt_t tag, void *&ptr, TClass *&ClassPtr) const
Retrieve the object stored in the buffer&#39;s object map at &#39;tag&#39; Set ptr and ClassPtr respectively to t...
Definition: TBufferIO.cxx:260
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
virtual Int_t GetMapCount() const
Definition: TBufferIO.h:91
virtual void WriteObject(const TObject *obj, Bool_t cacheReuse=kTRUE)
Write object to I/O buffer.
Definition: TBufferIO.cxx:530
virtual Bool_t CheckObject(const TObject *obj)
Check if the specified object is already in the buffer.
Definition: TBufferIO.cxx:225
virtual void Reset()
Reset buffer object. Resets map and buffer offset.
Definition: TBufferIO.cxx:305
virtual void WriteObject(const TObject *obj, Bool_t cacheReuse)=0
virtual void SetBufferDisplacement()
Definition: TBufferIO.h:82
unsigned long ULong_t
Definition: RtypesCore.h:51
A TRefTable maintains the association between a referenced object and the parent object supporting th...
Definition: TRefTable.h:35
virtual Int_t ReadClones(TClonesArray *a, Int_t nobjects, Version_t objvers)
Interface to TStreamerInfo::ReadBufferClones.
Definition: TBufferIO.cxx:372
TExMap * fMap
Map containing object,offset pairs for reading/writing.
Definition: TBufferIO.h:39
virtual UInt_t GetTRefExecId()
Return the exec id stored in the current TStreamerInfo element.
Definition: TBufferIO.cxx:447
Mother of all ROOT objects.
Definition: TObject.h:37
virtual Int_t GetVersionOwner() const
Return the version number of the owner file.
Definition: TBufferIO.cxx:77
An array of clone (identical) objects.
Definition: TClonesArray.h:32
Direct subclass of TBuffer, implements common methods for TBufferFile and TBufferText classes...
Definition: TBufferIO.h:30
static R__ALWAYS_INLINE ULong_t Void_Hash(const void *ptr)
Return hash value for provided object.
Definition: TBufferIO.h:53
virtual UShort_t WriteProcessID(TProcessID *pid)
Check if the ProcessID pid is already in the file.
Definition: TBufferIO.cxx:456
virtual void TagStreamerInfo(TVirtualStreamerInfo *info)
Mark the classindex of the current file as using this TStreamerInfo.
Definition: TBufferIO.cxx:350
virtual void SetReadParam(Int_t mapsize)
Set the initial size of the map used to store object and class references during reading.
Definition: TBufferIO.cxx:97
virtual void ForceWriteInfo(TVirtualStreamerInfo *info, Bool_t force)
force writing the TStreamerInfo to the file
Definition: TBufferIO.cxx:329
Abstract Interface class describing Streamer information for one class.
virtual void SetWriteParam(Int_t mapsize)
Set the initial size of the hashtable used to store object and class references during writing...
Definition: TBufferIO.cxx:117
static Int_t GetGlobalReadParam()
Get default read map size.
Definition: TBufferIO.cxx:572
const Bool_t kTRUE
Definition: RtypesCore.h:87
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
This class stores a (key,value) pair using an external hash.
Definition: TExMap.h:33