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

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

une partie de la maj doc overview pour sophya V2.1 , Reza 06/12/2007

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