12#include <TObjString.h>
24#include "Package2HTML.h"
29 HtmlCore* HtmlCore::fgInstance = NULL;
30 TString HtmlCore::fMainDir =
"";
31 Bool_t HtmlCore::fgOnline = kFALSE;
34 TString workdir = Hal::Std::GetHalrootPlus();
35 TString filetocopy = Form(
"%s/html/%s", workdir.Data(), css_name.Data());
36 TString outPath = Form(
"%s/table.css", path.Data());
37 if (path.Length() == 0) outPath =
"table.css";
38 gSystem->CopyFile(filetocopy, outPath, kTRUE);
42 TString workdir = Hal::Std::GetHalrootPlus();
43 TString filetocopy = Form(
"%s/html/hal_js.js", workdir.Data());
44 if (path.Length() != 0) {
45 gSystem->CopyFile(filetocopy, Form(
"%s/hal_js.js", path.Data()), kTRUE);
47 gSystem->CopyFile(filetocopy,
"hal_js.js", kTRUE);
51 filetocopy = Hal::Std::GetJsRoot();
52 if (path.Length() != 0) {
53 gSystem->mkdir(Form(
"%s/hal_js", path.Data()));
54 gSystem->mkdir(Form(
"%s/hal_js/img", path.Data()));
55 gSystem->mkdir(Form(
"%s/hal_js/scripts", path.Data()));
56 gSystem->mkdir(Form(
"%s/hal_js/style", path.Data()));
57 Hal::Std::CopyFiles(Form(
"%s/img", filetocopy.Data()), Form(
"%s/hal_js/img", path.Data()), kFALSE);
58 Hal::Std::CopyFiles(Form(
"%s/scripts", filetocopy.Data()), Form(
"%s/hal_js/scripts", path.Data()), kFALSE);
59 Hal::Std::CopyFiles(Form(
"%s/style", filetocopy.Data()), Form(
"%s/hal_js/style", path.Data()), kFALSE);
61 gSystem->mkdir(
"hal_js");
62 gSystem->mkdir(
"hal_js/img");
63 gSystem->mkdir(
"hal_js/scripts");
64 gSystem->mkdir(
"hal_js/style");
65 Hal::Std::CopyFiles(Form(
"%s/img", filetocopy.Data()),
"hal_js/img", kFALSE);
66 Hal::Std::CopyFiles(Form(
"%s/scripts", filetocopy.Data()),
"hal_js/scripts", kFALSE);
67 Hal::Std::CopyFiles(Form(
"%s/style", filetocopy.Data()),
"hal_js/style", kFALSE);
72 if (fgInstance != NULL) {
82 if (fgInstance != NULL) {
90 if (name.Length() == 0) {
Cout::PrintInfo(
"SetMainDir as null", Hal::EInfo::kLowWarning); }
102 address.ReplaceAll(
"//",
"/");
103 if (address.EndsWith(
".js") || address.EndsWith(
".html") || address.EndsWith(
".htm"))
return;
104 if (address.Length() > 0) {
105 if (!address.EndsWith(
"/")) { address = address +
"/"; }
164 TString
HtmlCore::GetUrl(TString adress, TString text) {
return Form(
"<a href=\"%s\">%s</a>", adress.Data(), text.Data()); }
167 TString url =
"<img border=\"0\" ";
168 if (width > 0) { url = url + Form(
"width=\"%i\" ", width); }
169 if (height > 0) { url = url + Form(
"height=\"%i\" ", height); }
170 for (
int i = 0; i < strings->GetEntries(); i++) {
171 TObjString* current_name = (TObjString*) strings->UncheckedAt(i);
172 TString capt = current_name->String();
174 url = url + Form(
"src=\"%s\" ", capt.Data());
175 url = url + Form(
"id=\"%s\" onclick=\"changeImage('%s',['%s'", id_name.Data(), id_name.Data(), capt.Data());
177 url = url + Form(
",'%s'", capt.Data());
180 url = url +
"])\" />";
186 if (path.EqualTo(fMainDir)) {
return ""; }
187 TString relative_path =
"";
188 TString temp = path(fMainDir.Length(), path.Length() - fMainDir.Length());
190 if (temp.EndsWith(
"/")) { temp.Remove(temp.Length() - 1); }
192 std::vector<TString> vec = Hal::Std::ExplodeString(temp,
'/');
194 if (vec.size() == 0)
return "";
195 for (
unsigned int i = 0; i < vec.size() - 1; i++) {
196 relative_path = relative_path +
"../";
198 if (temp.Length() != 0) { relative_path = relative_path +
"../"; }
199 return relative_path;
203 if (text.Contains(
"\n")) {
205 return Form(
"<pre>%s</pre>", text.Data());
210 TString HtmlCore::GetLastDir(TString name, Int_t i) {
211 if (name.EndsWith(
"/")) name = name(0, name.Length() - 1);
214 for (
int j = name.Length() - 1; j >= 0; j--) {
215 if (name[j] ==
'/') {
219 if (count == i)
break;
221 name = name(cut_pos + 1, name.Length());
222 if (name.Length() > 0) name = name +
"/";
226 TString
HtmlCore::GetJsDiv(TString root_file, TString object_name, TString draw_opt, TString draw_div_name) {
228 if (Hal::Std::GetJsRootVer() == 5) {
229 res =
"<script type='text/javascript'>\n";
230 res = res + Form(
"var filename = \"%s\";\n", root_file.Data());
231 res = res +
" JSROOT.OpenFile(filename, function(file) {\n";
232 res = res +
" JSROOT.gStyle.Palette= 50;\n";
233 res = res + Form(
"file.ReadObject(\"%s\", function(obj) {\n", object_name.Data());
234 res = res + Form(
"JSROOT.draw(\"%s\", obj, \"%s\");\n;", draw_div_name.Data(), draw_opt.Data());
235 res = res +
"});\n;});\n";
236 res = res +
"</script>\n<div id=\"" + draw_div_name +
"\" style=\"width:90%;height:900px\"></div>\n";
238 res =
"<script type='module'>\n";
239 res = res + Form(
"var filename = \"%s\";\n", root_file.Data());
240 res = res +
"JSROOT.settings.Palette= 50;\n";
241 res = res +
"JSROOT.openFile(filename)\n";
242 res = res +
"\t.then(file=> file.readObject(\"" + object_name +
"\"))\n";
243 res = res +
"\t.then(obj=> JSROOT.draw(\"" + draw_div_name.Data() +
"\",obj,\"" + draw_opt.Data() +
"\"));\n";
244 res = res +
"</script>\n<div id=\"" + draw_div_name +
"\" style=\"width:90%;height:900px\"></div>\n";
250 return Form(
"<button onclick=\"setTable('%s')\">%s</button>", tableName.Data(), text.Data());
254 return Form(
"<button onclick=\"setRow('%s')\">%s</button>", listName.Data(), text.Data());
258 TString drawOpt =
"";
259 if (h->InheritsFrom(
"TH3")) {
261 }
else if (h->InheritsFrom(
"TH2")) {
264 Bool_t batch = gROOT->IsBatch();
265 gROOT->SetBatch(kTRUE);
266 path = Form(
"%s/th_%i", path.Data(), no);
267 gSystem->mkdir(path);
268 TCanvas* c1 =
new TCanvas(
"canvas",
"canvas", 0, 0, 800, 600);
269 TH1* histo = (TH1*) h;
270 histo->Draw(drawOpt);
271 c1->SaveAs(Form(
"%s/histo.root", path.Data()));
273 gROOT->SetBatch(batch);
274 HtmlFile file(Form(
"%s/histo.html", path.Data()), kFALSE);
277 TString filename = Form(
"%s/histo.html", path.Data());
278 gROOT->SetBatch(batch);
283 TString className = obj->ClassName();
284 if (className.EqualTo(
"TObjString")) {
return static_cast<TObjString*
>(obj)->GetString(); }
285 if (className.EqualTo(
"TVector2")) {
return GetLinkVector(
static_cast<TVector2*
>(obj)); }
286 if (className.EqualTo(
"Hal::Package")) {
291 if (obj->InheritsFrom(
"Hal::Object")) {
return static_cast<Object*
>(obj)->
HTMLExtract(no, dir); }
292 if (obj->InheritsFrom(
"TList")) {
return GetLinkList(
static_cast<TList*
>(obj), no, dir); };
293 if (obj->InheritsFrom(
"TH1")) {
return GetLinkTH1(
static_cast<TH1*
>(obj), no, dir); }
294 if (obj->InheritsFrom(
"TGraph")) {
return GetLinkGraph(
static_cast<TGraph*
>(obj), no, dir); };
298 TString HtmlCore::GetLinkVector(TVector2* vect) {
299 TString stringA = Hal::Std::RoundToString(vect->Px(), 1);
300 TString stringB = Hal::Std::RoundToString(vect->Py(), 1);
301 stringA = stringA +
" ";
302 return stringA + stringB;
305 TString HtmlCore::GetLinkTH1(TH1* h1, Int_t no, TString path) {
306 while (path.Contains(
"//")) {
307 path.ReplaceAll(
"//",
"/");
309 TString rootFileName =
"histo1d.root";
311 TString pattern =
"th1";
312 if (h1->InheritsFrom(
"TH2")) {
313 rootFileName =
"histo2d.root";
317 if (h1->InheritsFrom(
"TH3")) {
318 rootFileName =
"histo3d.root";
322 Bool_t batch = gROOT->IsBatch();
323 gROOT->SetBatch(kTRUE);
324 path = Form(
"%s/%s_%i", path.Data(), pattern.Data(), no);
325 gSystem->mkdir(path);
326 TCanvas* c1 =
new TCanvas(
"canvas",
"canvas", 0, 0, 800, 600);
327 TH1* histo = (TH1*) h1;
329 c1->SaveAs(Form(
"%s/%s", path.Data(), rootFileName.Data()));
331 gROOT->SetBatch(batch);
332 HtmlFile file(Form(
"%s/histo.html", path.Data()), kFALSE);
335 TString filename = Form(
"%s/histo.html", path.Data());
336 gROOT->SetBatch(batch);
337 return HtmlCore::GetUrl(Form(
"%s_%i/histo.html", pattern.Data(), no), h1->ClassName());
340 TString HtmlCore::GetLinkGraph(TGraph* h, Int_t no, TString path) {
341 TString classname = h->ClassName();
342 Bool_t batch = gROOT->IsBatch();
343 gROOT->SetBatch(kTRUE);
344 path = Form(
"%s/graph_%i", path.Data(), no);
345 gSystem->mkdir(path);
346 TCanvas* c1 =
new TCanvas(
"canvas",
"canvas", 0, 0, 800, 600);
348 c1->SaveAs(Form(
"%s/graph.root", path.Data()));
350 HtmlFile F(Form(
"%s/graph.html", path.Data()), kFALSE);
353 gROOT->SetBatch(batch);
357 TString HtmlCore::GetLinkList(TList* list, Int_t no, TString path) {
358 TString filename = Form(
"%s/list_%i/list.html", path.Data(), no);
359 TString linkname = Form(
"list_%i.html", no);
360 HtmlFile file(filename, kFALSE);
361 file.AddStringContent(Form(
"<h1>Name %s </h1>", list->GetName()));
362 file.AddStringContent(
"<div id=\"main_table\">");
363 HtmlTable table(
"",
"haltable",
"");
364 HtmlRow row(
"", Hal::HtmlTableRowClass::TitleStyle(),
"");
365 row.AddContent(HtmlCell(
"No"));
366 row.AddContent(HtmlCell(
"ClassName"));
367 row.AddContent(HtmlCell(
"Value"));
368 row.AddContent(HtmlCell(
"Name"));
369 table.AddContent(row);
370 TString list_dir = Form(
"list_%i/", no);
371 path = Form(
"%s/list_%i/", path.Data(), no);
372 auto addToUrl = [](TString add_dir, TString url) {
373 if (!url.Contains(
"href")) {
return url; }
374 Int_t start_url = url.First(
"=") + 2;
375 TString first = url(0, start_url);
376 TString end = url(start_url, url.Length());
377 TString output = Form(
"%s%s%s", first.Data(), add_dir.Data(), end.Data());
378 output.ReplaceAll(
"//",
"/");
381 for (
int i = 0; i < list->GetEntries(); i++) {
382 TObject*
object = list->At(i);
383 TString name =
object->ClassName();
384 TString oryginal_class =
object->GetName();
385 HtmlRow row2(
"", Hal::HtmlTableRowClass::DefStyle(),
"");
386 table.AddContent(HtmlCell(Hal::Std::RoundToString(i)));
387 table.AddContent(HtmlCell(object->ClassName()));
389 table.AddContent(HtmlCell(addToUrl(list_dir,
HTMLExtract(
object, i, path))));
390 if (name ==
"Hal::Package") {
391 oryginal_class = ((Package*)
object)->GetName();
392 oryginal_class = Form(
"%s </br> [%s]", object->ClassName(), oryginal_class.Data());
393 table.AddContent(HtmlCell(oryginal_class));
395 table.AddContent(HtmlCell(object->GetName()));
397 table.AddContent(row2);
399 file.AddContent(table);
static void PrintInfo(TString text, Hal::EInfo status)
static TString GetUrl(TString adress, TString text)
static void HTMLExtractIntoTable(TObject *obj, Int_t no, HtmlTable &table, TString dir="", TString rel_dir="")
static TString GetRelativePath(TString path)
static void CopyCss(TString dir, TString css_name="table.css")
static void SetMainDirAndExtract(TString name)
static TString GetHideButtonTable(TString tableName, TString text)
static void SetMainDir(TString name)
static TString ClickablePic(TString id_name, TObjArray *strings, Int_t width=796, Int_t height=572)
static TString GetJsDiv(TString root_file, TString object_name, TString draw_opt="colz", TString draw_div_name="drawing")
static TString HTMLExtract(TObject *obj, Int_t no, TString dir="")
static void FixAddress(TString &address)
static void CopyJs(TString dir)
static TString GetHideButtonRow(TString listName, TString text)
virtual Bool_t CanBeTableElement(TObject *obj)
static TString GetLinkToHistogram(TH1 *h, Int_t no, TString path)
static HtmlCore * Instance()
static TString CheckBr(TString text)