10#include "PackageSql.h"
15#include "Package2HTML.h"
18#include <TCollection.h>
19#include <TDirectory.h>
24#include <TObjString.h>
26#include <TSQLServer.h>
27#include <TSQLStatement.h>
36 void PackageSql::ExportTask(AnaFile* extr, Int_t file_id, Int_t task_id) {
38 TSQLStatement* stat = fSQL->Statement(
"INSERT INTO Files (ID, FILE_ID,TASK_ID, Comment, SoftVer, "
39 "Date,DataType,ProcessedEvents,InputFIle,AnaName,Tags,PathFile) VALUES "
40 "(?,?,?,?,?,?,?,?,?,?,?,?)");
41 Package* metadata = (Package*) extr->GetMainObject(
"HalMetadata");
42 TString comment = metadata->GetComment();
43 ParameterString* anatype = (ParameterString*) metadata->GetObjectByName(
"Analysis Name");
44 ParameterString* data = (ParameterString*) fRunInfo->
GetObjectByName(
"Date");
45 ParameterString* sofwer = (ParameterString*) fRunInfo->
GetObjectByName(
"Software ver");
46 ParameterString* datatype = (ParameterString*) metadata->GetObjectByName(
"DataType");
47 ParameterUInt* processed = (ParameterUInt*) fRunInfo->
GetObjectByName(
"Processed_events");
48 ParameterString* inputfile = (ParameterString*) fRunInfo->
GetObjectByName(
"Input file");
49 TString path = GetPath(fFilename);
50 TList* list = (TList*) metadata->GetObjectByName(
"Tags");
53 for (
int j = 0; j < list->GetEntries(); j++) {
54 tags += ((TObjString*) list->At(j))->GetString();
59 stat->SetInt(1, file_id);
60 stat->SetInt(2, task_id);
61 stat->SetString(3, comment, comment.Length());
62 stat->SetString(4, sofwer->GetValue(), sofwer->GetValue().Length());
63 TString data_s = data->GetValue();
64 std::vector<TString> data_arr = Hal::Std::ExplodeString(data_s,
'-');
65 Int_t year, month, day;
66 year = data_arr[0].Atoi();
67 month = data_arr[1].Atoi();
68 day = data_arr[2].Atoi();
70 stat->SetDate(5, year, month, day);
71 stat->SetString(6, datatype->GetValue(), datatype->GetValue().Length());
72 stat->SetInt(7, processed->GetValue());
73 stat->SetString(8, inputfile->GetValue(), inputfile->GetValue().Length());
74 stat->SetString(9, anatype->GetValue(), anatype->GetValue().Length());
75 stat->SetString(10, tags, tags.Length());
76 stat->SetString(11, path, path.Length());
83 TString www_path = Hal::Std::GetConfigParameter(
"www_path");
84 if (www_path.Length() <= 0) {
85 Cout::PrintInfo(
"www_path not found in hal configruration file!", Hal::EInfo::kError);
88 TString datafile = Form(
"sqlite://%s/database.sqlite", www_path.Data());
89 TString user = Hal::Std::GetConfigParameter(
"www_path/database_user");
90 TString pass = Hal::Std::GetConfigParameter(
"www_path/database_password");
91 if (user.Length() == 0) { user =
"user"; }
92 if (pass.Length() == 0) { pass =
"password"; }
94 TString outPath = Form(
"%s/database.sqlite", www_path.Data());
95 std::ifstream f(outPath);
99 fSQL = TSQLServer::Connect(datafile, user, pass);
101 TString workdir = Hal::Std::GetHalrootPlus();
103 gSystem->MakeDirectory(www_path.Data());
104 gSystem->MakeDirectory(Form(
"%s/html_rep/", www_path.Data()));
105 gSystem->CopyFile(Form(
"%s/html/database.sqlite", workdir.Data()), Form(
"%s/database.sqlite", www_path.Data()));
106 gSystem->CopyFile(Form(
"%s/html/logo_search.gif", workdir.Data()), Form(
"%s/logo_search.gif", www_path.Data()));
107 gSystem->CopyFile(Form(
"%s/html/index.php", workdir.Data()), Form(
"%s/index.php", www_path.Data()));
108 gSystem->CopyFile(Form(
"%s/html/functions.php", workdir.Data()), Form(
"%s/functions.php", www_path.Data()));
109 gSystem->CopyFile(Form(
"%s/html/table.css", workdir.Data()), Form(
"%s/table.css", www_path.Data()));
110 gSystem->CopyFile(Form(
"%s/html/search_template.css", workdir.Data()), Form(
"%s/search_template.css", www_path.Data()));
113 fSQL = TSQLServer::Connect(datafile, user, pass);
117 TSQLStatement* stat = (TSQLStatement*) fSQL->Statement(
"SELECT COUNT(ID) FROM Files");
119 fID = stat->GetInt(0);
121 stat = (TSQLStatement*) fSQL->Statement(
"SELECT MAX(FILE_ID) FROM Files");
123 Int_t file_id = stat->GetInt(0) + 1;
126 TFile* file =
new TFile(filename);
127 TDirectory* dir = (TDirectory*) file->Get(
"HalPhysics");
128 TList* keys = dir->GetListOfKeys();
132 for (
int i = 0; i < keys->GetEntries(); i++) {
134 TKey* key = (TKey*) keys->At(i);
135 TString key_name = key->GetName();
137 if (pack == NULL)
continue;
140 ExportTask(extr, file_id, i);
144 HtmlCore::ResetMainDir();
148 PackageSql::~PackageSql() {}
150 TString PackageSql::RemoveDir(TString path) {
152 TString tmp = path(reg);
153 TString res(tmp(0, tmp.Length() - 1));
157 TString PackageSql::RemoveDoubleDot(TString path) {
158 TString res(path(3, path.Length() - 3));
162 Bool_t PackageSql::HasDir(TString path) {
163 if (path.BeginsWith(
"../")) {
170 TString PackageSql::GetPath(TString filename) {
171 TString pwd = gSystem->Getenv(
"PWD");
173 if (HasDir(filename)) {
174 filename = RemoveDoubleDot(filename);
175 pwd = RemoveDir(pwd);
182 path = path + filename;
Package * GetPackage(TString name) const
Package * GetMetaData() const
Bool_t SwitchPackage(TString name)
static void PrintInfo(TString text, Hal::EInfo status)
static void CopyCss(TString dir, TString css_name="table.css")
static void SetMainDir(TString name)
static void CopyJs(TString dir)
static HtmlCore * Instance()
PackageSql(TString filename)
TObject * GetObjectByName(TString name, Int_t index=0, Bool_t quited=kFALSE) const