Line data Source code
1 : #include "TApplication.h"
2 : #include "TGLabel.h"
3 : #include "TGClient.h"
4 : #include "TCanvas.h"
5 : #include "TRandom.h"
6 : #include "TPRegexp.h"
7 : #include "TGButton.h"
8 : #include "TGColorSelect.h"
9 : #include "TRootEmbeddedCanvas.h"
10 : #include "TH1F.h"
11 : #include "TGTextEntry.h"
12 : #include "TThread.h"
13 : #include "AliZMQMTviewerGUI.h"
14 : #include "AliZMQhistViewer.h"
15 : #include "AliZMQhelpers.h"
16 : #include "zmq.h"
17 : #include <cstdlib>
18 : #include <string>
19 : #include "TTimer.h"
20 : #include "Buttons.h"
21 : #include "TRootCanvas.h"
22 : #include "TGStatusBar.h"
23 : #include "TPad.h"
24 : #include "AliHLTDataTypes.h"
25 :
26 8 : ClassImpQ(AliZMQMTviewerGUI)
27 :
28 : const char* AliZMQMTviewerGUI::fUSAGE =
29 : "ZMQhstViewer: Draw() all ROOT drawables in a message\n"
30 : "options: \n"
31 : " -in : data in\n"
32 : " -sleep : how long to sleep in between requests for data in s (if applicable)\n"
33 : " -timeout : how long to wait for the server to reply (s)\n"
34 : " -Verbose : be verbose\n"
35 : " -select : only show selected histograms (by regexp)\n"
36 : " -unselect : as select, only inverted\n"
37 : " -drawoptions : what draw option to use\n"
38 : " -file : dump input to file and exit\n"
39 : " -log[xyz] : use log scale on [xyz] dimension\n"
40 : " -histstats : histogram stat box options (default 0)\n"
41 : " -AllowResetAtSOR : 0/1 to reset at change of run\n"
42 : ;
43 :
44 : //______________________________________________________________________
45 : AliZMQMTviewerGUI::AliZMQMTviewerGUI(const TGWindow *p,UInt_t w,UInt_t h, int argc, char** argv)
46 0 : : TGMainFrame(p,w,h)
47 0 : , fECanvas(NULL)
48 0 : , fStatusBar(NULL)
49 0 : , fPullButton(NULL)
50 0 : , fSelectionEntry(NULL)
51 0 : , fUnSelectionEntry(NULL)
52 0 : , fThread(NULL)
53 0 : , fCanvas(NULL)
54 0 : , fThreadArgs()
55 0 : , fViewer(NULL)
56 0 : , fTimer(NULL)
57 0 : , fWindowTitle()
58 0 : , fZMQviewerConfig()
59 0 : , fInitStatus(0)
60 0 : , fSelection(NULL)
61 0 : , fUnSelection(NULL)
62 0 : {
63 0 : fViewer = new AliZMQhistViewer();
64 0 : int viewerOptionRC = fViewer->ProcessOptionString(argc,argv);
65 0 : if (viewerOptionRC<1) {
66 0 : fInitStatus = -1;
67 0 : return;
68 : }
69 0 : fSelection = fViewer->GetSelection();
70 0 : fUnSelection = fViewer->GetUnSelection();
71 :
72 : // Creates widgets of the example
73 0 : SetCleanup(kDeepCleanup);
74 0 : fECanvas = new TRootEmbeddedCanvas ("Ecanvas", this, 600, 400);
75 0 : Int_t wid = fECanvas->GetCanvasWindowId();
76 0 : fCanvas = new TCanvas("", 10,10,wid);
77 0 : fECanvas->AdoptCanvas(fCanvas);
78 : //fCanvas->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)","AliZMQMTviewerGUI",this,
79 : // "EventInfo(Int_t,Int_t,Int_t,TObject*)");
80 0 : fCanvas->Connect("Selected(TVirtualPad*,TObject*,Int_t)","AliZMQMTviewerGUI",this,
81 : "PadSelected(TVirtualPad*,TObject*,Int_t)");
82 0 : fCanvas->Connect("Picked(TPad*,TObject*,Int_t)","AliZMQMTviewerGUI",this,
83 : "PadPicked(TPad*,TObject*,Int_t)");
84 :
85 0 : AddFrame(fECanvas, new TGLayoutHints(kLHintsTop | kLHintsLeft |
86 : kLHintsExpandX | kLHintsExpandY,0,0,1,1));
87 :
88 :
89 : ///////////////////////////////
90 : // selection / unselection frame
91 : TGCompositeFrame* fSelectionEntryFrame =
92 0 : new TGCompositeFrame(this, 60, 20, kHorizontalFrame | kSunkenFrame);
93 :
94 0 : TGLabel *selectionLabel = new TGLabel(fSelectionEntryFrame, "select:");
95 0 : fSelectionEntryFrame->AddFrame(selectionLabel,
96 0 : new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5, 2, 2, 2));
97 :
98 0 : fSelectionEntry = new TGTextEntry(fSelectionEntryFrame);
99 0 : fSelectionEntry->SetToolTipText("Enter a selection regexp");
100 : //fSelectionEntry->Resize(300, fSelectionEntry->GetDefaultHeight());
101 0 : fSelectionEntryFrame->AddFrame(fSelectionEntry,
102 0 : new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 2, 2, 2));
103 0 : fSelectionEntry->Connect("TabPressed()","AliZMQMTviewerGUI",this,"DoSelectionEntry()");
104 0 : fSelectionEntry->Connect("ReturnPressed()","AliZMQMTviewerGUI",this,"DoSelectionEntry()");
105 0 : if (fSelection) fSelectionEntry->SetText(fSelection->GetPattern().Data(), kFALSE);
106 :
107 0 : TGLabel *unSelectionLabel = new TGLabel(fSelectionEntryFrame, "unselect:");
108 0 : fSelectionEntryFrame->AddFrame(unSelectionLabel,
109 0 : new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5, 2, 2, 2));
110 :
111 0 : fUnSelectionEntry = new TGTextEntry(fSelectionEntryFrame);
112 0 : fUnSelectionEntry->SetToolTipText("this will be inversely matched");
113 : //fUnSelectionEntry->Resize(300, fUnSelectionEntry->GetDefaultHeight());
114 0 : fSelectionEntryFrame->AddFrame(fUnSelectionEntry,
115 0 : new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 2, 2, 2));
116 0 : fUnSelectionEntry->Connect("TabPressed()","AliZMQMTviewerGUI",this,"DoSelectionEntry()");
117 0 : fUnSelectionEntry->Connect("ReturnPressed()","AliZMQMTviewerGUI",this,"DoSelectionEntry()");
118 0 : if (fUnSelection) fUnSelectionEntry->SetText(fUnSelection->GetPattern().Data(), kFALSE);
119 :
120 0 : fPullButton = new TGTextButton(fSelectionEntryFrame, "Pull", 150);
121 0 : fPullButton->Connect("Clicked()", "AliZMQMTviewerGUI", this, "DoPullButton()");
122 0 : fPullButton->SetToolTipText("force update");
123 0 : fSelectionEntryFrame->AddFrame(fPullButton,
124 0 : new TGLayoutHints(kLHintsTop | kLHintsRight, 10, 5, 2, 2));
125 0 : AddFrame(fSelectionEntryFrame, new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 1, 1, 1, 1));
126 :
127 : ///////////////////////////////
128 : // Create status frame containing a button and a text entry widget
129 : TGCompositeFrame* fStatusFrame =
130 0 : new TGCompositeFrame(this, 60, 20, kHorizontalFrame | kSunkenFrame);
131 :
132 0 : Int_t parts[] = {70, 30};
133 0 : fStatusBar = new TGStatusBar(fStatusFrame, 100, 1, kHorizontalFrame);
134 0 : fStatusBar->SetParts(parts, 2);
135 0 : fStatusBar->Draw3DCorner(kFALSE);
136 0 : fStatusFrame->AddFrame(fStatusBar,
137 0 : new TGLayoutHints(kLHintsTop|kLHintsLeft|kLHintsExpandX, 5, 5, 2, 2));
138 :
139 0 : AddFrame(fStatusFrame, new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 1, 1, 1, 1));
140 :
141 :
142 0 : int rc = alizmq_socket_init(fZMQviewerConfig, alizmq_context(), "PUSH@inproc://viewerConfig");
143 0 : if (rc < 0) {
144 0 : printf("WARNING: viewer ZMQ config socket init error: %i %s\n", rc , zmq_strerror(errno));
145 : }
146 :
147 0 : fViewer->SetCanvas(fCanvas);
148 0 : bool updateCanvas = false;
149 0 : fViewer->GetUpdateCanvas(&updateCanvas);
150 :
151 0 : fTimer = new TTimer(this, 1000);
152 0 : fTimer->Reset();
153 0 : fTimer->TurnOn();
154 :
155 : // Sets window name and shows the main frame
156 0 : fWindowTitle = "HLT hist viewer";
157 0 : SetWindowName(fWindowTitle.c_str());
158 0 : MapSubwindows();
159 0 : Resize(GetDefaultSize());
160 0 : MapWindow();
161 :
162 : // set up the threads
163 0 : fThread = new TThread("MyThread1", &AliZMQMTviewerGUI::RunViewer, (void*)this);
164 0 : fThreadArgs.fRun = kTRUE;
165 0 : fThreadArgs.fThread = fThread;
166 0 : fThreadArgs.fCanvas = fCanvas;
167 0 : fThreadArgs.viewer = fViewer;
168 0 : fThread->Run(&fThreadArgs);
169 0 : }
170 :
171 : //______________________________________________________________________________
172 : void AliZMQMTviewerGUI::CloseWindow()
173 : {
174 : // terminate and delete the thread, then quit the application
175 0 : fThreadArgs.fRun = kFALSE;
176 0 : bool term = true;
177 0 : zmq_close(fZMQviewerConfig);
178 0 : zmq_ctx_term(alizmq_context());
179 0 : fViewer->GetTerminated(&term);
180 0 : while (fThread->GetState() == TThread::kRunningState) {
181 0 : gSystem->ProcessEvents();
182 : }
183 0 : fThread->Join();
184 0 : delete fThread;
185 0 : TGMainFrame::CloseWindow();
186 0 : gApplication->Terminate();
187 0 : }
188 :
189 : //______________________________________________________________________________
190 : void *AliZMQMTviewerGUI::RunViewer(void *ptr)
191 : {
192 : // this method is called by the thread
193 :
194 0 : ThreadArgs_t *args = (ThreadArgs_t *)ptr;
195 0 : if (!args) return 0;
196 0 : AliZMQhistViewer* viewer = args->viewer;
197 :
198 0 : viewer->Run(NULL);
199 :
200 : return NULL;
201 0 : }
202 :
203 : //______________________________________________________________________________
204 : void AliZMQMTviewerGUI::UpdateCanvas()
205 : {
206 0 : std::string info = fViewer->GetInfo();
207 0 : if (info.size()>0) {
208 0 : info=", "+info;
209 0 : }
210 0 : std::string title = fWindowTitle + info;
211 0 : SetWindowName(title.c_str());
212 0 : fViewer->UpdateCanvas(fCanvas, fSelection, fUnSelection);
213 0 : }
214 :
215 : //______________________________________________________________________________
216 : Bool_t AliZMQMTviewerGUI::HandleTimer(TTimer *t)
217 : {
218 0 : UpdateCanvas();
219 0 : fStatusBar->SetText(Form("source: %s",fViewer->GetZMQconfig().c_str()), 0);
220 0 : fTimer->Reset();
221 0 : return kTRUE;
222 0 : }
223 :
224 : //______________________________________________________________________________
225 : void AliZMQMTviewerGUI::EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
226 : {
227 0 : if (event==kMouseMotion) return;
228 0 : if (!selected) printf("event info null pointer\n");
229 0 : if (event==kMouseEnter) {
230 0 : fStatusBar->SetText(Form("%s",selected->GetName()),1);
231 0 : }
232 0 : }
233 :
234 : //______________________________________________________________________________
235 : void AliZMQMTviewerGUI::PadSelected(TVirtualPad* pad, TObject *object, Int_t event)
236 : {
237 0 : if (event==1 && pad) {
238 0 : if (pad==fCanvas) { return; }
239 0 : pad->cd();
240 0 : std::string name = "";
241 0 : std::string title = "";
242 0 : Int_t logx = pad->GetLogx();
243 0 : Int_t logy = pad->GetLogy();
244 0 : Int_t logz = pad->GetLogz();
245 0 : TList primitives;
246 0 : TObjLink* link = pad->GetListOfPrimitives()->FirstLink();
247 0 : while (link) {
248 0 : TObject* o = link->GetObject();
249 0 : if (!o) { continue; }
250 0 : if (o->InheritsFrom("TH1") || o->InheritsFrom("TGraph")) {
251 0 : TObject* copy = o->Clone();
252 0 : Option_t* option = link->GetOption();
253 0 : primitives.Add(copy,option);
254 0 : name = o->GetName();
255 0 : title = o->GetTitle();
256 0 : }
257 0 : link = link->Next();
258 0 : }
259 0 : if (primitives.GetSize()==0) return;
260 0 : AliZMQMTviewerGUIview* window = new AliZMQMTviewerGUIview(
261 0 : name.c_str(),title.c_str(),100,200,700,600);
262 0 : window->fDrawnObjects.AddAll(&primitives);
263 0 : window->fCanvas.cd();
264 0 : window->fCanvas.SetLogx(logx);
265 0 : window->fCanvas.SetLogy(logy);
266 0 : window->fCanvas.SetLogz(logz);
267 0 : link = primitives.FirstLink();
268 0 : while (link) {
269 0 : TObject* o = link->GetObject();
270 0 : if (!o) { continue; }
271 0 : Option_t* option = link->GetOption();
272 0 : o->Draw(option);
273 0 : link = link->Next();
274 0 : }
275 0 : window->fCanvas.Update();
276 0 : }
277 0 : }
278 :
279 : //______________________________________________________________________________
280 : void AliZMQMTviewerGUI::PadPicked(TPad* pad, TObject *object, Int_t event)
281 : {
282 0 : if (pad) {
283 0 : fStatusBar->SetText(pad->GetName(),1);
284 0 : }
285 0 : }
286 :
287 : //______________________________________________________________________________
288 : void AliZMQMTviewerGUI::ReconfigureViewer(std::string string)
289 : {
290 0 : aliZMQmsg message;
291 0 : alizmq_msg_add(&message, "", string);
292 0 : alizmq_msg_send(&message, fZMQviewerConfig, 0);
293 0 : alizmq_msg_close(&message);
294 0 : }
295 :
296 : //______________________________________________________________________________
297 : void AliZMQMTviewerGUI::DoPullButton()
298 : {
299 : //just send something to interrupt sleep
300 0 : void* tmpsocket=NULL;
301 0 : int rc = 0;
302 0 : rc = alizmq_socket_init(tmpsocket, alizmq_context(), "PUSH>inproc://sleep", 0);
303 0 : rc = zmq_send(tmpsocket, &rc, sizeof(rc), 0);
304 : if (false) { printf("sleep interrupted rc: %i\n", rc); }
305 0 : zmq_close(tmpsocket);
306 0 : }
307 :
308 : //______________________________________________________________________________
309 : void AliZMQMTviewerGUI::DoSelectionEntry()
310 : {
311 0 : string sel = fSelectionEntry->GetText();
312 0 : string unsel = fUnSelectionEntry->GetText();
313 0 : delete fSelection; fSelection = NULL;
314 0 : delete fUnSelection; fUnSelection = NULL;
315 0 : if (sel.size()>0) fSelection = new TPRegexp(sel.c_str());
316 0 : if (unsel.size()>0) fUnSelection = new TPRegexp(unsel.c_str());
317 :
318 0 : if (fSelectionEntry->HasFocus()) {
319 0 : fUnSelectionEntry->SetFocus();
320 0 : } else if (fUnSelectionEntry->HasFocus()) {
321 0 : fSelectionEntry->SetFocus();
322 : }
323 0 : fViewer->GetSelection(&sel);
324 0 : fViewer->GetUnSelection(&unsel);
325 0 : bool tmp = true;
326 0 : fViewer->GetClearCanvas(&tmp);
327 0 : DoPullButton();
328 0 : UpdateCanvas();
329 0 : }
330 :
331 8 : ClassImp(AliZMQMTviewerGUIview)
332 :
333 : void AliZMQMTviewerGUIview::CleanUp()
334 : {
335 0 : fDrawnObjects.Delete();
336 0 : delete this;
337 0 : }
338 :
|