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

Last change on this file since 2919 was 2919, checked in by ansari, 20 years ago

MAJ doc sophya oveview pour modifs Range() - Reza 23/02/2006

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