1 #include "KVSQLROOTFile.h"
14 fObjDB->select_data(
"objTable",
"unique_id",
Form(
"name = '%s'",
name.Data()));
16 while (fObjDB->get_next_result())
17 uuid = get_objTable()[
"unique_id"].get_data<
KVString>();
26 TObject* KVSQLROOTFile::get_object_with_UUID(
const KVString& uuid)
const
30 auto it = fObjList.find(uuid.
Data());
31 if (it != fObjList.end())
return it->second;
32 auto t = fObjStore->Get(uuid);
33 fObjList[uuid.
Data()] = t;
83 if (
OPT.Contains(
"CREATE")) {
89 TString rpath = FP +
"objStore.root";
91 save_working_directory();
92 fObjStore.reset(
new TFile(rpath,
OPT));
93 restore_working_directory();
94 fCurrentROOTFilePath = rpath;
96 TString sqlpath = FP +
"objInfos.sqlite";
99 if (
OPT.Contains(
"CREATE")) {
107 fObjDB->add_table(tmp);
123 fObjStore.reset(
nullptr);
170 if (!fObjDB->has_table(
"objInfos")) {
177 fObjDB->add_table(tmp);
180 fObjDB->add_missing_columns(
"objInfos", infos);
185 save_working_directory();
187 obj->
Write(unique_id);
188 restore_working_directory();
191 fObjDB->prepare_data_insertion(
"objTable");
192 get_objTable()[
"name"] = obj->
GetName();
193 get_objTable()[
"class"] = obj->
ClassName();
194 get_objTable()[
"unique_id"] = unique_id;
195 fObjDB->insert_data_row();
196 fObjDB->end_data_insertion();
198 fObjDB->select_data(
"objTable",
"obj_idx",
Form(
"unique_id='%s'", unique_id.
Data()));
200 while (fObjDB->get_next_result()) obj_idx = get_objTable()[
"obj_idx"].get_data<
int>();
202 fObjDB->prepare_data_insertion(
"objInfos");
204 info_copy.
SetValue(
"obj_idx", obj_idx);
208 fObjDB->insert_data_row();
209 fObjDB->end_data_insertion();
221 return get_object_with_UUID(UUID_for_object(
name));
236 while (!colnames.
End()) {
237 std::cout << colnames.
Next() << tabs;
239 std::cout <<
"\n==========================================================================================\n";
240 if (fObjDB->select_data(
"objTable,objInfos", colnames)) {
241 while (fObjDB->get_next_result()) {
243 while (!colnames.
End()) {
244 auto colname = colnames.
Next();
245 if (colname ==
"name" || colname ==
"class")
246 std::cout << get_objTable()[colname].get_data<
TString>() << tabs;
248 std::cout << get_objInfos()[colname].get_data<
TString>() << tabs;
250 std::cout << std::endl;
254 KVError::Error(
this,
"ls",
"Problem with KVSQLite::database::select_data");
303 fObjDB->select_data(
"objTable,objInfos",
"unique_id", where);
304 while (fObjDB->get_next_result()) {
305 auto uuid = get_objTable()[
"unique_id"].get_data<
KVString>();
306 list->
Add(get_object_with_UUID(uuid));
360 fObjDB->select_data(
"objTable,objInfos",
Form(
"unique_id,%s", numberlist_column.
Data()), where);
361 while (fObjDB->get_next_result()) {
362 KVNumberList nl(get_objInfos()[numberlist_column].get_data<KVString>());
364 auto uuid = get_objTable()[
"unique_id"].get_data<
KVString>();
365 list->
Add(get_object_with_UUID(uuid));
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
void SetValue(const Char_t *name, value_type value)
Strings used to represent a set of ranges of values.
Bool_t Contains(Int_t val) const
returns kTRUE if the value 'val' is contained in the ranges defined by the number list
Combine ROOT file containing objects with SQLite database with info on the objects.
void WriteObject(const TObject *, const KVNameValueList &)
void FillListOfObjectsWithSelection(KVSeqCollection *list, const KVString &where)
TObject * Get(const KVString &name) const
Return pointer to object with given name.
void ls(Option_t *="") const override
List the contents of the file with associated infos.
KVSQLROOTFile(const KVString &filepath, Option_t *option="READ")
Interface to ROOT SQLite database backend.
void primary_key(const TString &cols)
void foreign_key(const TString &child_key, const TString &parent_table, const TString &parent_key)
TString get_column_names(const TString &exclude="", const TString &delim=",") const
column & add_column(const KVSQLite::column &c)
void prepare_data(const KVNameValueList &, const KVNamedParameter *=nullptr)
KaliVeda extensions to ROOT collection classes.
void Add(TObject *obj) override
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
void Begin(TString delim) const
KVString Next(Bool_t strip_whitespace=kFALSE) const
virtual const char * GetName() const
virtual const char * ClassName() const
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
const char * Data() const
TString & Append(char c, Ssiz_t rep=1)
virtual int Chmod(const char *file, UInt_t mode)
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
virtual char * ExpandPathName(const char *path)
virtual int Unlink(const char *name)
const char * AsString() const
void Error(UserClass p, const char *location, const char *va_(fmt),...)