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

Last change on this file since 3006 was 3006, checked in by ansari, 19 years ago

suite documentation SOPHYA (DataTable, Spheres ...) Reza 04/07/2006

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