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