Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TBufferSQL2.cxx
Go to the documentation of this file.
1// @(#)root/sql:$Id$
2// Author: Sergey Linev 20/11/2005
3
4/*************************************************************************
5 * Copyright (C) 1995-2005, 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/**
13\class TBufferSQL2
14\ingroup IO
15
16Converts data to SQL statements or read data from SQL tables.
17
18Class for serializing/deserializing object to/from SQL data base.
19It redefines most of TBuffer class function to convert simple types,
20array of simple types and objects to/from TSQLStructure objects.
21TBufferSQL2 class uses streaming mechanism, provided by ROOT system,
22therefore most of ROOT and user classes can be stored. There are
23limitations for complex objects like TTree, TClonesArray, TDirectory and
24few other, which can not be converted to SQL (yet).
25*/
26
27#include "TBufferSQL2.h"
28
29#include "TROOT.h"
30#include "TDataType.h"
31#include "TClass.h"
32#include "TClassTable.h"
33#include "TMap.h"
34#include "TStreamerInfo.h"
35#include "TStreamerElement.h"
36#include "TMemberStreamer.h"
37#include "TStreamer.h"
39#include "snprintf.h"
40
41#include <iostream>
42#include <cstdlib>
43#include <string>
44
45#include "TSQLServer.h"
46#include "TSQLResult.h"
47#include "TSQLRow.h"
48#include "TSQLStructure.h"
49#include "TSQLObjectData.h"
50#include "TSQLFile.h"
51#include "TSQLClassInfo.h"
52
54
55////////////////////////////////////////////////////////////////////////////////
56/// Default constructor, should not be used
57
59 : TBufferText(), fSQL(nullptr), fIOVersion(1), fStructure(nullptr), fStk(nullptr), fReadBuffer(), fErrorFlag(0),
60 fCompressLevel(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal), fReadVersionBuffer(-1), fObjIdCounter(1), fIgnoreVerification(kFALSE),
61 fCurrentData(nullptr), fObjectsInfos(nullptr), fFirstObjId(0), fLastObjId(0), fPoolsMap(nullptr)
62{
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// Creates buffer object to serialize/deserialize data to/from sql.
67/// This constructor should be used, if data from buffer supposed to be stored in file.
68/// Mode should be either TBuffer::kRead or TBuffer::kWrite.
69
71 : TBufferText(mode, file), fSQL(nullptr), fIOVersion(1), fStructure(nullptr), fStk(nullptr), fReadBuffer(), fErrorFlag(0),
72 fCompressLevel(ROOT::RCompressionSetting::EAlgorithm::kUseGlobal), fReadVersionBuffer(-1), fObjIdCounter(1), fIgnoreVerification(kFALSE),
73 fCurrentData(nullptr), fObjectsInfos(nullptr), fFirstObjId(0), fLastObjId(0), fPoolsMap(nullptr)
74{
75 fSQL = file;
76 if (file) {
78 fIOVersion = file->GetIOVersion();
79 }
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Destroy sql buffer.
84
86{
87 if (fStructure)
88 delete fStructure;
89
90 if (fObjectsInfos) {
92 delete fObjectsInfos;
93 }
94
95 if (fPoolsMap) {
97 delete fPoolsMap;
98 }
99}
100
101////////////////////////////////////////////////////////////////////////////////
102/// Convert object of any class to sql structures
103/// Return pointer on created TSQLStructure
104/// TSQLStructure object will be owned by TBufferSQL2
105
106TSQLStructure *TBufferSQL2::SqlWriteAny(const void *obj, const TClass *cl, Long64_t objid)
107{
108 fErrorFlag = 0;
109
110 fStructure = nullptr;
111
112 fFirstObjId = objid;
113 fObjIdCounter = objid;
114
115 SqlWriteObject(obj, cl, kTRUE);
116
117 if (gDebug > 3)
118 if (fStructure) {
119 std::cout << "==== Printout of Sql structures ===== " << std::endl;
120 fStructure->Print("*");
121 std::cout << "=========== End printout ============ " << std::endl;
122 }
123
124 return fStructure;
125}
126
127////////////////////////////////////////////////////////////////////////////////
128/// Recreate object from sql structure.
129/// Return pointer to read object.
130/// if (cl!=0) returns pointer to class of object
131
132void *TBufferSQL2::SqlReadAny(Long64_t keyid, Long64_t objid, TClass **cl, void *obj)
133{
134 if (cl)
135 *cl = nullptr;
136 if (!fSQL)
137 return nullptr;
138
139 fCurrentData = nullptr;
140 fErrorFlag = 0;
141
143
145 fFirstObjId = objid;
146 fLastObjId = objid;
147 if (fObjectsInfos) {
149 if (objinfo)
150 fLastObjId = objinfo->GetObjId();
151 }
152
153 return SqlReadObjectDirect(obj, cl, objid);
154}
155
156////////////////////////////////////////////////////////////////////////////////
157/// Returns object info like classname and version
158/// Should be taken from buffer, which is produced in the beginning
159
161{
162 if ((objid < 0) || !fObjectsInfos)
163 return kFALSE;
164
165 // suppose that objects info are sorted out
166
167 Long64_t shift = objid - fFirstObjId;
168
169 TSQLObjectInfo *info = nullptr;
170 if ((shift >= 0) && (shift <= fObjectsInfos->GetLast())) {
171 info = (TSQLObjectInfo *)fObjectsInfos->At(shift);
172 if (info->GetObjId() != objid)
173 info = nullptr;
174 }
175
176 if (!info) {
177 // I hope, i will never get inside it
178 Info("SqlObjectInfo", "Standard not works %lld", objid);
179 for (Int_t n = 0; n <= fObjectsInfos->GetLast(); n++) {
180 info = (TSQLObjectInfo *)fObjectsInfos->At(n);
181 if (info->GetObjId() == objid)
182 break;
183 info = nullptr;
184 }
185 }
186
187 if (!info)
188 return kFALSE;
189
190 clname = info->GetObjClassName();
191 version = info->GetObjVersion();
192 return kTRUE;
193}
194
195////////////////////////////////////////////////////////////////////////////////
196/// Creates TSQLObjectData for specified object id and specified class
197///
198/// Object data for each class can be stored in two different tables.
199/// First table contains data in column-wise form for simple types like integer,
200/// strings and so on when second table contains any other data which cannot
201/// be converted into column-wise representation.
202/// TSQLObjectData will contain results of the requests to both such tables for
203/// concrete object id.
204
206{
207 TSQLResult *classdata = nullptr;
208 TSQLRow *classrow = nullptr;
209
210 if (sqlinfo->IsClassTableExist()) {
211
212 TSQLObjectDataPool *pool = nullptr;
213
214 if (fPoolsMap)
215 pool = (TSQLObjectDataPool *)fPoolsMap->GetValue(sqlinfo);
216
217 if (pool && (fLastObjId >= fFirstObjId)) {
218 if (gDebug > 4)
219 Info("SqlObjectData", "Before request to %s", sqlinfo->GetClassTableName());
221 if (gDebug > 4)
222 Info("SqlObjectData", "After request res = 0x%zx", (size_t)alldata);
223 if (!alldata) {
224 Error("SqlObjectData", "Cannot get data from table %s", sqlinfo->GetClassTableName());
225 return nullptr;
226 }
227
228 if (!fPoolsMap)
229 fPoolsMap = new TMap();
230 pool = new TSQLObjectDataPool(sqlinfo, alldata);
231 fPoolsMap->Add(sqlinfo, pool);
232 }
233
234 if (!pool)
235 return nullptr;
236
237 if (pool->GetSqlInfo() != sqlinfo) {
238 Error("SqlObjectData", "Missmatch in pools map !!! CANNOT BE !!!");
239 return nullptr;
240 }
241
242 classdata = pool->GetClassData();
243
244 classrow = pool->GetObjectRow(objid);
245 if (!classrow) {
246 Error("SqlObjectData", "Can not find row for objid = %lld in table %s", objid, sqlinfo->GetClassTableName());
247 return nullptr;
248 }
249 }
250
251 TSQLResult *blobdata = nullptr;
252 TSQLStatement *blobstmt = fSQL->GetBlobClassDataStmt(objid, sqlinfo);
253
254 if (!blobstmt)
255 blobdata = fSQL->GetBlobClassData(objid, sqlinfo);
256
257 return new TSQLObjectData(sqlinfo, objid, classdata, classrow, blobdata, blobstmt);
258}
259
260////////////////////////////////////////////////////////////////////////////////
261/// Write object to buffer.
262/// If object was written before, only pointer will be stored
263/// Return id of saved object
264
265Int_t TBufferSQL2::SqlWriteObject(const void *obj, const TClass *cl, Bool_t cacheReuse, TMemberStreamer *streamer,
266 Int_t streamer_index)
267{
268 if (gDebug > 1)
269 Info("SqlWriteObject", "Object: %p Class: %s", obj, (cl ? cl->GetName() : "null"));
270
271 PushStack();
272
273 Long64_t objid = -1;
274
275 if (!cl)
276 obj = nullptr;
277
278 if (!obj) {
279 objid = 0;
280 } else {
282 if (value > 0)
283 objid = fFirstObjId + value - 1;
284 }
285
286 if (gDebug > 1)
287 Info("SqlWriteObject", "Find objectid %ld", (long)objid);
288
289 if (objid >= 0) {
290 Stack()->SetObjectPointer(objid);
291 PopStack();
292 return objid;
293 }
294
295 objid = fObjIdCounter++;
296
297 Stack()->SetObjectRef(objid, cl);
298
299 if (cacheReuse)
300 MapObject(obj, cl, objid - fFirstObjId + 1);
301
302 if (streamer)
303 (*streamer)(*this, (void *)obj, streamer_index);
304 else
305 ((TClass *)cl)->Streamer((void *)obj, *this);
306
307 if (gDebug > 1)
308 Info("SqlWriteObject", "Done write of %s", cl->GetName());
309
310 PopStack();
311
312 return objid;
313}
314
315////////////////////////////////////////////////////////////////////////////////
316/// Read object from the buffer
317
318void *TBufferSQL2::SqlReadObject(void *obj, TClass **cl, TMemberStreamer *streamer, Int_t streamer_index,
319 const TClass *onFileClass)
320{
321 if (cl)
322 *cl = nullptr;
323
324 if (fErrorFlag > 0)
325 return obj;
326
327 Bool_t findptr = kFALSE;
328
329 const char *refid = fCurrentData->GetValue();
330 if (!refid || (strlen(refid) == 0)) {
331 Error("SqlReadObject", "Invalid object reference value");
332 fErrorFlag = 1;
333 return obj;
334 }
335
336 Long64_t objid = (Long64_t)std::stoll(refid);
337
338 if (gDebug > 2)
339 Info("SqlReadObject", "Starting objid: %ld column: %s", (long)objid, fCurrentData->GetLocatedField());
340
342 if (objid == 0) {
343 obj = nullptr;
344 findptr = kTRUE;
345 } else if (objid == -1) {
346 findptr = kTRUE;
347 } else if (objid >= fFirstObjId) {
348 void *obj1 = nullptr;
349 TClass *cl1 = nullptr;
350 GetMappedObject(objid - fFirstObjId + 1, obj1, cl1);
351 if (obj1 && cl1) {
352 obj = obj1;
353 if (cl)
354 *cl = cl1;
355 }
356 }
357 }
358
359 if ((gDebug > 3) && findptr)
360 Info("SqlReadObject", "Found pointer %p cl %s", obj, ((cl && *cl) ? (*cl)->GetName() : "null"));
361
362 if (findptr) {
364 return obj;
365 }
366
369 Error("SqlReadObject", "Object reference or pointer is not found in blob data");
370 fErrorFlag = 1;
371 return obj;
372 }
373
375
376 if ((gDebug > 2) || (objid < 0))
377 Info("SqlReadObject", "Found object reference %ld", (long)objid);
378
379 return SqlReadObjectDirect(obj, cl, objid, streamer, streamer_index, onFileClass);
380}
381
382////////////////////////////////////////////////////////////////////////////////
383/// Read object data.
384/// Class name and version are taken from special objects table.
385
386void *TBufferSQL2::SqlReadObjectDirect(void *obj, TClass **cl, Long64_t objid, TMemberStreamer *streamer,
387 Int_t streamer_index, const TClass *onFileClass)
388{
389 TString clname;
390 Version_t version;
391
392 if (!SqlObjectInfo(objid, clname, version))
393 return obj;
394
395 if (gDebug > 2)
396 Info("SqlReadObjectDirect", "objid = %lld clname = %s ver = %d", objid, clname.Data(), version);
397
398 TSQLClassInfo *sqlinfo = fSQL->FindSQLClassInfo(clname.Data(), version);
399
400 TClass *objClass = TClass::GetClass(clname);
401 if (objClass == TDirectory::Class())
402 objClass = TDirectoryFile::Class();
403
404 if (!objClass || !sqlinfo) {
405 Error("SqlReadObjectDirect", "Class %s is not known", clname.Data());
406 return obj;
407 }
408
409 if (!obj)
410 obj = objClass->New();
411
412 MapObject(obj, objClass, objid - fFirstObjId + 1);
413
414 PushStack()->SetObjectRef(objid, objClass);
415
416 TSQLObjectData *olddata = fCurrentData;
417
418 if (sqlinfo->IsClassTableExist()) {
419 // TObject and TString classes treated differently
420 if ((objClass == TObject::Class()) || (objClass == TString::Class())) {
421
422 TSQLObjectData *objdata = new TSQLObjectData;
423 if (objClass == TObject::Class())
424 TSQLStructure::UnpackTObject(fSQL, this, objdata, objid, version);
425 else if (objClass == TString::Class())
426 TSQLStructure::UnpackTString(fSQL, this, objdata, objid, version);
427
428 Stack()->AddObjectData(objdata);
429 fCurrentData = objdata;
430 } else
431 // before normal streamer first version will be read and
432 // then streamer functions of TStreamerInfo class
433 fReadVersionBuffer = version;
434 } else {
435 TSQLObjectData *objdata = SqlObjectData(objid, sqlinfo);
436 if (!objdata || !objdata->PrepareForRawData()) {
437 Error("SqlReadObjectDirect", "No found raw data for obj %lld in class %s version %d table", objid,
438 clname.Data(), version);
439 fErrorFlag = 1;
440 return obj;
441 }
442
443 Stack()->AddObjectData(objdata);
444
445 fCurrentData = objdata;
446 }
447
448 if (streamer) {
449 streamer->SetOnFileClass(onFileClass);
450 (*streamer)(*this, (void *)obj, streamer_index);
451 } else {
452 objClass->Streamer((void *)obj, *this, onFileClass);
453 }
454
455 PopStack();
456
457 if (gDebug > 1)
458 Info("SqlReadObjectDirect", "Read object of class %s done", objClass->GetName());
459
460 if (cl)
461 *cl = objClass;
462
463 fCurrentData = olddata;
464
465 return obj;
466}
467
468////////////////////////////////////////////////////////////////////////////////
469/// Function is called from TStreamerInfo WriteBuffer and Readbuffer functions
470/// and indent new level in data structure.
471/// This call indicates, that TStreamerInfo functions starts streaming
472/// object data of correspondent class
473
475{
476 if (!info)
477 return;
478
480
481 if (gDebug > 2)
482 Info("IncrementLevel", "Info: %s", info->GetName());
483
484 WorkWithClass(info->GetName(), info->GetClassVersion());
485}
486
487////////////////////////////////////////////////////////////////////////////////
488/// Function is called from TStreamerInfo WriteBuffer and Readbuffer functions
489/// and decrease level in sql structure.
490
492{
493 if (Stack()->GetElement())
494 PopStack(); // for element
495 PopStack(); // for streamerinfo
496
497 // restore value of object data
499
500 if (gDebug > 2)
501 Info("DecrementLevel", "Info: %s", info->GetName());
502}
503
504////////////////////////////////////////////////////////////////////////////////
505/// Function is called from TStreamerInfo WriteBuffer and Readbuffer functions
506/// and add/verify next element in sql tables
507/// This calls allows separate data, correspondent to one class member, from another
508
510{
511 if (Stack()->GetElement())
512 PopStack(); // was with if (number > 0), i.e. not first element.
513 TSQLStructure *curr = Stack();
514
515 TStreamerInfo *info = curr->GetStreamerInfo();
516 if (!info) {
517 Error("SetStreamerElementNumber", "Error in structures stack");
518 return;
519 }
520
521 WorkWithElement(elem, comp_type);
522}
523
524////////////////////////////////////////////////////////////////////////////////
525/// This method inform buffer data of which class now
526/// will be streamed. When reading, classversion should be specified
527/// as was read by TBuffer::ReadVersion().
528///
529/// ClassBegin(), ClassEnd() & ClassMemeber() should be used in
530/// custom class streamers to specify which kind of data are
531/// now streamed to/from buffer. That information is used to correctly
532/// convert class data to/from "normal" sql tables with meaningfull names
533/// and correct datatypes. Without that functions data from custom streamer
534/// will be saved as "raw" data in special _streamer_ table one value after another
535/// Such MUST be used when object is written with standard ROOT streaming
536/// procedure, but should be read back in custom streamer.
537/// For example, custom streamer of TNamed class may look like:
538
539void TBufferSQL2::ClassBegin(const TClass *cl, Version_t classversion)
540{
541 // void TNamed::Streamer(TBuffer &b)
542 // UInt_t R__s, R__c;
543 // if (b.IsReading()) {
544 // Version_t R__v = b.ReadVersion(&R__s, &R__c);
545 // b.ClassBegin(TNamed::Class(), R__v);
546 // b.ClassMember("TObject");
547 // TObject::Streamer(b);
548 // b.ClassMember("fName","TString");
549 // fName.Streamer(b);
550 // b.ClassMember("fTitle","TString");
551 // fTitle.Streamer(b);
552 // b.ClassEnd(TNamed::Class());
553 // b.SetBufferOffset(R__s+R__c+sizeof(UInt_t));
554 // } else {
555 // TNamed::Class()->WriteBuffer(b,this);
556 // }
557
558 if (classversion < 0)
559 classversion = cl->GetClassVersion();
560
561 PushStack()->SetCustomClass(cl, classversion);
562
563 if (gDebug > 2)
564 Info("ClassBegin", "Class: %s", cl->GetName());
565
566 WorkWithClass(cl->GetName(), classversion);
567}
568
569////////////////////////////////////////////////////////////////////////////////
570/// Method indicates end of streaming of classdata in custom streamer.
571/// See ClassBegin() method for more details.
572
574{
575 if (Stack()->GetType() == TSQLStructure::kSqlCustomElement)
576 PopStack(); // for element
577 PopStack(); // for streamerinfo
578
579 // restore value of object data
581
582 if (gDebug > 2)
583 Info("ClassEnd", "Class: %s", cl->GetName());
584}
585
586////////////////////////////////////////////////////////////////////////////////
587/// Method indicates name and typename of class memeber,
588/// which should be now streamed in custom streamer
589/// Following combinations are supported:
590/// see TBufferXML::ClassMember for the details.
591
592void TBufferSQL2::ClassMember(const char *name, const char *typeName, Int_t arrsize1, Int_t arrsize2)
593{
594 if (!typeName)
595 typeName = name;
596
597 if (!name || (strlen(name) == 0)) {
598 Error("ClassMember", "Invalid member name");
599 fErrorFlag = 1;
600 return;
601 }
602
603 TString tname = typeName;
604
605 Int_t typ_id = -1;
606
607 if (strcmp(typeName, "raw:data") == 0)
609
610 if (typ_id < 0) {
611 TDataType *dt = gROOT->GetType(typeName);
612 if (dt)
613 if ((dt->GetType() > 0) && (dt->GetType() < 20))
614 typ_id = dt->GetType();
615 }
616
617 if (typ_id < 0)
618 if (strcmp(name, typeName) == 0) {
619 TClass *cl = TClass::GetClass(tname.Data());
620 if (cl)
621 typ_id = TStreamerInfo::kBase;
622 }
623
624 if (typ_id < 0) {
625 Bool_t isptr = kFALSE;
626 if (tname[tname.Length() - 1] == '*') {
627 tname.Resize(tname.Length() - 1);
628 isptr = kTRUE;
629 }
630 TClass *cl = TClass::GetClass(tname.Data());
631 if (!cl) {
632 Error("ClassMember", "Invalid class specifier %s", typeName);
633 fErrorFlag = 1;
634 return;
635 }
636
637 if (cl->IsTObject())
639 else
640 typ_id = isptr ? TStreamerInfo::kAnyp : TStreamerInfo::kAny;
641
642 if ((cl == TString::Class()) && !isptr)
644 }
645
646 TStreamerElement *elem = nullptr;
647
648 if (typ_id == TStreamerInfo::kMissing) {
649 elem = new TStreamerElement(name, "title", 0, typ_id, "raw:data");
650 } else if (typ_id == TStreamerInfo::kBase) {
651 TClass *cl = TClass::GetClass(tname.Data());
652 if (cl) {
653 TStreamerBase *b = new TStreamerBase(tname.Data(), "title", 0);
654 b->SetBaseVersion(cl->GetClassVersion());
655 elem = b;
656 }
657 } else if ((typ_id > 0) && (typ_id < 20)) {
658 elem = new TStreamerBasicType(name, "title", 0, typ_id, typeName);
659 } else if ((typ_id == TStreamerInfo::kObject) || (typ_id == TStreamerInfo::kTObject) ||
660 (typ_id == TStreamerInfo::kTNamed)) {
661 elem = new TStreamerObject(name, "title", 0, tname.Data());
662 } else if (typ_id == TStreamerInfo::kObjectp) {
663 elem = new TStreamerObjectPointer(name, "title", 0, tname.Data());
664 } else if (typ_id == TStreamerInfo::kAny) {
665 elem = new TStreamerObjectAny(name, "title", 0, tname.Data());
666 } else if (typ_id == TStreamerInfo::kAnyp) {
667 elem = new TStreamerObjectAnyPointer(name, "title", 0, tname.Data());
668 } else if (typ_id == TStreamerInfo::kTString) {
669 elem = new TStreamerString(name, "title", 0);
670 }
671
672 if (!elem) {
673 Error("ClassMember", "Invalid combination name = %s type = %s", name, typeName);
674 fErrorFlag = 1;
675 return;
676 }
677
678 if (arrsize1 > 0) {
679 elem->SetArrayDim(arrsize2 > 0 ? 2 : 1);
680 elem->SetMaxIndex(0, arrsize1);
681 if (arrsize2 > 0)
682 elem->SetMaxIndex(1, arrsize2);
683 }
684
685 // return stack to CustomClass node
687 PopStack();
688
689 // we indicate that there is no streamerinfo
690 WorkWithElement(elem, -1);
691}
692
693////////////////////////////////////////////////////////////////////////////////
694/// This function is a part of IncrementLevel method.
695/// Also used in StartClass method
696
697void TBufferSQL2::WorkWithClass(const char *classname, Version_t classversion)
698{
699 if (IsReading()) {
700 Long64_t objid = 0;
701
702 // if ((fCurrentData!=0) && fCurrentData->VerifyDataType(sqlio::ObjectInst, kFALSE))
703 // if (!fCurrentData->IsBlobData()) Info("WorkWithClass","Big problem %s", fCurrentData->GetValue());
704
706 objid = atoi(fCurrentData->GetValue());
708 TString sobjid;
709 sobjid.Form("%lld", objid);
710 Stack()->ChangeValueOnly(sobjid.Data());
711 } else
712 objid = Stack()->DefineObjectId(kTRUE);
713 if (objid < 0) {
714 Error("WorkWithClass", "cannot define object id");
715 fErrorFlag = 1;
716 return;
717 }
718
719 TSQLClassInfo *sqlinfo = fSQL->FindSQLClassInfo(classname, classversion);
720 if (!sqlinfo) {
721 Error("WorkWithClass", "Can not find table for class %s version %d", classname, classversion);
722 fErrorFlag = 1;
723 return;
724 }
725
726 TSQLObjectData *objdata = SqlObjectData(objid, sqlinfo);
727 if (!objdata) {
728 Error("WorkWithClass", "Request error for data of object %lld for class %s version %d", objid, classname,
729 classversion);
730 fErrorFlag = 1;
731 return;
732 }
733
734 Stack()->AddObjectData(objdata);
735
736 fCurrentData = objdata;
737 }
738}
739
740////////////////////////////////////////////////////////////////////////////////
741/// This function is a part of SetStreamerElementNumber method.
742/// It is introduced for reading of data for specified data member of class.
743/// Used also in ReadFastArray methods to resolve problem of compressed data,
744/// when several data members of the same basic type streamed with single ...FastArray call
745
747{
748 if (gDebug > 2)
749 Info("WorkWithElement", "elem = %s", elem->GetName());
750
751 TSQLStructure *stack = Stack(1);
752 TStreamerInfo *info = stack->GetStreamerInfo();
753 Int_t number = info ? info->GetElements()->IndexOf(elem) : -1;
754
755 if (number >= 0)
756 PushStack()->SetStreamerElement(elem, number);
757 else
759
760 if (IsReading()) {
761
762 if (!fCurrentData) {
763 Error("WorkWithElement", "Object data is lost");
764 fErrorFlag = 1;
765 return;
766 }
767
769
770 Int_t located = Stack()->LocateElementColumn(fSQL, this, fCurrentData);
771
772 if (located == TSQLStructure::kColUnknown) {
773 Error("WorkWithElement", "Cannot locate correct column in the table");
774 fErrorFlag = 1;
775 return;
776 } else if ((located == TSQLStructure::kColObject) || (located == TSQLStructure::kColObjectArray) ||
777 (located == TSQLStructure::kColParent)) {
778 // search again for object data while for BLOB it should be already assign
780 }
781 }
782}
783
784////////////////////////////////////////////////////////////////////////////////
785/// Suppressed function of TBuffer
786
788{
789 return nullptr;
790}
791
792////////////////////////////////////////////////////////////////////////////////
793/// Suppressed function of TBuffer
794
796{
797}
798
799////////////////////////////////////////////////////////////////////////////////
800/// Read version value from buffer
801/// actually version is normally defined by table name
802/// and kept in intermediate variable fReadVersionBuffer
803
805{
806 Version_t res = 0;
807
808 if (start)
809 *start = 0;
810 if (bcnt)
811 *bcnt = 0;
812
813 if (fReadVersionBuffer >= 0) {
814 res = fReadVersionBuffer;
816 if (gDebug > 3)
817 Info("ReadVersion", "from buffer = %d", (int)res);
820 res = value.Atoi();
821 if (gDebug > 3)
822 Info("ReadVersion", "from blob %s = %d", fCurrentData->GetBlobPrefixName(), (int)res);
824 } else {
825 Error("ReadVersion", "No correspondent tags to read version");
826 fErrorFlag = 1;
827 }
828
829 return res;
830}
831
832////////////////////////////////////////////////////////////////////////////////
833/// Copies class version to buffer, but not writes it to sql immidiately
834/// Version will be used to produce complete table
835/// name, which will include class version
836
838{
839 if (gDebug > 2)
840 Info("WriteVersion", "cl:%s ver:%d", (cl ? cl->GetName() : "null"), (int)(cl ? cl->GetClassVersion() : 0));
841
842 if (cl)
843 Stack()->AddVersion(cl);
844
845 return 0;
846}
847
848////////////////////////////////////////////////////////////////////////////////
849/// Read object from buffer. Only used from TBuffer.
850
852{
853 return SqlReadObject(nullptr);
854}
855
856////////////////////////////////////////////////////////////////////////////////
857/// ?????? Skip any kind of object from buffer
858/// !!!!!! fix me, not yet implemented
859/// Should be just skip of current column later
860
862{
863}
864
865////////////////////////////////////////////////////////////////////////////////
866/// Write object to buffer. Only used from TBuffer
867
868void TBufferSQL2::WriteObjectClass(const void *actualObjStart, const TClass *actualClass, Bool_t cacheReuse)
869{
870 if (gDebug > 2)
871 Info("WriteObjectClass", "class %s", (actualClass ? actualClass->GetName() : " null"));
872 SqlWriteObject(actualObjStart, actualClass, cacheReuse);
873}
874
875////////////////////////////////////////////////////////////////////////////////
876/// Template method to read array content
877
878template <typename T>
880{
881 if (gDebug > 3)
882 Info("SqlReadArrayContent", "size %d", (int)(arrsize));
883 PushStack()->SetArray(withsize ? arrsize : -1);
884 Int_t indx(0), first, last;
885 if (fCurrentData->IsBlobData()) {
886 while (indx < arrsize) {
887 const char *name = fCurrentData->GetBlobPrefixName();
888 if (!strstr(name, sqlio::IndexSepar)) {
889 sscanf(name, "[%d", &first);
890 last = first;
891 } else {
892 sscanf(name, "[%d..%d", &first, &last);
893 }
894 if ((first != indx) || (last < first) || (last >= arrsize)) {
895 Error("SqlReadArrayContent", "Error reading array content %s", name);
896 fErrorFlag = 1;
897 break;
898 }
899 SqlReadBasic(arr[indx++]);
900 while (indx <= last)
901 arr[indx++] = arr[first];
902 }
903 } else {
904 while (indx < arrsize)
905 SqlReadBasic(arr[indx++]);
906 }
907 PopStack();
908 if (gDebug > 3)
909 Info("SqlReadArrayContent", "done");
910}
911
912template <typename T>
914{
916 if (n <= 0)
917 return 0;
918 if (!arr) {
919 if (is_static)
920 return 0;
921 arr = new T[n];
922 }
924 return n;
925}
926
927////////////////////////////////////////////////////////////////////////////////
928/// Read array of Bool_t from buffer
929
931{
932 return SqlReadArray(b);
933}
934
935////////////////////////////////////////////////////////////////////////////////
936/// Read array of Char_t from buffer
937
939{
940 return SqlReadArray(c);
941}
942
943////////////////////////////////////////////////////////////////////////////////
944/// Read array of UChar_t from buffer
945
947{
948 return SqlReadArray(c);
949}
950
951////////////////////////////////////////////////////////////////////////////////
952/// Read array of Short_t from buffer
953
955{
956 return SqlReadArray(h);
957}
958
959////////////////////////////////////////////////////////////////////////////////
960/// Read array of UShort_t from buffer
961
963{
964 return SqlReadArray(h);
965}
966
967////////////////////////////////////////////////////////////////////////////////
968/// Read array of Int_t from buffer
969
971{
972 return SqlReadArray(i);
973}
974
975////////////////////////////////////////////////////////////////////////////////
976/// Read array of UInt_t from buffer
977
979{
980 return SqlReadArray(i);
981}
982
983////////////////////////////////////////////////////////////////////////////////
984/// Read array of Long_t from buffer
985
987{
988 return SqlReadArray(l);
989}
990
991////////////////////////////////////////////////////////////////////////////////
992/// Read array of ULong_t from buffer
993
995{
996 return SqlReadArray(l);
997}
998
999////////////////////////////////////////////////////////////////////////////////
1000/// Read array of Long64_t from buffer
1001
1003{
1004 return SqlReadArray(l);
1005}
1006
1007////////////////////////////////////////////////////////////////////////////////
1008/// Read array of ULong64_t from buffer
1009
1011{
1012 return SqlReadArray(l);
1013}
1014
1015////////////////////////////////////////////////////////////////////////////////
1016/// Read array of Float_t from buffer
1017
1019{
1020 return SqlReadArray(f);
1021}
1022
1023////////////////////////////////////////////////////////////////////////////////
1024/// Read array of Double_t from buffer
1025
1027{
1028 return SqlReadArray(d);
1029}
1030
1031////////////////////////////////////////////////////////////////////////////////
1032/// Read array of Bool_t from buffer
1033
1035{
1036 return SqlReadArray(b, kTRUE);
1037}
1038
1039////////////////////////////////////////////////////////////////////////////////
1040/// Read array of Char_t from buffer
1041
1043{
1044 return SqlReadArray(c, kTRUE);
1045}
1046
1047////////////////////////////////////////////////////////////////////////////////
1048/// Read array of UChar_t from buffer
1049
1051{
1052 return SqlReadArray(c, kTRUE);
1053}
1054
1055////////////////////////////////////////////////////////////////////////////////
1056/// Read array of Short_t from buffer
1057
1059{
1060 return SqlReadArray(h, kTRUE);
1061}
1062
1063////////////////////////////////////////////////////////////////////////////////
1064/// Read array of UShort_t from buffer
1065
1067{
1068 return SqlReadArray(h, kTRUE);
1069}
1070
1071////////////////////////////////////////////////////////////////////////////////
1072/// Read array of Int_t from buffer
1073
1075{
1076 return SqlReadArray(i, kTRUE);
1077}
1078
1079////////////////////////////////////////////////////////////////////////////////
1080/// Read array of UInt_t from buffer
1081
1083{
1084 return SqlReadArray(i, kTRUE);
1085}
1086
1087////////////////////////////////////////////////////////////////////////////////
1088/// Read array of Long_t from buffer
1089
1091{
1092 return SqlReadArray(l, kTRUE);
1093}
1094
1095////////////////////////////////////////////////////////////////////////////////
1096/// Read array of ULong_t from buffer
1097
1099{
1100 return SqlReadArray(l, kTRUE);
1101}
1102
1103////////////////////////////////////////////////////////////////////////////////
1104/// Read array of Long64_t from buffer
1105
1107{
1108 return SqlReadArray(l, kTRUE);
1109}
1110
1111////////////////////////////////////////////////////////////////////////////////
1112/// Read array of ULong64_t from buffer
1113
1115{
1116 return SqlReadArray(l, kTRUE);
1117}
1118
1119////////////////////////////////////////////////////////////////////////////////
1120/// Read array of Float_t from buffer
1121
1123{
1124 return SqlReadArray(f, kTRUE);
1125}
1126
1127////////////////////////////////////////////////////////////////////////////////
1128/// Read array of Double_t from buffer
1129
1131{
1132 return SqlReadArray(d, kTRUE);
1133}
1134
1135////////////////////////////////////////////////////////////////////////////////
1136/// Template method to read content of array, which not include size of array
1137
1138template <typename T>
1140{
1141 if (arrsize > 0)
1142 SqlReadArrayContent(arr, arrsize, kFALSE);
1143}
1144
1145////////////////////////////////////////////////////////////////////////////////
1146/// Read array of Bool_t from buffer
1147
1149{
1151}
1152
1153////////////////////////////////////////////////////////////////////////////////
1154/// Read array of Char_t from buffer
1155/// if nodename==CharStar, read all array as string
1156
1158{
1160 const char *buf = SqlReadCharStarValue();
1161 if (!buf || (n <= 0))
1162 return;
1163 Int_t size = strlen(buf);
1164 if (size < n)
1165 size = n;
1166 memcpy(c, buf, size);
1167 } else {
1169 }
1170}
1171
1172////////////////////////////////////////////////////////////////////////////////
1173/// Read array of UChar_t from buffer
1174
1176{
1178}
1179
1180////////////////////////////////////////////////////////////////////////////////
1181/// Read array of Short_t from buffer
1182
1184{
1186}
1187
1188////////////////////////////////////////////////////////////////////////////////
1189/// Read array of UShort_t from buffer
1190
1192{
1194}
1195
1196////////////////////////////////////////////////////////////////////////////////
1197/// Read array of Int_t from buffer
1198
1200{
1201 SqlReadFastArray(i, n);
1202}
1203
1204////////////////////////////////////////////////////////////////////////////////
1205/// Read array of UInt_t from buffer
1206
1208{
1209 SqlReadFastArray(i, n);
1210}
1211
1212////////////////////////////////////////////////////////////////////////////////
1213/// Read array of Long_t from buffer
1214
1216{
1218}
1219
1220////////////////////////////////////////////////////////////////////////////////
1221/// Read array of ULong_t from buffer
1222
1224{
1226}
1227
1228////////////////////////////////////////////////////////////////////////////////
1229/// Read array of Long64_t from buffer
1230
1232{
1234}
1235
1236////////////////////////////////////////////////////////////////////////////////
1237/// Read array of ULong64_t from buffer
1238
1240{
1242}
1243
1244////////////////////////////////////////////////////////////////////////////////
1245/// Read array of Float_t from buffer
1246
1248{
1250}
1251
1252////////////////////////////////////////////////////////////////////////////////
1253/// Read array of n characters from the I/O buffer.
1254/// Used only from TLeafC, dummy implementation here
1255
1257{
1259}
1260
1261////////////////////////////////////////////////////////////////////////////////
1262/// Read array of Double_t from buffer
1263
1265{
1267}
1268
1269////////////////////////////////////////////////////////////////////////////////
1270/// Same functionality as TBuffer::ReadFastArray(...) but
1271/// instead of calling cl->Streamer(obj,buf) call here
1272/// buf.StreamObject(obj, cl). In that case it is easy to understand where
1273/// object data is started and finished
1274
1275void TBufferSQL2::ReadFastArray(void *start, const TClass *cl, Int_t n, TMemberStreamer *streamer,
1276 const TClass *onFileClass)
1277{
1278 if (gDebug > 2)
1279 Info("ReadFastArray", "(void *");
1280
1281 if (streamer) {
1282 StreamObjectExtra(start, streamer, cl, 0, onFileClass);
1283 // (*streamer)(*this,start,0);
1284 return;
1285 }
1286
1287 int objectSize = cl->Size();
1288 char *obj = (char *)start;
1289 char *end = obj + n * objectSize;
1290
1291 for (; obj < end; obj += objectSize) {
1292 StreamObject(obj, cl, onFileClass);
1293 }
1294 // TBuffer::ReadFastArray(start, cl, n, s);
1295}
1296
1297////////////////////////////////////////////////////////////////////////////////
1298/// Same functionality as TBuffer::ReadFastArray(...) but
1299/// instead of calling cl->Streamer(obj,buf) call here
1300/// buf.StreamObject(obj, cl). In that case it is easy to understand where
1301/// object data is started and finished
1302
1303void TBufferSQL2::ReadFastArray(void **start, const TClass *cl, Int_t n, Bool_t isPreAlloc, TMemberStreamer *streamer,
1304 const TClass *onFileClass)
1305{
1306 if (gDebug > 2)
1307 Info("ReadFastArray", "(void ** pre = %d n = %d", isPreAlloc, n);
1308
1309 Bool_t oldStyle = kFALSE; // flag used to reproduce old-style I/O actions for kSTLp
1310
1311 if ((fIOVersion < 2) && !isPreAlloc) {
1312 TStreamerElement *elem = Stack(0)->GetElement();
1313 if (elem && ((elem->GetType() == TStreamerInfo::kSTLp) ||
1315 oldStyle = kTRUE;
1316 }
1317
1318 if (streamer) {
1319 if (isPreAlloc) {
1320 for (Int_t j = 0; j < n; j++) {
1321 if (!start[j])
1322 start[j] = ((TClass *)cl)->New();
1323 }
1324 }
1325 if (oldStyle)
1326 (*streamer)(*this, (void *)start, n);
1327 else
1328 StreamObjectExtra((void *)start, streamer, cl, 0, onFileClass);
1329 return;
1330 }
1331
1332 if (!isPreAlloc) {
1333
1334 for (Int_t j = 0; j < n; j++) {
1335 if (oldStyle) {
1336 if (!start[j])
1337 start[j] = ((TClass *)cl)->New();
1338 ((TClass *)cl)->Streamer(start[j], *this);
1339 continue;
1340 }
1341
1342 // delete the object or collection
1343 if (start[j] && TStreamerInfo::CanDelete())
1344 ((TClass *)cl)->Destructor(start[j], kFALSE); // call delete and desctructor
1345 start[j] = ReadObjectAny(cl);
1346 }
1347
1348 } else { // case //-> in comment
1349
1350 for (Int_t j = 0; j < n; j++) {
1351 if (!start[j])
1352 start[j] = ((TClass *)cl)->New();
1353 StreamObject(start[j], cl, onFileClass);
1354 }
1355 }
1356
1357 if (gDebug > 2)
1358 Info("ReadFastArray", "(void ** Done");
1359
1360 // TBuffer::ReadFastArray(startp, cl, n, isPreAlloc, s);
1361}
1362
1363////////////////////////////////////////////////////////////////////////////////
1364/// Reads array size, written in raw data table.
1365/// Used in ReadArray methods, where TBuffer need to read array size first.
1366
1368{
1369 const char *value = SqlReadValue(sqlio::Array);
1370 if (!value || (strlen(value) == 0))
1371 return 0;
1372 Int_t sz = atoi(value);
1373 return sz;
1374}
1375
1376template <typename T>
1378{
1379 constexpr Int_t dataWidth = 1; // at least 1
1380 const Int_t maxElements = (std::numeric_limits<Int_t>::max() - Length())/dataWidth;
1381 if (arrsize < 0 || arrsize > maxElements)
1382 {
1383 Fatal("SqlWriteArray", "Not enough space left in the buffer (1GB limit). %lld elements is greater than the max left of %d", arrsize, maxElements);
1384 return; // In case the user re-routes the error handler to not die when Fatal is called)
1385 }
1386 if (!withsize && (arrsize <= 0))
1387 return;
1388 PushStack()->SetArray(withsize ? arrsize : -1);
1389 Int_t indx = 0;
1390 if (fCompressLevel > 0) {
1391 while (indx < arrsize) {
1392 Int_t curr = indx++;
1393 while ((indx < arrsize) && (arr[indx] == arr[curr]))
1394 indx++;
1395 SqlWriteBasic(arr[curr]);
1396 Stack()->ChildArrayIndex(curr, indx - curr);
1397 }
1398 } else {
1399 for (; indx < arrsize; indx++) {
1400 SqlWriteBasic(arr[indx]);
1401 Stack()->ChildArrayIndex(indx, 1);
1402 }
1403 }
1404 PopStack();
1405}
1406
1407////////////////////////////////////////////////////////////////////////////////
1408/// Write array of Bool_t to buffer
1409
1411{
1413}
1414
1415////////////////////////////////////////////////////////////////////////////////
1416/// Write array of Char_t to buffer
1417
1419{
1421}
1422
1423////////////////////////////////////////////////////////////////////////////////
1424/// Write array of UChar_t to buffer
1425
1427{
1429}
1430
1431////////////////////////////////////////////////////////////////////////////////
1432/// Write array of Short_t to buffer
1433
1435{
1437}
1438
1439////////////////////////////////////////////////////////////////////////////////
1440/// Write array of UShort_t to buffer
1441
1443{
1445}
1446
1447////////////////////////////////////////////////////////////////////////////////
1448/// Write array of Int_ to buffer
1449
1451{
1452 SqlWriteArray(i, n, kTRUE);
1453}
1454
1455////////////////////////////////////////////////////////////////////////////////
1456/// Write array of UInt_t to buffer
1457
1459{
1460 SqlWriteArray(i, n, kTRUE);
1461}
1462
1463////////////////////////////////////////////////////////////////////////////////
1464/// Write array of Long_t to buffer
1465
1467{
1469}
1470
1471////////////////////////////////////////////////////////////////////////////////
1472/// Write array of ULong_t to buffer
1473
1475{
1477}
1478
1479////////////////////////////////////////////////////////////////////////////////
1480/// Write array of Long64_t to buffer
1481
1483{
1485}
1486
1487////////////////////////////////////////////////////////////////////////////////
1488/// Write array of ULong64_t to buffer
1489
1491{
1493}
1494
1495////////////////////////////////////////////////////////////////////////////////
1496/// Write array of Float_t to buffer
1497
1499{
1501}
1502
1503////////////////////////////////////////////////////////////////////////////////
1504/// Write array of Double_t to buffer
1505
1507{
1509}
1510
1511////////////////////////////////////////////////////////////////////////////////
1512/// Write array of Bool_t to buffer
1513
1515{
1516 SqlWriteArray(b, n);
1517}
1518
1519////////////////////////////////////////////////////////////////////////////////
1520/// Write array of Char_t to buffer
1521/// it will be reproduced as CharStar node with string as attribute
1522
1524{
1525 Bool_t usedefault = (n == 0);
1526
1527 const Char_t *ccc = c;
1528 // check if no zeros in the array
1529 if (!usedefault)
1530 for (Long64_t i = 0; i < n; i++)
1531 if (*ccc++ == 0) {
1532 usedefault = kTRUE;
1533 break;
1534 }
1535
1536 if (usedefault) {
1537 SqlWriteArray(c, n);
1538 } else {
1539 Char_t *buf = new Char_t[n + 1];
1540 memcpy(buf, c, n);
1541 buf[n] = 0;
1543 delete[] buf;
1544 }
1545}
1546
1547////////////////////////////////////////////////////////////////////////////////
1548/// Write array of UChar_t to buffer
1549
1551{
1552 SqlWriteArray(c, n);
1553}
1554
1555////////////////////////////////////////////////////////////////////////////////
1556/// Write array of Short_t to buffer
1557
1559{
1560 SqlWriteArray(h, n);
1561}
1562
1563////////////////////////////////////////////////////////////////////////////////
1564/// Write array of UShort_t to buffer
1565
1567{
1568 SqlWriteArray(h, n);
1569}
1570
1571////////////////////////////////////////////////////////////////////////////////
1572/// Write array of Int_t to buffer
1573
1575{
1576 SqlWriteArray(i, n);
1577}
1578
1579////////////////////////////////////////////////////////////////////////////////
1580/// Write array of UInt_t to buffer
1581
1583{
1584 SqlWriteArray(i, n);
1585}
1586
1587////////////////////////////////////////////////////////////////////////////////
1588/// Write array of Long_t to buffer
1589
1591{
1592 SqlWriteArray(l, n);
1593}
1594
1595////////////////////////////////////////////////////////////////////////////////
1596/// Write array of ULong_t to buffer
1597
1599{
1600 SqlWriteArray(l, n);
1601}
1602
1603////////////////////////////////////////////////////////////////////////////////
1604/// Write array of Long64_t to buffer
1605
1607{
1608 SqlWriteArray(l, n);
1609}
1610
1611////////////////////////////////////////////////////////////////////////////////
1612/// Write array of ULong64_t to buffer
1613
1615{
1616 SqlWriteArray(l, n);
1617}
1618
1619////////////////////////////////////////////////////////////////////////////////
1620/// Write array of Float_t to buffer
1621
1623{
1624 SqlWriteArray(f, n);
1625}
1626
1627////////////////////////////////////////////////////////////////////////////////
1628/// Write array of Double_t to buffer
1629
1631{
1632 SqlWriteArray(d, n);
1633}
1634
1635////////////////////////////////////////////////////////////////////////////////
1636/// Write array of n characters into the I/O buffer.
1637/// Used only by TLeafC, just dummy implementation here
1638
1640{
1641 SqlWriteArray(c, n);
1642}
1643
1644////////////////////////////////////////////////////////////////////////////////
1645/// Same functionality as TBuffer::WriteFastArray(...) but
1646/// instead of calling cl->Streamer(obj,buf) call here
1647/// buf.StreamObject(obj, cl). In that case it is easy to understand where
1648/// object data is started and finished
1649
1650void TBufferSQL2::WriteFastArray(void *start, const TClass *cl, Long64_t n, TMemberStreamer *streamer)
1651{
1652 if (streamer) {
1653 StreamObjectExtra(start, streamer, cl, 0);
1654 // (*streamer)(*this, start, 0);
1655 return;
1656 }
1657
1658 char *obj = (char *)start;
1659 if (!n)
1660 n = 1;
1661 int size = cl->Size();
1662
1663 for (Long64_t j = 0; j < n; j++, obj += size)
1664 StreamObject(obj, cl);
1665}
1666
1667////////////////////////////////////////////////////////////////////////////////
1668/// Same functionality as TBuffer::WriteFastArray(...) but
1669/// instead of calling cl->Streamer(obj,buf) call here
1670/// buf.StreamObject(obj, cl). In that case it is easy to understand where
1671/// object data is started and finished
1672
1673Int_t TBufferSQL2::WriteFastArray(void **start, const TClass *cl, Long64_t n, Bool_t isPreAlloc, TMemberStreamer *streamer)
1674{
1675
1676 Bool_t oldStyle = kFALSE; // flag used to reproduce old-style I/O actions for kSTLp
1677
1678 if ((fIOVersion < 2) && !isPreAlloc) {
1679 TStreamerElement *elem = Stack(0)->GetElement();
1680 if (elem && ((elem->GetType() == TStreamerInfo::kSTLp) ||
1682 oldStyle = kTRUE;
1683 }
1684
1685 if (streamer) {
1686 if (oldStyle)
1687 (*streamer)(*this, (void *)start, n);
1688 else
1689 StreamObjectExtra((void *)start, streamer, cl, 0);
1690 return 0;
1691 }
1692
1693 int strInfo = 0;
1694
1695 Int_t res = 0;
1696
1697 if (!isPreAlloc) {
1698
1699 for (Long64_t j = 0; j < n; j++) {
1700 // must write StreamerInfo if pointer is null
1701 if (!strInfo && !start[j] && !oldStyle)
1702 ForceWriteInfo(((TClass *)cl)->GetStreamerInfo(), kFALSE);
1703 strInfo = 2003;
1704 if (oldStyle)
1705 ((TClass *)cl)->Streamer(start[j], *this);
1706 else
1707 res |= WriteObjectAny(start[j], cl);
1708 }
1709
1710 } else {
1711 // case //-> in comment
1712
1713 for (Long64_t j = 0; j < n; j++) {
1714 if (!start[j])
1715 start[j] = ((TClass *)cl)->New();
1716 StreamObject(start[j], cl);
1717 }
1718 }
1719 return res;
1720
1721 // return TBuffer::WriteFastArray(startp, cl, n, isPreAlloc, s);
1722}
1723
1724////////////////////////////////////////////////////////////////////////////////
1725/// Stream object to/from buffer
1726
1727void TBufferSQL2::StreamObject(void *obj, const TClass *cl, const TClass *onFileClass)
1728{
1729 if (fIOVersion < 2) {
1730 TStreamerElement *elem = Stack(0)->GetElement();
1731 if (elem && (elem->GetType() == TStreamerInfo::kTObject)) {
1732 ((TObject *)obj)->TObject::Streamer(*this);
1733 return;
1734 } else if (elem && (elem->GetType() == TStreamerInfo::kTNamed)) {
1735 ((TNamed *)obj)->TNamed::Streamer(*this);
1736 return;
1737 }
1738 }
1739
1740 if (gDebug > 1)
1741 Info("StreamObject", "class %s", (cl ? cl->GetName() : "none"));
1742 if (IsReading())
1743 SqlReadObject(obj, nullptr, nullptr, 0, onFileClass);
1744 else
1745 SqlWriteObject(obj, cl, kTRUE);
1746}
1747
1748////////////////////////////////////////////////////////////////////////////////
1749/// Stream object to/from buffer
1750
1751void TBufferSQL2::StreamObjectExtra(void *obj, TMemberStreamer *streamer, const TClass *cl, Int_t n,
1752 const TClass *onFileClass)
1753{
1754 if (!streamer)
1755 return;
1756
1757 if (gDebug > 1)
1758 Info("StreamObjectExtra", "class = %s", cl->GetName());
1759 // (*streamer)(*this, obj, n);
1760
1761 if (IsReading())
1762 SqlReadObject(obj, nullptr, streamer, n, onFileClass);
1763 else
1764 SqlWriteObject(obj, cl, kTRUE, streamer, n);
1765}
1766
1767////////////////////////////////////////////////////////////////////////////////
1768/// Reads Bool_t value from buffer
1769
1771{
1772 SqlReadBasic(b);
1773}
1774
1775////////////////////////////////////////////////////////////////////////////////
1776/// Reads Char_t value from buffer
1777
1779{
1780 SqlReadBasic(c);
1781}
1782
1783////////////////////////////////////////////////////////////////////////////////
1784/// Reads UChar_t value from buffer
1785
1787{
1788 SqlReadBasic(c);
1789}
1790
1791////////////////////////////////////////////////////////////////////////////////
1792/// Reads Short_t value from buffer
1793
1795{
1796 SqlReadBasic(h);
1797}
1798
1799////////////////////////////////////////////////////////////////////////////////
1800/// Reads UShort_t value from buffer
1801
1803{
1804 SqlReadBasic(h);
1805}
1806
1807////////////////////////////////////////////////////////////////////////////////
1808/// Reads Int_t value from buffer
1809
1811{
1812 SqlReadBasic(i);
1813}
1814
1815////////////////////////////////////////////////////////////////////////////////
1816/// Reads UInt_t value from buffer
1817
1819{
1820 SqlReadBasic(i);
1821}
1822
1823////////////////////////////////////////////////////////////////////////////////
1824/// Reads Long_t value from buffer
1825
1827{
1828 SqlReadBasic(l);
1829}
1830
1831////////////////////////////////////////////////////////////////////////////////
1832/// Reads ULong_t value from buffer
1833
1835{
1836 SqlReadBasic(l);
1837}
1838
1839////////////////////////////////////////////////////////////////////////////////
1840/// Reads Long64_t value from buffer
1841
1843{
1844 SqlReadBasic(l);
1845}
1846
1847////////////////////////////////////////////////////////////////////////////////
1848/// Reads ULong64_t value from buffer
1849
1851{
1852 SqlReadBasic(l);
1853}
1854
1855////////////////////////////////////////////////////////////////////////////////
1856/// Reads Float_t value from buffer
1857
1859{
1860 SqlReadBasic(f);
1861}
1862
1863////////////////////////////////////////////////////////////////////////////////
1864/// Reads Double_t value from buffer
1865
1867{
1868 SqlReadBasic(d);
1869}
1870
1871////////////////////////////////////////////////////////////////////////////////
1872/// Reads array of characters from buffer
1873
1875{
1876 const char *buf = SqlReadCharStarValue();
1877 if (buf)
1878 strcpy(c, buf); // NOLINT unfortunately, we do not know size of target buffer
1879}
1880
1881////////////////////////////////////////////////////////////////////////////////
1882/// Read a TString
1883
1885{
1886 if (fIOVersion < 2) {
1887 // original TBufferFile method can not be used, while used TString methods are private
1888 // try to reimplement close to the original
1889 Int_t nbig;
1890 UChar_t nwh;
1891 *this >> nwh;
1892 if (nwh == 0) {
1893 s.Resize(0);
1894 } else {
1895 if (nwh == 255)
1896 *this >> nbig;
1897 else
1898 nbig = nwh;
1899
1900 char *data = new char[nbig+1];
1901 data[nbig] = 0;
1902 ReadFastArray(data, nbig);
1903 s = data;
1904 delete[] data;
1905 }
1906 } else {
1907 // TODO: new code - direct reading of string
1908 }
1909}
1910
1911////////////////////////////////////////////////////////////////////////////////
1912/// Write a TString
1913
1915{
1916 if (fIOVersion < 2) {
1917 // original TBufferFile method, keep for compatibility
1918 Int_t nbig = s.Length();
1919 UChar_t nwh;
1920 if (nbig > 254) {
1921 nwh = 255;
1922 *this << nwh;
1923 *this << nbig;
1924 } else {
1925 nwh = UChar_t(nbig);
1926 *this << nwh;
1927 }
1928 const char *data = s.Data();
1929 WriteFastArray(data, nbig);
1930 } else {
1931 // TODO: make writing of string directly
1932 }
1933}
1934
1935////////////////////////////////////////////////////////////////////////////////
1936/// Read a std::string
1937
1938void TBufferSQL2::ReadStdString(std::string *obj)
1939{
1940 if (fIOVersion < 2) {
1941 if (!obj) {
1942 Error("ReadStdString", "The std::string address is nullptr but should not");
1943 return;
1944 }
1945 Int_t nbig;
1946 UChar_t nwh;
1947 *this >> nwh;
1948 if (nwh == 0) {
1949 obj->clear();
1950 } else {
1951 if (obj->size()) {
1952 // Insure that the underlying data storage is not shared
1953 (*obj)[0] = '\0';
1954 }
1955 if (nwh == 255) {
1956 *this >> nbig;
1957 obj->resize(nbig, '\0');
1958 ReadFastArray((char *)obj->data(), nbig);
1959 } else {
1960 obj->resize(nwh, '\0');
1961 ReadFastArray((char *)obj->data(), nwh);
1962 }
1963 }
1964 } else {
1965 // TODO: direct reading of std string
1966 }
1967}
1968
1969////////////////////////////////////////////////////////////////////////////////
1970/// Write a std::string
1971
1972void TBufferSQL2::WriteStdString(const std::string *obj)
1973{
1974 if (fIOVersion < 2) {
1975 if (!obj) {
1976 *this << (UChar_t)0;
1977 WriteFastArray("", 0);
1978 return;
1979 }
1980
1981 UChar_t nwh;
1982 Int_t nbig = obj->length();
1983 if (nbig > 254) {
1984 nwh = 255;
1985 *this << nwh;
1986 *this << nbig;
1987 } else {
1988 nwh = UChar_t(nbig);
1989 *this << nwh;
1990 }
1991 WriteFastArray(obj->data(), nbig);
1992 } else {
1993 // TODO: make writing of string directly
1994 }
1995}
1996
1997////////////////////////////////////////////////////////////////////////////////
1998/// Read a char* string
1999
2001{
2002 delete[] s;
2003 s = nullptr;
2004
2005 Int_t nch;
2006 *this >> nch;
2007 if (nch > 0) {
2008 s = new char[nch + 1];
2009 ReadFastArray(s, nch);
2010 s[nch] = 0;
2011 }
2012}
2013
2014////////////////////////////////////////////////////////////////////////////////
2015/// Write a char* string
2016
2018{
2019 Int_t nch = 0;
2020 if (s) {
2021 nch = strlen(s);
2022 *this << nch;
2023 WriteFastArray(s, nch);
2024 } else {
2025 *this << nch;
2026 }
2027}
2028
2029////////////////////////////////////////////////////////////////////////////////
2030/// Writes Bool_t value to buffer
2031
2033{
2035}
2036
2037////////////////////////////////////////////////////////////////////////////////
2038/// Writes Char_t value to buffer
2039
2041{
2043}
2044
2045////////////////////////////////////////////////////////////////////////////////
2046/// Writes UChar_t value to buffer
2047
2049{
2051}
2052
2053////////////////////////////////////////////////////////////////////////////////
2054/// Writes Short_t value to buffer
2055
2057{
2059}
2060
2061////////////////////////////////////////////////////////////////////////////////
2062/// Writes UShort_t value to buffer
2063
2065{
2067}
2068
2069////////////////////////////////////////////////////////////////////////////////
2070/// Writes Int_t value to buffer
2071
2073{
2074 SqlWriteBasic(i);
2075}
2076
2077////////////////////////////////////////////////////////////////////////////////
2078/// Writes UInt_t value to buffer
2079
2081{
2082 SqlWriteBasic(i);
2083}
2084
2085////////////////////////////////////////////////////////////////////////////////
2086/// Writes Long_t value to buffer
2087
2089{
2091}
2092
2093////////////////////////////////////////////////////////////////////////////////
2094/// Writes ULong_t value to buffer
2095
2097{
2099}
2100
2101////////////////////////////////////////////////////////////////////////////////
2102/// Writes Long64_t value to buffer
2103
2105{
2107}
2108
2109////////////////////////////////////////////////////////////////////////////////
2110/// Writes ULong64_t value to buffer
2111
2113{
2115}
2116
2117////////////////////////////////////////////////////////////////////////////////
2118/// Writes Float_t value to buffer
2119
2121{
2123}
2124
2125////////////////////////////////////////////////////////////////////////////////
2126/// Writes Double_t value to buffer
2127
2129{
2131}
2132
2133////////////////////////////////////////////////////////////////////////////////
2134/// Writes array of characters to buffer
2135
2137{
2139}
2140
2141////////////////////////////////////////////////////////////////////////////////
2142/// converts Char_t to string and creates correspondent sql structure
2143
2145{
2146 char buf[50];
2147 snprintf(buf, sizeof(buf), "%d", value);
2148 return SqlWriteValue(buf, sqlio::Char);
2149}
2150
2151////////////////////////////////////////////////////////////////////////////////
2152/// converts Short_t to string and creates correspondent sql structure
2153
2155{
2156 char buf[50];
2157 snprintf(buf, sizeof(buf), "%hd", value);
2158 return SqlWriteValue(buf, sqlio::Short);
2159}
2160
2161////////////////////////////////////////////////////////////////////////////////
2162/// converts Int_t to string and creates correspondent sql structure
2163
2165{
2166 char buf[50];
2167 snprintf(buf, sizeof(buf), "%d", value);
2168 return SqlWriteValue(buf, sqlio::Int);
2169}
2170
2171////////////////////////////////////////////////////////////////////////////////
2172/// converts Long_t to string and creates correspondent sql structure
2173
2175{
2176 char buf[50];
2177 snprintf(buf, sizeof(buf), "%ld", value);
2178 return SqlWriteValue(buf, sqlio::Long);
2179}
2180
2181////////////////////////////////////////////////////////////////////////////////
2182/// converts Long64_t to string and creates correspondent sql structure
2183
2185{
2186 std::string buf = std::to_string(value);
2187 return SqlWriteValue(buf.c_str(), sqlio::Long64);
2188}
2189
2190////////////////////////////////////////////////////////////////////////////////
2191/// converts Float_t to string and creates correspondent sql structure
2192
2194{
2195 char buf[200];
2196 ConvertFloat(value, buf, sizeof(buf), kTRUE);
2197 return SqlWriteValue(buf, sqlio::Float);
2198}
2199
2200////////////////////////////////////////////////////////////////////////////////
2201/// converts Double_t to string and creates correspondent sql structure
2202
2204{
2205 char buf[200];
2206 ConvertDouble(value, buf, sizeof(buf), kTRUE);
2207 return SqlWriteValue(buf, sqlio::Double);
2208}
2209
2210////////////////////////////////////////////////////////////////////////////////
2211/// converts Bool_t to string and creates correspondent sql structure
2212
2214{
2216}
2217
2218////////////////////////////////////////////////////////////////////////////////
2219/// converts UChar_t to string and creates correspondent sql structure
2220
2222{
2223 char buf[50];
2224 snprintf(buf, sizeof(buf), "%u", value);
2225 return SqlWriteValue(buf, sqlio::UChar);
2226}
2227
2228////////////////////////////////////////////////////////////////////////////////
2229/// converts UShort_t to string and creates correspondent sql structure
2230
2232{
2233 char buf[50];
2234 snprintf(buf, sizeof(buf), "%hu", value);
2235 return SqlWriteValue(buf, sqlio::UShort);
2236}
2237
2238////////////////////////////////////////////////////////////////////////////////
2239/// converts UInt_t to string and creates correspondent sql structure
2240
2242{
2243 char buf[50];
2244 snprintf(buf, sizeof(buf), "%u", value);
2245 return SqlWriteValue(buf, sqlio::UInt);
2246}
2247
2248////////////////////////////////////////////////////////////////////////////////
2249/// converts ULong_t to string and creates correspondent sql structure
2250
2252{
2253 char buf[50];
2254 snprintf(buf, sizeof(buf), "%lu", value);
2255 return SqlWriteValue(buf, sqlio::ULong);
2256}
2257
2258////////////////////////////////////////////////////////////////////////////////
2259/// converts ULong64_t to string and creates correspondent sql structure
2260
2262{
2263 std::string buf = std::to_string(value);
2264 return SqlWriteValue(buf.c_str(), sqlio::ULong64);
2265}
2266
2267//______________________________________________________________________________
2268
2269Bool_t TBufferSQL2::SqlWriteValue(const char *value, const char *tname)
2270{
2271 // create structure in stack, which holds specified value
2272
2273 Stack()->AddValue(value, tname);
2274
2275 return kTRUE;
2276}
2277
2278////////////////////////////////////////////////////////////////////////////////
2279/// Read current value from table and convert it to Char_t value
2280
2282{
2283 const char *res = SqlReadValue(sqlio::Char);
2284 if (res) {
2285 int n;
2286 sscanf(res, "%d", &n);
2287 value = n;
2288 } else
2289 value = 0;
2290}
2291
2292////////////////////////////////////////////////////////////////////////////////
2293/// Read current value from table and convert it to Short_t value
2294
2296{
2297 const char *res = SqlReadValue(sqlio::Short);
2298 if (res)
2299 sscanf(res, "%hd", &value);
2300 else
2301 value = 0;
2302}
2303
2304////////////////////////////////////////////////////////////////////////////////
2305/// Read current value from table and convert it to Int_t value
2306
2308{
2309 const char *res = SqlReadValue(sqlio::Int);
2310 if (res)
2311 sscanf(res, "%d", &value);
2312 else
2313 value = 0;
2314}
2315
2316////////////////////////////////////////////////////////////////////////////////
2317/// Read current value from table and convert it to Long_t value
2318
2320{
2321 const char *res = SqlReadValue(sqlio::Long);
2322 if (res)
2323 sscanf(res, "%ld", &value);
2324 else
2325 value = 0;
2326}
2327
2328////////////////////////////////////////////////////////////////////////////////
2329/// Read current value from table and convert it to Long64_t value
2330
2332{
2333 const char *res = SqlReadValue(sqlio::Long64);
2334 if (res)
2335 value = (Long64_t)std::stoll(res);
2336 else
2337 value = 0;
2338}
2339
2340////////////////////////////////////////////////////////////////////////////////
2341/// Read current value from table and convert it to Float_t value
2342
2344{
2345 const char *res = SqlReadValue(sqlio::Float);
2346 if (res)
2347 sscanf(res, "%f", &value);
2348 else
2349 value = 0.;
2350}
2351
2352////////////////////////////////////////////////////////////////////////////////
2353/// Read current value from table and convert it to Double_t value
2354
2356{
2357 const char *res = SqlReadValue(sqlio::Double);
2358 if (res)
2359 sscanf(res, "%lf", &value);
2360 else
2361 value = 0.;
2362}
2363
2364////////////////////////////////////////////////////////////////////////////////
2365/// Read current value from table and convert it to Bool_t value
2366
2368{
2369 const char *res = SqlReadValue(sqlio::Bool);
2370 if (res)
2371 value = (strcmp(res, sqlio::True) == 0);
2372 else
2373 value = kFALSE;
2374}
2375
2376////////////////////////////////////////////////////////////////////////////////
2377/// Read current value from table and convert it to UChar_t value
2378
2380{
2381 const char *res = SqlReadValue(sqlio::UChar);
2382 if (res) {
2383 unsigned int n;
2384 sscanf(res, "%ud", &n);
2385 value = n;
2386 } else
2387 value = 0;
2388}
2389
2390////////////////////////////////////////////////////////////////////////////////
2391/// Read current value from table and convert it to UShort_t value
2392
2394{
2395 const char *res = SqlReadValue(sqlio::UShort);
2396 if (res)
2397 sscanf(res, "%hud", &value);
2398 else
2399 value = 0;
2400}
2401
2402////////////////////////////////////////////////////////////////////////////////
2403/// Read current value from table and convert it to UInt_t value
2404
2406{
2407 const char *res = SqlReadValue(sqlio::UInt);
2408 if (res)
2409 sscanf(res, "%u", &value);
2410 else
2411 value = 0;
2412}
2413
2414////////////////////////////////////////////////////////////////////////////////
2415/// Read current value from table and convert it to ULong_t value
2416
2418{
2419 const char *res = SqlReadValue(sqlio::ULong);
2420 if (res)
2421 sscanf(res, "%lu", &value);
2422 else
2423 value = 0;
2424}
2425
2426////////////////////////////////////////////////////////////////////////////////
2427/// Read current value from table and convert it to ULong64_t value
2428
2430{
2431 const char *res = SqlReadValue(sqlio::ULong64);
2432 if (res)
2433 value = (ULong64_t)std::stoull(res);
2434 else
2435 value = 0;
2436}
2437
2438////////////////////////////////////////////////////////////////////////////////
2439/// Read string value from current stack node
2440
2441const char *TBufferSQL2::SqlReadValue(const char *tname)
2442{
2443 if (fErrorFlag > 0)
2444 return nullptr;
2445
2446 if (!fCurrentData) {
2447 Error("SqlReadValue", "No object data to read from");
2448 fErrorFlag = 1;
2449 return nullptr;
2450 }
2451
2453 if (!fCurrentData->VerifyDataType(tname)) {
2454 fErrorFlag = 1;
2455 return nullptr;
2456 }
2457
2459
2461
2462 if (gDebug > 4)
2463 Info("SqlReadValue", "%s = %s", tname, fReadBuffer.Data());
2464
2465 return fReadBuffer.Data();
2466}
2467
2468////////////////////////////////////////////////////////////////////////////////
2469/// Read CharStar value, if it has special code, request it from large table
2470
2472{
2473 const char *res = SqlReadValue(sqlio::CharStar);
2474 if (!res || !fSQL)
2475 return nullptr;
2476
2477 Long64_t objid = Stack()->DefineObjectId(kTRUE);
2478
2479 Int_t strid = fSQL->IsLongStringCode(objid, res);
2480 if (strid <= 0)
2481 return res;
2482
2483 fSQL->GetLongString(objid, strid, fReadBuffer);
2484
2485 return fReadBuffer.Data();
2486}
2487
2488////////////////////////////////////////////////////////////////////////////////
2489/// Push stack with structural information about streamed object
2490
2492{
2493 TSQLStructure *res = new TSQLStructure;
2494 if (!fStk) {
2495 fStructure = res;
2496 } else {
2497 fStk->Add(res);
2498 }
2499
2500 fStk = res; // add in the stack
2501 return fStk;
2502}
2503
2504////////////////////////////////////////////////////////////////////////////////
2505/// Pop stack
2506
2508{
2509 if (!fStk)
2510 return nullptr;
2511 fStk = fStk->GetParent();
2512 return fStk;
2513}
2514
2515////////////////////////////////////////////////////////////////////////////////
2516/// returns head of stack
2517
2519{
2520 TSQLStructure *curr = fStk;
2521 while ((depth-- > 0) && curr)
2522 curr = curr->GetParent();
2523 return curr;
2524}
2525
2526////////////////////////////////////////////////////////////////////////////////
2527/// Return current streamer info element
2528
2530{
2531 return Stack()->GetStreamerInfo();
2532}
#define R__ALWAYS_INLINE
Definition RConfig.hxx:544
#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
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
unsigned short UShort_t
Definition RtypesCore.h:40
short Version_t
Definition RtypesCore.h:65
unsigned char UChar_t
Definition RtypesCore.h:38
char Char_t
Definition RtypesCore.h:37
unsigned long ULong_t
Definition RtypesCore.h:55
long Long_t
Definition RtypesCore.h:54
float Float_t
Definition RtypesCore.h:57
short Short_t
Definition RtypesCore.h:39
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
long long Long64_t
Definition RtypesCore.h:80
unsigned long long ULong64_t
Definition RtypesCore.h:81
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char mode
char name[80]
Definition TGX11.cxx:110
Int_t gDebug
Definition TROOT.cxx:597
#define gROOT
Definition TROOT.h:407
#define snprintf
Definition civetweb.c:1540
void ForceWriteInfo(TVirtualStreamerInfo *info, Bool_t force) override
force writing the TStreamerInfo to the file
void MapObject(const TObject *obj, UInt_t offset=1) override
Add object to the fMap container.
Long64_t GetObjectTag(const void *obj)
Returns tag for specified object from objects map (if exists) Returns 0 if object not included into o...
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...
Int_t WriteObjectAny(const void *obj, const TClass *ptrClass, Bool_t cacheReuse=kTRUE) override
Write object to I/O buffer.
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.
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
void WriteFastArrayString(const Char_t *c, Long64_t n) final
Write array of n characters into the I/O buffer.
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.
void WriteCharP(const Char_t *c) final
Writes array of characters to buffer.
void WriteFastArray(const Bool_t *b, Long64_t n) final
Write array of Bool_t 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
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.
Int_t fReadVersionBuffer
! buffer, used to by ReadVersion method
Definition TBufferSQL2.h:39
void ClassMember(const char *name, const char *typeName=nullptr, 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 ...
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.
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.
TSQLStructure * fStructure
! structures, created by object storing
Definition TBufferSQL2.h:34
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.
R__ALWAYS_INLINE void SqlWriteArray(T *arr, Long64_t arrsize, Bool_t withsize=kFALSE)
friend class TSQLStructure
Definition TBufferSQL2.h:29
void WriteClass(const TClass *cl) final
Suppressed function of TBuffer.
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 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.
~TBufferSQL2() override
Destroy sql buffer.
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.
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
static const char * ConvertFloat(Float_t v, char *buf, unsigned len, Bool_t not_optimize=kFALSE)
convert float to string with configured format
static const char * ConvertDouble(Double_t v, char *buf, unsigned len, Bool_t not_optimize=kFALSE)
convert float to string with configured format
Bool_t IsReading() const
Definition TBuffer.h:86
Int_t Length() const
Definition TBuffer.h:100
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
void Streamer(void *obj, TBuffer &b, const TClass *onfile_class=nullptr) const
Definition TClass.h:607
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition TClass.cxx:4978
Int_t Size() const
Return size of object of this class.
Definition TClass.cxx:5704
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
Definition TClass.cxx:5938
Version_t GetClassVersion() const
Definition TClass.h:420
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2968
Basic data type descriptor (datatype information is obtained from CINT).
Definition TDataType.h:44
Int_t GetType() const
Definition TDataType.h:68
static TClass * Class()
static TClass * Class()
Int_t GetCompressionLevel() const
Definition TFile.h:391
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition TMap.h:40
void Add(TObject *obj) override
This function may not be used (but we need to provide it since it is a pure virtual in TCollection).
Definition TMap.cxx:54
void DeleteValues()
Remove all (key,value) pairs from the map AND delete the values when they are allocated on the heap.
Definition TMap.cxx:151
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Definition TMap.cxx:236
virtual void SetOnFileClass(const TClass *cl)
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Int_t IndexOf(const TObject *obj) const override
TObject * Last() const override
Return the object in the last filled slot. Returns 0 if no entries.
void Delete(Option_t *option="") override
Remove all objects from the array AND delete all heap based objects.
TObject * At(Int_t idx) const override
Definition TObjArray.h:164
Int_t GetLast() const override
Return index of last object in array.
Mother of all ROOT objects.
Definition TObject.h:41
static TClass * Class()
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1015
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:961
Contains information about tables specific to one class and version.
Bool_t IsClassTableExist() const
const char * GetClassTableName() const
Access an SQL db via the TFile interface.
Definition TSQLFile.h:30
Int_t GetIOVersion() const
Definition TSQLFile.h:196
Int_t IsLongStringCode(Long64_t objid, const char *value)
Checks if this is long string code returns 0, if not or string id.
TSQLClassInfo * FindSQLClassInfo(const char *clname, Int_t version)
Return (if exists) TSQLClassInfo for specified class name and version.
TObjArray * SQLObjectsInfo(Long64_t keyid)
Produce array of TSQLObjectInfo objects for all objects, belong to that key Array should be deleted b...
TSQLStatement * GetBlobClassDataStmt(Long64_t objid, TSQLClassInfo *sqlinfo)
Method return request results for specified objid from streamer classtable Data returned in form of s...
TSQLResult * GetBlobClassData(Long64_t objid, TSQLClassInfo *sqlinfo)
Method return request results for specified objid from streamer classtable.
TSQLResult * GetNormalClassDataAll(Long64_t minobjid, Long64_t maxobjid, TSQLClassInfo *sqlinfo)
Return data for several objects from the range from normal class table.
Bool_t GetLongString(Long64_t objid, Int_t strid, TString &value)
Returns value of string, extracted from special table, where long strings are stored.
XML object keeper class.
TSQLRow * GetObjectRow(Long64_t objid)
Returns single sql row with object data for that class.
TSQLResult * GetClassData() const
TSQLClassInfo * GetSqlInfo() const
TSQLObjectData is used in TBufferSQL2 class in reading procedure.
const char * GetLocatedField() const
void ShiftToNextValue()
shift to next column or next row in blob data
Bool_t IsBlobData() const
const char * GetValue() const
const char * GetBlobPrefixName() const
Bool_t PrepareForRawData()
prepare to read data from raw table
Bool_t VerifyDataType(const char *tname, Bool_t errormsg=kTRUE)
checks if data type corresponds to that stored in raw table
Info (classname, version) about object in database.
Version_t GetObjVersion() const
const char * GetObjClassName() const
Long64_t GetObjId() const
This is hierarchical structure, which is created when data is written by TBufferSQL2.
TSQLStructure * GetParent() const
Int_t LocateElementColumn(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data)
find column in TSQLObjectData object, which correspond to current element
void Add(TSQLStructure *child)
Add child structure.
void AddVersion(const TClass *cl, Int_t version=-100)
add child as version
void SetObjectPointer(Long64_t ptrid)
set structure type as kSqlPointer
void SetArray(Int_t sz=-1)
Set structure as array element.
TSQLObjectData * GetObjectData(Bool_t search=false)
searches for objects data
TStreamerInfo * GetStreamerInfo() const
return TStreamerInfo* if type is kSqlStreamerInfo
void SetCustomClass(const TClass *cl, Version_t version)
set structure type as kSqlCustomClass
static Bool_t UnpackTString(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data, Long64_t objid, Int_t clversion)
Unpack TString data in form, accepted by custom TString streamer.
void AddValue(const char *value, const char *tname=nullptr)
Add child structure as value.
void SetStreamerInfo(const TStreamerInfo *info)
set structure type as kSqlStreamerInfo
void AddObjectData(TSQLObjectData *objdata)
add element with pointer to object data
Int_t GetType() const
static Bool_t UnpackTObject(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data, Long64_t objid, Int_t clversion)
Unpack TObject data in form, accepted by custom TObject streamer.
void ChangeValueOnly(const char *value)
change value of this structure used as "workaround" to keep object id in kSqlElement node
void Print(Option_t *option="") const override
print content of complete structure
void SetCustomElement(TStreamerElement *elem)
set structure type as kSqlCustomElement
void SetObjectRef(Long64_t refid, const TClass *cl)
set structure type as kSqlObject
Long64_t DefineObjectId(Bool_t recursive=kTRUE)
defines current object id, to which this structure belong make life complicated, because some objects...
TStreamerElement * GetElement() const
return TStremerElement* if type is kSqlElement
void SetStreamerElement(const TStreamerElement *elem, Int_t number)
set structure type as kSqlElement
void ChildArrayIndex(Int_t index, Int_t cnt=1)
set array index for last child element if (cnt<=1) return;
Int_t GetType() const
virtual void SetArrayDim(Int_t dim)
Set number of array dimensions.
virtual void SetMaxIndex(Int_t dim, Int_t max)
set maximum index for array with dimension dim
Describes a persistent version of a class.
TObjArray * GetElements() const override
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
const char * Data() const
Definition TString.h:376
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Definition TString.cxx:1152
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2356
static TClass * Class()
Abstract Interface class describing Streamer information for one class.
static Bool_t CanDelete()
static function returning true if ReadBuffer can delete object
virtual Int_t GetClassVersion() const =0
const Int_t n
Definition legend1.C:16
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
const char * Long
const char * ULong
const char * Float
const char * ObjectRef
const char * False
const char * Double
const char * UChar
const char * ObjectPtr
const char * ULong64
const char * IndexSepar
const char * ObjectInst
const char * Version
const char * Short
const char * Int
const char * Long64
const char * UInt
const char * True
const char * Array
const char * UShort
const char * Bool
const char * Char
const char * CharStar
TLine l
Definition textangle.C:4