ComparisonBox.cxx
Go to the documentation of this file.
2 #include <iostream>
3 #include "TGButton.h"
4 #include "TGListBox.h"
5 #include "TGTextEntry.h"
6 #include "TGFileDialog.h"
12 using namespace om;
13 
14 ComparisonBox::ComparisonBox(const TGWindow* win,
15  unsigned int w,
16  unsigned int h,
17  unsigned int opt) :
18  TGCompositeFrame(win, w, h, opt),
20 {
21  TGLayoutHints* xx = new TGLayoutHints(kLHintsExpandX);
22 
23  fCompareWhichFrame = new TGGroupFrame(this, "Comparison to...");
24  this->LayoutWhichFrame();
25  this->AddFrame(fCompareWhichFrame, xx);
26 
27  fCompareHowFrame = new TGGroupFrame(this, "Comparison method");
28  this->LayoutHowFrame();
29  this->AddFrame(fCompareHowFrame, xx);
30 
31  fCompareNormFrame = new TGGroupFrame(this, "Normalization method");
32  this->LayoutNormFrame();
33  this->AddFrame(fCompareNormFrame, xx);
34 
35  fApplyOptions = new TGTextButton(this, "Apply Options");
36  fApplyOptions->SetToolTipText("Apply chosen comparison options now");
37  fApplyOptions->Connect("Clicked()", "om::ComparisonBox",
38  this, "HandleApplyOptions()");
39  this->AddFrame(fApplyOptions, xx);
40 }
41 
42 //......................................................................
43 
45 {
46  unsigned int i;
47 
48  TGLayoutHints* fCompWhichLayout = new TGLayoutHints(kLHintsTop|kLHintsLeft);
49  for (i=0; i<ComparisonOptions::kMaxCompWhich; ++i) {
51  new TGRadioButton(fCompareWhichFrame,
53  i);
54  fCompareWhichButtons[i]->Connect("Clicked()",
55  "om::ComparisonBox",
56  this,
57  "HandleCompareWhichButtons()");
58  fCompareWhichFrame->AddFrame(fCompareWhichButtons[i],fCompWhichLayout);
59 
61  this->LayoutReferenceFile();
62  }
63 
65  this->LayoutRecent();
66  }
67 
68  }
69 }
70 
71 //......................................................................
72 
73 //
74 // Make a horizontal frame to hold the text and button
75 //
77 {
78  fReferenceFile = new TGHorizontalFrame(fCompareWhichFrame);
79 
80  //
81  // Layout the two widgets inside the horizontal frame
82  //
83  fReferenceFileText = new TGTextEntry(fReferenceFile);
84  fReferenceFileText->SetText("choose reference file");
85 
86  TGLayoutHints* xx = new TGLayoutHints(kLHintsExpandX);
87  fReferenceFile->AddFrame(fReferenceFileText, xx);
88 
89  TGLayoutHints* yy = new TGLayoutHints(kLHintsRight);
90  fReferenceFileBrowse = new TGPictureButton(fReferenceFile,
92  fReferenceFileBrowse->SetToolTipText("Browse to open a file");
93  fReferenceFileBrowse->Connect("Clicked()", "om::ComparisonBox",
94  this, "HandleFileBrowse()");
95  fReferenceFile->AddFrame(fReferenceFileBrowse, yy);
96 
97  fCompareWhichFrame->AddFrame(fReferenceFile, xx);
98 }
99 
100 //......................................................................
101 
103 {
104  fLookBack = new TGListBox(fCompareWhichFrame, 89);
105  fLookBack->Resize(30,60);
106 
107  TGLayoutHints* xx = new TGLayoutHints(kLHintsExpandX);
108  fCompareWhichFrame->AddFrame(fLookBack, xx);
109 }
110 
111 //......................................................................
112 
114 {
115  unsigned int i;
116 
117  TGLayoutHints* fCompHowLayout = new TGLayoutHints(kLHintsTop|kLHintsLeft);
118  for (i=0; i<ComparisonOptions::kMaxCompHow; ++i) {
120  new TGRadioButton(fCompareHowFrame,
122  i);
123  fCompareHowButtons[i]->Connect("Clicked()",
124  "om::ComparisonBox",
125  this,
126  "HandleCompareHowButtons()");
127  fCompareHowFrame->AddFrame(fCompareHowButtons[i],fCompHowLayout);
128  }
129 }
130 
131 //......................................................................
132 
134 {
135  unsigned int i;
136 
137  TGLayoutHints* fCompNormLayout = new TGLayoutHints(kLHintsTop|kLHintsLeft);
138  for (i=0; i<ComparisonOptions::kMaxCompNorm; ++i) {
140  new TGRadioButton(fCompareNormFrame,
142  i);
143  fCompareNormButtons[i]->Connect("Clicked()",
144  "om::ComparisonBox",
145  this,
146  "HandleCompareNormButtons()");
147  fCompareNormFrame->AddFrame(fCompareNormButtons[i],fCompNormLayout);
148  }
149 }
150 
151 //......................................................................
152 
154 {
155  if (id==-1) {
156  TGButton* btn = (TGButton*)gTQSender;
157  id = btn->WidgetId();
158  }
159 
161 }
162 
163 //......................................................................
164 
166 {
167  if (id==-1) {
168  TGButton* btn = (TGButton*)gTQSender;
169  id = btn->WidgetId();
170  }
171 
173 
174 }
175 
176 //......................................................................
177 
179 {
180  if (id==-1) {
181  TGButton* btn = (TGButton*)gTQSender;
182  id = btn->WidgetId();
183  }
184 
186 
187 }
188 
189 //......................................................................
190 
192 {
193  GUIModel::Instance().SetLookBack(fLookBack->GetSelected());
195 }
196 
197 //......................................................................
198 
200 {
201  const char *filetypes[] = { "All ROOT files", "*.root",
202  "End subrun files", "*endsubrun*.root",
203  "End run files", "*endrun*.root",
204  "All files", "*",
205  0, 0 };
206  TGFileInfo fi;
207  fi.fFileTypes = filetypes;
208 
209  ///\todo: Set the startup directory to an appropriate directory of reference files
210  fi.fIniDir = StrDup(".");
211  new TGFileDialog(gClient->GetRoot(), new TGMainFrame(gClient->GetRoot(), 400, 220), kFDOpen, &fi);
212  if(fi.fFilename != 0) {
213  printf("Open file: %s\n", fi.fFilename);
214  fReferenceFileText->SetText(fi.fFilename);
217  }
218 }
219 
220 //......................................................................
221 
223  unsigned int which)
224 {
225  if ( (which&kRefFileInitID) !=0 ) {
226  fReferenceFileText->SetText(om::GUIModel::Instance().Data().fComparisonOpt.fReferenceFile.c_str());
227  }
228 
229  if ( (which&kComparisonOptionsID) != 0 || (which&kRefFileInitID)!= 0 ) {
230  unsigned int i;
231  for (i=0; i<ComparisonOptions::kMaxCompWhich; ++i) {
232  if (m.fComparisonOpt.fWhich == i) {
233  fCompareWhichButtons[i]->SetState(kButtonDown);
234  }
235  else {
236  fCompareWhichButtons[i]->SetState(kButtonUp);
237  }
238  }
239 
240  for (i=0; i<ComparisonOptions::kMaxCompHow; ++i) {
241  if (m.fComparisonOpt.fMethod == i) {
242  fCompareHowButtons[i]->SetState(kButtonDown);
243  }
244  else {
245  fCompareHowButtons[i]->SetState(kButtonUp);
246  }
247  }
248 
249  for (i=0; i<ComparisonOptions::kMaxCompNorm; ++i) {
250  if (m.fComparisonOpt.fNormalize == i) {
251  fCompareNormButtons[i]->SetState(kButtonDown);
252  }
253  else {
254  fCompareNormButtons[i]->SetState(kButtonUp);
255  }
256  }
257  }
258 
259  if ( (which&kCurrentHistogramID)!=0 ) {
260  fLookBack->RemoveAll();
261  const HistoData* hd =
263  if (hd!=0) {
264  for (unsigned int i=0; i<hd->fLookBack; ++i) {
265  char buff[256];
266  sprintf(buff, "look back %d",i+1);
267  fLookBack->AddEntry(buff, i);
268  }
269  }
270  fLookBack->Layout();
271  }
272 }
273 
274 //......................................................................
275 
277 {
278 
279  unsigned int i;
280 
281  if(fCompareWhichFrame) {
282  delete fCompareWhichFrame;
283  fCompareWhichFrame = 0;
284  }
285  for (i=0; i<ComparisonOptions::kMaxCompWhich; ++i) {
286  if(fCompareWhichButtons[i]) {
287  delete fCompareWhichButtons[i];
288  fCompareWhichButtons[i] = 0;
289  }
290  }
291 
292  if(fReferenceFile) {
293  delete fReferenceFile;
294  fReferenceFile = 0;
295  }
296  if(fReferenceFileText) {
297  delete fReferenceFileText;
298  fReferenceFileText = 0;
299  }
301  delete fReferenceFileBrowse;
303  }
304 
305  if(fLookBack) {
306  delete fLookBack;
307  fLookBack = 0;
308  }
309 
310  if(fCompareHowFrame) {
311  delete fCompareHowFrame;
312  fCompareHowFrame = 0;
313  }
314  for (i=0; i<ComparisonOptions::kMaxCompHow; ++i) {
315  if(fCompareHowButtons[i]) {
316  delete fCompareHowButtons[i];
317  fCompareHowButtons[i] = 0;
318  }
319  }
320 
321  if(fCompareNormFrame) {
322  delete fCompareNormFrame;
323  fCompareNormFrame = 0;
324  }
325  for (i=0; i<ComparisonOptions::kMaxCompNorm; ++i) {
326  if(fCompareNormButtons[i]) {
327  delete fCompareNormButtons[i];
328  fCompareNormButtons[i] = 0;
329  }
330  }
331 
332  if(fApplyOptions) {
333  delete fApplyOptions;
334  fApplyOptions = 0;
335  }
336 
337 }
338 
339 ////////////////////////////////////////////////////////////////////////
unsigned int fLookBack
How many copies to save in history.
Definition: HistoData.h:43
void HandleCompareNormButtons(int i=-1)
unsigned int fWhich
Which histo. to compare to?
void HandleCompareWhichButtons(int i=-1)
Double_t xx
Definition: macro.C:12
void SetCompareNorm(unsigned int i)
Definition: GUIModel.cxx:181
const HistoData * LookUp(const char *nm) const
Definition: HistoTable.cxx:293
static const unsigned int kRefFileInitID
Definition: GUIModelData.h:28
static const unsigned int kCurrentHistogramID
Definition: GUIModelData.h:15
static const char * CompareTo(unsigned int i)
TGGroupFrame * fCompareHowFrame
Definition: ComparisonBox.h:54
void HandleCompareHowButtons(int i=-1)
void SetReferenceFile(const char *RefFile)
Definition: GUIModel.cxx:155
void SetCompareWhich(unsigned int i)
Definition: GUIModel.cxx:147
void SetLookBack(int lb)
Definition: GUIModel.cxx:163
Class to read, hold, and deliver histogram data.
void GUIModelDataIssue(const GUIModelData &m, unsigned int which)
static const unsigned int kComparisonUpdateID
Definition: GUIModelData.h:24
ComparisonOptions fComparisonOpt
Definition: GUIModelData.h:41
static GUIModel & Instance()
Definition: GUIModel.cxx:11
TGHorizontalFrame * fReferenceFile
Definition: ComparisonBox.h:48
printf("%d Experimental points found\n", nlines)
void Publish(unsigned int which) const
Definition: GUIModel.cxx:227
TGGroupFrame * fCompareNormFrame
Definition: ComparisonBox.h:57
ComparisonBox(const TGWindow *win, unsigned int w, unsigned int h, unsigned int opt)
unsigned int fMethod
How to show the comparison?
TGRadioButton * fCompareHowButtons[ComparisonOptions::kMaxCompHow]
Definition: ComparisonBox.h:55
static const char * CompareMethod(unsigned int i)
const char * Current() const
static const unsigned int kComparisonOptionsID
Definition: GUIModelData.h:21
TGRadioButton * fCompareWhichButtons[ComparisonOptions::kMaxCompWhich]
Definition: ComparisonBox.h:46
CurrentHistogram fCurrentHistogram
Definition: GUIModelData.h:37
const TGPicture * FolderExplore()
Definition: Icons.cxx:81
static const char * CompareNormalize(unsigned int i)
TGTextEntry * fReferenceFileText
Definition: ComparisonBox.h:49
void SetCompareMethod(unsigned int i)
Definition: GUIModel.cxx:173
TGRadioButton * fCompareNormButtons[ComparisonOptions::kMaxCompNorm]
Definition: ComparisonBox.h:58
TGGroupFrame * fCompareWhichFrame
Definition: ComparisonBox.h:45
TGPictureButton * fReferenceFileBrowse
Definition: ComparisonBox.h:50
static HistoTable & Instance(const char *f=0, Detector_t d=kALLDET)
Definition: HistoTable.cxx:21
unsigned int fNormalize
How to normalize the histos?
TH1F * hd
Definition: Xdiff_gwt.C:57
Float_t w
Definition: plot.C:20
TGListBox * fLookBack
Definition: ComparisonBox.h:52
Online Monitoring package header.
TGTextButton * fApplyOptions
Definition: ComparisonBox.h:60