File indexing completed on 2025-01-18 09:14:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DDEve/Display.h>
0016 #include <DDEve/EventControl.h>
0017 #include <DDEve/EventHandler.h>
0018 #include <DD4hep/InstanceCount.h>
0019
0020
0021 #include <TROOT.h>
0022 #include <TSystem.h>
0023 #include <TGTab.h>
0024 #include <TGLabel.h>
0025 #include <TGFrame.h>
0026 #include <TGButton.h>
0027 #include <TG3DLine.h>
0028 #include <TGFileDialog.h>
0029
0030 #include <TTree.h>
0031 #include <libgen.h>
0032
0033 using namespace dd4hep;
0034
0035 ClassImp(EventControl)
0036
0037
0038 EventControl::EventControl(Display* display, unsigned int width, unsigned int height)
0039 : FrameControl(&display->client(), "EventControl GUI", width, height), EventConsumer(),
0040 m_display(display), m_dataGroup(0), m_dataFrame(0), m_eventGroup(0),
0041 m_numEvtFrame(0), m_input1(0), m_input2(0), m_numEvtLabel(0),
0042 m_open(0), m_prev(0), m_next(0), m_goto(0)
0043 {
0044 SetWindowName("XX GUI");
0045 m_display->eventHandler().Subscribe(this);
0046 InstanceCount::increment(this);
0047 }
0048
0049
0050 EventControl::~EventControl() {
0051 try {
0052 m_display->eventHandler().Unsubscribe(this);
0053 }
0054 catch(...) {
0055 }
0056 InstanceCount::decrement(this);
0057 }
0058
0059
0060 TGCompositeFrame* EventControl::CreateFrame() {
0061 return new TGVerticalFrame(this);
0062 }
0063
0064
0065 void EventControl::NextEvent() {
0066 m_display->eventHandler().NextEvent();
0067 }
0068
0069
0070 void EventControl::PreviousEvent() {
0071 m_display->eventHandler().PreviousEvent();
0072 }
0073
0074
0075 void EventControl::GotoEvent() {
0076 long number = 0;
0077 m_display->eventHandler().GotoEvent(number);
0078 }
0079
0080
0081 bool EventControl::Open() {
0082 std::string fname = m_display->OpenEventFileDialog(".");
0083 if ( !fname.empty() ) {
0084 return m_display->eventHandler().Open(m_display->getEventHandlerName(),fname);
0085 }
0086 return false;
0087 }
0088
0089
0090 void EventControl::OnFileOpen(EventHandler& handler) {
0091 char text[1024], fname[1024];
0092 ::strncpy(fname, handler.datasourceName().c_str(), sizeof(fname)-1);
0093 fname[sizeof(fname)-1] = 0;
0094
0095 if ( handler.hasFile() ) {
0096 ::snprintf(text,sizeof(text),"Number of events: %ld",handler.numEvents());
0097 m_input1->SetText(::basename(fname));
0098 m_input2->SetText(text);
0099 }
0100 else {
0101 ::snprintf(text,sizeof(text),"Currently NO input defined");
0102 m_input1->SetText("");
0103 m_input2->SetText(text);
0104 }
0105 m_eventGroup->Layout();
0106 client().NeedRedraw(m_eventGroup,kTRUE);
0107 }
0108
0109
0110 void EventControl::OnNewEvent(EventHandler& handler) {
0111 typedef EventHandler::TypedEventCollections Types;
0112 typedef std::vector<EventHandler::Collection> Collections;
0113 const Types& types = handler.data();
0114 std::size_t cnt = 1;
0115 m_lines[0].second.first->SetText("Hit collection name");
0116 m_lines[0].second.second->SetText("No.Hits");
0117 for(const auto& t : types) {
0118 const Collections& colls = t.second;
0119 Line line = m_lines[cnt++];
0120 std::string cl = t.first;
0121 std::size_t idx = cl.rfind("Geant4");
0122 if ( idx != std::string::npos ) {
0123 cl = cl.substr(idx);
0124 cl = cl.substr(0,cl.find('*'));
0125 }
0126 else if ( (idx=cl.rfind("::")) != std::string::npos ) {
0127 cl = cl.substr(idx+2);
0128 if ( (idx=cl.rfind('*')) != std::string::npos ) cl = cl.substr(0,idx);
0129 if ( (idx=cl.rfind('>')) != std::string::npos ) cl = cl.substr(0,idx);
0130 }
0131 line.second.first->SetTextColor(kRed);
0132 line.second.second->SetTextColor(kRed);
0133 line.second.first->SetText(("Coll.Type: "+cl).c_str());
0134 line.second.second->SetText("");
0135 for(const auto& c : colls) {
0136 char text[132];
0137 ::snprintf(text,sizeof(text),"%ld",long(c.second));
0138 line = m_lines[cnt++];
0139 line.second.first->SetText(c.first);
0140 line.second.second->SetText(text);
0141 line.second.first->SetTextColor(kBlack);
0142 line.second.second->SetTextColor(kBlack);
0143 }
0144 }
0145 for(; cnt<m_lines.size(); ) {
0146 Line line = m_lines[cnt++];
0147 line.second.first->SetText("");
0148 line.second.second->SetText("");
0149 }
0150 m_dataGroup->Layout();
0151 client().NeedRedraw(m_dataGroup,kTRUE);
0152 }
0153
0154
0155 void EventControl::OnBuild() {
0156 std::string icondir = TString::Format("%s/", TROOT::GetIconPath().Data()).Data();
0157 TGGroupFrame* group = new TGGroupFrame(m_frame,"Event I/O Control");
0158 TGCompositeFrame* top = new TGHorizontalFrame(group);
0159 TGPictureButton* b = 0;
0160 char text[1024];
0161
0162 group->SetTitlePos(TGGroupFrame::kLeft);
0163 m_frame->AddFrame(group, new TGLayoutHints(kLHintsExpandX|kLHintsCenterX, 2, 2, 2, 2));
0164 m_eventGroup = group;
0165
0166 m_numEvtFrame = new TGVerticalFrame(group);
0167 if ( m_display->eventHandler().hasFile() ) {
0168 ::snprintf(text,sizeof(text),"Number of events: %ld",m_display->eventHandler().numEvents());
0169 m_input1 = new TGLabel(m_numEvtFrame,m_display->eventHandler().datasourceName().c_str());
0170 m_input2 = new TGLabel(m_numEvtFrame,text);
0171 }
0172 else {
0173 ::snprintf(text,sizeof(text),"Currently NO input defined");
0174 m_input1 = new TGLabel(m_numEvtFrame,"");
0175 m_input2 = new TGLabel(m_numEvtFrame,text);
0176 }
0177 m_numEvtFrame->AddFrame(m_input1, new TGLayoutHints(kLHintsNormal, 2, 0, 2, 2));
0178 m_numEvtFrame->AddFrame(m_input2, new TGLayoutHints(kLHintsNormal, 2, 0, 2, 2));
0179 group->AddFrame(m_numEvtFrame, new TGLayoutHints(kLHintsExpandX|kLHintsCenterX, 2, 2, 2, 2));
0180
0181 top->AddFrame(new TGLabel(top,"Open event file:"), new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2, 2, 2, 2));
0182 m_open = b = new TGPictureButton(top, LoadPicture((icondir+"bld_open.png")));
0183 b->Connect("Clicked()", "dd4hep::EventControl", this, "Open()");
0184 b->SetSize(TGDimension(32,32));
0185 top->AddFrame(b, new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
0186 group->AddFrame(top, new TGLayoutHints(kLHintsExpandX|kLHintsCenterX, 2, 2, 2, 2));
0187
0188 top = new TGHorizontalFrame(group);
0189 top->AddFrame(new TGLabel(top,"Previous:"), new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2, 2, 2, 2));
0190 m_prev = b = new TGPictureButton(top, LoadPicture((icondir+"bld_undo.png")));
0191 b->Connect("Clicked()", "dd4hep::EventControl", this, "PreviousEvent()");
0192 b->SetSize(TGDimension(32,32));
0193 top->AddFrame(b, new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
0194
0195 top->AddFrame(new TGLabel(top,""), new TGLayoutHints(kLHintsExpandX|kLHintsCenterY, 2, 2, 2, 2));
0196 top->AddFrame(new TGLabel(top,"Next:"), new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2, 2, 2, 2));
0197 m_next = b = new TGPictureButton(top, LoadPicture((icondir+"bld_redo.png")));
0198 b->Connect("Clicked()", "dd4hep::EventControl", this, "NextEvent()");
0199 b->SetSize(TGDimension(32,32));
0200 top->AddFrame(b, new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
0201 group->AddFrame(top,new TGLayoutHints(kLHintsExpandX|kLHintsCenterX, 2, 2, 2, 2));
0202
0203 top = new TGHorizontalFrame(group);
0204 top->AddFrame(new TGLabel(top,"Goto event:"), new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2, 2, 2, 2));
0205 m_goto = b = new TGPictureButton(top, LoadPicture((icondir+"ed_goto.png")));
0206 b->Connect("Clicked()", "dd4hep::EventControl", this, "GotoEvent()");
0207 b->SetSize(TGDimension(32,32));
0208 top->AddFrame(b, new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
0209 group->AddFrame(top,new TGLayoutHints(kLHintsExpandX|kLHintsCenterX, 2, 2, 2, 2));
0210
0211 group = new TGGroupFrame(m_frame,"Event data",200);
0212 m_frame->AddFrame(group,new TGLayoutHints(kLHintsLeft|kLHintsExpandX|kLHintsExpandY, 0, 0, 2, 2));
0213 m_dataFrame = new TGVerticalFrame(group);
0214 for( int i=0; i<NUM_DATA_LINES; ++i ) {
0215 Line line;
0216 TGCompositeFrame* fr = new TGHorizontalFrame(m_dataFrame);
0217 fr->AddFrame(line.second.first=new TGLabel(fr,""), new TGLayoutHints(kLHintsNormal, 2, 0, 2, 2));
0218 fr->AddFrame(line.second.second=new TGLabel(fr,""), new TGLayoutHints(kLHintsRight, 20, 1, 2, 2));
0219 line.first = fr;
0220 m_lines.push_back(line);
0221 m_dataFrame->AddFrame(fr,new TGLayoutHints(kLHintsExpandX));
0222 }
0223 group->AddFrame(m_dataFrame, new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY));
0224 m_dataGroup = group;
0225
0226 }
0227