Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TBufferSQL2.h
Go to the documentation of this file.
1// @(#)root/sql
2// Author: Sergey Linev 20/11/2005
3
4#ifndef ROOT_TBufferSQL2
5#define ROOT_TBufferSQL2
6
7#include "TBufferText.h"
8#include "TString.h"
9#include <string>
10
11class TMap;
12class TExMap;
15class TObjArray;
16class TMemberStreamer;
17
18class TSQLStackObj;
19class TSQLServer;
20class TSQLResult;
21class TSQLRow;
22class TSQLFile;
23class TSQLStructure;
24class TSQLObjectData;
25class TSQLClassInfo;
26
27class TBufferSQL2 final : public TBufferText {
28
29 friend class TSQLStructure;
30
31protected:
32 TSQLFile *fSQL; ///<! instance of TSQLFile
33 Int_t fIOVersion; ///<! I/O version from TSQLFile
34 TSQLStructure *fStructure; ///<! structures, created by object storing
35 TSQLStructure *fStk; ///<! pointer on current active structure (stack head)
36 TString fReadBuffer; ///<! Buffer for read value
37 Int_t fErrorFlag; ///<! Error id value
38 Int_t fCompressLevel; ///<! compress level used to minimize size of data in database
39 Int_t fReadVersionBuffer; ///<! buffer, used to by ReadVersion method
40 Long64_t fObjIdCounter; ///<! counter of objects id
41 Bool_t fIgnoreVerification; ///<! ignore verification of names
43 TObjArray *fObjectsInfos; ///<! array of objects info for selected key
44 Long64_t fFirstObjId; ///<! id of first object to be read from the database
45 Long64_t fLastObjId; ///<! id of last object correspond to this key
46 TMap *fPoolsMap; ///<! map of pools with data from different tables
47
48 // TBufferSQL2 objects cannot be copied or assigned
49 TBufferSQL2(const TBufferSQL2 &); // not implemented
50 void operator=(const TBufferSQL2 &); // not implemented
51
53
54 // redefined protected virtual functions
55
56 void WriteObjectClass(const void *actualObjStart, const TClass *actualClass, Bool_t cacheReuse) final;
57
58 // end redefined protected virtual functions
59
62 TSQLStructure *Stack(Int_t depth = 0);
63
64 void WorkWithClass(const char *classname, Version_t classversion);
65 void WorkWithElement(TStreamerElement *elem, Int_t comp_type);
66
68 Bool_t SqlObjectInfo(Long64_t objid, TString &clname, Version_t &version);
70
84 Bool_t SqlWriteValue(const char *value, const char *tname);
85
86 void SqlReadBasic(Char_t &value);
87 void SqlReadBasic(Short_t &value);
88 void SqlReadBasic(Int_t &value);
89 void SqlReadBasic(Long_t &value);
90 void SqlReadBasic(Long64_t &value);
91 void SqlReadBasic(Float_t &value);
92 void SqlReadBasic(Double_t &value);
93 void SqlReadBasic(Bool_t &value);
94 void SqlReadBasic(UChar_t &value);
95 void SqlReadBasic(UShort_t &value);
96 void SqlReadBasic(UInt_t &value);
97 void SqlReadBasic(ULong_t &value);
98 void SqlReadBasic(ULong64_t &value);
99 const char *SqlReadValue(const char *tname);
100 const char *SqlReadCharStarValue();
101
102 Int_t SqlWriteObject(const void *obj, const TClass *objClass, Bool_t cacheReuse, TMemberStreamer *streamer = nullptr,
103 Int_t streamer_index = 0);
104 void *SqlReadObject(void *obj, TClass **cl = nullptr, TMemberStreamer *streamer = nullptr, Int_t streamer_index = 0,
105 const TClass *onFileClass = nullptr);
106 void *SqlReadObjectDirect(void *obj, TClass **cl, Long64_t objid, TMemberStreamer *streamer = nullptr,
107 Int_t streamer_index = 0, const TClass *onFileClass = nullptr);
108
109 void StreamObjectExtra(void *obj, TMemberStreamer *streamer, const TClass *cl, Int_t n = 0,
110 const TClass *onFileClass = nullptr);
111
112 template <typename T>
113 R__ALWAYS_INLINE void SqlReadArrayContent(T *arr, Int_t arrsize, Bool_t withsize);
114
115 template <typename T>
116 R__ALWAYS_INLINE Int_t SqlReadArray(T *&arr, Bool_t is_static = kFALSE);
117
118 template <typename T>
119 R__ALWAYS_INLINE void SqlReadFastArray(T *arr, Int_t arrsize);
120
121 template <typename T>
122 R__ALWAYS_INLINE void SqlWriteArray(T *arr, Int_t arrsize, Bool_t withsize = kFALSE);
123
124public:
125 TBufferSQL2(TBuffer::EMode mode, TSQLFile *file = nullptr);
126 virtual ~TBufferSQL2();
127
128 void SetCompressionLevel(int level) { fCompressLevel = level; }
129
131
132 Int_t GetErrorFlag() const { return fErrorFlag; }
133
135
136 TSQLStructure *SqlWriteAny(const void *obj, const TClass *cl, Long64_t objid);
137
138 void *SqlReadAny(Long64_t keyid, Long64_t objid, TClass **cl, void *obj = nullptr);
139
140 // suppress class writing/reading
141
142 TClass *ReadClass(const TClass *cl = nullptr, UInt_t *objTag = nullptr) final;
143 void WriteClass(const TClass *cl) final;
144
145 // redefined virtual functions of TBuffer
146
147 Version_t ReadVersion(UInt_t *start = nullptr, UInt_t *bcnt = nullptr, const TClass *cl = nullptr) final;
148 UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt = kFALSE) final;
149
150 void *ReadObjectAny(const TClass *clCast) final;
151 void SkipObjectAny() final;
152
154 void SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type) final;
156
157 void ClassBegin(const TClass *, Version_t = -1) final;
158 void ClassEnd(const TClass *) final;
159 void ClassMember(const char *name, const char *typeName = 0, Int_t arrsize1 = -1, Int_t arrsize2 = -1) final;
160
161 Int_t ReadArray(Bool_t *&b) final;
162 Int_t ReadArray(Char_t *&c) final;
163 Int_t ReadArray(UChar_t *&c) final;
164 Int_t ReadArray(Short_t *&h) final;
165 Int_t ReadArray(UShort_t *&h) final;
166 Int_t ReadArray(Int_t *&i) final;
167 Int_t ReadArray(UInt_t *&i) final;
168 Int_t ReadArray(Long_t *&l) final;
169 Int_t ReadArray(ULong_t *&l) final;
170 Int_t ReadArray(Long64_t *&l) final;
171 Int_t ReadArray(ULong64_t *&l) final;
172 Int_t ReadArray(Float_t *&f) final;
173 Int_t ReadArray(Double_t *&d) final;
174
180 Int_t ReadStaticArray(Int_t *i) final;
181 Int_t ReadStaticArray(UInt_t *i) final;
188
189 void ReadFastArray(Bool_t *b, Int_t n) final;
190 void ReadFastArray(Char_t *c, Int_t n) final;
191 void ReadFastArray(UChar_t *c, Int_t n) final;
192 void ReadFastArray(Short_t *h, Int_t n) final;
193 void ReadFastArray(UShort_t *h, Int_t n) final;
194 void ReadFastArray(Int_t *i, Int_t n) final;
195 void ReadFastArray(UInt_t *i, Int_t n) final;
196 void ReadFastArray(Long_t *l, Int_t n) final;
197 void ReadFastArray(ULong_t *l, Int_t n) final;
198 void ReadFastArray(Long64_t *l, Int_t n) final;
199 void ReadFastArray(ULong64_t *l, Int_t n) final;
200 void ReadFastArray(Float_t *f, Int_t n) final;
201 void ReadFastArray(Double_t *d, Int_t n) final;
202 void ReadFastArrayString(Char_t *c, Int_t n) final;
203 void ReadFastArray(void *start, const TClass *cl, Int_t n = 1, TMemberStreamer *s = nullptr,
204 const TClass *onFileClass = nullptr) final;
205 void ReadFastArray(void **startp, const TClass *cl, Int_t n = 1, Bool_t isPreAlloc = kFALSE,
206 TMemberStreamer *s = nullptr, const TClass *onFileClass = nullptr) final;
207
208 void WriteArray(const Bool_t *b, Int_t n) final;
209 void WriteArray(const Char_t *c, Int_t n) final;
210 void WriteArray(const UChar_t *c, Int_t n) final;
211 void WriteArray(const Short_t *h, Int_t n) final;
212 void WriteArray(const UShort_t *h, Int_t n) final;
213 void WriteArray(const Int_t *i, Int_t n) final;
214 void WriteArray(const UInt_t *i, Int_t n) final;
215 void WriteArray(const Long_t *l, Int_t n) final;
216 void WriteArray(const ULong_t *l, Int_t n) final;
217 void WriteArray(const Long64_t *l, Int_t n) final;
218 void WriteArray(const ULong64_t *l, Int_t n) final;
219 void WriteArray(const Float_t *f, Int_t n) final;
220 void WriteArray(const Double_t *d, Int_t n) final;
221
222 void WriteFastArray(const Bool_t *b, Int_t n) final;
223 void WriteFastArray(const Char_t *c, Int_t n) final;
224 void WriteFastArray(const UChar_t *c, Int_t n) final;
225 void WriteFastArray(const Short_t *h, Int_t n) final;
226 void WriteFastArray(const UShort_t *h, Int_t n) final;
227 void WriteFastArray(const Int_t *i, Int_t n) final;
228 void WriteFastArray(const UInt_t *i, Int_t n) final;
229 void WriteFastArray(const Long_t *l, Int_t n) final;
230 void WriteFastArray(const ULong_t *l, Int_t n) final;
231 void WriteFastArray(const Long64_t *l, Int_t n) final;
232 void WriteFastArray(const ULong64_t *l, Int_t n) final;
233 void WriteFastArray(const Float_t *f, Int_t n) final;
234 void WriteFastArray(const Double_t *d, Int_t n) final;
235 void WriteFastArrayString(const Char_t *c, Int_t n) final;
236 void WriteFastArray(void *start, const TClass *cl, Int_t n = 1, TMemberStreamer *s = nullptr) final;
237 Int_t WriteFastArray(void **startp, const TClass *cl, Int_t n = 1, Bool_t isPreAlloc = kFALSE,
238 TMemberStreamer *s = nullptr) final;
239
240 void StreamObject(void *obj, const TClass *cl, const TClass *onFileClass = nullptr) final;
242
243 void ReadBool(Bool_t &b) final;
244 void ReadChar(Char_t &c) final;
245 void ReadUChar(UChar_t &c) final;
246 void ReadShort(Short_t &s) final;
247 void ReadUShort(UShort_t &s) final;
248 void ReadInt(Int_t &i) final;
249 void ReadUInt(UInt_t &i) final;
250 void ReadLong(Long_t &l) final;
251 void ReadULong(ULong_t &l) final;
252 void ReadLong64(Long64_t &l) final;
253 void ReadULong64(ULong64_t &l) final;
254 void ReadFloat(Float_t &f) final;
255 void ReadDouble(Double_t &d) final;
256 void ReadCharP(Char_t *c) final;
257 void ReadTString(TString &s) final;
258 void ReadStdString(std::string *s) final;
259 using TBuffer::ReadStdString;
260 void ReadCharStar(char *&s) final;
261
262 void WriteBool(Bool_t b) final;
263 void WriteChar(Char_t c) final;
264 void WriteUChar(UChar_t c) final;
265 void WriteShort(Short_t s) final;
266 void WriteUShort(UShort_t s) final;
267 void WriteInt(Int_t i) final;
268 void WriteUInt(UInt_t i) final;
269 void WriteLong(Long_t l) final;
270 void WriteULong(ULong_t l) final;
271 void WriteLong64(Long64_t l) final;
272 void WriteULong64(ULong64_t l) final;
273 void WriteFloat(Float_t f) final;
274 void WriteDouble(Double_t d) final;
275 void WriteCharP(const Char_t *c) final;
276 void WriteTString(const TString &s) final;
277 void WriteStdString(const std::string *s) final;
278 using TBuffer::WriteStdString;
279 void WriteCharStar(char *s) final;
280
282
283 // end of redefined virtual functions
284
285 ClassDefOverride(TBufferSQL2, 0); // a specialized TBuffer to convert data to SQL statements or read data from SQL tables
286};
287
288#endif
#define R__ALWAYS_INLINE
Definition RConfig.hxx:564
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
unsigned short UShort_t
Definition RtypesCore.h:40
int Int_t
Definition RtypesCore.h:45
short Version_t
Definition RtypesCore.h:65
unsigned char UChar_t
Definition RtypesCore.h:38
char Char_t
Definition RtypesCore.h:37
unsigned int UInt_t
Definition RtypesCore.h:46
const Bool_t kFALSE
Definition RtypesCore.h:101
unsigned long ULong_t
Definition RtypesCore.h:55
long Long_t
Definition RtypesCore.h:54
bool Bool_t
Definition RtypesCore.h:63
short Short_t
Definition RtypesCore.h:39
double Double_t
Definition RtypesCore.h:59
long long Long64_t
Definition RtypesCore.h:80
unsigned long long ULong64_t
Definition RtypesCore.h:81
float Float_t
Definition RtypesCore.h:57
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassDefOverride(name, id)
Definition Rtypes.h:329
char name[80]
Definition TGX11.cxx:110
Converts data to SQL statements or read data from SQL tables.
Definition TBufferSQL2.h:27
Long64_t fObjIdCounter
! counter of objects id
Definition TBufferSQL2.h:40
void SetStreamerElementNumber(TStreamerElement *elem, Int_t comp_type) final
Function is called from TStreamerInfo WriteBuffer and Readbuffer functions and add/verify next elemen...
TSQLStructure * PopStack()
Pop stack.
Bool_t SqlObjectInfo(Long64_t objid, TString &clname, Version_t &version)
Returns object info like classname and version Should be taken from buffer, which is produced in the ...
void ClassBegin(const TClass *, Version_t=-1) final
This method inform buffer data of which class now will be streamed.
void StreamObjectExtra(void *obj, TMemberStreamer *streamer, const TClass *cl, Int_t n=0, const TClass *onFileClass=nullptr)
Stream object to/from buffer.
R__ALWAYS_INLINE void SqlWriteArray(T *arr, Int_t arrsize, Bool_t withsize=kFALSE)
void ReadUShort(UShort_t &s) final
Reads UShort_t value from buffer.
Long64_t fFirstObjId
! id of first object to be read from the database
Definition TBufferSQL2.h:44
Bool_t SqlWriteBasic(Char_t value)
converts Char_t to string and creates correspondent sql structure
TSQLObjectData * fCurrentData
!
Definition TBufferSQL2.h:42
Int_t fErrorFlag
! Error id value
Definition TBufferSQL2.h:37
void WriteShort(Short_t s) final
Writes Short_t value to buffer.
void DecrementLevel(TVirtualStreamerInfo *) final
Function is called from TStreamerInfo WriteBuffer and Readbuffer functions and decrease level in sql ...
void WriteULong64(ULong64_t l) final
Writes ULong64_t value to buffer.
void WriteChar(Char_t c) final
Writes Char_t value to buffer.
void WriteCharStar(char *s) final
Write a char* string.
virtual ~TBufferSQL2()
Destroy sql buffer.
void WriteCharP(const Char_t *c) final
Writes array of characters to buffer.
Long64_t fLastObjId
! id of last object correspond to this key
Definition TBufferSQL2.h:45
void WriteInt(Int_t i) final
Writes Int_t value to buffer.
TSQLStructure * PushStack()
Push stack with structural information about streamed object.
void * ReadObjectAny(const TClass *clCast) final
Read object from buffer. Only used from TBuffer.
void ReadLong64(Long64_t &l) final
Reads Long64_t value from buffer.
void WriteULong(ULong_t l) final
Writes ULong_t value to buffer.
void WriteUInt(UInt_t i) final
Writes UInt_t value to buffer.
void ReadLong(Long_t &l) final
Reads Long_t value from buffer.
void WriteLong(Long_t l) final
Writes Long_t value to buffer.
Int_t fIOVersion
! I/O version from TSQLFile
Definition TBufferSQL2.h:33
void WriteUShort(UShort_t s) final
Writes UShort_t value to buffer.
TSQLFile * fSQL
! instance of TSQLFile
Definition TBufferSQL2.h:32
void SetIgnoreVerification()
Int_t ReadStaticArray(Bool_t *b) final
Read array of Bool_t from buffer.
void WriteStdString(const std::string *s) final
Write a std::string.
void operator=(const TBufferSQL2 &)
Int_t fReadVersionBuffer
! buffer, used to by ReadVersion method
Definition TBufferSQL2.h:39
void ReadFastArray(Bool_t *b, Int_t n) final
Read array of Bool_t from buffer.
void StreamObject(void *obj, const TClass *cl, const TClass *onFileClass=nullptr) final
Stream object to/from buffer.
Bool_t fIgnoreVerification
! ignore verification of names
Definition TBufferSQL2.h:41
void ReadUChar(UChar_t &c) final
Reads UChar_t value from buffer.
void ReadShort(Short_t &s) final
Reads Short_t value from buffer.
void ReadBool(Bool_t &b) final
Reads Bool_t value from buffer.
TSQLStructure * GetStructure() const
R__ALWAYS_INLINE Int_t SqlReadArray(T *&arr, Bool_t is_static=kFALSE)
void ReadTString(TString &s) final
Read a TString.
TBufferSQL2()
Default constructor, should not be used.
R__ALWAYS_INLINE void SqlReadFastArray(T *arr, Int_t arrsize)
Template method to read content of array, which not include size of array.
void ReadFastArrayString(Char_t *c, Int_t n) final
Read array of n characters from the I/O buffer.
TVirtualStreamerInfo * GetInfo() final
Return current streamer info element.
void WriteFastArrayString(const Char_t *c, Int_t n) final
Write array of n characters into the I/O buffer.
TSQLStructure * fStructure
! structures, created by object storing
Definition TBufferSQL2.h:34
TBufferSQL2(const TBufferSQL2 &)
void WriteBool(Bool_t b) final
Writes Bool_t value to buffer.
TClass * ReadClass(const TClass *cl=nullptr, UInt_t *objTag=nullptr) final
Suppressed function of TBuffer.
UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE) final
Copies class version to buffer, but not writes it to sql immidiately Version will be used to produce ...
void ReadCharP(Char_t *c) final
Reads array of characters from buffer.
TMap * fPoolsMap
! map of pools with data from different tables
Definition TBufferSQL2.h:46
TSQLStructure * Stack(Int_t depth=0)
returns head of stack
void ClassEnd(const TClass *) final
Method indicates end of streaming of classdata in custom streamer.
void ReadFloat(Float_t &f) final
Reads Float_t value from buffer.
void SetCompressionLevel(int level)
const char * SqlReadValue(const char *tname)
Read string value from current stack node.
TString fReadBuffer
! Buffer for read value
Definition TBufferSQL2.h:36
TSQLStructure * fStk
! pointer on current active structure (stack head)
Definition TBufferSQL2.h:35
void ReadUInt(UInt_t &i) final
Reads UInt_t value from buffer.
const char * SqlReadCharStarValue()
Read CharStar value, if it has special code, request it from large table.
void WriteClass(const TClass *cl) final
Suppressed function of TBuffer.
Int_t GetErrorFlag() const
Int_t SqlReadArraySize()
Reads array size, written in raw data table.
void * SqlReadObject(void *obj, TClass **cl=nullptr, TMemberStreamer *streamer=nullptr, Int_t streamer_index=0, const TClass *onFileClass=nullptr)
Read object from the buffer.
void WorkWithClass(const char *classname, Version_t classversion)
This function is a part of IncrementLevel method.
void IncrementLevel(TVirtualStreamerInfo *) final
Function is called from TStreamerInfo WriteBuffer and Readbuffer functions and indent new level in da...
Int_t ReadArray(Bool_t *&b) final
Read array of Bool_t from buffer.
void ReadChar(Char_t &c) final
Reads Char_t value from buffer.
Int_t SqlWriteObject(const void *obj, const TClass *objClass, Bool_t cacheReuse, TMemberStreamer *streamer=nullptr, Int_t streamer_index=0)
Write object to buffer.
void WriteArray(const Bool_t *b, Int_t n) final
Write array of Bool_t to buffer.
void ReadStdString(std::string *s) final
Read a std::string.
void ReadDouble(Double_t &d) final
Reads Double_t value from buffer.
void ReadCharStar(char *&s) final
Read a char* string.
void ReadInt(Int_t &i) final
Reads Int_t value from buffer.
void SkipObjectAny() final
?????? Skip any kind of object from buffer !!!!!! fix me, not yet implemented Should be just skip of ...
Bool_t SqlWriteValue(const char *value, const char *tname)
void WriteTString(const TString &s) final
Write a TString.
void * SqlReadObjectDirect(void *obj, TClass **cl, Long64_t objid, TMemberStreamer *streamer=nullptr, Int_t streamer_index=0, const TClass *onFileClass=nullptr)
Read object data.
void WriteFloat(Float_t f) final
Writes Float_t value to buffer.
void WorkWithElement(TStreamerElement *elem, Int_t comp_type)
This function is a part of SetStreamerElementNumber method.
void WriteFastArray(const Bool_t *b, Int_t n) final
Write array of Bool_t to buffer.
void WriteObjectClass(const void *actualObjStart, const TClass *actualClass, Bool_t cacheReuse) final
Write object to buffer. Only used from TBuffer.
TSQLObjectData * SqlObjectData(Long64_t objid, TSQLClassInfo *sqlinfo)
Creates TSQLObjectData for specified object id and specified class.
TSQLStructure * SqlWriteAny(const void *obj, const TClass *cl, Long64_t objid)
Convert object of any class to sql structures Return pointer on created TSQLStructure TSQLStructure o...
void WriteDouble(Double_t d) final
Writes Double_t value to buffer.
void ReadULong64(ULong64_t &l) final
Reads ULong64_t value from buffer.
void WriteUChar(UChar_t c) final
Writes UChar_t value to buffer.
void * SqlReadAny(Long64_t keyid, Long64_t objid, TClass **cl, void *obj=nullptr)
Recreate object from sql structure.
Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr) final
Read version value from buffer actually version is normally defined by table name and kept in interme...
TObjArray * fObjectsInfos
! array of objects info for selected key
Definition TBufferSQL2.h:43
R__ALWAYS_INLINE void SqlReadArrayContent(T *arr, Int_t arrsize, Bool_t withsize)
Template method to read array content.
void WriteLong64(Long64_t l) final
Writes Long64_t value to buffer.
void SqlReadBasic(Char_t &value)
Read current value from table and convert it to Char_t value.
void ClassMember(const char *name, const char *typeName=0, Int_t arrsize1=-1, Int_t arrsize2=-1) final
Method indicates name and typename of class memeber, which should be now streamed in custom streamer ...
Int_t fCompressLevel
! compress level used to minimize size of data in database
Definition TBufferSQL2.h:38
void ReadULong(ULong_t &l) final
Reads ULong_t value from buffer.
Base class for text-based streamers like TBufferJSON or TBufferXML Special actions list will use meth...
Definition TBufferText.h:20
Buffer base class used for serializing objects.
Definition TBuffer.h:43
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
This class stores a (key,value) pair using an external hash.
Definition TExMap.h:33
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition TMap.h:40
An array of TObjects.
Definition TObjArray.h:31
Contains information about tables specific to one class and version.
Access an SQL db via the TFile interface.
Definition TSQLFile.h:30
TSQLObjectData is used in TBufferSQL2 class in reading procedure.
This is hierarchical structure, which is created when data is written by TBufferSQL2.
Basic string class.
Definition TString.h:136
Abstract Interface class describing Streamer information for one class.
const Int_t n
Definition legend1.C:16
Definition file.py:1
auto * l
Definition textangle.C:4