AliPhysics  3337bb0 (3337bb0)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  ForwardOADBDialog(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()","ForwardOADBDialog",this,"HandleIncr()");
83  }
85  ForwardOADBDialog& operator=(const ForwardOADBDialog&) { 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;
119  //TGHProgressBar fProgress;
121  TTimer fIncrement;
122 };
123 
125 {
126  enum {
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),
140  fTableLabel(&fTableFrame, "Table: "),
143  fRunLabel(&fRunFrame, "Run: "),
144  fRunInput(&fRunFrame, 0, 0, -1,
145  TGNumberFormat::kNESReal,
146  TGNumberFormat::kNEANonNegative,
147  TGNumberFormat::kNELLimitMin, 0),
150  fSysLabel(&fSysFrame, "System: "),
153  fSNNLabel(&fSNNFrame, "sqrt(sNN) [GeV]: "),
154  fSNNInput(&fSNNFrame, 0, 0, -1, TGNumberFormat::kNESReal,
155  TGNumberFormat::kNEANonNegative,
156  TGNumberFormat::kNELLimitMin, 0),
158  fFldLabel(&fFldFrame, "L3 field [kG]: "),
161  fMCButton(&fOtherFrame, "MC"),
162  fSatButton(&fOtherFrame, "Satellite"),
164  fOptionsLabel(&fOptionsFrame, "Draw/Print options:"),
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),
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.SetHeight(22);
230  fSelectFrame.AddFrame(&fSysFrame, &fFrameHints);
231  fSysFrame.AddFrame(&fSysLabel, &fLabelHints);
232  fSysFrame.AddFrame(&fSysSelect, &fEntryHints);
233 
234  fSNNLabel.SetWidth(kLabelWidth); fSNNLabel.SetMinWidth(kLabelWidth);
235  fSNNInput.SetHeight(22);
236  fSelectFrame.AddFrame(&fSNNFrame, &fFrameHints);
237  fSNNFrame.AddFrame(&fSNNLabel, &fLabelHints);
238  fSNNFrame.AddFrame(&fSNNInput, &fEntryHints);
239 
240  fFldLabel.SetWidth(kLabelWidth); fFldLabel.SetMinWidth(kLabelWidth);
241  fFldSelect.AddEntry("- select -", 999);
242  fFldSelect.AddEntry("-5", -5);
243  fFldSelect.AddEntry("0 ", 0);
244  fFldSelect.AddEntry("+5", +5);
245  fFldSelect.SetHeight(22);
246  fSelectFrame.AddFrame(&fFldFrame, &fFrameHints);
247  fFldFrame.AddFrame(&fFldLabel, &fLabelHints);
248  fFldFrame.AddFrame(&fFldSelect, &fEntryHints);
249 
250  fSelectFrame.AddFrame(&fOtherFrame, &fFrameHints);
251  fOtherFrame.SetLayoutHints(&fButtonHints);
252  fMCButton.AllowStayDown(true);
253  fSatButton.AllowStayDown(true);
254  // fOtherFrame.AddFrame(&fMCButton, &fEntryHints);
255  // fOtherFrame.AddFrame(&fSatButton, &fEntryHints);
256  // new TGCheckButton(&fOtherFrame, "MC:");
257  // new TGCheckButton(&fOtherFrame, "Satellite:");
258 
259  fOptionsLabel.SetWidth(2*kLabelWidth);
263 
264  // Info("", "Connecting signals");
265  fQueryButton.Connect("Clicked()", "ForwardOADBGUI", this, "HandleQuery()");
266  fListButton.Connect("Clicked()", "ForwardOADBGUI", this, "HandleList()");
267  fDrawButton.Connect("Clicked()", "ForwardOADBGUI", this, "HandleDraw()");
268  fCopyButton.Connect("Clicked()", "ForwardOADBGUI", this, "HandleCopy()");
269  fPDFButton.Connect("Clicked()", "ForwardOADBGUI", this, "HandlePDF()");
270  fPrintButton.Connect("Clicked()", "ForwardOADBGUI", this, "HandlePrint()");
272  fCommandFrame.SetLayoutHints(&fButtonHints);
273 
274  // fList = new TGListView(&fMain, 800, 400);
275  // fListContainer = new TGLVContainer(fList);
276  fListContainer.SetColHeaders("Entry",
277  "Run",
278  "System",
279  "sqrt(sNN)",
280  "L3 Field",
281  "Type",
282  "IP",
283  "Date",
284  "Author",
285  "AliROOT",
286  "Data");
287  fList.SetViewMode(kLVDetails);
288  fList.Connect("Clicked(TGLVEntry*,Int_t)",
289  "ForwardOADBGUI", this, "HandleItem(TGLVEntry*,Int_t)");
290  fList.Connect("DoubleClicked(TGLVEntry*,Int_t)",
291  "ForwardOADBGUI", this, "HandleItem(TGLVEntry*,Int_t)");
292  fListContainer.Connect("Clicked(TGFrame*,Int_t)",
293  "ForwardOADBGUI", this,
294  "HandleItem(TGFrame*,Int_t)");
295  fList.SetMinWidth(400);
296  fList.SetMinHeight(200);
297  fMain.AddFrame(&fList, &fListHints);
298 
299  fStatusBar.SetParts(1);
300  fMain.AddFrame(&fStatusBar, &fStatusBarHints);
301 #ifndef __CINT__
302  ::SetErrorHandler(ForwardOADBGUIErrorHandler);
303 #endif
304  HandleEnable();
305 
306  fMain.SetMinWidth(600);
307  fMain.SetMinHeight(480);
308  fMain.MapSubwindows();
309  fMain.Resize(600, 480); // fMain.GetDefaultSize());
310  fMain.MapWindow();
311  }
313  {
314  HandleClose();
315 #ifndef __CINT__
316  ::SetErrorHandler(::DefaultErrorHandler);
317 #endif
318  Info("~ForwardOADBGUI", "Closing");
319  }
321  : fMain(gClient->GetRoot(), 10, 10, kVerticalFrame),
322  fOpenFrame(&fMain),
323  fFileText(&fOpenFrame, ""),
324  fFileSelect(&fOpenFrame, ""),
325  fTablesText(&fOpenFrame, ""),
326  fOpenButton(&fOpenFrame, ""),
327  fRWButton(&fOpenFrame, ""),
328  fCloseButton(&fOpenFrame, ""),
329  fSelectFrame(&fMain),
331  fTableLabel(&fTableFrame, ""),
334  fRunLabel(&fRunFrame, ""),
338  fSysLabel(&fSysFrame, ""),
341  fSNNLabel(&fSNNFrame, ""),
344  fFldLabel(&fFldFrame, ""),
347  fMCButton(&fOtherFrame, ""),
348  fSatButton(&fOtherFrame, ""),
359  fList(&fMain, 800, 400),
361  fFrameHints(),
362  fLabelHints(),
363  fEntryHints(),
364  fButtonHints(),
365  fListHints(),
366  fStatusBar(&fMain),
367  fStatusBarHints(),
368  fMsg(0),
369  fDB(0),
370  fEntry(0)
371  {}
372  ForwardOADBGUI& operator=(const ForwardOADBGUI&) { return *this; }
373 
375  {
376  if (!db) return;
377 
378  if (fDB) HandleClose();
379  fEntry = 0;
380  fDB = db;
381 
382  TString lt;
383  const TMap& tables = fDB->GetTables();
384  TIter next(&tables);
385  TObject* key = 0;
386  // Int_t i = 0;
387  while ((key = next())) {
388  AliOADBForward::Table* t = fDB->FindTable(key->GetName());
389 
390  lt.Append(Form("%s/%s", t->GetName(), t->fTree->GetTitle()));
391  }
392  fTablesText.SetText(lt);
393  HandleEnable();
394  }
395  void HandleKill()
396  {
397  // fMain.DontCallClose();
398  fMain.DeleteWindow();
399  Printf("Starting timer");
400  // TTimer* t = new TTimer(Form("delete (ForwardOADBGUI*)%p", this), 100);
401  // t->Start(100, true);
402  }
404  {
405  Info("HandleDBEntry", "Selected entry %p", e);
406  Bool_t en = (e != 0);
407  fDrawButton.SetEnabled(en);
408  fCopyButton.SetEnabled(en);
409  fPrintButton.SetEnabled(en);
410  fPDFButton.SetEnabled(en);
411 
412  fEntry = e;
413  }
415  {
416  Bool_t enabled = fDB ? true : false;
417  Bool_t hasTable = fTableSelect.GetSelected() != 0;
418 
419  fTableSelect.SetEnabled(enabled);
420  fRunMode.SetEnabled(enabled);
421  fSysSelect.SetEnabled(enabled);
422  fFldSelect.SetEnabled(enabled);
423  fMCButton.SetEnabled(enabled);
424  fSatButton.SetEnabled(enabled);
425  fQueryButton.SetEnabled(enabled && hasTable);
426  fListButton.SetEnabled(enabled && hasTable);
427  fPrintButton.SetEnabled(enabled && hasTable);
428  fDrawButton.SetEnabled(enabled && hasTable);
429  fCopyButton.SetEnabled(enabled && hasTable);
430  fPDFButton.SetEnabled(enabled && hasTable);
431  fOpenButton.SetEnabled(!enabled);
432  fCloseButton.SetEnabled(enabled);
433  HandleDBEntry(0);
434 
435  Int_t tsel = 0;
436  if (!enabled) {
437  fTableSelect.RemoveAll();
438  fTableSelect.AddEntry("- select -", 0);
439  }
440  else {
441  const TMap& tables = fDB->GetTables();
442  TIter next(&tables);
443  TObject* key = 0;
444  Int_t i = 0;
445  while ((key = next())) {
446  fTableSelect.AddEntry(key->GetName(), ++i);
447  }
448  if (tables.GetEntries() == 1) tsel = 1;
449  }
450  fTableSelect.Select(tsel, true);
451  fSysSelect.Select(0, true);
452  fFldSelect.Select(999, true);
453  fRunMode.Select(0, true);
454 
455  fMain.Layout();
456  }
457  void HandleClose()
458  {
459  if (fDB) {
460  delete fDB;
461  fDB = 0;
462  }
463  SetStatus("No DB connected");
464  HandleEnable();
465  }
466  void HandleOpen()
467  {
468  if (fDB) HandleClose();
469  Bool_t rw = fRWButton.IsOn();
470  fDB = new AliOADBForward;
471  Info("HandleOpen", "Opening DB file %s for tables %s",
472  fFileText.GetText(), fTablesText.GetText());
473  TString fn(fFileText.GetText());
474  TString tn(fTablesText.GetText());
475  if (!fDB->Open(fn, tn, rw, true, true)) {
476  Error("HandleOpen", "Failed to open database");
477  delete fDB;
478  fDB = 0;
479  }
480  SetStatus(Form("Connected to %s", fFileText.GetText()));
481  // else
482  // fDB->Print();
483  HandleEnable();
484  }
486  {
487  TGFileInfo fi;
488  TString iniDir;
489  if (gSystem->Getenv("OADB_PATH"))
490  iniDir = gSystem->ExpandPathName("$(OADB_PATH)");
491  if (iniDir.IsNull())
492  iniDir = gSystem->ExpandPathName("$(ALICE_PHYSICS)/OADB");
493  iniDir.Append("/PWGLF/FORWARD/CORRECTIONS/data");
494  char* ini = new char[iniDir.Length()+1];
495  for (int i = 0; i < iniDir.Length(); i++) ini[i] = iniDir[i];
496  ini[iniDir.Length()] = '\0';
497  Printf("Initial directory: %s (%s)", iniDir.Data(), ini);
498  fi.fIniDir = ini;
499  new TGFileDialog(gClient->GetRoot(), &fMain, kFDOpen, &fi);
500 
501  TString nf = fi.fFilename; //
502  // nf = gSystem->ConcatFileName(fi.fIniDir, fi.fFilename);
503  Info("HandleBrowse", "New file: %s", nf.Data());
504  fFileText.SetText(nf);
505  }
507  {
508  TGLVEntry* lve = new TGLVEntry(&fListContainer, Form("%d", i), "");
509  if (i < 0) lve->SetUserData(e);
510  lve->SetUniqueID(i);
511  TDatime dt(e->fTimestamp);
512  lve->SetSubnames(Form("%lu", e->fRunNo),
513  (e->fSys == 1 ? "p-p" :
514  e->fSys == 2 ? "Pb-Pb" :
515  e->fSys == 3 ? "p-Pb" :
516  e->fSys == 4 ? "Pb-p" : "?"),
517  Form("%4huGeV",e->fSNN),
518  Form("%+2hdkG", e->fField),
519  (e->fMC ? "MC" : "Real"),
520  (e->fSatellite ? "Satellite" : "Nominal"),
521  dt.AsSQLString(),
522  e->fAuthor, Form("%lu", e->fAliROOTRevision),
523  (e->fData ? e->fData->GetName() : "null"));
524  fListContainer.AddItem(lve);
525  }
526  void HandleList()
527  {
528  if (!fDB) return;
529  TString table;
530  SelectedTable(table);
531 
532  if (table.IsNull()) {
533  // Error("HandleList", "No table selected");
534  return;
535  }
536  HandleDBEntry(0);
537  AliOADBForward::Table* t= fDB->FindTable(table);
538  if (!t) {
539  Error("HandleList", "No table named %s in DB", table.Data());
540  return;
541  }
542  // HandleQuery();
543  t->Print(fOptionsText.GetText());
544  // if (!fListContainer) return;
545 
546  fListContainer.RemoveAll();
547  TTree* tree = t->fTree;
548  Int_t n = tree->GetEntries();
549  for (Int_t i = 0; i < n; i++) {
550  tree->GetEntry(i);
552  HandleEntry(i, e);
553  }
554  fList.AdjustHeaders();
555  fMain.Layout();
556  }
557  void SelectedTable(TString& ret) const
558  {
559  ret = "";
560  TGLBEntry* e = fTableSelect.GetSelectedEntry();
561  if (!e) {
562  Error("SelectedTable", "No table selected");
563  return ;
564  }
565  ret = e->GetTitle();
566  }
568  {
569  Info("HandleTable", "Id=%d", id);
570  fListButton.SetEnabled(id != 0);
571  fQueryButton.SetEnabled(id != 0);
572  fListContainer.RemoveAll();
573  fList.AdjustHeaders();
574  fMain.Layout();
575  // fPrintButton.SetEnabled(enabled);
576  // fDrawButton.SetEnabled(enabled);
577  // fPDFButton.SetEnabled(enabled);
578  }
579  void HandleItem(TGFrame* lve, Int_t btn)
580  {
581  Info("HandleItem", "frame=%p", lve);
582  HandleItem(static_cast<TGLVEntry*>(lve), btn);
583  }
584  void HandleItem(TGLVEntry* lve, Int_t)
585  {
586  Info("HandleItem", "entry=%p", lve);
587  if (!lve) {
588  Warning("HandleItem", "No item");
589  return;
590  }
591  void* data = lve->GetUserData();
592  AliOADBForward::Entry* e = 0;
593  if (data) {
594  e = reinterpret_cast<AliOADBForward::Entry*>(data);
595  }
596  else {
597  TString tab;
598  SelectedTable(tab);
599  if (tab.IsNull()) return;
600 
602  // Info("HandleItem", "Fetching item %d from table", lve->GetUniqueID());
603  t->fTree->GetEntry(lve->GetUniqueID());
604  e = t->fEntry;
605  }
606  if (!e) {
607  Warning("HandleItem", "No entry");
608  return;
609  }
610  // if (!gPad) TCanvas::MakeDefCanvas();
611  e->Print();
612  HandleDBEntry(e);
613  // e->fData->Draw();
614  }
615  void HandlePrint()
616  {
617  // TObject* o = HandleQuery();
618  // if (!o) return;
619  if (!fEntry) {
620  Warning("HandlePrint", "No entry selected");
621  return;
622  }
623  fEntry->fData->Print(fOptionsText.GetText());
624  }
625  void HandleDraw()
626  {
627  if (!fEntry) {
628  Warning("HandleDraw", "No entry selected");
629  return;
630  }
631 
632  TObject* o = fEntry->fData;
633  Info("HandleDraw", "Will draw object of type %s", o->ClassName());
634  TString msg;
635  if (o->IsA()->InheritsFrom(TParameter<Double_t>::Class())) {
636  TParameter<Double_t>* pd = static_cast<TParameter<Double_t>*>(o);
637  msg = Form("%f", pd->GetVal());
638  }
639  if (o->IsA()->InheritsFrom(TParameter<Float_t>::Class())) {
640  TParameter<Float_t>* pf = static_cast<TParameter<Float_t>*>(o);
641  msg = Form("%f", pf->GetVal());
642  }
643  if (!msg.IsNull()) {
644  if (!gPad) TCanvas::MakeDefCanvas();
645 
646  TPaveText* t = new TPaveText(.1, .1, .9, .9);
647  t->AddText(msg);
648  t->Draw();
649  return;
650  }
651  CorrDraw(o, false);
652  // o->Draw(fOptionsText.GetText());
653  }
654  void HandleCopy()
655  {
656  TString table;
657  SelectedTable(table);
658  if (table.IsNull()) return;
659 
660  if (!fEntry) {
661  Warning("HandleCopy", "No entry selected");
662  return;
663  }
664 
665  TObject* o = fEntry->fData;
666  Info("HandleCopy", "Will copy object of type %s", o->ClassName());
667 
668 
669  ULong_t newRun = fRunInput.GetHexNumber();
670  UShort_t newSys = fSysSelect.GetSelected();
671  UShort_t newSNN = fSNNInput.GetIntNumber();
672  Short_t newFld = fFldSelect.GetSelected();
673  Bool_t mc = fMCButton.IsDown();
674  Bool_t sat = fSatButton.IsDown();
675  ULong_t oldRun = fEntry->fRunNo;
676  UShort_t oldSys = fEntry->fSys;
677  UShort_t oldSNN = fEntry->fSNN;
678  Short_t oldFld = fEntry->fField;
679 
680  TString msg;
681  msg = Form("Will copy %lu/%hu/%hu/%hd -> %lu/%hu/%hu/%hd (%s,%s) in %s",
682  oldRun, oldSys, oldSNN, oldFld,
683  newRun, newSys, newSNN, newFld,
684  (mc ? "mc" : "real"), (sat ? "satellite" : "nominal"),
685  table.Data());
686 
687  Int_t ret = 0;
688  new TGMsgBox(gClient->GetRoot(), gClient->GetRoot(),
689  "Confirm copy of OADB entry",
690  msg.Data(), 0, kMBOk|kMBCancel, &ret);
691 
692  if (ret == kMBCancel) {
693  Info("HandleCopy", "%s CANCELLED", msg.Data());
694  return;
695  }
696  Info("HandleCopy", "%s CONFIRMED", msg.Data());
697 
698  if (!fDB->CopyEntry(table,
699  oldRun, oldSys, oldSNN, oldFld,
700  newRun, newSys, newSNN, newFld,
701  mc, sat)) {
702  // Warning("HandleCopy", "Copy failed!");
703  return;
704  }
705  fDB->Update();
706 
707 
708  // o->Draw(fOptionsText.GetText());
709  }
710  void HandlePDF()
711  {
712  if (!fEntry) {
713  Warning("HandlePrint", "No entry selected");
714  return;
715  }
716 
717 
718  TObject* o = fEntry->fData;
719  gROOT->SetBatch(true);
720  CorrDraw(o, true);
721  gROOT->SetBatch(false);
722  // fEntry->fData->SaveAs(out, fOptionsText.GetText());
723 
724  }
726  {
727  const char* opt = "++g";
728  const char* fwd = "$ALICE_PHYSICS/PWGLF/FORWARD/analysis2";
729  gSystem->AddIncludePath(Form("-I$ALICE_ROOT/include "
730  "-I$ALICE_PHYSICS/include "
731  "-I%s -I%s/scripts", fwd, fwd));
732  Info("CorrDraw", "Loading SummaryDrawer.C%s", opt);
733  gROOT->LoadMacro(Form("%s/scripts/SummaryDrawer.C%s", fwd, opt));
734  // gROOT->ProcessLine(".Class SummaryDrawer");
735  Info("CorrDraw", "Loading CorrDrawer.C%s", opt);
736  gROOT->LoadMacro(Form("%s/corrs/CorrDrawer.C%s", fwd, opt));
737  // gROOT->ProcessLine(".Class SummaryDrawer");
738  // gROOT->ProcessLine(".Class CorrDrawer");
739  CloseMsg();
740  }
741  void CorrDraw(const TObject* o, Bool_t summarize)
742  {
743  if (!gROOT->GetClass("CorrDrawer")) {
744  TTimer* t = new TTimer(Form("((ForwardOADBGUI*)%p)->LoadCorrDraw()",this),
745  0, kTRUE);
746  t->Start(100, true);
747  MakeMsg("Compiling drawer");
748  }
749  o->Print();
750  if (summarize) {
751  TTimer* t = new TTimer(Form("((ForwardOADBGUI*)%p)"
752  "->DoCorrDraw((TObject*)%p,1)",this, o),
753  0, kTRUE);
754  t->Start(100, true);
755  MakeMsg("Drawing to PDF");
756  }
757  else
758  DoCorrDraw(o, false);
759  }
760  void DoCorrDraw(const TObject* o, Bool_t summarize)
761  {
762  TString cmd(Form("CorrDrawer cd; cd.Summarize((const %s*)%p,%d);",
763  o->ClassName(), o, summarize));
764  gROOT->ProcessLine(cmd);
765  CloseMsg();
766  }
767  void MakeFileName(TString& out) const
768  {
769  if (!fEntry) return;
770 
771  SelectedTable(out);
772  if (out.IsNull()) return;
773 
774  out.Append(Form("_run%09lu", fEntry->fRunNo));
775  out.Append(Form("_%s", (fEntry->fSys == 1 ? "pp" :
776  fEntry->fSys == 2 ? "PbPb" :
777  fEntry->fSys == 3 ? "pPb" :
778  fEntry->fSys == 4 ? "Pbp" : "XX")));
779  out.Append(Form("_%04huGeV", fEntry->fSNN));
780  out.Append(Form("_%c%hukG", fEntry->fField >= 0 ? 'p' : 'm',
781  TMath::Abs(fEntry->fField)));
782  out.Append(Form("_%s", fEntry->fMC ? "mc" : "real"));
783  out.Append(Form("_%s", fEntry->fSatellite ? "sat" : "nom"));
784  out.Append(".pdf");
785  }
787  {
788  ULong_t run = fRunInput.GetHexNumber();
789  Short_t mode = fRunMode.GetSelected();
790  Short_t sys = fSysSelect.GetSelected();
791  UShort_t sNN = fSNNInput.GetIntNumber();
792  Short_t fld = fFldSelect.GetSelected();
793  Bool_t mc = fMCButton.IsDown();
794  Bool_t sat = fSatButton.IsDown();
795  TString tab;
796  SelectedTable(tab);
797 
798  Info("HandleQuery", "tab=%s runNo=%lu mode=%d sys=%d "
799  "sNN=%d fld=%d mc=%d sat=%d",
800  tab.Data(), run, mode, sys, sNN, fld, mc, sat);
801 
802  if (tab.IsNull()) {
803  // Error("HandleQuery", "No table selected");
804  return 0;
805  }
807  switch (mode) {
808  case 0: qmode = AliOADBForward::kDefault; break;
809  case 1: qmode = AliOADBForward::kExact; break;
810  case 2: qmode = AliOADBForward::kNewest; break;
811  case 3: qmode = AliOADBForward::kNear; break;
812  case 4: qmode = AliOADBForward::kOlder; break;
813  case 5: qmode = AliOADBForward::kNewer; break;
814  }
815 
816  Info("HandleQuery", "tab=%s runNo=%lu mode=%d sys=%d "
817  "sNN=%d fld=%d mc=%d sat=%d",
818  tab.Data(), run, qmode, sys, sNN, fld, mc, sat);
819 
820  AliOADBForward::Entry* e = fDB->Get(tab, run, qmode, sys, sNN,
821  fld, mc, sat);
822  if (!e) return 0;
823  // if (drawNotPrint) e->Inspect();
824  // else e->Print(fOptionsText.GetText());
825  e->Print();
826  // if (fListContainer) {
827  fListContainer.RemoveAll();
828  HandleEntry(-1, e);
829  // }
830  if (!e->fData) return 0;
831  HandleDBEntry(e);
832 
833  fList.AdjustHeaders();
834  fMain.Layout();
835 
836  return e->fData;
837  }
838  TGMainFrame* GetMain() { return &fMain; }
839  void MakeMsg(const char* what)
840  {
841  fMsg.Show(what);
842  }
843  void CloseMsg()
844  {
845  Info("CloseMsg", "Closing message window");
846  fMsg.Hide();
847  }
848  void SetStatus(const char* what)
849  {
850  fStatusBar.SetText(what,0);
851  }
852  TGMainFrame fMain;
853  TGHorizontalFrame fOpenFrame;
854  TGTextEntry fFileText;
855  TGTextButton fFileSelect;
856  TGTextEntry fTablesText;
857  TGTextButton fOpenButton;
858  TGCheckButton fRWButton;
859  TGTextButton fCloseButton;
860  TGVerticalFrame fSelectFrame;
861  TGHorizontalFrame fTableFrame;
862  TGLabel fTableLabel;
863  TGComboBox fTableSelect;
864  TGHorizontalFrame fRunFrame;
865  TGLabel fRunLabel;
866  TGNumberEntry fRunInput;
867  TGComboBox fRunMode;
868  TGHorizontalFrame fSysFrame;
869  TGLabel fSysLabel;
870  TGComboBox fSysSelect;
871  TGHorizontalFrame fSNNFrame;
872  TGLabel fSNNLabel;
873  TGNumberEntry fSNNInput;
874  TGHorizontalFrame fFldFrame;
875  TGLabel fFldLabel;
876  TGComboBox fFldSelect;
877  TGHButtonGroup fOtherFrame;
878  TGTextButton fMCButton;
879  TGTextButton fSatButton;
880  TGHorizontalFrame fOptionsFrame;
881  TGLabel fOptionsLabel;
882  TGTextEntry fOptionsText;
883  TGHButtonGroup fCommandFrame;
884  TGTextButton fQueryButton;
885  TGTextButton fListButton;
886  TGTextButton fPrintButton;
887  TGTextButton fCopyButton;
888  TGTextButton fDrawButton;
889  TGTextButton fPDFButton;
890  TGListView fList;
891  TGLVContainer fListContainer;
892  TGLayoutHints fFrameHints;
893  TGLayoutHints fLabelHints;
894  TGLayoutHints fEntryHints;
895  TGLayoutHints fButtonHints;
896  TGLayoutHints fListHints;
897  TGStatusBar fStatusBar;
898  TGLayoutHints fStatusBarHints;
902  // TCanvas* fDataCanvas;
903  // TCanvas* fEntryCanvas;
904 };
905 
906 
907 TGMainFrame* ForwardOADBGui(AliOADBForward* db=0,
908  const char* path=0)
909 {
910  const char* fwd = "$ALICE_PHYSICS/PWGLF/FORWARD/analysis2";
911  if (!gROOT->GetClass("AliOADBForward"))
912  // gSystem->Load("libGui");
913  gROOT->Macro(Form("%s/scripts/LoadLibs.C", fwd));
914 
915  // gSystem->AddIncludePath(Form("-I%s", fwd));
916  // gROOT->LoadMacro(Form("%s/corrs/ForwardOADBGUI.C", fwd));
917 
918  new TBrowser;
919  // new TGClient();
920  ForwardOADBGUI* gui = new ForwardOADBGUI();
921  if (db) {
922  gui->UseDB(db);
923  if (path) gui->SetStatus(Form("Connected to %s", path));
924  }
925  return gui->GetMain();
926 }
927 
928 //
929 // EOF
930 //
931 
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
TSystem * gSystem
TGComboBox fSysSelect
ForwardOADBGUI & operator=(const ForwardOADBGUI &)
void Show(const char *msg)
void HandleDBEntry(AliOADBForward::Entry *e)
void HandleEntry(Int_t i, AliOADBForward::Entry *e)
TGTextEntry fOptionsText
ForwardOADBDialog fMsg
void CorrDraw(const TObject *o, Bool_t summarize)
TGLayoutHints fEntryHints
Table * FindTable(const TString &name, Bool_t quite=false) const
TGComboBox fFldSelect
TGComboBox fTableSelect
TString fAuthor
ULong_t fRunNo
void HandleItem(TGFrame *lve, Int_t btn)
Bool_t CopyEntry(const TString &table, ULong_t oldRunNo, UShort_t oldSys, UShort_t oldSNN, Short_t oldField, ULong_t newRunNo, UShort_t newSys, UShort_t newSNN, Short_t newField, Bool_t mc, Bool_t sat)
int Int_t
Definition: External.C:63
TGTextButton fCloseButton
Bool_t fMC
TGHorizontalFrame fRunFrame
void SetStatus(const char *what)
const TMap & GetTables() const
void MakeFileName(TString &out) const
TGTextButton fCopyButton
void HandleTable(Int_t id)
TGTextButton fPrintButton
TGTextEntry fFileText
ForwardOADBDialog(TGMainFrame *p)
TGTextButton fPDFButton
TGTextButton fQueryButton
TGTextEntry fTablesText
unsigned long ULong_t
Definition: External.C:38
TGTransientFrame fFrame
Int_t mode
Definition: anaM.C:41
Bool_t fSatellite
ForwardOADBDialog(const ForwardOADBDialog &)
TGTextButton fMCButton
void UseDB(AliOADBForward *db)
void Print(Option_t *option="") const
short Short_t
Definition: External.C:23
TGHButtonGroup fCommandFrame
TGTextButton fSatButton
TGHorizontalFrame fTableFrame
TGLayoutHints fHints
TGTextButton fOpenButton
const char * fwd
TGTextButton fDrawButton
ForwardOADBDialog & operator=(const ForwardOADBDialog &)
TGComboBox fRunMode
TGHButtonGroup fOtherFrame
TGMainFrame fMain
TGCheckButton fRWButton
TGVerticalFrame fSelectFrame
Entry * Get(const TString &table, ULong_t run=0, ERunSelectMode mode=kNear, UShort_t sys=0, UShort_t sNN=0, Short_t fld=0, Bool_t mc=false, Bool_t sat=false) const
TGTextButton fListButton
TGHorizontalFrame fSNNFrame
unsigned short UShort_t
Definition: External.C:28
TGListView fList
TGNumberEntry fRunInput
UInt_t fTimestamp
TGLayoutHints fButtonHints
bool Bool_t
Definition: External.C:53
Short_t fField
Bool_t Open(const TString &fileName, const TString &tables="*", Bool_t rw=false, Bool_t verb=false, Bool_t fallback=false)
void MakeMsg(const char *what)
TGTextButton fFileSelect
TGHorizontalFrame fFldFrame
TGLayoutHints fLabelHints
TObject * HandleQuery()
TObject * fData
TGLayoutHints fListHints