10#include "QAPlotReport.h"
30 QAPlotReport::QAPlotReport() :
31 fExtraInfo(nullptr), fOriginName(
"OriginName",
""), f1dHistos(nullptr), f2dHistos(nullptr), f3dHistos(nullptr) {}
33 QAPlotReport::~QAPlotReport() {
34 if (f1dHistos)
delete f1dHistos;
35 if (f2dHistos)
delete f2dHistos;
36 if (f3dHistos)
delete f3dHistos;
37 if (fExtraInfo)
delete fExtraInfo;
40 QAPlotReport::QAPlotReport(
const QAPlotReport& other) :
42 f1dFlags(other.f1dFlags),
43 f2dFlags(other.f2dFlags),
44 f3dFlags(other.f3dFlags),
49 fOriginName = other.fOriginName;
50 if (other.f1dHistos) f1dHistos =
new HistogramManager_1_1D<TH1D>(*other.f1dHistos);
51 if (other.f2dHistos) f2dHistos =
new HistogramManager_1_2D<TH2D>(*other.f2dHistos);
52 if (other.f3dHistos) f3dHistos =
new HistogramManager_1_3D<TH3D>(*other.f3dHistos);
53 if (other.fExtraInfo) { fExtraInfo = (Object*) other.fExtraInfo->Clone(); }
56 QAPlotReport& QAPlotReport::operator=(
const QAPlotReport& other) {
57 if (
this == &other)
return *
this;
75 Object::operator=(other);
76 fOriginName = other.fOriginName;
77 if (other.f1dHistos) f1dHistos =
new HistogramManager_1_1D<TH1D>(*other.f1dHistos);
78 if (other.f2dHistos) f2dHistos =
new HistogramManager_1_2D<TH2D>(*other.f2dHistos);
79 if (other.f3dHistos) f3dHistos =
new HistogramManager_1_3D<TH3D>(*other.f3dHistos);
80 f1dFlags = other.f1dFlags;
81 f2dFlags = other.f2dFlags;
82 f3dFlags = other.f3dFlags;
83 if (other.fExtraInfo) { fExtraInfo = (Object*) other.fExtraInfo->Clone(); }
87 void QAPlotReport::TranslateFlag(TString flag, Int_t& hist1, Int_t& hist2, Char_t& op)
const {
88 if (flag.Contains(
"/")) { op =
'/'; }
89 if (flag.Contains(
"+")) { op =
'+'; }
90 if (flag.Contains(
"-")) { op =
'-'; }
91 std::vector<TString> arr = Hal::Std::ExplodeString(flag, op);
92 hist1 = arr[0].Atoi();
93 hist2 = arr[1].Atoi();
96 void QAPlotReport::Operate(TH1* h0, TH1* h1, TH1* h2, Char_t op)
const {
97 TString name = h0->GetName();
98 TString title = h0->GetTitle();
99 TString xAxis = h0->GetXaxis()->GetTitle();
100 TString yAxis = h0->GetYaxis()->GetTitle();
101 TString zAxis = h0->GetXaxis()->GetTitle();
105 if (xAxis.Length() > 0) h0->GetXaxis()->SetTitle(xAxis);
106 if (yAxis.Length() > 0) h0->GetYaxis()->SetTitle(yAxis);
107 if (zAxis.Length() > 0) h0->GetZaxis()->SetTitle(zAxis);
124 void QAPlotReport::Add(
const Object* pack) {
126 if (fExtraInfo) fExtraInfo->
Add(qa->fExtraInfo);
127 for (
int i = 0; i < GetSize1D(); i++) {
128 f1dHistos->At(i)->Add(qa->f1dHistos->
At(i));
130 for (
int i = 0; i < GetSize2D(); i++) {
131 f2dHistos->At(i)->Add(qa->f2dHistos->
At(i));
133 for (
int i = 0; i < GetSize3D(); i++) {
134 f3dHistos->At(i)->Add(qa->f3dHistos->
At(i));
139 Long64_t QAPlotReport::Merge(TCollection* collection) {
140 Object::Merge(collection);
144 void QAPlotReport::Recalculate() {
147 for (
int i = 0; i < GetSize1D(); i++) {
148 if (f1dFlags[i].Length() < 3)
continue;
149 TranslateFlag(f1dFlags[i], h1, h2, oper);
150 TH1* H0 = f1dHistos->At(i);
151 TH1* H1 = f1dHistos->At(h1);
152 TH1* H2 = f1dHistos->At(h2);
153 Operate(H0, H1, H2, oper);
155 for (
int i = 0; i < GetSize2D(); i++) {
156 if (f2dFlags[i].Length() < 3)
continue;
157 TranslateFlag(f2dFlags[i], h1, h2, oper);
158 TH1* H0 = f2dHistos->At(i);
159 TH1* H1 = f2dHistos->At(h1);
160 TH1* H2 = f2dHistos->At(h2);
161 Operate(H0, H1, H2, oper);
163 for (
int i = 0; i < GetSize3D(); i++) {
164 if (f3dFlags[i].Length() < 3)
continue;
165 TranslateFlag(f3dFlags[i], h1, h2, oper);
166 TH1* H0 = f3dHistos->At(i);
167 TH1* H1 = f3dHistos->At(h1);
168 TH1* H2 = f3dHistos->At(h2);
169 Operate(H0, H1, H2, oper);
173 QAPlotReport::QAPlotReport(TString name, Int_t oneDim, Int_t twoDim, Int_t threeDim) :
174 Object(), fExtraInfo(nullptr), fOriginName(
"OriginName", name), f1dHistos(nullptr), f2dHistos(nullptr), f3dHistos(nullptr) {
176 f1dFlags.resize(oneDim);
177 f2dFlags.resize(twoDim);
178 f3dFlags.resize(threeDim);
186 if (fExtraInfo)
delete fExtraInfo;
191 if (
CheckFlag(no, c, h1, h2, 1)) f1dFlags[no] = Form(
"%i%c%i", h1, c, h2);
195 if (
CheckFlag(no, c, h1, h2, 2)) f2dFlags[no] = Form(
"%i%c%i", h1, c, h2);
199 if (
CheckFlag(no, c, h1, h2, 3)) f3dFlags[no] = Form(
"%i%c%i", h1, c, h2);
209 if (no >= size)
return kFALSE;
210 if (no < 0)
return kFALSE;
211 if (h1 >= size)
return kFALSE;
212 if (h1 < 0)
return kFALSE;
213 if (h2 >= size)
return kFALSE;
214 if (h2 < 0)
return kFALSE;
215 if (h1 == h2)
return kFALSE;
216 if (no == h1)
return kFALSE;
217 if (no == h2)
return kFALSE;
218 if (c !=
'/' && c !=
'+' && c !=
'-')
return kFALSE;
228 TString draw_opt =
"";
229 if (h->InheritsFrom(
"TH2")) {
232 }
else if (h->InheritsFrom(
"TH3")) {
237 TString rootPathFull = Form(
"%shist_%id_%i.root", path.Data(), dim, count);
238 TString rootPathShort = Form(
"hist_%id_%i.root", dim, count);
239 TString htmlPathFull = Form(
"%shist_%id_%i.html", path.Data(), dim, count);
240 TString htmlPathShort = dir + Form(
"hist_%id_%i.html", dim, count);
242 TCanvas* c1 =
new TCanvas(
"canvas",
"canvas", 0, 0, 1000, 1500);
243 h->DrawClone(draw_opt);
244 c1->SaveAs(rootPathFull);
246 HtmlFile file(htmlPathFull, kFALSE);
253 Bool_t batch = gROOT->IsBatch();
254 gROOT->SetBatch(kTRUE);
255 TString path = Form(
"%s/qa_plot_%i/", dir.Data(), no);
257 gSystem->mkdir(path);
258 TString filename = Form(
"%sqa_plot.html", path.Data());
259 TString filePath = Form(
"qa_plot_%i", no);
265 HtmlTable table1(
"table_1d",
"haltable",
"");
267 HtmlRow rowParent(
"",
"green_",
"");
270 HtmlRow extra(
"",
"green_",
"");
272 if (fExtraInfo ==
nullptr) {
275 TString url = fExtraInfo->
HTMLExtract(0, Form(
"%s/qa_plot_%i/", path.Data(), no));
281 HtmlRow rowLeg1(
"",
"dark_blue",
"");
287 for (
int i = 0; i < max; i++) {
288 HtmlRow rowEnt(
"",
"light_blue",
"");
290 TString cell1 =
"", cell2 =
"", cell3;
301 file.AddContent(div);
303 gROOT->SetBatch(batch);
304 TString relPath = Form(
"qa_plot_%i/qa_plot.html", no);
309 Bool_t batch = gROOT->IsBatch();
310 gROOT->SetBatch(kTRUE);
311 TString path = Form(
"%s/qa_plot_%i/", dir.Data(), no);
312 TString subdir = Form(
"qa_plot_%i", no);
313 if (rel_dir.Length() > 0) subdir = Form(
"%s/qa_plot_%i", rel_dir.Data(), no);
316 gSystem->mkdir(path);
320 TString className = Form(
"med_blue qa_%i", no);
332 HtmlRow rowPaint(
"", className,
"display:none");
333 TString buttonDraw = Form(
"<button onclick=\"qaPopup('%i')\">Plot Many</button>", no);
336 gSystem->mkdir(path);
338 struct constRowData {
348 data.className = className;
349 data.subDir = subdir;
354 auto makeRow = [](Int_t nu, TH1* h, constRowData dat) {
355 HtmlRow rowElement2(
"", dat.className,
"display:none");
356 TString url = dat.rep->ExportHistogramToFile(dat.path, dat.subDir, nu, h);
357 TString boxname = Form(
"cb_%i_%i_%i", dat.no, dat.dim, nu);
358 TString urlBox = Form(
"<input type=\"checkbox\" name = \"%s\" >", boxname.Data());
360 cell.AddAtrib(
"onclick", Form(
"chageCheckBoxCell('%s')", boxname.Data()));
364 dat.table->AddContent(rowElement2);
366 HtmlRow rowElement(
"", className,
"display:none");
374 makeRow(i, f1dHistos->
At(i), data);
383 makeRow(i, f2dHistos->
At(i), data);
392 makeRow(i, f3dHistos->
At(i), data);
402 if (fExtraInfo ==
nullptr) {
411 HtmlRow extra(
"", className,
"display:none");
413 TString url = fExtraInfo->
HTMLExtract(0, Form(
"%s/qa_plot_%i/", path.Data(), no));
419 gROOT->SetBatch(batch);
422 void QAPlotReport::Browse(TBrowser* b) {
423 b->Add(&fOriginName);
425 b->Add(f1dHistos->
At(i));
428 b->Add(f2dHistos->
At(i));
431 b->Add(f3dHistos->
At(i));
435 void QAPlotReport::Print(Option_t* )
const {
437 Cout::InStars(
"1D", kWhite);
439 TString name = f1dHistos->
At(i)->GetName();
440 TString flag = f1dFlags[i];
443 Cout::InStars(
"2D", kWhite);
445 TString name = f2dHistos->
At(i)->GetName();
446 TString flag = f2dFlags[i];
449 Cout::InStars(
"3D", kWhite);
451 TString name = f3dHistos->
At(i)->GetName();
452 TString flag = f3dFlags[i];
459 case 1: f1dFlags[no] = flag;
break;
460 case 2: f2dFlags[no] = flag;
break;
461 case 3: f3dFlags[no] = flag;
break;
static void Database(Int_t no...)
T * At(const Int_t i) const
static TString GetUrl(TString adress, TString text)
static TString GetJsDiv(TString root_file, TString object_name, TString draw_opt="colz", TString draw_div_name="drawing")
static void FixAddress(TString &address)
static TString GetHideButtonRow(TString listName, TString text)
void SetClass(TString className)
virtual void AddContent(const HtmlObject &obj)
virtual void AddContent(const HtmlObject &obj)
virtual void AddContent(const HtmlObject &obj)
virtual void Add(const Object *pack)
virtual TString HTMLExtract(Int_t, TString="") const
virtual TString HTMLExtract(Int_t no, TString dir="") const
virtual void HTMLExtractIntoTable(Int_t no, HtmlTable &obj, TString dir="", TString rel_dir="") const
TString ExportHistogramToFile(TString path, Int_t count, TH1 *h) const
void SetFlag(Int_t no, TString flag, Int_t dim)
void SetFlag3D(Int_t no, Char_t c=' ', Int_t h1=0, Int_t h2=0)
void SetFlag2D(Int_t no, Char_t c=' ', Int_t h1=0, Int_t h2=0)
void SetFlag1D(Int_t no, Char_t c=' ', Int_t h1=0, Int_t h2=0)
Bool_t CheckFlag(Int_t no, Char_t c, Int_t h1, Int_t h2, Int_t dim) const
virtual void SetExtraInfo(Object *p)