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

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

sophya.tex (overview) complete pour tag V2.1, Reza 07/12/2007

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