28 #include "TGFileDialog.h"
34 using namespace DD4hep;
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)
44 SetWindowName(
"XX GUI");
45 m_display->eventHandler().Subscribe(
this);
46 InstanceCount::increment(
this);
50 EventControl::~EventControl() {
51 m_display->eventHandler().Unsubscribe(
this);
52 InstanceCount::decrement(
this);
56 TGCompositeFrame* EventControl::CreateFrame() {
57 return new TGVerticalFrame(
this);
61 void EventControl::NextEvent() {
62 m_display->eventHandler().NextEvent();
66 void EventControl::PreviousEvent() {
67 m_display->eventHandler().PreviousEvent();
71 void EventControl::GotoEvent() {
73 m_display->eventHandler().GotoEvent(number);
77 bool EventControl::Open() {
83 std::string fname = m_display->OpenEventFileDialog(
".");
84 if ( !fname.empty() ) {
85 return m_display->eventHandler().Open(m_display->getEventHandlerName(),fname);
92 char text[1024], fname[1024];
93 ::strncpy(fname, handler->
datasourceName().c_str(),
sizeof(fname)-1);
94 fname[
sizeof(fname)-1] = 0;
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);
102 ::snprintf(text,
sizeof(text),
"Currently NO input defined");
103 m_input1->SetText(
"");
104 m_input2->SetText(text);
106 m_eventGroup->Layout();
107 client().NeedRedraw(m_eventGroup,kTRUE);
113 typedef std::vector<EventHandler::Collection> Collections;
114 const Types& types = handler->
data();
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 ) {
125 cl = cl.substr(0,cl.find(
'*'));
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);
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) {
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);
146 for(; cnt<m_lines.size(); ) {
147 Line line = m_lines[cnt++];
148 line.second.first->SetText(
"");
149 line.second.second->SetText(
"");
151 m_dataGroup->Layout();
152 client().NeedRedraw(m_dataGroup,kTRUE);
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;
162 group->SetTitlePos(TGGroupFrame::kLeft);
163 m_frame->AddFrame(group,
new TGLayoutHints(kLHintsExpandX|kLHintsCenterX, 2, 2, 2, 2));
164 m_eventGroup = group;
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);
173 ::snprintf(text,
sizeof(text),
"Currently NO input defined");
174 m_input1 =
new TGLabel(m_numEvtFrame,
"");
175 m_input2 =
new TGLabel(m_numEvtFrame,text);
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));
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));
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));
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));
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));
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) {
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));
220 m_lines.push_back(line);
221 m_dataFrame->AddFrame(fr,
new TGLayoutHints(kLHintsExpandX));
223 group->AddFrame(m_dataFrame,
new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY));
virtual bool hasFile() const
Check if a data file is connected to the handler.
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.
virtual const TypedEventCollections & data() const =0
Access the map of simulation data collections.
std::pair< TGCompositeFrame *, Labels > Line
class FrameControl FrameControl.h DDEve/FrameControl.h
std::map< std::string, std::vector< Collection > > TypedEventCollections
Types collection: collections are grouped by type (class name)
The main class of the DDEve display.