AliPhysics  41af4b0 (41af4b0)
ForwardOADBGui.C
Go to the documentation of this file.
1 
2 #ifndef __CINT__
3 #include "AliOADBForward.h"
4 #include <TGListBox.h>
5 #include <TGNumberEntry.h>
6 #include <TGTextEntry.h>
7 #include <TGComboBox.h>
8 #include <TGFrame.h>
9 #include <TGFileDialog.h>
10 #include <TGButtonGroup.h>
11 #include <TGButton.h>
12 #include <TGLabel.h>
13 #include <TGMsgBox.h>
14 #include <TSystem.h>
15 #include <TError.h>
16 #include <TTimer.h>
17 #include <TCanvas.h>
18 #include <TTree.h>
19 #include <TGListView.h>
20 #include <TGStatusBar.h>
21 #include <TDatime.h>
22 #include <TParameter.h>
23 #include <TPaveText.h>
24 #include <TBrowser.h>
25 
26 namespace {
27  void
28  ForwardOADBGUIErrorHandler(Int_t lvl, Bool_t doAbort,
29  const char* location,
30  const char* msg)
31  {
32  if (!doAbort && lvl >= kWarning) {
33  EMsgBoxIcon msgIcon = kMBIconAsterisk;
34  // if (lvl >= kInfo) msgIcon = kMBIconAsterisk;
35  if (lvl >= kWarning) msgIcon = kMBIconExclamation;
36  if (lvl >= kError) msgIcon = kMBIconStop;
37 
38  new TGMsgBox(gClient->GetRoot(), gClient->GetRoot(),
39  location, msg, msgIcon);
40  }
41  DefaultErrorHandler(lvl, doAbort, location, msg);
42  }
43 }
44 #else
45 class AliOADBForward;
47 // #if 0
48 class TGTransientFrame;
49 class TGFrame;
50 class TGLVEntry;
51 class TGHorizontalFrame;
52 class TGTextButton;
53 class TGCheckButton;
54 class TGTextEntry;
55 class TGVerticalFrame;
56 class TGLabel;
57 class TGComboBox;
58 class TGMainFrame;
59 class TGListView;
60 class TGLVContainer;
61 class TGHButtonGroup;
62 class TGLayoutHints;
63 class TGNumberEntry;
64 class TGStatusBar;
65 // #endif
66 #endif
67 
69 {
70  ForwardOADBWait(TGMainFrame* p)
71  : fFrame(gClient->GetRoot(), p, 200, 40, kVerticalFrame),
72  fHints(kLHintsExpandX,30,30,30,30),
73  fLabel(&fFrame, ""),
74  // fProgress(&fFrame, 100),
75  fIsShown(false),
76  fIncrement(0,false)
77  {
78  fFrame.AddFrame(&fLabel, &fHints );
79  // fFrame.AddFrame(&fProgress, &fHints);
80  fFrame.SetWindowName("Please wait ...");
81  // fProgress.SetRange(0,1);
82  fIncrement.Connect("Timeout()","ForwardOADBWait",this,"HandleIncr()");
83  }
85  ForwardOADBWait& operator=(const ForwardOADBWait&) { return *this; }
86  void HandleIncr()
87  {
88  // Float_t dp = 0.1;
89  // Float_t p = fProgress.GetPosition();
90  // Info("HandleIncr", "Handing increment (%f)", p);
91  // if (p+dp >= 1) fProgress.SetPosition(0);
92  // fProgress.Increment(dp);
93  // fFrame.GetClient()->NeedRedraw(&fFrame);
94  }
95  void Show(const char* msg)
96  {
97  fLabel.SetText(msg);
98  // fProgress.SetPosition(0);
99  fFrame.MapSubwindows();
100  Int_t width = fFrame.GetDefaultWidth();
101  Int_t height = fFrame.GetDefaultHeight();
102  fFrame.Resize(width, height);
103  fFrame.SetWMSize(width, height);
104  fFrame.SetWMSizeHints(width, height, width, height, 0, 0);
105  fFrame.MapRaised();
106  fIsShown = true;
107  // fIncrement.Start(0,false);
108  fFrame.GetClient()->WaitForUnmap(&fFrame);
109  }
110  void Hide()
111  {
112  if (!fIsShown) return;
113  // fIncrement.Stop();
114  fFrame.UnmapWindow();
115  }
116  TGTransientFrame fFrame;
117  TGLayoutHints fHints;
118  TGLabel fLabel;
120  TTimer fIncrement;
121 
122 };
123 
125 {
126  enum {
127  kLabelWidth = 200
128  };
130  : fMain(gClient->GetRoot(), 10, 10, kVerticalFrame),
131  fOpenFrame(&fMain),
132  fFileText(&fOpenFrame, "fmd_corrections.root"),
133  fFileSelect(&fOpenFrame, "Browse"),
134  fTablesText(&fOpenFrame, "*"),
135  fOpenButton(&fOpenFrame, "Open"),
136  fRWButton(&fOpenFrame, "R/W"),
137  fCloseButton(&fOpenFrame, "Close"),
138  fSelectFrame(&fMain),
139  fTableFrame(&fSelectFrame),
140  fTableLabel(&fTableFrame, "Table: "),
141  fTableSelect(&fTableFrame),
142  fRunFrame(&fSelectFrame),
143  fRunLabel(&fRunFrame, "Run: "),
144  fRunInput(&fRunFrame, 0, 0, -1,
145  TGNumberFormat::kNESReal,
146  TGNumberFormat::kNEANonNegative,
147  TGNumberFormat::kNELLimitMin, 0),
148  fRunMode(&fRunFrame),
149  fSysFrame(&fSelectFrame),
150  fSysLabel(&fSysFrame, "System: "),
151  fSysSelect(&fSysFrame),
152  fSNNFrame(&fSelectFrame),
153  fSNNLabel(&fSNNFrame, "sqrt(sNN) [GeV]: "),
154  fSNNInput(&fSNNFrame, 0, 0, -1, TGNumberFormat::kNESReal,
155  TGNumberFormat::kNEANonNegative,
156  TGNumberFormat::kNELLimitMin, 0),
157  fFldFrame(&fSelectFrame),
158  fFldLabel(&fFldFrame, "L3 field [kG]: "),
159  fFldSelect(&fFldFrame),
160  fOtherFrame(&fSelectFrame),
161  fMCButton(&fOtherFrame, "MC"),
162  fSatButton(&fOtherFrame, "Satellite"),
163  fOptionsFrame(&fSelectFrame),
164  fOptionsLabel(&fOptionsFrame, "Draw/Print options:"),
165  fOptionsText(&fOptionsFrame, ""),
166  fCommandFrame(&fSelectFrame),
167  fQueryButton(&fCommandFrame, "Query"),
168  fListButton(&fCommandFrame, "List table"),
169  fPrintButton(&fCommandFrame, "Print entry"),
170  fCopyButton(&fCommandFrame, "Copy entry"),
171  fDrawButton(&fCommandFrame, "Draw entry"),
172  fPDFButton(&fCommandFrame, "Summarize entry"),
173  fList(&fMain, 800, 400),
174  fListContainer(&fList),
175  fFrameHints(kLHintsExpandX, 0, 0, 2, 0),
176  fLabelHints(kLHintsNoHints, 4, 2, 0, 0),
177  fEntryHints(kLHintsExpandX|kLHintsExpandY, 2, 4, 0, 0),
178  fButtonHints(kLHintsExpandX, 2, 2, 0, 0),
179  fListHints(kLHintsExpandX|kLHintsExpandY, 2, 2, 4, 2),
180  fStatusBar(&fMain),
181  fStatusBarHints(kLHintsExpandX, 2, 2, 4, 2),
182  fMsg(&fMain),
183  fDB(0),
184  fEntry(0)
185  {
186  fMain.Connect("CloseWindow()", "ForwardOADBGUI", this, "HandleKill()");
187  fMain.DontCallClose();
188 
189  fFileSelect.Connect("Clicked()", "ForwardOADBGUI", this, "HandleBrowse()");
190  fOpenButton.Connect("Clicked()", "ForwardOADBGUI", this, "HandleOpen()");
191  fCloseButton.Connect("Clicked()", "ForwardOADBGUI", this, "HandleClose()");
192  fMain.AddFrame(&fOpenFrame, &fFrameHints);
193  fOpenFrame.AddFrame(&fFileText, &fEntryHints);
194  fOpenFrame.AddFrame(&fFileSelect, &fEntryHints);
195  fOpenFrame.AddFrame(&fTablesText, &fEntryHints);
196  fOpenFrame.AddFrame(&fOpenButton, &fEntryHints);
197  fOpenFrame.AddFrame(&fRWButton, &fButtonHints);
198  fOpenFrame.AddFrame(&fCloseButton, &fEntryHints);
199 
200  fMain.AddFrame(&fSelectFrame, &fFrameHints);
201 
202  fTableLabel.SetWidth(kLabelWidth); fTableLabel.SetMinWidth(kLabelWidth);
203  fTableSelect.SetHeight(22);
204  fTableSelect.Connect("Selected(Int_t)","ForwardOADBGUI",this,
205  "HandleTable(Int_t)");
206  fSelectFrame.AddFrame(&fTableFrame, &fFrameHints);
207  fTableFrame.AddFrame(&fTableLabel, &fLabelHints);
208  fTableFrame.AddFrame(&fTableSelect, &fEntryHints);
209 
210  fRunLabel.SetWidth(kLabelWidth); fRunLabel.SetMinWidth(kLabelWidth);
211  fRunMode.AddEntry("default", 0);
212  fRunMode.AddEntry("Exact", 1);
213  fRunMode.AddEntry("Newest", 2);
214  fRunMode.AddEntry("Near", 3);
215  fRunMode.AddEntry("Older", 4);
216  fRunMode.AddEntry("Newer", 5);
217  fRunMode.SetHeight(22);
218  fSelectFrame.AddFrame(&fRunFrame, &fFrameHints);
219  fRunFrame.AddFrame(&fRunLabel, &fLabelHints);
220  fRunFrame.AddFrame(&fRunInput, &fEntryHints);
221  fRunFrame.AddFrame(&fRunMode, &fEntryHints);
222 
223  fSysLabel.SetWidth(kLabelWidth); fSysLabel.SetMinWidth(kLabelWidth);
224  fSysSelect.AddEntry("- select -", 0);
225  fSysSelect.AddEntry("p-p", 1);
226  fSysSelect.AddEntry("Pb-Pb ",2);
227  fSysSelect.AddEntry("p-Pb", 3);
228  fSysSelect.AddEntry("Pb-p", 4);
229  fSysSelect.AddEntry("Xe-Xe", 5);
230  fSysSelect.SetHeight(22);
231  fSelectFrame.AddFrame(&fSysFrame, &fFrameHints);
232  fSysFrame.AddFrame(&fSysLabel, &fLabelHints);
233  fSysFrame.AddFrame(&fSysSelect, &fEntryHints);
234 
235  fSNNLabel.SetWidth(kLabelWidth); fSNNLabel.SetMinWidth(kLabelWidth);
236  fSNNInput.SetHeight(22);
237  fSelectFrame.AddFrame(&fSNNFrame, &fFrameHints);
238  fSNNFrame.AddFrame(&fSNNLabel, &fLabelHints);
239  fSNNFrame.AddFrame(&fSNNInput, &fEntryHints);
240 
241  fFldLabel.SetWidth(kLabelWidth); fFldLabel.SetMinWidth(kLabelWidth);
242  fFldSelect.AddEntry("- select -", 999);
243  fFldSelect.AddEntry("-5", -5);
244  fFldSelect.AddEntry("-2", -2);
245  fFldSelect.AddEntry("0 ", 0);
246  fFldSelect.AddEntry("+2", +2);
247  fFldSelect.AddEntry("+5", +5);
248  fFldSelect.SetHeight(22);
249  fSelectFrame.AddFrame(&fFldFrame, &fFrameHints);
250  fFldFrame.AddFrame(&fFldLabel, &fLabelHints);
251  fFldFrame.AddFrame(&fFldSelect, &fEntryHints);
252 
253  fSelectFrame.AddFrame(&fOtherFrame, &fFrameHints);
254  fOtherFrame.SetLayoutHints(&fButtonHints);
255  fMCButton.AllowStayDown(true);
256  fSatButton.AllowStayDown(true);
257  // fOtherFrame.AddFrame(&fMCButton, &fEntryHints);
258  // fOtherFrame.AddFrame(&fSatButton, &fEntryHints);
259  // new TGCheckButton(&fOtherFrame, "MC:");
260  // new TGCheckButton(&fOtherFrame, "Satellite:");
261 
262  fOptionsLabel.SetWidth(2*kLabelWidth);
263  fSelectFrame.AddFrame(&fOptionsFrame, &fFrameHints);
264  fOptionsFrame.AddFrame(&fOptionsLabel, &fLabelHints);
265  fOptionsFrame.AddFrame(&fOptionsText, &fEntryHints);
266 
267  // Info("", "Connecting signals");
268  fQueryButton.Connect("Clicked()", "ForwardOADBGUI", this, "HandleQuery()");
269  fListButton.Connect("Clicked()", "ForwardOADBGUI", this, "HandleList()");
270  fDrawButton.Connect("Clicked()", "ForwardOADBGUI", this, "HandleDraw()");
271  fCopyButton.Connect("Clicked()", "ForwardOADBGUI", this, "HandleCopy()");
272  fPDFButton.Connect("Clicked()", "ForwardOADBGUI", this, "HandlePDF()");
273  fPrintButton.Connect("Clicked()", "ForwardOADBGUI", this, "HandlePrint()");
274  fSelectFrame.AddFrame(&fCommandFrame, &fFrameHints);
275  fCommandFrame.SetLayoutHints(&fButtonHints);
276 
277  // fList = new TGListView(&fMain, 800, 400);
278  // fListContainer = new TGLVContainer(fList);
279  fListContainer.SetColHeaders("Entry",
280  "Run",
281  "System",
282  "sqrt(sNN)",
283  "L3 Field",
284  "Type",
285  "IP",
286  "Date",
287  "Author",
288  "AliROOT",
289  "Data");
290  fList.SetViewMode(kLVDetails);
291  fList.Connect("Clicked(TGLVEntry*,Int_t)",
292  "ForwardOADBGUI", this, "HandleItem(TGLVEntry*,Int_t)");
293  fList.Connect("DoubleClicked(TGLVEntry*,Int_t)",
294  "ForwardOADBGUI", this, "HandleItem(TGLVEntry*,Int_t)");
295  fListContainer.Connect("Clicked(TGFrame*,Int_t)",
296  "ForwardOADBGUI", this,
297  "HandleItem(TGFrame*,Int_t)");
298  fList.SetMinWidth(400);
299  fList.SetMinHeight(200);
300  fMain.AddFrame(&fList, &fListHints);
301 
302  fStatusBar.SetParts(1);
303  fMain.AddFrame(&fStatusBar, &fStatusBarHints);
304 #ifndef __CINT__
305  ::SetErrorHandler(ForwardOADBGUIErrorHandler);
306 #endif
307  HandleEnable();
308 
309  fMain.SetMinWidth(600);
310  fMain.SetMinHeight(480);
311  fMain.MapSubwindows();
312  fMain.Resize(600, 480); // fMain.GetDefaultSize());
313  fMain.MapWindow();
314  }
316  {
317  HandleClose();
318 #ifndef __CINT__
319  ::SetErrorHandler(::DefaultErrorHandler);
320 #endif
321  Info("~ForwardOADBGUI", "Closing");
322  }
324  : fMain(gClient->GetRoot(), 10, 10, kVerticalFrame),
325  fOpenFrame(&fMain),
326  fFileText(&fOpenFrame, ""),
327  fFileSelect(&fOpenFrame, ""),
328  fTablesText(&fOpenFrame, ""),
329  fOpenButton(&fOpenFrame, ""),
330  fRWButton(&fOpenFrame, ""),
331  fCloseButton(&fOpenFrame, ""),
332  fSelectFrame(&fMain),
333  fTableFrame(&fSelectFrame),
334  fTableLabel(&fTableFrame, ""),
335  fTableSelect(&fTableFrame),
336  fRunFrame(&fSelectFrame),
337  fRunLabel(&fRunFrame, ""),
338  fRunInput(&fRunFrame),
339  fRunMode(&fRunFrame),
340  fSysFrame(&fSelectFrame),
341  fSysLabel(&fSysFrame, ""),
342  fSysSelect(&fSysFrame),
343  fSNNFrame(&fSelectFrame),
344  fSNNLabel(&fSNNFrame, ""),
345  fSNNInput(&fSNNFrame),
346  fFldFrame(&fSelectFrame),
347  fFldLabel(&fFldFrame, ""),
348  fFldSelect(&fFldFrame),
349  fOtherFrame(&fSelectFrame),
350  fMCButton(&fOtherFrame, ""),
351  fSatButton(&fOtherFrame, ""),
352  fOptionsFrame(&fSelectFrame),
353  fOptionsLabel(&fOptionsFrame, ""),
354  fOptionsText(&fOptionsFrame, ""),
355  fCommandFrame(&fSelectFrame),
356  fQueryButton(&fCommandFrame, ""),
357  fListButton(&fCommandFrame, ""),
358  fPrintButton(&fCommandFrame, ""),
359  fCopyButton(&fCommandFrame, ""),
360  fDrawButton(&fCommandFrame, ""),
361  fPDFButton(&fCommandFrame, ""),
362  fList(&fMain, 800, 400),
363  fListContainer(&fList),
364  fFrameHints(),
365  fLabelHints(),
366  fEntryHints(),
367  fButtonHints(),
368  fListHints(),
369  fStatusBar(&fMain),
370  fStatusBarHints(),
371  fMsg(0),
372  fDB(0),
373  fEntry(0)
374  {}
375  ForwardOADBGUI& operator=(const ForwardOADBGUI&) { return *this; }
376 
378  {
379  if (!db) return;
380 
381  if (fDB) HandleClose();
382  fEntry = 0;
383  fDB = db;
384 
385  TString lt;
386  const TMap& tables = fDB->GetTables();
387  TIter next(&tables);
388  TObject* key = 0;
389  // Int_t i = 0;
390  while ((key = next())) {
391  AliOADBForward::Table* t = fDB->FindTable(key->GetName());
392 
393  lt.Append(Form("%s/%s", t->GetName(), t->fTree->GetTitle()));
394  }
395  fTablesText.SetText(lt);
396  HandleEnable();
397  }
398  void HandleKill()
399  {
400  // fMain.DontCallClose();
401  fMain.DeleteWindow();
402  Printf("Starting timer");
403  // TTimer* t = new TTimer(Form("delete (ForwardOADBGUI*)%p", this), 100);
404  // t->Start(100, true);
405  }
407  {
408  Info("HandleDBEntry", "Selected entry %p", e);
409  Bool_t en = (e != 0);
410  fDrawButton.SetEnabled(en);
411  fCopyButton.SetEnabled(en);
412  fPrintButton.SetEnabled(en);
413  fPDFButton.SetEnabled(en);
414 
415  fEntry = e;
416  }
418  {
419  Bool_t enabled = fDB ? true : false;
420  Bool_t hasTable = fTableSelect.GetSelected() != 0;
421 
422  fTableSelect.SetEnabled(enabled);
423  fRunMode.SetEnabled(enabled);
424  fSysSelect.SetEnabled(enabled);
425  fFldSelect.SetEnabled(enabled);
426  fMCButton.SetEnabled(enabled);
427  fSatButton.SetEnabled(enabled);
428  fQueryButton.SetEnabled(enabled && hasTable);
429  fListButton.SetEnabled(enabled && hasTable);
430  fPrintButton.SetEnabled(enabled && hasTable);
431  fDrawButton.SetEnabled(enabled && hasTable);
432  fCopyButton.SetEnabled(enabled && hasTable);
433  fPDFButton.SetEnabled(enabled && hasTable);
434  fOpenButton.SetEnabled(!enabled);
435  fCloseButton.SetEnabled(enabled);
436  HandleDBEntry(0);
437 
438  Int_t tsel = 0;
439  if (!enabled) {
440  fTableSelect.RemoveAll();
441  fTableSelect.AddEntry("- select -", 0);
442  }
443  else {
444  const TMap& tables = fDB->GetTables();
445  TIter next(&tables);
446  TObject* key = 0;
447  Int_t i = 0;
448  while ((key = next())) {
449  fTableSelect.AddEntry(key->GetName(), ++i);
450  }
451  if (tables.GetEntries() == 1) tsel = 1;
452  }
453  fTableSelect.Select(tsel, true);
454  fSysSelect.Select(0, true);
455  fFldSelect.Select(999, true);
456  fRunMode.Select(0, true);
457 
458  fMain.Layout();
459  }
460  void HandleClose()
461  {
462  if (fDB) {
463  delete fDB;
464  fDB = 0;
465  }
466  SetStatus("No DB connected");
467  HandleEnable();
468  }
469  void HandleOpen()
470  {
471  if (fDB) HandleClose();
472  Bool_t rw = fRWButton.IsOn();
473  fDB = new AliOADBForward;
474  Info("HandleOpen", "Opening DB file %s for tables %s",
475  fFileText.GetText(), fTablesText.GetText());
476  TString fn(fFileText.GetText());
477  TString tn(fTablesText.GetText());
478  if (!fDB->Open(fn, tn, rw, true, true)) {
479  Error("HandleOpen", "Failed to open database");
480  delete fDB;
481  fDB = 0;
482  }
483  SetStatus(Form("Connected to %s", fFileText.GetText()));
484  // else
485  // fDB->Print();
486  HandleEnable();
487  }
489  {
490  TGFileInfo fi;
491  TString iniDir;
492  if (gSystem->Getenv("OADB_PATH"))
493  iniDir = gSystem->ExpandPathName("$(OADB_PATH)");
494  if (iniDir.IsNull())
495  iniDir = gSystem->ExpandPathName("$(ALICE_PHYSICS)/OADB");
496  iniDir.Append("/PWGLF/FORWARD/CORRECTIONS/data");
497  char* ini = new char[iniDir.Length()+1];
498  for (int i = 0; i < iniDir.Length(); i++) ini[i] = iniDir[i];
499  ini[iniDir.Length()] = '\0';
500  Printf("Initial directory: %s (%s)", iniDir.Data(), ini);
501  fi.fIniDir = ini;
502  new TGFileDialog(gClient->GetRoot(), &fMain, kFDOpen, &fi);
503 
504  TString nf = fi.fFilename; //
505  // nf = gSystem->ConcatFileName(fi.fIniDir, fi.fFilename);
506  Info("HandleBrowse", "New file: %s", nf.Data());
507  fFileText.SetText(nf);
508  }
510  {
511  TGLVEntry* lve = new TGLVEntry(&fListContainer, Form("%d", i), "");
512  if (i < 0) lve->SetUserData(e);
513  lve->SetUniqueID(i);
514  TDatime dt(e->fTimestamp);
515  lve->SetSubnames(Form("%lu", e->fRunNo),
516  (e->fSys == 1 ? "p-p" :
517  e->fSys == 2 ? "Pb-Pb" :
518  e->fSys == 3 ? "p-Pb" :
519  e->fSys == 4 ? "Pb-p" :
520  e->fSys == 5 ? "Xe-Xe" : "?"),
521  Form("%4huGeV",e->fSNN),
522  Form("%+2hdkG", e->fField),
523  (e->fMC ? "MC" : "Real"),
524  (e->fSatellite ? "Satellite" : "Nominal"),
525  dt.AsSQLString(),
526  e->fAuthor, Form("%lu", e->fAliROOTRevision),
527  (e->fData ? e->fData->GetName() : "null"));
528  fListContainer.AddItem(lve);
529  }
530  void HandleList()
531  {
532  if (!fDB) return;
533  TString table;
534  SelectedTable(table);
535 
536  if (table.IsNull()) {
537  // Error("HandleList", "No table selected");
538  return;
539  }
540  HandleDBEntry(0);
541  AliOADBForward::Table* t= fDB->FindTable(table);
542  if (!t) {
543  Error("HandleList", "No table named %s in DB", table.Data());
544  return;
545  }
546  // HandleQuery();
547  t->Print(fOptionsText.GetText());
548  // if (!fListContainer) return;
549 
550  fListContainer.RemoveAll();
551  TTree* tree = t->fTree;
552  Int_t n = tree->GetEntries();
553  for (Int_t i = 0; i < n; i++) {
554  tree->GetEntry(i);
556  HandleEntry(i, e);
557  }
558  fList.AdjustHeaders();
559  fMain.Layout();
560  }
561  void SelectedTable(TString& ret) const
562  {
563  ret = "";
564  TGLBEntry* e = fTableSelect.GetSelectedEntry();
565  if (!e) {
566  Error("SelectedTable", "No table selected");
567  return ;
568  }
569  ret = e->GetTitle();
570  }
572  {
573  Info("HandleTable", "Id=%d", id);
574  fListButton.SetEnabled(id != 0);
575  fQueryButton.SetEnabled(id != 0);
576  fListContainer.RemoveAll();
577  fList.AdjustHeaders();
578  fMain.Layout();
579  // fPrintButton.SetEnabled(enabled);
580  // fDrawButton.SetEnabled(enabled);
581  // fPDFButton.SetEnabled(enabled);
582  }
583  void HandleItem(TGFrame* lve, Int_t btn)
584  {
585  Info("HandleItem", "frame=%p", lve);
586  HandleItem(static_cast<TGLVEntry*>(lve), btn);
587  }
588  void HandleItem(TGLVEntry* lve, Int_t)
589  {
590  Info("HandleItem", "entry=%p", lve);
591  if (!lve) {
592  Warning("HandleItem", "No item");
593  return;
594  }
595  void* data = lve->GetUserData();
596  AliOADBForward::Entry* e = 0;
597  if (data) {
598  e = reinterpret_cast<AliOADBForward::Entry*>(data);
599  }
600  else {
601  TString tab;
602  SelectedTable(tab);
603  if (tab.IsNull()) return;
604 
605  AliOADBForward::Table* t = fDB->FindTable(tab);
606  // Info("HandleItem", "Fetching item %d from table", lve->GetUniqueID());
607  t->fTree->GetEntry(lve->GetUniqueID());
608  e = t->fEntry;
609  }
610  if (!e) {
611  Warning("HandleItem", "No entry");
612  return;
613  }
614  // if (!gPad) TCanvas::MakeDefCanvas();
615  e->Print();
616  HandleDBEntry(e);
617  // e->fData->Draw();
618  }
619  void HandlePrint()
620  {
621  // TObject* o = HandleQuery();
622  // if (!o) return;
623  if (!fEntry) {
624  Warning("HandlePrint", "No entry selected");
625  return;
626  }
627  fEntry->fData->Print(fOptionsText.GetText());
628  }
629  void HandleDraw()
630  {
631  if (!fEntry) {
632  Warning("HandleDraw", "No entry selected");
633  return;
634  }
635 
636  TObject* o = fEntry->fData;
637  Info("HandleDraw", "Will draw object of type %s", o->ClassName());
638  TString msg;
639  if (o->IsA()->InheritsFrom(TParameter<Double_t>::Class())) {
640  TParameter<Double_t>* pd = static_cast<TParameter<Double_t>*>(o);
641  msg = Form("%f", pd->GetVal());
642  }
643  if (o->IsA()->InheritsFrom(TParameter<Float_t>::Class())) {
644  TParameter<Float_t>* pf = static_cast<TParameter<Float_t>*>(o);
645  msg = Form("%f", pf->GetVal());
646  }
647  if (!msg.IsNull()) {
648  if (!gPad) TCanvas::MakeDefCanvas();
649 
650  TPaveText* t = new TPaveText(.1, .1, .9, .9);
651  t->AddText(msg);
652  t->Draw();
653  return;
654  }
655  CorrDraw(o, false);
656  // o->Draw(fOptionsText.GetText());
657  }
658  void HandleCopy()
659  {
660  TString table;
661  SelectedTable(table);
662  if (table.IsNull()) return;
663 
664  if (!fEntry) {
665  Warning("HandleCopy", "No entry selected");
666  return;
667  }
668 
669  TObject* o = fEntry->fData;
670  Info("HandleCopy", "Will copy object of type %s", o->ClassName());
671 
672 
673  ULong_t newRun = fRunInput.GetHexNumber();
674  UShort_t newSys = fSysSelect.GetSelected();
675  UShort_t newSNN = fSNNInput.GetIntNumber();
676  Short_t newFld = fFldSelect.GetSelected();
677  Bool_t mc = fMCButton.IsDown();
678  Bool_t sat = fSatButton.IsDown();
679  ULong_t oldRun = fEntry->fRunNo;
680  UShort_t oldSys = fEntry->fSys;
681  UShort_t oldSNN = fEntry->fSNN;
682  Short_t oldFld = fEntry->fField;
683 
684  TString msg;
685  msg = Form("Will copy %lu/%hu/%hu/%hd -> %lu/%hu/%hu/%hd (%s,%s) in %s",
686  oldRun, oldSys, oldSNN, oldFld,
687  newRun, newSys, newSNN, newFld,
688  (mc ? "mc" : "real"), (sat ? "satellite" : "nominal"),
689  table.Data());
690 
691  Int_t ret = 0;
692  new TGMsgBox(gClient->GetRoot(), gClient->GetRoot(),
693  "Confirm copy of OADB entry",
694  msg.Data(), 0, kMBOk|kMBCancel, &ret);
695 
696  if (ret == kMBCancel) {
697  Info("HandleCopy", "%s CANCELLED", msg.Data());
698  return;
699  }
700  Info("HandleCopy", "%s CONFIRMED", msg.Data());
701 
702  if (!fDB->CopyEntry(table,
703  oldRun, oldSys, oldSNN, oldFld,
704  newRun, newSys, newSNN, newFld,
705  mc, sat)) {
706  // Warning("HandleCopy", "Copy failed!");
707  return;
708  }
709  fDB->Update();
710 
711 
712  // o->Draw(fOptionsText.GetText());
713  }
714  void HandlePDF()
715  {
716  if (!fEntry) {
717  Warning("HandlePrint", "No entry selected");
718  return;
719  }
720 
721 
722  TObject* o = fEntry->fData;
723  gROOT->SetBatch(true);
724  CorrDraw(o, true);
725  gROOT->SetBatch(false);
726  // fEntry->fData->SaveAs(out, fOptionsText.GetText());
727 
728  }
730  {
731  const char* opt = "++g";
732  const char* fwd = "$ALICE_PHYSICS/PWGLF/FORWARD/analysis2";
733  gSystem->AddIncludePath(Form("-I$ALICE_ROOT/include "
734  "-I$ALICE_PHYSICS/include "
735  "-I%s -I%s/scripts", fwd, fwd));
736  Info("CorrDraw", "Loading SummaryDrawer.C%s", opt);
737  gROOT->LoadMacro(Form("%s/scripts/SummaryDrawer.C%s", fwd, opt));
738  // gROOT->ProcessLine(".Class SummaryDrawer");
739  Info("CorrDraw", "Loading CorrDrawer.C%s", opt);
740  gROOT->LoadMacro(Form("%s/corrs/CorrDrawer.C%s", fwd, opt));
741  // gROOT->ProcessLine(".Class SummaryDrawer");
742  // gROOT->ProcessLine(".Class CorrDrawer");
743  CloseMsg();
744  }
745  void CorrDraw(const TObject* o, Bool_t summarize)
746  {
747  if (!gROOT->GetClass("CorrDrawer")) {
748  TTimer* t = new TTimer(Form("((ForwardOADBGUI*)%p)->LoadCorrDraw()",this),
749  0, kTRUE);
750  t->Start(100, true);
751  MakeMsg("Compiling drawer");
752  }
753  o->Print();
754  if (summarize) {
755  TTimer* t = new TTimer(Form("((ForwardOADBGUI*)%p)"
756  "->DoCorrDraw((TObject*)%p,1)",this, o),
757  0, kTRUE);
758  t->Start(100, true);
759  MakeMsg("Drawing to PDF");
760  }
761  else
762  DoCorrDraw(o, false);
763  }
764  void DoCorrDraw(const TObject* o, Bool_t summarize)
765  {
766  TString cmd(Form("CorrDrawer cd; cd.Summarize((const %s*)%p,%d);",
767  o->ClassName(), o, summarize));
768  gROOT->ProcessLine(cmd);
769  CloseMsg();
770  }
771  void MakeFileName(TString& out) const
772  {
773  if (!fEntry) return;
774 
775  SelectedTable(out);
776  if (out.IsNull()) return;
777 
778  out.Append(Form("_run%09lu", fEntry->fRunNo));
779  out.Append(Form("_%s", (fEntry->fSys == 1 ? "pp" :
780  fEntry->fSys == 2 ? "PbPb" :
781  fEntry->fSys == 3 ? "pPb" :
782  fEntry->fSys == 4 ? "Pbp" :
783  fEntry->fSys == 5 ? "Xe-Xe" : "XX")));
784  out.Append(Form("_%04huGeV", fEntry->fSNN));
785  out.Append(Form("_%c%hukG", fEntry->fField >= 0 ? 'p' : 'm',
786  TMath::Abs(fEntry->fField)));
787  out.Append(Form("_%s", fEntry->fMC ? "mc" : "real"));
788  out.Append(Form("_%s", fEntry->fSatellite ? "sat" : "nom"));
789  out.Append(".pdf");
790  }
792  {
793  ULong_t run = fRunInput.GetHexNumber();
794  Short_t mode = fRunMode.GetSelected();
795  Short_t sys = fSysSelect.GetSelected();
796  UShort_t sNN = fSNNInput.GetIntNumber();
797  Short_t fld = fFldSelect.GetSelected();
798  Bool_t mc = fMCButton.IsDown();
799  Bool_t sat = fSatButton.IsDown();
800  TString tab;
801  SelectedTable(tab);
802 
803  Info("HandleQuery", "tab=%s runNo=%lu mode=%d sys=%d "
804  "sNN=%d fld=%d mc=%d sat=%d",
805  tab.Data(), run, mode, sys, sNN, fld, mc, sat);
806 
807  if (tab.IsNull()) {
808  // Error("HandleQuery", "No table selected");
809  return 0;
810  }
812  switch (mode) {
813  case 0: qmode = AliOADBForward::kDefault; break;
814  case 1: qmode = AliOADBForward::kExact; break;
815  case 2: qmode = AliOADBForward::kNewest; break;
816  case 3: qmode = AliOADBForward::kNear; break;
817  case 4: qmode = AliOADBForward::kOlder; break;
818  case 5: qmode = AliOADBForward::kNewer; break;
819  }
820 
821  Info("HandleQuery", "tab=%s runNo=%lu mode=%d sys=%d "
822  "sNN=%d fld=%d mc=%d sat=%d",
823  tab.Data(), run, qmode, sys, sNN, fld, mc, sat);
824 
825  AliOADBForward::Entry* e = fDB->Get(tab, run, qmode, sys, sNN,
826  fld, mc, sat);
827  if (!e) return 0;
828  // if (drawNotPrint) e->Inspect();
829  // else e->Print(fOptionsText.GetText());
830  e->Print();
831  // if (fListContainer) {
832  fListContainer.RemoveAll();
833  HandleEntry(-1, e);
834  // }
835  if (!e->fData) return 0;
836  HandleDBEntry(e);
837 
838  fList.AdjustHeaders();
839  fMain.Layout();
840 
841  return e->fData;
842  }
843  TGMainFrame* GetMain() { return &fMain; }
844  void MakeMsg(const char* what)
845  {
846  fMsg.Show(what);
847  }
848  void CloseMsg()
849  {
850  Info("CloseMsg", "Closing message window");
851  fMsg.Hide();
852  }
853  void SetStatus(const char* what)
854  {
855  fStatusBar.SetText(what,0);
856  }
857  TGMainFrame fMain;
858  TGHorizontalFrame fOpenFrame;
859  TGTextEntry fFileText;
860  TGTextButton fFileSelect;
861  TGTextEntry fTablesText;
862  TGTextButton fOpenButton;
863  TGCheckButton fRWButton;
864  TGTextButton fCloseButton;
865  TGVerticalFrame fSelectFrame;
866  TGHorizontalFrame fTableFrame;
867  TGLabel fTableLabel;
868  TGComboBox fTableSelect;
869  TGHorizontalFrame fRunFrame;
870  TGLabel fRunLabel;
871  TGNumberEntry fRunInput;
872  TGComboBox fRunMode;
873  TGHorizontalFrame fSysFrame;
874  TGLabel fSysLabel;
875  TGComboBox fSysSelect;
876  TGHorizontalFrame fSNNFrame;
877  TGLabel fSNNLabel;
878  TGNumberEntry fSNNInput;
879  TGHorizontalFrame fFldFrame;
880  TGLabel fFldLabel;
881  TGComboBox fFldSelect;
882  TGHButtonGroup fOtherFrame;
883  TGTextButton fMCButton;
884  TGTextButton fSatButton;
885  TGHorizontalFrame fOptionsFrame;
886  TGLabel fOptionsLabel;
887  TGTextEntry fOptionsText;
888  TGHButtonGroup fCommandFrame;
889  TGTextButton fQueryButton;
890  TGTextButton fListButton;
891  TGTextButton fPrintButton;
892  TGTextButton fCopyButton;
893  TGTextButton fDrawButton;
894  TGTextButton fPDFButton;
895  TGListView fList;
896  TGLVContainer fListContainer;
897  TGLayoutHints fFrameHints;
898  TGLayoutHints fLabelHints;
899  TGLayoutHints fEntryHints;
900  TGLayoutHints fButtonHints;
901  TGLayoutHints fListHints;
902  TGStatusBar fStatusBar;
903  TGLayoutHints fStatusBarHints;
907  // TCanvas* fDataCanvas;
908  // TCanvas* fEntryCanvas;
909 };
910 
911 
912 TGMainFrame* ForwardOADBGui(AliOADBForward* db=0,
913  const char* path=0)
914 {
915  const char* fwd = "$ALICE_PHYSICS/PWGLF/FORWARD/analysis2";
916  if (!gROOT->GetClass("AliOADBForward"))
917  // gSystem->Load("libGui");
918  gROOT->Macro(Form("%s/scripts/LoadLibs.C", fwd));
919 
920  // gSystem->AddIncludePath(Form("-I%s", fwd));
921  // gROOT->LoadMacro(Form("%s/corrs/ForwardOADBGUI.C", fwd));
922 
923  new TBrowser;
924  // new TGClient();
925  ForwardOADBGUI* gui = new ForwardOADBGUI();
926  if (db) {
927  gui->UseDB(db);
928  if (path) gui->SetStatus(Form("Connected to %s", path));
929  }
930  return gui->GetMain();
931 }
932 
933 //
934 // EOF
935 //
936 
TGMainFrame * ForwardOADBGui(AliOADBForward *db=0, const char *path=0)
AliOADBForward::Entry * fEntry
ULong_t fAliROOTRevision
TGLayoutHints fStatusBarHints
void DoCorrDraw(const TObject *o, Bool_t summarize)
const Char_t * GetName() const
TGMainFrame * GetMain()
TGStatusBar fStatusBar
UShort_t fSys
ForwardOADBGUI(const ForwardOADBGUI &)
void Print(Option_t *option="") const
TGHorizontalFrame fSysFrame
TGLabel fOptionsLabel
AliOADBForward * fDB
TGHorizontalFrame fOpenFrame
UShort_t fSNN
TGHorizontalFrame fOptionsFrame
void HandleItem(TGLVEntry *lve, Int_t)
TGLVContainer fListContainer
TGLayoutHints fFrameHints
TGNumberEntry fSNNInput
void SelectedTable(TString &ret) const
TGTransientFrame fFrame
TSystem * gSystem
TGComboBox fSysSelect
ForwardOADBGUI & operator=(const ForwardOADBGUI &)
void HandleDBEntry(AliOADBForward::Entry *e)
void HandleEntry(Int_t i, AliOADBForward::Entry *e)
TGTextEntry fOptionsText
TGLayoutHints fHints
void CorrDraw(const TObject *o, Bool_t summarize)
TGLayoutHints fEntryHints
TGComboBox fFldSelect
ForwardOADBWait fMsg
TGComboBox fTableSelect
TString fAuthor
ULong_t fRunNo
void HandleItem(TGFrame *lve, Int_t btn)
int Int_t
Definition: External.C:63
TGTextButton fCloseButton
Bool_t fMC
TGHorizontalFrame fRunFrame
void SetStatus(const char *what)
void MakeFileName(TString &out) const
TGTextButton fCopyButton
void HandleTable(Int_t id)
TGTextButton fPrintButton
TGTextEntry fFileText
TGTextButton fPDFButton
TGTextButton fQueryButton
ForwardOADBWait & operator=(const ForwardOADBWait &)
TGTextEntry fTablesText
unsigned long ULong_t
Definition: External.C:38
Int_t mode
Definition: anaM.C:41
Bool_t fSatellite
TGTextButton fMCButton
void Show(const char *msg)
void UseDB(AliOADBForward *db)
void Print(Option_t *option="") const
short Short_t
Definition: External.C:23
TGHButtonGroup fCommandFrame
TGTextButton fSatButton
TGHorizontalFrame fTableFrame
TGTextButton fOpenButton
const char * fwd
TGTextButton fDrawButton
TGComboBox fRunMode
TGHButtonGroup fOtherFrame
TGMainFrame fMain
TGCheckButton fRWButton
ForwardOADBWait(TGMainFrame *p)
TGVerticalFrame fSelectFrame
TGTextButton fListButton
TGHorizontalFrame fSNNFrame
unsigned short UShort_t
Definition: External.C:28
TGListView fList
ForwardOADBWait(const ForwardOADBWait &)
TGNumberEntry fRunInput
UInt_t fTimestamp
TGLayoutHints fButtonHints
bool Bool_t
Definition: External.C:53
Short_t fField
void MakeMsg(const char *what)
TGTextButton fFileSelect
TGHorizontalFrame fFldFrame
TGLayoutHints fLabelHints
TObject * HandleQuery()
TObject * fData
TGLayoutHints fListHints