DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EventControl.cpp
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 
15 // Framework include files
16 #include "DDEve/Display.h"
17 #include "DDEve/EventControl.h"
18 #include "DDEve/EventHandler.h"
19 #include "DD4hep/InstanceCount.h"
20 
21 // ROOT include files
22 #include <TSystem.h>
23 #include <TGTab.h>
24 #include <TGLabel.h>
25 #include <TGFrame.h>
26 #include <TGButton.h>
27 #include <TG3DLine.h>
28 #include "TGFileDialog.h"
29 
30 #include "TTree.h"
31 #include <libgen.h>
32 
33 using namespace std;
34 using namespace DD4hep;
35 
37 
38 EventControl::EventControl(Display* display, unsigned int width, unsigned int height)
40 : FrameControl(&display->client(), "EventControl GUI", width, height), EventConsumer(),
41  m_display(display), m_dataGroup(0), m_dataFrame(0), m_numEvtFrame(0), m_input1(0), m_input2(0),
42  m_open(0), m_prev(0), m_next(0), m_goto(0)
43 {
44  SetWindowName("XX GUI");
45  m_display->eventHandler().Subscribe(this);
46  InstanceCount::increment(this);
47 }
48 
50 EventControl::~EventControl() {
51  m_display->eventHandler().Unsubscribe(this);
52  InstanceCount::decrement(this);
53 }
54 
56 TGCompositeFrame* EventControl::CreateFrame() {
57  return new TGVerticalFrame(this);
58 }
59 
61 void EventControl::NextEvent() {
62  m_display->eventHandler().NextEvent();
63 }
64 
66 void EventControl::PreviousEvent() {
67  m_display->eventHandler().PreviousEvent();
68 }
69 
71 void EventControl::GotoEvent() {
72  long number = 0;
73  m_display->eventHandler().GotoEvent(number);
74 }
75 
77 bool EventControl::Open() {
78  // e- shots:
79  //m_display->eventHandler().Open("/home/frankm/SW/DD4hep_head_dbg.root_v5.34.10/build/CLICSiD_2014-06-10_15-26.root");
80  // pi- shots:
81  //m_display->eventHandler().Open("/home/frankm/SW/DD4hep_head_dbg.root_v5.34.10/build/CLICSiD_2014-06-18_12-48.root");
82 
83  std::string fname = m_display->OpenEventFileDialog(".");
84  if ( !fname.empty() ) {
85  return m_display->eventHandler().Open(m_display->getEventHandlerName(),fname);
86  }
87  return false;
88 }
89 
91 void EventControl::OnFileOpen(EventHandler* handler) {
92  char text[1024], fname[1024];
93  ::strncpy(fname, handler->datasourceName().c_str(), sizeof(fname)-1);
94  fname[sizeof(fname)-1] = 0;
95  // -----------------------------------------------------------------------------------------
96  if ( handler && handler->hasFile() ) {
97  ::snprintf(text,sizeof(text),"Number of events: %ld",handler->numEvents());
98  m_input1->SetText(::basename(fname));
99  m_input2->SetText(text);
100  }
101  else {
102  ::snprintf(text,sizeof(text),"Currently NO input defined");
103  m_input1->SetText("");
104  m_input2->SetText(text);
105  }
106  m_eventGroup->Layout();
107  client().NeedRedraw(m_eventGroup,kTRUE);
108 }
109 
111 void EventControl::OnNewEvent(EventHandler* handler) {
113  typedef std::vector<EventHandler::Collection> Collections;
114  const Types& types = handler->data();
115  size_t cnt = 1;
116  m_lines[0].second.first->SetText("Hit collection name");
117  m_lines[0].second.second->SetText("No.Hits");
118  for(Types::const_iterator i=types.begin(); i!=types.end() && cnt+1<m_lines.size(); ++i) {
119  const Collections& colls = (*i).second;
120  Line line = m_lines[cnt++];
121  string cl = (*i).first;
122  size_t idx = cl.rfind("Geant4");
123  if ( idx != string::npos ) {
124  cl = cl.substr(idx);
125  cl = cl.substr(0,cl.find('*'));
126  }
127  else if ( (idx=cl.rfind("::")) != string::npos ) {
128  cl = cl.substr(idx+2);
129  if ( (idx=cl.rfind('*')) != string::npos ) cl = cl.substr(0,idx);
130  if ( (idx=cl.rfind('>')) != string::npos ) cl = cl.substr(0,idx);
131  }
132  line.second.first->SetTextColor(kRed);
133  line.second.second->SetTextColor(kRed);
134  line.second.first->SetText(("Coll.Type: "+cl).c_str());
135  line.second.second->SetText("");
136  for(Collections::const_iterator j=colls.begin(); j!=colls.end() && cnt+1<m_lines.size(); ++j) {
137  char text[132];
138  ::snprintf(text,sizeof(text),"%ld",long((*j).second));
139  line = m_lines[cnt++];
140  line.second.first->SetText((*j).first);
141  line.second.second->SetText(text);
142  line.second.first->SetTextColor(kBlack);
143  line.second.second->SetTextColor(kBlack);
144  }
145  }
146  for(; cnt<m_lines.size(); ) {
147  Line line = m_lines[cnt++];
148  line.second.first->SetText("");
149  line.second.second->SetText("");
150  }
151  m_dataGroup->Layout();
152  client().NeedRedraw(m_dataGroup,kTRUE);
153 }
154 
156 void EventControl::OnBuild() {
157  string icondir = TString::Format("%s/icons/", gSystem->Getenv("ROOTSYS")).Data();
158  TGGroupFrame* group = new TGGroupFrame(m_frame,"Event I/O Control");
159  TGCompositeFrame* top = new TGHorizontalFrame(group);
160  TGPictureButton* b = 0;
161  char text[1024];
162  group->SetTitlePos(TGGroupFrame::kLeft);
163  m_frame->AddFrame(group, new TGLayoutHints(kLHintsExpandX|kLHintsCenterX, 2, 2, 2, 2));
164  m_eventGroup = group;
165  // -----------------------------------------------------------------------------------------
166  m_numEvtFrame = new TGVerticalFrame(group);
167  if ( m_display->eventHandler().hasFile() ) {
168  ::snprintf(text,sizeof(text),"Number of events: %ld",m_display->eventHandler().numEvents());
169  m_input1 = new TGLabel(m_numEvtFrame,m_display->eventHandler().datasourceName().c_str());
170  m_input2 = new TGLabel(m_numEvtFrame,text);
171  }
172  else {
173  ::snprintf(text,sizeof(text),"Currently NO input defined");
174  m_input1 = new TGLabel(m_numEvtFrame,"");
175  m_input2 = new TGLabel(m_numEvtFrame,text);
176  }
177  m_numEvtFrame->AddFrame(m_input1, new TGLayoutHints(kLHintsNormal, 2, 0, 2, 2));
178  m_numEvtFrame->AddFrame(m_input2, new TGLayoutHints(kLHintsNormal, 2, 0, 2, 2));
179  group->AddFrame(m_numEvtFrame, new TGLayoutHints(kLHintsExpandX|kLHintsCenterX, 2, 2, 2, 2));
180  // -----------------------------------------------------------------------------------------
181  top->AddFrame(new TGLabel(top,"Open event file:"), new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2, 2, 2, 2));
182  m_open = b = new TGPictureButton(top, LoadPicture((icondir+"bld_open.png")));
183  b->Connect("Clicked()", "DD4hep::EventControl", this, "Open()");
184  b->SetSize(TGDimension(32,32));
185  top->AddFrame(b, new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
186  group->AddFrame(top, new TGLayoutHints(kLHintsExpandX|kLHintsCenterX, 2, 2, 2, 2));
187  // -----------------------------------------------------------------------------------------
188  top = new TGHorizontalFrame(group);
189  top->AddFrame(new TGLabel(top,"Previous:"), new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2, 2, 2, 2));
190  m_prev = b = new TGPictureButton(top, LoadPicture((icondir+"bld_undo.png")));
191  b->Connect("Clicked()", "DD4hep::EventControl", this, "PreviousEvent()");
192  b->SetSize(TGDimension(32,32));
193  top->AddFrame(b, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
194 
195  top->AddFrame(new TGLabel(top,""), new TGLayoutHints(kLHintsExpandX|kLHintsCenterY, 2, 2, 2, 2));
196  top->AddFrame(new TGLabel(top,"Next:"), new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2, 2, 2, 2));
197  m_next = b = new TGPictureButton(top, LoadPicture((icondir+"bld_redo.png")));
198  b->Connect("Clicked()", "DD4hep::EventControl", this, "NextEvent()");
199  b->SetSize(TGDimension(32,32));
200  top->AddFrame(b, new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
201  group->AddFrame(top,new TGLayoutHints(kLHintsExpandX|kLHintsCenterX, 2, 2, 2, 2));
202  // -----------------------------------------------------------------------------------------
203  top = new TGHorizontalFrame(group);
204  top->AddFrame(new TGLabel(top,"Goto event:"), new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2, 2, 2, 2));
205  m_goto = b = new TGPictureButton(top, LoadPicture((icondir+"ed_goto.png")));
206  b->Connect("Clicked()", "DD4hep::EventControl", this, "GotoEvent()");
207  b->SetSize(TGDimension(32,32));
208  top->AddFrame(b, new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
209  group->AddFrame(top,new TGLayoutHints(kLHintsExpandX|kLHintsCenterX, 2, 2, 2, 2));
210  // -----------------------------------------------------------------------------------------
211  group = new TGGroupFrame(m_frame,"Event data",200);
212  m_frame->AddFrame(group,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsExpandY, 0, 0, 2, 2));
213  m_dataFrame = new TGVerticalFrame(group);
214  for(int i=0; i<NUM_DATA_LINES; ++i) {
215  Line line;
216  TGCompositeFrame* fr = new TGHorizontalFrame(m_dataFrame);
217  fr->AddFrame(line.second.first=new TGLabel(fr,""), new TGLayoutHints(kLHintsNormal, 2, 0, 2, 2));
218  fr->AddFrame(line.second.second=new TGLabel(fr,""), new TGLayoutHints(kLHintsRight, 20, 1, 2, 2));
219  line.first = fr;
220  m_lines.push_back(line);
221  m_dataFrame->AddFrame(fr,new TGLayoutHints(kLHintsExpandX));
222  }
223  group->AddFrame(m_dataFrame, new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY));
224  m_dataGroup = group;
225  // -----------------------------------------------------------------------------------------
226 }
227 
virtual bool hasFile() const
Check if a data file is connected to the handler.
Definition: EventHandler.h:94
virtual long numEvents() const =0
Access the number of events on the current input data source (-1 if no data source connected) ...
virtual std::string datasourceName() const =0
Access the data source name.
ClassImp(EventControl) EventControl
Standard constructor.
Event handler base class. Interface to all DDEve I/O actions.
Definition: EventHandler.h:66
virtual const TypedEventCollections & data() const =0
Access the map of simulation data collections.
std::pair< TGCompositeFrame *, Labels > Line
Definition: EventControl.h:51
class FrameControl FrameControl.h DDEve/FrameControl.h
Definition: FrameControl.h:37
std::map< std::string, std::vector< Collection > > TypedEventCollections
Types collection: collections are grouped by type (class name)
Definition: EventHandler.h:79
The main class of the DDEve display.
Definition: Display.h:57