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

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

descip. modifs HistoErr et grphique associe cmv 12/01/2007

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