-
Notifications
You must be signed in to change notification settings - Fork 13
/
panguinOnline.cc
1093 lines (960 loc) · 28.7 KB
/
panguinOnline.cc
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
///////////////////////////////////////////////////////////////////
// Macro to help with online analysis
// B. Moffit Oct. 2003
#include "panguinOnline.hh"
#include <string>
#include <fstream>
#include <iostream>
#include <list>
#include <TMath.h>
#include <TBranch.h>
#include <TGClient.h>
#include <TCanvas.h>
#include <TStyle.h>
#include <TROOT.h>
#include <TGImageMap.h>
#include <TGFileDialog.h>
#include <TKey.h>
#include <TSystem.h>
#include <TLatex.h>
#include <TText.h>
#include "TPaveText.h"
#include <TApplication.h>
//#define DEBUG
//#define DEBUG2
//#define NOISY
//#define OLDTIMERUPDATE
using namespace std;
///////////////////////////////////////////////////////////////////
// Class: OnlineGUI
//
// Creates a GUI to display the commands used in OnlineConfig
//
//
OnlineGUI::OnlineGUI(OnlineConfig& config, Bool_t printonly):
runNumber(0),
timer(0),
fFileAlive(kFALSE)
{
// Constructor. Get the config pointer, and make the GUI.
fConfig = &config;
if(printonly) {
fPrintOnly=kTRUE;
PrintPages();
} else {
fPrintOnly=kFALSE;
CreateGUI(gClient->GetRoot(),200,200);
}
}
void OnlineGUI::CreateGUI(const TGWindow *p, UInt_t w, UInt_t h)
{
// Open the RootFile. Die if it doesn't exist.
// unless we're watching a file.
fRootFile = new TFile(fConfig->GetRootFile(),"READ");
if(!fRootFile->IsOpen()) {
cout << "ERROR: rootfile: " << fConfig->GetRootFile()
<< " does not exist"
<< endl;
if(fConfig->IsMonitor()) {
cout << "Will wait... hopefully.." << endl;
} else {
gApplication->Terminate();
}
} else {
fFileAlive = kTRUE;
//ObtainRunNumber();//FIXME CG
// Open the Root Trees. Give a warning if it's not there..
GetFileObjects();
GetRootTree();
GetTreeVars();
for(UInt_t i=0; i<fRootTree.size(); i++) {
if(fRootTree[i]==0) {
fRootTree.erase(fRootTree.begin() + i);
}
}
}
TString goldenfilename=fConfig->GetGoldenFile();
if(!goldenfilename.IsNull()) {
fGoldenFile = new TFile(goldenfilename,"READ");
if(!fGoldenFile->IsOpen()) {
cout << "ERROR: goldenrootfile: " << goldenfilename
<< " does not exist. Oh well, no comparison plots."
<< endl;
doGolden = kFALSE;
fGoldenFile=NULL;
} else {
doGolden = kTRUE;
}
} else {
doGolden=kFALSE;
fGoldenFile=NULL;
}
// Create the main frame
fMain = new TGMainFrame(p,w,h);
fMain->Connect("CloseWindow()", "OnlineGUI", this, "MyCloseWindow()");
ULong_t lightgreen, lightblue, red, mainguicolor;
gClient->GetColorByName("lightgreen",lightgreen);
gClient->GetColorByName("lightblue",lightblue);
gClient->GetColorByName("red",red);
Bool_t good_color=kFALSE;
TString usercolor = fConfig->GetGuiColor();
if(!usercolor.IsNull()) {
good_color = gClient->GetColorByName(usercolor,mainguicolor);
}
if(!good_color) {
if(!usercolor.IsNull()) {
cout << "Bad guicolor (" << usercolor << ").. using default." << endl;
}
if(fConfig->IsMonitor()) {
// Default background color for Online Monitor
mainguicolor = lightgreen;
} else {
// Default background color for Normal Online Display
mainguicolor = lightblue;
}
}
fMain->SetBackgroundColor(mainguicolor);
// Top frame, to hold page buttons and canvas
fTopframe = new TGHorizontalFrame(fMain,200,200);
fTopframe->SetBackgroundColor(mainguicolor);
fMain->AddFrame(fTopframe, new TGLayoutHints(kLHintsExpandX
| kLHintsExpandY,10,10,10,1));
// Create a verticle frame widget with radio buttons
// This will hold the page buttons
vframe = new TGVerticalFrame(fTopframe,40,200);
vframe->SetBackgroundColor(mainguicolor);
TString buff;
for(UInt_t i=0; i<fConfig->GetPageCount(); i++) {
buff = fConfig->GetPageTitle(i);
fRadioPage[i] = new TGRadioButton(vframe,buff,i);
fRadioPage[i]->SetBackgroundColor(mainguicolor);
}
fRadioPage[0]->SetState(kButtonDown);
current_page = 0;
for (UInt_t i=0; i<fConfig->GetPageCount(); i++) {
vframe->AddFrame(fRadioPage[i], new TGLayoutHints(kLHintsLeft |
kLHintsCenterY,5,5,3,4));
fRadioPage[i]->Connect("Pressed()", "OnlineGUI", this, "DoRadio()");
}
if(!fConfig->IsMonitor()) {
wile =
new TGPictureButton(vframe,gClient->GetPicture(guiDirectory+"/genius.xpm"));
wile->Connect("Pressed()","OnlineGUI", this,"DoDraw()");
} else {
wile =
new TGPictureButton(vframe,gClient->GetPicture(guiDirectory+"/panguin.xpm"));
wile->Connect("Pressed()","OnlineGUI", this,"DoDrawClear()");
}
wile->SetBackgroundColor(mainguicolor);
vframe->AddFrame(wile,new TGLayoutHints(kLHintsBottom|kLHintsLeft,5,10,4,2));
fTopframe->AddFrame(vframe,new TGLayoutHints(kLHintsCenterX|
kLHintsCenterY,2,2,2,2));
// Create canvas widget
fEcanvas = new TRootEmbeddedCanvas("Ecanvas", fTopframe, 800, 600);
fEcanvas->SetBackgroundColor(mainguicolor);
fTopframe->AddFrame(fEcanvas, new TGLayoutHints(kLHintsExpandY,10,10,10,1));
fCanvas = fEcanvas->GetCanvas();
// Create the bottom frame. Contains control buttons
fBottomFrame = new TGHorizontalFrame(fMain,1200,200);
fBottomFrame->SetBackgroundColor(mainguicolor);
fMain->AddFrame(fBottomFrame, new TGLayoutHints(kLHintsExpandX,10,10,10,10));
// Create a horizontal frame widget with buttons
hframe = new TGHorizontalFrame(fBottomFrame,1200,40);
hframe->SetBackgroundColor(mainguicolor);
fBottomFrame->AddFrame(hframe,new TGLayoutHints(kLHintsExpandX,200,20,2,2));
fPrev = new TGTextButton(hframe,"Prev");
fPrev->SetBackgroundColor(mainguicolor);
fPrev->Connect("Clicked()","OnlineGUI",this,"DrawPrev()");
hframe->AddFrame(fPrev, new TGLayoutHints(kLHintsCenterX,5,5,1,1));
fNext = new TGTextButton(hframe,"Next");
fNext->SetBackgroundColor(mainguicolor);
fNext->Connect("Clicked()","OnlineGUI",this,"DrawNext()");
hframe->AddFrame(fNext, new TGLayoutHints(kLHintsCenterX,5,5,1,1));
fExit = new TGTextButton(hframe,"Exit GUI");
fExit->SetBackgroundColor(red);
fExit->Connect("Clicked()","OnlineGUI",this,"CloseGUI()");
hframe->AddFrame(fExit, new TGLayoutHints(kLHintsCenterX,5,5,1,1));
TString Buff;
if(runNumber==0) {
Buff = "";
} else {
Buff = "Run #";
Buff += runNumber;
}
TGString labelBuff(Buff);
fRunNumber = new TGLabel(hframe,Buff);
fRunNumber->SetBackgroundColor(mainguicolor);
hframe->AddFrame(fRunNumber,new TGLayoutHints(kLHintsCenterX,5,5,1,1));
fPrint = new TGTextButton(hframe,"Print To &File");
fPrint->SetBackgroundColor(mainguicolor);
fPrint->Connect("Clicked()","OnlineGUI",this,"PrintToFile()");
hframe->AddFrame(fPrint, new TGLayoutHints(kLHintsCenterX,5,5,1,1));
// Set a name to the main frame
if(fConfig->IsMonitor()) {
fMain->SetWindowName("Parity ANalysis GUI moNitor");
} else {
fMain->SetWindowName("Online Analysis GUI");
}
// Map all sub windows to main frame
fMain->MapSubwindows();
// Initialize the layout algorithm
fMain->Resize(fMain->GetDefaultSize());
// Map main frame
fMain->MapWindow();
#ifdef DEBUG
fMain->Print();
#endif
if(fFileAlive) DoDraw();
if(fConfig->IsMonitor()) {
timer = new TTimer();
if(fFileAlive) {
timer->Connect(timer,"Timeout()","OnlineGUI",this,"TimerUpdate()");
} else {
timer->Connect(timer,"Timeout()","OnlineGUI",this,"CheckRootFile()");
}
timer->Start(UPDATETIME);
}
}
void OnlineGUI::DoDraw()
{
// The main Drawing Routine.
gStyle->SetOptStat(1110);
gStyle->SetStatFontSize(0.1);
if (fConfig->IsLogy(current_page)) {
gStyle->SetOptLogy(1);
} else {
gStyle->SetOptLogy(0);
}
// gStyle->SetTitleH(0.10);
// gStyle->SetTitleW(0.40);
gStyle->SetTitleH(0.10);
gStyle->SetTitleW(0.60);
gStyle->SetStatH(0.70);
gStyle->SetStatW(0.35);
// gStyle->SetLabelSize(0.10,"X");
// gStyle->SetLabelSize(0.10,"Y");
gStyle->SetLabelSize(0.05,"X");
gStyle->SetLabelSize(0.05,"Y");
gStyle->SetPadLeftMargin(0.14);
gStyle->SetNdivisions(505,"X");
gStyle->SetNdivisions(404,"Y");
gROOT->ForceStyle();
// Determine the dimensions of the canvas..
UInt_t draw_count = fConfig->GetDrawCount(current_page);
if(draw_count>=8) {
gStyle->SetLabelSize(0.08,"X");
gStyle->SetLabelSize(0.08,"Y");
}
// Int_t dim = Int_t(round(sqrt(double(draw_count))));
pair <UInt_t,UInt_t> dim = fConfig->GetPageDim(current_page);
#ifdef DEBUG
cout << "Dimensions: " << dim.first << "X"
<< dim.second << endl;
#endif
// Create a nice clean canvas.
fCanvas->Clear();
fCanvas->Divide(dim.first,dim.second);
vector <TString> drawcommand(5);
// Draw the histograms.
for(UInt_t i=0; i<draw_count; i++) {
drawcommand = fConfig->GetDrawCommand(current_page,i);
fCanvas->cd(i+1);
if (drawcommand[0] == "macro") {
MacroDraw(drawcommand);
} else if (IsHistogram(drawcommand[0])) {
HistDraw(drawcommand);
} else {
TreeDraw(drawcommand);
}
}
fCanvas->cd();
fCanvas->Update();
if(!fPrintOnly) {
CheckPageButtons();
}
}
void OnlineGUI::DrawNext()
{
// Handler for the "Next" button.
fRadioPage[current_page]->SetState(kButtonUp);
// The following line triggers DoRadio(), or at least.. used to
fRadioPage[current_page+1]->SetState(kButtonDown);
current_page++;
DoDraw();
}
void OnlineGUI::DrawPrev()
{
// Handler for the "Prev" button.
fRadioPage[current_page]->SetState(kButtonUp);
// The following line triggers DoRadio(), or at least.. used to
fRadioPage[current_page-1]->SetState(kButtonDown);
current_page--;
DoDraw();
}
void OnlineGUI::DoRadio()
{
// Handle the radio buttons
// Find out which button has been pressed..
// turn off the previous button...
// then draw the appropriate page.
// This routine also handles the Draw from the Prev/Next buttons
// - makes a call to DoDraw()
UInt_t pagecount = fConfig->GetPageCount();
TGButton *btn = (TGButton *) gTQSender;
UInt_t id = btn->WidgetId();
if (id <= pagecount) {
fRadioPage[current_page]->SetState(kButtonUp);
}
current_page = id;
if(!fConfig->IsMonitor()) DoDraw();
}
void OnlineGUI::CheckPageButtons()
{
// Checks the current page to see if it's the first or last page.
// If so... turn off the appropriate button.
// If not.. turn on both buttons.
if(current_page==0) {
fPrev->SetState(kButtonDisabled);
if(fConfig->GetPageCount()!=1)
fNext->SetState(kButtonUp);
} else if(current_page==fConfig->GetPageCount()-1) {
fNext->SetState(kButtonDisabled);
if(fConfig->GetPageCount()!=1)
fPrev->SetState(kButtonUp);
} else {
fPrev->SetState(kButtonUp);
fNext->SetState(kButtonUp);
}
}
Bool_t OnlineGUI::IsHistogram(TString objectname)
{
// Utility to determine if the objectname provided is a histogram
for(UInt_t i=0; i<fileObjects.size(); i++) {
if (fileObjects[i].first.Contains(objectname)) {
#ifdef DEBUG2
cout << fileObjects[i].first << " "
<< fileObjects[i].second << endl;
#endif
if(fileObjects[i].second.Contains("TH"))
return kTRUE;
}
}
return kFALSE;
}
void OnlineGUI::GetFileObjects()
{
// Utility to find all of the objects within a File (TTree, TH1F, etc).
// The pair stored in the vector is <ObjName, ObjType>
// If there's no good keys.. do nothing.
#ifdef DEBUG
cout << "Keys = " << fRootFile->ReadKeys() << endl;
#endif
if(fRootFile->ReadKeys()==0) {
fUpdate = kFALSE;
// delete fRootFile;
// fRootFile = 0;
// CheckRootFile();
return;
}
fileObjects.clear();
TIter next(fRootFile->GetListOfKeys());
TKey *key = new TKey();
// Do the search
while((key=(TKey*)next())!=0) {
#ifdef DEBUG
cout << "Key = " << key << endl;
#endif
TString objname = key->GetName();
TString objtype = key->GetClassName();
#ifdef DEBUG
cout << objname << " " << objtype << endl;
#endif
fileObjects.push_back(make_pair(objname,objtype));
}
fUpdate = kTRUE;
delete key;
}
void OnlineGUI::GetTreeVars()
{
// Utility to find all of the variables (leaf's/branches) within a
// Specified TTree and put them within the treeVars vector.
treeVars.clear();
TObjArray *branchList;
vector <TString> currentTree;
for(UInt_t i=0; i<fRootTree.size(); i++) {
currentTree.clear();
branchList = fRootTree[i]->GetListOfBranches();
TIter next(branchList);
TBranch *brc;
while((brc=(TBranch*)next())!=0) {
TString found = brc->GetName();
// Not sure if the line below is so smart...
currentTree.push_back(found);
}
treeVars.push_back(currentTree);
}
#ifdef DEBUG2
for(UInt_t iTree=0; iTree<treeVars.size(); iTree++) {
cout << "In Tree " << iTree << ": " << endl;
for(UInt_t i=0; i<treeVars[iTree].size(); i++) {
cout << treeVars[iTree][i] << endl;
}
}
#endif
}
void OnlineGUI::GetRootTree() {
// Utility to search a ROOT File for ROOT Trees
// Fills the fRootTree vector
fRootTree.clear();
list <TString> found;
for(UInt_t i=0; i<fileObjects.size(); i++) {
#ifdef DEBUG2
cout << "Object = " << fileObjects[i].second <<
" Name = " << fileObjects[i].first << endl;
#endif
if(fileObjects[i].second.Contains("TTree"))
found.push_back(fileObjects[i].first);
}
// Remove duplicates, then insert into fRootTree
found.unique();
UInt_t nTrees = found.size();
for(UInt_t i=0; i<nTrees; i++) {
fRootTree.push_back((TTree*)fRootFile->Get(found.front()));
found.pop_front();
}
// Initialize the fTreeEntries vector
fTreeEntries.clear();
for(UInt_t i=0;i<fRootTree.size();i++) {
fTreeEntries.push_back(0);
}
}
UInt_t OnlineGUI::GetTreeIndex(TString var) {
// Utility to find out which Tree (in fRootTree) has the specified
// variable "var". If the variable is a collection of Tree
// variables (e.g. bcm1:lumi1), will only check the first
// (e.g. bcm1).
// Returns the correct index. if not found returns an index 1
// larger than fRootTree.size()
// This is for 2d draws... look for the first only
if(var.Contains(":")) {
TString first_var = fConfig->SplitString(var,":")[0];
var = first_var;
}
if(var.Contains("-")) {
TString first_var = fConfig->SplitString(var,"-")[0];
var = first_var;
}
if(var.Contains("/")) {
TString first_var = fConfig->SplitString(var,"/")[0];
var = first_var;
}
if(var.Contains("*")) {
TString first_var = fConfig->SplitString(var,"*")[0];
var = first_var;
}
if(var.Contains("+")) {
TString first_var = fConfig->SplitString(var,"+")[0];
var = first_var;
}
if(var.Contains("(")) {
TString first_var = fConfig->SplitString(var,"(")[0];
var = first_var;
}
// This is for variables with multiple dimensions.
if(var.Contains("[")) {
TString first_var = fConfig->SplitString(var,"[")[0];
var = first_var;
}
#ifdef OLD_GETTREEINDEX
TObjArray *branchList;
for(UInt_t i=0; i<fRootTree.size(); i++) {
branchList = fRootTree[i]->GetListOfBranches();
TIter next(branchList);
TBranch *brc;
while((brc=(TBranch*)next())!=0) {
TString found = brc->GetName();
if (found == var) {
return i;
}
}
}
#else
for(UInt_t iTree=0; iTree<treeVars.size(); iTree++) {
for(UInt_t ivar=0; ivar<treeVars[iTree].size(); ivar++) {
if(var == treeVars[iTree][ivar]) return iTree;
}
}
#endif
return fRootTree.size()+1;
}
UInt_t OnlineGUI::GetTreeIndexFromName(TString name) {
// Called by TreeDraw(). Tries to find the Tree index provided the
// name. If it doesn't match up, return a number that's one larger
// than the number of found trees.
for(UInt_t iTree=0; iTree<fRootTree.size(); iTree++) {
TString treename = fRootTree[iTree]->GetName();
if(name == treename) {
return iTree;
}
}
return fRootTree.size()+1;
}
void OnlineGUI::MacroDraw(vector <TString> command) {
// Called by DoDraw(), this will make a call to the defined macro, and
// plot it in it's own pad. One plot per macro, please.
if(command[1].IsNull()) {
cout << "macro command doesn't contain a macro to execute" << endl;
return;
}
if(doGolden) fRootFile->cd();
gROOT->Macro(command[1]);
}
void OnlineGUI::DoDrawClear() {
// Utility to grab the number of entries in each tree. This info is
// then used, if watching a file, to "clear" the TreeDraw
// histograms, and begin looking at new data.
for(UInt_t i=0; i<fTreeEntries.size(); i++) {
fTreeEntries[i] = (Int_t) fRootTree[i]->GetEntries();
}
}
void OnlineGUI::TimerUpdate() {
// Called periodically by the timer, if "watchfile" is indicated
// in the config. Reloads the ROOT file, and updates the current page.
#ifdef DEBUG
cout << "Update Now" << endl;
#endif
#ifdef OLDTIMERUPDATE
fRootFile = new TFile(fConfig->GetRootFile(),"READ");
if(fRootFile->IsZombie()) {
cout << "New run not yet available. Waiting..." << endl;
fRootFile->Close();
delete fRootFile;
fRootFile = 0;
timer->Reset();
timer->Disconnect();
timer->Connect(timer,"Timeout()","OnlineGUI",this,"CheckRootFile()");
return;
}
// Update the runnumber
//ObtainRunNumber();//FIXME CG
if(runNumber != 0) {
TString rnBuff = "Run #";
rnBuff += runNumber;
fRunNumber->SetText(rnBuff.Data());
hframe->Layout();
}
// Open the Root Trees. Give a warning if it's not there..
GetFileObjects();
if (fUpdate) { // Only do this stuff if their are valid keys
GetRootTree();
GetTreeVars();
for(UInt_t i=0; i<fRootTree.size(); i++) {
if(fRootTree[i]==0) {
fRootTree.erase(fRootTree.begin() + i);
}
}
DoDraw();
}
fRootFile->Close();
fRootFile->Delete();
delete fRootFile;
fRootFile = 0;
#else
if(fRootFile->IsZombie() || (fRootFile->GetSize() == -1)
|| (fRootFile->ReadKeys()==0)) {
cout << "New run not yet available. Waiting..." << endl;
fRootFile->Close();
delete fRootFile;
fRootFile = 0;
timer->Reset();
timer->Disconnect();
timer->Connect(timer,"Timeout()","OnlineGUI",this,"CheckRootFile()");
return;
}
for(UInt_t i=0; i<fRootTree.size(); i++) {
fRootTree[i]->Refresh();
}
DoDraw();
timer->Reset();
#endif
}
void OnlineGUI::BadDraw(TString errMessage) {
// Routine to display (in Pad) why a particular draw method has
// failed.
TPaveText *pt = new TPaveText(0.1,0.1,0.9,0.9,"brNDC");
pt->SetBorderSize(3);
pt->SetFillColor(10);
pt->SetTextAlign(22);
pt->SetTextFont(72);
pt->SetTextColor(2);
pt->AddText(errMessage.Data());
pt->Draw();
// cout << errMessage << endl;
}
void OnlineGUI::CheckRootFile() {
// Check the path to the rootfile (should follow symbolic links)
// ... If found:
// Reopen new root file,
// Reconnect the timer to TimerUpdate()
if(gSystem->AccessPathName(fConfig->GetRootFile())==0) {
cout << "Found the new run" << endl;
#ifndef OLDTIMERUPDATE
if(OpenRootFile()==0) {
#endif
timer->Reset();
timer->Disconnect();
timer->Connect(timer,"Timeout()","OnlineGUI",this,"TimerUpdate()");
#ifndef OLDTIMERUPDATE
}
#endif
} else {
TString rnBuff = "Waiting for run";
fRunNumber->SetText(rnBuff.Data());
hframe->Layout();
}
}
Int_t OnlineGUI::OpenRootFile() {
fRootFile = new TFile(fConfig->GetRootFile(),"READ");
if(fRootFile->IsZombie() || (fRootFile->GetSize() == -1)
|| (fRootFile->ReadKeys()==0)) {
cout << "New run not yet available. Waiting..." << endl;
fRootFile->Close();
delete fRootFile;
fRootFile = 0;
timer->Reset();
timer->Disconnect();
timer->Connect(timer,"Timeout()","OnlineGUI",this,"CheckRootFile()");
return -1;
}
// Update the runnumber
//ObtainRunNumber();//FIXME cg
if(runNumber != 0) {
TString rnBuff = "Run #";
rnBuff += runNumber;
fRunNumber->SetText(rnBuff.Data());
hframe->Layout();
}
// Open the Root Trees. Give a warning if it's not there..
GetFileObjects();
if (fUpdate) { // Only do this stuff if their are valid keys
GetRootTree();
GetTreeVars();
for(UInt_t i=0; i<fRootTree.size(); i++) {
if(fRootTree[i]==0) {
fRootTree.erase(fRootTree.begin() + i);
}
}
DoDraw();
} else {
return -1;
}
return 0;
}
void OnlineGUI::HistDraw(vector <TString> command) {
// Called by DoDraw(), this will plot a histogram.
Bool_t showGolden=kFALSE;
if(doGolden) showGolden=kTRUE;
if(command.size()==2)
if(command[1]=="noshowgolden") {
showGolden = kFALSE;
}
cout<<"showGolden= "<<showGolden<<endl;
// Determine dimensionality of histogram
for(UInt_t i=0; i<fileObjects.size(); i++) {
if (fileObjects[i].first.Contains(command[0])) {
if(fileObjects[i].second.Contains("TH1")) {
if(showGolden) fRootFile->cd();
mytemp1d = (TH1D*)gDirectory->Get(command[0]);
if(mytemp1d->GetEntries()==0) {
BadDraw("Empty Histogram");
} else {
if(showGolden) {
fGoldenFile->cd();
mytemp1d_golden = (TH1D*)gDirectory->Get(command[0]);
mytemp1d_golden->SetLineColor(30);
mytemp1d_golden->SetFillColor(30);
Int_t fillstyle=3027;
if(fPrintOnly) fillstyle=3010;
mytemp1d_golden->SetFillStyle(fillstyle);
mytemp1d_golden->Draw();
cout<<"one golden histo drawn"<<endl;
mytemp1d->Draw("sames");
} else {
mytemp1d->Draw();
}
}
break;
}
if(fileObjects[i].second.Contains("TH2")) {
if(showGolden) fRootFile->cd();
mytemp2d = (TH2D*)gDirectory->Get(command[0]);
if(mytemp2d->GetEntries()==0) {
BadDraw("Empty Histogram");
} else {
// These are commented out for some reason (specific to DVCS?)
// if(showGolden) {
// fGoldenFile->cd();
// mytemp2d_golden = (TH2D*)gDirectory->Get(command[0]);
// mytemp2d_golden->SetMarkerColor(2);
// mytemp2d_golden->Draw();
//mytemp2d->Draw("sames");
// } else {
mytemp2d->Draw();
// }
}
break;
}
if(fileObjects[i].second.Contains("TH3")) {
if(showGolden) fRootFile->cd();
mytemp3d = (TH3D*)gDirectory->Get(command[0]);
if(mytemp3d->GetEntries()==0) {
BadDraw("Empty Histogram");
} else {
mytemp3d->Draw();
if(showGolden) {
fGoldenFile->cd();
mytemp3d_golden = (TH3D*)gDirectory->Get(command[0]);
mytemp3d_golden->SetMarkerColor(2);
mytemp3d_golden->Draw();
mytemp3d->Draw("sames");
} else {
mytemp3d->Draw();
}
}
break;
}
}
}
}
void OnlineGUI::TreeDraw(vector <TString> command) {
// Called by DoDraw(), this will plot a Tree Variable
TString var = command[0];
// Combine the cuts (definecuts and specific cuts)
TCut cut = "";
TString tempCut;
if(command.size()>1) {
tempCut = command[1];
vector <TString> cutIdents = fConfig->GetCutIdent();
for(UInt_t i=0; i<cutIdents.size(); i++) {
if(tempCut.Contains(cutIdents[i])) {
TString cut_found = (TString)fConfig->GetDefinedCut(cutIdents[i]);
tempCut.ReplaceAll(cutIdents[i],cut_found);
}
}
cut = (TCut)tempCut;
}
// Determine which Tree the variable comes from, then draw it.
UInt_t iTree;
if(command[4].IsNull()) {
iTree = GetTreeIndex(var);
} else {
iTree = GetTreeIndexFromName(command[4]);
}
TString drawopt = command[2];
Int_t errcode=0;
if(drawopt.IsNull() && var.Contains(":")) drawopt = "box";
if(drawopt=="scat") drawopt = "";
if (iTree <= fRootTree.size() ) {
errcode = fRootTree[iTree]->Draw(var,cut,drawopt,
1000000000,fTreeEntries[iTree]);
TObject *hobj = (TObject*)gROOT->FindObject("htemp");
if(errcode==-1) {
BadDraw(var+" not found");
} else if (errcode!=0) {
if(!command[3].IsNull()) {
TH1* thathist = (TH1*)hobj;
thathist->SetTitle(command[3]);
}
} else {
BadDraw("Empty Histogram");
}
} else {
BadDraw(var+" not found");
if (fConfig->IsMonitor()){
// Maybe we missed it... look again. I dont like the code
// below... maybe I can come up with something better
GetFileObjects();
GetRootTree();
GetTreeVars();
}
}
}
void OnlineGUI::PrintToFile()
{
// Routine to print the current page to a File.
// A file dialog pops up to request the file name.
fCanvas = fEcanvas->GetCanvas();
gStyle->SetPaperSize(20,24);
static TString dir("printouts");
TGFileInfo fi;
const char *myfiletypes[] =
{ "All files","*",
"Portable Document Format","*.pdf",
"PostScript files","*.ps",
"Encapsulated PostScript files","*.eps",
"GIF files","*.gif",
"JPG files","*.jpg",
0, 0 };
fi.fFileTypes = myfiletypes;
fi.fIniDir = StrDup(dir.Data());
new TGFileDialog(gClient->GetRoot(), fMain, kFDSave, &fi);
if(fi.fFilename!=NULL) fCanvas->Print(fi.fFilename);
}
void OnlineGUI::PrintPages() {
// Routine to go through each defined page, and print the output to
// a postscript file. (good for making sample histograms).
// Open the RootFile
// unless we're watching a file.
fRootFile = new TFile(fConfig->GetRootFile(),"READ");
if(!fRootFile->IsOpen()) {
cout << "ERROR: rootfile: " << fConfig->GetRootFile()
<< " does not exist"
<< endl;
gApplication->Terminate();
} else {
fFileAlive = kTRUE;
//ObtainRunNumber();//FIXME cg
// Open the Root Trees. Give a warning if it's not there..
GetFileObjects();
GetRootTree();
GetTreeVars();
for(UInt_t i=0; i<fRootTree.size(); i++) {
if(fRootTree[i]==0) {
fRootTree.erase(fRootTree.begin() + i);
}
}
}
TString goldenfilename=fConfig->GetGoldenFile();
if(!goldenfilename.IsNull()) {
fGoldenFile = new TFile(goldenfilename,"READ");
if(!fGoldenFile->IsOpen()) {
cout << "ERROR: goldenrootfile: " << goldenfilename
<< " does not exist. Oh well, no comparison plots."
<< endl;
doGolden = kFALSE;
fGoldenFile=NULL;
} else {
doGolden = kTRUE;
}
} else {
doGolden=kFALSE;
fGoldenFile=NULL;
}
// Added this decision to make reasonable aspect ration for web content
// if (confFileName) {
fCanvas = new TCanvas("fCanvas","trythis",1000,800);
// } else {
// I'm not sure exactly how this works. But it does.
// fCanvas = new TCanvas("fCanvas","trythis",850,1100);
// }
// TCanvas *maincanvas = new TCanvas("maincanvas","whatever",850,1100);
// maincanvas->SetCanvas(fCanvas);
TLatex *lt = new TLatex();
TString plotsdir = fConfig->GetPlotsDir();
Bool_t useGIF = kFALSE;
if(!plotsdir.IsNull()) useGIF = kTRUE;
TString filename = "summaryplots";
if(runNumber!=0) {
filename += "_";
filename += runNumber;
} else {
printf(" Warning for pretty plots: runNumber = %i\n",runNumber);
}
if(useGIF) {
filename.Prepend(plotsdir+"/");
filename += "_pageXXXX.gif";
}
else filename += ".pdf";
TString pagehead = "Summary Plots";
if(runNumber!=0) {
pagehead += "(Run #";
pagehead += runNumber;
pagehead += ")";
}