-
Notifications
You must be signed in to change notification settings - Fork 0
/
IROOT.cpp
2588 lines (2219 loc) · 85.6 KB
/
IROOT.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "IROOT.h"
#include "ui_IROOT.h"
IROOTAxisEditor *axisEditor;
IROOTFittingObjects *fitObjects;
IROOTLoopModule *loopModule;
static int tableN =1;
TFile* IROOT::currentFile = 0;
TTree* IROOT::currentTree = 0;
IROOT::IROOT(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::IROOT)
{
ui->setupUi(this);
RemoveDlls();
InitializeVariables();
InitializeRoot();
CreateWidgets();
showMaximized();
ui->mainStackedWidget->setCurrentWidget(ui->openingPage);
ui->filesWidget->setHeaderHidden(false);
loadSettings();
}
IROOT::~IROOT()
{
delete ui;
// delete loopModule;
// message->close();
// fitObjects->close();
// axisEditor->close();
// loopModule->close();
}
// this function is required because windows sometime does not allow to delete the dlls when in use. We delete on startup.
void IROOT::RemoveDlls()
{
QStringList wildCards;
wildCards<<"irootcode*";
QFileInfoList l= QDir::current().entryInfoList(wildCards,QDir::Files);
for(int ii=0;ii<l.count();ii++){
qDebug()<<l.at(ii).fileName();
QFile f(l.at(ii).fileName());
if(f.exists())
f.remove();
}
}
/*
*Intializes ROOT Variables
*/
void IROOT::closeEvent(QCloseEvent *)
{
saveSettings();
delete colorDialog;
delete message;
delete axisEditor;
delete fitOptions;
delete fitObjects;
delete loopModule;
delete histogramBinning;
delete worksheetImporter;
delete multiDirSearch;
delete asciiConvertor;
delete plotOptionsEntry;
delete binaryConvertor;
}
void IROOT::InitializeRoot()
{
iRootApp = new TApplication("iRootApp",0,0);
iRootApp->SetReturnFromRun(true); // tell application to return from run
// set up our own style
gStyle->SetCanvasColor(kWhite); // background is no longer mouse-dropping white
gStyle->SetCanvasBorderMode(0); // turn off canvas borders
// gStyle->SetPadBorderMode(0);
gStyle->SetFrameBorderMode(0);
gStyle->SetFrameLineWidth(0.2);
gStyle->SetTitleFillColor(0);
gStyle->SetStatColor(0);
//iRoot Default Styles
gStyle->SetStatFont(2+(13)*10); // Times New Roman Regular
gStyle->SetStatFontSize(0.03);
gStyle->SetStatTextColor(1); //Red Color
gStyle->SetTitleTextColor(1);
gStyle->SetTitleFontSize(0.03);
gStyle->SetTitleFont(2+(13)*10,"t");
gStyle->SetTitleFont(2+(13)*10,"xyz");
gStyle->SetTitleSize(0.03,"xyz");
gStyle->SetTitleColor(1,"xyz");
gStyle->SetLabelFont(2+(13)*10,"xyz");
gStyle->SetLabelSize(0.03,"xyz");
gStyle->SetLabelColor(1,"xyz");
gStyle->SetMarkerStyle(2);
gStyle->SetMarkerSize(1);
gStyle->SetMarkerColor(4);
gStyle->SetHistFillColor(38);
gStyle->SetHistLineStyle(0);
gStyle->SetHistLineColor(1);
gROOT->SetStyle("Pub");
ui->plotTemplate->setCurrentIndex(4);
gROOT->ForceStyle();
gStyle->UseCurrentStyle();
// on_addNewCanvas_clicked();
}
// intitialize variables
void IROOT::InitializeVariables()
{
currentTree =0;
isChain =false;
QStringList generalOptions;
QStringList histogramOptions12;
QStringList histogramOptions1;
QStringList histogramOptions2;
QStringList histogramOptions3;
QStringList graphOptions;
generalOptions<<"Superimpose on previous plot |SAME"
<<"Draw X axis on the top side |X+"
<<"Draw Y axis on the left side |Y+"
<<"Use the graphical cut |[cutg]";
histogramOptions12<<"Draw error bars |E"
<<"Lego plot with hidden line removal |LEGO1"
<<"Lego plot with hidden surfacee removal |LEGO2"
<<"Lego plot with hidden line removal without borders |LEGO2"
<<"Draw bin contents as text |TEXT"
<<"Draw bin contents as text tilted by 45 degrees |TEXT45";
histogramOptions1<<"Draw without axis |AH"
<<"Bar chart |B"
<<"3D bar chart |BAR"
<<"3D horizontal bars |HBAR"
<<"Draw smooth curve through bins |C"
<<"Draw error bars for bins with 0 contents |E0"
<<"Draw error bars with perpendicular lines at edges |E1"
<<"Draw error bars with rectangles |E2"
<<"Draw fill area through end points of vertical error bars |E3"
<<"Draw smooth fill area through end points of error bars |E4"
<<"Draw fill area through end points of vertical error bars (ignore empty bins) |E5"
<<"Draw smooth fill area through end points of error bars (ignore empty bins) |E6"
<<"Draw a line through the bins |L"
<<"Draw marker at each non-empty bins |P"
<<"Draw marker at all bins |P0"
<<"Pie chart |PIE"
<<"Use high resolution mode |9";
histogramOptions2<<"Arrow mode, shows gradient between adjancent cells |ARR"
<<"Draw a box for each cell, size proportional to contents absoulte value |BOX"
<<"Draw a 3D box for each cell, size proportional to contents absoulte value |BOX"
<<"Draw a box for each cell with color scale varying with contents |COL"
<<"Draw a box for each cell with color scale varying with contents, show palette |COLZ"
<<"Contour plot with surface colors |CONT0"
<<"Contour plot with different line styles for contours|CONT1"
<<"Contour plot with same line styles for contours |CONT2"
<<"Contour plot with fill area colors |CONT3"
<<"Contour plot with surface colors |CONT4"
<<"Contour plot with delaunay triangles |CONT5"
<<"Cylindrical coordinates |CYL"
<<"Polar coordinates |POL"
<<"Spherical coordinates |SPH"
<<"Pseudorapidity/Phi coordinates |PSR"
<<"Surface plot with hidden line removal |SURF"
<<"Surface plot with hidden surface removal |SURF1"
<<"Surface plot with colors for cell contents |SURF2"
<<"Surface plot with contour view |SURF3"
<<"Surface plot with Gouraud shading |SURF4"
<<"Surface plot with only contours (use with CYL, SPH, PSR) |SURF5";
histogramOptions3<<"Draw a Gouraud shaded 3d iso surface |ISO"
<<"Draw a box with volume proportional to absolute value of cell |BOX";
graphOptions<<"Draw axis around the graph |A"
<<"Polyline |L"
<<"Fill area |F"
<<"Smooth curve |C"
<<"Draw a * at each point |*"
<<"Use current marker |P"
<<"Bar chart |B";
QTreeWidgetItem *generalOptionsItem = new QTreeWidgetItem();
generalOptionsItem->setText(0,"General options");
QList <QTreeWidgetItem*> generalOptionsItemChildren;
for(int ii=0; ii<generalOptions.count();ii++){
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0,generalOptions.at(ii));
generalOptionsItemChildren.append(item);
}
generalOptionsItem->addChildren(generalOptionsItemChildren);
ui->templateOptions->addTopLevelItem(generalOptionsItem);
QTreeWidgetItem *histogramOptions12Item = new QTreeWidgetItem();
histogramOptions12Item->setText(0,"1D and 2D histogram options");
QList <QTreeWidgetItem*> histogramOptions12ItemChildren;
for(int ii=0; ii<histogramOptions12.count();ii++){
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0,histogramOptions12.at(ii));
histogramOptions12ItemChildren.append(item);
}
histogramOptions12Item->addChildren(histogramOptions12ItemChildren);
ui->templateOptions->addTopLevelItem(histogramOptions12Item);
QTreeWidgetItem *histogramOptions1Item = new QTreeWidgetItem();
histogramOptions1Item->setText(0,"1D histogram options");
QList <QTreeWidgetItem*> histogramOptions1ItemChildren;
for(int ii=0; ii<histogramOptions1.count();ii++){
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0,histogramOptions1.at(ii));
histogramOptions1ItemChildren.append(item);
}
histogramOptions1Item->addChildren(histogramOptions1ItemChildren);
ui->templateOptions->addTopLevelItem(histogramOptions1Item);
QTreeWidgetItem *histogramOptions2Item = new QTreeWidgetItem();
histogramOptions2Item->setText(0,"2D histogram options");
QList <QTreeWidgetItem*> histogramOptions2ItemChildren;
for(int ii=0; ii<histogramOptions2.count();ii++){
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0,histogramOptions2.at(ii));
histogramOptions2ItemChildren.append(item);
}
histogramOptions2Item->addChildren(histogramOptions2ItemChildren);
ui->templateOptions->addTopLevelItem(histogramOptions2Item);
QTreeWidgetItem *histogramOptions3Item = new QTreeWidgetItem();
histogramOptions3Item->setText(0,"3D histogram options");
QList <QTreeWidgetItem*> histogramOptions3ItemChildren;
for(int ii=0; ii<histogramOptions3.count();ii++){
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0,histogramOptions3.at(ii));
histogramOptions3ItemChildren.append(item);
}
histogramOptions3Item->addChildren(histogramOptions3ItemChildren);
ui->templateOptions->addTopLevelItem(histogramOptions3Item);
QTreeWidgetItem *graphOptionsItem = new QTreeWidgetItem();
graphOptionsItem->setText(0,"Graph options");
QList <QTreeWidgetItem*> graphOptionsItemChildren;
for(int ii=0; ii<graphOptions.count();ii++){
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0,graphOptions.at(ii));
graphOptionsItemChildren.append(item);
}
graphOptionsItem->addChildren(graphOptionsItemChildren);
ui->templateOptions->addTopLevelItem(graphOptionsItem);
fitResultsTable = new IROOTWorksheet(2);
fitResultsTable->SetTable(ui->fitResultsTable);
connect(fitResultsTable,SIGNAL(Message(QString,QString)),this,SLOT(AppendMessage(QString,QString)));
connect(fitResultsTable,SIGNAL(CreatePad()),this,SLOT(on_addNewCanvas_clicked()));
drawStringCompleter =new QCompleter();
cutStringCompleter =new QCompleter();
filterStringCompleter =new QCompleter();
ui->plotString->setCompleter(0);
ui->cutString->setCompleter(0);
drawStringCompleter->setCompletionMode(QCompleter::PopupCompletion);
drawStringCompleter->setCaseSensitivity(Qt::CaseInsensitive);
cutStringCompleter->setCompletionMode(QCompleter::PopupCompletion);
cutStringCompleter->setCaseSensitivity(Qt::CaseInsensitive);
filterStringCompleter->setCompletionMode(QCompleter::PopupCompletion);
filterStringCompleter->setCaseSensitivity(Qt::CaseInsensitive);
connect(drawStringCompleter,SIGNAL(activated(QString)),this,SLOT(setDrawStringFromCompleter(QString)));
connect(cutStringCompleter,SIGNAL(activated(QString)),this,SLOT(setCutStringFromCompleter(QString)));
connect(filterStringCompleter,SIGNAL(activated(QString)),this,SLOT(setFilterStringFromCompleter(QString)));
uniqueLineColor = new QAction("Line color",this);
uniqueMarkerColor = new QAction("Marker color",this);
uniqueMarkerStyle = new QAction("Marker style",this);
ui->unique->addAction(uniqueLineColor);
ui->unique->addAction(uniqueMarkerColor);
ui->unique->addAction(uniqueMarkerStyle);
connect(uniqueLineColor,SIGNAL(triggered()),this,SLOT(SetUniqueLineColor()));
connect(uniqueMarkerColor,SIGNAL(triggered()),this,SLOT(SetUniqueMarkerColor()));
connect(uniqueMarkerStyle,SIGNAL(triggered()),this,SLOT(SetUniqueMarkerStyle()));
lineLegend =new QAction("Lines",this);
markerLegend =new QAction("Markers",this);
linemarkerLegend =new QAction("Line/Markers",this);
ui->createLegends->addAction(lineLegend);
ui->createLegends->addAction(markerLegend);
ui->createLegends->addAction(linemarkerLegend);
connect(lineLegend,SIGNAL(triggered()),this,SLOT(CreateLineLegend()));
connect(markerLegend,SIGNAL(triggered()),this,SLOT(CreateMarkerLegend()));
connect(linemarkerLegend,SIGNAL(triggered()),this,SLOT(CreateLineMarkerLegend()));
// ui->unique->setStyleSheet("background-color: black; color: white; font: 7pt \"Segoe UI\"");
// ui->createLegends->setStyleSheet("background-color: black; color: white; font: 7pt \"Segoe UI\"");
}
void IROOT::setDrawStringFromCompleter(QString completer)
{
QStringList l = ui->plotString->currentText().split(":");
l.removeLast();
QString merged;
merged= l.join(":").append(":").append(completer);
if(!ui->plotString->currentText().contains(":"))// first element
merged =completer;
ui->plotString->insertItem(0,merged);
ui->plotString->setCurrentIndex(0);
}
void IROOT::setCutStringFromCompleter(QString completer)
{
QString currentString = ui->cutString->currentText();
int size= cutStringCompleter->completionPrefix().size();
// currentString.replace("&&","::");
// currentString.replace("||","::");
// currentString.replace("==","::");
currentString.remove(currentString.size()-size,size);
currentString.append(completer);
// QStringList l = currentString.split("::");
// l.removeLast();
// QString merged;
// merged= l.join(":").append(":").append(completer);
// // if(!ui->plotString->currentText().contains(":"))// first element
// // merged =completer;
// QString merged = ui->cutString->currentText().append(completer);
ui->cutString->insertItem(0,currentString);
ui->cutString->setCurrentIndex(0);
}
void IROOT::setFilterStringFromCompleter(QString completer)
{
QString currentString = ui->filterString->text();
int size= filterStringCompleter->completionPrefix().size();
// currentString.replace("&&","::");
// currentString.replace("||","::");
// currentString.replace("==","::");
currentString.remove(currentString.size()-size,size);
currentString.append(completer);
// QStringList l = currentString.split("::");
// l.removeLast();
// QString merged;
// merged= l.join(":").append(":").append(completer);
// // if(!ui->plotString->currentText().contains(":"))// first element
// // merged =completer;
// QString merged = ui->cutString->currentText().append(completer);
ui->filterString->setText(currentString);
}
void IROOT::CreateWidgets()
{
message = new IROOTMessageBox();
axisEditor = new IROOTAxisEditor();
fitOptions = new IROOTFitOptions();
fitObjects = new IROOTFittingObjects();
loopModule = new IROOTLoopModule();
histogramBinning = new IROOTHistogramBinning();
worksheetImporter = new IROOTWorksheetImporter();
multiDirSearch = new IROOTMultiDirectorySearch();
asciiConvertor = new IROOTAsciiFileConvertor();
plotOptionsEntry = new IROOTPlotOptionsEntry();
binaryConvertor = new IROOTBinaryFileConvertor();
connect(binaryConvertor,SIGNAL(openFiles(QStringList)),this,SLOT(OpenFiles(QStringList)));
connect(multiDirSearch,SIGNAL(OpenFiles(QStringList)),this,SLOT(OpenFiles(QStringList)));
connect(asciiConvertor,SIGNAL(rootFilesReady(QStringList)),this,SLOT(OpenFiles(QStringList)));
connect(plotOptionsEntry,SIGNAL(plotOptionsChanged(QString)),ui->styleString,SLOT(setText(QString)));
connect(ui->styleString,SIGNAL(textChanged(QString)),plotOptionsEntry,SLOT(setText(QString)));
connect(worksheetImporter->GetImportThread(),SIGNAL(Stopped(int)),this,SLOT(CreateTable()));
// ui->frontPageWidgets->addWidget(asciiConvertor);
// ui->frontPageWidgets->setCurrentIndex(2);
colorDialog = new QColorDialog;
colorDialog->setOption(QColorDialog::NoButtons);
connect(fitOptions,SIGNAL(selectionChanged(QList<QTreeWidgetItem*>)),this,SLOT(SetFitOption(QList<QTreeWidgetItem*>)));
connect(colorDialog,SIGNAL(currentColorChanged(QColor)),this,SLOT(fontColorSelected(QColor)));
// connect(ui->mdiArea,SIGNAL(subWindowActivated(QMdiSubWindow*)),this,SLOT(windowActivated(QMdiSubWindow*)));
QList <QTabBar*> tabList = ui->mdiArea->findChildren<QTabBar*>();
//tabList.at(0)->setTabsClosable("true");
connect(tabList.at(tabList.count()-1), SIGNAL(currentChanged(int)),this, SLOT(tabChanged(int)),Qt::AutoConnection);
connect(tabList.at(tabList.count()-1), SIGNAL(tabCloseRequested(int)),this, SLOT(tabChanged(int)),Qt::AutoConnection);
connect(fitObjects,SIGNAL(itemsSelected(QStringList)),this,SLOT(fitObjectsSelected(QStringList)));
ui->fitResultsTable->setModel(fitResultsTable);
ui->fitResultsTable->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->fitResultsTable, SIGNAL(customContextMenuRequested(const QPoint &)),fitResultsTable, SLOT(showMenu(QPoint)));
connect(histogramBinning,SIGNAL(binningChanged(HistBin)),this,SLOT(setCurrentBinning(HistBin)));
currentBinning = histogramBinning->GetCurrentBinning();
ui->fit->setDisabled(true);
IROOTTreeModel = new IROOTWorksheet(1);
connect(this,SIGNAL(currentTreeChanged(TTree*, QStringList)),IROOTTreeModel,SLOT(SetCurrentTree(TTree*, QStringList)));
CreateTreeViewer();
closeTimer =new QTimer();
closeTimer->setInterval(250);
closeTimer->start();
connect(closeTimer,SIGNAL(timeout()),this,SLOT(closeHiddenWidgets()));
}
void IROOT::closeHiddenWidgets()
{
if(!asciiConvertor->isActiveWindow()){
if(!asciiConvertor->isEditing())
asciiConvertor->hide();
}
if(!axisEditor->isActiveWindow())
axisEditor->hide();
if(!fitOptions->isActiveWindow())
fitOptions->hide();
if(!fitObjects->isActiveWindow())
fitObjects->hide();
if(!histogramBinning->isActiveWindow())
histogramBinning->hide();
if(!loopModule->isActiveWindow())
loopModule->hide();
if(!multiDirSearch->isActiveWindow())
multiDirSearch->hide();
if(!plotOptionsEntry->isActiveWindow())
plotOptionsEntry->hide();
if(!worksheetImporter->isActiveWindow())
worksheetImporter->hide();
// axisEditor = new IROOTAxisEditor();
// fitModule = new IROOTFittingModule();
// fitOptions = new IROOTFitOptions();
// fitObjects = new IROOTFittingObjects();
// loopModule = new IROOTLoopModule();
// histogramBinning = new IROOTHistogramBinning();
// worksheetImporter = new IROOTWorksheetImporter();
// multiDirSearch = new IROOTMultiDirectorySearch();
// asciiConvertor = new IROOTAsciiFileConvertor();
// plotOptionsEntry = new IROOTPlotOptionsEntry();
}
void IROOT::tabChanged(int tabN)
{
QMdiSubWindow *window = ui->mdiArea->currentSubWindow();
if(window!=NULL){
//qDebug()<<window->widget()->metaObject()->className();
if(window->widget()->metaObject()->className()==QString("iCanvas")){ // canvas
((iCanvas*)(window->widget()))->GetCanvas()->cd(1);
fitObjects->Update();
}
}
}
void IROOT::tabClose(int tabN)
{
// QMdiSubWindow *window = ui->mdiArea->currentSubWindow();
// if(window!=NULL){
// //qDebug()<<window->widget()->metaObject()->className();
// if(window->windowTitle()==QString("IROOT Tree Viewer (Read Only)")){ // canvas
// ShowMessage("This window cannot be closed","ERR");
// }
// }
}
void QMdiSubWindow::closeEvent(QCloseEvent *closeEvent)
{
if(windowTitle()==QString("IROOT Tree Viewer (Read only)")){ // canvas
closeEvent->ignore();
}
else closeEvent->accept();
}
void IROOT::windowActivated(QMdiSubWindow *window)
{
if(window!=NULL){
//qDebug()<<window->widget()->metaObject()->className();
if(window->widget()->metaObject()->className()==QString("iCanvas")){
((iCanvas*)(window->widget()))->GetCanvas()->cd(1);
}
}
}
void IROOT::on_backtoOpeningPage_clicked()
{
ui->mainStackedWidget->setCurrentWidget(ui->openingPage);
}
//On pressing the open button
void IROOT::on_openFiles_clicked()
{
QStringList filenames = QFileDialog::getOpenFileNames(this,"Open ROOT Files", "","(*.root);;All files (*.*)");
OpenFiles(filenames);
ui->mainStackedWidget->setCurrentWidget(ui->workingPage);
}
/*TCanvas *iRoot::AddCanvas(QString title, int x,int y)
*Adds a new canvas in the mdi area and dividing it x by y
*if x and y are 0 then the values from the ui are taken
*/
TCanvas *IROOT::AddCanvas(QString title, int x,int y)// adds a new canvas window divided by x rows and y columns
{
setCursor(Qt::BusyCursor);
QMdiSubWindow *subWindow = new QMdiSubWindow();
iCanvas *widget = new iCanvas(axisEditor,fitObjects, subWindow);
subWindow->setWidget(widget);
ui->mdiArea->addSubWindow(subWindow);
subWindow->showMaximized();
if(title==""){
subWindow->setWindowTitle(QString("Canvas %1").arg(iCanvas::canvasN));
}
else
subWindow->setWindowTitle(title);
subWindow->setAttribute(Qt::WA_DeleteOnClose);
subWindow->activateWindow();
subWindow->setOption (QMdiSubWindow::RubberBandResize);
ui->mdiArea->setActiveSubWindow(subWindow);
setCursor(Qt::ArrowCursor);
if(x<1)
x=ui->canvasRows->value();
if(y<1)
y=ui->canvasColumns->value();
widget->GetCanvas()->Divide(x,y);
widget->GetCanvas()->cd(1);
gPad->SetLogx(ui->logX->isChecked());
gPad->SetLogy(ui->logY->isChecked());
gPad->SetGridx(ui->gridX->isChecked());
gPad->SetGridy(ui->gridY->isChecked());
widget->GetCanvas()->Update();
gPad->Clear();
return(widget->GetCanvas());
}
void IROOT::OpenFiles(QStringList fileNames)
{
int nFiles=0;
isClearingFiles=false;// reset the flag, if set by clear files slot
for(int ii=0;ii<fileNames.count();ii++){
QString file= fileNames.at(ii);
TFile *f = new TFile(file.toLatin1().data(),"READ");
if(f!=NULL){
QList <TTree*> l= GetTree(f);
if(l.count()>1)
AppendMessage("This file has more than 1 tree, opening as different files","INFO");
for(int jj=0;jj<l.count();jj++){
TTree *tree = l.at(jj);
if(tree!=NULL){
QTreeWidgetItem *newfile = new QTreeWidgetItem(ui->filesWidget);
newfile->setText(0, f->GetFile()->GetName());
newfile->setText(1, QString("%1").arg(tree->GetEntriesFast()));
newfile->setText(2,tree->GetName());
newfile->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsSelectable);
ui->filesWidget->resizeColumnToContents(0);
ui->filesWidget->resizeColumnToContents(1);
newfile->setCheckState(0,Qt::Unchecked);
//GetListofRootPlots(f);
nFiles++;
//delete f; !!! wrong if more than 1 tree is present
}
}
// if(GetListofRootPlots(f)>0 && l.count()==0){ // check for plots
// mainWindow->ShowMessage(QString("No trees found in: %1").arg(file),"WARN");
// QTreeWidgetItem *newfile = new QTreeWidgetItem(ui->filesWidget);
// newfile->setText(0, f->GetFile()->GetName());
// newfile->setText(1, "0");
// newfile->setText(2,"");
// newfile->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsSelectable);
// ui->filesWidget->resizeColumnToContents(0);
// ui->filesWidget->resizeColumnToContents(1);
// newfile->setCheckState(0,Qt::Unchecked);
// nFiles++;
// //delete f;
// }
delete f;
}
else{
AppendMessage(QString("Error opening file %1").arg(file),"ERR");
}
}
// if(nFiles>0)
// spreadSheetEntryN=0; // reset
if(ui->filesWidget->currentItem()==NULL)
SetCurrentFile(0);
ui->mainStackedWidget->setCurrentWidget(ui->workingPage);
ui->leftStackWidget->setCurrentWidget(ui->filesPage);
if(nFiles>0)
AppendMessage(QString("%1 file(s) opened...").arg(nFiles),"INFO");
isChain=false;
}
void IROOT::OpenFilesAsChain(QStringList filenames)
{
if(filenames.count()>0){
TChain *chain=0;
isChain=false;
bool chainCreated=false;
//QString treeName=set->GetChainTreeName();
QString treeName="";
for(int ii=0;ii<filenames.count();ii++){
QString file= filenames.at(ii);
TFile *f = new TFile(file.toLatin1().data(),"READ");
if(f!=NULL){
TTree *tree = GetTree(f).at(0);
if(tree==0){
ShowMessage(QString("Error: No trees found in the file: %1").arg(file),"ERR");
}
else{
if(treeName=="")
treeName=tree->GetName();
if(treeName==tree->GetName()){
if(chainCreated==false){
ShowMessage(QString("Creating TChain with tree name: %1").arg(treeName),"INFO");
chain = new TChain(treeName.toLatin1().data());
chainCreated=true;
}
QTreeWidgetItem *newfile = new QTreeWidgetItem(ui->filesWidget);
newfile->setText(0, f->GetFile()->GetName());
newfile->setText(1, QString("%1").arg(tree->GetEntriesFast()));
newfile->setText(2,tree->GetName());
newfile->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsSelectable);
ui->filesWidget->resizeColumnToContents(0);
ui->filesWidget->resizeColumnToContents(1);
newfile->setCheckState(0,Qt::Checked);
delete f;
if(chainCreated==true) chain->Add(file.toLatin1().data());
}
else{
ShowMessage(QString("Error: Could not find tree %1 in file %2").arg(treeName).arg(file),"ERR");
}
}
}
else{
ShowMessage(QString("Error opening file %1").arg(file),"ERR");
}
}
if(chainCreated==true){ // enable or disable
//ui->actionOpen_Root_Files->setDisabled(true);
//ui->actionOpen_Root_Files_as_Chain->setDisabled(true);
isChain=true;
ui->filesWidget->setDisabled(true);
// ui->actionSplit_Selected_Trees->setDisabled(true);
// loop->DisableFiles();
currentTree=chain;
QStringList branches = IROOTTree::GetListofBranches(currentTree);
UpdateBranches(branches);
currentTreeChanged(currentTree,branches);
}
else{ // chain not created
isChain=false;
}
}
}
int IROOT::GetNumberOfFiles(bool selectedOnly)
{
int nF=ui->filesWidget->topLevelItemCount();
int selectedN=0;
if(selectedOnly){
for(int ii=0;ii<nF;ii++)
if(ui->filesWidget->topLevelItem(ii)->checkState(0)==Qt::Checked) selectedN++;
return selectedN;
}
return nF;
}
QStringList IROOT::GetFileList()
{
QStringList fileList;
for(int ii=0;ii<ui->filesWidget->topLevelItemCount();ii++){
fileList.append(ui->filesWidget->topLevelItem(ii)->text(0));
}
return fileList;
}
/*Sets the file at index as the current file
*/
void IROOT::SetCurrentFile(int index)
{
if(index<ui->filesWidget->topLevelItemCount()&& index >-1){
ui->filesWidget->setCurrentItem(ui->filesWidget->topLevelItem(index));
}
}
/*TTree* iRootFileContentsWidget::GetTree(TFile *f)
* returns the trees in the file
*
*/
QList <TTree*> IROOT::GetTree(TFile *f)
{
QList <TTree*> treeList;
if(f!=NULL){
TList *list = f->GetListOfKeys();//StreamerInfo
TKey *keys;
if(list==NULL){
//mainWindow->ShowMessage("Error: No keys found for finding tree in file...","ERR");
return treeList;
}
TIter next(list);
TString className="TTree";
TTree *tree=0;
while ((keys = (TKey *)next())){
if(keys->GetClassName()==className){
tree = (TTree*)f->Get(keys->GetName());
if(tree!=NULL){
if(tree->GetEntry(tree->GetEntryNumber(0))==-1){
//mainWindow->ShowMessage("Error: No entries found in tree...","ERR");
}
else{
treeList.append(tree);
}
}
}
}
}
else{
//mainWindow->ShowMessage("Error: No tree found in file...","ERR");
return treeList;
}
return treeList;
}
//on clicking new file in file widget
void IROOT::on_filesWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
//bool closePreviousFile = !ui->keepFilesOpen->isChecked();
if(!isClearingFiles){// do not call this slot if clearing files is going on
if(previous!=NULL&¤tFile!=0){
// if(closePreviousFile){ // latest addition
// delete currentFile; // close previous file
// }
if(!ui->multiFileMode->isChecked())
delete currentFile;
}
currentFile = new TFile(current->text(0).toLatin1().data(),"READ");
if(current->text(2)==""){
currentTree=0;
ui->branchWidget->clear();
}
else{
currentTree = (TTree*)currentFile->Get(current->text(2).toLatin1().data());
QStringList branches = IROOTTree::GetListofBranches(currentTree);
UpdateBranches(branches);
currentTreeChanged(currentTree,branches);
if(ui->applyFilterToAll->isChecked() && ui->filterString->text()!=""){
on_filterEntries_clicked();
}
// if(ui->filterAutoApply->isChecked()){
// FilterTree(currentTree,ui->filterString->text());
// }
//else ResetAllFilters(currentTree);
}
// GetListofRootPlots(currentFile);
// mainWindow->ShowMessage(QString("File: %1 opened...").arg(currentFile->GetName()),"SUCCESS");
}
}
void IROOT::UpdateBranches(QStringList branches){
if(branches.count()>0){
ui->branchWidget->clear();
for(int ii=0;ii<branches.count();ii++){
QTreeWidgetItem *t2 = new QTreeWidgetItem(ui->branchWidget);
t2->setText(0,branches.at(ii));
// if(ii>=(leafList.count()-nFriends)){
// t2->setTextColor(0,Qt::blue);
// }
}
QStringList branches_and_options = branches;
branches_and_options.append("Entry$");
drawStringCompleter->setModel(new QStringListModel(branches_and_options,drawStringCompleter));
cutStringCompleter->setModel(new QStringListModel(branches_and_options,cutStringCompleter));
filterStringCompleter->setModel(new QStringListModel(branches_and_options,filterStringCompleter));
}
}
///*QStringList iRootFileContentsWidget::ListBranches(TTree *tree)
// *List the names of branches in the tree
// */
//QStringList IROOT::ListBranches(TTree *tree)
//{
// QStringList leafList;
// ui->branchWidget->clear();
// if(tree!=NULL){
// QCompleter *completer;
// leafList = GetListofLeavesinTree(tree);
// // if tree has friends
// int nFriends=0;
// TList *l = tree->GetListOfFriends();
// if(l!=NULL){
// int n = l->GetEntries();
// if(n>0){
// for(int ii=0;ii<n;ii++){
// //mainWindow->ShowMessage(QString("Found friend tree: %1...").arg(l->At(ii)->GetName()),"INFO");
// TFriendElement * fe = (TFriendElement*)l->At(ii);
// if(fe!=NULL){
// TTree *t = fe->GetTree();
// if(t!=NULL){
// QStringList friendList = GetListofLeavesinTree(t);
// leafList.append(friendList);
// nFriends = nFriends+friendList.count();
// }
// }
// }
// }
// }
// if(leafList.count()>0){
// for(int ii=0;ii<leafList.count();ii++){
// QTreeWidgetItem *t2 = new QTreeWidgetItem(ui->branchWidget);
// t2->setText(0,leafList.at(ii));
// if(ii>=(leafList.count()-nFriends)){
// t2->setTextColor(0,Qt::blue);
// }
// }
// completer = new QCompleter(leafList, this);
// ui->plotString->setCompleter(completer);
// ui->cutString->setCompleter(completer);
// }
// return leafList;
// }
// return leafList;
//}
///*QStringList iRootFileContentsWidget::GetListofLeavesinTree(TTree *tree)
// *Gets the list of names of leaves in the tree
// */
//QStringList IROOT::GetListofLeavesinTree(TTree *tree)
//{
// QStringList leavesList;
// if(tree==NULL)return leavesList;
// int nDim=0; //dimension of the arrays if present
// QChar fillChar = QLatin1Char('0');
// //tree->ResetBranchAddresses();
// TObjArray * leafarray = tree->GetListOfLeaves();
// TObject *leaf;
// QString s,slstr;
// QString s2;
// QStringList sl;
// int leafcnt=0;
// int dim1,dim2;
// if(leafarray!=NULL){
// for(int ii=0;ii<leafarray->GetEntries();ii++){
// leaf = leafarray->At(ii);
// if(leaf!=NULL){
// leavesList.append(QString("%1").arg(leaf->GetName()));
// s = ((TLeaf*) leaf)->GetBranch()->GetName();
// nDim=s.count("[");
// //**IMPROVE**//
// // allow only for 1d and 2d arrays at the moment
// ((TLeaf*)leaf)->GetLeafCounter(leafcnt);
// if(leafcnt>1){ // its an array
// //cross check for dimensions from leaf title
// s2=leaf->GetTitle();
// if(s2.count("[")==2){ nDim=2;
// s=s2;
// }
// if(nDim==1||nDim==0){ // one dimensional array
// for(int jj =0; jj<leafcnt; jj++){
// leavesList.append(QString("%1[%2]").arg(leaf->GetName()).arg(jj,3,10,fillChar));
// }
// }
// else if(nDim==2){
// // Get the dimensions from the string
// dim1=0; dim2=0;
// sl=s.split("[");
// slstr=sl.at(1);
// slstr=slstr.remove("]");
// dim1 = slstr.toInt();
// slstr=sl.at(2);
// slstr=slstr.remove("]");
// dim2 = slstr.toInt();
// for(int ii =0; ii<dim1; ii++){
// for(int jj=0;jj<dim2;jj++){
// leavesList.append(QString("%1[%2][%3]").arg(leaf->GetName()).arg(ii,3,10,fillChar).arg(jj,3,10,fillChar));
// }
// }
// }
// }
// }
// }
// return leavesList;
// }
// return leavesList;
//}
void IROOT::on_branchWidget_itemClicked(QTreeWidgetItem *item, int column)
{
if(currentTree!=NULL){
QList <QTreeWidgetItem*> selectedItems= ui->branchWidget->selectedItems();
if(selectedItems.count()>2){
while(selectedItems.count()!=2){
ui->branchWidget->setItemSelected(selectedItems.at(1),false);
selectedItems.removeAt(1);
}
}
if(selectedItems.count()==1){
ui->plotString->insertItem(0,selectedItems.at(0)->text(0));
ui->plotString->setCurrentIndex(0);
on_plot_clicked();
}
if(selectedItems.count()==2){
ui->plotString->insertItem(0,selectedItems.at(1)->text(0).append(":").append(selectedItems.at(0)->text(0)));
ui->plotString->setCurrentIndex(0);
on_plot_clicked();
}
}
}
void IROOT::on_addNewCanvas_clicked()
{
AddCanvas("",ui->canvasRows->value(),ui->canvasColumns->value());
ui->mainStackedWidget->setCurrentWidget(ui->workingPage);
}
void IROOT::on_canvasRows_valueChanged(int arg1)
{
if(gPad!=NULL){
gPad->GetCanvas()->Clear();
gPad->GetCanvas()->Divide(arg1,ui->canvasColumns->value());
gPad->GetCanvas()->Update();
gPad->cd(1);
gPad->SetLogx(ui->logX->isChecked());
gPad->SetLogy(ui->logY->isChecked());
gPad->SetGridx(ui->gridX->isChecked());
gPad->SetGridy(ui->gridY->isChecked());
}