ROOT
Version v6.34
master
v6.32
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
►
ROOT
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
spy.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_net
3
/// Client program which allows the snooping of objects from a spyserv process.
4
/// To run this demo do the following (see spyserv.C):
5
/// - open two or more windows
6
/// - start root in all windows
7
/// - execute in the first window: .x spyserv.C (or spyserv.C++)
8
/// - execute in the other window(s): .x spy.C (or spy.C++)
9
/// - in the "spy" client windows click the "Connect" button and snoop
10
/// the histograms by clicking on the "hpx", "hpxpy" and "hprof"
11
/// buttons
12
///
13
/// \macro_code
14
///
15
/// \author Fons Rademakers
16
17
#include "
TGButton.h
"
18
#include "
TRootEmbeddedCanvas.h
"
19
#include "
TGLayout.h
"
20
#include "
TH2.h
"
21
#include "
TCanvas.h
"
22
#include "
TSocket.h
"
23
#include "
TMessage.h
"
24
#include "
RQ_OBJECT.h
"
25
26
27
class
Spy
{
28
29
RQ_OBJECT
(
"Spy"
)
30
31
private
:
32
TGMainFrame
*fMain;
33
TRootEmbeddedCanvas
*fCanvas;
34
TGHorizontalFrame
*
fHorz
;
35
TGHorizontalFrame
*
fHorz2
;
36
TGLayoutHints
*
fLbut
;
37
TGLayoutHints
*
fLhorz
;
38
TGLayoutHints
*
fLcan
;
39
TGButton
*
fHpx
;
40
TGButton
*
fHpxpy
;
41
TGButton
*
fHprof
;
42
TGButton
*
fConnect
;
43
TGButton
*fQuit;
44
TSocket
*
fSock
;
45
TH1
*fHist;
46
47
public
:
48
Spy
();
49
~
Spy
();
50
51
void
Connect();
52
void
DoButton();
53
};
54
55
void
Spy
::DoButton()
56
{
57
// Ask for histogram...
58
59
if
(!
fSock
->IsValid())
60
return
;
61
62
TGButton
*
btn
= (
TGButton
*)
gTQSender
;
63
switch
(
btn
->WidgetId()) {
64
case
1:
65
fSock
->Send(
"get hpx"
);
66
break
;
67
case
2:
68
fSock
->Send(
"get hpxpy"
);
69
break
;
70
case
3:
71
fSock
->Send(
"get hprof"
);
72
break
;
73
}
74
TMessage
*
mess
;
75
if
(
fSock
->Recv(
mess
) <= 0) {
76
Error
(
"Spy::DoButton"
,
"error receiving message"
);
77
return
;
78
}
79
80
if
(fHist)
delete
fHist;
81
if
(
mess
->GetClass()->InheritsFrom(
TH1::Class
())) {
82
fHist = (
TH1
*)
mess
->ReadObject(
mess
->GetClass());
83
if
(
mess
->GetClass()->InheritsFrom(
TH2::Class
()))
84
fHist->
Draw
(
"cont"
);
85
else
86
fHist->
Draw
();
87
fCanvas->
GetCanvas
()->
Modified
();
88
fCanvas->
GetCanvas
()->
Update
();
89
}
90
91
delete
mess
;
92
}
93
94
void
Spy::Connect()
95
{
96
// Connect to SpyServ
97
fSock
=
new
TSocket
(
"localhost"
, 9090);
98
fConnect
->SetState(
kButtonDisabled
);
99
fHpx
->SetState(
kButtonUp
);
100
fHpxpy
->SetState(
kButtonUp
);
101
fHprof
->SetState(
kButtonUp
);
102
}
103
104
Spy::Spy()
105
{
106
// Create a main frame
107
fMain =
new
TGMainFrame
(0, 100, 100);
108
fMain->SetCleanup(
kDeepCleanup
);
109
110
// Create an embedded canvas and add to the main frame, centered in x and y
111
// and with 30 pixel margins all around
112
fCanvas =
new
TRootEmbeddedCanvas
(
"Canvas"
, fMain, 600, 400);
113
fLcan
=
new
TGLayoutHints
(
kLHintsCenterX
|
kLHintsCenterY
,30,30,30,30);
114
fMain->AddFrame(fCanvas,
fLcan
);
115
116
// Create a horizontal frame containing three text buttons
117
fLhorz
=
new
TGLayoutHints
(
kLHintsExpandX
, 0, 0, 0, 30);
118
fHorz
=
new
TGHorizontalFrame
(fMain, 100, 100);
119
fMain->AddFrame(
fHorz
,
fLhorz
);
120
121
// Create three text buttons to get objects from server
122
// Add to horizontal frame
123
fLbut
=
new
TGLayoutHints
(
kLHintsCenterX
, 10, 10, 0, 0);
124
fHpx
=
new
TGTextButton
(
fHorz
,
"Get hpx"
, 1);
125
fHpx
->SetState(
kButtonDisabled
);
126
fHpx
->Connect(
"Clicked()"
,
"Spy"
,
this
,
"DoButton()"
);
127
fHorz
->AddFrame(
fHpx
,
fLbut
);
128
fHpxpy
=
new
TGTextButton
(
fHorz
,
"Get hpxpy"
, 2);
129
fHpxpy
->SetState(
kButtonDisabled
);
130
fHpxpy
->Connect(
"Clicked()"
,
"Spy"
,
this
,
"DoButton()"
);
131
fHorz
->AddFrame(
fHpxpy
,
fLbut
);
132
fHprof
=
new
TGTextButton
(
fHorz
,
"Get hprof"
, 3);
133
fHprof
->SetState(
kButtonDisabled
);
134
fHprof
->Connect(
"Clicked()"
,
"Spy"
,
this
,
"DoButton()"
);
135
fHorz
->AddFrame(
fHprof
,
fLbut
);
136
137
// Create a horizontal frame containing two text buttons
138
fHorz2
=
new
TGHorizontalFrame
(fMain, 100, 100);
139
fMain->AddFrame(
fHorz2
,
fLhorz
);
140
141
// Create "Connect" and "Quit" buttons
142
// Add to horizontal frame
143
fConnect
=
new
TGTextButton
(
fHorz2
,
"Connect"
);
144
fConnect
->Connect(
"Clicked()"
,
"Spy"
,
this
,
"Connect()"
);
145
fHorz2
->AddFrame(
fConnect
,
fLbut
);
146
fQuit =
new
TGTextButton
(
fHorz2
,
"Quit"
);
147
fQuit->
SetCommand
(
"gApplication->Terminate()"
);
148
fHorz2
->AddFrame(fQuit,
fLbut
);
149
150
// Set main frame name, map sub windows (buttons), initialize layout
151
// algorithm via Resize() and map main frame
152
fMain->SetWindowName(
"Spy on SpyServ"
);
153
fMain->MapSubwindows();
154
fMain->Resize(fMain->GetDefaultSize());
155
fMain->MapWindow();
156
157
fHist = 0;
158
}
159
160
Spy::~Spy()
161
{
162
// Clean up
163
164
delete
fHist;
165
delete
fSock
;
166
delete
fLbut
;
167
delete
fLhorz
;
168
delete
fLcan
;
169
delete
fHpx
;
170
delete
fHpxpy
;
171
delete
fHprof
;
172
delete
fConnect
;
173
delete
fQuit;
174
delete
fHorz
;
175
delete
fHorz2
;
176
delete
fCanvas;
177
delete
fMain;
178
}
179
180
void
spy
()
181
{
182
new
Spy
;
183
}
RQ_OBJECT.h
RQ_OBJECT
#define RQ_OBJECT(sender_class)
Definition
RQ_OBJECT.h:87
TCanvas.h
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
Error
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition
TError.cxx:185
TGButton.h
kButtonDisabled
@ kButtonDisabled
Definition
TGButton.h:56
kButtonUp
@ kButtonUp
Definition
TGButton.h:53
kDeepCleanup
@ kDeepCleanup
Definition
TGFrame.h:42
TGLayout.h
kLHintsCenterY
@ kLHintsCenterY
Definition
TGLayout.h:28
kLHintsCenterX
@ kLHintsCenterX
Definition
TGLayout.h:25
kLHintsExpandX
@ kLHintsExpandX
Definition
TGLayout.h:30
TH2.h
TMessage.h
gTQSender
R__EXTERN void * gTQSender
Definition
TQObject.h:46
TRootEmbeddedCanvas.h
TSocket.h
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TCanvas::Update
void Update() override
Update canvas pad buffers.
Definition
TCanvas.cxx:2489
TGButton
A button abstract base class.
Definition
TGButton.h:68
TGHorizontalFrame
A composite frame that layout their children in horizontal way.
Definition
TGFrame.h:385
TGLayoutHints
This class describes layout hints used by the layout classes.
Definition
TGLayout.h:50
TGMainFrame
Defines top level windows that interact with the system Window Manager.
Definition
TGFrame.h:397
TGTextButton
Yield an action as soon as it is clicked.
Definition
TGButton.h:142
TGWidget::SetCommand
virtual void SetCommand(const char *command)
Definition
TGWidget.h:73
TH1
TH1 is the base class of all histogram classes in ROOT.
Definition
TH1.h:59
TH1::Class
static TClass * Class()
TH1::Draw
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition
TH1.cxx:3066
TH2::Class
static TClass * Class()
TMessage
Definition
TMessage.h:33
TPad::Modified
void Modified(Bool_t flag=true) override
Mark pad modified Will be repainted when TCanvas::Update() will be called next time.
Definition
TPad.cxx:7369
TRootEmbeddedCanvas
This class creates a TGCanvas in which a TCanvas is created.
Definition
TRootEmbeddedCanvas.h:24
TRootEmbeddedCanvas::GetCanvas
TCanvas * GetCanvas() const
Definition
TRootEmbeddedCanvas.h:55
TSocket
Definition
TSocket.h:41
tutorials
net
spy.C
ROOT v6-34 - Reference Guide Generated on Mon Apr 7 2025 16:53:12 (GVA Time) using Doxygen 1.10.0