Newer
Older
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
///////////////////////////////////////////////////////////////////
// Macro to help with online analysis
// B. Moffit (moffit@jlab.org)
// - Originally written in Oct. 2003
// Documentation and updates available at:
// http://www.jlab.org/~moffit/onlineGUI/
//
#include "online.h"
#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 <TObjString.h>
#include <TSystem.h>
#include <TLatex.h>
#include <TText.h>
#include <TGraph.h>
#include "GetRootFileName.C"
#include "GetRunNumber.C"
#include "TPaveText.h"
#ifdef STANDALONE
#include <TApplication.h>
#endif
// #define DEBUGGETFILEOBJECTS
// #define DEBUGPARSE
// #define DEBUG
//#define DEBUG2
//#define NOISY
//#define INTERNALSTYLE
//TString guiDirectory = "onlineGUI_v1.2.1/";
TString guiDirectory = "./";
///////////////////////////////////////////////////////////////////
// Class: OnlineConfig
//
// Utility class that reads in a text file (.cfg) and
// stores it's contents.
//
//
OnlineConfig::OnlineConfig()
{
// Constructor. Without an argument, will use default "standard" config
fMonitor = kFALSE;
OnlineConfig("standard");
}
OnlineConfig::OnlineConfig(TString anatype)
{
// Constructor. Takes the config anatype as the only argument.
// Loads up the configuration file, and stores it's contents for access.
confFileName = anatype;
configfilestart=anatype;
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
if(!confFileName.Contains(".cfg"))
confFileName += ".cfg";
fMonitor = kFALSE;
fFoundCfg = kFALSE;
// Attempt to find the config file in specified (first argument,
// relative or absolute) location, then in guiDirectory
fConfFile = new ifstream(confFileName.Data());
if ( ! (*fConfFile) ) {
cerr << "OnlineConfig() WARNING: config file " << confFileName.Data()
<< " does not exist" << endl;
cerr << " Checking the " << guiDirectory << " directory" << endl;
confFileName.Prepend(guiDirectory+"/");
fConfFile = new ifstream(confFileName.Data());
if ( ! (*fConfFile) ) {
// Didn't find it... load up the default config
confFileName = guiDirectory+"/default.cfg";
cout << "OnlineConfig() Trying " << confFileName.Data()
<< " as default configuration." << endl
<< " (May be ok.)" << endl;
fConfFile = new ifstream(confFileName.Data());
if ( ! (*fConfFile) ) {
cerr << "OnlineConfig() WARNING: no file "
<< confFileName.Data() <<endl;
cerr << "You need a configuration to run. Ask an expert."<<endl;
fFoundCfg = kFALSE;
// return;
} else {
fFoundCfg = kTRUE;
}
} else {
fFoundCfg = kTRUE;
}
} else {
fFoundCfg = kTRUE;
}
if(fFoundCfg) {
clog << "GUI Configuration loading from "
<< confFileName.Data() << endl;
}
ParseFile();
// Load up a user configurable style (if it exists)
TString styleFile = guiDirectory+"onlineGUI_Style.C";
if(!gSystem->AccessPathName(styleFile))
gROOT->Macro(styleFile);
fConfFile->close();
delete fConfFile;
}
void OnlineConfig::ParseFile()
{
// Reads in the Config File, and makes the proper calls to put
// the information contained into memory.
if(!fFoundCfg) {
return;
}
TString comment = "#";
vector<TString> strvect;
TString sinput, sline;
while (sline.ReadLine(*fConfFile)) {
strvect.clear();
// Strip away leading and trailing spaces.
sline = sline.Strip(TString::kBoth,' ');
// If the line starts with a comment, skip it.
if(sline.BeginsWith(comment)) continue;
// If the line contains a comment, split it up into two and keep
// the uncommented (first) part
if(sline.Contains(comment)) {
TObjArray *tmpoarr = sline.Tokenize(comment);
TObjString *tmpostr = (TObjString*)tmpoarr->First();
sline = tmpostr->GetString().Strip(TString::kTrailing,' ');
delete tmpoarr;
}
// Now split up the line according to 's and spaces. This is for
// looking for the histogram using it's title (which may contain
// spaces) instead of its name.
if(sline.Contains("'")) {
TObjArray *tmpoarr = sline.Tokenize("'");
Bool_t quote_on_odd = kTRUE;
if(!(sline.BeginsWith("'"))) quote_on_odd=kFALSE;
TIterator *next = tmpoarr->MakeIterator();
TObjString *tmpostr; Bool_t odd=kTRUE;
while((tmpostr=(TObjString*)next->Next())!=NULL) {
if((quote_on_odd&&odd) || (!quote_on_odd&&!odd)) {
strvect.push_back(tmpostr->GetString());
odd = !odd;
} else {
TObjArray *tmpoarr2 = tmpostr->GetString().Tokenize(" ");
TIterator *next2 = tmpoarr2->MakeIterator();
TObjString *tmpostr2;
while((tmpostr2=(TObjString*)next2->Next())!=NULL) {
strvect.push_back(tmpostr2->GetString());
}
delete tmpoarr2;
odd = !odd;
}
}
delete tmpoarr;
} else { // No 's.. just split according to spaces
TObjArray *tmpoarr2 = sline.Tokenize(" ");
TIterator *next2 = tmpoarr2->MakeIterator();
TObjString *tmpostr2;
while((tmpostr2=(TObjString*)next2->Next())!=NULL) {
strvect.push_back(tmpostr2->GetString());
}
delete tmpoarr2;
}
sConfFile.push_back(strvect);
}
#ifdef DEBUGPARSE
for(UInt_t ii=0; ii<sConfFile.size(); ii++) {
cout << "Line " << ii << endl << " ";
for(UInt_t jj=0; jj<sConfFile[ii].size(); jj++)
cout << sConfFile[ii][jj] << " ";
cout << endl;
}
#endif
cout << " " << sConfFile.size() << " lines read from "
<< confFileName << endl;
}
Bool_t OnlineConfig::ParseConfig()
{
// Goes through each line of the config [must have been ParseFile()'d]
// and interprets.
if(!fFoundCfg) {
return kFALSE;
}
UInt_t command_cnt=0;
UInt_t j=0;
Bool_t hasMultiPlots=kFALSE;
canvaswidth = 800; // Default canvas size
canvasheight = 600;
// If statement for each high level command (cut, newpage, etc)
for(UInt_t i=0;i<sConfFile.size();i++) {
// "newpage" command
if(sConfFile[i][0] == "newpage") {
// sConfFile[i] is first of pair
for(j=i+1;j<sConfFile.size();j++) {
if(sConfFile[j][0] != "newpage") {
// Count how many commands within the page
command_cnt++;
} else break;
}
pageInfo.push_back(make_pair(i,command_cnt));
i += command_cnt;
command_cnt=0;
}
if(sConfFile[i][0] == "watchfile") {
fMonitor = kTRUE;
}
if(sConfFile[i][0] == "definecut") {
if(sConfFile[i].size()>3) {
cerr << "cut command has too many arguments" << endl;
continue;
}
TCut tempCut(sConfFile[i][1],sConfFile[i][2]);
cutList.push_back(tempCut);
}
if(sConfFile[i][0] == "rootfile") {
if(sConfFile[i].size() != 2) {
cerr << "WARNING: rootfile command does not have the "
<< "correct number of arguments"
<< endl;
continue;
}
if(!rootfilename.IsNull()) {
cerr << "WARNING: too many rootfile's defined. "
<< " Will only use the first one."
<< endl;
continue;
}
rootfilename = sConfFile[i][1];
}
if(sConfFile[i][0] == "goldenrootfile") {
if(sConfFile[i].size() != 2) {
cerr << "WARNING: goldenfile command does not have the "
<< "correct number of arguments"
<< endl;
continue;
}
if(!goldenrootfilename.IsNull()) {
cerr << "WARNING: too many goldenrootfile's defined. "
<< " Will only use the first one."
<< endl;
continue;
}
goldenrootfilename = sConfFile[i][1];
}
if(sConfFile[i][0] == "protorootfile") {
if(sConfFile[i].size() != 2) {
cerr << "WARNING: protorootfile command does not have the "
<< "correct number of arguments"
<< endl;
continue;
}
if(!protorootfile.IsNull()) {
cerr << "WARNING: too many protorootfile's defined. "
<< " Will only use the first one."
<< endl;
continue;
}
protorootfile = sConfFile[i][1];
}
if(sConfFile[i][0] == "guicolor") {
if(sConfFile[i].size() != 2) {
cerr << "WARNING: guicolor command does not have the "
<< "correct number of arguments (needs 1)"
<< endl;
continue;
}
if(!guicolor.IsNull()) {
cerr << "WARNING: too many guicolor's defined. "
<< " Will only use the first one."
<< endl;
continue;
}
guicolor = sConfFile[i][1];
}
if(sConfFile[i][0] == "canvassize") {
if(sConfFile[i].size() != 3) {
cerr << "WARNING: canvassize command does not have the "
<< "correct number of arguments (needs 2)"
<< endl;
continue;
}
canvaswidth = UInt_t(atoi(sConfFile[i][1]));
canvasheight = UInt_t(atoi(sConfFile[i][2]));
}
if(sConfFile[i][0] == "plotsdir") {
if(sConfFile[i].size() != 2) {
cerr << "WARNING: plotsdir command does not have the "
<< "correct number of arguments (needs 1)"
<< endl;
continue;
}
if(!plotsdir.IsNull()) {
cerr << "WARNING: too many plotdir's defined. "
<< " Will only use the first one."
<< endl;
continue;
}
plotsdir = sConfFile[i][1];
}
if(sConfFile[i][0] == "multiplot") {
hasMultiPlots = kTRUE;
}
}
if(hasMultiPlots) {
if(!ParseForMultiPlots()) {
cerr << "ParseForMultiPlots() Failed" << endl;
}
}
#ifdef NOISY
for(UInt_t i=0; i<GetPageCount(); i++) {
cout << "Page " << i << " (" << GetPageTitle(i) << ")"
<< " will draw " << GetDrawCount(i)
<< " histograms." << endl;
}
#endif
cout << "Number of pages defined = " << GetPageCount() << endl;
cout << "Number of cuts defined = " << cutList.size() << endl;
if (fMonitor)
cout << "Will periodically update plots" << endl;
if(!goldenrootfilename.IsNull()) {
cout << "Will compare chosen histrograms with the golden rootfile: "
<< endl
<< goldenrootfilename << endl;
}
return kTRUE;
}
Bool_t OnlineConfig::ParseForMultiPlots() {
// Parse through each line of sConfFile,
// and replace each "multiplot" command with a real draw entry
vector < vector <TString> > newConfFile;
for(UInt_t iter=0;iter<sConfFile.size();iter++) {
if(sConfFile[iter][0]=="multiplot") {
// First argument is the low limit,
// second argument is the high limit
UInt_t lolimit = (UInt_t)sConfFile[iter][1].Atoi();
UInt_t hilimit = (UInt_t)sConfFile[iter][2].Atoi();
// For the rest of the line, replace all of the XXXXX's
// with an iteration from lolimit to hilimit.
for(UInt_t imult=lolimit;imult<=hilimit;imult++) {
vector <TString> newline;
for(UInt_t ielem=3; ielem<sConfFile[iter].size();ielem++) {
TString origString = sConfFile[iter][ielem];
TString newString = origString;
newString.ReplaceAll("XXXXX",Form("%d",imult));
newline.push_back(newString);
}
newConfFile.push_back(newline);
}
} else {
newConfFile.push_back(sConfFile[iter]);
}
}
#ifdef DEBUG
for(UInt_t iter=0;iter<newConfFile.size();iter++) {
for(UInt_t iline=0;iline<newConfFile[iter].size();iline++) {
cout << newConfFile[iter][iline] << " ";
}
cout << endl;
}
#endif
// Out with the old, in with the new.
sConfFile.clear();
sConfFile = newConfFile;
// Now need to recalculate pageInfo.
UInt_t command_cnt=0;
UInt_t j=0;
pageInfo.clear();
// If statement for each high level command (cut, newpage, etc)
for(UInt_t i=0;i<sConfFile.size();i++) {
// "newpage" command
if(sConfFile[i][0] == "newpage") {
// sConfFile[i] is first of pair
for(j=i+1;j<sConfFile.size();j++) {
if(sConfFile[j][0] != "newpage") {
// Count how many commands within the page
command_cnt++;
} else break;
}
pageInfo.push_back(make_pair(i,command_cnt));
i += command_cnt;
command_cnt=0;
}
}
return kTRUE;
}
TCut OnlineConfig::GetDefinedCut(TString ident) {
// Returns the defined cut, according to the identifier
for(UInt_t i=0; i<cutList.size(); i++) {
if((TString)cutList[i].GetName() == ident.Data()) {
TCut tempCut = cutList[i].GetTitle();
return tempCut;
}
}
return "";
}
vector <TString> OnlineConfig::GetCutIdent() {
// Returns a vector of the cut identifiers, specified in config
vector <TString> out;
for(UInt_t i=0; i<cutList.size(); i++) {
out.push_back(cutList[i].GetName());
}
return out;
}
Bool_t OnlineConfig::IsLogx(UInt_t page) {
// Check if last word on line is "logx"
UInt_t page_index = pageInfo[page].first;
Int_t word_index = sConfFile[page_index].size()-1;
if (word_index <= 0) return kFALSE;
TString option = sConfFile[page_index][word_index];
if(option == "logx") return kTRUE;
return kFALSE;
}
Bool_t OnlineConfig::IsLogy(UInt_t page) {
// Check if last word on line is "logy"
UInt_t page_index = pageInfo[page].first;
Int_t word_index = sConfFile[page_index].size()-1;
if (word_index <= 0) return kFALSE;
TString option = sConfFile[page_index][word_index];
if(option == "logy") return kTRUE;
return kFALSE;
}
Bool_t OnlineConfig::IsLogz(UInt_t page) {
// Check if last word on line is "logz"
UInt_t page_index = pageInfo[page].first;
Int_t word_index = sConfFile[page_index].size()-1;
if (word_index <= 0) return kFALSE;
TString option = sConfFile[page_index][word_index];
if(option == "logz") return kTRUE;
return kFALSE;
}
pair <UInt_t, UInt_t> OnlineConfig::GetPageDim(UInt_t page)
{
// If defined in the config, will return those dimensions
// for the indicated page. Otherwise, will return the
// calculated dimensions required to fit all histograms.
pair <UInt_t, UInt_t> outDim;
// This is the page index in sConfFile.
UInt_t page_index = pageInfo[page].first;
UInt_t size1 = 2;
Eric Pooser
committed
if (IsLogx(page)) size1 = 3; // last word is "logy"
Eric Pooser
committed
if (IsLogz(page)) size1 = 3; // last word is "logy"
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
// If the dimensions are defined, return them.
if(sConfFile[page_index].size()>size1-1) {
if(sConfFile[page_index].size() == size1) {
outDim = make_pair(UInt_t(atoi(sConfFile[page_index][1])),
UInt_t(atoi(sConfFile[page_index][1])));
return outDim;
} else if (sConfFile[page_index].size() == size1+1) {
outDim = make_pair(UInt_t(atoi(sConfFile[page_index][1])),
UInt_t(atoi(sConfFile[page_index][2])));
return outDim;
} else {
cout << "Warning: newpage command has too many arguments. "
<< "Will automatically determine dimensions of page."
<< endl;
}
}
// If not defined, return the "default."
UInt_t draw_count = GetDrawCount(page);
UInt_t dim = UInt_t(TMath::Nint(sqrt(double(draw_count+1))));
outDim = make_pair(dim,dim);
return outDim;
}
TString OnlineConfig::GetPageTitle(UInt_t page)
{
// Returns the title of the page.
// if it is not defined in the config, then return "Page #"
TString title;
UInt_t iter_command = pageInfo[page].first+1;
for(UInt_t i=0; i<pageInfo[page].second; i++) { // go through each command
if(sConfFile[iter_command+i][0] == "title") {
// Combine the strings, and return it
for (UInt_t j=1; j<sConfFile[iter_command+i].size(); j++) {
title += sConfFile[iter_command+i][j];
title += " ";
}
title.Chop();
return title;
}
}
title = "Page "; title += page;
return title;
}
vector <UInt_t> OnlineConfig::GetDrawIndex(UInt_t page)
{
// Returns an index of where to find the draw commands within a page
// within the sConfFile vector
vector <UInt_t> index;
UInt_t iter_command = pageInfo[page].first+1;
for(UInt_t i=0; i<pageInfo[page].second; i++) {
if(sConfFile[iter_command+i][0] != "title") {
index.push_back(iter_command+i);
}
}
return index;
}
UInt_t OnlineConfig::GetDrawCount(UInt_t page)
{
// Returns the number of histograms that have been request for this page
UInt_t draw_count=0;
for(UInt_t i=0; i<pageInfo[page].second; i++) {
if(sConfFile[pageInfo[page].first+i+1][0] != "title") draw_count++;
}
return draw_count;
}
drawcommand OnlineConfig::GetDrawCommand(UInt_t page, UInt_t nCommand)
{
// Returns the vector of strings pertaining to a specific page, and
// draw command from the config.
// Return vector of TStrings:
// 0: variable
// 1: cut - only for Tree variables
// 2: type
// 3: title
// 4: treename - only for Tree variables
// 5: nostat
// 6: noshowgolden - only for Histograms
// This should probably be replaced with an actual structure
drawcommand out_command;
vector <UInt_t> command_vector = GetDrawIndex(page);
UInt_t index = command_vector[nCommand];
#ifdef DEBUG
cout << "OnlineConfig::GetDrawCommand(" << page << ","
<< nCommand << ")" << endl;
#endif
// First line is the variable
if(sConfFile[index].size()>=1) {
out_command.variable = sConfFile[index][0];
}
if(sConfFile[index].size()>=2) {
if((sConfFile[index][1] != "-type") &&
(sConfFile[index][1] != "-title") &&
(sConfFile[index][1] != "-tree") &&
(sConfFile[index][1] != "-noshowgolden") &&
(sConfFile[index][1] != "-nostat")) {
if(out_command.variable=="macro") {
out_command.macro = sConfFile[index][1];
} else {
out_command.cut = sConfFile[index][1];
}
}
}
// Now go through the rest of that line..
for (UInt_t i=1; i<sConfFile[index].size(); i++) {
if(sConfFile[index][i]=="-type") {
out_command.type = sConfFile[index][i+1];
i = i+1;
} else if(sConfFile[index][i]=="-title") {
// Put the entire title, surrounded by quotes, as one TString
TString title;
UInt_t j=0;
for(j=i+1; j<sConfFile[index].size(); j++) {
TString word = sConfFile[index][j];
if( (word.BeginsWith("\"")) && (word.EndsWith("\"")) ) {
title = word.ReplaceAll("\"","");
out_command.title = title;
i = j;
break;
} else if(word.BeginsWith("\"")) {
title = word.ReplaceAll("\"","");
} else if(word.EndsWith("\"")) {
title += " " + word.ReplaceAll("\"","");
out_command.title = title;
i = j;
break;
} else {
title += " " + word;
}
}
// If we got here, and out_command.title is null... then just copy the contents
// of "title" to out_command.title (taking out any "'s along the way)
if(out_command.title.IsNull())
out_command.title = title.ReplaceAll("\"","");
} else if(sConfFile[index][i]=="-tree") {
out_command.treename = sConfFile[index][i+1];
i = i+1;
} else if(sConfFile[index][i]=="-nostat") {
out_command.nostat = "nostat";
} else if(sConfFile[index][i]=="-noshowgolden") {
out_command.noshowgolden = "noshowgolden";
}
#ifdef DEBUG
cout << endl;
#endif
}
#ifdef DEBUG
cout << sConfFile[index].size() << ": ";
for(UInt_t i=0; i<sConfFile[index].size(); i++) {
cout << sConfFile[index][i] << " ";
}
cout << endl;
#endif
return out_command;
}
vector <TString> OnlineConfig::SplitString(TString instring,TString delim)
{
// Utility to split up a string on the deliminator.
// returns a vector of strings.
vector <TString> v;
TString remainingString = instring;
TString tempstring = instring;
int i;
while (remainingString.Index(delim) != -1) {
i = remainingString.Index(delim);
tempstring.Remove(i);
v.push_back(tempstring);
remainingString.Remove(0,i+1);
while(remainingString.Index(delim) == 0) {
remainingString.Remove(0,1);
}
tempstring = remainingString;
// Cut out the rest, if it's a comment (starts with #)
if(TString(remainingString.Strip(TString::kLeading,' ')).BeginsWith("#")) {
tempstring = "";
break;
}
}
while(tempstring.EndsWith(delim)) {
tempstring.Chop();
}
if(!tempstring.IsNull()) v.push_back(tempstring);
return v;
}
void OnlineConfig::OverrideRootFile(UInt_t runnumber)
{
// Override the ROOT file defined in the cfg file If
// protorootfile is used, construct filename using it, otherwise
// uses a helper macro "GetRootFileName.C(UInt_t runnumber)
if(!protorootfile.IsNull()) {
TString rn = "";
rn += runnumber;
protorootfile.ReplaceAll("XXXXX",rn.Data());
rootfilename = protorootfile;
} else {
rootfilename = GetRootFileName(runnumber);
}
cout << "Overridden File name: " << rootfilename << endl;
}
///////////////////////////////////////////////////////////////////
// Class: OnlineGUI
//
// Creates a GUI to display the commands used in OnlineConfig
//
//
OnlineGUI::OnlineGUI(OnlineConfig& config, Bool_t printonly, Bool_t rootonly,UInt_t RunNum):
runNumber(RunNum),
timer(0),
fFileAlive(kFALSE)
{
// Constructor. Get the config pointer, and make the GUI.
fConfig = &config;
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
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.RootFile = new TFile(fConfig->GetRootFile(),"READ");
if(!fRootFile.RootFile->IsOpen()) {
cout << "ERROR: rootfile: " << fConfig->GetRootFile()
<< " does not exist"
<< endl;
if(fConfig->IsMonitor()) {
cout << "Will wait... hopefully.." << endl;
} else {
#ifdef STANDALONE
gApplication->Terminate();
#else
return;
#endif
}
} else {
fFileAlive = kTRUE;
ObtainRunNumber();
// Open the Root Trees. Give a warning if it's not there..
GetFileObjects(&fRootFile);
GetRootTree(&fRootFile);
GetTreeVars(&fRootFile);
for(UInt_t i=0; i<fRootFile.RootTree.size(); i++) {
if(fRootFile.RootTree[i]==0) {
fRootFile.RootTree.erase(fRootFile.RootTree.begin() + i);
}
}
}
TString goldenfilename=fConfig->GetGoldenFile();
if(!goldenfilename.IsNull()) {
fGoldenFile.RootFile = new TFile(goldenfilename,"READ");
if(!fGoldenFile.RootFile->IsOpen()) {
cout << "ERROR: goldenrootfile: " << goldenfilename
<< " does not exist. Oh well, no comparison plots."
<< endl;
doGolden = kFALSE;
fGoldenFile.RootFile=NULL;
} else {
// Open the Root Trees. Give a warning if it's not there..
GetFileObjects(&fGoldenFile);
GetRootTree(&fGoldenFile);
GetTreeVars(&fGoldenFile);
for(UInt_t i=0; i<fGoldenFile.RootTree.size(); i++) {
if(fGoldenFile.RootTree[i]==0) {
fGoldenFile.RootTree.erase(fGoldenFile.RootTree.begin() + i);
}
}
doGolden = kTRUE;
}
} else {
doGolden=kFALSE;
fGoldenFile.RootFile=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);
UInt_t canvas_width = fConfig->GetCanvasWidth();
UInt_t canvas_height = fConfig->GetCanvasHeight();
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+"/hcsmall.png"));
wile->Connect("Pressed()","OnlineGUI", this,"DoDraw()");
} else {
wile =
new TGPictureButton(vframe,
gClient->GetPicture(guiDirectory+"/panguin.xpm"));
wile->Connect("Pressed()","OnlineGUI", this,"DoDrawClear(&fRootFile)");
}
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, canvas_width, canvas_height);
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,canvas_width+400,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,canvas_width+400,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.
#ifdef INTERNALSTYLE
gStyle->SetOptStat(1110);
gStyle->SetStatFontSize(0.1);
#endif
if (fConfig->IsLogx(current_page)) {
gStyle->SetOptLogx(1);
} else {
gStyle->SetOptLogx(0);
}
if (fConfig->IsLogy(current_page)) {
gStyle->SetOptLogy(1);
} else {
gStyle->SetOptLogy(0);
}
if (fConfig->IsLogz(current_page)) {
gStyle->SetOptLogz(1);