1 #ifndef RestCore_TRestDataBase
2 #define RestCore_TRestDataBase
8 #include "TRestTools.h"
25 DBEntry(
int _runNr = 0, std::string _type =
"", std::string _tag =
"", std::string _description =
"",
26 std::string _version =
"") {
30 description = _description;
33 DBEntry(std::vector<std::string> defs);
35 std::string type =
"";
37 std::string user =
"";
38 std::string description =
"";
39 std::string version =
"";
43 std::string value =
"";
45 bool IsZombie() {
return runNr == 0 || (type ==
"" && value ==
""); }
53 for (
int i = 0; i < 41; i++) {
61 DBFile(std::string filename) { this->filename = filename; }
62 static DBFile ParseFile(std::string filename);
65 operator std::string() {
return filename; }
76 struct DBTable :
public std::vector<std::vector<std::string>> {
77 std::vector<std::string> headerline;
78 int rows() {
return size(); }
79 int columns() {
return headerline.size(); }
84 std::vector<DBEntry> fDataEntries;
85 std::string fConnectionString;
98 virtual void print(std::string cmd) {}
100 virtual DBTable
exec(std::string cmd) {
return DBTable(); }
104 virtual DBEntry
query_run(
int runnumber) {
return DBEntry(runnumber); }
108 virtual std::vector<DBFile>
query_run_files(
int runnumber) {
return std::vector<DBFile>(); }
111 virtual std::vector<int>
search_run(DBEntry info) {
return std::vector<int>{0}; }
119 virtual int set_run(DBEntry info,
bool overwrite =
true);
121 virtual int set_runfile(
int runnumber, std::string filename) {
return 0; }
127 virtual int set_data(DBEntry info,
bool overwrite =
true) {
return 0; }
virtual void Initialize()
default: read the dataURL file
TRestDataBase()
default constructor, setting fConnectionString according to the env
virtual void print(std::string cmd)
print the table after query std::string cmd
virtual std::vector< int > search_run_with_file(std::string filepattern)
search runs according to the file name. return a list of run numbers
virtual int get_lastrun()
get the latest run id in database
virtual DBEntry query_data(DBEntry info)
virtual void test()
test function
virtual DBFile query_run_file(int runnumber, int fileid)
return file of certain file id in certain run
~TRestDataBase()
destructor
virtual std::vector< DBFile > query_run_files(int runnumber)
return all the files of the run
virtual int set_run(DBEntry info, bool overwrite=true)
add/update a run, with run info as struct DBEntry. returns the added run id
virtual std::vector< int > search_run(DBEntry info)
search runs according to the run info. return a list of run numbers
virtual DBTable exec(std::string cmd)
return a table from query std::string cmd
virtual int set_runfile(int runnumber, std::string filename)
add/update a runfile to the specified run
virtual DBEntry query_run(int runnumber)
virtual int set_data(DBEntry info, bool overwrite=true)
add/update a new record of metadata in database