DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
EventControl.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DDEve/Display.h>
16 #include <DDEve/EventControl.h>
17 #include <DDEve/EventHandler.h>
18 #include <DD4hep/InstanceCount.h>
19 
20 // ROOT include files
21 #include <TROOT.h>
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 dd4hep;
34 
36 
37 EventControl::EventControl(Display* display, unsigned int width, unsigned int height)
39 : FrameControl(&display->client(), "EventControl GUI", width, height), EventConsumer(),
40  m_display(display), m_dataGroup(0), m_dataFrame(0), m_eventGroup(0),
41  m_numEvtFrame(0), m_input1(0), m_input2(0), m_numEvtLabel(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  try {
53  }
54  catch(...) {
55  }
57 }
58 
60 TGCompositeFrame* EventControl::CreateFrame() {
61  return new TGVerticalFrame(this);
62 }
63 
67 }
68 
72 }
73 
76  long number = 0;
77  m_display->eventHandler().GotoEvent(number);
78 }
79 
82  std::string fname = m_display->OpenEventFileDialog(".");
83  if ( !fname.empty() ) {
85  }
86  return false;
87 }
88 
91  char text[1024], fname[1024];
92  ::strncpy(fname, handler.datasourceName().c_str(), sizeof(fname)-1);
93  fname[sizeof(fname)-1] = 0;
94  // -----------------------------------------------------------------------------------------
95  if ( handler.hasFile() ) {
96  ::snprintf(text,sizeof(text),"Number of events: %ld",handler.numEvents());
97  m_input1->SetText(::basename(fname));
98  m_input2->SetText(text);
99  }
100  else {
101  ::snprintf(text,sizeof(text),"Currently NO input defined");
102  m_input1->SetText("");
103  m_input2->SetText(text);
104  }
105  m_eventGroup->Layout();
106  client().NeedRedraw(m_eventGroup,kTRUE);
107 }
108 
112  typedef std::vector<EventHandler::Collection> Collections;
113  const Types& types = handler.data();
114  std::size_t cnt = 1;
115  m_lines[0].second.first->SetText("Hit collection name");
116  m_lines[0].second.second->SetText("No.Hits");
117  for(const auto& t : types) {
118  const Collections& colls = t.second;
119  Line line = m_lines[cnt++];
120  std::string cl = t.first;
121  std::size_t idx = cl.rfind("Geant4");
122  if ( idx != std::string::npos ) {
123  cl = cl.substr(idx);
124  cl = cl.substr(0,cl.find('*'));
125  }
126  else if ( (idx=cl.rfind("::")) != std::string::npos ) {
127  cl = cl.substr(idx+2);
128  if ( (idx=cl.rfind('*')) != std::string::npos ) cl = cl.substr(0,idx);
129  if ( (idx=cl.rfind('>')) != std::string::npos ) cl = cl.substr(0,idx);
130  }
131  line.second.first->SetTextColor(kRed);
132  line.second.second->SetTextColor(kRed);
133  line.second.first->SetText(("Coll.Type: "+cl).c_str());
134  line.second.second->SetText("");
135  for(const auto& c : colls) {
136  char text[132];
137  ::snprintf(text,sizeof(text),"%ld",long(c.second));
138  line = m_lines[cnt++];
139  line.second.first->SetText(c.first);
140  line.second.second->SetText(text);
141  line.second.first->SetTextColor(kBlack);
142  line.second.second->SetTextColor(kBlack);
143  }
144  }
145  for(; cnt<m_lines.size(); ) {
146  Line line = m_lines[cnt++];
147  line.second.first->SetText("");
148  line.second.second->SetText("");
149  }
150  m_dataGroup->Layout();
151  client().NeedRedraw(m_dataGroup,kTRUE);
152 }
153 
156  std::string icondir = TString::Format("%s/", TROOT::GetIconPath().Data()).Data();
157  TGGroupFrame* group = new TGGroupFrame(m_frame,"Event I/O Control");
158  TGCompositeFrame* top = new TGHorizontalFrame(group);
159  TGPictureButton* b = 0;
160  char text[1024];
161 
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 
dd4hep::Display
The main class of the DDEve display.
Definition: Display.h:56
dd4hep::EventControl::m_eventGroup
TGGroupFrame * m_eventGroup
Data frame.
Definition: EventControl.h:45
dd4hep::Display::getEventHandlerName
std::string getEventHandlerName()
Get Event Handler Plugin name.
Definition: Display.h:139
dd4hep::EventControl::m_prev
TGPictureButton * m_prev
Definition: EventControl.h:49
dd4hep::EventControl::m_input2
TGLabel * m_input2
Definition: EventControl.h:47
dd4hep::EventHandler
Event handler base class: Interface to all DDEve I/O actions.
Definition: EventHandler.h:67
dd4hep::Display::OpenEventFileDialog
std::string OpenEventFileDialog(const std::string &default_dir) const
Popup ROOT file chooser. returns chosen file name; empty on cancel.
Definition: Display.cpp:313
dd4hep::EventControl::OnNewEvent
virtual void OnNewEvent(EventHandler &handler) override
EventConsumer overload: New consumer event data.
Definition: EventControl.cpp:110
dd4hep::EventControl::m_goto
TGPictureButton * m_goto
Definition: EventControl.h:49
dd4hep::EventControl::m_dataGroup
TGGroupFrame * m_dataGroup
Data frame.
Definition: EventControl.h:42
dd4hep::FrameControl::client
TGClient & client() const
Access to the windows client.
Definition: FrameControl.h:50
dd4hep::GenericEventHandler::datasourceName
virtual std::string datasourceName() const override
Access the data source name.
Definition: GenericEventHandler.cpp:71
dd4hep::EventControl::GotoEvent
virtual void GotoEvent()
Goto a specified event.
Definition: EventControl.cpp:75
dd4hep::EventControl::Open
virtual bool Open()
Open a new event data file.
Definition: EventControl.cpp:81
dd4hep::EventControl::NextEvent
virtual void NextEvent()
Load the next event.
Definition: EventControl.cpp:65
dd4hep::EventHandler::datasourceName
virtual std::string datasourceName() const =0
Access the data source name.
dd4hep::EventControl::m_input1
TGLabel * m_input1
Definition: EventControl.h:47
dd4hep::EventControl::m_open
TGPictureButton * m_open
Definition: EventControl.h:49
dd4hep::GenericEventHandler::NextEvent
virtual bool NextEvent() override
Load the next event.
Definition: GenericEventHandler.cpp:147
dd4hep::EventConsumer
Event event consumer base class for DDEve: Interface class for event I/O.
Definition: EventHandler.h:127
dd4hep::EventControl::CreateFrame
TGCompositeFrame * CreateFrame() override
Create the frame for this control structure. Default: create horizontal frame.
Definition: EventControl.cpp:60
dd4hep::EventHandler::hasFile
virtual bool hasFile() const
Check if a data file is connected to the handler.
Definition: EventHandler.h:95
dd4hep::EventControl::OnBuild
virtual void OnBuild() override
User callback to add elements to the control.
Definition: EventControl.cpp:155
dd4hep::GenericEventHandler::GotoEvent
virtual bool GotoEvent(long event_number) override
Goto a specified event in the file.
Definition: GenericEventHandler.cpp:182
ClassImp
ClassImp(EventControl) EventControl
Standard constructor.
Definition: EventControl.cpp:35
dd4hep::EventControl::PreviousEvent
virtual void PreviousEvent()
Load the previous event.
Definition: EventControl.cpp:70
dd4hep::FrameControl::m_frame
TGCompositeFrame * m_frame
Reference to control's frame.
Definition: FrameControl.h:42
dd4hep::EventControl::EventControl
EventControl(Display *disp, unsigned int width, unsigned int height)
Standard constructor.
dd4hep::GenericEventHandler::PreviousEvent
virtual bool PreviousEvent() override
User overloadable function: Load the previous event.
Definition: GenericEventHandler.cpp:171
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
Display.h
dd4hep::EventControl::m_next
TGPictureButton * m_next
Definition: EventControl.h:49
dd4hep::EventControl
Event input control for DDEve: Interface class for event I/O.
Definition: EventControl.h:37
EventHandler.h
dd4hep::EventControl::m_lines
Lines m_lines
Definition: EventControl.h:53
dd4hep::FrameControl::LoadPicture
virtual const TGPicture * LoadPicture(const std::string &path)
Helper: Load picture using path name.
Definition: FrameControl.cpp:65
dd4hep::GenericEventHandler::Open
virtual bool Open(const std::string &type, const std::string &file_name) override
Open a new event data file.
Definition: GenericEventHandler.cpp:100
dd4hep::GenericEventHandler::numEvents
virtual long numEvents() const override
Access the number of events on the current input data source (-1 if no data source connected)
Definition: GenericEventHandler.cpp:66
dd4hep::Display::eventHandler
GenericEventHandler & eventHandler() const
Access to the event reader.
Definition: Display.cpp:168
dd4hep::EventControl::NUM_DATA_LINES
@ NUM_DATA_LINES
Definition: EventControl.h:38
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::EventControl::m_dataFrame
TGCompositeFrame * m_dataFrame
Definition: EventControl.h:43
dd4hep::EventControl::m_display
Display * m_display
Refernece to the display object.
Definition: EventControl.h:40
dd4hep::EventHandler::numEvents
virtual long numEvents() const =0
Access the number of events on the current input data source (-1 if no data source connected)
dd4hep::FrameControl
class FrameControl FrameControl.h DDEve/FrameControl.h
Definition: FrameControl.h:36
InstanceCount.h
dd4hep::EventControl::m_numEvtFrame
TGCompositeFrame * m_numEvtFrame
Definition: EventControl.h:46
dd4hep::EventHandler::TypedEventCollections
std::map< std::string, std::vector< Collection > > TypedEventCollections
Types collection: collections are grouped by type (class name)
Definition: EventHandler.h:80
dd4hep::GenericEventHandler::Unsubscribe
virtual void Unsubscribe(EventConsumer *display)
Unsubscribe from notification of new data present.
Definition: GenericEventHandler.cpp:60
EventControl.h
dd4hep::EventControl::OnFileOpen
virtual void OnFileOpen(EventHandler &handler) override
EventConsumer overload: New event data file.
Definition: EventControl.cpp:90
dd4hep::EventHandler::data
virtual const TypedEventCollections & data() const =0
Access the map of simulation data collections.
dd4hep::EventControl::Line
std::pair< TGCompositeFrame *, Labels > Line
Definition: EventControl.h:51