#include "TBufferSQL2.h"
#include "TObjArray.h"
#include "TROOT.h"
#include "TDataType.h"
#include "TClass.h"
#include "TClassTable.h"
#include "TMap.h"
#include "TExMap.h"
#include "TMethodCall.h"
#include "TStreamerInfo.h"
#include "TStreamerElement.h"
#include "TProcessID.h"
#include "TFile.h"
#include "TMemberStreamer.h"
#include "TStreamer.h"
#include "Riostream.h"
#include <stdlib.h>
#include "TStreamerInfoActions.h"
#include "TSQLServer.h"
#include "TSQLResult.h"
#include "TSQLRow.h"
#include "TSQLStructure.h"
#include "TSQLObjectData.h"
#include "TSQLFile.h"
#include "TSQLClassInfo.h"
#ifdef R__VISUAL_CPLUSPLUS
#define FLong64 "%I64d"
#define FULong64 "%I64u"
#else
#define FLong64 "%lld"
#define FULong64 "%llu"
#endif
ClassImp(TBufferSQL2);
TBufferSQL2::TBufferSQL2() :
TBufferFile(),
fSQL(0),
fStructure(0),
fStk(0),
fObjMap(0),
fReadBuffer(),
fErrorFlag(0),
fExpectedChain(kFALSE),
fCompressLevel(0),
fReadVersionBuffer(-1),
fObjIdCounter(1),
fIgnoreVerification(kFALSE),
fCurrentData(0),
fObjectsInfos(0),
fFirstObjId(0),
fLastObjId(0),
fPoolsMap(0)
{
}
TBufferSQL2::TBufferSQL2(TBuffer::EMode mode) :
TBufferFile(mode),
fSQL(0),
fStructure(0),
fStk(0),
fObjMap(0),
fReadBuffer(),
fErrorFlag(0),
fExpectedChain(kFALSE),
fCompressLevel(0),
fReadVersionBuffer(-1),
fObjIdCounter(1),
fIgnoreVerification(kFALSE),
fCurrentData(0),
fObjectsInfos(0),
fFirstObjId(0),
fLastObjId(0),
fPoolsMap(0)
{
SetParent(0);
SetBit(kCannotHandleMemberWiseStreaming);
SetBit(kTextBasedStreaming);
}
TBufferSQL2::TBufferSQL2(TBuffer::EMode mode, TSQLFile* file) :
TBufferFile(mode),
fSQL(0),
fStructure(0),
fStk(0),
fObjMap(0),
fReadBuffer(),
fErrorFlag(0),
fExpectedChain(kFALSE),
fCompressLevel(0),
fReadVersionBuffer(-1),
fObjIdCounter(1),
fIgnoreVerification(kFALSE),
fCurrentData(0),
fObjectsInfos(0),
fFirstObjId(0),
fLastObjId(0),
fPoolsMap(0)
{
fBufSize = 1000000000;
SetBit(kCannotHandleMemberWiseStreaming);
SetBit(kTextBasedStreaming);
SetParent(file);
fSQL = file;
if (file!=0)
SetCompressionLevel(file->GetCompressionLevel());
}
TBufferSQL2::~TBufferSQL2()
{
if (fObjMap) delete fObjMap;
if (fStructure!=0) {
delete fStructure;
fStructure = 0;
}
if (fObjectsInfos!=0) {
fObjectsInfos->Delete();
delete fObjectsInfos;
}
if (fPoolsMap!=0) {
fPoolsMap->DeleteValues();
delete fPoolsMap;
}
}
TSQLStructure* TBufferSQL2::SqlWriteAny(const void* obj, const TClass* cl, Long64_t objid)
{
fErrorFlag = 0;
fStructure = 0;
fFirstObjId = objid;
fObjIdCounter = objid;
SqlWriteObject(obj, cl);
if (gDebug>3)
if (fStructure!=0) {
std::cout << "==== Printout of Sql structures ===== " << std::endl;
fStructure->Print("*");
std::cout << "=========== End printout ============ " << std::endl;
}
return fStructure;
}
void* TBufferSQL2::SqlReadAny(Long64_t keyid, Long64_t objid, TClass** cl, void* obj)
{
if (cl) *cl = 0;
if (fSQL==0) return 0;
fCurrentData = 0;
fErrorFlag = 0;
fReadVersionBuffer = -1;
fObjectsInfos = fSQL->SQLObjectsInfo(keyid);
fFirstObjId = objid;
fLastObjId = objid;
if (fObjectsInfos!=0) {
TSQLObjectInfo* objinfo = (TSQLObjectInfo*) fObjectsInfos->Last();
if (objinfo!=0) fLastObjId = objinfo->GetObjId();
}
return SqlReadObjectDirect(obj, cl, objid);
}
Bool_t TBufferSQL2::SqlObjectInfo(Long64_t objid, TString& clname, Version_t& version)
{
if ((objid<0) || (fObjectsInfos==0)) return kFALSE;
Long64_t shift = objid - fFirstObjId;
TSQLObjectInfo* info = 0;
if ((shift>=0) && (shift<=fObjectsInfos->GetLast())) {
info = (TSQLObjectInfo*) fObjectsInfos->At(shift);
if (info->GetObjId()!=objid) info = 0;
}
if (info==0) {
Info("SqlObjectInfo", "Standard not works %lld", objid);
for (Int_t n=0;n<=fObjectsInfos->GetLast();n++) {
info = (TSQLObjectInfo*) fObjectsInfos->At(n);
if (info->GetObjId()==objid) break;
info = 0;
}
}
if (info==0) return kFALSE;
clname = info->GetObjClassName();
version = info->GetObjVersion();
return kTRUE;
}
TSQLObjectData* TBufferSQL2::SqlObjectData(Long64_t objid, TSQLClassInfo* sqlinfo)
{
TSQLResult *classdata = 0;
TSQLRow *classrow = 0;
if (sqlinfo->IsClassTableExist()) {
TSQLObjectDataPool* pool = 0;
if (fPoolsMap!=0)
pool = (TSQLObjectDataPool*) fPoolsMap->GetValue(sqlinfo);
if ((pool==0) && (fLastObjId>=fFirstObjId)) {
if (gDebug>4) Info("SqlObjectData","Before request to %s",sqlinfo->GetClassTableName());
TSQLResult *alldata = fSQL->GetNormalClassDataAll(fFirstObjId, fLastObjId, sqlinfo);
if (gDebug>4) Info("SqlObjectData","After request res = 0x%lx",(Long_t)alldata);
if (alldata==0) {
Error("SqlObjectData","Cannot get data from table %s",sqlinfo->GetClassTableName());
return 0;
}
if (fPoolsMap==0) fPoolsMap = new TMap();
pool = new TSQLObjectDataPool(sqlinfo, alldata);
fPoolsMap->Add(sqlinfo, pool);
}
if (pool==0) return 0;
if (pool->GetSqlInfo()!=sqlinfo) {
Error("SqlObjectData","Missmatch in pools map !!! CANNOT BE !!!");
return 0;
}
classdata = pool->GetClassData();
classrow = pool->GetObjectRow(objid);
if (classrow==0) {
Error("SqlObjectData","Can not find row for objid = %lld in table %s", objid, sqlinfo->GetClassTableName());
return 0;
}
}
TSQLResult *blobdata = 0;
TSQLStatement* blobstmt = fSQL->GetBlobClassDataStmt(objid, sqlinfo);
if (blobstmt==0) blobdata = fSQL->GetBlobClassData(objid, sqlinfo);
return new TSQLObjectData(sqlinfo, objid, classdata, classrow, blobdata, blobstmt);
}
void TBufferSQL2::WriteObject(const TObject *obj)
{
TBufferFile::WriteObject(obj);
}
Int_t TBufferSQL2::SqlWriteObject(const void* obj, const TClass* cl, TMemberStreamer *streamer, Int_t streamer_index)
{
if (gDebug>1)
std::cout << " SqlWriteObject " << obj << " : cl = " << (cl ? cl->GetName() : "null") << std::endl;
PushStack();
Long64_t objid = -1;
if (cl==0) obj = 0;
if (obj==0)
objid = 0;
else
if (fObjMap!=0) {
ULong_t hash = TString::Hash(&obj, sizeof(void*));
Long_t value = fObjMap->GetValue(hash, (Long_t) obj);
if (value>0)
objid = fFirstObjId + value - 1;
}
if (gDebug>1)
std::cout << " Find objectid = " << objid << std::endl;
if (objid>=0) {
Stack()->SetObjectPointer(objid);
PopStack();
return objid;
}
objid = fObjIdCounter++;
Stack()->SetObjectRef(objid, cl);
ULong_t hash = TString::Hash(&obj, sizeof(void*));
if (fObjMap==0) fObjMap = new TExMap();
if (fObjMap->GetValue(hash, (Long_t) obj)==0)
fObjMap->Add(hash, (Long_t) obj, (Long_t) objid - fFirstObjId + 1);
if (streamer!=0)
(*streamer)(*this, (void*) obj, streamer_index);
else
((TClass*)cl)->Streamer((void*)obj, *this);
if (gDebug>1)
std::cout << "Done write of " << cl->GetName() << std::endl;
PopStack();
return objid;
}
void* TBufferSQL2::SqlReadObject(void* obj, TClass** cl, TMemberStreamer *streamer, Int_t streamer_index, const TClass *onFileClass)
{
if (cl) *cl = 0;
if (fErrorFlag>0) return obj;
Bool_t findptr = kFALSE;
const char* refid = fCurrentData->GetValue();
if ((refid==0) || (strlen(refid)==0)) {
Error("SqlReadObject","Invalid object reference value");
fErrorFlag = 1;
return obj;
}
Long64_t objid = -1;
sscanf(refid, FLong64, &objid);
if (gDebug>2)
Info("SqlReadObject","Starting objid = %lld column=%s", objid, fCurrentData->GetLocatedField());
if (!fCurrentData->IsBlobData() ||
fCurrentData->VerifyDataType(sqlio::ObjectPtr,kFALSE)) {
if (objid==0) {
obj = 0;
findptr = kTRUE;
} else {
if (objid==-1) {
findptr = kTRUE;
} else {
if ((fObjMap!=0) && (objid>=fFirstObjId)) {
void* obj1 = (void*) (Long_t)fObjMap->GetValue((Long_t) objid - fFirstObjId);
if (obj1!=0) {
obj = obj1;
findptr = kTRUE;
TString clname;
Version_t version;
if ((cl!=0) && SqlObjectInfo(objid, clname, version))
*cl = TClass::GetClass(clname);
}
}
}
}
}
if ((gDebug>3) && findptr)
std::cout << " Found pointer " << (obj ? obj : 0)
<< " class = " << ((cl && *cl) ? (*cl)->GetName() : "null") << std::endl;
if (findptr) {
fCurrentData->ShiftToNextValue();
return obj;
}
if (fCurrentData->IsBlobData())
if (!fCurrentData->VerifyDataType(sqlio::ObjectRef)) {
Error("SqlReadObject","Object reference or pointer is not found in blob data");
fErrorFlag = 1;
return obj;
}
fCurrentData->ShiftToNextValue();
if ((gDebug>2) || (objid<0))
std::cout << "Found object reference " << objid << std::endl;
return SqlReadObjectDirect(obj, cl, objid, streamer, streamer_index, onFileClass);
}
void* TBufferSQL2::SqlReadObjectDirect(void* obj, TClass** cl, Long64_t objid, TMemberStreamer *streamer, Int_t streamer_index, const TClass *onFileClass)
{
TString clname;
Version_t version;
if (!SqlObjectInfo(objid, clname, version)) return obj;
if (gDebug>2)
Info("SqlReadObjectDirect","objid = %lld clname = %s ver = %d",objid, clname.Data(), version);
TSQLClassInfo* sqlinfo = fSQL->FindSQLClassInfo(clname.Data(), version);
TClass* objClass = TClass::GetClass(clname);
if (objClass == TDirectory::Class()) objClass = TDirectoryFile::Class();
if ((objClass==0) || (sqlinfo==0)) {
Error("SqlReadObjectDirect","Class %s is not known", clname.Data());
return obj;
}
if (obj==0) obj = objClass->New();
if (fObjMap==0) fObjMap = new TExMap();
fObjMap->Add((Long_t) objid - fFirstObjId, (Long_t) obj);
PushStack()->SetObjectRef(objid, objClass);
TSQLObjectData* olddata = fCurrentData;
if (sqlinfo->IsClassTableExist()) {
if ((objClass==TObject::Class()) || (objClass==TString::Class())) {
TSQLObjectData* objdata = new TSQLObjectData;
if (objClass==TObject::Class())
TSQLStructure::UnpackTObject(fSQL, this, objdata, objid, version);
else
if (objClass==TString::Class())
TSQLStructure::UnpackTString(fSQL, this, objdata, objid, version);
Stack()->AddObjectData(objdata);
fCurrentData = objdata;
} else
fReadVersionBuffer = version;
} else {
TSQLObjectData* objdata = SqlObjectData(objid, sqlinfo);
if ((objdata==0) || !objdata->PrepareForRawData()) {
Error("SqlReadObjectDirect","No found raw data for obj %lld in class %s version %d table", objid, clname.Data(), version);
fErrorFlag = 1;
return obj;
}
Stack()->AddObjectData(objdata);
fCurrentData = objdata;
}
if (streamer!=0) {
streamer->SetOnFileClass( onFileClass );
(*streamer)(*this, (void*)obj, streamer_index);
} else {
objClass->Streamer((void*)obj, *this, onFileClass);
}
PopStack();
if (gDebug>1)
std::cout << "Read object of class " << objClass->GetName() << " done" << std::endl << std::endl;
if (cl!=0) *cl = objClass;
fCurrentData = olddata;
return obj;
}
void TBufferSQL2::IncrementLevel(TVirtualStreamerInfo* info)
{
if (info==0) return;
PushStack()->SetStreamerInfo((TStreamerInfo*)info);
if (gDebug>2)
std::cout << " IncrementLevel " << info->GetName() << std::endl;
WorkWithClass(info->GetName(), info->GetClassVersion());
}
void TBufferSQL2::DecrementLevel(TVirtualStreamerInfo* info)
{
TSQLStructure* curr = Stack();
if (curr->GetType()==TSQLStructure::kSqlElement) PopStack();
PopStack();
fCurrentData = Stack()->GetObjectData(kTRUE);
fExpectedChain = kFALSE;
if (gDebug>2)
std::cout << " DecrementLevel " << info->GetClass()->GetName() << std::endl;
}
void TBufferSQL2::SetStreamerElementNumber(Int_t number)
{
if (number>0) PopStack();
TSQLStructure* curr = Stack();
TStreamerInfo* info = curr->GetStreamerInfo();
if (info==0) {
Error("SetStreamerElementNumber","Error in structures stack");
return;
}
TStreamerElement* elem = info->GetStreamerElementReal(number, 0);
Int_t comp_type = info->GetTypes()[number];
Int_t elem_type = elem->GetType();
fExpectedChain = ((elem_type>0) && (elem_type<20)) &&
(comp_type - elem_type == TStreamerInfo::kOffsetL);
WorkWithElement(elem, number);
}
void TBufferSQL2::ClassBegin(const TClass* cl, Version_t classversion)
{
if (classversion<0) classversion = cl->GetClassVersion();
PushStack()->SetCustomClass(cl, classversion);
if (gDebug>2) Info("ClassBegin", "%s", cl->GetName());
WorkWithClass(cl->GetName(), classversion);
}
void TBufferSQL2::ClassEnd(const TClass* cl)
{
TSQLStructure* curr = Stack();
if (curr->GetType()==TSQLStructure::kSqlCustomElement) PopStack();
PopStack();
fCurrentData = Stack()->GetObjectData(kTRUE);
fExpectedChain = kFALSE;
if (gDebug>2) Info("ClassEnd","%s",cl->GetName());
}
void TBufferSQL2::ClassMember(const char* name, const char* typeName, Int_t arrsize1, Int_t arrsize2)
{
if (typeName==0) typeName = name;
if ((name==0) || (strlen(name)==0)) {
Error("ClassMember","Invalid member name");
fErrorFlag = 1;
return;
}
TString tname = typeName;
Int_t typ_id = -1;
if (strcmp(typeName,"raw:data")==0)
typ_id = TStreamerInfo::kMissing;
if (typ_id<0) {
TDataType *dt = gROOT->GetType(typeName);
if (dt!=0)
if ((dt->GetType()>0) && (dt->GetType()<20))
typ_id = dt->GetType();
}
if (typ_id<0)
if (strcmp(name, typeName)==0) {
TClass* cl = TClass::GetClass(tname.Data());
if (cl!=0) typ_id = TStreamerInfo::kBase;
}
if (typ_id<0) {
Bool_t isptr = kFALSE;
if (tname[tname.Length()-1]=='*') {
tname.Resize(tname.Length()-1);
isptr = kTRUE;
}
TClass* cl = TClass::GetClass(tname.Data());
if (cl==0) {
Error("ClassMember","Invalid class specifier %s", typeName);
fErrorFlag = 1;
return;
}
if (cl->IsTObject())
typ_id = isptr ? TStreamerInfo::kObjectp : TStreamerInfo::kObject;
else
typ_id = isptr ? TStreamerInfo::kAnyp : TStreamerInfo::kAny;
if ((cl==TString::Class()) && !isptr)
typ_id = TStreamerInfo::kTString;
}
TStreamerElement* elem = 0;
if (typ_id == TStreamerInfo::kMissing) {
elem = new TStreamerElement(name,"title",0, typ_id, "raw:data");
} else
if (typ_id==TStreamerInfo::kBase) {
TClass* cl = TClass::GetClass(tname.Data());
if (cl!=0) {
TStreamerBase* b = new TStreamerBase(tname.Data(), "title", 0);
b->SetBaseVersion(cl->GetClassVersion());
elem = b;
}
} else
if ((typ_id>0) && (typ_id<20)) {
elem = new TStreamerBasicType(name, "title", 0, typ_id, typeName);
} else
if ((typ_id==TStreamerInfo::kObject) ||
(typ_id==TStreamerInfo::kTObject) ||
(typ_id==TStreamerInfo::kTNamed)) {
elem = new TStreamerObject(name, "title", 0, tname.Data());
} else
if (typ_id==TStreamerInfo::kObjectp) {
elem = new TStreamerObjectPointer(name, "title", 0, tname.Data());
} else
if (typ_id==TStreamerInfo::kAny) {
elem = new TStreamerObjectAny(name, "title", 0, tname.Data());
} else
if (typ_id==TStreamerInfo::kAnyp) {
elem = new TStreamerObjectAnyPointer(name, "title", 0, tname.Data());
} else
if (typ_id==TStreamerInfo::kTString) {
elem = new TStreamerString(name, "title", 0);
}
if (elem==0) {
Error("ClassMember","Invalid combination name = %s type = %s", name, typeName);
fErrorFlag = 1;
return;
}
if (arrsize1>0) {
elem->SetArrayDim(arrsize2>0 ? 2 : 1);
elem->SetMaxIndex(0, arrsize1);
if (arrsize2>0)
elem->SetMaxIndex(1, arrsize2);
}
if (Stack()->GetType()==TSQLStructure::kSqlCustomElement) PopStack();
fExpectedChain = kFALSE;
WorkWithElement(elem, -1);
}
void TBufferSQL2::WorkWithClass(const char* classname, Version_t classversion)
{
fExpectedChain = kFALSE;
if (IsReading()) {
Long64_t objid = 0;
if ((fCurrentData!=0) && fCurrentData->IsBlobData() &&
fCurrentData->VerifyDataType(sqlio::ObjectInst, kFALSE)) {
objid = atoi(fCurrentData->GetValue());
fCurrentData->ShiftToNextValue();
TString sobjid;
sobjid.Form("%lld",objid);
Stack()->ChangeValueOnly(sobjid.Data());
} else
objid = Stack()->DefineObjectId(kTRUE);
if (objid<0) {
Error("WorkWithClass","cannot define object id");
fErrorFlag = 1;
return;
}
TSQLClassInfo* sqlinfo = fSQL->FindSQLClassInfo(classname, classversion);
if (sqlinfo==0) {
Error("WorkWithClass","Can not find table for class %s version %d", classname, classversion);
fErrorFlag = 1;
return;
}
TSQLObjectData* objdata = SqlObjectData(objid, sqlinfo);
if (objdata==0) {
Error("WorkWithClass","Request error for data of object %lld for class %s version %d", objid, classname, classversion);
fErrorFlag = 1;
return;
}
Stack()->AddObjectData(objdata);
fCurrentData = objdata;
}
}
void TBufferSQL2::WorkWithElement(TStreamerElement* elem, Int_t number)
{
if (gDebug>2)
Info("WorkWithElement","elem = %s",elem->GetName());
if (number>=0)
PushStack()->SetStreamerElement(elem, number);
else
PushStack()->SetCustomElement(elem);
if (IsReading()) {
if (fCurrentData==0) {
Error("WorkWithElement","Object data is lost");
fErrorFlag = 1;
return;
}
fCurrentData = Stack()->GetObjectData(kTRUE);
Int_t located = Stack()->LocateElementColumn(fSQL, this, fCurrentData);
if (located==TSQLStructure::kColUnknown) {
Error("WorkWithElement","Cannot locate correct column in the table");
fErrorFlag = 1;
return;
} else
if ((located==TSQLStructure::kColObject) ||
(located==TSQLStructure::kColObjectArray) ||
(located==TSQLStructure::kColParent)) {
fCurrentData = Stack()->GetObjectData(kTRUE);
}
}
}
TClass* TBufferSQL2::ReadClass(const TClass*, UInt_t*)
{
return 0;
}
void TBufferSQL2::WriteClass(const TClass*)
{
}
Int_t TBufferSQL2::CheckByteCount(UInt_t , UInt_t , const TClass* )
{
return 0;
}
Int_t TBufferSQL2::CheckByteCount(UInt_t, UInt_t, const char*)
{
return 0;
}
void TBufferSQL2::SetByteCount(UInt_t, Bool_t)
{
}
void TBufferSQL2::SkipVersion(const TClass *cl)
{
ReadVersion(0,0,cl);
}
Version_t TBufferSQL2::ReadVersion(UInt_t *start, UInt_t *bcnt, const TClass *)
{
Version_t res = 0;
if (start) *start = 0;
if (bcnt) *bcnt = 0;
if (fReadVersionBuffer>=0) {
res = fReadVersionBuffer;
fReadVersionBuffer = -1;
if (gDebug>3)
std::cout << "TBufferSQL2::ReadVersion from buffer = " << res << std::endl;
} else
if ((fCurrentData!=0) && fCurrentData->IsBlobData() &&
fCurrentData->VerifyDataType(sqlio::Version)) {
TString value = fCurrentData->GetValue();
res = value.Atoi();
if (gDebug>3)
std::cout << "TBufferSQL2::ReadVersion from blob " << fCurrentData->GetBlobPrefixName() << " = " << res << std::endl;
fCurrentData->ShiftToNextValue();
} else {
Error("ReadVersion", "No correspondent tags to read version");
fErrorFlag = 1;
}
return res;
}
UInt_t TBufferSQL2::WriteVersion(const TClass *cl, Bool_t )
{
if (gDebug>2)
std::cout << "TBufferSQL2::WriteVersion " << (cl ? cl->GetName() : "null") << " ver = " << (cl ? cl->GetClassVersion() : 0) << std::endl;
if (cl)
Stack()->AddVersion(cl);
return 0;
}
void* TBufferSQL2::ReadObjectAny(const TClass*)
{
return SqlReadObject(0);
}
void TBufferSQL2::SkipObjectAny()
{
}
void TBufferSQL2::WriteObjectClass(const void *actualObjStart, const TClass *actualClass)
{
if (gDebug>2)
std::cout << "TBufferSQL2::WriteObject of class " << (actualClass ? actualClass->GetName() : " null") << std::endl;
SqlWriteObject(actualObjStart, actualClass);
}
#define SQLReadArrayUncompress(vname, arrsize) \
{ \
while(indx<arrsize) \
SqlReadBasic(vname[indx++]); \
}
#define SQLReadArrayCompress(vname, arrsize) \
{ \
while(indx<arrsize) { \
const char* name = fCurrentData->GetBlobPrefixName(); \
Int_t first, last, res; \
if (strstr(name,sqlio::IndexSepar)==0) { \
res = sscanf(name,"[%d", &first); last = first; \
} else res = sscanf(name,"[%d..%d", &first, &last); \
if (gDebug>5) std::cout << name << " first = " << first << " last = " << last << " res = " << res << std::endl; \
if ((first!=indx) || (last<first) || (last>=arrsize)) { \
Error("SQLReadArrayCompress","Error reading array content %s", name); \
fErrorFlag = 1; \
break; \
} \
SqlReadBasic(vname[indx]); indx++; \
while(indx<=last) \
vname[indx++] = vname[first]; \
} \
}
#define SQLReadArrayContent(vname, arrsize, withsize) \
{ \
if (gDebug>3) std::cout << "SQLReadArrayContent " << (arrsize) << std::endl; \
PushStack()->SetArray(withsize ? arrsize : -1); \
Int_t indx = 0; \
if (fCurrentData->IsBlobData()) \
SQLReadArrayCompress(vname, arrsize) \
else \
SQLReadArrayUncompress(vname, arrsize) \
PopStack(); \
if (gDebug>3) std::cout << "SQLReadArrayContent done " << std::endl; \
}
#define TBufferSQL2_ReadArray(tname, vname) \
{ \
Int_t n = SqlReadArraySize(); \
if (n<=0) return 0; \
if (!vname) vname = new tname[n]; \
SQLReadArrayContent(vname, n, kTRUE); \
return n; \
}
void TBufferSQL2::ReadFloat16 (Float_t *f, TStreamerElement * )
{
SqlReadBasic(*f);
}
void TBufferSQL2::ReadDouble32 (Double_t *d, TStreamerElement * )
{
SqlReadBasic(*d);
}
void TBufferSQL2::ReadWithFactor(Float_t *ptr, Double_t , Double_t )
{
SqlReadBasic(*ptr);
}
void TBufferSQL2::ReadWithNbits(Float_t *ptr, Int_t )
{
SqlReadBasic(*ptr);
}
void TBufferSQL2::ReadWithFactor(Double_t *ptr, Double_t , Double_t )
{
SqlReadBasic(*ptr);
}
void TBufferSQL2::ReadWithNbits(Double_t *ptr, Int_t )
{
SqlReadBasic(*ptr);
}
void TBufferSQL2::WriteFloat16 (Float_t *f, TStreamerElement * )
{
SqlWriteBasic(*f);
}
void TBufferSQL2::WriteDouble32 (Double_t *d, TStreamerElement * )
{
SqlWriteBasic(*d);
}
Int_t TBufferSQL2::ReadArray(Bool_t *&b)
{
TBufferSQL2_ReadArray(Bool_t,b);
}
Int_t TBufferSQL2::ReadArray(Char_t *&c)
{
TBufferSQL2_ReadArray(Char_t,c);
}
Int_t TBufferSQL2::ReadArray(UChar_t *&c)
{
TBufferSQL2_ReadArray(UChar_t,c);
}
Int_t TBufferSQL2::ReadArray(Short_t *&h)
{
TBufferSQL2_ReadArray(Short_t,h);
}
Int_t TBufferSQL2::ReadArray(UShort_t *&h)
{
TBufferSQL2_ReadArray(UShort_t,h);
}
Int_t TBufferSQL2::ReadArray(Int_t *&i)
{
TBufferSQL2_ReadArray(Int_t,i);
}
Int_t TBufferSQL2::ReadArray(UInt_t *&i)
{
TBufferSQL2_ReadArray(UInt_t,i);
}
Int_t TBufferSQL2::ReadArray(Long_t *&l)
{
TBufferSQL2_ReadArray(Long_t,l);
}
Int_t TBufferSQL2::ReadArray(ULong_t *&l)
{
TBufferSQL2_ReadArray(ULong_t,l);
}
Int_t TBufferSQL2::ReadArray(Long64_t *&l)
{
TBufferSQL2_ReadArray(Long64_t,l);
}
Int_t TBufferSQL2::ReadArray(ULong64_t *&l)
{
TBufferSQL2_ReadArray(ULong64_t,l);
}
Int_t TBufferSQL2::ReadArray(Float_t *&f)
{
TBufferSQL2_ReadArray(Float_t,f);
}
Int_t TBufferSQL2::ReadArray(Double_t *&d)
{
TBufferSQL2_ReadArray(Double_t,d);
}
Int_t TBufferSQL2::ReadArrayFloat16(Float_t *&f, TStreamerElement * )
{
TBufferSQL2_ReadArray(Float_t,f);
}
Int_t TBufferSQL2::ReadArrayDouble32(Double_t *&d, TStreamerElement * )
{
TBufferSQL2_ReadArray(Double_t,d);
}
#define TBufferSQL2_ReadStaticArray(vname) \
{ \
Int_t n = SqlReadArraySize(); \
if (n<=0) return 0; \
if (!vname) return 0; \
SQLReadArrayContent(vname, n, kTRUE); \
return n; \
}
Int_t TBufferSQL2::ReadStaticArray(Bool_t *b)
{
TBufferSQL2_ReadStaticArray(b);
}
Int_t TBufferSQL2::ReadStaticArray(Char_t *c)
{
TBufferSQL2_ReadStaticArray(c);
}
Int_t TBufferSQL2::ReadStaticArray(UChar_t *c)
{
TBufferSQL2_ReadStaticArray(c);
}
Int_t TBufferSQL2::ReadStaticArray(Short_t *h)
{
TBufferSQL2_ReadStaticArray(h);
}
Int_t TBufferSQL2::ReadStaticArray(UShort_t *h)
{
TBufferSQL2_ReadStaticArray(h);
}
Int_t TBufferSQL2::ReadStaticArray(Int_t *i)
{
TBufferSQL2_ReadStaticArray(i);
}
Int_t TBufferSQL2::ReadStaticArray(UInt_t *i)
{
TBufferSQL2_ReadStaticArray(i);
}
Int_t TBufferSQL2::ReadStaticArray(Long_t *l)
{
TBufferSQL2_ReadStaticArray(l);
}
Int_t TBufferSQL2::ReadStaticArray(ULong_t *l)
{
TBufferSQL2_ReadStaticArray(l);
}
Int_t TBufferSQL2::ReadStaticArray(Long64_t *l)
{
TBufferSQL2_ReadStaticArray(l);
}
Int_t TBufferSQL2::ReadStaticArray(ULong64_t *l)
{
TBufferSQL2_ReadStaticArray(l);
}
Int_t TBufferSQL2::ReadStaticArray(Float_t *f)
{
TBufferSQL2_ReadStaticArray(f);
}
Int_t TBufferSQL2::ReadStaticArray(Double_t *d)
{
TBufferSQL2_ReadStaticArray(d);
}
Int_t TBufferSQL2::ReadStaticArrayFloat16(Float_t *f, TStreamerElement * )
{
TBufferSQL2_ReadStaticArray(f);
}
Int_t TBufferSQL2::ReadStaticArrayDouble32(Double_t *d, TStreamerElement * )
{
TBufferSQL2_ReadStaticArray(d);
}
#define TBufferSQL2_ReadFastArray(vname) \
{ \
if (n<=0) return; \
TStreamerElement* elem = Stack(0)->GetElement(); \
if ((elem!=0) && (elem->GetType()>TStreamerInfo::kOffsetL) && \
(elem->GetType()<TStreamerInfo::kOffsetP) && \
(elem->GetArrayLength()!=n)) fExpectedChain = kTRUE; \
if (fExpectedChain) { \
fExpectedChain = kFALSE; \
Int_t startnumber = Stack(0)->GetElementNumber(); \
TStreamerInfo* info = Stack(1)->GetStreamerInfo(); \
Int_t number = 0; \
Int_t index = 0; \
while (index<n) { \
elem = info->GetStreamerElementReal(startnumber, number++); \
if (number>1) { PopStack(); WorkWithElement(elem, startnumber); } \
if (elem->GetType()<TStreamerInfo::kOffsetL) { \
SqlReadBasic(vname[index]); \
index++; \
} else { \
Int_t elemlen = elem->GetArrayLength(); \
SQLReadArrayContent((vname+index), elemlen, kFALSE); \
index+=elemlen; \
} \
} \
} else { \
SQLReadArrayContent(vname, n, kFALSE); \
} \
}
void TBufferSQL2::ReadFastArray(Bool_t *b, Int_t n)
{
TBufferSQL2_ReadFastArray(b);
}
void TBufferSQL2::ReadFastArray(Char_t *c, Int_t n)
{
if ((n>0) && fCurrentData->IsBlobData() &&
fCurrentData->VerifyDataType(sqlio::CharStar, kFALSE)) {
const char* buf = SqlReadCharStarValue();
if ((buf==0) || (n<=0)) return;
Int_t size = strlen(buf);
if (size<n) size = n;
memcpy(c, buf, size);
} else {
TBufferSQL2_ReadFastArray(c);
}
}
void TBufferSQL2::ReadFastArray(UChar_t *c, Int_t n)
{
TBufferSQL2_ReadFastArray(c);
}
void TBufferSQL2::ReadFastArray(Short_t *h, Int_t n)
{
TBufferSQL2_ReadFastArray(h);
}
void TBufferSQL2::ReadFastArray(UShort_t *h, Int_t n)
{
TBufferSQL2_ReadFastArray(h);
}
void TBufferSQL2::ReadFastArray(Int_t *i, Int_t n)
{
TBufferSQL2_ReadFastArray(i);
}
void TBufferSQL2::ReadFastArray(UInt_t *i, Int_t n)
{
TBufferSQL2_ReadFastArray(i);
}
void TBufferSQL2::ReadFastArray(Long_t *l, Int_t n)
{
TBufferSQL2_ReadFastArray(l);
}
void TBufferSQL2::ReadFastArray(ULong_t *l, Int_t n)
{
TBufferSQL2_ReadFastArray(l);
}
void TBufferSQL2::ReadFastArray(Long64_t *l, Int_t n)
{
TBufferSQL2_ReadFastArray(l);
}
void TBufferSQL2::ReadFastArray(ULong64_t *l, Int_t n)
{
TBufferSQL2_ReadFastArray(l);
}
void TBufferSQL2::ReadFastArray(Float_t *f, Int_t n)
{
TBufferSQL2_ReadFastArray(f);
}
void TBufferSQL2::ReadFastArray(Double_t *d, Int_t n)
{
TBufferSQL2_ReadFastArray(d);
}
void TBufferSQL2::ReadFastArrayFloat16(Float_t *f, Int_t n, TStreamerElement * )
{
TBufferSQL2_ReadFastArray(f);
}
void TBufferSQL2::ReadFastArrayWithFactor(Float_t *f, Int_t n, Double_t , Double_t )
{
TBufferSQL2_ReadFastArray(f);
}
void TBufferSQL2::ReadFastArrayWithNbits(Float_t *f, Int_t n, Int_t )
{
TBufferSQL2_ReadFastArray(f);
}
void TBufferSQL2::ReadFastArrayDouble32(Double_t *d, Int_t n, TStreamerElement * )
{
TBufferSQL2_ReadFastArray(d);
}
void TBufferSQL2::ReadFastArrayWithFactor(Double_t *d, Int_t n, Double_t , Double_t )
{
TBufferSQL2_ReadFastArray(d);
}
void TBufferSQL2::ReadFastArrayWithNbits(Double_t *d, Int_t n, Int_t )
{
TBufferSQL2_ReadFastArray(d);
}
void TBufferSQL2::ReadFastArray(void *start, const TClass *cl, Int_t n, TMemberStreamer *streamer, const TClass* onFileClass )
{
if (gDebug>2)
Info("ReadFastArray","(void *");
if (streamer) {
StreamObject(start, streamer, cl, 0, onFileClass);
return;
}
int objectSize = cl->Size();
char *obj = (char*)start;
char *end = obj + n*objectSize;
for(; obj<end; obj+=objectSize) {
StreamObject(obj, cl, onFileClass);
}
}
void TBufferSQL2::ReadFastArray(void **start, const TClass *cl, Int_t n, Bool_t isPreAlloc, TMemberStreamer *streamer, const TClass* onFileClass )
{
if (gDebug>2)
Info("ReadFastArray","(void ** pre = %d n = %d", isPreAlloc, n);
if (streamer) {
if (isPreAlloc) {
for (Int_t j=0;j<n;j++) {
if (!start[j]) start[j] = ((TClass*)cl)->New();
}
}
StreamObject((void*)start, streamer, cl, 0, onFileClass);
return;
}
if (!isPreAlloc) {
for (Int_t j=0; j<n; j++){
if (start[j] && TStreamerInfo::CanDelete()) ((TClass*)cl)->Destructor(start[j],kFALSE);
start[j] = ReadObjectAny(cl);
}
} else {
for (Int_t j=0; j<n; j++) {
if (!start[j]) start[j] = ((TClass*)cl)->New();
StreamObject(start[j], cl, onFileClass);
}
}
if (gDebug>2)
Info("ReadFastArray","(void ** Done" );
}
Int_t TBufferSQL2::SqlReadArraySize()
{
const char* value = SqlReadValue(sqlio::Array);
if ((value==0) || (strlen(value)==0)) return 0;
Int_t sz = atoi(value);
return sz;
}
#define SQLWriteArrayNoncompress(vname, arrsize) \
{ \
for(Int_t indx=0;indx<arrsize;indx++) { \
SqlWriteBasic(vname[indx]); \
Stack()->ChildArrayIndex(indx, 1); \
} \
}
#define SQLWriteArrayCompress(vname, arrsize) \
{ \
Int_t indx = 0; \
while(indx<arrsize) { \
Int_t curr = indx; indx++; \
while ((indx<arrsize) && (vname[indx]==vname[curr])) indx++; \
SqlWriteBasic(vname[curr]); \
Stack()->ChildArrayIndex(curr, indx-curr); \
} \
}
#define SQLWriteArrayContent(vname, arrsize, withsize) \
{ \
PushStack()->SetArray(withsize ? arrsize : -1); \
if (fCompressLevel>0) { \
SQLWriteArrayCompress(vname, arrsize) \
} else { \
SQLWriteArrayNoncompress(vname, arrsize) \
} \
PopStack(); \
}
#define TBufferSQL2_WriteArray(vname) \
{ \
SQLWriteArrayContent(vname, n, kTRUE); \
}
void TBufferSQL2::WriteArray(const Bool_t *b, Int_t n)
{
TBufferSQL2_WriteArray(b);
}
void TBufferSQL2::WriteArray(const Char_t *c, Int_t n)
{
TBufferSQL2_WriteArray(c);
}
void TBufferSQL2::WriteArray(const UChar_t *c, Int_t n)
{
TBufferSQL2_WriteArray(c);
}
void TBufferSQL2::WriteArray(const Short_t *h, Int_t n)
{
TBufferSQL2_WriteArray(h);
}
void TBufferSQL2::WriteArray(const UShort_t *h, Int_t n)
{
TBufferSQL2_WriteArray(h);
}
void TBufferSQL2::WriteArray(const Int_t *i, Int_t n)
{
TBufferSQL2_WriteArray(i);
}
void TBufferSQL2::WriteArray(const UInt_t *i, Int_t n)
{
TBufferSQL2_WriteArray(i);
}
void TBufferSQL2::WriteArray(const Long_t *l, Int_t n)
{
TBufferSQL2_WriteArray(l);
}
void TBufferSQL2::WriteArray(const ULong_t *l, Int_t n)
{
TBufferSQL2_WriteArray(l);
}
void TBufferSQL2::WriteArray(const Long64_t *l, Int_t n)
{
TBufferSQL2_WriteArray(l);
}
void TBufferSQL2::WriteArray(const ULong64_t *l, Int_t n)
{
TBufferSQL2_WriteArray(l);
}
void TBufferSQL2::WriteArray(const Float_t *f, Int_t n)
{
TBufferSQL2_WriteArray(f);
}
void TBufferSQL2::WriteArray(const Double_t *d, Int_t n)
{
TBufferSQL2_WriteArray(d);
}
void TBufferSQL2::WriteArrayFloat16(const Float_t *f, Int_t n, TStreamerElement * )
{
TBufferSQL2_WriteArray(f);
}
void TBufferSQL2::WriteArrayDouble32(const Double_t *d, Int_t n, TStreamerElement * )
{
TBufferSQL2_WriteArray(d);
}
#define TBufferSQL2_WriteFastArray(vname) \
{ \
if (n<=0) return; \
TStreamerElement* elem = Stack(0)->GetElement(); \
if ((elem!=0) && (elem->GetType()>TStreamerInfo::kOffsetL) && \
(elem->GetType()<TStreamerInfo::kOffsetP) && \
(elem->GetArrayLength()!=n)) fExpectedChain = kTRUE; \
if (fExpectedChain) { \
TStreamerInfo* info = Stack(1)->GetStreamerInfo(); \
Int_t startnumber = Stack(0)->GetElementNumber(); \
Int_t number = 0; \
Int_t index = 0; \
while (index<n) { \
elem = info->GetStreamerElementReal(startnumber, number++); \
if (number>1) { PopStack(); WorkWithElement(elem, startnumber + number); } \
if (elem->GetType()<TStreamerInfo::kOffsetL) { \
SqlWriteBasic(vname[index]); \
index++; \
} else { \
Int_t elemlen = elem->GetArrayLength(); \
SQLWriteArrayContent((vname+index), elemlen, kFALSE); \
index+=elemlen; \
} \
fExpectedChain = kFALSE; \
} \
} else { \
SQLWriteArrayContent(vname, n, kFALSE); \
} \
}
void TBufferSQL2::WriteFastArray(const Bool_t *b, Int_t n)
{
TBufferSQL2_WriteFastArray(b);
}
void TBufferSQL2::WriteFastArray(const Char_t *c, Int_t n)
{
Bool_t usedefault = (n==0) || fExpectedChain;
const Char_t* ccc = c;
if (!usedefault)
for (int i=0;i<n;i++)
if (*ccc++==0) { usedefault = kTRUE; break; }
if (usedefault) {
TBufferSQL2_WriteFastArray(c);
} else {
Char_t* buf = new Char_t[n+1];
memcpy(buf, c, n);
buf[n] = 0;
SqlWriteValue(buf, sqlio::CharStar);
delete[] buf;
}
}
void TBufferSQL2::WriteFastArray(const UChar_t *c, Int_t n)
{
TBufferSQL2_WriteFastArray(c);
}
void TBufferSQL2::WriteFastArray(const Short_t *h, Int_t n)
{
TBufferSQL2_WriteFastArray(h);
}
void TBufferSQL2::WriteFastArray(const UShort_t *h, Int_t n)
{
TBufferSQL2_WriteFastArray(h);
}
void TBufferSQL2::WriteFastArray(const Int_t *i, Int_t n)
{
TBufferSQL2_WriteFastArray(i);
}
void TBufferSQL2::WriteFastArray(const UInt_t *i, Int_t n)
{
TBufferSQL2_WriteFastArray(i);
}
void TBufferSQL2::WriteFastArray(const Long_t *l, Int_t n)
{
TBufferSQL2_WriteFastArray(l);
}
void TBufferSQL2::WriteFastArray(const ULong_t *l, Int_t n)
{
TBufferSQL2_WriteFastArray(l);
}
void TBufferSQL2::WriteFastArray(const Long64_t *l, Int_t n)
{
TBufferSQL2_WriteFastArray(l);
}
void TBufferSQL2::WriteFastArray(const ULong64_t *l, Int_t n)
{
TBufferSQL2_WriteFastArray(l);
}
void TBufferSQL2::WriteFastArray(const Float_t *f, Int_t n)
{
TBufferSQL2_WriteFastArray(f);
}
void TBufferSQL2::WriteFastArray(const Double_t *d, Int_t n)
{
TBufferSQL2_WriteFastArray(d);
}
void TBufferSQL2::WriteFastArrayFloat16(const Float_t *f, Int_t n, TStreamerElement * )
{
TBufferSQL2_WriteFastArray(f);
}
void TBufferSQL2::WriteFastArrayDouble32(const Double_t *d, Int_t n, TStreamerElement * )
{
TBufferSQL2_WriteFastArray(d);
}
void TBufferSQL2::WriteFastArray(void *start, const TClass *cl, Int_t n, TMemberStreamer *streamer)
{
if (streamer) {
StreamObject(start, streamer, cl, 0);
return;
}
char *obj = (char*)start;
if (!n) n=1;
int size = cl->Size();
for(Int_t j=0; j<n; j++,obj+=size)
StreamObject(obj, cl);
}
Int_t TBufferSQL2::WriteFastArray(void **start, const TClass *cl, Int_t n, Bool_t isPreAlloc, TMemberStreamer *streamer)
{
if (streamer) {
StreamObject((void*) start, streamer, cl, 0);
return 0;
}
int strInfo = 0;
Int_t res = 0;
if (!isPreAlloc) {
for (Int_t j=0;j<n;j++) {
if (!strInfo && !start[j] ) ForceWriteInfo(((TClass*)cl)->GetStreamerInfo(),kFALSE);
strInfo = 2003;
res |= WriteObjectAny(start[j],cl);
}
} else {
for (Int_t j=0;j<n;j++) {
if (!start[j]) start[j] = ((TClass*)cl)->New();
StreamObject(start[j], cl);
}
}
return res;
}
void TBufferSQL2::StreamObject(void *obj, const type_info &typeinfo, const TClass *onFileClass)
{
StreamObject(obj, TClass::GetClass(typeinfo), onFileClass);
}
void TBufferSQL2::StreamObject(void *obj, const char *className, const TClass *onFileClass)
{
StreamObject(obj, TClass::GetClass(className), onFileClass);
}
void TBufferSQL2::StreamObject(void *obj, const TClass *cl, const TClass *onFileClass)
{
if (gDebug>1)
std::cout << " TBufferSQL2::StreamObject class = " << (cl ? cl->GetName() : "none") << std::endl;
if (IsReading())
SqlReadObject(obj, 0, 0, 0, onFileClass);
else
SqlWriteObject(obj, cl);
}
void TBufferSQL2::StreamObject(TObject *obj)
{
StreamObject(obj, obj ? obj->IsA() : TObject::Class());
}
void TBufferSQL2::StreamObject(void *obj, TMemberStreamer *streamer, const TClass *cl, Int_t n, const TClass *onFileClass)
{
if (streamer==0) return;
if (gDebug>1)
std::cout << "Stream object of class = " << cl->GetName() << std::endl;
if (IsReading())
SqlReadObject(obj, 0, streamer, n, onFileClass);
else
SqlWriteObject(obj, cl, streamer, n);
}
#define TBufferSQL2_operatorin(vname) \
{ \
SqlReadBasic(vname); \
}
void TBufferSQL2::ReadBool(Bool_t &b)
{
TBufferSQL2_operatorin(b);
}
void TBufferSQL2::ReadChar(Char_t &c)
{
TBufferSQL2_operatorin(c);
}
void TBufferSQL2::ReadUChar(UChar_t &c)
{
TBufferSQL2_operatorin(c);
}
void TBufferSQL2::ReadShort(Short_t &h)
{
TBufferSQL2_operatorin(h);
}
void TBufferSQL2::ReadUShort(UShort_t &h)
{
TBufferSQL2_operatorin(h);
}
void TBufferSQL2::ReadInt(Int_t &i)
{
TBufferSQL2_operatorin(i);
}
void TBufferSQL2::ReadUInt(UInt_t &i)
{
TBufferSQL2_operatorin(i);
}
void TBufferSQL2::ReadLong(Long_t &l)
{
TBufferSQL2_operatorin(l);
}
void TBufferSQL2::ReadULong(ULong_t &l)
{
TBufferSQL2_operatorin(l);
}
void TBufferSQL2::ReadLong64(Long64_t &l)
{
TBufferSQL2_operatorin(l);
}
void TBufferSQL2::ReadULong64(ULong64_t &l)
{
TBufferSQL2_operatorin(l);
}
void TBufferSQL2::ReadFloat(Float_t &f)
{
TBufferSQL2_operatorin(f);
}
void TBufferSQL2::ReadDouble(Double_t &d)
{
TBufferSQL2_operatorin(d);
}
void TBufferSQL2::ReadCharP(Char_t *c)
{
const char* buf = SqlReadCharStarValue();
if (buf) strcpy(c, buf);
}
void TBufferSQL2::ReadTString(TString &)
{
printf("ERROR NOT IMPLEMENTED\n");
}
void TBufferSQL2::WriteTString(const TString &)
{
printf("ERROR NOT IMPLEMENTED\n");
}
#define TBufferSQL2_operatorout(vname) \
{ \
SqlWriteBasic(vname); \
}
void TBufferSQL2::WriteBool(Bool_t b)
{
TBufferSQL2_operatorout(b);
}
void TBufferSQL2::WriteChar(Char_t c)
{
TBufferSQL2_operatorout(c);
}
void TBufferSQL2::WriteUChar(UChar_t c)
{
TBufferSQL2_operatorout(c);
}
void TBufferSQL2::WriteShort(Short_t h)
{
TBufferSQL2_operatorout(h);
}
void TBufferSQL2::WriteUShort(UShort_t h)
{
TBufferSQL2_operatorout(h);
}
void TBufferSQL2::WriteInt(Int_t i)
{
TBufferSQL2_operatorout(i);
}
void TBufferSQL2::WriteUInt(UInt_t i)
{
TBufferSQL2_operatorout(i);
}
void TBufferSQL2::WriteLong(Long_t l)
{
TBufferSQL2_operatorout(l);
}
void TBufferSQL2::WriteULong(ULong_t l)
{
TBufferSQL2_operatorout(l);
}
void TBufferSQL2::WriteLong64(Long64_t l)
{
TBufferSQL2_operatorout(l);
}
void TBufferSQL2::WriteULong64(ULong64_t l)
{
TBufferSQL2_operatorout(l);
}
void TBufferSQL2::WriteFloat(Float_t f)
{
TBufferSQL2_operatorout(f);
}
void TBufferSQL2::WriteDouble(Double_t d)
{
TBufferSQL2_operatorout(d);
}
void TBufferSQL2::WriteCharP(const Char_t *c)
{
SqlWriteValue(c, sqlio::CharStar);
}
Bool_t TBufferSQL2::SqlWriteBasic(Char_t value)
{
char buf[50];
snprintf(buf, sizeof(buf), "%d", value);
return SqlWriteValue(buf, sqlio::Char);
}
Bool_t TBufferSQL2::SqlWriteBasic(Short_t value)
{
char buf[50];
snprintf(buf, sizeof(buf), "%hd", value);
return SqlWriteValue(buf, sqlio::Short);
}
Bool_t TBufferSQL2::SqlWriteBasic(Int_t value)
{
char buf[50];
snprintf(buf, sizeof(buf), "%d", value);
return SqlWriteValue(buf, sqlio::Int);
}
Bool_t TBufferSQL2::SqlWriteBasic(Long_t value)
{
char buf[50];
snprintf(buf, sizeof(buf), "%ld", value);
return SqlWriteValue(buf, sqlio::Long);
}
Bool_t TBufferSQL2::SqlWriteBasic(Long64_t value)
{
char buf[50];
snprintf(buf, sizeof(buf), "%lld", value);
return SqlWriteValue(buf, sqlio::Long64);
}
Bool_t TBufferSQL2::SqlWriteBasic(Float_t value)
{
char buf[200];
snprintf(buf, sizeof(buf), TSQLServer::GetFloatFormat(), value);
return SqlWriteValue(buf, sqlio::Float);
}
Bool_t TBufferSQL2::SqlWriteBasic(Double_t value)
{
char buf[128];
snprintf(buf, sizeof(buf), TSQLServer::GetFloatFormat(), value);
return SqlWriteValue(buf, sqlio::Double);
}
Bool_t TBufferSQL2::SqlWriteBasic(Bool_t value)
{
return SqlWriteValue(value ? sqlio::True : sqlio::False, sqlio::Bool);
}
Bool_t TBufferSQL2::SqlWriteBasic(UChar_t value)
{
char buf[50];
snprintf(buf, sizeof(buf), "%u", value);
return SqlWriteValue(buf, sqlio::UChar);
}
Bool_t TBufferSQL2::SqlWriteBasic(UShort_t value)
{
char buf[50];
snprintf(buf, sizeof(buf), "%hu", value);
return SqlWriteValue(buf, sqlio::UShort);
}
Bool_t TBufferSQL2::SqlWriteBasic(UInt_t value)
{
char buf[50];
snprintf(buf, sizeof(buf), "%u", value);
return SqlWriteValue(buf, sqlio::UInt);
}
Bool_t TBufferSQL2::SqlWriteBasic(ULong_t value)
{
char buf[50];
snprintf(buf, sizeof(buf), "%lu", value);
return SqlWriteValue(buf, sqlio::ULong);
}
Bool_t TBufferSQL2::SqlWriteBasic(ULong64_t value)
{
char buf[50];
snprintf(buf, sizeof(buf), FULong64, value);
return SqlWriteValue(buf, sqlio::ULong64);
}
Bool_t TBufferSQL2::SqlWriteValue(const char* value, const char* tname)
{
Stack()->AddValue(value, tname);
return kTRUE;
}
void TBufferSQL2::SqlReadBasic(Char_t& value)
{
const char* res = SqlReadValue(sqlio::Char);
if (res) {
int n;
sscanf(res,"%d", &n);
value = n;
} else
value = 0;
}
void TBufferSQL2::SqlReadBasic(Short_t& value)
{
const char* res = SqlReadValue(sqlio::Short);
if (res)
sscanf(res,"%hd", &value);
else
value = 0;
}
void TBufferSQL2::SqlReadBasic(Int_t& value)
{
const char* res = SqlReadValue(sqlio::Int);
if (res)
sscanf(res,"%d", &value);
else
value = 0;
}
void TBufferSQL2::SqlReadBasic(Long_t& value)
{
const char* res = SqlReadValue(sqlio::Long);
if (res)
sscanf(res,"%ld", &value);
else
value = 0;
}
void TBufferSQL2::SqlReadBasic(Long64_t& value)
{
const char* res = SqlReadValue(sqlio::Long64);
if (res)
sscanf(res, FLong64, &value);
else
value = 0;
}
void TBufferSQL2::SqlReadBasic(Float_t& value)
{
const char* res = SqlReadValue(sqlio::Float);
if (res)
sscanf(res, "%f", &value);
else
value = 0.;
}
void TBufferSQL2::SqlReadBasic(Double_t& value)
{
const char* res = SqlReadValue(sqlio::Double);
if (res)
sscanf(res, "%lf", &value);
else
value = 0.;
}
void TBufferSQL2::SqlReadBasic(Bool_t& value)
{
const char* res = SqlReadValue(sqlio::Bool);
if (res)
value = (strcmp(res, sqlio::True)==0);
else
value = kFALSE;
}
void TBufferSQL2::SqlReadBasic(UChar_t& value)
{
const char* res = SqlReadValue(sqlio::UChar);
if (res) {
unsigned int n;
sscanf(res,"%ud", &n);
value = n;
} else
value = 0;
}
void TBufferSQL2::SqlReadBasic(UShort_t& value)
{
const char* res = SqlReadValue(sqlio::UShort);
if (res)
sscanf(res,"%hud", &value);
else
value = 0;
}
void TBufferSQL2::SqlReadBasic(UInt_t& value)
{
const char* res = SqlReadValue(sqlio::UInt);
if (res)
sscanf(res,"%u", &value);
else
value = 0;
}
void TBufferSQL2::SqlReadBasic(ULong_t& value)
{
const char* res = SqlReadValue(sqlio::ULong);
if (res)
sscanf(res,"%lu", &value);
else
value = 0;
}
void TBufferSQL2::SqlReadBasic(ULong64_t& value)
{
const char* res = SqlReadValue(sqlio::ULong64);
if (res)
sscanf(res, FULong64, &value);
else
value = 0;
}
const char* TBufferSQL2::SqlReadValue(const char* tname)
{
if (fErrorFlag>0) return 0;
if (fCurrentData==0) {
Error("SqlReadValue","No object data to read from");
fErrorFlag = 1;
return 0;
}
if (!fIgnoreVerification)
if (!fCurrentData->VerifyDataType(tname)) {
fErrorFlag = 1;
return 0;
}
fReadBuffer = fCurrentData->GetValue();
fCurrentData->ShiftToNextValue();
if (gDebug>4)
std::cout << " SqlReadValue " << tname << " = " << fReadBuffer << std::endl;
return fReadBuffer.Data();
}
const char* TBufferSQL2::SqlReadCharStarValue()
{
const char* res = SqlReadValue(sqlio::CharStar);
if ((res==0) || (fSQL==0)) return 0;
Long64_t objid = Stack()->DefineObjectId(kTRUE);
Int_t strid = fSQL->IsLongStringCode(objid, res);
if (strid<=0) return res;
fSQL->GetLongString(objid, strid, fReadBuffer);
return fReadBuffer.Data();
}
TSQLStructure* TBufferSQL2::PushStack()
{
TSQLStructure* res = new TSQLStructure;
if (fStk==0) {
fStructure = res;
} else {
fStk->Add(res);
}
fStk = res;
return fStk;
}
TSQLStructure* TBufferSQL2::PopStack()
{
if (fStk==0) return 0;
fStk = fStk->GetParent();
return fStk;
}
TSQLStructure* TBufferSQL2::Stack(Int_t depth)
{
TSQLStructure* curr = fStk;
while ((depth-->0) && (curr!=0)) curr = curr->GetParent();
return curr;
}
void TBufferSQL2::SetFloatFormat(const char* fmt)
{
TSQLServer::SetFloatFormat(fmt);
}
const char* TBufferSQL2::GetFloatFormat()
{
return TSQLServer::GetFloatFormat();
}
Int_t TBufferSQL2::ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *obj)
{
TVirtualStreamerInfo *info = sequence.fStreamerInfo;
IncrementLevel(info);
if (gDebug) {
TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
for(TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
iter != end;
++iter) {
SetStreamerElementNumber((*iter).fConfiguration->fElemId);
(*iter).PrintDebug(*this,obj);
(*iter)(*this,obj);
}
} else {
TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
for(TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
iter != end;
++iter) {
SetStreamerElementNumber((*iter).fConfiguration->fElemId);
(*iter)(*this,obj);
}
}
DecrementLevel(info);
return 0;
}
Int_t TBufferSQL2::ApplySequenceVecPtr(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection, void *end_collection)
{
TVirtualStreamerInfo *info = sequence.fStreamerInfo;
IncrementLevel(info);
if (gDebug) {
TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
for(TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
iter != end;
++iter) {
SetStreamerElementNumber((*iter).fConfiguration->fElemId);
(*iter).PrintDebug(*this,*(char**)start_collection);
(*iter)(*this,start_collection,end_collection);
}
} else {
TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
for(TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
iter != end;
++iter) {
SetStreamerElementNumber((*iter).fConfiguration->fElemId);
(*iter)(*this,start_collection,end_collection);
}
}
DecrementLevel(info);
return 0;
}
Int_t TBufferSQL2::ApplySequence(const TStreamerInfoActions::TActionSequence &sequence, void *start_collection, void *end_collection)
{
TVirtualStreamerInfo *info = sequence.fStreamerInfo;
IncrementLevel(info);
TStreamerInfoActions::TLoopConfiguration *loopconfig = sequence.fLoopConfig;
if (gDebug) {
void *arr0 = loopconfig->GetFirstAddress(start_collection,end_collection);
TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
for(TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
iter != end;
++iter) {
SetStreamerElementNumber((*iter).fConfiguration->fElemId);
(*iter).PrintDebug(*this,arr0);
(*iter)(*this,start_collection,end_collection,loopconfig);
}
} else {
TStreamerInfoActions::ActionContainer_t::const_iterator end = sequence.fActions.end();
for(TStreamerInfoActions::ActionContainer_t::const_iterator iter = sequence.fActions.begin();
iter != end;
++iter) {
SetStreamerElementNumber((*iter).fConfiguration->fElemId);
(*iter)(*this,start_collection,end_collection,loopconfig);
}
}
DecrementLevel(info);
return 0;
}