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

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

fin(?) des modifications de la documentation pour V=2.1, Reza 13/12/2007

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