LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
JobMenu.cxx
Go to the documentation of this file.
1 #include <cstdlib>
9 #include <string>
10 #include <iostream>
11 #include "TROOT.h"
12 #include "TSystem.h"
13 #include "TGMsgBox.h"
14 #include "TGMenu.h"
15 #include "TGLayout.h"
16 #include "TGFileDialog.h"
17 #include "TTimer.h"
18 
22 
23 namespace evdb{
24 
25  // Define ID codes for the actions on the file menu
26  enum {
27  kM_JOB_OPENXML = 99001,
29  kM_JOB_RESETJOB = 99003,
31  };
32 
33  //......................................................................
34 
35  JobMenu::JobMenu(TGMenuBar* menubar, TGMainFrame* /*mf*/)
36  //: fMainFrame(mf)
37  {
38  //======================================================================
39  // Build the help menu
40  //======================================================================
41  fJobMenu = new TGPopupMenu(gClient->GetRoot());
42  fLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
43 
44  fConfigMenu = new TGPopupMenu();
45  fServiceMenu = new TGPopupMenu();
46 
47  // Create the list of functions. Associate each which a command code
48  fJobMenu->AddEntry("&Load job", kM_JOB_OPENXML);
49  fJobMenu->AddEntry("&Reset Job", kM_JOB_RESETJOB);
50  fJobMenu->AddSeparator();
51  fJobMenu->AddPopup("&Configure Module", fConfigMenu);
52  fJobMenu->AddSeparator();
53  fJobMenu->AddPopup("&Configure Service", fServiceMenu);
54 
55  // Connect only the fJobMenu - the other pop-ups that are embedded in
56  // it do not get their own signals for some reason known only to the
57  // ROOT developers
58  fJobMenu->Connect("Activated(Int_t)",
59  "evdb::JobMenu",
60  this,
61  "HandleMenu(int)");
62 
63  // Attach the menu to the menu bar
64  menubar->AddPopup("&Job",fJobMenu,fLayout);
65  }
66 
67  //......................................................................
68 
70  {
71  //======================================================================
72  // Delete the job menu
73  //======================================================================
74  if (fLayout) { delete fLayout; fLayout = 0; }
75  if (fJobMenu) { delete fJobMenu; fJobMenu = 0; }
76  }
77 
78  //......................................................................
79 
80  void JobMenu::SetWorkers(const std::vector<std::string>& w)
81  {
82  // Wipe out the existing menus and lists
83  for (unsigned int i=0;;++i) {
84  TGMenuEntry* m = fConfigMenu->GetEntry(i);
85  if (m) fConfigMenu->DeleteEntry(i);
86  else break;
87  }
88 
89  // Rebuild the list
90  for (unsigned int i=0; i<w.size(); ++i) {
91  fConfigMenu->AddEntry(w[i].c_str(), kM_JOB_EDITCONFIG+i);
92  }
93  }
94 
95  //......................................................................
96 
97  void JobMenu::SetServices(const std::vector<std::string>& w)
98  {
99  // Wipe out the existing menus and lists
100  for (unsigned int i=0;;++i) {
101  TGMenuEntry* m = fConfigMenu->GetEntry(i);
102  if (m) fConfigMenu->DeleteEntry(i);
103  else break;
104  }
105 
106  // Rebuild the list
107  for (unsigned int i=0; i<w.size(); ++i) {
108  fServiceMenu->AddEntry(w[i].c_str(), kM_JOB_EDITSERVICE+i);
109  }
110  }
111 
112  //......................................................................
113 
114  void JobMenu::HandleMenu(int menu)
115  {
116  //======================================================================
117  // Take care of menu events
118  //======================================================================
119  switch(menu) {
120  case kM_JOB_OPENXML:
121  this->OpenJob();
122  break;
123  case kM_JOB_RESETJOB:
124  this->ResetJob();
125  break;
126  default:
127  if(menu >= kM_JOB_EDITCONFIG &&
128  menu < kM_JOB_EDITSERVICE) this->EditConfig(menu);
129  else if(menu >= kM_JOB_EDITSERVICE) this->EditService(menu);
130  break;
131  }
132  }
133 
134  //......................................................................
135 
136  void JobMenu::EditConfig(int /*i*/)
137  {
138  // make sure to subtract off the offset used to distinguish between
139  // module and service configs
140  // art::ServiceHandle<evdb::EventDisplay> evd;
141  // evd->EditWorkerParameterSet(i-kM_JOB_EDITCONFIG);
142  }
143 
144  //......................................................................
145 
146  void JobMenu::EditService(int /*i*/)
147  {
148  // make sure to subtract off the offset used to distinguish between
149  // module and service configs
150  // art::ServiceHandle<evdb::EventDisplay> evd;
151  // evd->EditServiceParameterSet(i-kM_JOB_EDITSERVICE);
152  }
153 
154  //......................................................................
155 
157  {
158  // not every experiment uses SRT, so be sure to have
159  // a non-SRT option for the directory
160  static TString dir("./");
161  char* dirchar = getenv("SRT_PRIVATE_CONTEXT");
162  if(dirchar) dir = dirchar;
163  const char* filetypes[] = {
164  "Configuration Files", "*.fcl",
165  0, 0
166  };
167 
168  TGFileInfo finfo;
169  finfo.fIniDir = StrDup(dir.Data());
170  finfo.fFileTypes = filetypes;
171 
172  new TGFileDialog(gClient->GetRoot(),
173  gClient->GetRoot(),
174  kFDOpen,
175  &finfo);
176  if (finfo.fFilename == 0) return 0;
177 
178  return 0;
179  }
180 
181  //......................................................................
182 
184  {
185  // jobc::Stack::Instance().CleanUp();
186  }
187 
188 }// namespace
TGPopupMenu * fJobMenu
The file menu.
Definition: JobMenu.h:43
TGPopupMenu * fConfigMenu
The module configuration menu.
Definition: JobMenu.h:44
TGLayoutHints * fLayout
How to layout the menu.
Definition: JobMenu.h:46
Manage all things related to colors for the event display.
void HandleMenu(int menu)
Definition: JobMenu.cxx:114
void SetWorkers(const std::vector< std::string > &w)
Definition: JobMenu.cxx:80
The interactive event display.
void EditConfig(int cfg)
Definition: JobMenu.cxx:136
void ResetJob()
Definition: JobMenu.cxx:183
TDirectory * dir
Definition: macro.C:5
void EditService(int cfg)
Definition: JobMenu.cxx:146
virtual ~JobMenu()
Definition: JobMenu.cxx:69
Float_t w
Definition: plot.C:23
JobMenu(TGMenuBar *menubar, TGMainFrame *mf)
Definition: JobMenu.cxx:35
int OpenJob()
Definition: JobMenu.cxx:156
void SetServices(const std::vector< std::string > &w)
Definition: JobMenu.cxx:97
The job pull down menu.
TGPopupMenu * fServiceMenu
The user service configuration menu.
Definition: JobMenu.h:45