source: Sophya/trunk/SophyaLib/Manual/sophya.tex@ 3085

Last change on this file since 3085 was 3061, checked in by cmv, 19 years ago

un oeu de texte cmv 14/8/2006

File size: 85.2 KB
Line 
1\documentclass[twoside,10pt]{article}
2% Package standard : Utilisation de caracteres accentues, mode francais et graphique
3\usepackage{url}
4\usepackage[latin1]{inputenc}
5\usepackage[T1]{fontenc}
6\usepackage[english]{babel}
7\usepackage{graphicx}
8% package a mettre pour faire du pdf
9\usepackage{palatino}
10
11% Extension de symboles mathematiques
12\usepackage{amssymb}
13
14% Definition pour Docs Sophya
15\usepackage{defsophya}
16
17% Constitution d'index
18\usepackage{makeidx}
19
20\usepackage[ps2pdf,bookmarks,bookmarksnumbered,%
21 urlcolor=blue,citecolor=blue,linkcolor=blue,%
22 pagecolor=blue,%hyperindex,%
23 colorlinks=true,hyperfigures=true,hyperindex=true
24 ]{hyperref}
25
26\makeindex % Constitution d'index
27
28\newcommand{\rond}{$\bullet \ $}
29\newcommand{\etoile}{$\star \ $}
30\newcommand{\cercle}{$\circ \ $}
31\newcommand{\carre}{$\Box \ $}
32
33
34\begin{document}
35
36\begin{titlepage}
37% The title page - top of the page with the title of the paper
38\titrehp{Sophya \\ An overview }
39% Authors list
40\auteurs{
41R. Ansari & ansari@lal.in2p3.fr \\
42E. Aubourg & aubourg@hep.saclay.cea.fr \\
43G. Le Meur & lemeur@lal.in2p3.fr \\
44C. Magneville & cmv@hep.saclay.cea.fr \\
45S. Henrot-Versille & versille@in2p3.fr
46}
47% \auteursall
48% The title page - bottom of the page with the paper number
49\vspace{1cm}
50\begin{center}
51{\bf \Large Sophya Version: 2.0 (V\_Jul2006) }
52\end{center}
53\titrebp{1}
54\end{titlepage}
55
56\tableofcontents
57
58\newpage
59
60\section{Introduction}
61
62{\bf SOPHYA} ({\bf SO}ftware for {\bf PHY}sics {\bf A}nalysis)
63is a collection of C++ classes designed for numerical and
64physics analysis software development. Our goal is to provide
65easy to use, yet powerful classes which can be used by scientists.
66Although some of the SOPHYA modules (SkyMap, Samba, SkyT)
67have been designed with the specific goal of CMB data analysis, most
68modules presented here have a much broader scope and can be
69used in scientific data analysis and modeling/simulation.
70Whenever possible, we use existing numerical packages and libraries,
71encapsulating them in classes in order to facilitate their usage.
72\par
73Our main requirements in designing SOPHYA classes can be summarized as
74follow:
75\begin{itemize}
76\item[\rond] Provide a comprehensive set of data containers, such as arrays and tables
77(tuple) covering the most common needs in scientific simulation and data analysis
78softwares.
79\item[\rond] Take advantage of the C++ language and define methods and operators
80for most basic operation, such as arithmetic operations, in a rather intuitive way, while
81maintaining performances comparable to low level coding in other languages
82(C, Fortran, F90 \ldots)
83\item[\rond] Simplify memory management for programmers using the class library.
84This has been a strong requirement for most SOPHYA classes. Automatic reference
85sharing and memory management is implemented in SOPHYA classes intended
86for large size objects. We recommend to allocate SOPHYA objects on the stack,
87including when objects are returned by methods or functions.
88See section \ref{memgt} for more information.
89\item[\rond] Archiving, importing (reading) and exporting (writing) data in a
90efficient and consistent way is a major concern in many scientific software
91and projects. SOPHYA provide a native data I/O or persistence system,
92(PPF, \ref{ppfdesc}) as well as import/export services for ASCII and FITS formats.
93\end{itemize}
94
95% \vspace*{2mm}
96This documents
97presents only a brief overview of the class library,
98mainly from the user's point of view. A more complete description
99can be found in the reference manual, available from the SOPHYA
100web site: % {\bf http://www.sophya.org}.
101\href{http://www.sophya.org}{http://www.sophya.org}.
102%%%
103%%%
104\subsection{SOPHYA modules}
105\label{sopmodules}
106The source directory tree
107\footnote{ CVS: cvsserver.lal.in2p3.fr:/exp/eros/CVSSophya}
108is organised into a number of modules.
109
110\begin{itemize}
111\item[] {\bf BuildMgr/} Scripts for code management,
112makefile generation and software installation
113\item[] {\bf BaseTools/} General architecture support classes such
114as {\tt PPersist, NDataBlock<T>}, and few utility classes
115such as the dynamic variable list manager ({\tt DVList}) as well
116as the basic set of exception classes used in SOPHYA.
117\item[] {\bf TArray/} template numerical arrays, vectors and matrices \\
118({\tt TArray<T> TMatrix<T> TVector<T> } \ldots)
119\item[] {\bf NTools/} Some standard numerical analysis tools
120(linear, and non linear parameter fitting, FFT, \ldots)
121\item[] {\bf HiStats/} Histogram-ming and data set handling classes (tuples) \\
122({\tt Histo Histo2D NTuple DataTable} \ldots)
123\item[] {\bf SkyMap/} Local and full sky maps, and some 3D geometry
124handling utility classes. \\
125({\tt PixelMap<T>, LocalMap<T>, SphericalMap<T>, \ldots})
126\item[] {\bf SUtils/} This module contains few utility classes, such as the
127{\tt DataCard} class, as well as string manipulation functions in C and C++.
128\item[] {\bf SysTools/} This module contains classes implementing
129an interface to various OS specific services, such
130threads and dynamic link/shared library handling.
131
132\end{itemize}
133
134The modules listed below are more tightly related to the
135CMB (Cosmic Microwave Background) data analysis problem:
136\begin{itemize}
137\item[] {\bf SkyT/}
138classes for spectral emission and detector frequency response modelling \\
139({\tt SpectralResponse, RadSpectra, BlackBody} \ldots)
140\item[] {\bf Samba/} Spherical harmonic analysis, noise generators \ldots
141\end{itemize}
142
143The following modules contain the interface classes with
144external libraries:
145\begin{itemize}
146\item[] {\bf FitsIOServer/} Classes for handling file input-output
147in FITS format using the cfitsio library.
148FITS is maintained by NASA and SAO and is available from: \\
149\href{http://heasarc.gsfc.nasa.gov/docs/software/fitsio/fitsio.html}
150{http://heasarc.gsfc.nasa.gov/docs/software/fitsio/fitsio.html}
151\item[] {\bf LinAlg/} Interface with Lapack linear algebra package.
152Lapack is a linear algebra package and can be downloaded from: \\
153\href{http://www.netlib.org/lapack/}{http://www.netlib.org/lapack/}
154\item[] {\bf IFFTW/} Interface with FFTW package (libfftw.a).
155FFTW is a package for performing Fourier transforms, written in C.
156Documentation and source code can be found at: \\
157\href{http://www.fftw.org/}{http://www.fftw.org/}
158\item[] {\bf XAstroPack/} Interface to some common astronomical
159computation libraries. Presently, this module uses an external library
160extracted from the {\bf Xephem } source code. The corresponding source
161code is also available from SOPHYA cvs repository, module {\bf XephemAstroLib}.
162Information on Xephem can be found at : \\
163\href{http://www.clearskyinstitute.com/xephem/}{http://www.clearskyinstitute.com/xephem/}
164\item[] {\bf MinuitAdapt/} Wrapper classes to CERN minimization routines (Minuit). \\
165\href{http://wwwinfo.cern.ch/asdoc/minuit/minmain.html}{http://wwwinfo.cern.ch/asdoc/minuit/minmain.html}
166
167\end{itemize}
168
169The following modules contain each a set of related programs using the
170SOPHYA library.
171\begin{itemize}
172\item[] {\bf Tests/} Simple test programs
173\item[] {\bf PrgUtil/} Various utility programs (runcxx, scanppf, scanfits, \ldots)
174\item[] {\bf PrgMap/} Programs performing operations on skymaps: projections,
175power spectrum in harmonic space, \ldots
176\item[] {\bf PMixer/} skymixer and related programs
177\end{itemize}
178
179As a companion to SOPHYA, the {\bf (s)piapp} interactive data analysis
180program is built on top of SOPHYA and the {\bf PI} GUI class library
181and application framework. The {\bf PI} ({\bf P}eida {\bf Interactive})
182development started in 1995, in the EROS \footnote{EROS: {\bf E}xp\'erience
183de {\bf R}echerche d'{\bf O}bjets {\bf S}ombres - http://eros.in2p3.fr}
184microlensing search collaboration, with PEIDA++ \footnote {PEIDA++:
185The EROS data analysis class library -
186http://www.lal.in2p3.fr/recherche/eros/PeidaDoc/}.
187The {\bf PI} documentation and the {\bf piapp} user's guide are available
188from \href{http://www.sophya.org}{http://www.sophya.org}.
189%\href{http://www.sophya.org}{http://www.sophya.org}.
190The {\bf PI} is organized as the following modules:
191\begin{itemize}
192\item[] {\bf PI/} Portable GUI class library and application development
193framework kernel.
194\item[] {\bf PIGcont/} Contour-plot drawing classes.
195\item[] {\bf PIext/} Specific drawers and adapters for SOPHYA objects,
196and the {\bf piapp} interactive data analysis framework.
197\item[] {\bf ProgPI/} interactive analysis tool main program and pre-loaded
198modules.
199\end{itemize}
200
201Modules containing examples and demo programs and scripts:
202\begin{itemize}
203\item[] {\bf Examples/} Sample SOPHYA codes and example programs and
204makefiles.
205\item[] {\bf DemoPIApp/} Sample scripts and programs for (s)piapp
206interactive analysis tools.
207\end{itemize}
208\newpage
209
210\section{Using Sophya}
211The organisation of SOPHYA directories and some of the associated
212utility programs are described in this section.
213Basic usage of Sophya classes is described in the following sections.
214Complete Sophya documentation can be found at our web site
215{\bf http://www.sophya.org}.
216
217\subsection{Directories, environment variables, configuration files}
218\label{directories}
219The environment variable {\bf SOPHYABASE} is used
220to define the path where the Sophya libraries and binaries are installed.
221\begin{itemize}
222\item \$SOPHYABASE/include : Include (.h) files
223\item \$SOPHYABASE/lib : Path for the archive libraries (.a)
224\item \$SOPHYABASE/slb: Shared library path (.so or .dylib on Darwin/MacOS)
225\item \$SOPHYABASE/exe : Path for binary program files
226\end{itemize}
227
228The directory { \tt \$SOPHYABASE/include/SophyaConfInfo/ } contains files
229describing the installed configuration of SOPHYA software.
230
231The file { \tt \$SOPHYABASE/include/machdefs.h } contains definitions
232(flags, typedef) used in SOPHYA, while some more specific flags,
233are found in { \tt \$SOPHYABASE/include/sspvflags.h }
234
235The file { \tt \$SOPHYABASE/include/sophyamake.inc } contains the
236compilation commands and flags used for building the software.
237Users can use most of compilation and link commands defined in this file:
238 {\tt \$CCOMPILE , \$CXXCOMPILE . \$CXXLINK \ldots}.
239 (See module Example).
240
241The configure script (BuildMgr/configure) creates the directory tree and the
242above files. It also copy (or create symbolic link) for all SOPHYA include
243files as well as symbolic links for external libraries
244include files path in {\tt \$SOPHYABASE/include} (FitsIO, FFTW, XAstro \ldots).
245
246Object files for each module are grouped in a static archive library
247by the build procedure (libXXX.a for module
248XXX, with XXX = BaseTools, TArray, HiStats, FitsIOServer \ldots).
249
250When shared libraries are build, all stand alone SOPHYA modules
251are grouped in {\tt libsophya.so}, {\tt libextsophya.so} contains
252the interface modules with external libraries {\bf (FitsIOServer, LinAlg \ldots)},
253while {\bf PI, PIext, PIGcont} modules are grouped in {\tt libPI.so}.
254Alternatively, it is possible to group all modules in a single shared
255library {\tt libAsophyaextPI.so} (See \ref{build})
256
257In order to use the shared libraries, the {\bf LD\_LIBRARY\_PATH} variable
258should contain the Sophya shared library path
259({\tt \$SOPHYABASE/slb}).
260On Silicon Graphics machines with IRIX64 operating system,
261the default SOPHYA configuration correspond to the 64 bit architecture.
262The environment variable { \bf LD\_LIBRARY64\_PATH } replace in
263this case the usual {\bf LD\_LIBRARY\_PATH} variable.
264On IBM machines with AIX, the {\bf LIBPATH} environment variables
265contains the shared libraries search path.
266
267When using the dynamic load services in SOPHYA ({\tt PDynLinkMgr}
268class), in runcxx or (s)piapp applications for example, the shared
269library search path must contain the current working directory (
270dot . in unix).
271
272\subsection{the runcxx program}
273\index{runcxx} \label{runcxx}
274{\bf runcxx} is a simple program which can be used to compile, link
275and run simple C++ programs. It handles the creation of a
276complete program file, containing the basic set C++ include files,
277the necessary include files for SOPHYA SysTools, TArray, HiStats
278and NTools modules, and the main program with exception handling.
279Other Sophya modules can be included using the {\tt -import} flag.
280Use of additional include files can be specified using the
281{\tt -inc} flag.
282\begin{verbatim}
283csh> runcxx -h
284 PIOPersist::Initialize() Starting Sophya Persistence management service
285SOPHYA Version 1.9 Revision 0 (V_Mai2005) -- May 31 2005 15:11:32 cxx
286 runcxx : compiling and running of a piece of C++ code
287 Usage: runcxx [-compopt CompileOptions] [-linkopt LinkOptions]
288 [-tmpdir TmpDirectory] [-f C++CodeFileName]
289 [-inc includefile] [-inc includefile ...]
290 [-import modulename] [-import modulename ...]
291 [-uarg UserArg1 UserArg2 ...]
292 if no file name is specified, read from standard input
293 modulenames: SkyMap, Samba, SkyT, FitsIOServer,
294 LinAlg, IFFTW, XAstroPack
295\end{verbatim}
296Most examples in this manual can be tested using runcxx. The
297example below shows how to compile, link and run a sample
298code.
299\begin{verbatim}
300// File example.icc
301Matrix a(3,3);
302a = IdentityMatrix(1.);
303cout << a ;
304// Executing this sample code
305csh> runcxx -f example.icc
306\end{verbatim}
307
308\subsection{the scanppf program}
309\index{scanppf} \label{scanppf}
310{\bf scanppf} is a simple SOPHYA application which can be used to check
311PPF files and list their contents. It can also provide the list of all registered
312PPF handlers.
313\begin{verbatim}
314csh> scanppf -h
315 PIOPersist::Initialize() Starting Sophya Persistence management service
316SOPHYA Version 2.0 Revision 0 (V_Jul2006) -- Jul 17 2006 14:13:27 cxx
317 Usage: scanppf [flags] filename
318 flags = -s -n -a0 -a1 -a2 -a3 -lh -lho -lmod
319 -s[=default} : Sequential reading of objects
320 -n : Object reading at NameTags
321 -a0...a3 : Tag List with PInPersist.AnalyseTags(0...3)
322 -lh : List PPersist handler classes
323 -lho : List PPersist handler and dataobj classes
324 -lmod : List initialized/registered modules
325\end{verbatim}
326
327\subsection{the scanfits program}
328\index{scanfits} \label{scanfits}
329{\bf scanfits} is a SOPHYA program using the FitsIOServer
330\footnote{FitsIOServer module uses the cfitsio library. scanfits has to be linked with
331with FitsIOServer module and cfitsio libraries, or libextsophya.so}
332module which can be used
333to analyse the content of FITS files. It can list the FITS headers, the appropriate
334SOPHYA-FITS handler (implementing {\tt FitsHandlerInterface}) class, and the list of
335all registered FITS handlers.
336\begin{verbatim}
337csh> scanfits -h
338 PIOPersist::Initialize() Starting Sophya Persistence management service
339SOPHYA Version 2.0 Revision 0 (V_Jul2006) -- Jul 17 2006 14:13:27 cxx
340 Usage: scanfits [flags] filename
341 flags = -V1 -lh -rd -header
342 -V1 : Scan using old (V1) code version
343 -lh : Print the list of registered handlers (FitsHandlerInterface)
344 -rd : try to read each HDU data using appropriate handler
345 -header : List header information
346\end{verbatim}
347
348\newpage
349
350\section{Copy constructor and assignment operator}
351\label{memgt}
352In C++, objects can be copied by assignment or by initialisation.
353Copying by initialisation corresponds to creating an object and
354initialising its value through the copy constructor.
355The copy constructor has its first argument as a reference, or
356const reference to the object's class type. It can have
357more arguments, if default values are provided.
358Copying by assignment applies to an existing object and
359is performed through the assignment operator (=).
360The copy constructor implements this for identical type objects:
361\begin{verbatim}
362class MyObject {
363public:
364 MyObject(); // Default constructor
365 MyObject(MyObject const & a); // Copy constructor
366 MyObject & operator = (MyObject const & a) // Assignment operator
367}
368\end{verbatim}
369The copy constructors play an important role, as they are
370called when class objects are passed by value,
371returned by value, or thrown as an exception.
372\begin{verbatim}
373// A function declaration with an argument of type MyObject,
374// passed by value, and returning a MyObject
375MyObject f(MyObject x)
376{
377 MyObject r;
378 ...
379 return(r); // Copy constructor is called here
380}
381// Calling the function :
382MyObject a;
383f(a); // Copy constructor called for a
384\end{verbatim}
385It should be noted that the C++ syntax is ambiguous for the
386assignment operator. {\tt MyObject x; x=y; } and
387{\tt MyObject x=y;} have different meaning.
388\begin{verbatim}
389MyObject a; // default constructor call
390MyObject b(a); // copy constructor call
391MyObject bb = a; // identical to bb(a) : copy constructor call
392MyObject c; // default constructor call
393c = a; // assignment operator call
394\end{verbatim}
395
396As a general rule in SOPHYA, objects which implements
397reference sharing on their data members have a copy constructor
398which shares the data, while the assignment operator copies or
399duplicate the data.
400
401\newpage
402\section{Module BaseTools}
403
404{\bf BaseTools} contains utility classes such as
405{\tt DVlist}, an hierarchy of exception classes for Sophya, a template
406class {\tcls{NDataBlock}} for handling reference counting on numerical
407arrays, as well as classes providing the services for implementing simple
408serialisation.
409\vspace*{5mm}
410
411\subsection{Initialisation}
412\index{SophyaInitiator}
413A number of actions have to be taken before
414some of the services provided by SOPHYA become operational. This is the case
415of SOPHYA persistence, as well as FITS I/O facilities.
416Initialisation of many SOPHYA modules is performed through an initialiser class,
417which inherits from {\bf SophyaInitiator}.
418\par
419Static instance of each initialiser class exist in the library and the various SOPHYA services
420should be operational when the user code ({\tt main()}) starts, except for
421modules in the second or third shared libraries
422({\tt libextsophya.so libPI.so}). Indeed, a problem related
423to the initialisation of shared libraries arises on some systems
424(Darwin/Mac OS X in particular) causing program crash at start-up,
425if static instance of initialiser class is present in the second shared library.
426The FitsIOServer module should thus be explicitly initialised in the user
427program.
428\par
429In cases where the run time loader does not perform correctly the static
430object initialisation, the initialiser class for the modules used in the
431program must be instanciated in the beginning of your main program: \\
432{\tt TArrayInitiator , HiStatsInitiator , SkyMapInitiator , FitsIOServer \ldots}
433%%%
434\subsection{SOPHYA persistence}
435\label{ppfdesc}
436\index{PPersist} \index{PInPersist} \index{POutPersist}
437\begin{figure}[hbt]
438\dclsa{PPersist}
439\dclsccc{PPFBinarIOStream}{PPFBinaryInputStream}{PInPersist}
440\dclscc{PPFBinaryOutputStream}{POutPersist}
441\caption{partial class diagram for classes handling persistence in Sophya}
442\end{figure}
443A simple persistence mechanism is defined in SOPHYA. Its main
444features are:
445\begin{itemize}
446\item[] Portable file format, containing the description of the data structures
447and object hierarchy. \\
448{\bf PPF} {\bf P}ortable {\bf P}ersistence file {\bf F}ormat.
449\index{PPF}
450\item[] Handling of read/write for multiply referenced objects.
451\item[] All write operations are carried using sequential access only. This
452holds also for read operations, unless positional tags are used.
453SOPHYA persistence services can thus be used to transfer objects
454through network links.
455\item[] The serialisation (reading/writing) for objects for a given class
456is implemented through a handler object. The handler class inherits
457from {\tt PPersist} class.
458\item[] A run time registration mechanism is used in conjunction with
459RTTI (Run Time Type Identification) for identifying handler classes
460when reading {\bf PInPersist} streams, or for associating handlers
461with data objects {\bf AnyDataObject} for write operations.
462\end{itemize}
463A complete description of SOPHYA persistence mechanism and guidelines
464for writing delegate classes for handling object persistence is beyond
465the scope of this document. The most useful methods for using Sophya
466persistence are listed below:
467\begin{itemize}
468\item[] {\tt POutPersist::PutObject(AnyDataObj \& o)} \\
469Writes the data object {\bf o} to the output stream.
470\item[] {\tt POutPersist::PutObject(AnyDataObj \& o, string tagname)} \\
471Writes the data object {\bf o} to the output stream, associated with an
472identification tag {\bf tagname}.
473\item[] {\tt PInPersist::GetObject(AnyDataObj \& o)} \\
474Reads the next object in stream into {\bf o}. An exception is
475generated for incompatible object types.
476\item[] {\tt PInPersist::GetObject(AnyDataObj \& o, string tagname)} \\
477Reads the object associated with the tag {\bf tagname} into {\bf o}.
478An exception is generated for incompatible object types.
479\end{itemize}
480The operators {\tt operator << (POutPersist ...) } and
481{\tt operator >> (PInPersist ...) } are often overloaded
482to perform {\tt PutObject()} and {\tt GetObject()} operations.
483the {\bf PPFNameTag} (ppfnametag.h) class can be used in conjunction with
484{\tt << >> } operators to write objects with a name tag or to retrieve
485an object identified with a name tag. The example below shows the
486usage of these operators:
487\begin{verbatim}
488// Creating and filling a histogram
489Histo hw(0.,10.,100);
490...
491// Writing histogram to a PPF stream
492POutPersist os("hw.ppf");
493os << PPFNameTag("myhisto") << hw;
494
495// Reading a histogram from a PPF stream
496PInPersist is("hr.ppf");
497is >> PPFNameTag("myhisto") >> hr;
498\end{verbatim}
499
500The {\bf scanppf} program can be used to list the content of a PPF file.
501
502\subsection{\tcls{NDataBlock}}
503\index{\tcls{NDataBlock}}
504\begin{figure}[hbt]
505\dclsbb{AnyDataObj}{\tcls{NDataBlock}}
506\dclsbb{PPersist}{\tcls{FIO\_NDataBlock}}
507\end{figure}
508The {\bf \tcls{NDataBlock}} is designed to handle reference counting
509and sharing of memory blocs (contiguous arrays) for numerical data
510types. Initialisation, resizing, basic arithmetic operations, as
511well as persistence handling services are provided.
512The persistence handler class ({\tt \tcls{FIO\_NDataBlock}}) insures
513that a single copy of data is written for multiply referenced objects,
514and the data is shared among objects when reading.
515\par
516The example below shows writing of NDataBlock objects through the
517use of overloaded operator $ << $ :
518\begin{verbatim}
519#include "fiondblock.h"
520// ...
521POutPersist pos("aa.ppf");
522NDataBlock<r_4> rdb(40);
523rdb = 567.89;
524pos << rdb;
525// We can also use the PutObject method
526NDataBlock<int_4> idb(20);
527idb = 123;
528pos.PutObject(idb);
529\end{verbatim}
530The following sample programs show the reading of the created PPF file :
531\begin{verbatim}
532PInPersist pis("aa.ppf");
533NDataBlock<r_4> rdb;
534pis >> rdb;
535cout << rdb;
536NDataBlock<int_4> idb;
537cout << idb;
538\end{verbatim}
539
540\subsection{DVList, MuTyV and TimeStamp classes}
541\index{DVList} \index{MuTyV} \index{TimeStamp}
542\begin{figure}[hbt]
543\dclsa{MuTyV}
544\dclsbb{AnyDataObj}{DVList}
545\dclsbb{PPersist}{\tclsc{ObjFileIO}{DVList}}
546\end{figure}
547The {\bf DVList} class objects can be used to create and manage list
548of values, associated with names. A list of pairs of (MuTyV, name(string))
549is maintained by DVList objects. {\bf MuTyV} is a simple class
550capable of holding string, integer, float or complex values,
551providing easy conversion methods between these objects.
552{\bf MuTyV} objects can also hold {\bf TimeStamp } objects.
553\begin{verbatim}
554// Using MuTyV objects
555MuTyV s("hello"); // string type value
556MuTyV x;
557x = "3.14159626"; // string type value, ASCII representation for Pi
558double d = x; // x converted to double = 3.141596
559x = 314; // x contains the integer value = 314
560// Using DVList
561DVList dvl;
562dvl("Pi") = 3.14159626; // float value, named Pi
563dvl("Log2") = 0.30102999; // float value, named Log2
564dvl("FileName") = "myfile.fits"; // string value, named myfile.fits
565// Printing DVList object
566cout << dvl;
567\end{verbatim}
568
569\begin{figure}[hbt]
570\dclsbb{AnyDataObj}{TimeStamp}
571\end{figure}
572%
573The {\bf TimeStamp} class represent date and time and provides
574many standard operations, such as Initialisation from strings,
575conversion to strings and time interval computations. \\
576Usage example:
577\begin{verbatim}
578// Create a object with the current date and time and prints it to cout
579TimeStamp ts;
580cout << ts << endl;
581// Create an object with a specified date and time
582TimeStamp ts2("01/01/1905","00:00:00");
583// Get the number of days since 0 Jan 1901
584cout << ts2.ToDays() << endl;
585
586// Combined use of TimeStamp and MuTyV
587string s;
588TimeStamp ts; // Current date/time
589MuTyV mvt = ts;
590s = mvt; // s contains the current date in string format
591cout << s << endl;
592\end{verbatim}
593
594\subsection{\tcls{SegDataBlock} , \tcls{SwSegDataBlock}}
595\index{\tcls{SegDataBlock}} \index{\tcls{SwSegDataBlock}}
596%%
597\begin{figure}[hbt]
598\dclsccc{AnyDataObj}{\tcls{SegDBInterface}}{ \tcls{SegDataBlock} }
599\dclscc{\tcls{SegDBInterface}}{ \tcls{SwSegDataBlock} }
600\end{figure}
601\begin{itemize}
602\item[] \tcls{SegDataBlock} handles arrays of object of
603type {\bf T} with reference sharing in memory. The array can be extended
604(increase in array size) with fixed segment size. It implements the interface
605defined by \tcls{SegDBInterface}.
606\item[] \tcls{SwSegDataBlock} Implements the same \tcls{SegDBInterface}
607using a data swapper object. Data swappers implement the interface defined in
608(\tcls{DataSwapperInterface} class. \tcls{SwSegDataBlock} can
609thus be used to handle arrays with very large number of objects.
610These classes handles reference sharing.
611\end{itemize}
612
613\newpage
614\section{Module TArray}
615\index{\tcls{TArray}}
616{\bf TArray} module contains template classes for handling standard
617operations on numerical arrays. Using the class {\tt \tcls{TArray} },
618it is possible to create and manipulate up to 5-dimension numerical
619arrays {\tt (int, float, double, complex, \ldots)}. The include
620file {\tt array.h} declares all the classes and definitions
621in module TArray. {\bf Array} is a typedef for arrays
622with double precision floating value elements. \\
623{\tt typedef TArray$<$r\_8$>$ Array ; }
624
625\begin{figure}[hbt]
626\dclsccc{AnyDataObj}{BaseArray}{\tcls{TArray}}
627\dclsbb{PPersist}{\tcls{FIO\_TArray}}
628\end{figure}
629
630The development of this module started around 1999-2000,
631after evaluation of a number of publicly available
632C++ array hadling packages, including TNT, Lapack++, Blitz++,
633as well as commercial packages from RogueWave (math.h++ \ldots).
634Most of these packages provide interesting functionalities, however,
635not any one package seemed to fulfill most of our requirements.
636\begin{itemize}
637\item Capability to handle {\bf large - multidimensional - dense}
638arrays, for numerical data types. Although we have used templates, for
639data type specialisation, the actual code, apart inline functions is
640not in header files. Instead, we use explicit instanciation, and the
641compiled code for the various numerical types of arrays is the
642library .
643\item The shape and size of the arrays can be defined and changed
644at run time. The classes ensure the memory management of the
645created objets, with reference sharing for the array data.
646The default behaviour of the copy constructor is to share the data,
647avoiding expensive memory copies.
648\item The package provides transparent management of sub-arrays
649and slices, in an intuitive way, somehow similar to what is
650available in Mathlab or Scilab.
651\item The memory organisation for arrays, specially matrices
652(row-major or column major) can be
653controled. This provide compatibility when using existing C or
654Fortran coded numerical libraries.
655\item The classes provide efficient methods to perform basic arithmetic
656and mathematical operations on arrays. In addition, operator overload
657provides intuitive programming for element acces and most basic
658arithmetic operations.
659\item Conversion can be performed between arrays with different
660data types. Copy and arithmetic operations can be done transparently
661between arrays with different memory organisation patterns.
662\item This module does not provide more complex operations
663such as FFT or linear algebra. Additional libraries are used, with interface
664classes for these operations.
665\item ASCII formatted I/O, for printing and read/write operations to/from text files.
666\item Efficient binary I/O for object persistence (PPF format), or import/export
667to other data formats, such as FITS are provided by helper or handler classes.
668\end{itemize}
669
670\subsection{Using arrays}
671\index{Sequence} \index{RandomSequence} \index{RegularSequence}
672\index{EnumeratedSequence}
673The example below shows basic usage of arrays, creation, initialisation
674and arithmetic operations. Different kind of {\bf Sequence} objects
675can be used for initialising arrays.
676
677\begin{figure}[hbt]
678\dclsbb{Sequence}{RandomSequence}
679\dclsb{RegularSequence}
680\dclsb{EnumeratedSequence}
681\end{figure}
682
683The example below shows basic usage of arrays:
684\index{\tcls{TArray}}
685\begin{verbatim}
686// Creating and initialising a 1-D array of integers
687TArray<int> ia(5);
688EnumeratedSequence es;
689es = 24, 35, 46, 57, 68;
690ia = es;
691cout << "Array<int> ia = " << ia;
692// 2-D array of floats
693TArray<r_4> b(6,4), c(6,4);
694// Initializing b with a constant
695b = 2.71828;
696// Filling c with random numbers
697c = RandomSequence();
698// Arithmetic operations
699TArray<r_4> d = b+0.3f*c;
700cout << "Array<float> d = " << d;
701\end{verbatim}
702
703The copy constructor shares the array data, while the assignment operator
704copies the array elements, as illustrated in the following example:
705\begin{verbatim}
706TArray<int> a1(4,3);
707a1 = RegularSequence(0,2);
708// Array a2 and a1 shares their data
709TArray<int> a2(a1);
710// a3 and a1 have the same size and identical elements
711TArray<int> a3;
712a3 = a1;
713// Changing one of the a2 elements
714a2(1,1,0) = 555;
715// a1(1,1) is also changed to 555, but not a3(1,1)
716cout << "Array<int> a1 = " << a1;
717cout << "Array<int> a3 = " << a3;
718\end{verbatim}
719
720\subsection{Arithmetic operations}
721The four usual arithmetic operators ({\bf + \, - \, * \, / }) are defined
722to perform constant addition, subtraction, multiplication and division.
723The three operators ({\bf + \, - \, / }) between two arrays of the same type
724are defined to perform element by element addition, subtraction
725and division. In order to avoid confusion with matrix multiplication,
726element by element multiplication is defined by overloading the
727operator {\bf \, \&\& \, }, as shown in the example below:
728\begin{verbatim}
729TArray<int_4> a(4,3), b(4,3), c , d, e;
730a = RegularSequence(1.,1.);
731b = RegularSequence(10.,10.);
732cout << a << b ;
733c = a && b;
734d = c / a;
735e = (c / b) - a;
736cout << c << d << e;
737\end{verbatim}
738
739\subsection{Matrices and vectors}
740\index{\tcls{TMatrix}} \index{\tcls{TVector}}
741\begin{figure}[hbt]
742\dclsccc{\tcls{TArray}}{\tcls{TMatrix}}{\tcls{TVector}}
743\end{figure}
744Vectors and matrices are 2 dimensional arrays. The array size
745along one dimension is equal 1 for vectors. Column vectors
746have {\tt NCols() = 1} and row vectors have {\tt NRows() = 1}.
747Mathematical expressions involving matrices and vectors can easily
748be translated into C++ code using {\tt TMatrix} and
749{\tt TVector} objects. {\bf Matrix} and {\bf Vector} are
750typedefs for double precision float matrices and vectors.
751The operator {\bf *} beteween matrices is redefined to
752perform matrix multiplication. One can then write: \\
753\begin{verbatim}
754 // We create a row vector
755 Vector v(1000, BaseArray::RowVector);
756 // Initialize values with a random sequence
757 v = RandomSequence();
758 // Compute the vector length (norm)
759 double norm = (v*v.Transpose()).toScalar();
760 cout << "Norm(v) = " << norm << endl;
761\end{verbatim}
762
763This module contains basic array and matrix operations
764such as the Gauss matrix inversion algorithm
765which can be used to solve linear systems, as illustrated by the
766example below:
767\begin{verbatim}
768#include "sopemtx.h"
769// ...
770// Creation of a random 5x5 matrix
771Matrix A(5,5);
772A = RandomSequence(RandomSequence::Flat);
773Vector X0(5);
774X0 = RandomSequence(RandomSequence::Gaussian);
775// Computing B = A*X0
776Vector B = A*X0;
777// Solving the system A*X = B
778Vector X;
779LinSolve(A, B, X);
780// Checking the result
781Vector diff = X-X0;
782cout << "X-X0= " << diff ;
783double min,max;
784diff.MinMax(min, max);
785cout << " Min(X-X0) = " << min << " Max(X-X0) = " << max << endl;
786\end{verbatim}
787
788{\bf Warning: } The operations defined in {\tt sopemtx.h}, such as
789matrix inversion and linear system solver use a basic Gauss pivot
790algorithm which are not adapted for large matrices ($>\sim 100x100$).
791The services provided in other modules, such as {\bf LinAlg} should
792be preferred in such cases.
793
794\subsection{Working with sub-arrays and Ranges}
795\index{Range}
796A powerful mechanism is included in array classes for working with
797sub-arrays. The class {\bf Range} can be used to specify range of array
798indexes in any of the array dimensions. Any regularly spaced index
799range can be specified, using the {\tt start} and {\tt end} index
800and an optional step (or stride). It is also possible to specify
801the {\tt start} index and the number of elements.
802\begin{itemize}
803\item {\bf Range::all()} {\tt = Range(Range::firstIndex(), Range::lastIndex())} \\
804return a Range objects representing all valid indexes along the
805corresponding axe.
806\item {\bf Range::first()} {\tt = Range(Range::firstIndex())} \\
807return a Range object representing the first valid index
808\item {\bf Range::last()} {\tt = Range(Range::lastIndex())}
809return a Range object representing the last valid index
810\item {\bf Range(idx)} represents a single index ({\bf = idx})
811\item {\bf Range(first, last)} represents the range of indices
812{\bf first} $\leq$ index $\leq$ {\bf last}.
813The static method {\tt Range::lastIndex()} can be used
814to specify the last valid index.
815\item {\bf Range(first, last, step)} represents the range of index
816which is equivalent to \\ {\tt for(index=first; index <= last; index += step) }
817\item { \bf Range (first, last, size, step) } the general form can be used
818to specify an index range, using the number of elements.
819It is possible to specify a range of index, ending with the last valid index.
820For example \\
821\hspace*{5mm}
822{\tt Range(Range::lastIndex(), Range::lastIndex(), 3, 2) } \\
823defines the index range: \hspace*{5mm} last-4, last-2, last.
824
825\begin{center}
826\begin{tabular}{ll}
827\hline \\
828\multicolumn{2}{c}{ {\bf Range} {\tt (start, end, size, step) } } \\[2mm]
829\hline \\
830{\bf Range} {\tt r(7); } & index range: \hspace{2mm} 7 \\
831{\bf Range} {\tt r(3,6); } & index range: \hspace{2mm} 3,4,5,6 \\
832{\bf Range} {\tt r(3,7,2); } & index range: \hspace{2mm} 3,5,7 \\
833{\bf Range} {\tt r(7,0,3,1); } & index range: \hspace{2mm} 7,8,9 \\
834{\bf Range} {\tt r(10,0,5,2); } & index range: \hspace{2mm} 10,12,14,16,18 \\[2mm]
835\hline
836\end{tabular}
837\end{center}
838\end{itemize}
839
840The method {\tt TArray<T>SubArray(Range ...)} can be used
841to extract subarrays and slices. The operator {\tt operator() (Range rx, Range ry ...)}
842is also overloaded for sub-array extraction.
843For matrices, {\tt TMatrix<T>::Row()} and {\tt TMatrix<T>::Column()}
844extract selected matrix rows and columns.
845
846The example illustrates the sub-array extraction using Range objects:
847\begin{verbatim}
848 // Creating and initialising a 2-D (6 x 4) array of integers
849 TArray<int> iaa(6, 4);
850 iaa = RegularSequence(1,2);
851 cout << "Array<int> iaa = \n" << iaa;
852 // We extract a sub-array - data is shared with iaa
853 TArray<int> iae = iaa(Range(1, Range::lastIndex(), 3) ,
854 Range::all(), Range::first() );
855 cout << "Array<int> iae=subarray(iaa) = \n" << iae;
856 // Changing iae elements changes corresponding iaa elements
857 iae = 0;
858 cout << "Array<int> iae=0 --> iaa = \n" << iaa;
859
860\end{verbatim}
861
862In the following example, a simple low-pass filter, on a one
863dimensional stream (Vector) has been written using sub-arrays:
864
865\begin{verbatim}
866// Input Vector containing a noisy periodic signal
867 Vector in(1024), out(1024);
868 in = RandomSequence(RandomSequence::Gaussian, 0., 1.);
869 for(int kk=0; kk<in.Size(); kk++)
870 in(kk) += 2*sin(kk*0.05);
871// Compute the output vector by a simple low pass filter
872 Vector out(1024);
873 int w = 2;
874 for(int k=w; k<in.Size()-w; k++)
875 out(k) = in(Range(k-w, k+w).Sum()/(2.*w+1.);
876\end{verbatim}
877
878\subsection{Input, Output}
879Arrays can easily be saved to, or restored from files in different formats.
880SOPHYA library can handle array I/O to ASCII formatted files, to PPF streams,
881as well as to files in FITS format.
882FITS format input/output is provided through the classes in
883{\bf FitsIOServer} module. Only arrays with data types
884supported by the FITS standard can be handled during
885I/O operations to and from FITS streams (See the FitsIOServer section
886for additional details).
887
888\subsubsection{PPF streams}
889
890SOPHYA persistence (PPF streams) handles reference sharing, and multiply
891referenced objects are only written once. A hierarchy of arrays and sub-arrays
892written to a PPF stream is thus completely recovered, when the stream is read.
893The following example illustrates this point:
894\begin{verbatim}
895{
896// Saving an array with a sub-array into a POutPersist file
897Matrix A(3,4);
898A = RegularSequence(10,5);
899// Create a sub-array of A
900Matrix AS = A(Range(1,2), Range(2,3));
901// Save the two arrays to a PPF stream
902POutPersist pos("aas.ppf");
903pos << A << AS;
904}
905{
906// Reading arrays from the previously created PPF file aas.ppf
907PInPersist pis("aas.ppf");
908Matrix B,BS;
909pis >> B >> BS;
910// BS is a sub-array of B, modifying BS changes also B
911BS(1,1) = 98765.;
912cout << " B , BS after BS(1,1) = 98765. "
913 << B << BS << endl;
914}
915\end{verbatim}
916The execution of this sample code creates the file {\tt aas.ppf} and
917its output is reproduced here. Notice that the array hierarchy is
918recovered. BS is a sub-array of B, and modifying BS changes also
919the corresponding element in B.
920\begin{verbatim}
921 B , BS after BS(1,1) = 98765.
922
923--- TMatrix<double>(NRows=3, NCols=4) ND=2 SizeX*Y*...= 4x3 ---
92410 15 20 25
92530 35 40 45
92650 55 60 98765
927
928--- TMatrix<double>(NRows=2, NCols=2) ND=2 SizeX*Y*...= 2x2 ---
92940 45
93060 98765
931\end{verbatim}
932
933\centerline{\bf Warning: }
934
935There is a drawback in this behaviour: only a single
936copy of an array is written to a file, even if the array is modified,
937without being resized and written to a PPF stream.
938\begin{verbatim}
939{
940POutPersist pos("mca.ppf");
941TArray<int_4> ia(5,3);
942ia = 8;
943pos << ia;
944ia = 16;
945pos << ia;
946ia = 32;
947pos << ia;
948}
949\end{verbatim}
950
951Only a single copy of the data is effectively written to the output
952PPF file, corresponding to the value 8 for array elements. When we
953read the three array from the file mca.ppf, the same array elements
954are obtained three times (all elements equal to 8):
955\begin{verbatim}
956{
957PInPersist pis("mca.ppf");
958TArray<int_4> ib;
959pis >> ib;
960cout << " First array read from mca.ppf : " << ib;
961pis >> ib;
962cout << " Second array read from mca.ppf : " << ib;
963pis >> ib;
964cout << " Third array read from mca.ppf : " << ib;
965}
966\end{verbatim}
967
968\subsubsection{ASCII streams}
969
970The {\bf WriteASCII} method can be used to dump an array to an ASCII
971formatted file, while the {\bf ReadASCII} method can be used to decode
972ASCII formatted files. Space or tabs are the possible separators.
973Complex numbers should be specified as a pair of comma separated
974real and imaginary parts, enclosed in parenthesis.
975
976\begin{verbatim}
977{
978// Creating array A and writing it to an ASCII file (aaa.txt)
979Array A(4,6);
980A = RegularSequence(0.5, 0.2);
981ofstream ofs("aaa.txt");
982A.WriteASCII(ofs);
983}
984{
985// Decoding the ASCII file aaa.txt
986ifstream ifs("aaa.txt");
987Array B;
988sa_size_t nr, nc;
989B.ReadASCII(ifs,nr,nc);
990cout << " Array B; B.ReadASCII() from file " << endl;
991cout << B ;
992}
993\end{verbatim}
994
995
996\subsection{Complex arrays}
997The {\bf TArray} module provides few functions for manipulating
998arrays of complex numbers (single and double precision).
999These functions are declared in {\tt matharr.h}.
1000\begin{itemize}
1001\item[\bul] Creating a complex array through the specification of the
1002real and imaginary parts.
1003\item[\bul] Functions returning arrays corresponding to real and imaginary
1004parts of a complex array: {\tt real(za) , imag(za) }
1005({\bf Warning:} Note that the present implementation does not provide
1006shared memory access to real and imaginary parts.)
1007\item[\bul] Functions returning arrays corresponding to the module,
1008phase, and module squared of a complex array:
1009 {\tt phase(za) , module(za) , module2(za) }
1010\end{itemize}
1011
1012\begin{verbatim}
1013 TVector<r_4> p_real(10, BaseArray::RowVector);
1014 TVector<r_4> p_imag(10, BaseArray::RowVector);
1015 p_real = RegularSequence(0., 0.5);
1016 p_imag = RegularSequence(0., 0.25);
1017 TVector< complex<r_4> > zvec = ComplexArray(p_real, p_imag);
1018 cout << " :: zvec= " << zvec;
1019 cout << " :: real(zvec) = " << real(zvec) ;
1020 cout << " :::: imag(zvec) = " << imag(zvec) ;
1021 cout << " :::: module2(zvec) = " << module2(zvec) ;
1022 cout << " :::: module(zvec) = " << module(zvec) ;
1023 cout << " :::: phase(zvec) = " << phase(zvec) ;
1024\end{verbatim}
1025
1026The decoding of complex numbers from an ASCII formatted stream
1027is illustrated by the next example. As mentionned already,
1028complex numbers should be specified as a pair of comma separated
1029real and imaginary parts, enclosed in parenthesis.
1030
1031\begin{verbatim}
1032csh> cat zzz.txt
1033(1.,-1) (2., 2.5) -3. 12.
1034-24. (-6.,7.) 14.2 (8.,64.)
1035
1036// Decoding of complex numbers from an ASCII file
1037// Notice that the << operator can be used instead of ReadASCII
1038TArray< complex<r_4> > Z;
1039ifstream ifs("zzz.txt");
1040ifs >> Z;
1041cout << " TArray< complex<r_4> > Z from file zzz.txt " << Z ;
1042\end{verbatim}
1043
1044
1045\subsection{Memory organisation}
1046{\tt \tcls{TArray} } can handle numerical arrays with various memory
1047organisation, as long as the spacing (steps) along each axis is
1048regular. The five axis are labeled X,Y,Z,T,U. The examples below
1049illustrates the memory location for a 2-dimensional, $N_x=4 \times N_y=3$.
1050The first index is along the X axis and the second index along the Y axis.
1051\begin{verbatim}
1052 | (0,0) (0,1) (0,2) (0,3) |
1053 | (1,0) (1,1) (1,2) (1,3) |
1054 | (2,0) (2,1) (2,2) (2,3) |
1055\end{verbatim}
1056In the first case, the array is completely packed
1057($Step_X=1, Step_Y=N_X=4$), with zero offset,
1058while in the second case, $Step_X=2, Step_Y=10, Offset=10$:
1059\begin{verbatim}
1060 | 0 1 2 3 | | 10 12 14 16 |
1061Ex1 | 4 5 6 7 | Ex2 | 20 22 24 26 |
1062 | 8 9 10 11 | | 30 32 34 36 |
1063\end{verbatim}
1064
1065For matrices and vectors, an optional argument ({\tt MemoryMapping})
1066can be used to select the memory mapping, where two basic schemes
1067are available: \\
1068{\tt CMemoryMapping} and {\tt FortranMemoryMapping}. \\
1069In the case where {\tt CMemoryMapping} is used, a given matrix line
1070is packed in memory, while the columns are packed when
1071{\tt FortranMemoryMapping} is used. The first index when addressing
1072the matrix elements (line number index) runs along
1073the Y-axis if {\tt CMemoryMapping} is used, and along the X-axis
1074in the case of {\tt FortranMemoryMapping}.
1075Arithmetic operations between matrices
1076with different memory organisation is allowed as long as
1077the two matrices have the same sizes (Number of rows and columns).
1078The following code example and the corresponding output illustrates
1079these two memory mappings. The {\tt \tcls{TMatrix}::TransposeSelf() }
1080method changes effectively the matrix memory mapping, which is also
1081the case of {\tt \tcls{TMatrix}::Transpose() } method without argument.
1082
1083\begin{verbatim}
1084TArray<r_4> X(4,2);
1085X = RegularSequence(1,1);
1086cout << "Array X= " << X << endl;
1087TMatrix<r_4> X_C(X, true, BaseArray::CMemoryMapping);
1088cout << "Matrix X_C (CMemoryMapping) = " << X_C << endl;
1089TMatrix<r_4> X_F(X, true, BaseArray::FortranMemoryMapping);
1090cout << "Matrix X_F (FortranMemoryMapping) = " << X_F << endl;
1091\end{verbatim}
1092This code would produce the following output (X\_F = Transpose(X\_C)) :
1093\begin{verbatim}
1094Array X=
1095--- TArray<f> ND=2 SizeX*Y*...= 4x2 ---
10961, 2, 3, 4
10975, 6, 7, 8
1098
1099Matrix X_C (CMemoryMapping) =
1100--- TMatrix<f>(NRows=2, NCols=4) ND=2 SizeX*Y*...= 4x2 ---
11011, 2, 3, 4
11025, 6, 7, 8
1103
1104Matrix X_F (FortranMemoryMapping) =
1105--- TMatrix<f>(NRows=4, NCols=2) ND=2 SizeX*Y*...= 4x2 ---
11061, 5
11072, 6
11083, 7
11094, 8
1110\end{verbatim}
1111
1112\newpage
1113
1114\section{Module HiStats}
1115\begin{figure}[hbt]
1116\dclsbb{AnyDataObj}{Histo}
1117\dclscc{Histo}{HProf}
1118\dclscc{Histo}{HistoErr}
1119\dclsbb{AnyDataObj}{Histo2D}
1120\caption{partial class diagram for histograms and ntuples}
1121\end{figure}
1122
1123{\bf HiStats} contains classes for creating, filling, printing and
1124doing various operations on one or two dimensional histograms
1125{\tt Histo} and {\tt Histo2D} as well as profile histograms {\tt HProf}. \\
1126This module also contains {\tt NTuple} and {\tt DataTable} which are
1127more or less the same as the binary or ascii FITS tables.
1128
1129\subsection{Histograms}
1130\subsubsection{1D Histograms}
1131\index{Histo}
1132For 1D histograms, various numerical methods are provided such as
1133computing means and sigmas, finding maxima, fitting, rebinning,
1134integrating \dots \\
1135The example below shows creating and filling a one dimensional histogram
1136of 100 bins from $-5.$ to $+5.$ to create a Gaussian normal distribution
1137with errors~:
1138\begin{verbatim}
1139#include "histos.h"
1140// ...
1141Histo H(-0.5,0.5,100);
1142H.Errors();
1143for(int i=0;i<25000;i++) {
1144 double x = NorRand();
1145 H.Add(x);
1146}
1147H.Print(80);
1148\end{verbatim}
1149
1150\subsubsection{2D Histograms}
1151\index{Histo2D}
1152Much of these operations are also valid for 2D histograms. 1D projection
1153or slices can be set~:
1154\begin{verbatim}
1155#include "histos2.h"
1156// ...
1157Histo2D H2(-1.,1.,100,0.,60.,50);
1158H2.SetProjX(); // create the 1D histo for X projection
1159H2.SetBandX(25.,35.); // create 1D histo projection for 25.<y<35.
1160H2.SetBandX(35.,45.); // create 1D histo projection for 35.<y<45.
1161H2.SetBandX(40.,55.); // create 1D histo projection for 40.<y<55.
1162//... fill H2 with what ever you want
1163H2.Print();
1164Histo *hx = H2.HProjX();
1165 hx->Print(80);
1166Histo *hbx2 = HBandX(1); // Get the second X band (35.<y<45.)
1167 hbx2->Print(80);
1168\end{verbatim}
1169
1170\subsubsection{Profile Histograms}
1171\index{HProf}
1172Profiles histograms {\bf HProf} contains the mean and the
1173sigma of the distribution
1174of the values filled in each bin. The sigma can be changed to
1175the error on the mean. When filled, the profile histogram looks
1176like a 1D histogram and much of the operations that can be done on 1D histo
1177may be applied onto profile histograms.
1178
1179\subsubsection{Histograms HistoErr}
1180\index{HistoErr}
1181The {\bf HistoErr} are histograms where the number of entries for each bin is kept.
1182Various methods to deal with the computation of the mean in each bin
1183are provided.
1184
1185\subsection{Data tables (tuples)}
1186\begin{figure}[hbt]
1187\dclsbb{AnyDataObj}{NTuple}
1188\dclsccc{AnyDataObj}{BaseDataTable}{DataTable}
1189\dclscc{BaseDataTable}{SwPPFDataTable}
1190\end{figure}
1191
1192\subsubsection{NTuple}
1193\index{NTuple}
1194{\bf NTuple} are memory resident tables of 32 or 64 bits floating values
1195(float/double).They are arranged in columns. Each line is often called an event.
1196These objects are frequently used to analyze data.
1197The piapp graphicals tools can plot a column against an other one
1198with respect to various selection cuts. \\
1199Here is an example of creation and filling~:
1200\begin{verbatim}
1201#include "ntuple.h"
1202#include "srandgen.h"
1203// ...
1204char* nament[4] = {"i","x","y","ey"};
1205r_4 xnt[4];
1206NTuple NT(4,nament);
1207for(i=0;i<5000;i++) {
1208 xnt[0] = i+1;
1209 xnt[1] = 5.*drandpm1(); // a random value between -5 and +5
1210 xnt[2] = 100.*exp(-0.5*xnt[1]*xnt[1]) + 1.;
1211 xnt[3] = sqrt(xnt[2]);
1212 xnt[2] += xnt[3] * NorRand(); // add a random gaussian error
1213 NT.Fill(xnt);
1214}
1215\end{verbatim}
1216
1217{\bf XNTuple} provide additional functionalities, compared to NTuple. However,
1218this class is deprecated and superseded by classes inheriting from BaseDataTable.
1219It is only kept for backward compatibility and should not be used anymore.
1220Use DataTable and SwPPFDataTable instead.
1221Object of type XNTuple handle various types
1222of column values (double,float,int,string,...) and can handle
1223very large data sets, through swap space on disk.
1224
1225\subsubsection{DataTables}
1226\label{datatables}
1227\index{DataTable}
1228The class {\bf DataTable} extends significantly the functionalities provided by
1229NTuple. DataTable is a memory resident implementation of the interface
1230{\bf BaseDataTable } which organizes the data as a 2-D table. User can define
1231the name and data type of each column. Data is added to the table as rows.
1232The table is extended as necessary when adding rows.
1233The sample code below shows an example of DataTable usage :
1234\begin{verbatim}
1235 #include "datatable.h"
1236 // ...
1237 {
1238 DataTable dt(64);
1239 dt.AddFloatColumn("X0_f");
1240 dt.AddFloatColumn("X1_f");
1241 dt.AddDoubleColumn("X0X0pX1X1_d");
1242 double x[5];
1243 for(int i=0; i<63; i++) {
1244 x[0] = (i/9)-4.; x[1] = (i/9)-3.; x[2] = x[0]*x[0]+x[1]*x[1];
1245 dt.AddLine(x);
1246 }
1247 // Printing table info
1248 cout << dt ;
1249 // Saving object into a PPF file
1250 POutPersist po("dtable.ppf");
1251 po << dt ;
1252 }
1253\end{verbatim}
1254
1255
1256\index{SwPPFDataTable}
1257The class {\bf SwPPFDataTable} implements the BaseDataTable interface
1258using segmented data blocks with swap on PPF streams. Very large data sets
1259can be created and manipulated through this class. A similar class
1260SwFitsDataTable (\ref{SwFitsDataTable}), using
1261FITS files as swap space is also provided in the FitsIOServer module.
1262
1263\index{DataTableRow}
1264The class {\bf DataTableRow } is an auxiliary class which simplifies the manipulation
1265of BaseDataTable object rows.
1266The example below show how to create and filling a table, using a PPF stream as
1267swap space. In addition, we have used a {\tt DataTableRow} to prepare data
1268for each table line.
1269\begin{verbatim}
1270 #include "swppfdtable.h"
1271 // ...
1272 {
1273 // ---------- Create an output PPF stream (file)
1274 POutPersist po("swdtable.ppf");
1275 // ------------------
1276 // Create a table with 3 columns, using the above stream as swap space
1277 SwPPFDataTable dtrow(po, 64);
1278 dtrow.AddStringColumn("sline");
1279 dtrow.AddIntegerColumn("line");
1280 dtrow.AddDateTimeColumn("datime");
1281 //
1282 TimeStamp ts, ts2; // Initialize current date and time
1283 string sline;
1284 //---- Create a table row with the required structure
1285 DataTableRow row = dtrow.EmptyRow();
1286 // ----- Fill the table
1287 for(int k = 0; k<2500; k++) {
1288 sline = "L-";
1289 sline += (string)MuTyV(k);
1290 row["sline"] = sline;
1291 row[1] = k;
1292 ts2.Set(ts.ToDays()+(double)k);
1293 row["datime"] = ts2;
1294 dtrow.AddRow(row);
1295 }
1296 //------ Write the table itself to the stream, before closing the file
1297 po << PPFNameTag("SwTable") << dtrow;
1298 }
1299\end{verbatim}
1300%%
1301The previously created table can easily be read in, as shown below:
1302%%
1303\begin{verbatim}
1304 #include "swppfdtable.h"
1305 // ...
1306 {
1307 // ------ Create the input PPF stream (file)
1308 PInPersist pin("swdtable.ppf");
1309 // ------ Read in the SwPPFDataTable object
1310 SwPPFDataTable dtr;
1311 pin >> PPFNameTag("SwTable") >> dtr;
1312 // ---- Create a table row with the required structure
1313 DataTableRow row = dtr.EmptyRow();
1314 // ---- Acces and print two of the table rows :
1315 cout << dtr.GetRow(6, row) << endl;
1316 cout << dtr.GetRow(17, row) << endl;
1317 }
1318\end{verbatim}
1319
1320\subsection{Writing, viewing \dots }
1321
1322All these objects have been design to be written to or read from a persistent file.
1323The following example shows how to write the previously created objects
1324into such a file~:
1325\begin{verbatim}
1326//-- Writing
1327{
1328char *fileout = "myfile.ppf";
1329string tag;
1330POutPersist outppf(fileout);
1331tag = "H"; outppf.PutObject(H,tag);
1332tag = "H2"; outppf.PutObject(H2,tag);
1333tag = "NT"; outppf.PutObject(NT,tag);
1334} // closing ``}'' destroy ``outppf'' and automatically close the file !
1335\end{verbatim}
1336
1337Sophya graphical tools (spiapp) can automatically display and operate
1338all these objects.
1339
1340\newpage
1341\section{Module NTools}
1342
1343This module provides elementary numerical tools for numerical integration,
1344fitting, sorting and ODE solving. FFTs are also provided (Mayer,FFTPack).
1345
1346\subsection{Fitting}
1347\index{Fitting} \index{Minimisation}
1348Fitting is done with two classes {\tt GeneralFit} and {\tt GeneralFitData}
1349and is based on the Levenberg-Marquardt method.
1350\index{GeneralFit} \index{GeneralFitData}
1351GeneralFitData is a class which provide a description of the data
1352to be fitted. GeneralFit is the fitter class. Parametrized functions
1353can be given as classes which inherit {\tt GeneralFunction}
1354or as simple C functions. Classes of pre-defined functions are provided
1355(see files fct1dfit.h and fct2dfit.h). The user interface is very close
1356from that of the CERN {\tt Minuit} fitter.
1357Number of objects (Histo, HProf \dots ) are interfaced with GeneralFit
1358and can be easily fitted. \\
1359Here is a very simple example for fitting the previously created NTuple
1360with a Gaussian~:
1361\begin{verbatim}
1362#include "fct1dfit.h"
1363// ...
1364
1365// Read from ppf file
1366NTuple nt;
1367{
1368PInPersist pis("myfile.ppf");
1369string tag = "NT"; pis.GetObject(nt,tag);
1370}
1371
1372// Fill GeneralData
1373GeneralData mGdata(nt.NEntry());
1374for(int i=0; i<nt.NEntry(); i++)
1375 mGdata.AddData1(xnt[1],xnt[2],xnt[3]); // Fill x, y and error on y
1376mGData.PrintStatus();
1377
1378// Function for fitting : y = f(x) + noise
1379Gauss1DPol mFunction; // gaussian + constant
1380
1381// Prepare for fit
1382GeneralFit mFit(&mFunction); // create a fitter for the choosen function
1383mFit.SetData(&mGData); // connect data to the fitter
1384
1385// Set and initialise the parameters (that's non-linear fitting!)
1386// (num par, name, guess start, step, [limits min and max])
1387mFit.SetParam(0,"high",90.,1..);
1388mFit.SetParam(1,"xcenter",0.05,0.01);
1389mFit.SetParam(2,"sigma",sig,0.05,0.01,10.);
1390 // Give limits to avoid division by zero
1391mFit.SetParam(3,"constant",0.,1.);
1392
1393// Fit and print result
1394int rcfit = mFit.Fit();
1395mFit.PrintFit();
1396if(rcfit>0) {)
1397 cout<<"Reduce_Chisquare = "<<mFit.GetChi2Red()
1398 <<" nstep="<<mFit.GetNStep()<<" rc="<<rcfit<<endl;
1399} else {
1400 cout<<"Fit_Error, rc = "<<rcfit<<" nstep="<<mFit.GetNStep()<<endl;
1401 mFit.PrintFitErr(rcfit);
1402}
1403
1404// Get the result for further use
1405TVector<r_8> ParResult = mFit.GetParm();
1406cout<<ParResult;
1407\end{verbatim}
1408
1409Much more usefull possibilities and detailed informations might be found
1410in the HTML pages of the Sophya manual.
1411
1412\subsection{Polynomial}
1413\index{Polynomial} \index{Poly} \index{Poly2}
1414Polynomials of 1 or 2 variables are supported ({\tt Poly} and {\tt Poly2}).
1415Various operations are supported~:
1416\begin{itemize}
1417\item elementary operations between polynomials $(+,-,*,/) $
1418\item setting or getting coefficients
1419\item computing the value of the polynomial for a given value
1420 of the variable(s),
1421\item derivating
1422\item computing roots (degre 1 or 2)
1423\item fitting the polynomial to vectors of data.
1424\end{itemize}
1425Here is an example of polynomial fitting~:
1426\begin{verbatim}
1427#include "poly.h"
1428// ...
1429Poly pol(2);
1430pol[0] = 100.; pol[1] = 0.; pol[2] = 0.01; // Setting coefficients
1431TVector<r_8> x(100);
1432TVector<r_8> y(100);
1433TVector<r_8> ey(100);
1434for(int i=0;i<100;i++) {
1435 x(i) = i;
1436 ey(i) = 10.;
1437 y(i) = pol((double) i) + ey(i)*NorRand();
1438 ey(i) *= ey(i)
1439}
1440
1441TVector<r_8> errcoef;
1442Poly polfit;
1443polfit.Fit(x,y,ey,2,errcoef);
1444
1445cout<<"Fit Result"<<polfit<<endl;
1446cout<<"Errors :"<<errcoef;
1447\end{verbatim}
1448
1449Similar operations can be done on polynomials with 2 variables.
1450
1451\subsection{Integration, Differential equations}
1452\index{Integration}
1453The NTools module provide also simple classes for numerical integration
1454of functions and differential equations.
1455\begin{figure}[hbt]
1456\dclsbb{Integrator}{GLInteg}
1457\dclsb{TrpzInteg}
1458\end{figure}
1459
1460\index{GLInteg} \index{TrpzInteg}
1461{\bf GLInteg} implements the integration through Gauss-Legendre method
1462and {\bf TrpzInteg} implements trapeze integration. For {\bf TrpzInteg},
1463number of steps specify the number of trapeze, and integration step,
1464their width.
1465The sample code below illustrates the use of TrpzInteg class:
1466\begin{verbatim}
1467#include "integ.h"
1468// ......................................................
1469// Function to be integrated
1470double myf(double x)
1471{
1472// Simple a x + b x^2 (a=2 b=3)
1473return (x*(2.+3.*x));
1474}
1475// ......................................................
1476
1477// Compute Integral(myf, 2., 5.) between xmin=2., xmax=5.
1478TrpzInteg trpz(myf, 2., 5.);
1479// We specify an integration step
1480trpz.DX(0.01);
1481// The integral can be computed as trpz.Value()
1482double myf_integral = trpz.Value();
1483// We could have used the cast operator :
1484cout << "Integral[myf, 2., 5.]= " << (double)trpz << endl;
1485// Limits can be specified through ValueBetween() method
1486cout << "Integral[myf, 0., 4.]= " << trpz.ValueBetween(0.,4.) << endl;
1487\end{verbatim}
1488
1489\subsection{Fourier transform (FFT)}
1490\index{FFT} \index{FFTPackServer}
1491An abstract interface for performing FFT operations is defined by the
1492{\bf FFTServerInterface} class. The {\bf FFTPackSever} class implements
1493one dimensional FFT, on real and complex data. FFTPackServer uses an
1494adapted and extended version of FFTPack (available from netlib),
1495translated in C, and can operate on single and double precision
1496({\tt float, double}) data.
1497
1498The sample code below illustrates the use of FFTServers:
1499\begin{verbatim}
1500#include "fftpserver.h"
1501 // ...
1502TVector<r_8> in(32);
1503TVector< complex<r_8> > out;
1504in = RandomSequence();
1505FFTPackServer ffts;
1506ffts.setNormalize(true); // To have normalized transforms
1507cout << " FFTServer info string= " << ffts.getInfo() << endl;
1508cout << "in= " << in << endl;
1509cout << " Calling ffts.FFTForward(in, out) : " << endl;
1510ffts.FFTForward(in, out);
1511cout << "out= " << out << endl;
1512\end{verbatim}
1513
1514% \newpage
1515\section{Module SUtils}
1516Some utility classes and C/C++ string manipulation functions are gathered
1517in {\bf SUtils} module.
1518\subsection{Using DataCards}
1519\index{DataCards}
1520The {\bf DataCards} class can be used to read parameters from a file.
1521Each line in the file starting with \@ defines a set of values
1522associated with a keyword. In the example below, we read the
1523parameters corresponding with the keyword {\tt SIZE} from the
1524file {\tt ex.d}. We suppose that {\tt ex.d} contains the line: \\
1525{\tt @SIZE 400 250} \\
1526\begin{verbatim}
1527#include "datacards.h"
1528// ...
1529// Initialising DataCards object dc from file ex.d
1530DataCards dc( "ex.d" );
1531// Getting the first and second parameters for keyword size
1532// We define a default value 100
1533int size_x = dc.IParam("SIZE", 0, 100);
1534int size_y = dc.IParam("SIZE", 1, 100);
1535cout << " size_x= " << size_x << " size_y= " << size_y << endl;
1536\end{verbatim}
1537
1538\section{Module SysTools}
1539The {\bf SysTools} module contains classes implementing interface to some
1540OS specific services, such as thread creation and management, dynamic loading and
1541resource usage information. For example, yhe class {\bf Periodic} provides the
1542necessary services needed to implement the execution of a periodic action.
1543
1544\subsection{Resource usage (CPU, memory \ldots) }
1545 The class {\bf ResourceUsage} \index{ResourceUsage}
1546and {\bf Timer} \index{Timer} provides access to information
1547about various resource usage (memory, CPU, ...).
1548The class {\bf Timer} \index{time (CPU, elapsed)} and c-functions
1549{\tt InitTim() , PrtTim(const char * Comm) } can be used to print
1550the amount of CPU and elapsed time in programs.
1551
1552The following sample code illustrates the use of {\bf ResourceUsage} :
1553\begin{verbatim}
1554 // How to check resource usage for a given part of the program
1555 ResourceUsage res;
1556 // --- Part of the program to be checked : Start
1557 // ...
1558 res.Update();
1559 cout << " Memory size increase (KB):" << res.getDeltaMemorySize() << endl;
1560 cout << " Resource usage info : \n" << res << endl;
1561\end{verbatim}
1562
1563\subsection{Thread management classes}
1564\index{ZThread} \index{ZMutex}
1565A basic interface to POSIX threads is also provided
1566through the \index{threads} {\bf ZThread}, {\bf ZMutex} and {\bf ZSync}
1567classes. The best way to use thread management classes is by inheriting
1568from {\bf ZThread} and redefining the {\tt run() } method.
1569It is also possible to use the default {\tt run() } implementation and associate
1570a function to perform the action, as in the example below :
1571\begin{verbatim}
1572 // The functions to perform computing
1573 void fun1(void *arg) { }
1574 void fun2(void *arg) { }
1575 // ...
1576 ZThread zt1;
1577 zt1.setAction(fun1, arg[1]);
1578 ZThread zt2;
1579 zt2.setAction(fun2, arg[1]);
1580 cout << " Starting threads ... " << endl;
1581 zt1.start();
1582 zt2.start();
1583 cout << " Waiting for threads to end ... " << endl;
1584 zt1.join();
1585 zt2.join();
1586\end{verbatim}
1587The classes {\bf ZMutex} \index{mutex} and {\bf ZSync} can be used
1588to perform synchronisation and signaling between threads.
1589
1590\subsection{Dynamic linker and C++ compiler classes}
1591\index{PDynLinkMgr}
1592The class {\bf PDynLinkMgr} can be used for managing shared libraries
1593at run time. The example below shows the run time linking of a function:\\
1594{\tt extern "C" { void myfunc(); } } \\
1595\begin{verbatim}
1596#include "pdlmgr.h"
1597// ...
1598string soname = "mylib.so";
1599string funcname = "myfunc";
1600PDynLinkMgr dyl(soname);
1601DlFunction f = dyl.GetFunction(funcname);
1602if (f != NULL) {
1603// Calling the function
1604 f();
1605}
1606\end{verbatim}
1607
1608\index{CxxCompilerLinker}
1609The {\bf CxxCompilerLinker} class provides the services to compile C++ code and building
1610shared libraries, using the same compiler and options which have
1611been used to create the SOPHYA shared library.
1612The sample program below illustrates using this class to build
1613the shared library (myfunc.so) from the source file myfunc.cc :
1614\begin{verbatim}
1615#include "cxxcmplnk.h"
1616// ...
1617string flnm = "myfunc.cc";
1618string oname, soname;
1619int rc;
1620CxxCompilerLinker cxx;
1621// The Compile method provides a default object file name
1622rc = cxx.Compile(flnm, oname);
1623if (rc != 0 ) { // Error when compiling ... }
1624// The BuildSO method provides a default shared object file name
1625rc = cxx.BuildSO(oname, soname);
1626if (rc != 0 ) { // Error when creating shared object ... }
1627\end{verbatim}
1628
1629\subsection{Command interpreter}
1630The class {\bf Commander} can be used in interactive programs to provide
1631c-shell like command interpreter and scripting capabilties.
1632Arithmetic expression evaluation is implemented through the {\bf CExpressionEvaluator}
1633and {\bf RPNExpressionEvaluator} classes.
1634The command language provides variable manipulation through the usual
1635{\tt \$varname} vector variable and arithmetic expression extensions, as well
1636as the control and test blocs.
1637\begin{verbatim}
1638#include "commander.h"
1639...
1640Commander cmd;
1641char* ss[3] = {"foreach f ( AA bbb CCCC ddddd )", "echo $f" , "end"};
1642for(int k=0; k<3; k++) {
1643 string line = ss[k];
1644 cmd.Interpret(line);
1645}
1646\end{verbatim}
1647
1648\newpage
1649\section{Module SkyMap}
1650\begin{figure}[hbt]
1651\dclsbb{AnyDataObj}{PixelMap}
1652\dclsccc{PixelMap}{Sphericalmap}{SphereHEALPix}
1653\dclsc{SphereThetaPhi}
1654\dclsc{SphereECP}
1655\dclsb{LocalMap}
1656\caption{partial class diagram for spherical map classes in Sophya}
1657\end{figure}
1658The {\bf SkyMap} module provides classes for creating, filling, reading pixelized spherical and 2D-maps. The types of values stored in pixels can be int, float, double , complex etc. according to the specialization of the template type.
1659\subsection {Spherical maps}
1660SkyMap module provides three kinds of complete ($4 \pi$) spherical maps according to the
1661pixelization scheme.
1662SphereHEALPix represents spheres pixelized following the HEALPIix algorithm (E. Hivon, K. Gorski)
1663\footnote{see the HEALPix Homepage: http://www.eso.org/kgorski/healpix/ }
1664, SphereThetaPhi represents spheres pixelized following an algorithm developed at LAL-ORSAY. The example below shows creating and filling of a SphereHEALPix with nside = 8 (it will be 12*8*8= 768 pixels) :
1665\index{\tcls{SphereHEALPix}}
1666
1667\begin{verbatim}
1668#include "spherehealpix.h"
1669// ...
1670SphereHEALPix<double> sph(8);
1671for (int k=0; k< sph.NbPixels(); k++) sph(k) = (double)(10*k);
1672\end{verbatim}
1673
1674SphereThetaPhi is used in a similar way with an argument representing number of slices in theta (Euler angle) for an hemisphere.
1675\index{\tcls{SphereThetaPhi}}
1676The SphereECP class correspond to the cylindrical projection and can be used for representing
1677partial or full spherical maps. However, it has the disadvantage of having non uniform pixel
1678size.
1679\index{\tcls{SphereECP}}
1680
1681\subsection {Local maps}
1682\index{\tcls{LocalMap}}
1683A local map is a 2 dimensional array, with i as column index and j as row index. The map is supposed to lie on a plan tangent to the celestial sphere in a point whose coordinates are (x0,y0) on the local map and (theta0, phi0) on the sphere. The range of the map is defined by two values of angles covered respectively by all the pixels in x direction and all the pixels in y direction (SetSize()). Default value of (x0, y0) is middle of the map, center of pixel(nx/2, ny/2).
1684
1685Internally, a map is first defined within this reference plane and tranported until the point (theta0, phi0) in such a way that both axes are kept parallel to meridian and parallel lines of the sphere. The user can define its own map with axes rotated with respect to reference axes (this rotation is characterized by angle between the local parallel line and the wanted x-axis-- method SetOrigin(...))
1686
1687The example below shows creating and filling of a LocalMap with 4 columns and 5 rows. The origin is set to default. The map covers a sphere portion defined by two angles of 30. degrees (methods \textit{SetOrigin()} and \textit{SetSize()} must be called in order to completely define the map).
1688\begin{verbatim}
1689#include "localmap.h"
1690//..............
1691 LocalMap<r_4> locmap(4,5);
1692 for (int k=0; k<locmap.NbPixels();k++) locmap(k)=10.*k;
1693 locmap.SetOrigin();
1694 locmap.SetSize(30.,30.);
1695\end{verbatim}
1696
1697\subsection{Writing, viewing \dots }
1698
1699All these objects have been design to be written to or read from a persistant file.
1700The following example shows how to write the previously created objects
1701into such a file~:
1702\begin{verbatim}
1703//-- Writing
1704
1705#include "fiospherehealpix.h"
1706//................
1707
1708char *fileout = "myfile.ppf";
1709POutPersist outppf(fileout);
1710FIO_SphereHEALPix<r_8> outsph(sph);
1711outsph.Write(outppf);
1712FIO_LocalMap<r_8> outloc(locmap);
1713outloc.Write(outppf);
1714// It is also possible to use the << operator
1715POutPersist os("sph.ppf");
1716os << outsph;
1717os << outloc;
1718\end{verbatim}
1719
1720Sophya graphical tools (spiapp) can automatically display and operate
1721all these objects.
1722
1723\newpage
1724\section{Samba and SkyT}
1725\subsection{Samba}
1726\index{Spherical Harmonics}
1727\index{SphericalTransformServer}
1728The module provides several classes for spherical harmonic analysis. The main class is \textit{SphericalTranformServer}. It contains methods for analysis and synthesis of spherical maps. The following example fills a vector of Cl's, generate a spherical map from these Cl's. This map is analysed back to Cl's...
1729\begin{verbatim}
1730#include "skymap.h"
1731#include "samba.h"
1732....................
1733
1734// Generate input spectra a + b* l + c * gaussienne(l, 50, 20)
1735int lmax = 92;
1736Vector clin(lmax);
1737for(int l=0; l<lmax; l++) {
1738 double xx = (l-50.)/10.;
1739 clin(l) = 1.e-2 -1.e-4*l + 0.1*exp(-xx*xx);
1740}
1741
1742// Compute map from spectra
1743SphericalTransformServer<r_8> ylmserver;
1744int m = 128; // HealPix pixelisation parameter
1745SphereHEALPix<r_8> map(m);
1746ylmserver.GenerateFromCl(map, m, clin, 0.);
1747// Compute power spectrum from map
1748Vector clout = ylmserver.DecomposeToCl(map, lmax, 0.);
1749\end{verbatim}
1750
1751\subsection{Module SkyT}
1752\index{RadSpectra} \index{SpectralResponse}
1753The SkyT module is composed of two types of classes:
1754\begin{itemize}
1755\item{} one which corresponds to an emission spectrum of
1756radiation, which is called RadSpectra
1757\item{} one which corresponds to the spectral response
1758of a given detector (i.e. corresponding to a detector
1759filter in a given frequency domain), which is called
1760SpectralResponse.
1761\end{itemize}
1762\begin{figure}[hbt]
1763\dclsbb{RadSpectra}{RadSpectraVec}
1764\dclsb{BlackBody}
1765\dclsccc{AnyDataObj}{SpectralResponse}{SpecRespVec}
1766\dclsc{GaussianFilter}
1767\caption{partial class for SkyT module}
1768\end{figure}
1769
1770\begin{verbatim}
1771#include "skyt.h"
1772// ....
1773// Compute the flux from a blackbody at 2.73 K through a square filter
1774BlackBody myBB(2.73);
1775// We define a square filter from 100 - 200 GHz
1776SquareFilter mySF(100,200);
1777// Compute the filtered integrated flux :
1778double flux = myBB.filteredIntegratedFlux(mySF);
1779\end{verbatim}
1780
1781A more detailed description of SkyT module can be found in:
1782{\it The SkyMixer (SkyT and PMixer modules) - Sophya Note No 2. }
1783available also from Sophya Web site.
1784
1785\newpage
1786\section{Module FitsIOServer}
1787This module provides classes for handling file input-output in FITS
1788\footnote{http://heasarc.gsfc.nasa.gov/docs/software/fitsio/fitsio.html}
1789format using the cfitsio library. Its
1790design is similar to the SOPHYA persistence (see Module BaseTools).
1791Delegate classes or handlers perform the actual read/write from/to fits files.
1792\par
1793Compared to the SOPHYA native persistence (PPF format),
1794FITS format has the advantage of being used extensively, and handled
1795by a many different software tools. It is a de facto standard in
1796astronomy and astrophysics.
1797However, FITS lacks some of the features present in SOPHYA PPF, and although
1798many SOPHYA objects can be saved in FITS files, FITS persistence has
1799some limitations. For example, FITS does not currently handle complex arrays.
1800\subsection{FITS streams}
1801\index{FITS} \index{FitsInOutFile}
1802%%
1803The class {\bf FitsInOutFile} can be seen as a wrapper class for the cfitsio library functions.
1804This class has been introduced in 2005 (V=1.9), when the module has been
1805extensively changed. In order to keep backward compatibility, the old fits wrapper
1806classes ({\bf FitsFile, FitsInFile, FitsOutFile}) has been changed to inherit from
1807 {\bf FitsInOutFile}. The use of class FitsFile and specific services of these old classes
1808 should be avoided, but FitsInFile, FitsOutFile can be safely considered a specialisation
1809 of FitsInOutFile for read/input and write/output operations respectively.
1810 Most c-fitsio errors are converted to an exception: {\bf FitsIOException}.
1811 \par
1812 File names are passed to cfitsio library. It is thus possible to use cfitsio file name conventions,
1813 such as {\bf ! } as the first character, for overwriting existing files (when creating files).
1814 The diagram below shows the class hierarchy for cfitsio wrapper classes.
1815\begin{figure}[hbt]
1816\dclsa{FitsInOutFile}
1817\dclscc{FitsFile}{FitsInFile}
1818\dclscc{FitsFile}{FitsOutFile}
1819\end{figure}
1820%%%%
1821\subsection{FITS handlers and I/O operators}
1822\index{FitsManager}
1823Handlers classes inheriting from {\bf FitsHandlerInterface} perform write/read operations
1824for AnyDataObj objects to/from FitsInOutFile streams. The {\bf FitsManager} class provides
1825top level services for object read/write in FITS files.
1826\par In most cases,
1827\hspace{5mm} {\tt FitsInOutFile\& $<<$ } \, and \, {\tt FitsInOutFile\& $>>$ } \hspace{5mm}
1828operators can be used to write and read objects.
1829When reading objects from a fits file using the {\tt FitsInOutFile\& $>>$ } operator,
1830the fits file is positioned on the next HDU, after reading. Also, if the {\bf FitsInOutFile}
1831object is positioned on a first empty HDU (without data, naxis=0), reading in objects
1832corresponding to a binary or ascii table using the operator $>>$ will skip automatically
1833the empty HDU and position the fits file on the second HDU, before trying to read in
1834the object.
1835\par
1836The two main types of fits data structures, images and tables
1837{\tt (IMAGE\_HDU , BINARY\_TBL , ASCII\_TBL)} are handled by the generic handlers: \\
1838{\bf \tcls{FitsArrayHandler}} and {\bf FitsHandler$<$BaseDataTable$>$}.
1839\par
1840A number of more specific handlers are also available, in particular for NTuple,
1841\tcls{SphereHealPix} and \tcls{SphereThetaPhi}. \\[2mm]
1842{\bf Warning:} Some handlers were written with the old FitsIOServer classes.
1843They inherit from the intermediate class {\bf FitsIOHandler} and
1844have been adapted to the new scheme. \\[2mm]
1845%%%
1846The examples below illustrates the usage of FitsIOServer classes. They can be compiled
1847and executed using runcxx, without the {\tt include} lines: \\[1mm]
1848\hspace*{5mm} {\tt csh> runcxx -import SkyMap -import FitsIOServer -inc fiosinit.h }
1849%%%
1850\begin{enumerate}
1851\item Saving an array and a HealPix map to a Fits file
1852\begin{verbatim}
1853#include "fitsioserver.h"
1854#include "fiosinit.h"
1855// ....
1856{
1857// Make sure FitsIOServer module is initialised :
1858FitsIOServerInit();
1859// Create and open a fits file named myfile.fits
1860FitsInOutFile fos("myfile.fits", FitsInOutFile ::Fits_Create);
1861// Create and save a 15x11 matrix of integers
1862TMatrix<int_4> mxi(15, 11);
1863mxi = RegularSequence(10.,10.);
1864fos << mxi;
1865// Save a HEALPix spherical map using FitsManager services
1866SphereHEALPix<r_8> sph(16);
1867sph = 48.3;
1868FitsManager::Write(fos, sph);
1869// --- The << operator could have been used instead : fos << sph;
1870}
1871\end{verbatim}
1872%%%%
1873%%%%
1874\item Reading objects and the header from the previously created fits file:
1875\begin{verbatim}
1876{
1877FitsIOServerInit(); // Initialisation
1878// ---- Open the fits file named myfile.fits
1879FitsInFile fis("myfile.fits");
1880//---- print file information on cout
1881cout << fis << endl;
1882//--- Read in the array
1883TArray<int_4> arr;
1884fis >> arr;
1885arr.Show();
1886//--- Position on second HDU
1887fis.MoveAbsToHDU(2);
1888//--- read and display header information
1889DVList hdu2;
1890fis.GetHeaderRecords(hdu2, true, true);
1891cout << hdu2;
1892//--- read in the HEALPix map
1893SphereHEALPix<r_8> sph;
1894FitsManager::Read(fis, sph);
1895// --- The >> operator could have been used instead : fis >> sph;
1896sph.Show();
1897}
1898\end{verbatim}
1899%%%%%%%
1900%%%
1901\item DataTable objects can be read from and written to FITS files as ASCII or
1902binary tables. The example belo show reading the DataTable created in the example
1903in section \ref{datatables} from a PPF file and saving it to a fits file.
1904\begin{verbatim}
1905#include "swfitsdtable.h"
1906// ....
1907{
1908FitsIOServerInit(); // FitsIOServer Initialisation
1909//--- Reading in DataTable object from PPF file
1910PInPersist pin("dtable.ppf");
1911DataTable dt;
1912pin >> dt;
1913dt.Show();
1914//--- Saving table to FITS
1915FitsInOutFile fos("!dtable.fits", FitsInOutFile ::Fits_Create);
1916fos << dt;
1917}
1918\end{verbatim}
1919%%%%
1920\end{enumerate}
1921%%%
1922A partial class diagram of FITS persistence handling classes is shown below. The
1923class {\tt FitsIOhandler} conforms to the old FitsIOServer module design and
1924should not be used anymore.
1925\begin{figure}[hbt]
1926\dclsbb{FitsHandlerInterface}{FitsArrayHandler$<$T$>$}
1927\dclsb{\tcls{FitsHandler}}
1928\dclscc{FitsIOhandler}{FITS\_NTuple}
1929\dclsc{FITS\_SphereHEALPix}
1930% \dclsb{FITS\_LocalMap}
1931\end{figure}
1932
1933\subsection{SwFitsDataTable and other classes}
1934\label{SwFitsDataTable}
1935\index{SwFitsDataTable}
1936The {\bf SwFitsDataTable} class implements the BaseDataTable interface
1937using a FITS file as swap space. Compared to SwPPFDataTable, they can be
1938used in R/W mode (reading from the table, when it is being created / filled).
1939They can be used in a way similar to DataTable and SwPPFDataTable.
1940When creating the table, a {\tt FitsInOutFile } stream, opened for writing has
1941to be passed to the creator. No further operation is needed.
1942\begin{verbatim}
1943// ....
1944FitsInOutFile so("!myswtable.fits", FitsInOutFile::Fits_Create);
1945SwFitsDataTable dt(so, 16);
1946// define table columns
1947dt.AddIntegerColumn("X0_i");
1948dt.AddFloatColumn("X1_f");
1949// ... Fill the table
1950r_8 x[5];
1951for(int i=0; i<63; i++) {
1952 x[0] = (i%9)-4.; x[1] = (i/9)-3.;
1953 dt.AddLine(x);
1954}
1955\end{verbatim}
1956The class {\bf FitsBTNtuIntf } provide an alternative tool to read FITS tables.
1957{\bf FitsABTColRd} , {\bf FitsABTWriter } and {\bf FitsImg2DWriter } can also
1958be used to manipulate FITS files.
1959\par
1960The {\bf scanfits} program can be used to check FITS files and analyse their
1961content (See \ref{scanfits}).
1962
1963%%%%
1964\newpage
1965\section{LinAlg and IFFTW modules}
1966An interface to use LAPACK library (available from {\tt http://www.netlib.org})
1967is implemented by the {\bf LapackServer} class, in module LinAlg.
1968\index{LapackServer}.
1969The sample code below shows how to use SVD (Singular Value Decomposition)
1970through LapackServer:
1971\begin{verbatim}
1972#include "intflapack.h"
1973// ...
1974// Use FortranMemoryMapping as default
1975BaseArray::SetDefaultMemoryMapping(BaseArray::FortranMemoryMapping);
1976// Create an fill the arrays A and its copy AA
1977int n = 20;
1978Matrix A(n , n), AA;
1979A = RandomSequence(RandomSequence::Gaussian, 0., 4.);
1980AA = A; // AA is a copy of A
1981// Compute the SVD decomposition
1982Vector S; // Vector of singular values
1983Matrix U, VT;
1984LapackServer<r_8> lpks;
1985lpks.SVD(AA, S, U, VT);
1986// We create a diagonal matrix using S
1987Matrix SM(n, n);
1988for(int k=0; k<n; k++) SM(k,k) = S(k);
1989// Check the result : A = U*SM*VT
1990Matrix diff = U*(SM*VT) - A;
1991double min, max;
1992diff.MinMax(min, max);
1993cout << " Min/Max difference Matrix (?=0) , Min= " << min
1994 << " Max= " << max << endl;
1995\end{verbatim}
1996
1997\index{FFTWServer}
1998The {\bf FFTWServer} class (in module FFTW) implements FFTServerInterface class
1999methods, for one dimensional and multi-dimensional Fourier
2000transforms on double precision data using the FFTW package
2001(available from {\tt http://www.fftw.org}).
2002
2003\newpage
2004\section{Building and installing Sophya}
2005\subsection{Supported platforms}
2006Presently, the Sophya library has been tested with the following
2007compiler/platform pairs:
2008
2009\begin{center}
2010\begin{tabular}{|l|l|}
2011\hline
2012OS & compiler \\
2013\hline
2014Linux & g++ (3.x 4.0) \\
2015Linux (SCL) & icc - Intel compiler (9.0) \\
2016MacOSX/Darwin 10.3 \, 10.4 & g++ (3.3 4.0)\\
2017HP/Compaq/DEC Tru64 ( OSF1) & cxx (6.1 6.3) \\
2018SGI IRIX64 & CC (7.3) \\
2019IBM AIX & xlC (7.x) \\
2020\hline
2021\end{tabular}
2022\end{center}
2023
2024\subsection{Library and makefile structure}
2025%
2026The object files from a given Sophya module are grouped in an archive library
2027with the module's name ({\tt libmodulename.a}). All Sophya modules
2028 are grouped in a single shared library ({\tt libsophya.so}), while the
2029modules with reference to external libraries are grouped in
2030({\tt libextsophya.so}). The {\bf PI} and {\bf PIext} modules are
2031grouped in ({\tt libPI.so}).
2032Alternatively, it is possible to group all modules in a single shared
2033library {\tt libAsophyaextPI.so}.
2034\par
2035Each library module has a {\tt Makefile} which compiles the source files
2036and build the correspond static (archive) library using the compilation
2037rules and flags defined in \\
2038\hspace*{5mm} {\tt \$SOPHYABASE/include/sophyamake.inc}. \\
2039Each program module has a {\tt Makefile} which compiles and link the
2040corresponding programs using the compilation rules and libraries
2041defined in {\$SOPHYABASE/include/sophyamake.inc}.
2042The top level Makefile in BuildMgr/ compiles each library modules
2043and builds shared libraries.
2044\par
2045Some of the modules in the Sophya package uses external libraries. The
2046{\bf FitsIOServer} is an example of such a module, where the {\tt libcfitsio.a}
2047is used. The list of all Sophya modules using external libraries is
2048presented in section \ref{sopmodules}.
2049The external libraries should be installed before the configure step
2050(see below) and the compilation of the corresponding Sophya modules.
2051\par
2052The series of Makefiles use the link to {\tt sophyamake.inc} in BuildMgr.
2053There are also the {\tt smakefile} series which uses the explicit path, using
2054{\tt \$SOPHYABASE} environment variable.
2055
2056\subsection{Build instructions}
2057\label{build}
2058The build procedure has two main steps:
2059\begin{enumerate}
2060\item The configure step (BuildMgr/configure) setup the directory structure and
2061the necessary configuration file. Refer to section \ref{directories} for
2062the description of SOPHYA directory tree and files.
2063\item The make step compiles the different sources files, create the library and optionaly
2064builds all or some of the associated executables.
2065\end{enumerate}
2066
2067{\tt BuildMgr/configure } is a c-shell script with a number of arguments:
2068\begin{verbatim}
2069csh> ./configure -h
2070configure [-sbase SOPHYABASE] [-scxx SOPHYACXX] [-incln]
2071 [-minc mymake.inc]
2072 [-extp dir1 -extp dir2 ...] [-extip dir1 -extip dir2 ... ]
2073 [-extlp dir1 -extlp dir2 ... ]
2074 [-noextlib -noext fits -noext fftw -noext lapack ]
2075 [-noext astro -noext minuit]
2076 [-usefftw2 -uselapack2] [-singleslb]
2077\end{verbatim}
2078\begin{itemize}
2079\item[] -sbase : define SOPHYA installation base directory. \$SOPHYABASE is used
2080if not specified.
2081\item[] -scxx : selects the C++ compiler. \$SOPHYACXX s used
2082if not specified.
2083\item[] -incln : creates symbolic link for include files, instead of copying them.
2084\item[] -minc : give an explicit name for the file used to generate
2085\$SOPHYABASE/include/sophyamake.inc.
2086\item[] -extp : Adds the specied path to the search path of the external libraries
2087include files and archive library.
2088\item[] -extip : Adds the specied path to the search path of the external libraries
2089include files.
2090\item[] -extp : Adds the specied path to the search path of the external libraries
2091archive (libxxx.a).
2092\item[] -noextlib : Disable compiling of modules referencing external libraries.
2093\item[] -noext : Disable compiling of the specified module (with reference to external
2094library.
2095\item[] -usefftw2: FFTW V2 is being used (default FFTW V3) - A compilation flag
2096will be defined in sspvflags.h
2097\item[] -uselapack2: Lapack V2 is being used (defaulr V3) - A compilation flag
2098will be defined in sspvflags.h
2099\item[] -singleslb: A single shared library for all SOPHYA, PI and external library interface
2100modules will be build. A compilation flag
2101will be defined in sspvflags.h . `See also target {\tt slballinone} below.
2102\end{itemize}
2103
2104In the example below, we assume that we want to install Sophya from a
2105released (tagged) version in the source directory {\tt \$SRC} in the
2106{\tt /usr/local/Sophya} directory, using {\tt g++}. We assume that
2107the external libraries can be found in {\tt /usr/local/ExtLibs/}.
2108We disable the compilation of the MinuitAdapt and XAstrPack packages.
2109
2110\vspace*{3mm}
2111\begin{verbatim}
2112# Create the top level directory
2113csh> mkdir /usr/local/Sophya/
2114csh> cd $SRC/BuildMgr
2115# Step 1.a : Run the configuration script
2116csh> ./configure -sbase /usr/local/Sophya -scxx g++ -extp /usr/local/ExtLibs/ \
2117-noext astro -noext minuit
2118# Step 1.b : Check the generated file $SOPHYABASE/include/sophyamake.inc
2119csh> ls -lt *.inc
2120csh> more sophyamake.inc
2121\end{verbatim}
2122If necessary, edit the generated file {\tt sophyamake.inc } in order to modify
2123compilation flags, library list. The file is rather short and self documented.
2124\begin{verbatim}
2125# Step 2.a: Compile the modules without external library reference
2126csh> make libs
2127# Step 2.b: Compile the modules WITH external library reference (optional)
2128csh> make extlibs
2129# Step 2.c: Build libsophya.so
2130csh> make slb
2131# Step 2.d: Build libextsophya.so (optional)
2132csh> make slbext
2133# Step 2.e: Compile the PI and PIext modules (optional)
2134csh> make PI
2135# Step 2.f: Build the corresponding shared library libPI.so (optional)
2136csh> make slbpi
2137\end{verbatim}
2138
2139To compile all modules and build the shared libraries, it is possible
2140to perform the steps 2.a to 2.f using the targets {\tt all} and {\tt slball}
2141defined in the Makefile
2142\begin{verbatim}
2143# Step 2.a ... 2.f
2144csh> make all slball
2145\end{verbatim}
2146
2147It is also possible to group all modules in a single shared library using
2148the target {\tt slballinone}.
2149\begin{verbatim}
2150# Step 2.a ... 2.f
2151csh> make all slballinone
2152\end{verbatim}
2153
2154At this step, all libraries should have been made. Programs using
2155Sophya libraries can now be built:
2156\begin{verbatim}
2157# To compile some of the test programs
2158csh> make basetests
2159# To compile runcxx , scanppf , scanfits
2160csh> make prgutil
2161# To build (s)piapp (libPI.so is needed)
2162csh> make piapp
2163\end{verbatim}
2164
2165If no further modification or update of source files is foreseen, it is possible
2166to remove all .o files:
2167\begin{verbatim}
2168# To clean $SOPHYABASE/obj directory :
2169csh> make cleanobj
2170\end{verbatim}
2171
2172
2173\subsection{Notes}
2174\begin{itemize}
2175\item[{\bf Makefile}] List of top level Makefile build targets
2176\begin{verbatim}
2177> libs extlibs PI = all
2178> slb slbext slbpi = slball (OR = slballinone)
2179> clean cleanobj
2180> tests prgutil prgmap progpi = prgall
2181> basetests piapp (ou progpi) pmixer
2182\end{verbatim}
2183\item[{\bf MacOS X}] A high performance mathematic and signal processing
2184library, including LAPACK and BLAS is packaged in Darwin/MacOS X (10.3, 10.4) : \\
2185\hspace*{5mm} {\bf -framework Accelerate}
2186\item[{\bf Tru64/OSF}] An optimised math library with LAPACK and BLAS might
2187optionaly be installed {\bf (-lcxlm) }. On our system, this libray contained Lapack V2.
2188So we used the LAPACK, as compiled from the public sources, and linked with
2189the Tru64 native BLAS.
2190\item[{\bf IRIX64}] We used the math library with LAPACK V2 and BLAS
2191from SGI : {\bf -lcomplib.sgimath}
2192\item[{\bf AIX}] There seem to be a problem on AIX when several shared
2193libraries are used. We have been able to run SOPHYA programs either
2194using static libraries, or a single shared library (libAsophyaextPI.so)
2195if extlibs and PI are needed, in addition to stand alone SOPHYA modules.
2196It has not been possible to link SOPHYA with fortran libraries
2197\item[{\bf Mgr}] This module contains makefiles and build scripts
2198that were used in SOPHYA up to version 1.7 (2004) : OBSOLETE.
2199\end{itemize}
2200
2201\subsection{Files and scripts in BuildMgr/ }
2202\begin{itemize}
2203\item[] {\bf Makefile:} Top level Makefile for building SOPHYA.
2204{\tt smakefile} is similar to Makefile, except that it uses
2205the smakefiles in each module.
2206\item[] {\bf mkmflib:} c-shell script for creation of library module
2207Makefile / smakefile. \\
2208\hspace*{5mm} {\tt ./mkmflib -sbase /tmp/sbase SUtils }
2209\item[] {\b mkmfprog:}
2210c-shell script for creation of programs module Makefile / smakefile \\
2211\hspace*{5mm} {\tt ./mkmfprog -sbase /tmp/sbase ProgPI }
2212\item[] {\bf domkmf:} c-shell script - calls mkmflib for all modules \\
2213\hspace*{5mm} {\tt ./domkmf -sbase /tmp/sbase}
2214\item[] {\bf xxx\_make.inc:} Configuration files for different compilers and OS
2215{\tt ( Linux\_g++\_make.inc , OSF1\_cxx\_make.inc \ldots )}.
2216These files are used to generate {\tt sophyamake.inc}
2217\end{itemize}
2218
2219
2220
2221\newpage
2222\appendix
2223\section{SOPHYA Exceptions}
2224\index{Exception classes} \index{PThrowable} \index{PError} \index{PException}
2225SOPHYA library defines a set of exceptions which are used
2226for signalling error conditions. The figure below shows a partial
2227class diagram for exception classes in SOPHYA.
2228\begin{figure}[hbt]
2229\dclsbb{PThrowable}{PError}
2230\dclscc{PError}{AllocationError}
2231\dclscc{PError}{NullPtrError}
2232\dclscc{PError}{ForbiddenError}
2233\dclscc{PError}{AssertionFailedError}
2234\dclsbb{PThrowable}{PException}
2235\dclscc{PException}{IOExc}
2236\dclscc{PException}{SzMismatchError}
2237\dclscc{PException}{RangeCheckError}
2238\dclscc{PException}{ParmError}
2239\dclscc{PException}{TypeMismatchExc}
2240\dclscc{PException}{MathExc}
2241\dclscc{PException}{CaughtSignalExc}
2242\caption{partial class diagram for exception handling in Sophya}
2243\end{figure}
2244
2245For simple programs, it is a good practice to handle
2246the exceptions at least at high level, in the {\tt main()} function.
2247The example below shows the exception handling and the usage
2248of Sophya persistence.
2249
2250\input{ex1.inc}
2251
2252
2253\newpage
2254\addcontentsline{toc}{section}{Index}
2255\printindex
2256\end{document}
2257
Note: See TracBrowser for help on using the repository browser.