Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EventDispUI.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <sys/stat.h>
4 #include <TSystem.h>
5 #include <TFile.h>
6 #include <TTree.h>
7 #include <TEveManager.h>
8 #include <TEveBrowser.h>
9 #include <TGFrame.h>
10 #include <TGButton.h>
11 #include <TGLabel.h>
12 #include <TGNumberEntry.h>
13 #include <UtilAna/UtilOnline.h>
14 #include <fun4all/Fun4AllServer.h>
16 #include <evt_filter/EvtFilter.h>
17 #include "PHEventDisplay.h"
18 #include "EventDispUI.h"
19 using namespace std;
20 
22  : m_run(0)
23  , m_n_evt(0)
24  , m_i_evt(0)
25  , m_fr_main(0)
26  , m_fr_menu(0)
27  , m_fr_evt_sel(0)
28  , m_fr_evt_next(0)
29  , m_fr_evt_prev(0)
30  , m_lbl_mode(0)
31  , m_lbl_run(0)
32  , m_lbl_n_evt(0)
33  , m_ne_evt_id(0)
34  , m_ne_trig(0)
35  , m_online_mode(true)
36  , m_auto_mode(true)
37  , m_tid1(0)
38 {
39  ;
40 }
41 
42 std::string EventDispUI::GetDstPath(const int run)
43 {
44  return m_online_mode ? UtilOnline::GetEDDstFilePath(run) : UtilOnline::GetDstFilePath(run);
45 }
46 
48 {
49  int nn = m_list_run.size();
50  int run = nn > 0 ? m_list_run[nn-1] : RUN_MIN;
51  while (++run < RUN_MAX) {
52  string fname = GetDstPath(run);
53  if (! gSystem->AccessPathName(fname.c_str())) { // if exists
54  m_list_run.push_back(run);
55  }
56  }
57  return m_list_run.size() > nn;
58 }
59 
61 {
62  int ret = -1;
63  TFile* file = new TFile(GetDstPath(run).c_str());
64  if (file->IsOpen()) {
65  TTree* tree = (TTree*)file->Get("T");
66  if (tree) ret = tree->GetEntries();
67  }
68  delete file;
69  return ret;
70 }
71 
73 {
74  cout << "EventDispUI::OpenRunFile(): run = " << run << endl;
75  m_run = run;
76  m_n_evt = FetchNumEvents(run);
77  m_i_evt = 0;
78  UpdateLabels();
80  return in->fileopen(GetDstPath(run));
81 }
82 
84 {
85  if (m_online_mode && m_auto_mode) {
86  cout << "NextEvent(): Ignored in auto mode." << endl;
87  return;
88  }
89  if (m_i_evt >= m_n_evt) {
90  cout << "NextEvent(): No next event." << endl;
91  return;
92  }
94  m_i_evt++;
95  cout << "Next: " << m_i_evt << " / " << m_n_evt << endl;
96  UpdateLabels();
97  if (se->run(1, true) != 0) {
98  cout << "NextEvent() failed. No event remains?" << endl;
99  }
100 }
101 
103 {
104  if (m_online_mode && m_auto_mode) {
105  cout << "PrevEvent(): Ignored in auto mode." << endl;
106  return;
107  }
108  if (m_i_evt < 2) {
109  cout << "PrevEvent(): No previous events." << endl;
110  return;
111  }
112  int i_new = m_i_evt - 1;
113  cout << "Prev: " << i_new << " / " << m_n_evt << endl;
114  if (OpenRunFile(m_run) != 0) {
115  cout << "PrevEvent(): Cannot reopen DST." << endl;
116  return;
117  }
118  m_i_evt = i_new;
119  UpdateLabels();
121  if (m_i_evt > 1) se->skip(m_i_evt - 1); // First move to the previous-to-previous event.
122  if (se->run(1, true) != 0) { // Then read the previous event.
123  cout << "PrevEvent() failed." << endl;
124  }
125 }
126 
127 void EventDispUI::MoveEvent(const int i_evt)
128 {
129  if (i_evt > m_n_evt) {
130  OpenRunFile(m_run);
131  if (i_evt > m_n_evt) {
132  cout << "Unexpected!!" << endl;
133  return;
134  }
135  }
136  int i_move = i_evt - m_i_evt;
137  m_i_evt = i_evt;
138  UpdateLabels();
140  if (i_move > 1) se->skip(i_move - 1); // First move to the previous event.
141  if (se->run(1, true) != 0) { // Then read the previous event.
142  cout << "MoveEvent() failed." << endl;
143  }
144 }
145 
147 {
148  int num = (int)m_ne_evt_id->GetNumberEntry()->GetIntNumber();
149  cout << "ReqEvtID: " << num << endl;
150  EvtFilter* filter = (EvtFilter*)Fun4AllServer::instance()->getSubsysReco("EvtFilter");
151  filter->set_event_id_req(num);
152 }
153 
155 {
156  int num = (int)m_ne_trig->GetNumberEntry()->GetIntNumber();
157  cout << "ReqTrig: " << num << endl;
158  EvtFilter* filter = (EvtFilter*)Fun4AllServer::instance()->getSubsysReco("EvtFilter");
159  filter->set_trigger_req(num);
160 }
161 
163 {
164  cout << "Top View" << endl;
166  disp->set_view_top();
167 }
168 
170 {
171  cout << "Side View" << endl;
173  disp->set_view_side();
174 }
175 
177 {
178  cout << "3D View" << endl;
180  disp->set_view_3d();
181 }
182 
184 {
185  ostringstream oss;
186  oss << (m_online_mode ? "Online" : "Offline") << " Mode";
187  m_lbl_mode->SetText(oss.str().c_str());
188 
189  oss.str("");
190  oss << "Run " << m_run;
191  m_lbl_run->SetText(oss.str().c_str());
192 
193  oss.str("");
194  oss << "Event " << m_i_evt << " / " << m_n_evt;
195  m_lbl_n_evt->SetText(oss.str().c_str());
196 }
197 
198 void EventDispUI::SetAutoMode(bool value)
199 {
200  m_auto_mode = value;
201  UpdateInterface();
202 }
203 
207 void EventDispUI::Init(const bool online_mode)
208 {
209  m_online_mode = online_mode;
210  if (! FindNewRuns()) {
211  cout << "EventDispUI::Init(): Found no run. Abort." << endl;
212  exit(1);
213  }
214  m_run = m_list_run.back();
215  if (! online_mode) {
216  cout << "\nHit only 'Enter' to select the last run, " << m_list_run.back() << ".\n"
217  << "Or input a run number that you select.\n";
218  while (true) {
219  cout << "Run? " << flush;
220  char line[64];
221  cin.getline(line, 64);
222  if (line[0] == '\0') {
223  m_run = m_list_run.back();
224  } else if ((m_run = atoi(line)) <= 0) {
225  cout << " Invalid input." << endl;
226  continue;
227  }
228  break;
229  }
230  }
231 }
232 
234 {
235  BuildInterface();
236  OpenRunFile(m_run);
237  MoveEvent(1); // Need process one event here, before calling "FuncNewEventCheck"
238  if (m_online_mode) {
239  pthread_create(&m_tid1, NULL, FuncNewEventCheck, this);
240  }
241 }
242 
244 {
245  TEveBrowser* browser = gEve->GetBrowser();
246  browser->StartEmbedding(TRootBrowser::kLeft);
247 
248  m_fr_main = new TGMainFrame(gClient->GetRoot(), 1000, 600);
249  m_fr_main->SetWMPosition(0, 0); // Often ignored by the window manager
250  m_fr_main->SetWindowName("Event Display");
251  m_fr_main->SetCleanup(kDeepCleanup);
252 
253  m_fr_menu = new TGVerticalFrame(m_fr_main);
254 
255  TGLabel* lab = 0;
256  lab = new TGLabel(m_fr_menu, "- - - Event Info - - -");
257  m_fr_menu->AddFrame(lab, new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 2,2,2,2));
258 
259  m_lbl_mode = new TGLabel(m_fr_menu, "Online/Offline Mode");
260  m_fr_menu->AddFrame(m_lbl_mode, new TGLayoutHints(kLHintsExpandX, 2,2,2,2));
261 
262  m_lbl_run = new TGLabel(m_fr_menu, "Run ??????");
263  m_fr_menu->AddFrame(m_lbl_run, new TGLayoutHints(kLHintsCenterY | kLHintsExpandX | kLHintsLeft, 2,2,2,2));
264 
265  m_lbl_n_evt = new TGLabel(m_fr_menu, "Event ?? / ??");
266  m_fr_menu->AddFrame(m_lbl_n_evt, new TGLayoutHints(kLHintsCenterY | kLHintsExpandX | kLHintsLeft, 2,2,2,2));
267 
268  lab = new TGLabel(m_fr_menu, "- - - Event Navigation - - -");
269  m_fr_menu->AddFrame(lab, new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 2,2,10,2));
270 
271  { // m_fr_evt_mode
272  m_fr_evt_mode = new TGCompositeFrame(m_fr_menu);
273  TGCheckButton* check = new TGCheckButton(m_fr_evt_mode, new TGHotString("Auto mode"), 99);
274  check->SetToolTipText("When checked, the last sampled event is automatically shown.");
275  check->SetState(m_auto_mode ? kButtonDown : kButtonUp);
276  check->Connect("Toggled(Bool_t)", "EventDispUI", this, "SetAutoMode(Bool_t)");
277  m_fr_evt_mode->AddFrame(check);
278  m_fr_menu->AddFrame(m_fr_evt_mode, new TGLayoutHints(kLHintsCenterX, 5, 5, 2, 2));
279  }
280 
281  TGTextButton* butt;
282  { // m_fr_evt_sel
283  m_fr_evt_sel = new TGCompositeFrame(m_fr_menu);
284 
285  TGHorizontalFrame* frm1 = 0;
286  frm1 = new TGHorizontalFrame(m_fr_evt_sel);
287  lab = new TGLabel(frm1, "Event ID");
288  frm1->AddFrame(lab, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 5, 3, 4));
289  m_ne_evt_id = new TGNumberEntry(frm1, -1, 9, 999, TGNumberFormat::kNESInteger,
290  TGNumberFormat::kNEAAnyNumber,
291  TGNumberFormat::kNELLimitMinMax,
292  -999999, 999999);
293  m_ne_evt_id->Connect("ValueSet(Long_t)", "EventDispUI", this, "ReqEvtID()");
294  frm1->AddFrame(m_ne_evt_id, new TGLayoutHints(kLHintsCenterY | kLHintsRight, 5, 5, 5, 5));
295  m_fr_evt_sel->AddFrame(frm1);
296 
297  frm1 = new TGHorizontalFrame(m_fr_evt_sel);
298  lab = new TGLabel(frm1, "Trigger");
299  frm1->AddFrame(lab, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 5, 3, 4));
300  m_ne_trig = new TGNumberEntry(frm1, -1, 9, 999, TGNumberFormat::kNESInteger,
301  TGNumberFormat::kNEAAnyNumber,
302  TGNumberFormat::kNELLimitMinMax,
303  -999, 999);
304  m_ne_trig->Connect("ValueSet(Long_t)", "EventDispUI", this, "ReqTrig()");
305  frm1->AddFrame(m_ne_trig, new TGLayoutHints(kLHintsCenterY | kLHintsRight, 5, 5, 5, 5));
306  m_fr_evt_sel->AddFrame(frm1);
307 
308  m_fr_menu->AddFrame(m_fr_evt_sel, new TGLayoutHints(kLHintsCenterX, 5, 5, 2, 2));
309  }
310 
311  { // m_fr_evt_next
312  m_fr_evt_next = new TGCompositeFrame(m_fr_menu);
313 
314  butt = new TGTextButton(m_fr_evt_next, "Next Event");
315  m_fr_evt_next->AddFrame(butt);
316  butt->Connect("Clicked()", "EventDispUI", this, "NextEvent()");
317 
318  m_fr_menu->AddFrame(m_fr_evt_next, new TGLayoutHints(kLHintsCenterX, 5, 5, 2, 2));
319  }
320 
321  { // m_fr_evt_prev
322  m_fr_evt_prev = new TGCompositeFrame(m_fr_menu);
323 
324  butt = new TGTextButton(m_fr_evt_prev, "Previous Event");
325  m_fr_evt_prev->AddFrame(butt);
326  butt->Connect("Clicked()", "EventDispUI", this, "PrevEvent()");
327 
328  m_fr_menu->AddFrame(m_fr_evt_prev, new TGLayoutHints(kLHintsCenterX, 5, 5, 2, 2));
329  }
330 
331  lab = new TGLabel(m_fr_menu, "- - - View Navigation - - -");
332  m_fr_menu->AddFrame(lab, new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 2,2,10,2));
333 
334  butt = new TGTextButton(m_fr_menu, " Top View ");
335  m_fr_menu->AddFrame(butt, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
336  butt->Connect("Clicked()", "EventDispUI", this, "ViewTop()");
337 
338  butt = new TGTextButton(m_fr_menu, " Side View ");
339  m_fr_menu->AddFrame(butt, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
340  butt->Connect("Clicked()", "EventDispUI", this, "ViewSide()");
341 
342  butt = new TGTextButton(m_fr_menu, " 3D View ");
343  m_fr_menu->AddFrame(butt, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
344  butt->Connect("Clicked()", "EventDispUI", this, "View3D()");
345 
346  lab = new TGLabel(m_fr_menu, "Left-button drag = Rotate");
347  m_fr_menu->AddFrame(lab, new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 2,2,2,2));
348 
349  lab = new TGLabel(m_fr_menu, "Middle-button drag = Pan");
350  m_fr_menu->AddFrame(lab, new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 2,2,2,2));
351 
352  lab = new TGLabel(m_fr_menu, "Middle-button scroll = Zoom");
353  m_fr_menu->AddFrame(lab, new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 2,2,2,2));
354 
355  butt = new TGTextButton(m_fr_menu, "Exit","gApplication->Terminate(0)");
356  m_fr_menu->AddFrame(butt, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2,2,10,2));
357 
358  m_fr_main->AddFrame(m_fr_menu);
359 
360  m_fr_main->MapSubwindows();
361  m_fr_main->Resize();
362  m_fr_main->MapWindow();
363 
364  browser->StopEmbedding();
365  browser->SetTabTitle("Event Control", 0);
366 
367  UpdateInterface();
368 }
369 
371 {
372  if (m_online_mode) {
373  m_fr_menu->ShowFrame(m_fr_evt_mode);
374  m_fr_menu->HideFrame(m_fr_evt_sel);
375  if (m_auto_mode) {
376  m_fr_menu->HideFrame(m_fr_evt_next);
377  m_fr_menu->HideFrame(m_fr_evt_prev);
378  } else {
379  m_fr_menu->ShowFrame(m_fr_evt_next);
380  m_fr_menu->ShowFrame(m_fr_evt_prev);
381  }
382  } else {
383  m_fr_menu->HideFrame(m_fr_evt_mode);
384  m_fr_menu->ShowFrame(m_fr_evt_sel);
385  m_fr_menu->ShowFrame(m_fr_evt_next);
386  m_fr_menu->HideFrame(m_fr_evt_prev);
387  }
388  m_fr_menu->Resize(); // (m_fr_menu->GetDefaultSize());
389  m_fr_menu->MapWindow();
390 }
391 
393 {
394  EventDispUI* ui = (EventDispUI*)arg;
395  ui->ExecNewEventCheck();
396 }
397 
399 {
400  while (true) {
401  if (m_auto_mode) {
402  cout << "AutoMode()" << endl;
403  if (FindNewRuns()) {
404  cout << " New run." << endl;
405  OpenRunFile(m_list_run.back());
406  }
407  int n_now = FetchNumEvents(m_run);
408  if (n_now > m_i_evt) {
409  cout << " New event." << endl;
410  MoveEvent(n_now);
411  }
412  }
413  sleep(15);
414  }
415 }
416 
void SetAutoMode(bool value)
Fun4AllInputManager * getInputManager(const char *name)
void ReqEvtID()
void NextEvent()
Definition: EventDispUI.cxx:83
void UpdateLabels()
void UpdateInterface()
static Fun4AllServer * instance()
Fun4AllServer * se
event display interface, set parameters/switches, call detector modules, control display.
int run(const int nEvents=1)
Definition: run.C:10
int skip(const int nevnts=0)
skip n events (0 means up to the end of file). Skip means read, don&#39;t process.
void BuildInterface()
#define NULL
Definition: Pdb.h:9
void ExecNewEventCheck()
bool FindNewRuns()
Definition: EventDispUI.cxx:47
static std::string GetDstFilePath(const int run)
Definition: UtilOnline.cc:74
int run(const int nevnts=0, const bool require_nevents=false)
run n events (0 means up to end of file)
std::string GetDstPath(const int run)
Definition: EventDispUI.cxx:42
static std::string GetEDDstFilePath(const int run)
Definition: UtilOnline.cc:79
void ViewTop()
int FetchNumEvents(const int run)
Definition: EventDispUI.cxx:60
void set_event_id_req(int eventIdReq)
Definition: EvtFilter.h:54
static void * FuncNewEventCheck(void *arg)
void Init(const bool online_mode)
void set_trigger_req(unsigned short triggerReq)
Definition: EvtFilter.h:46
int OpenRunFile(const int run)
Definition: EventDispUI.cxx:72
void PrevEvent()
SubsysReco * getSubsysReco(const std::string &name)
void ReqTrig()
void ViewSide()
virtual int fileopen(const std::string &)
void MoveEvent(const int i_evt)