using the qt to create complex interactive henp applications at star by v.fine, j.lauret,...
TRANSCRIPT
Using the Qt to create complex interactive HENP applications
at STAR
by
V.Fine, J.Lauret, V.Perevoztchikov
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
2
Introduction
• This talk presents an overview of the main components of a unique set of tools, in use in the STAR experiment, born from the fusion of two advanced technologies: the ROOT framework and libraries and the Qt GUI and event handling package
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
3
Can we afford third party package ?“bad packages” use case
Use case:One needs 100 different small functions (wish list)There are 100 different packages (free) each implements
one function from the wish-list above
Question:• Does it worth to install and maintain 100 different
packages to get (free :) those 100 functions or one should implement (re-implement) those functions on his / her own ?
One needs extremely strong reason to go the former way
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
4
Can we afford third party package ? “good package” use case
Use case:One still needs 100 different small functions (wish list)There is one single package that provides 100 different
functions all those functions are on one's wish list
Question:• Does it worth to install and maintain such package?
One needs extremely strong reason to reject the package in question
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
5
Cost to maintain vs “re-use” gain:”good package” case
Functionality %
Cos
t to
mai
ntai
n“r
e-us
e ga
in”
0100
Cost to maintain
“re-use” gainHow to increase the gain:• Increase the “re-use”• Decrease the cost of ownership
“gain”
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
6
ROOT and Qt are a “good packages”
• Together (see impressive #61 GO4 talks also), ROOT and Qt allow creating software packages and help resolving complex data-analysis or visualization problems, enhance computer simulation or help develop geometry models demonstrating that it is not only feasible, but beneficial to integrate and benefit from the best of each technology.
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
7
We (@STAR) were not first one(see http://root.bnl.gov )
• The core library and system has been under development for the last 4 years and has solidified and made into concrete use through several applications for the STAR experiment at BNL as well as ROOT plugins. As a result, STAR has been empowered with stable interactive applications for online control and offline data-analysis built on the top of the STAR ROOT-based framework and this, while preserving the initial software components in a non disruptive manner.
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
8
Qt Root
In fact, many components are not STAR specific and can be re-used or used in the context of “user custom filters”, “detector geometry” components or even various 3D views for the High Energy and Nuclear Physics events
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
9
Distribution
• The portion of the project is already included in the official ROOT distribution and part of LCG binary distribution of the ROOT package for RHIC and LHC experiments.
• In full it is available from http://root.bnl.gov Web site.
• Binary “InstallShield”-based installation for Windows is available from that page also.
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
10
ComponentsThe project contains the set of the "user” components and
tools of QtRoot layer to facilitate:• Creation the Qt-based ROOT application and shared
library; • The ROOT-based Qt-application; • Using Qt GUI "designer" and Qt "project file“; • generating the class HTML (THtml) documentation of the
Qt/Root-based user classes; • ROOT-based and stand-alone QtRoot layer installation • Embedding 2D and 3D Qt widgets rendering the ROOT
graphical objects.• Qt signal / slot – ROOT signal / signal slot bidirectional
mapping
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
11
TGQt – Qt-based implementation of TVirtualX – the core of QtRoot
• Qt-ROOT implementation of TVirtualX (Qt-layer) provides a convenient way of creating complex end-user applications requiring both Qt GUI and ROOT features.
• The primary goal is to allow “seamless embedding” into Qt applications the ROOT GUI and visualization
• Components defined with the ROOT plugin mechanism TGQt ROOT class, a Qt-based implementation of TVirtualX interface is an optional ROOT component.
• Supported by the STAR collaboration’s S&C • The history of the project and the QtRoot technical
implementation details – presented at ACAT 2002 (Moscow) – ACAT 2003 (Tsukuba).
TVirtualX
TGQt
QObject
TQtClientFilter
TGQt::CreateWindow(…)
TGQt::Init(…)
QWidget::installEventFilter
QFrame
TQtClientWidget
QWidget
QPtrQueue<Event_t> fRootEventQueue
TGQt::NextEvent()
TGClient::ProcessOneEvent
Event_t QEvent
Transformation the QEvent Q-object into the ROOT Event_t structure
QWidget
TQtWidget
TGQt::InitWindow(…)
method
• “Clear boxes” show the overloaded methods of the TVirtualX interface
Class name
• “Gray boxes” show the Classes inheritance diagram
TGQt::OpenPixmap()
QPixmap
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
13
TVirtualX implementationsThe current official ROOT provide 3 different
implementations of the TVirtualX interface (see Fons’ talk).
The size (lines of the C++/C code) of these implications:
win32gdk 40000 Win32 ( Windows 9x/NT/XP )
x11 7100 X11 (Unix, MacOS, cygwin)
qt 6900 Win32 / X11 / Mac native / Qt3 and Qt4 (no user support for Qt4 yet)
One still needs cleaning TGQt up further to remove the code used to debug itTGQt - one single code for all platforms: no #ifdef, no single/multithread games seen with other implementations
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
14
“Split” repositoryAt the moment the project is “split” by two separate
CVS Repositories: “Qt layer” and “Qt Extension”• The full version that “Qt-layer” + “Qt Extension” is
available from BNL CVS Repository– CVSROOT :pserver:[email protected]:/date01/CVS– Web (STAR): http://root.bnl.gov– Mail list: [email protected]
• The “Qt-layer” is a part of the official ROOT repository. See: http://root.cern.ch
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
15
Two QtRoot end-user “use cases”User’s code
TCanvas/TPad TQtWidget TQtGLViewerWidget
TVirtualX QWidget QGLViewer
TGX11TGQt TWin32Gdk
Even though the TGQt class is a “soul” of the Qt layer it just implements at the TVirtualX interface and is normally hidden from the end-user code
1. Qt-based ROOT applications use “TCanvas”
2. ROOT-based Qt application use TQtWidget
TQtGLViewerWidget
BNL CVS Repository
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
16
Use case: “Qt-based ROOT applications”
“ROOT application” is the application that either instantiates the ROOT TApplication / TRint class and enters the ROOT event loop or is the shared library that can be loaded into the already running ROOT application via TSystem::Load method or via ROOT plug-in mechanism. You must neither initialize Qt QApplication nor enter the Qt event loop. Qt-layer takes care about both of these steps. What you need is just to instantiate the Qt object of your choice and keeps playing ROOT rules.
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
17
Use case: “ROOT-based Qt applications”
“Qt application” is the application that either instantiates the Qt QApplication and enters the Qt event loop or is the shared library that can be loaded into the already running Qt application via Qt plug-in mechanism. You must neither initialize ROOT TApplication / TRint nor enter the ROOT event loop. Qt-layer takes care about both of these steps. What you need is just to instantiate the embedded and regular ROOT objects of your choice and keep playing Qt rules.
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
18
Qt/Root integrationTo increase the gain we should to integrate Root and Qt as
much as possible and preserver the ROOT integrity, This is possible thanks th unique ROOT Plugin mechanism and modular OO design.
• Qt components -> native ROOT plugin (shared libraries)• ROOT GUI component -> native " Qt primitivesThis means:• TCanvas is represent by QWidget• TPad is represented by QPixmap• TImage is backed by QImage etc
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
19
BenefitsOne can include third party Qt GUI
components and packages into both cases
Coin3D
GO4
Qwt
QGLViewer
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
20
2D ROOT graphics:TQtWidget – QWidget for embedded
TCanvas
•Can be used with Qt “designer”
•Provided with a bunch of the proxy-methods to access the embedded TCanvas object
•Provided with the convenient Qt signals to notify the client code about the object selection, mouse events and interactions
•Can be subclassed to meet some special needs.
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
21
Simple histogram browser(60 lines of C++ code)
GO4 “design”
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
22
3D ROOT graphics – QtGLViewerWidget
•Can be used with Qt “designer”
•Very simple the end-user interface to pass the “GL list” to be rendered
•Provided with the convenient Qt signals to notify about the GL object selection
•Can be sub-classed to meet some customer needs also
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
23
Qt implementation of ROOT 3D viewer interfaceclassical: Model-View-Controller
TVirtualViewer3D(ROOT > 4.01ROOT > 4.01)
TQtRootViewer3D
TQtGLViewer
TGLViewer(ROOT < 4.01ROOT < 4.01)
TPad
TObject
GL list
Coin Node
model controller view
TQtGLViewerWidget
QGLWidget
QGLViewer
QWidget
GL attrib
GL list
ROOT plug-in
ROOT plug-in
ROOT plug-in
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
24
Combination of the different GL attributes
Original Original + wired
Solid + wired
Solid
Wired“Sliced”
The number of possible combinations and its complexity are unlimited
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
25
Qt 3D features• No “soft” matrix / coordinate transformations
– it is as fast as your GL video hardware• One to one “model-matrix” “view-matrix”, “model-points” “view-points”, “hierarchical model” “hierarchical
view”– Trivial navigation “model->view” and “view->mode”– Change the model does entail change neither in the controller
not in view source code– “Controller” and “view” implementations are trivial, therefore it
is robust and stable• Unlimited number of the simultaneously rendered views / sub-
views / widgets / objects• No user’s model (TObject for example) pointer needed
– The destruction of the model does not entail the viewer crash and versa verse.
• Functionality satisfies the most STAR collaboration requirements
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
26
Click mouse action of QGLViewer
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
27
Mouse action of QGLViewer
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
28
3D selection and highlighting
“Full” wired
Status bar
ROOT context menu
Satellite widget
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
29
3D customizationIs trivial and it is defined by the Qt and QGLViewer
implementation, “philosophy” and design• 3D viewer attributes – base class
– Use – predefined subclasses– Subclass yourself and use
• Rendering– Ask controller to generate the view for the “known” ROOT
classes– Provide your own custom view factory for your class or for the
“know” ROOT class– Provide the Qt slot to respond the “QGLViewer “draw” Qt signal
• Selection ( like “Rendering”)– Provide the Qt slot to respond to the QGLViewer “select” signal
• Provide your own “controller”/”view”
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
30
ROOT resource parametersPlugin.TVirtualPadEditor: Ged TQtGedEditor QtGed "TQtGedEditor(TCanvas*)"
Plugin.TPaletteEditor: * TQtPaletteEditor QtImage "TQtPaletteEditor(TAttImage*,UInt_t,UInt_t)“
Plugin.TImage: * TQtImage QtImage "TQtImage()“
# GUI specific settingsGui.Style: windows | native | motif | platinum | etc . . . Gui.Backend: qt | nativeGui.Factory: qtgui | native | qt
Plugin.TVirtualX: qt TGQt GQt "TGQt(const char*,const char*)"
Plugin.TGuiFactory: qtgui TQtGUIFactory QtGui "TQtGUIFactory()"
Plugin.TVirtualViewer3D: ogl TQtRootViewer3D RQTGL "TQtRootViewer3D(TVirtualPad*)"
All plugins but TVirtualX are optional
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
31
“HelloWord” examples:
• HelloWord - Qt-based ROOT application (see p.362)• HelloCanvas - ROOT-based Qt-application (see p.362)• HelloCint(*) - ROOT-based shared library (see p.363)• ex1 - the simple ROOT-based Qt-applciation
built automatically with qt "designer" (see: p.364)• QtGBrowser(*) - "Advanced version of Qt application
build with the Qt "designer“ • CustomWidgets(*)• CustomCanvasMenu
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
32
Installation• ROOT bundle
./configure […] --enable-qt make
• Stand-alone, either from ROOT CVS or from full version BNL CVS (against an arbitrary not too old ROOT version)
qmake [<subdir>.pro]make
See: http://root.bnl.gov
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
33
Qt project and Qt designer• Qt designer
Import the pre-defined Qt “Custom widget” definition:
$ROOTSYS/include/TQtWidget.cw
$ROOTSYS/include/TQtGLViewerWidget.cw
• Qt “qmake” utility
Include the qmake include file into your project
$ROOTSYS/include/rootcint.pri
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
34
Documentation tools
• On-line documentation is prepared with the ROOT THtml class. In addition there is a script to post-process the output of the THtml class. It replaces all references of the Qt classes with the proper hyperlinks to TrollTech or QGLViewer online documentation. To be useful for the other application as well.
• Since ROOT 4.04 the ROOT User’s Manual contains the “Qt” section.
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
35
STAR “Event Displays”
Online event display: Web broadcast the real-time STAR events 24 x 7 during the RUN 2005 (Run 2006 coming next month
Offline “Event display”: used to debug the STAR reconstruction and analysis codes
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
36
Readiness• Works on UNIX and “native” Mac. It was
tested on Windows with ROOT 4.00.08.• 2D / 3D Qt Root widget are working and
stable• ROOT GUI needs work inside TGQt class
that affects no end-user interface• In other words, QtRoot interface is stable
and it is safe to use it within Qt-based applications.
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
37
From the single source code
X11
win32gdk
Qt native
Qt X11
(cygwin)
UNIX
Mac
Windows
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
38
To Do• Find and fix the remaining bugs
• Negotiate with ROOT team to adopt more project “pieces”
• Add QtThreadImp class to the official CERN distribution.
• More Qt Proxy for ROOT Editor classes
• Integrate ROOT “ql” view
etc
(ROOT is fast evolving project after all)
Feb 15, 2006 CHEP’06, MumbaiV.Fine, JLauret, V.Perevoztchikov
39
References • CINT status, Masa Goto
http://www.slac.stanford.edu/BFROOT/www/Computing/Distributed/ROOT2004/files/goto.ppt
• Cross-platform approach to create the interactive application based on ROOT and Qt GUI libraries.http://www-conf.kek.jp/acat03/prog/presen/id0112.ppt
• ROOT in GO4, Joern Adamczewski http://www.slac.stanford.edu/BFROOT/www/Computing/Distributed/ROOT2004/files/adamczewski.ppt
• Cross-platform Qt-based implementation of low level GUI layer of ROOT
http://acat02.sinp.msu.ru/presentations/fine/Acat2002.ppt
• Cross-platform approach to create the interactive application based on ROOT and Qt GUI librarieshttp://www-conf.kek.jp/acat03/prog/presen/id0112.ppt
• Visualization of the ROOT 3D class objects with Open Inventor-like viewers http://www-conf.kek.jp/acat03/prog/presen/id0113.ppt
• C++ GUI Programming with Qt3 http://phptr.com/content/images/0131240722/downloads/blanchette_book.pdf
• ROOT 4.04 User’s Manual