source: Sophya/trunk/SophyaLib/Manual/piapp.tex@ 3438

Last change on this file since 3438 was 3438, checked in by ansari, 18 years ago

Ajout aknowledgments ds docs et + chapitre 5 ds piapp.tex (expression plotting) - Reza 12/12/2007

File size: 62.9 KB
RevLine 
[3041]1\documentclass[twoside,10pt]{article}
[2384]2% \usepackage[latin1]{inputenc}
3% \usepackage[T1]{fontenc}
[2171]4\usepackage[francais]{babel}
5\usepackage{graphicx}
6
[2384]7\usepackage{amsmath}
8\usepackage{amssymb}
9\usepackage{latexsym}
10
[2171]11\usepackage{palatino}
12
13% Definition pour Docs Sophya
14\usepackage{defsophya}
15
16\usepackage{makeidx}
17
18\usepackage[ps2pdf,bookmarks,bookmarksnumbered,%
19 urlcolor=blue,citecolor=blue,linkcolor=blue,%
20 pagecolor=blue,%hyperindex,%
21 colorlinks=true,hyperfigures=true,hyperindex=true
22 ]{hyperref}
23
[3429]24\setlength{\textwidth}{15cm}
25\setlength{\textheight}{20.5cm}
26\setlength{\topmargin}{0.cm}
[2171]27\setlength{\oddsidemargin}{0.cm}
28\setlength{\evensidemargin}{0.cm}
29\setlength{\unitlength}{1mm}
30
[2384]31% \newcommand{\piacommand}[1]{
32% \framebox{\bf \Large #1 } \index{#1} % (Command)
33%}
34% \newcommand{\piahelpitem}[1]{
35% \framebox{\bf \Large #1 } \index{#1} (Help item)
36%}
37
[3041]38\newcommand{\rond}{$\bullet \ $}
39\newcommand{\etoile}{$\star \ $}
40\newcommand{\cercle}{$\circ \ $}
41\newcommand{\carre}{$\Box \ $}
42
43%%%% Definition des commandes pour l'aide en ligne
[2171]44\newcommand{\piacommand}[1]{
[2384]45$\blacksquare$ \hspace{3mm} {\bf \Large #1 } \index{#1} % (Command)
[2171]46}
47\newcommand{\piahelpitem}[1]{
[2384]48$\square$ \hspace{3mm} {\bf \Large #1 } \index{#1} (Help item)
[2171]49}
50
[3041]51\newcommand{\menubar}[1]{\hspace{1mm} \framebox{\it MenuBar::#1} \hspace{1mm}}
52
[2171]53\newcommand{\myppageref}[1]{ (p. \pageref{#1} ) }
54
55\makeindex % Constitution d'index
56
57\begin{document}
58\begin{titlepage}
59% The title page - top of the page with the title of the paper
60\titrehp{piapp \\ An interactive data analysis tool}
61% Authors list
62\auteurs{
63R. Ansari & ansari@lal.in2p3.fr \\
64E. Aubourg & aubourg@hep.saclay.cea.fr \\
65C. Magneville & cmv@hep.saclay.cea.fr \\
66O. Perdereau & perderos@lal.in2p3.fr \\
67}
68% \author{R. Ansari {\tt ansari@lal.in2p3.fr} \\
69% E. Aubourg {\tt aubourg@hep.saclay.cea.fr} \\
70% C. Magneville {\tt cmv@hep.saclay.cea.fr}
71% }
72\vspace{1cm}
73\begin{center}
[3429]74{\bf \Large piapp Version: 4.1 (V\_Nov2007) }
[2171]75\end{center}
76\titrebp{5}
77
78\end{titlepage}
79
80\newpage
81\tableofcontents
82\newpage
83
84\section{Introduction}
85\index{piapp}
86{\bf piapp} (or {\bf spiapp}) is an interactive data analysis
87and visualization program. It is based on the {\bf PI} GUI library
[3041]88and the {\bf SOPHYA} \footnote{see http://www.sophya.org}
89(or {\bf PEIDA++} \footnote{PEIDA++ has been used in EROS software.
90(http://eros.in2p3.fr). It is not maintained anymore.})
91C++ data analysis class library.
92\par
93{\bf piapp} is a powerful command oriented tool for visualising and analysing data.
94Its main features are summarised below:
95\begin{itemize}
96\item[\rond] Image, multiple 2D and few 3D representations
97\item[\rond] Highly interactive graphics, with postscript as export format
98\item[\rond] Capability to handle large data sets. Data can be imported and
99exported in different formats: ASCII, PPF and FITS.
100\item[\rond] Interactive analysis: 2D/3D distributions, histograms, FFT \ldots
101\item[\rond] Flexible c-shell inspired command interpreter.
102\item[\rond] Possibility to perform more complex operations in C++, on objects
103managed by the application through the on-the-fly compilation and execution
104of c++ code fragments in piapp.
105\item[\rond] piapp is a multi-threaded program with separate threads for graphics
106and command execution, ensuring interactive response, even while heavy
107computation is being performed. In addition, thread safe commands can be executed
108in separate threads, for taking advantage of multi CPU (or CPU-cores) workstations.
109\item[\rond] The application can be easily extended through modules which can be
110loaded at run time.
111\end{itemize}
[3438]112
113\subsection{Acknowlegments}
114Many people have contributed to the development SOPHYA and/or the PI library
115and (s)piapp interactive analysis tool.
116we are grateful to the following people:
117
118\begin{tabular}{lcl}
119Reza Ansari & \hspace{5mm} & (LAL-Univ.Paris Sud, Orsay) \\
120Eric Aubourg & & (DAPNIA-CEA/APC, Saclay) \\
121Sophie Henrot-Versille & & (LAL-IN2P3/CNRS, Orsay) \\
122Alex Kim & & (LBL, Berkeley) \\
123Guy Le Meur & & (LAL-IN2P3/CNRS, Orsay) \\
124Eric Lesquoy & & (DAPNIA-CEA, Saclay) \\
125Christophe Magneville & & (DAPNIA-CEA, Saclay) \\
126Bruno Mansoux & & (LAL-IN2P3/CNRS, Orsay) \\
127Olivier Perdereau & & (LAL-IN2P3/CNRS, Orsay) \\
128Nicolas Regnault & & (LPNHE-IN2P3/CNRS, Paris) \\
129Benoit Revenu & & (APC/Univ.Paris 7, Paris) \\
130Francois Touze & & (LAL-IN2P3/CNRS, Orsay) \\
131\end{tabular}
132
133We thank also the persons who have helped us by useful suggestions, among others : \\
134S. Bargot, S. Du, S. Plasczczynski, C. Renault and D. Yvon.
135
[3041]136%%%
[3429]137\begin{figure}[ht!]
138\begin{center}
139\includegraphics[width=15cm]{piapp_mainwin.eps}
140\caption{piapp main window}
141\label{figmainwin}
142\end{center}
143\end{figure}
144\subsection{starting piapp}
[3041]145 {\bf piapp} can simply be started on the command line in a terminal window
146once the SOPHYA/piapp environment has been initialised.
147The environment variables {\tt SOPHYABASE} should contain the directory
148where SOPHYA/piapp has been installed. the shared library path
149{\tt LD\_LIBRARY\_PATH} must contain {\tt \$SOPHYABASE /slb} and the
150current directory {\tt .} and the executable search path {\tt PATH} must
151contain {\tt \$SOPHYABASE /exe}. Refer to the SOPHYA overview manual
152for more information on SOPHYA directory structure. \\
153It might also be necessary to define the environment variable
154{\bf PIXKBMOMASK}, used by the libPI.a to map correctly
155the {\tt <Alt>} key with some X servers (in particular with
156X11 on MacOS X). \\
157{\tt csh> setenv PIXKBMODMASK 2 }
158\par
159{\tt (s)piapp -h} provides a brief help of the command line
[2171]160arguments. Xtoolkit options can also be specified as command line
[3041]161arguments. {\bf spiapp} is the name of SOPHYA/piapp executable,
162in order to distinguish it from PEIDA/piapp.
[2171]163\begin{verbatim}
164csh> spiapp -h
[3041]165 SophyaInitiator::SophyaInitiator() BaseTools Init
166 PIOPersist::Initialize() Starting Sophya Persistence management service
[3429]167SOPHYA Version 2.1 Revision 0 (V_Nov2007) -- Nov 24 2007 13:08:58 gcc 3.3
16820030304 (Apple Computer, Inc. build 1495)
[3041]169 piapp: Interactive data analysis and visualisation program
[3429]170 Usage: piapp [-nored] [-doublered] [-termread] [-term]
171 [-hidezswin] [-small] [-nosig] [-nosigfpe] [-nosigsegv]
[3041]172 [-tmpdir TmpDirectory] [-help2tex] [-exec file [args]]
173 -nored : Don't redirect stdout/stderr to piapp console
[3429]174 -doublered : Redirect stdout/stderr to piapp console AND the terminal
[3041]175 -termread : Read commands on terminal (stdin)
176 -term : equivalent to -nored -termread -small
177 -hidezswin : Hide Zoom/Stat/ColMap window
178 -small : Create small size main piapp window
179 -nosig : Don't catch SigFPE, SigSEGV
180 -nosigfpe -nosigsegv: Don t catch SigFPE / SigSEGV
181 -tmpdir TmpDirectory: defines TMDIR for temporary files
[2171]182 -help2tex: Create a LaTeX help file (piahelp.tex)
[3041]183 -exec file [args] : Execute command file (last option)
[2171]184\end{verbatim}
[3041]185Once {\bf piapp} is started, the main piapp window appears.
186It contains the menu bar, an upper part with the zoom and colormap
187widgets for image displays, memory and CPU usage and a terminal like
188widget (piapp console, see {\bf PIConsole} \myppageref{PIConsole})
189in the lower part. The figure \ref{figmainwin}
[2171]190shows an image of the piapp main window.
[3041]191{\tt stdout/cout, stderr/cerr} are redirected to the piapp console and
192commands can be entered in this widget. It is also possible to keep
193the terminal where piapp was started for {\tt stdout/stderr} (flag {\tt -nored}).
194It is also possible to have a command reader on the terminal
195({\tt stdin}), using the flag {\tt -term}. \\[1mm]
196%
197{\bf Warning:} The output redirection uses unix pipes. On Linux, with commands
198producing long outputs, the application may block because of incorrect management
[3429]199of pipes. If this happens, use piapp with {\tt -nored} flag. This problem has been
200in principle solved with SOPHYA V=2.1 / piapp V=4.1
[2171]201
[3041]202\par
203In section 2, we present a quick tour of {\bf piapp}.
204a brief overview of piapp graphics, supported data formats, interactive
205analysis possibilities, the command interpreter and c++ execution
206are presented in the following sections.
207Section \ref{piappcmdref} contains a brief description of all piapp commands
208and help items. Various interactive control windows are described in appendix.
[2171]209
210
211\newpage
212\section{A Tour of piapp}
[3041]213\subsection{Interacting with piapp, getting help}
214Users interact with piapp through commands entered in the piapp-console
215(or the unix terminal), and through the different menus.
216Some of the possibilities of the piapp-console are described
217in {\bf PIConsole} help item, in the command reference section \myppageref{PIConsole}.
218The description
219of the commands in available online using the help command.
220An online help window can be displayed by \menubar{File / Help}.
221Commands and help items are grouped in categories which can be
222selected using the OptionMenu in the Help window.
223\begin{verbatim}
224Cmd> help func
225Displays a function y=f(x) (Fills a vector with function values)
226 Usage: func f(x) xmin xmax [npt graphic_attributes]
227 Related commands: funcff func2d func2dff
228Cmd> func sin(x)/x 0.1 10 100 'red line=solid,2'
229---> Graphic display of the function
230\end{verbatim}
231The directory {\tt DemoPIApp} contains a number of example
232command script and sample data files.
233
[2171]234\subsection{the Object Manager (NamedObjMgr)}
235The {\bf piapp} application is built around an object manager
236(class {\tt NamedObjMgr}) and a graphic application
237(class {\tt PIStdImgApp}). Objects inheriting from
238the class {\tt AnyDataObj} can be managed through adapter
239classes (classes inheriting from {\tt NObjMgrAdapter}) by
240the object manager.
241\par
242User sees the objects (such as Sophya objects Histo, NTuple,
243Arrays, Images, SkyMaps, \ldots) kept in memory, organized
244in a single level tree structure. Four memory directories
245are automatically created and can not be removed: \\
246\centerline{\bf /home \hspace{10mm} /old \hspace{10mm} /tmp \hspace{10mm} /autoc}
247The default working directory (in memory) is {\bf /home}.
248Other directories can be created by the user.
249\begin{center}
250{\bf Warning:} These are only the directory
251structure managed by the piapp application and do not
252correspond to the file system directories
253\end{center}
254The window {\bf ObjMgr} shown in figure \ref{figobjmgrw}
255can be used to navigate in the memory directories and
[3041]256execute simple operations on objects. \\
257This window can be displayed using the menu command
258\menubar{Objects / ObjectManager}.
[2171]259The button \framebox{\small \bf SetCurObj} can be used to set the value
260of the interpreter's variable {\tt cobj} to the selected
261object name.
262Refer to the commands in group {\bf Object Management}
263for more information.
264
265\vspace*{5mm}
266\begin{figure}[ht!]
267\begin{center}
268\includegraphics[width=10cm]{piapp_objmgr.eps}
269\caption{The interactive object management window}
270\label{figobjmgrw}
271\end{center}
272\end{figure}
273
274\subsection{command language}
[3041]275A basic command interpreter ({\bf PIACmd/Commander}) is included in {\bf piapp} and
[2171]276other command interpreters can be inserted in the application
277framework.
[3041]278This interpreter ({\bf Commander} \myppageref{Commander})
[2171]279synthax is close to the c-shell
280(csh) shell script. It is possible to define and use variables
281({\tt set} command, {\tt \$varname}), and execute loops
282({\tt foreach,for}), as well as simple tests
283({\tt if test then ... else ... endif}).
284Commands from a file (default extension .pic) can be executed
285using the {\tt exec} command.
286Long commands can be put on several lines, by ending a line
287by the backslash \\ caracter, to signal that the command
288continues on the next line.
289
290The command macro below shows a sample piapp session, where
291data from the file {\tt demo.ppf} are displayed.
292\begin{verbatim}
293# Trace mode -> On
294traceon
295# Deleting all objects in the current directory
296delobjs *
297# Opening the PPF file demo.ppf
298openppf demo.ppf
299# Various displays in a graphic window, divided into 2x2 zones
300zone 2 2
301# 1D histogram display
302disp h1d blue
303# 2D histogram display
304disp h2d
305# Function display
306func sin(x)/x 0.1 10. 200 gold
307# Surface representation of a matrix
308surf mtx1 colbr32
[2253]309# Contour representation of a matrix
310contour mtx1 'colrj32 normalline ncont=7'
[2171]311# 3D representation of points using a PAW like command
312n/plot nt31.z%y%x ! ! win
313# 3D points superimposed on the previous display
314nt3d nt32 x y z ex ey ez - - 'same fcirclemarker7 red'
315\end{verbatim}
316
317\subsection{NTuple vue / PAW like commands}
318It is possible to plot various expressions of objects, seen as
319a 2D table, with named columns. This possibility exist not only
320for NTuples, but also for most objects (from SOPHYA) handled
321by piapp. See command groups {\bf Expr.Plotting} and
322{\bf pawCmd}
323
324\subsection{C++ execution inside piapp}
325For more complex processings, where the full power of C++
326and the class libraries are necessary, {\bf piapp} provide
327the possibility of executing C++ code, without the burden
328of having to write a complete program. The objects
329present in the current directory are automatically
330declared. The communication with the piapp application
331is done by the {\bf NamedObjMgr} class.
332Two macros {\tt KeepObj()} and {\tt DisplayObj()}
333simplify the task of keeping newly created objects.
334In the example below, we first create a noisy signal
335in a vector, and we keep it in the application
336(Notice the use of multiline command) :
337
338\begin{verbatim}
339Cmd> c++exec c++exec Vector in(1024); \
[3041]340...? in = RandomSequence(RandomSequence::Gaussian, 0., 1.); \
341...? for(int kk=0; kk<in.Size(); kk++) \
342...? in(kk) += 2*sin(kk*0.05); \
343...? KeepObj(in);
[2171]344\end{verbatim}
345We can of course display the resulting vector:
346\begin{verbatim}
347Cmd> disp in
348\end{verbatim}
349
350And, at a subsequent stage, make a low pass filter
351on the vector in:
352\begin{verbatim}
353Cmd> c++exec Vector out(1024); \
[3041]354...? int w = 2; \
355...? for(int k=w; k<in.Size()-w; k++) \
356...? out(k) = in(Range(k-w, k+w)).Sum()/(2.*w+1.); \
357...? KeepObj(out);
[2171]358\end{verbatim}
359
360We can display the new vector {\tt out} overlayed
361on the previously displayed vector:
362\begin{verbatim}
363Cmd> disp out 'red same'
364\end{verbatim}
365
366See command group {\bf CxxExecutorCmd} for more information,
367and the option window activated by the menu:
368{\bf Special/CxxExecOption}.
369
370\subsection{Extending the application}
371The {\bf piapp} application can easily be extended by the user.
372This is done through shared libraries which can be opened
373and used by the application.
374Two main methods can be used (see command group
375{\bf ExternalModules}) :
376\begin{itemize}
377\item Creation of user functions. A shared library containing
378at least one user function with the following prototype
379should be created:
380\begin{verbatim}
381extern "C" {
382 void myfonction(vector<string>& args);
383}
384\end{verbatim}
385The class {\bf NameObjMgr} should be used to communicate with the
386application. The {\tt link} \myppageref{link} and {\tt call} \myppageref{call}
387should be used to load and execute user functions. An example of
388user function can be found in DemoPIApp/user.cc exlink.pic.
389
390\item Creation of loadable modules: Loadable modules can be
391used to extend the application possibilities in a way totally
392transparent to the user. It is possible to define new commands,
393handling of new object types, additional graphic functionalities
394in a loadable module.
395
396The class {\bf CmdExecutor} is the base class for extending piapp.
397A shared library should be built, containing two functions,for
398the activation and deactivation of the module, with the following
399prototype (where {\tt mymodule} is the module's name.
400\begin{verbatim}
401extern "C" {
402 void mymodule_init();
403 void mymodule_end();
404}
405\end{verbatim}
406
407\end{itemize}
408
[3041]409%%%%%%%%%% Section 3: Graphiques
[2171]410\newpage
[3043]411\section{Interactive graphics}
412%%%
413\subsection{Display commands}
414Many objects managed by piapp have a default graphic representation. The
415{\bf disp} command \myppageref{disp} can be used to display the object, while
416other commands like {\bf surf} \myppageref{surf} , {\bf imag}
[3429]417or {\bf contour} \myppageref{contour} will try to force a given graphic representation.
418
[3043]419Data from table like objects can be plotted using commands like {\bf nt2d}
420\myppageref{nt2d} or {\bf nt3d} \myppageref{nt3d}. Most objects in piapp
421can also be manipulated like table for plotting purposes, using commands
422like {\bf plot2d} \myppageref{plot2d} , {\bf plot3d} \myppageref{plot3d}
423or {\bf n/plot} \myppageref{nZplot}. These commands are described in section
[3429]424\ref{tableplot}.
425
426Commands producing a graphic output have usually an optional argument called \\
427{\tt graphic\_attributes} or {\tt gr\_att}. \\
428This argument provide a flexible and easy
429way to change and customise the output graphic, as discussed in the paragraphs below.
430
[3043]431The piapp graphics can be exported in postscript (.ps) or encapsulated postscript
432(.eps) format. The commands {\bf w2ps} \myppageref{w2ps} and
433 {\bf w2eps} \myppageref{w2eps} as well the menu \menubar{PostScript} can
[3429]434 be used to export graphics. \\[2mm]
435The examples in the followwing pages illustrates the usage of some piapp graphic commands.
436\newpage
[3043]437\begin{enumerate}
438\item Image display
439\begin{verbatim}
440# Open a PPF file containing topographic data for france
441# as a TMatrix<short> 1332x1548
442openppf francetopo.ppf
443# Display the matrix, whit a zoom factor, lut and color map
444disp francetopo 'zoom/3 lut=lin,-700,800 colbr128 win'
445w2eps francetopo.eps
446\end{verbatim}
447\begin{center}
448\includegraphics[width=13cm]{francetopo.eps}
449\end{center}
[2171]450
[3043]451\item Simple 2D graphics with vector displays
452\begin{verbatim}
453# Create and initialize two vectors - prevent display : nodisp
454Cmd> newvec vva 100 sin(x/10.+0.7)+cos(x/7.+1.4)*1.26 nodisp
455Cmd> newvec vvb 100 sin(x/10.)+cos(x/7.)*1.34 nodisp
456# Set axe drawing options
457Cmd> setaxesatt 'font=times,bold,16 minorticks tickslen=0.02,0.012'
458# Display the two vectors, with different graphic attributes
459Cmd> disp vva 'red line=solid,2 notitle'
460# Define a title for the graphic
461Cmd> settitle 'Example-1: 2 vectors' ' ' 'font=times,bolditalic,18'
462Cmd> disp vvb 'blue marker=box,7 same'
463# Save the graphic into an eps file
464Cmd> w2eps gr2vec.eps
465\end{verbatim}
466% \begin{figure}[ht!]
467\begin{center}
468\includegraphics[width=12cm]{gr2vec.eps}
469% \label{g22vec}
470\end{center}
471%%%
472\item Creating a comparison chart using {\bf bargraph}
473\begin{verbatim}
474# Representation du PNB (en $, 2003) pour quelques pays
475set pays ( Allemagne Espagne France Italie Pays-Bas Suisse UK USA )
476set pnbh ( 22670 14430 22010 18960 23960 37930 25250 35060 )
477setaxesatt 'font=times,bold,16'
478bargraph pnbh pays - 'blue horizontalbars nofill packfrac=0.65 font=helvetica,bold,14'
479setaxelabels 'PNB / Hab , $ 2003' ' ' 'font=times,bold,16'
480w2eps pnbargraph.eps
481\end{verbatim}
482\begin{center}
483\includegraphics[width=12cm]{pnbbargraph.eps}
484\end{center}
485%%%
486\item Displaying a matrix as a surface
487\begin{verbatim}
488openppf demo.ppf mtx1
489setaxesatt 'font=time,bold,16'
490surf mtx1 'colbr128 line=solid,1 grey'
491w2eps surfcol.eps
492\end{verbatim}
493\begin{center}
494\includegraphics[width=13cm]{surfcol.eps}
495\end{center}
496
497\end{enumerate}
498
499%%%%%%%%%%
500\subsection{Graphic objects in piapp}
501The piapp graphics is handled by the {\bf PI} \footnote {http://www.sophya.org/PI} library,
502which provide a large variety of 2D representations,
503few 3D graphics and powerful image display. \\
504Currently, all graphic representations, except for image displays, are handled
505through {\bf PIDrawers} which are managed by a viewer. A viewer can
506manage several {\bf PIDrawers} objects which correspond then to a multilayer
507graphic display. The viewers are also responsible for managing user
508interactions. \\
509Image displays are handled through a specific viewer
510{\bf PIImage} which is also capable of managing PIDrawer objects
511for multi-layer 2D overlay vector graphics. \\[2mm]
512%%
[3429]513Main piapp/PI graphic viewers, windows and drawer objects are described if
514the following sections.
515
516\subsubsection{PIScDrawWdg (2D display)}
517The {\bf PIScDrawWdg} handles a set of of 2-D drawers, managing
[3043]518the 2D coordinate system and interactive zoom. The axes drawing is
519handled by a specialised drawer, number 0, which also manages various added
520graphic elements (text \ldots). The list of various mouse and
521keyboard actions is described in the reference section, under {\bf PIScDrawWdg} \myppageref{PIScDrawWdg} title. In particular, mouse-button-2 can be used
522to zoom on a particular part, {\tt $<$Alt$>$A} activates the coordinates
523and axes manipulation window ({\bf PIAxesTools}) and {\tt $<$Alt$>$G}
524activates the PIDrawer graphic attributes control window ({\bf PIDrawerTools}).
525%%%
[3429]526\subsubsection{PIDraw3DWdg (3D display)}
527The {\bf PIDraw3DWdg} handles a set of of 3-D drawers, managing
[3043]528interactive camera/object rotation (mouse-button-2) and zoom (mouse-button-2).
529{\tt $<$Alt$>$G} to display/activate the PIDrawer graphic attributes
530control window ({\bf PIDrawerTools}).
531See {\bf PIDraw3DWdg} \myppageref{PIDraw3DWdg} for a complete list of mouse
532and keyboard actions.
533Drawer 0 handles axes drawing and graphic elements.
534%%%
[3429]535\subsubsection{PIImage (Image Display)}
536The display of 2-D arrays $A(i,j)$ as an image is managed by
[3043]537the {\bf PIImage} viewer/widget. The PI library interface {\bf P2DArrayAdapter} is used
538to represent a generic 2-D array. The array values are converted into an index, converted
539itself into a color by the use of a color-map or color-table {\bf PIColorMap}.
540$$ \mathrm{LUT:} A(i,j) \longrightarrow idx(i,j) \hspace{5mm} \mathrm{ColorMap:}
541 idx(i,j) \longrightarrow col(i,j) $$
542Currently index range is 0...255 with color-map having 32 or 128 distinct colors.
543PIImage viewers controls a zoom widget, as well as a global image view widget, and
544a color map view widget. A specific image control window can be activated using
545 {\tt $<$Alt$>$O}. See {\bf PIImage} \myppageref{PIImage} for
546a complete list of mouse and keyboard actions. A base drawer (number 0) can handle
547axes drawing and added graphic elements.
548%%%
[3429]549\subsubsection{Windows}
[3043]550The viewers described above are displayed in differnt kind of windows.
551The graphic option {\tt next,win,same,stack} can be used to control the way the
552type of windows used. Graphic windows can be divided into several zones
[3429]553(Command {\bf zone} \myppageref{zone}).
554
555When an object is diplayed in piapp, a widget (PIWdg) is created which manages
556the drawer or the 2d-array. The default name for this widget is the displayed
557object name. However, it is possible to specify a name using the graphic attribute: \\
558\hspace*{5mm} {\tt wname=WidgetName} \\
559It is possible to display multiple objects on a single widget, corresponding
560to the superposition of the different drawers. Displaying an object superimposed
561on the previously displayed object can be done using the graphic option
562{\tt same}. It is also possible to specify a target widget by its name, through
563the graphic option \\
564\hspace*{5mm} {\tt samew=WidgetName} \\
565It is also possible to specify the display of the drawer in a specified region
566of the last displayed widget \\
567\hspace*{5mm} {\tt same=fx1,fx2,fy1,fy2} \\
568where {\tt fx1,fx2,fy1,fy2} express X and Y limits, as fraction of widget size.
569
[2172]570Refer to the command reference section on windows ({\bf Windows}
571\myppageref{Windows})
[2171]572for information on the different type of windows used by piapp
[3429]573and their properties. \\
574
[3043]575%%%
[3429]576\subsubsection{Drawers}
577Graphical representation of most objects in piapp is
578handled through objects inheriting from the {\bf PIDrawer class}. A base drawer
[3043]579(PIElDrawer, number 0) associated to all three above viewers manages the axes drawing
580as well as the added graphic elements (text, arrow, \ldots). A drawer management menu
581can be activated using {\tt $<$Alt$>$D}. This menu can be used to move and resize
582drawers, or to display a window for changing drawers graphic attributes.
[3429]583%%%
[2172]584\par
[2171]585In addition, a number of control windows can be used to examine and
586change view properties of differents viewers and drawers.
587\begin{itemize}
[3043]588\item[] {\bf PIDrawerTools} activated using {\tt $<$Alt$>$G} or
589\menubar{Tools/Show DrawerTools} on any viewer (see page \myppageref{secdrwtools})
590\item[] {\bf PIAxesTools} activated using {\tt $<$Alt$>$A} or
591\menubar{Tools/Show AxeTools} on PIScDrawWdg (see page \myppageref{secaxestools})
592\item[] {\bf PIImageTools} activated using {\tt $<$Alt$>$O} or
593\menubar{Tools/Show ImageTools} on PIImage
594(see page \myppageref{secimagetools})
595\item[] {\bf PIHisto2DTools} activated using {\tt $<$Alt$>$O} or through the PIDrawerTools
596for an active PIHisto2D drawer. (see page \myppageref{sech2dtools})
597\item[] {\bf PIContourTools} activated using {\tt $<$Alt$>$O} or through the PIDrawerTools
598for an active PIContourDrawer drawer. (see page \myppageref{secconttools})
[2171]599\end{itemize}
[3043]600These control tools are briefly described in appendix.
[2171]601
[3043]602%%%%%%%%%%
603\subsection{Graphic attributes}
604Graphic attributes are specified as a set of space separated strings. Use
605quotes to group them into a single argument parsed by the command
606interpreter. The options are decoded by the different objects handling the
607graphic (viewer widget, drawer, axe drawer). \\
608The complex decoding scheme
609is usually transparent for piapp users. However, there is an ambiguity when
610specifying some of the axes attributes, such as color or the font used for
611drawing the axes. The command {\bf setaxesatt} (\myppageref{setaxesatt})
612should thus be used to specify generic graphic attributes (color, font, line type). \\
613for axes.
614\begin{itemize}
615\item[\bul] The {\bf PIScDrawWdg} viewer options: \\
616\begin{verbatim}
617>> To define the 2D axes limits (in user coordinates)
618 xylimits=xmin,xmax,ymin,ymax
619>> To define the default drawing rectangle, in fraction of widget size
620 defdrrect=x1,x2,y1,y2 (default: x1=y1=0.1 x2=y2=0.9)
621>> Axes flags :
622 linx logx liny logy
623>> To change the background color (default=white)
624 wbgcol=colname
625
626\end{verbatim}
627%%%
628\item[\bul] The {\bf PIDraw3DWdg} viewer options: \\
629\begin{verbatim}
630>> To define the 3D box limits :
631 xyzlimits=xmin,xmax,ymin,ymax,zmin,zmax
632 limit3dbox=xmin,xmax,ymin,ymax,zmin,zmax
633>> Autoscaling flags (rescaling of X/Y or X/Y/Z axes)
634 autoscale3dbox / noautoscale3dbox
635 autoscalexy3dbox / noautoscalexy3dbox
636 autoscalez3dbox / noautoscalez3dbox
637>> To change the background color (default=white)
638 wbgcol=colname
639
640\end{verbatim}
641%%%
642\item[\bul] The {\bf PIImage} viewer options: \\
643\begin{verbatim}
644>> Define display zoomfactor
645 zoomxFact (zoomx2 zoomx3 ... zoomx9 ...)
646 zoom/Fact (zoom/2 zoom/3 ... )
647>> LUT (look-up table) definition (pixel value to index conversion)
648 lut=type,min,max (type=lin/log/sqrt/square)
[3294]649>> AutoLut selector : define the method for automatic determination
650 of LUT limits (min/max)
651 autolut=alt[,ns[,minp,maxp]] (minp<=pixels<=maxp)
652 - autolut=minmax[,Frac] 0<=Frac<=1
653 - autolut=meansig[,ns] --> mean +/- ns*sigma
654 - autolut=hispeak[,ns] --> around the peak of pixel values histogram
655 - autolut=histail[,ns] --> the tail of pixel values histogram
[3043]656>> Define color table and reversing color indexing flag
657 ColTableName revcmap
658 ==> Standard tables with 32 distinct colors:
659 grey32 invgrey32 colrj32 colbr32 colrv32
660 ==> Standard tables with 128 distinct colors:
661 grey128 invgrey128 colrj128 colbr128
662 ==> Shades of red/green/blue ...
663 red32cm green32cm blue32cm yellow32cm
664 orange32cm cyan32cm violet32cm
665 ==> Some of MIDAS color tables :
666 midas_pastel midas_heat midas_rainbow3
667 midas_bluered midas_bluewhite midas_stairs8
668 midas_stairs9 midas_staircase midas_color
669 midas_manycol midas_idl14 midas_idl15
670 ==> Other tables
671 multicol16 multicol64
672>> Viewed center position (image/array coordinates)
673 imagecenter=xc,yc
674>> Array axes to window axes mapping flags
675 invx invy exchxy
676>> To change the background color (default=black)
677 wbgcol=colname
678
679\end{verbatim}
680%%%
681\item[\bul] The {\bf PIGraphicAtt} Generic graphic attributes (color/font/line \ldots)
682decoded by all drawers: \\
683\begin{verbatim}
684>>> color=ColorName - fgcolor=ColorName - bgcolor=ColorName
685 ColorName: black white grey red blue green yellow
686 magenta cyan turquoise navyblue orange
687 siennared purple limegreen gold violet
688 violetred blueviolet darkviolet skyblue
689 royalblue forestgreen orangered brown
690>>> line=DashType,LineWidth
691 DashType: solid, dash, dotted, dashdotted Width: 1,2,...
692>>> font=FontName,FontAtt,FontSize
693 FontName: courier, helvetica, times, symbol
694 FontAtt: roman, bold, italic, bolditalic
695 FontSize: 6,8,10,12... (pts) - integer
696>>> marker=MarkerType,MarkerSize (MarkerSize: integer 3,5,7...
697 MarkerType: dot, plus, cross, circle, fcircle, box, fbox
698 triangle, ftriangle, star, fstar
699>>> arrow=ArrowType,ArrowSize (ArrowSize: integer 3,5,7...
700 ArrowType: basic, triangle, ftriangle,
701 arrowshaped, farrowshaped
702>>> ColorTables: defcmap grey32 invgrey32 colrj32 colbr32
703 grey128 invgrey128 colrj128 colbr128
704 red32cm green32cm blue32cm yellow32cm
705 orange32cm cyan32cm violet32cm
706 midas_pastel midas_heat midas_rainbow3 midas_bluered
707 midas_bluewhite midas_redwhite
708 multicol16 multicol64
709> revcmap : This flag reverses ColorMap indexing
710------- Old style graphic att ----------
711>> Lines: defline normalline thinline thickline dashedline thindashedline
712 thickdashedline dottedline thindottedline thickdottedline
713>> Font Att: deffontatt normalfont boldfont italicfont bolditalicfont
714 smallfont smallboldfont smallitalicfont smallbolditalicfont
715 bigfont bigboldfont bigitalicfont bigbolditalicfont
716 hugefont hugeboldfont hugeitalicfont hugebolditalicfont
717>> Font Names: deffont courierfont helveticafont timesfont symbolfont
718>> Marker: dotmarker<S> plusmarker<S> crossmarker<S> circlemarker <S>
719 fcirclemarker<S> boxmarker<S> fboxmarker<S> trianglemarker<S>
720 ftrianglemarker<S> starmarker<S> fstarmarker<S>
721 with <S> = 1 3 5 7 9 , Example fboxmarker5 , plusmarker9 ...
722
723\end{verbatim}
724%%%%
725\item[\bul] The {\bf PIElDrawer} decodes axe drawing attributes: \\
726\begin{verbatim}
727 >> Axe and grid configuration flags:
728 axesnone stdaxes defaxes
729 boxaxes boxaxesgrid fineaxes fineaxesgrid
730 centeredaxes finecenteredaxes centeredaxesgrid
731 finecenteredaxesgrid grid/nogrid
732 >> Centered axes position: axescenter=xc,yc
733 >> Axe ticks/labels (h=horizontal/x, v=vertical/y):
734 labels/nolabels hlabels/nohlabels vlabels/novlabels
735 ticks/noticks minorticks/nominorticks
736 extticks/intticks/extintticks nbticks=X_NbTicks,Y_NbTicks
737 tickslen=MajorTickLenFrac,MinorTickLenFraC
738 >> Axe label font size:
739 autofontsize=FontSizeFrac fixedfontsize
740 >> Up/Down title: title tit notitle notit
741 ... Color/Font/line attributes :
742
743\end{verbatim}
744\item[\bul] The {\bf PINTuple} handles most 2D plotting : \\
745\begin{verbatim}
746 sta,stat,stats: activate statistic display
747 nsta,nstat,nostat,nostats: deactivate statistic display
748 statposoff=OffsetX,OffsetY : Position offset for Stats drawing
749 as a fraction of total size
750 connectpoints: The points are connected by a line
751 noconnectpoints (this is the default)
752 colorscale/nocolorscale (Use color scale for weight)
753 sizescale/sizescale=nbins/nosizescale (Use marker size for weight)
754 (and usual color/line/marker/... attribute decoding)
755
756\end{verbatim}
757%%%
758\item[\bul] {\bf PIHisto} and {\bf PIHisto2D} handle1D and 2D histograms display. \\
759The following options are recognised by PIHisto: \\
760\begin{verbatim}
[3138]761 ---- PIHisto options help info :
[3043]762 sta,stat,stats: activate statistic display
763 nsta,nstat,nostat,nostats: deactivate statistic display
764 err / noerr,nerr : draw, do not draw error bars
765 autoerr : draw error bars if Marker drawing requested OR Profile histo
766 fill / nofill,nfill : fill, do not fill bars with selected color
767 statposoff=OffsetX,OffsetY : Position offset for Stats drawing
768 as a fraction of total size
[3151]769 ---- HistoWrapper options :
770 hbincont: select bin content as Y value for display (default)
771 hbinerr: select bin error as Y value for display
772 hbinent: select bin entries as Y value for display
773 hscale=value : multiplicative factor for Y value
774 hoffset=value : additive coefficient for Y value
775 hs1: set hscale=1 hoffset=0 (default)
776 hscale=value : multiplicative factor (in Y)
[3138]777
[3043]778\end{verbatim}
779The following options are recognised by PIHisto2D: \\
780\begin{verbatim}
781- sta,stat,stats: activate statistic display
782 nsta,nstat,nostat,nostats: deactivate statistic display
783- h2disp=typ[,fracpts]: choose display type
784 typ=var: variable size boxes
785 typ=hbk: "a la hbook2"
786 typ=img: image like (use "h2col" for color map)
787 typ=pts: point clouds (fracpts=max possible fraction
788 of used pixels per bin [0,1])
789- h2scale=lin/log[,logscale]: choose linear or logarithmic scale
790- h2dyn=[hmin][,hmax]: choose histogramme range for display
791- use general key to define color table (ex: grey32,midas_heat,...)
792 (see general graphicatt description)
793- use key "revcmap" to reverse color table
794- h2frac=[fmin][,fmax]: choose sub-range display [0,1]
[3151]795 ---- HistoWrapper options : (see HistoWrapper above)
[3043]796
797\end{verbatim}
798%%%%
799\item[\bul] The {\bf PINTuple3D} and {\bf PISurfaceDrawer}
800handles basic 3D plotting and can decode the common 3D box options: \\
801\begin{verbatim}
802 X/Y,Z axis rescaling option (-> cubic 3D box)
803 rescale=autoscale/ norescale=noautoscale : X/Y and Z axis
804 rescalexy=autoscalexy / norescalexy=noautoscalexy : X/Y axis
805 rescalexy=autoscalexy / norescalexy=noautoscalexy : Z axis
806\end{verbatim}
807The PINTuple3D decodes in addition the following options:
808\begin{verbatim}
809 connectpoints: The points are connected by a line
810 noconnectpoints (this is the default)
811 colorscale/nocolorscale (Use color scale for weight)
812 sizescale/sizescale=nbins/nosizescale (Use marker size for weight)
813
814\end{verbatim}
[3429]815\item[\bul] The {\bf (PIContourDrawer)} decodes the following options : \\
816\begin{verbatim}
817 autolevels : automatic selection of levels and number of contours
818 ncont=nLevel (or nc=NLevel) : sets the number of contour
819 lev=v1,v2,v3... (or niv=v1,v2,v3...) set the number and levels of contours
820 lstep=nLev,start,step : define incremental levels
821 labon/laboff : display of contour level values on/off
822 linear/bspline/cubicspl=3spl : select contour kind
823
824\end{verbatim}
825
[3043]826\item[\bul] {\bf PIBarGraph} options : \\
827\begin{verbatim}
828 ---- PIBarGraph options help info :
829 fill/nofill: set bar fill option
830 horizontalbars/verticalbars: set bar orientation
831 packfrac=value : set bar packing fraction (0..1)
832 barvaluelabel/nobarvaluelabel: Use/Don't use bar value as labels
833 --- + Usual colr/line/font attribute decoding ...
834 \end{verbatim}
835\end{itemize}
836
837
[3041]838%%%%%%%%%%%%%%% Section 4 : I/O
839\newpage
[3302]840\section{Data formats and input-output (I/O)}
841The data file formats recognized by piapp are the ones supported by the
842SOPHYA library or its extension.
[3041]843\begin{itemize}
[3302]844\item[\bul] ASCII files - Data can be imported from ascii (text) files as
845datatables or arrays. These objects can also be exported as text files.
846\item[\bul] FITS files - FITS is a popular format used in particular in astronomy.
847\href{http://heasarc.gsfc.nasa.gov/docs/software/fitsio/fitsio.html}
848Data is usually read from FITS files as vectors, images, cubes or tables.
849A subset of SOPHYA objects can be exported in FITS format.
850\item[\bul] PPF (Portable Persistence file Format) is the native SOPHYA
851data format.
852\item[\bul] PostScript - All graphic output produced by piapp can be exported
853as postscript (.ps) or encapsulated postscript (.eps) files.
854\end{itemize}
855
[3429]856\subsection{Text files}
857Text (or ascii) files can be read into array or datatable objects by spiapp.
858
859{\bf Arrays :} \\
860Arrays can be written to to files in text/ascii format using the {\tt arrtoascii}
861 \myppageref{arrtoascii} command. Double precision matrices and vectors
862 can be read from text files using the commands
863 {\tt mtxfrascii} \myppageref{mtxfrascii} and
864 {\tt vecfrascii} \myppageref{vecfrascii} . \\
865The menu-bar command \menubar{File/Open-ASCII} reads in a text
866file as a matrix.
867\begin{verbatim}
868# Create and initialize a matrix
869newmtx arr 250 150 x+3*y
870# Save the file in the text file arr.txt
871arrtoascii arr arr.txt
872# Read the previously created file and fill a matrix
873mtxfrascii mxa arr.txt
874# Print and display the matrix
875print mxa
876disp mxa zoomx2
877\end{verbatim}
878It is possible to specify the field separator in the input file, as well as the marker for the comment
879lines.
880
881{\bf DataTable :} \\
882Text files can also be read as a 2-D table (NTuple or DataTable). The table should be
883created using the {\tt newnt} \myppageref{newnt} or
884{\tt newdt} \myppageref{newdt} command.
885The command {\tt ntfrascii} \myppageref{ntfrascii} can then be used to append
886data from the file to the datatable.
887
888\subsection{PPF}
889%%%
890PPF (Portable Persistence file Format) is the the native persistence
891format of SOPHYA and thus is fully handled by spiapp. PPF files can
892be opened through the menu-bar \menubar{File/Open-PPF}, or through
893the {\tt openppf} \myppageref{openppf}.
894
895If the PPF file contains NameTags, only the objects marked with nametags are read and given
896the corresponding names. Otherwise, all objects are red sequentially, with their names
897formed by the filename followed by a sequence number. It is also possible to force the sequential
898reading specifying the {\tt -s} flag for openppf.
899
900The objects managed in spiapp by the {\bf NamedObjMgr} can be saved to PPF files, with their
901names as NameTags. The commands {\tt saveppf} \myppageref{saveppf} or
902 {\tt saveall} \myppageref{saveall} can be used to this end.
903
904\begin{verbatim}
905# Create two vectors and two matrices
906newvec va1 150 sin(sqrt(x))
907newvec vb2 150 sin(sqrt(x))*sqrt(x*0.1)
908newmtx mxa 250 150 x+2.*y
909newmtx mxb 250 150 sin(sqrt(x))*cos(sqrt(y))
910# List of the objects in memory
911listobjs
912# Save the two vectors in the file vecab.ppf
913saveppf v* vecab.ppf
914# Save the two matrices in the file mxab.ppf
915saveppf m* mxab.ppf
916\end{verbatim}
917
918\subsection{FITS}
919FITS files may contain three types of data structures
920\begin{enumerate}
921\item Image or array data structure : {\tt IMAGE\_HDU}
922\item Binary table : {\tt BINARY\_TBL}
923\item ascii table : {\tt ASCII\_TBL}
924\end{enumerate}
925The {\bf FitsIOServer} module contain FitsHandler classes which
926can map many SOPHYA classes on FITS data structures.
927Generic {\tt IMAGE\_HDU} correspond to the SOPHYA \tcls{TArray}
928class, while {\tt BINARY\_TBL} or {\tt ASCII\_TBL} is mapped
929to NTuple or DataTable.
930
931FITS format files can be read through the menu command \menubar{File/Open-Fits},
932or using {\tt readfits/openfits} \myppageref{readfits} command.
933Objects can be exported to FITS using the {\tt writefits/savefits}
934\myppageref{writefits} command.
935
936\begin{verbatim}
937# Open the PPF file created by the commands above
938openppf vecab.ppf
939# Export the two vector objects to file vecab.fits
940# Note that the '!' forces c-fitsio to overwrite the file, if it exists
941writefits v?? !vecab.fits
942\end{verbatim}
943
[3437]944There are two commands useful
945when analyzing large catalogs (BINARY\_TBL) in FITS format, which avoid reading the whole
946table in memory. {\tt swfitstable}\myppageref{swfitstable} reads a specified HDU
947as a {\bf SwFitsDataTable} object which uses the FITS file as swap space.
948The {\tt fitsadapt}\myppageref{fitsadapt} can also be used for similar purposes.
949
950The following commands shows how to open a FITS file containing a synchrotron map
951of our galaxy:
952\begin{verbatim}
953# Open the fits file : the map is in HEALPix format
954readfits syncmap.fits
955# Create a window with the appropriate size
956newwin 1 1 800 400
957# Display the map, specifying the colormap
958disp syncmap 'lut=lin,2,50 midas_bluered'
959\end{verbatim}
960\begin{figure}[h]
961\begin{center}
962\includegraphics[width=15cm]{syncmap.eps}
963\caption{Synchron map of our Galaxy, displayed in Molleweide projection}
964\end{center}
965\end{figure}
966
[3302]967\subsection{Graphic export in postscript}
[3429]968%%
969Postscript a page description language widely used for printing and
970graphic output, developed by Adobe systems. Refer to
971\href{http://www.adobe.com/products/postscript/}{Adobe/PostScript3}
972for more detail.
[2171]973
[3429]974Piapp graphic output can be exported in postscript (level 2) or
975encapsulated postscript format.
976Postscript (.ps) files my contain several pages, each vue or window
977corresponding to one page and are suitable for direct printing.
978An Encapsulated Postscript (.eps) file contains a single page,
979corresponding to a window and is suitable for inclusion in
980other document.
981
982Postscript file can easily be converted to other formats,
983PDF or image formats (jpeg \ldots) using converters like
984{\bf ps2pdf} or {imagemagick}.
985
986The menu items under \menubar{PostScript} can be used to export
987graphics in postscript. The default file name is {\tt pia.ps}
988or {\tt pia1.eps} {\tt pia2.eps} \ldots
989The following commands can also be used to create postscriot file
990from the display in the current graphic window:
991\begin{itemize}
992\item {\tt w2ps} \myppageref{w2ps} to add the current graphic
993output as a new page to the output postscript file.
994The current output postscript file (default = w2ps.ps)
995should be closed before being used. Exiting piapp closes automatically
996all postscript files.
997\item {\tt psclosefile} \myppageref{psclosefile} to close the current
998output postscript file.
999\item {\tt pssetfilename} \myppageref{pssetfilename} To define
1000the output postscript file name for the subsequent {\tt w2ps} commands.
1001\item {\tt w2eps} \myppageref{w2eps} to export the current
1002graphic display, in Encapsulated Postscript format to the specified file.
1003\begin{verbatim}
1004# Open the PPF file created by the commands above
1005openppf vecab.ppf
1006# Display one of the vectors
1007setaxesatt 'font=helvetica,bold,18 fixedfontsize'
1008disp va1 'blue marker=box,5'
1009# Export the graphic to file va1.eps
1010w2eps va1.eps
1011# The created file can be viewed using gv
1012\end{verbatim}
1013\end{itemize}
1014
[3041]1015%%%%%%%%%%%%%%% Section 5 : analyse a la paw
[2171]1016\newpage
[3438]1017\section{Tables and Expression Plotting}
[3043]1018\label{tableplot}
[3438]1019A powerful data analysis technic available in piapp is
10202D, 3D plot, and histogramming applied to arbitrary analytical
1021expression of table columns.
1022This analysis technic has been introduced by the popular
1023CERN \href{http://paw.web.cern.ch/paw/}{\bf PAW}
1024({\bf P}hysics {\bf A}nalysis {\bf Workstation})
1025\footnote{PAW home page : http://paw.web.cern.ch/paw/ } program
1026and the underlying HBOOK fortran library.
1027Compared to PAW, piapp extends in many respects this capability,
1028piapp offers in particular the possibility to manipulate many
1029objects as if they where a DataTable, or NTuple.
1030There are also additional 2D and 3D representations e.g.
1031{\tt plot2de} \myppageref{plot2de},
1032{\tt plot2dw} \myppageref{plot2dw},
1033{\tt plot2dc} \myppageref{plot2dc} and
1034{\tt plot3dw} \myppageref{plot3dw}.
[3041]1035
[3438]1036\subsection{How does it work ?}
1037
1038The Expression.Plotting commands in piapp operate on objects through the
1039{\bf NTupleInterface} class methods. Some classes like NTuple or BaseDataTable
1040inherit from NTupleInterface, while for the other classes, the corresponding
1041NObjMgrAdapter class exposes an object conforming to NTupleInterface through the
1042method : \\
1043\hspace*{5mm} {\tt NTupleInterface* NObjMgrAdapter::GetNTupleInterface()} \\
1044A C file (PIATmp\_xxx/expf\_pia\_dl.c) is created by piapp containing the
1045specified expressions, which should conform to the C-language syntax.
1046In addition to the functions in {\tt math.h} (sin, cos, log \ldots),
1047the following functions are defined by piapp and can be used:
1048\begin{itemize}
1049\item Flat random number generators: {\tt drand01() , drandpm1() }
1050\item Gaussian random number generator: {\tt GauRand() }
1051\item Angle conversion: {\tt deg2rad(double d), rad2deg(double r) }
1052\item $(\theta,\varphi)$ to Molleweide X,Y projection: \\
1053\hspace*{5mm}{\tt double tetphi2mollX(double theta, double phi)} \\
1054\hspace*{5mm}{\tt double tetphi2mollY(double theta)}
1055\item Longitude(0..360) deg., Latitude(-90..90) deg. conversion to Molleweide X,Y: \\
1056\hspace*{5mm}{\tt double longlat2mollX(double longit, double lat) } \\
1057\hspace*{5mm}{\tt double longlat2mollY(double lat) }
1058\end{itemize}
1059
1060The processing steps for an Expression.Plotting in piapp :
1061\begin{enumerate}
1062\item Creation of the C-file.
1063\item On the fly compilation of the generated file.
1064\item The resulting shared-object is loaded and linked with the application
1065\item Loop over the NTupleInterface object rows. The created function is called
1066with the data from each row
1067\item The return values are used to fill an histogram, or a matrix/vector or
1068another NTuple or to produce a 2D or 3D graphic display.
1069\end{enumerate}
1070
1071Although rather complex, the efficiency gain during processing data easily compensates
1072for the overhead of the compilation step.
1073
1074\subsection{Column/variable names}
1075
1076When working with real 2-D tables (NTuple, DataTable \ldots), the column names
1077are the name of the variables which can be used in the C-expressions.
1078There is an additional variable, called {\tt \_nl}, automatically
1079provided by piapp, corresponding the table row number, starting from 0.
1080
1081For the other objects in piapp, the variable names are listed below:
1082\begin{itemize}
1083\item[\rond] For 2D table objects {\bf (NTuple,DataTable,\ldots)}: ColumnNames,\_nl
1084\item[\rond] For FITS files opened through {\tt fitsadapt} command: FITSColumnNames,\_nl
1085\item[\rond] For {\bf Histo1D/HProf} objects : i,x,val,err,nb,\_nl
1086\item[\rond] For {\bf Histo2D} objects : i,j,x,y,val,err,\_nl
1087\item[\rond] For {\bf HistoErr} objects : i,x,val,err2,nb,\_nl
1088\item[\rond] For {\bf Histo2DErr} objects : i,j,x,y,val,err2,nb,\_nl
1089\item[\rond] For {\bf \tcls{TVector}, \tcls{TMatrix} , \tcls{Image} } objects : \\
1090 \hspace*{10mm} n,r,c,val,real,imag,mod,phas,\_nl
1091\item[\rond] For {\bf \tcls{TArray}} objects : n,x,y,z,t,u,val,real,imag,mod,phas,\_nl
1092\item[\rond] For {\bf GeneralFitData} objects : x0,ex0 x1,ex1 ... xn,exn y,ey ,ok,\_nl
1093\item[\rond] For {\bf \tcls{SphereHEALPix} , \tcls{SphereThetaPhi} , \tcls{SphereECP}
1094\tcls{LocalMap} } objects : \hspace{10mm} i,k,val,real,imag,mod,phas,teta,phi,\_nl
1095\end{itemize}
1096
[3041]1097%%%%%%%%%%%%%%% Section 6 : command interpreter
1098\newpage
1099\section{Command interpreter}
1100piapp uses the class {\bf PIACmd} which extends slightly the
1101SOPHYA class {\bf Commander} as the command interpreter.
1102{\bf Commander} is a c-shell inspired, string oriented command
1103interpreter. Although it has many limitations compared to
1104c-shell, or Tcl , it provides some interesting possibilities:
1105\begin{itemize}
1106\item Extended arithmetic operations (c-like and RPN)
1107\item Simple and vector variables
1108\item Script definition
1109\item Command execution in separate threads
1110\item Dynamic Load
1111\end{itemize}
1112
1113We describe below the {\bf Commander} possibilities,
1114as well as the few {\bf PIACmd} extensions.
1115
1116\subsection{Variables}
1117The SOPHYA::Commander interpreter manages non typed set of variables.
1118Environment variables are also accessible through
1119the usual {\tt \$varenvname}, unless shadowed by a Commander
1120variable. All Commander variables are vector of strings, and are
1121extended as necessary. {\tt \$varname} is the string formed by all
1122the vector elements. Except when performing arithmetic operations,
1123variables are treated as strings.
1124\par
1125An application level set of variables is also managed
1126by Commander, through redefinition of \\
[3043]1127{\tt Commander::GetVarApp() / GetVarApp() \ldots } methods. \\
[3041]1128The {\bf PIACmd} in piapp redefines the {\tt GetVarApp() }
1129in order to provide an easy access to some of objects attributes or methods,
[3043]1130managed by {\bf NamedObjMgr} (See below).
[3041]1131
[3438]1132\subsubsection{Interpreter/Commander variables}
[3041]1133\begin{itemize}
1134\item[\rond] {\bf Definition and initialisation of variables }
1135\begin{verbatim}
1136# Notice that the set command has no = sign
1137Cmd> set sv StringValue
1138# Clearing/removing of a variable : unset or clearvar
1139Cmd> unset sv
1140
1141# Definition of a multi element variable (vector type)
1142# Notice that spaces before / after '(' and ')' are mandatory
1143Cmd> set vecv ( mot1 mot2 mot3 mot4 mot5 )
[3429]1144# Arithmetic expression : C language syntax - spaces
1145# before/after '=' are mandatory
[3046]1146Cmd> a = 2+3*sqrt(4)
[3041]1147# The '=' operator can also be used to initialize a variable with a string
1148Cmd> a = 'Bonjour Madame'
1149# A vector element can be specified in the left hand side
1150Cmd> vecv[2] = 'coucou'
1151# Or using an interpreter variable as index :
1152Cmd> i = 3
1153Cmd> vecv[i] = 'Ooohhh'
1154\end{verbatim}
1155
1156On the right hand side, the value of a variable should be accessed using
1157the \$ character. \\
1158A string can be parsed into words using {\tt var2words}
1159\begin{verbatim}
1160Cmd> var2words varname wordvarname [separateur]
1161\end{verbatim}
1162
1163\item[\rond] {\bf Accessing variable contents } \\
1164The \$ character is used to access the content of a variable {\tt \$varname} .
1165Substitution rules :
1166The {\tt \$xxx} is replaced by the value of variable xxx.
1167No substitution is performed for strings enclosed in simple quotes {\tt ' ... \$xxx '},
1168but substitution is done in strings enclosed in double quotes.
1169Parenthesis or brackets can be used to specify the variable name, inside a string
1170without white space: {\tt \${vname} } ou {\tt \$(vname)}.
1171\begin{verbatim}
1172Cmd> x = 'Hello'
1173Cmd> echo $x
1174# Size of a vector variable : $#vname
1175Cmd> set vx ( 111 2222 3333 444444 )
1176Cmd> echo $#vx
1177# Accessing vector elements
1178Cmd> echo $vx[0] $vx[1]
1179# or using an interpreter variable as index :
1180Cmd> i = 2
1181Cmd> echo $vx[i]
1182# Special syntax: $[vname] is replaced by the content
1183# of a variable whose name is $vname
1184Cmd> zzz = 'Commander'
1185Cmd> xxx = 'zzz'
1186Cmd> echo '---> $[xxx]= ' $[xxx]
1187---> $[xxx]= Commander
1188\end{verbatim}
1189
1190\par
[3438]1191\end{itemize}
[3041]1192
[3438]1193\subsubsection{Special variables}
[3041]1194\begin{itemize}
1195\item {\tt \$retval} ou {\tt \$retstr} : the string specified in the last {\bf return} statement
1196\item {\tt \$status} : Return code from the last executed command.
1197Arguments of scripts (see below) or file executed through {\bf exec} command.
1198\item {\tt \$\# } : number of arguments, except \$0
1199\item {\tt \$0} : Script or file name
1200\item {\tt \$1 \$2 \$3} .... : Arguments (for scripts and .pic files (exec))
1201\end{itemize}
[3043]1202
[3438]1203\subsubsection{Environment variables}
1204Environment variables can simply be accessed by {\tt \$varenvname}.
1205However, the environment variables have the lowest priority during substitution.
1206Interpreter's variables have the highest priority, followed
1207by the application level variables.
1208
1209\subsubsection{Objects/Application level variables}
[3043]1210For some classes managed by NamedObjMgr,
1211PIACmd provide acces to some of the attributes of the object by
1212{\tt \${objname.attname} }. This mechanism has been implemented in particular for
1213TArrays, TMatrix/TVector, Histograms, NTuples and DataTables.
1214In addition, when brackets are used ($\${vname}$), the priority level between interpreter variables
1215and application level variable is changed. If {\tt vname} exist at the application level,
1216{\tt \${vname} } is replaced by its value, even if an interpreter variable with the
1217same name has been defined.
[3438]1218\begin{itemize}
1219\item[\rond] Accessing object attributes
[3043]1220\begin{verbatim}
1221# -------- Example with a Vector
1222piapp[1] newvec va 12
1223piapp[2] echo $va
1224TVector<d>(12) (nr=12, nc=1)
1225# ------- An undefined attribute, such as ? might be
1226# used to get list of valid attributes
1227piapp[3] echo ${va.?}
[3438]1228TMatrix.Att: rank size/nelts nrow/nrows ncol/ncols sum sumsq norm min ...
[3429]1229# Compound names, in the form name.att must be inclosed in
1230# braces {name.att}
[3043]1231piapp[4] echo ${va.size}
123212
1233# -------- Example with an histogram
1234piapp[8] newh1d his 0. 20. 40
1235piapp[10] echo ${his.?}
1236Histo1D: nbin binw mean sigma over under nentries ndata
1237 xmin xmax vmin vmax imin imax
1238piapp[11] echo ${his.nbin}
123940
1240\end{verbatim}
1241
[3438]1242\item[\rond] Accessing object.Info() \\
1243For objects having an DVList Info() object (TArray/TVector/TMatrix , NTuple, DataTable, SwPPFDataTable, it is possible to access DVList members by the corresponding names : \\
1244\hspace*{10mm} {\tt \$\{objName.info.varName\} }
1245\item[\rond] Getting DataTable rows \\
1246For NTuple and BaseDataTable objects (DataTable, SwPPFDataTable, SwFitsDataTable), it is
1247possible to get a string representation of a given row, by specifying
1248\$\{tableName.row\} followed by the row number (starting from 0) : \\
1249\hspace*{10mm} {\tt \$\{tableName.row.num\} }
1250\end{itemize}
[3043]1251
[3041]1252
[3043]1253
[3041]1254\subsection{Control structures}
1255
1256\begin{itemize}
1257\item[\rond] Enumerated loop:
1258\begin{verbatim}
1259foreach f ( w1 w2 w3 ... )
1260 ...
1261 echo $f
1262end
1263\end{verbatim}
1264
1265Note that spaces before/after '(' et and ')' are mandatory.
1266An alternative form uses a vector variable name :
1267\begin{verbatim}
1268foreach v vecname
1269 ...
1270 echo $v
1271end
1272\end{verbatim}
1273
1274\item[\rond] Integer type loop:
1275\begin{verbatim}
1276for i startInt:endInt[:stepInt]
1277 ....
1278 echo $i
1279end
1280\end{verbatim}
1281
1282\item[\rond] Integer type loop:
1283\begin{verbatim}
1284for f startFloat:endFloat[:stepFloat]
1285 ....
1286 echo $f
1287end
1288\end{verbatim}
1289
1290\item[\rond] Loop over lines of a file
1291\begin{verbatim}
1292forinfile line FileName
1293 ...
1294 echo $line
1295end
1296\end{verbatim}
1297
1298\item[\rond] The {\tt break} instruction can be used to exit from a loop
1299
1300\item[\rond] {\bf if then else} Conditional execution:
1301\begin{verbatim}
1302if ( test ) then
1303endif
1304
1305if ( test ) then
1306 ....
1307else
1308 ....
1309endif
1310\end{verbatim}
1311Note that spaces before/after '(' et and ')' are mandatory.
1312
1313test is in the form {\tt a == b} OR {\tt a != b} OR {\tt a < b} OR {\tt a > b}
1314OR {\tt a <= b} OR {\tt a >= b}. Comparison operators should be delimited
1315by spaces.
1316{\tt ==} et {\tt !=} make a string comparison, while
1317{\tt < , > , <= , >=} compare the values obtained after string to double conversion.
1318\end{itemize}
1319
1320\subsection{Script definition}
1321A script is a sequence of commands. It is very similar to the execution of commands
1322from a file ({\bf exec filename}). Once a script has been defined, it can be called specifying
1323specifying the script name followed by its arguments.
1324\begin{verbatim}
1325# Script definition :
1326defscript scriptname [description ]
1327 ....
1328endscript
1329
1330# Executing the script
1331Cmd> scriptname arg1 arg2 arg3 ....
1332\end{verbatim}
1333
1334The {\tt return} instruction stops the execution and returns from a script, or from a command
1335file called through {\bf exec}. \\
1336The commands {\bf listscript } and {\bf clearscript scriptname} can be used
1337to obtain the list of already defined script, or to clear a script definition.
1338
1339\subsection{Other built-in commands}
1340\begin{itemize}
1341\item[\rond] Instruction {\bf echo } to write the line to cout/stdout
1342\item[\rond] Instruction {\bf echo2file} to write (append) the line to file ({\tt echo2file filename ....})
1343\item[\rond] Instruction {\bf sleep nsec} wait for {\tt nsec} seconds
1344\item[\rond] Instructions {\bf timingon , timingoff , traceon , traceoff } \\
1345%
1346\item[\rond] {\bf exec filename [arg1 arg2 ... ] } to execute command from
1347the file named {\tt filename}. {\tt .pic} is the default extension for the interpreter
1348command files.
1349\item[\rond] {\bf help} and {help keyword/commandname }
1350\item[\rond] {\bf listvars , listcommands } to print the list of defined variables and known
1351commands
1352\item[\rond] An alias for a command by {\bf alias aliasname 'string ' }. Alias substitution
1353occurs for the first word in a command line. {\bf listalias} prints the list of all
1354defined aliases.
1355\item[\rond] Execution control (piapp/PIACmd extension):
1356It is possible to stop the interpreter execution in a loop, a script or
1357a command file by the {\bf stop} command, or using
1358 {\tt <Cntrl C>} in the piapp console (PIConsole) \\
1359\end{itemize}
1360
1361\subsection {Command execution in separate threads}
1362It is possible to create new threads to execute commands
1363( for non built-in interpreter commands). The syntax is similar
1364to unix shell background tasks: an {\&} should be added at the end
1365of the command line. A new thread is then created for the
1366execution of the command, if declared as thread safe \\
1367(see {\tt CmdExecutor::IsThreadable() }.
1368\par
1369Thread management commands:
1370\begin{itemize}
1371\item[\rond] {\bf thrlist }Print current list of threads, with the associated command
1372the thread identifier (integer ThrId) and its status.
1373\item[\rond] {\bf cleanthrlist } Removes all finished threads from the list.
1374An automatic cleanup is performed periodically.
1375\item[\rond] {\bf cancelthr ThId } / {\bf killthr ThId } Stops/kills the thread with
1376the identifier ThId. Avoid using theses commands as the cleanup does
1377not release some resources associated with
1378the thread (memory, mutex \ldots).
1379\end{itemize}
1380
[3438]1381Executing commands in a separate thread is useful for CPU or data intensive
1382commands. Most {\bf Expr.Plotting}
1383(plot2d, plot2dw, plot2de, plot3d, ntloop, fillvec, fillmtx \ldots)
1384and some of the {\bf pawCmd} (n/plot n/proj) are thread safe. However, due to the
1385current mutex lock management for these Expr.Plotting/pawCmd commands, only one
1386such command can run concurrently with other piapp threads.
1387Some of the commands in the {\bf CxxExecutorCmd} (
1388c++exec, c++execfrf, c++create, c++createfrf, c++compile, c++link) are also thread safe.
1389The same remark concerning lock management applies to these commands, while
1390CxxExecutorCmd commands can run in parallel with Expr.Plotting commands.
1391
1392
[3041]1393%%%%%%%%%%%%%%% Section 7 : c++ execution
1394\newpage
1395\section{On the fly C++ execution}
1396
1397%%%%%%%%%%%%%%% Section 8 : command reference
1398\newpage
[2171]1399\section{piapp command reference}
[2253]1400\label{piappcmdref}
[2171]1401This section contains the description of piapp commands. This information
1402is available on-line, through the help command, or through a graphic
[3041]1403window, accessible by \menubar{File / Help}.
[2171]1404The help items and command are divided into different sections,
1405where related commands are grouped. \\[10mm]
1406
1407% \include{piahelp}
1408\input{piahelp.tex}
1409
1410% La partie des appendix
1411\appendix
1412\newpage
[3041]1413\section{Interactive control windows}
1414\subsection{DrawerTools} \index{DrawerTools}
[2171]1415\label{secdrwtools}
1416The {\bf PIDrawerTools}, shown in the figure \ref{figdrwtools} can be
1417used to change the graphic attributes (color, font, marker, \ldots)
1418of the Drawers displayed in 2D displays
1419({\bf PIScDrawWdg} \myppageref{PIScDrawWdg}) or 3D displays
1420({\bf PIDraw3DWdg} \myppageref{PIDraw3DWdg}), as well in image displays
1421{\bf PIImage} (\myppageref{PIImage}). The PIDrawerTools can be activated
1422either using {\tt Alt<G>} on a PIScDrawWdg,PIDraw3DWdg,PIImage,
[3043]1423or through the \menubar{Tools/Show DrawerTools}.
1424A given drawer can be selected through the DrawerId selector (+ / - buttons)
[2171]1425
[3041]1426\vspace*{5mm}
[2171]1427\begin{figure}[ht!]
1428\begin{center}
[3043]1429\includegraphics[width=8cm]{piapp_drwtools.eps}
[2171]1430\caption{PIDrawerTools}
1431\label{figdrwtools}
1432\end{center}
1433\end{figure}
[3041]1434%%%%
1435\subsection{AxesTools} \index{AxesTools}
[2171]1436\label{secaxestools}
1437The {\bf PIAxesTools}, shown in the figure \ref{figaxestools} can be used to
1438control and change the setting of axes on 2D displays
1439({\bf PIScDrawWdg} \myppageref{PIScDrawWdg}).
1440The PIAxesTools can be activated
1441either using {\tt Alt<A>} on a PIScDrawWdg or through
[3043]1442the \menubar{Tools/Show AxesTools}.
[2171]1443
[3041]1444\vspace*{5mm}
[2171]1445\begin{figure}[ht!]
1446\begin{center}
1447\includegraphics[width=8cm]{piapp_axestools.eps}
1448\caption{PIAxesTools}
1449\label{figaxestools}
1450\end{center}
1451\end{figure}
[3041]1452%%%%%
[3043]1453\subsection{ImageTools} \index{ImageTools}
[2171]1454\label{secimagetools}
1455The {\bf PIImageTools}, shown in the figure \ref{figimgtools} can be used to
1456manipulate a display of type image. Image display are handled by the
1457{\bf PIImage} (\myppageref{PIImage}). The PIImageTools can be activated
[3043]1458either using {\tt Alt<O>} on a PIImage, or through the
1459\menubar{Tools/Show ImageTools}.
[2171]1460
[3041]1461\vspace*{5mm}
[2171]1462\begin{figure}[ht!]
1463\begin{center}
1464\includegraphics[width=8cm]{piapp_imgtools.eps}
1465\caption{PIImageTools}
1466\label{figimgtools}
1467\end{center}
1468\end{figure}
1469
[3041]1470\subsection{Histo2DTools} \index{Histo2DTools}
[2171]1471\label{sech2dtools}
1472The {\bf PIHisto2DTools}, shown in the figure \ref{figh2dtools} can be
1473used to control and change the display caracteristics of 2D histograms.
[2253]1474PIHisto2DTools can be activated
[2171]1475either using {\tt Alt<O>} on a PIScDrawWdg, when the active
1476drawer is a PIHisto2DDrawer, or through the generic drawer tool
1477PIDrawerTools.
1478
[3041]1479\vspace*{5mm}
[2171]1480\begin{figure}[ht!]
1481\begin{center}
1482\includegraphics[width=8cm]{piapp_h2dtools.eps}
1483\caption{PIHisto2DTools}
1484\label{figh2dtools}
1485\end{center}
1486\end{figure}
1487
[3041]1488\subsection{ContourTools} \index{ContourTools}
[2171]1489\label{secconttools}
1490The {\bf PIContourTools}, shown in the figure \ref{figconttools} can be
1491used to control and change the caracteristics of contour displays.
[2253]1492PIContourTools can be activated
[2171]1493either using {\tt Alt<O>} on a PIScDrawWdg, when the active
1494drawer is a PIContDrawer, or through the generic drawer tool
1495PIDrawerTools.
1496
1497\vspace*{10mm}
1498\begin{figure}[ht!]
1499\begin{center}
1500\includegraphics[width=11cm]{piapp_conttools.eps}
1501\caption{PIContourTools}
1502\label{figconttools}
1503\end{center}
1504\end{figure}
1505
1506
[2253]1507
1508Both drawing options (e.g. color, line type, fonts...) and contour
1509determination parameters (e.g. contour number and levels) are controlled
1510by {\bf PIContourTools}.
1511
[3041]1512\subsubsection{Drawing options}
[2253]1513The top choices in {\bf PIContourTools}
1514concern the color map (left choice) or color (right choice) of the contours.
1515If a color map has been chosen, it is used to give each contour a color
1516(according to its level). If no color map has been chosen, contours may be
1517given a color using the left choice box.
1518
1519Contour are by default traced by lines.
1520Alternatively (or in addition) the user may ask to trace them by markers
1521or to put numeric labels (with the contour's level) aside the contour.
1522These options are enabled/disabled by the {\tt LineON}, {\tt MarkerON} and {\tt LabelON}
1523buttons from {\bf PIContourTools}.
1524
1525Options may be recovered ({\tt GetAtt}) or set ({\tt SetAtt})
1526from/to a drawer. Setting an option which adds to the screen will be immediately visible
1527whereas unsetting it requires a {\tt Refresh} to be visible.
1528
1529
[3041]1530\subsubsection{Contour options}
[2253]1531The contouring routines in {\tt spiapp} are based on a hack of the {\tt GNUPlot}
1532routines. Contours are determined from a grid of values
1533using an interpolation scheme. Three schemes may be used
1534(selected by the left menu) :
1535\begin{enumerate}
1536\item Linear interpolation (default), selected by the {\tt Int. Lin.} option
1537\item A cubic spline algorithm, selected by the {\tt CubicSpl} option
1538\item A 2d BSpline algorihm, selected by the {\tt B-Spline} option
1539\end{enumerate}
1540
1541Contour levels and number are automatically
1542determined by the program. They may be specified differently,
1543 through command-line options
1544(see section \ref{piappcmdref} for the help of the contour/ntcont commands)
1545or the lower part of the {\bf PIContourTools} window.
1546
1547The user may specify one of the following alternatives :
1548\begin{enumerate}
1549\item the number of contour (their level beeing automatically set).
1550To do this, select {\tt LevelNum} in the right menu and enter the contour number
1551in the left box below.
1552\item the levels of the contours, through an array of numerical values
1553(e.g. 1,4,6,9,27,4.5 will result in 6 contour lines being drawn, if possible and necessary).
1554To do this, select {\tt LevelDisc} and enter the contour number (left box)
1555and the values (right box) separated by ``{\tt ,}''.
1556\item the levels of the contours through an initial (lower) value and an increment.
1557For this, select {\tt LevelInc} and enter the contour number (left box)
1558and the initial value and increment in the right box, as above.
1559\item come back to the default situation, by choosing {\tt LevelAuto}
1560\end{enumerate}
1561
1562Once these options are set, it is necessary the the program recomputes
1563the contour lines. This is commanded by the {\tt SetParm} button.
1564
1565
[2171]1566\newpage
1567\addcontentsline{toc}{section}{Index}
1568\printindex
1569
1570\end{document}
Note: See TracBrowser for help on using the repository browser.