38 TKeySQL::TKeySQL(TDirectory *mother,
const TObject *obj,
const char *name,
const char *title)
44 SetName(obj->GetName());
45 fClassName = obj->ClassName();
52 StoreKeyObject((
void *)obj, obj ? obj->IsA() : 0);
58 TKeySQL::TKeySQL(TDirectory *mother,
const void *obj,
const TClass *cl,
const char *name,
const char *title)
64 SetName(cl ? cl->GetName() :
"Noname");
69 StoreKeyObject(obj, cl);
75 TKeySQL::TKeySQL(TDirectory *mother, Long64_t keyid, Long64_t objid,
const char *name,
const char *title,
76 const char *keydatetime, Int_t cycle,
const char *classname)
77 : TKey(mother), fKeyId(keyid), fObjId(objid)
82 TDatime dt(keydatetime);
85 fClassName = classname;
93 Bool_t TKeySQL::IsKeyModified(
const char *keyname,
const char *keytitle,
const char *keydatime, Int_t cycle,
94 const char *classname)
96 Int_t len1 = (GetName() == 0) ? 0 : strlen(GetName());
97 Int_t len2 = (keyname == 0) ? 0 : strlen(keyname);
100 if ((len1 > 0) && (strcmp(GetName(), keyname) != 0))
103 len1 = (GetTitle() == 0) ? 0 : strlen(GetTitle());
104 len2 = (keytitle == 0) ? 0 : strlen(keytitle);
107 if ((len1 > 0) && (strcmp(GetTitle(), keytitle) != 0))
110 const char *tm = GetDatime().AsSQLString();
111 len1 = (tm == 0) ? 0 : strlen(tm);
112 len2 = (keydatime == 0) ? 0 : strlen(keydatime);
115 if ((len1 > 0) && (strcmp(tm, keydatime) != 0))
118 if (cycle != GetCycle())
121 len1 = (GetClassName() == 0) ? 0 : strlen(GetClassName());
122 len2 = (classname == 0) ? 0 : strlen(classname);
125 if ((len1 > 0) && (strcmp(GetClassName(), classname) != 0))
135 void TKeySQL::Delete(Option_t * )
137 TSQLFile *f = (TSQLFile *)GetFile();
140 f->DeleteKeyFromDB(GetDBKeyId());
142 fMotherDir->GetListOfKeys()->Remove(
this);
148 Long64_t TKeySQL::GetDBDirId()
const
150 return GetMotherDir() ? GetMotherDir()->GetSeekDir() : 0;
156 void TKeySQL::StoreKeyObject(
const void *obj,
const TClass *cl)
158 TSQLFile *f = (TSQLFile *)GetFile();
160 fCycle = GetMotherDir()->AppendKey(
this);
162 fKeyId = f->DefineNextKeyId();
164 fObjId = f->StoreObjectInTables(fKeyId, obj, cl);
167 fClassName = cl->GetName();
169 if (GetDBObjId() >= 0) {
171 if (!f->WriteKeyData(
this)) {
173 Error(
"StoreKeyObject",
"Cannot write data to key tables");
175 f->DeleteKeyFromDB(GetDBKeyId());
180 if (GetDBObjId() < 0)
181 GetMotherDir()->GetListOfKeys()->Remove(
this);
190 Int_t TKeySQL::Read(TObject *tobj)
195 void *res = ReadKeyObject(tobj, 0);
197 return res == 0 ? 0 : 1;
204 TObject *TKeySQL::ReadObj()
206 TObject *tobj = (TObject *)ReadKeyObject(0, TObject::Class());
209 if (gROOT->GetForceStyle())
210 tobj->UseCurrentStyle();
211 if (tobj->IsA() == TDirectoryFile::Class()) {
212 TDirectoryFile *dir = (TDirectoryFile *)tobj;
213 dir->SetName(GetName());
214 dir->SetTitle(GetTitle());
215 dir->SetSeekDir(GetDBKeyId());
216 dir->SetMother(fMotherDir);
218 fMotherDir->Append(dir);
229 TObject *TKeySQL::ReadObjWithBuffer(
char * )
231 TObject *tobj = (TObject *)ReadKeyObject(0, TObject::Class());
234 if (gROOT->GetForceStyle())
235 tobj->UseCurrentStyle();
236 if (tobj->IsA() == TDirectoryFile::Class()) {
237 TDirectoryFile *dir = (TDirectoryFile *)tobj;
238 dir->SetName(GetName());
239 dir->SetTitle(GetTitle());
240 dir->SetSeekDir(GetDBKeyId());
241 dir->SetMother(fMotherDir);
243 fMotherDir->Append(dir);
253 void *TKeySQL::ReadObjectAny(
const TClass *expectedClass)
255 void *res = ReadKeyObject(0, expectedClass);
257 if (res && (expectedClass == TDirectoryFile::Class())) {
258 TDirectoryFile *dir = (TDirectoryFile *)res;
259 dir->SetName(GetName());
260 dir->SetTitle(GetTitle());
261 dir->SetSeekDir(GetDBKeyId());
262 dir->SetMother(fMotherDir);
264 fMotherDir->Append(dir);
273 void *TKeySQL::ReadKeyObject(
void *obj,
const TClass *expectedClass)
275 TSQLFile *f = (TSQLFile *)GetFile();
277 if ((GetDBKeyId() <= 0) || !f)
280 TBufferSQL2 buffer(TBuffer::kRead, f);
284 TClass *cl =
nullptr;
286 void *res = buffer.SqlReadAny(GetDBKeyId(), GetDBObjId(), &cl, obj);
293 if (expectedClass != 0) {
294 delta = cl->GetBaseClassOffset(expectedClass);
300 if (cl->GetState() > TClass::kEmulated && expectedClass->GetState() <= TClass::kEmulated) {
302 Warning(
"XmlReadAny",
"Trying to read an emulated class (%s) to store in a compiled pointer (%s)",
303 cl->GetName(), expectedClass->GetName());
307 return ((
char *)res) + delta;