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

Last change on this file since 1435 was 1435, checked in by ansari, 25 years ago

MAJ doc Sophya overview - Preparation pour release - Reza 7/3/2001

File size: 49.3 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\makeindex
20
21\begin{document}
22
23\begin{titlepage}
24% The title page - top of the page with the title of the paper
25\titrehp{Sophya \\ An overview }
26% Authors list
27\auteurs{
28R. Ansari & ansari@lal.in2p3.fr \\
29E. Aubourg & aubourg@hep.saclay.cea.fr \\
30G. Le Meur & lemeur@lal.in2p3.fr \\
31C. Magneville & cmv@hep.saclay.cea.fr \\
32S. Henrot-Versille & versille@in2p3.fr
33}
34% \auteursall
35% The title page - bottom of the page with the paper number
36\vspace{1cm}
37\begin{center}
38{\bf \Large Sophya Version: 1.1 (V\_Fev2001) \\
39Document revision 1.0 }
40\end{center}
41\titrebp{1}
42\end{titlepage}
43
44\tableofcontents
45
46\newpage
47
48\section{Introduction}
49
50{\bf SOPHYA} ({\bf SO}ftware for {\bf PHY}sics {\bf A}nalysis)
51is a collection of C++ classes designed for numerical and
52physics analysis software development. Our goal is to provide
53easy to use, yet powerful classes which can be used by scientists.
54We have decided to use as much as possible available
55numerical analysis libraries, encapsulating them whenever
56possible. Although some the modules in SOPHYA have been
57designed with the specific goal of providing the general framework for
58the Planck-HFI data processing software, most of the
59packages presented here have a more general scope than the
60CMB analysis and Planck mission problem.
61\par
62\vspace*{2mm}
63This documents
64presents only a brief overview of the class library,
65mainly from the user's point of view. A more complete description
66can be found in the reference manual, available from our
67web site: {\bf http://www.sophya.org}.
68\par
69\vspace*{2mm}
70The source directory tree
71\footnote{ CVS: cvsserver.lal.in2p3.fr:/exp/eros/CVSPlanck}
72is organised into a number of modules.
73
74\begin{itemize}
75\item[] {\bf Mgr/} Scripts for code management,
76makefile generation and software installation
77\item[] {\bf SysTools/} General architecture support classes such
78as {\tt PPersist, NDataBlock<T>}, and few utility classes
79({\tt DataCard, DVList} \ldots).
80\item[] {\bf TArray/} template numerical arrays, vectors and matrices \\
81({\tt PixelMap<T> SphericalMap<T>} \ldots)
82\item[] {\bf NTools/} Some standard numerical analysis tools
83(linear, and non linear parameter fitting, FFT, \ldots)
84\item[] {\bf HiStats/} Histogram-ming and data set handling classes \\
85({\tt Histo Histo2D NTuple XNTuple} \ldots)
86\end{itemize}
87
88The modules listed below are more tightly related to the
89CMB (Cosmic Microwave Background) data analysis problem:
90\begin{itemize}
91\item[] {\bf SkyMap/} Local and full sky maps, and few geometry
92handling utility classes. \\
93({\tt PixelMap<T>, LocalMap<T>, SphericalMap<T>, \ldots})
94\item[] {\bf SkyT/}
95classes for spectral emission and detector frequency response modelling \\
96({\tt SpectralResponse, RadSpectra, BlackBody} \ldots)
97\item[] {\bf Samba/} Spherical harmonic analysis.
98\end{itemize}
99
100The following modules contain the interface classes with
101external libraries:
102\begin{itemize}
103\item[] {\bf FitsIOServer/} Classes for handling file input-output
104in FITS format using the cfitsio library.
105\item[] {\bf LinAlg/} Interface with Lapack linear algebra package
106\item[] {\bf IFFTW/} Interface with FFTW package (libfftw.a)
107\end{itemize}
108
109Other modules:
110\begin{itemize}
111\item[] {\bf Tests/} Simple test programs
112\item[] {\bf PrgUtil/} Various utility programs (runcxx, scanppf, scanfits, \ldots)
113\item[] {\bf PMixer/} skymixer and related programs
114\item[] {\bf ProgPI/} interactive analysis tool - It should be noted that
115this module uses the SOPHYA class library and is based on {\bf PI}
116which is a C++ library defining a complete GUI program
117architecture. An additional module (PIext) define the interactive
118analysis program framework and the interfaces with the objects
119in SOPHYA. The {\bf PI/} \footnote{the PI package documentation
120is available from {\bf http://www.lal.in2p3.fr/recherche/eros/PeidaDoc/} }
121and {\bf PIext/} modules are not currently part
122of the SOPHYA CVS structure.
123\end{itemize}
124
125Modules containing examples and demo programs:
126\begin{itemize}
127\item[] {\bf Examples/} Sample SOPHYA codes and example programs and
128makefiles (auto\_makefile and ex\_makefile).
129\item[] {\bf DemoPIApp/} Sample exripts and programs for (s)piapp
130interactive analysis tools.
131\end{itemize}
132\newpage
133
134\section{Using Sophya}
135Basic usage of Sophya classes are described in in the following sections.
136Complete Sophya documentation can be found at our web site: \\
137{\bf http://www.sophya.org}.
138
139\subsection{Environment variables}
140Two environment variables {\bf DPCBASEREP} and {\bf EROSCXX} are used
141to define the path where the Sophya libraries and executable are installed.
142{\bf DPCBASEREP} defines the base directory path and {\bf EROSCXX} the
143name of the C++ compiler. The complete path is built using {\bf DPCBASEREP},
144the operating system name (as obtained by the {\tt uname} command), and
145the compiler name. In the example below, we show the complete path
146for a {\tt Linux} system, using the GNU g++ compiler:
147
148\begin{itemize}
149\item \$DPCBASEREP/Include : Include (.h) files
150\item \$DPCBASEREP/Linux-g++/Libs : Path for the archive libraries (.a)
151\item \$DPCBASEREP/Linux-g++/ShLibs : Shared library path (.so)
152\item \$DPCBASEREP/Linux-g++/Exec : Executable file path
153\end{itemize}
154
155In order to use the shared libraries, the {\bf LD\_LIBRARY\_PATH} variable
156should contain the Sophya shared library path
157({\tt \$DPCBASEREP/Linux-g++/ShLibs } when using g++ compiler on Linux)
158
159For modules using external libraries, the {\bf EXTLIBDIR}
160environment variable should contain the path to these libraries
161and corresponding include files.
162C-FitsIO anf FFTW include files should be accessible through: \\
163{\tt \$EXTLIBDIR/Include/FitsIO } \\
164{\tt \$EXTLIBDIR/Include/FFTW } \\
165The corresponding libraries are expected to be found in: \\
166{\tt \$EXTLIBDIR/Linux-g++/Libs} \\
167
168\subsection{User makefiles}
169The file {\tt \$DPCBASEREP/Include/MakefileUser.h} defines the compilation
170flags and the list of Sophya libraries. It should be included in the
171user's makefile. The default compilation rules assumes that the object (.o)
172and executable files would be put in the following directories: \\
173{\tt \$HOME/`uname`-\$EROSCXX/Objs} \\
174{\tt \$HOME/`uname`-\$EROSCXX/Exec}.
175In the case of a {\tt Linux} system and using {\tt g++} as the C++ compiler,
176these two directories would be translated to \\
177{\tt \$HOME/Linux-g++/Objs} and {\tt \$HOME/Linux-g++/Exec}.
178The GNU make program should be used.
179\par
180The file {\tt Examples/auto\_makefile} defines the rules to compile
181a given source program, and link it against the Sophya libraries to produce
182an executable. The example below shows the steps to compile a program named
183{\tt trivial.cc }.
184\begin{verbatim}
185csh> cp Examples/auto_makefile makefile
186csh> cp Examples/ex1.cc trivial.cc
187csh> make trivial
188\end{verbatim}
189This command should compile the {\tt trivial.cc} file,
190and link it against the sophya libraries.
191The file {\tt Examples/ex\_makefile} provides another
192example makefile.
193
194\subsection{the runcxx program}
195\index{runcxx}
196{\bf runcxx} is a simple program which can be used to compile, link
197and run simple C++ programs. It handles the creation of a
198complete program file, containing the basic set C++ include files,
199the necessary include files for SOPHYA SysTools, TArray, HiStats
200and NTools modules, and the main program with exception handling.
201Other Sophya modules can be included using the {\tt -import} flag.
202Use of additional include files can be specified using the
203{\tt -inc} flag.
204\begin{verbatim}
205csh> runcxx -h
206SOPHYA Version 1.1 Revision 0 (V_Fev2001) -- Feb 28 2001 11:19:17 cxx
207 runcxx : compiling and running of a piece of C++ code
208 Usage: runcxx [-compopt CompileOptions] [-linkopt LinkOptions]
209 [-tmpdir TmpDirectory] [-f C++CodeFileName]
210 [-inc includefile] [-inc includefile ...]
211 [-import modulename] [-import modulename ...]
212 [-uarg UserArg1 UserArg2 ...]
213 if no file name is specified, read from standard input
214 modulenames: SkyMap, Samba, SkyT, FitsIOServer, LinAlg, IFFTW
215\end{verbatim}
216Most examples in this manual can be tested using runcxx. The
217example below shows how to compile, link and run a sample
218code.
219\begin{verbatim}
220// File example.icc
221Matrix a(3,3);
222a = IdentityMatrix(1.);
223cout << a ;
224// Executing this sample code
225csh> runcxx -f example.icc
226\end{verbatim}
227
228\newpage
229
230\section{Copy constructor and assignment operator}
231In C++, objects can be copied by assignment or by initialisation.
232Copying by initialisation corresponds to creating an object and
233initialising its value through the copy constructor.
234The copy constructor has its first argument as a reference, or
235const reference to the object's class type. It can have
236more arguments, if default values are provided.
237Copying by assignment applies to an existing object and
238is performed through the assignment operator (=).
239The copy constructor implements this for identical type objects:
240\begin{verbatim}
241class MyObject {
242public:
243 MyObject(); // Default constructor
244 MyObject(MyObject const & a); // Copy constructor
245 MyObject & operator = (MyObject const & a) // Assignment operator
246}
247\end{verbatim}
248The copy constructors play an important role, as they are
249called when class objects are passed by value,
250returned by value, or thrown as an exception.
251\begin{verbatim}
252// A function declaration with an argument of type MyObject,
253// passed by value, and returning a MyObject
254MyObject f(MyObject x)
255{
256 MyObject r;
257 ...
258 return(r); // Copy constructor is called here
259}
260// Calling the function :
261MyObject a;
262f(a); // Copy constructor called for a
263\end{verbatim}
264It should be noted that the C++ syntax is ambiguous for the
265assignment operator. {\tt MyObject x; x=y; } and
266{\tt MyObject x=y;} have different meaning.
267\begin{verbatim}
268MyObject a; // default constructor call
269MyObject b(a); // copy constructor call
270MyObject bb = a; // identical to bb(a) : copy constructor call
271MyObject c; // default constructor call
272c = a; // assignment operator call
273\end{verbatim}
274
275As a general rule in SOPHYA, objects which implements
276reference sharing on their data members have a copy constructor
277which shares the data, while the assignment operator copies or
278duplicate the data.
279
280\newpage
281\section{Module SysTools}
282
283{\bf SysTools} contains utility classes such as {\tt DataCards} or
284{\tt DVlist}, an hierarchy of exception classes for Sophya, a template
285class {\tcls{NDataBlock}} for handling reference counting on numerical
286arrays, as well as classes providing the services for implementing simple
287serialisation.
288\vspace*{5mm}
289
290\subsection{SOPHYA persistence}
291\index{PPersist} \index{PInPersist} \index{POutPersist}
292\begin{figure}[hbt]
293\dclsa{PPersist}
294\dclsbb{PIOPersist}{PInPersist}
295\dclsb{POutPersist}
296\caption{partial class diagram for classes handling persistence in Sophya}
297\end{figure}
298A simple persistence mechanism is defined in SOPHYA. Its main
299features are:
300\begin{itemize}
301\item[] Portable file format, containing the description of the data structures
302and object hierarchy. \\
303{\bf PPF} {\bf P}ortable {\bf P}ersistence file {\bf F}ormat.
304\item[] Handling of read/write for multiply referenced objects.
305\item[] All write operations are carried using sequential access only. This
306holds also for read operations, unless positional tags are used.
307SOPHYA persistence services can thus be used to transfer objects
308through network links.
309\item[] The serialisation (reading/writing) for objects for a given class
310is implemented through a handler object. The handler class inherits
311from {\tt PPersist} class.
312\item[] A run time registration mechanism is used in conjunction with
313RTTI (Run Time Type Identification) for identifying handler classes
314when reading {\bf PInPersist} streams, or for associating handlers
315with data objects {\bf AnyDataObject} for write operations.
316\end{itemize}
317A complete description of SOPHYA persistence mechanism and guidelines
318for writing delegate classes for handling object persistence is beyond
319the scope of this document. The most useful methods for using Sophya
320persistence are listed below:
321\begin{itemize}
322\item[] {\tt POutPersist::PutObject(AnyDataObj \& o)} \\
323Writes the data object {\bf o} to the output stream.
324\item[] {\tt POutPersist::PutObject(AnyDataObj \& o, string tagname)} \\
325Writes the data object {\bf o} to the output stream, associated with an
326identification tag {\bf tagname}.
327\item[] {\tt PInPersist::GetObject(AnyDataObj \& o)} \\
328Reads the next object in stream into {\bf o}. An exception is
329generated for incompatible object types.
330\item[] {\tt PInPersist::GetObject(AnyDataObj \& o, string tagname)} \\
331Reads the object associated with the tag {\bf tagname} into {\bf o}.
332An exception is generated for incompatible object types.
333\end{itemize}
334The operators {\tt operator << (POutPersist ...) } and
335{\tt operator >> (PInPersist ...) } are often overloaded
336to perform {\tt PutObject()} and {\tt GetObject()} operations,
337as illustrated in the example below:
338\begin{verbatim}
339// Creating and filling a histogram
340Histo hw(0.,10.,100);
341...
342// Writing histogram to a PPF stream
343POutPersist os("hw.ppf");
344os << hw;
345// Reading a histogram from a PPF stream
346PInPersist is("hr.ppf");
347is >> hr;
348\end{verbatim}
349
350The {\bf scanppf} program can be used to list the content of a PPF file.
351\index{scanppf}
352\begin{verbatim}
353csh> scanppf -h
354SOPHYA Version 1.1 Revision 0 (V_Fev2001) -- Feb 28 2001 11:19:17 cxx
355 Usage: scanppf filename [s/n/a0/a1/a2/a3]
356 s[=default} : Sequential reading of objects
357 n : Object reading at NameTags
358 a0...a3 : Tag List with PInPersist.AnalyseTags(0...3)
359\end{verbatim}
360
361
362\subsection{\tcls{NDataBlock}}
363\index{\tcls{NDataBlock}}
364\begin{figure}[hbt]
365\dclsbb{AnyDataObj}{\tcls{NDataBlock}}
366\dclsbb{PPersist}{\tcls{FIO\_NDataBlock}}
367\end{figure}
368The {\bf \tcls{NDataBlock}} is designed to handle reference counting
369and sharing of memory blocs (contiguous arrays) for numerical data
370types. Initialisation, resizing, basic arithmetic operations, as
371well as persistence handling services are provided.
372The persistence handler class ({\tt \tcls{FIO\_NDataBlock}}) insures
373that a single copy of data is written for multiply referenced objects,
374and the data is shared among objects when reading.
375\par
376The example below shows writing of NDataBlock objects through the
377use of overloaded operator $ << $ :
378\begin{verbatim}
379#include "fiondblock.h"
380// ...
381POutPersist pos("aa.ppf");
382NDataBlock<r_4> rdb(40);
383rdb = 567.89;
384pos << rdb;
385// We can also use the PutObject method
386NDataBlock<int_4> idb(20);
387idb = 123;
388pos.PutObject(idb);
389\end{verbatim}
390The following sample programs show the reading of the created PPF file :
391\begin{verbatim}
392PInPersist pis("aa.ppf");
393NDataBlock<r_4> rdb;
394pis >> rdb;
395cout << rdb;
396NDataBlock<int_4> idb;
397cout << idb;
398\end{verbatim}
399
400\subsection{Using DVList}
401\index{DVList} \index{MuTyV}
402\begin{figure}[hbt]
403\dclsbb{AnyDataObj}{DVList}
404\dclsbb{PPersist}{\tclsc{ObjFileIO}{DVList}}
405\end{figure}
406The {\bf DVList} class objects can be used to create and manage list
407of values, associated with names. A list of pairs of (MuTyV, name(string))
408is maintained by DVList objects. {\bf MuTyV} is a simple class
409capable of holding string, integer, float or complex values,
410providing easy conversion methods between these objects.
411\begin{verbatim}
412// Using MuTyV objects
413MuTyV s("hello"); // string type value
414MuTyV x;
415x = "3.14159626"; // string type value, ASCII representation for Pi
416double d = x; // x converted to double = 3.141596
417x = 314; // x contains the integer value = 314
418// Using DVList
419DVList dvl;
420dvl("Pi") = 3.14159626; // float value, named Pi
421dvl("Log2") = 0.30102999; // float value, named Log2
422dvl("FileName") = "myfile.fits"; // string value, named myfile.fits
423// Printing DVList object
424cout << dvl;
425\end{verbatim}
426
427\subsection{Using DataCards}
428\index{DataCards}
429The {\bf DataCards} class can be used to read parameters from a file.
430Each line in the file starting with \@ defines a set of values
431associated with a keyword. In the example below, we read the
432parameters corresponding with the keyword {\tt SIZE} from the
433file {\tt ex.d}. We suppose that {\tt ex.d} contains the line: \\
434{\tt @SIZE 400 250} \\
435\begin{verbatim}
436#include "datacards.h"
437// ...
438// Initialising DataCards object dc from file ex.d
439DataCards dc( "ex.d" );
440// Getting the first and second parameters for keyword size
441// We define a default value 100
442int size_x = dc.IParam("SIZE", 0, 100);
443int size_y = dc.IParam("SIZE", 1, 100);
444cout << " size_x= " << size_x << " size_y= " << size_y << endl;
445\end{verbatim}
446
447\subsection{Dynamic linker}
448\index{PDynLinkMgr}
449The class {\bf PDynLinkMgr} can be used for managing shared libraries
450at run time. The example below shows the run time linking of a function:\\
451{\tt extern "C" { void myfunc(); } } \\
452\begin{verbatim}
453#include "pdlmgr.h"
454// ...
455string soname = "mylib.so";
456string funcname = "myfunc";
457PDynLinkMgr dyl(soname);
458DlFunction f = dyl.GetFunction(funcname);
459if (f != NULL) {
460// Calling the function
461 f();
462}
463\end{verbatim}
464
465\subsection{CxxCompilerLinker class}
466\index{CxxCompilerLinker}
467This class provides the services to compile C++ code and building
468shared libraries, using the same compiler and options which have
469been used to create the SOPHYA shared library.
470The sample program below illustrates using this class to build
471the shared library (myfunc.so) from the source file myfunc.cc :
472\begin{verbatim}
473#include "cxxcmplnk.h"
474// ...
475string flnm = "myfunc.cc";
476string oname, soname;
477int rc;
478CxxCompilerLinker cxx;
479// The Compile method provides a default object file name
480rc = cxx.Compile(flnm, oname);
481if (rc != 0 ) { // Error when compiling ... }
482// The BuildSO method provides a default shared object file name
483rc = cxx.BuildSO(oname, soname);
484if (rc != 0 ) { // Error when creating shared object ... }
485\end{verbatim}
486
487\newpage
488\section{Module TArray}
489\index{\tcls{TArray}}
490{\bf TArray} module contains template classes for handling standard
491operations on numerical arrays. Using the class {\tt \tcls{TArray} },
492it is possible to create and manipulate up to 5-dimension numerical
493arrays {\tt (int, float, double, complex, \ldots)}. The include
494file {\tt array.h} declares all the classes and definitions
495in module TArray. {\bf Array} is a typedef for arrays
496with double precision floating value elements. \\
497{\tt typedef TArray$<$r\_8$>$ Array ; }
498
499\begin{figure}[hbt]
500\dclsccc{AnyDataObj}{BaseArray}{\tcls{TArray}}
501\dclsbb{PPersist}{\tcls{FIO\_TArray}}
502\end{figure}
503
504
505\subsection{Using arrays}
506\index{Sequence} \index{RandomSequence} \index{RegularSequence}
507\index{EnumeratedSequence}
508The example below shows basic usage of arrays, creation, initialisation
509and arithmetic operations. Different kind of {\bf Sequence} objects
510can be used for initialising arrays.
511
512\begin{figure}[hbt]
513\dclsbb{Sequence}{RandomSequence}
514\dclsb{RegularSequence}
515\dclsb{EnumeratedSequence}
516\end{figure}
517
518The example below shows basic usage of arrays:
519\index{\tcls{TArray}}
520\begin{verbatim}
521// Creating and initialising a 1-D array of integers
522TArray<int> ia(5);
523EnumeratedSequence es;
524es = 24, 35, 46, 57, 68;
525ia = es;
526cout << "Array<int> ia = " << ia;
527// 2-D array of floats
528TArray<r_4> b(6,4), c(6,4);
529// Initializing b with a constant
530b = 2.71828;
531// Filling c with random numbers
532c = RandomSequence();
533// Arithmetic operations
534TArray<r_4> d = b+0.3f*c;
535cout << "Array<float> d = " << d;
536\end{verbatim}
537
538The copy constructor shares the array data, while the assignment operator
539copies the array elements, as illustrated in the following example:
540\begin{verbatim}
541TArray<int> a1(4,3);
542a1 = RegularSequence(0,2);
543// Array a2 and a1 shares their data
544TArray<int> a2(a1);
545// a3 and a1 have the same size and identical elements
546TArray<int> a3;
547a3 = a1;
548// Changing one of the a2 elements
549a2(1,1,0) = 555;
550// a1(1,1) is also changed to 555, but not a3(1,1)
551cout << "Array<int> a1 = " << a1;
552cout << "Array<int> a3 = " << a3;
553\end{verbatim}
554
555\subsection{Matrices and vectors}
556\index{\tcls{TMatrix}} \index{\tcls{TVector}}
557\begin{figure}[hbt]
558\dclsccc{\tcls{TArray}}{\tcls{TMatrix}}{\tcls{TVector}}
559\end{figure}
560Vectors and matrices are 2 dimensional arrays. The array size
561along one dimension is equal 1 for vectors. Column vectors
562have {\tt NCols() = 1} and row vectors have {\tt NRows() = 1}.
563Mathematical expressions involving matrices and vectors can easily
564be translated into C++ code using {\tt TMatrix} and
565{\tt TVector} objects. {\bf Matrix} and {\bf Vector} are
566typedefs for double precision float matrices and vectors.
567The operator {\bf *} beteween matrices is redefined to
568perform matrix multiplication. One can then write: \\
569\begin{verbatim}
570 // We create a row vector
571 Vector v(1000, BaseArray::RowVector);
572 // Initialize values with a random sequence
573 v = RandomSequence();
574 // Compute the vector length (norm)
575 double norm = (v*v.Transpose()).toScalar();
576 cout << "Norm(v) = " << norm << endl;
577\end{verbatim}
578
579This module contains basic array and matrix operations
580such as the Gauss matrix inversion algorithm
581which can be used to solve linear systems, as illustrated by the
582example below:
583\begin{verbatim}
584#include "sopemtx.h"
585// ...
586// Creation of a random 5x5 matrix
587Matrix A(5,5);
588A = RandomSequence(RandomSequence::Flat);
589Vector X0(5);
590X0 = RandomSequence(RandomSequence::Gaussian);
591// Computing B = A*X0
592Vector B = A*X0;
593// Solving the system A*X = B
594Vector X;
595LinSolve(A, B, X);
596// Checking the result
597Vector diff = X-X0;
598cout << "X-X0= " << diff ;
599double min,max;
600diff.MinMax(min, max);
601cout << " Min(X-X0) = " << min << " Max(X-X0) = " << max << endl;
602\end{verbatim}
603
604\subsection{Working with sub-arrays and Ranges}
605\index{Range}
606A powerful mechanism is included in array classes for working with
607sub-arrays. The class {\bf Range} can be used to specify range of array
608indexes in any of the array dimensions. Any regularly spaced index
609range can be specified, using the {\tt start} and {\tt end} index
610and an optional step (or stride). It is also possible to specify
611the {\tt start} index and the number of elements.
612In the following example, a simple low-pas filter, on a one
613dimensional stream (Vector) has been written using sub-arrays:
614
615\begin{verbatim}
616// Input Vector containing a noisy periodic signal
617 Vector in(1024), out(1024);
618 in = RandomSequence(RandomSequence::Gaussian, 0., 1.);
619 for(int kk=0; kk<in.Size(); kk++)
620 in(kk) += 2*sin(kk*0.05);
621// Compute the output vector by a simple low pass filter
622 Vector out(1024);
623 int w = 2;
624 for(int k=w; k<in.Size()-w; k++)
625 out(k) = in(Range(k-w, k+w).Sum()/(2.*w+1.);
626\end{verbatim}
627
628\subsection{Memory organisation}
629{\tt \tcls{TArray} } can handle numerical arrays with various memory
630organisation, as long as the spacing (steps) along each axis is
631regular. The five axis are labeled X,Y,Z,T,U. The examples below
632illustrates the memory location for a 2-dimensional, $N_x=4 \times N_y=3$.
633The first index is along the X axis and the second index along the Y axis.
634\begin{verbatim}
635 | (0,0) (0,1) (0,2) (0,3) |
636 | (1,0) (1,1) (1,2) (1,3) |
637 | (2,0) (2,1) (2,2) (2,3) |
638\end{verbatim}
639In the first case, the array is completely packed
640($Step_X=1, Step_Y=N_X=4$), with zero offset,
641while in the second case, $Step_X=2, Step_Y=10, Offset=10$:
642\begin{verbatim}
643 | 0 1 2 3 | | 10 12 14 16 |
644Ex1 | 4 5 6 7 | Ex2 | 20 22 24 26 |
645 | 8 9 10 11 | | 30 32 34 36 |
646\end{verbatim}
647
648For matrices and vectors, an optional argument ({\tt MemoryMapping})
649can be used to select the memory mapping, where two basic schemes
650are available: \\
651{\tt CMemoryMapping} and {\tt FortranMemoryMapping}. \\
652In the case where {\tt CMemoryMapping} is used, a given matrix line
653is packed in memory, while the columns are packed when
654{\tt FortranMemoryMapping} is used. The first index when addressing
655the matrix elements (line number index) runs along
656the Y-axis if {\tt CMemoryMapping} is used, and along the X-axis
657in the case of {\tt FortranMemoryMapping}.
658Arithmetic operations between matrices
659with different memory organisation is allowed as long as
660the two matrices have the same sizes (Number of rows and columns).
661The following code example and the corresponding output illustrates
662these two memory mappings. The {\tt \tcls{TMatrix}::TransposeSelf() }
663method changes effectively the matrix memory mapping, which is also
664the case of {\tt \tcls{TMatrix}::Transpose() } method without argument.
665
666\begin{verbatim}
667TArray<r_4> X(4,2);
668X = RegularSequence(1,1);
669cout << "Array X= " << X << endl;
670TMatrix<r_4> X_C(X, true, BaseArray::CMemoryMapping);
671cout << "Matrix X_C (CMemoryMapping) = " << X_C << endl;
672TMatrix<r_4> X_F(X, true, BaseArray::FortranMemoryMapping);
673cout << "Matrix X_F (FortranMemoryMapping) = " << X_F << endl;
674\end{verbatim}
675This code would produce the following output (X\_F = Transpose(X\_C)) :
676\begin{verbatim}
677Array X=
678--- TArray<f> ND=2 SizeX*Y*...= 4x2 ---
6791, 2, 3, 4
6805, 6, 7, 8
681
682Matrix X_C (CMemoryMapping) =
683--- TMatrix<f>(NRows=2, NCols=4) ND=2 SizeX*Y*...= 4x2 ---
6841, 2, 3, 4
6855, 6, 7, 8
686
687Matrix X_F (FortranMemoryMapping) =
688--- TMatrix<f>(NRows=4, NCols=2) ND=2 SizeX*Y*...= 4x2 ---
6891, 5
6902, 6
6913, 7
6924, 8
693\end{verbatim}
694
695\newpage
696
697\section{Module HiStats}
698\begin{figure}[hbt]
699\dclsccc{AnyDataObj}{Histo}{HProf}
700\dclsbb{AnyDataObj}{Histo2D}
701\dclsbb{AnyDataObj}{Ntuple}
702\dclsb{XNtuple}
703\caption{partial class diagram for histograms and ntuples}
704\end{figure}
705
706{\bf HiStats} contains classes for creating, filling, printing and
707doing various operations on one or two dimensional histograms
708{\tt Histo} and {\tt Histo2D} as well as profile histograms {\tt HProf}. \\
709This module also contains {\tt NTuple} and {\tt XNTuple} which are
710more or less the same that the binary FITS tables.
711
712\subsection{1D Histograms}
713\index{Histo}
714For 1D histograms, various numerical methods are provided such as
715computing means and sigmas, finding maxima, fitting, rebinning,
716integrating \dots \\
717The example below shows creating and filling a one dimensional histogram
718of 100 bins from $-5.$ to $+5.$ to create a Gaussian normal distribution
719with errors~:
720\begin{verbatim}
721#include "histos.h"
722// ...
723Histo H(-0.5,0.5,100);
724H.Errors();
725for(int i=0;i<25000;i++) {
726 double x = NorRand();
727 H.Add(x);
728}
729H.Print(80);
730\end{verbatim}
731
732\subsection{2D Histograms}
733\index{Histo2D}
734Much of these operations are also valid for 2D histograms. 1D projection
735or slices can be set~:
736\begin{verbatim}
737#include "histos2.h"
738// ...
739Histo2D H2(-1.,1.,100,0.,60.,50);
740H2.SetProjX(); // create the 1D histo for X projection
741H2.SetBandX(25.,35.); // create 1D histo projection for 25.<y<35.
742H2.SetBandX(35.,45.); // create 1D histo projection for 35.<y<45.
743H2.SetBandX(40.,55.); // create 1D histo projection for 40.<y<55.
744//... fill H2 with what ever you want
745H2.Print();
746Histo *hx = H2.HProjX();
747 hx->Print(80);
748Histo *hbx2 = HBandX(1); // Get the second X band (35.<y<45.)
749 hbx2->Print(80);
750\end{verbatim}
751
752\subsection{Profile Histograms}
753\index{HProf}
754Profiles histograms {\bf HProf} contains the mean and the
755sigma of the distribution
756of the values filled in each bin. The sigma can be changed to
757the error on the mean. When filled, the profile histogram looks
758like a 1D histogram and much of the operations that can be done on 1D histo
759may be applied onto profile histograms.
760
761\subsection{Data tables (tuples)}
762\index{NTuple}
763NTuple are memory resident tables of 32 bits floating values (float).
764They are arranged in columns. Each line is often called an event.
765These objects are frequently used to analyze data.
766Graphicals tools (spiapp) can plot a column against an other one
767with respect to various selection cuts. \\
768Here is an example of creation and filling~:
769\begin{verbatim}
770#include "ntuple.h"
771#include "srandgen.h"
772// ...
773char* nament[4] = {"i","x","y","ey"};
774r_4 xnt[4];
775NTuple NT(4,nament);
776for(i=0;i<5000;i++) {
777 xnt[0] = i+1;
778 xnt[1] = 5.*drandpm1(); // a random value between -5 and +5
779 xnt[2] = 100.*exp(-0.5*xnt[1]*xnt[1]) + 1.;
780 xnt[3] = sqrt(xnt[2]);
781 xnt[2] += xnt[3] * NorRand(); // add a random gaussian error
782 NT.Fill(xnt);
783}
784\end{verbatim}
785
786XNTuple are sophisticated NTuple : they accept various types
787of column values (double,float,int,string,...) and can handle
788very large data sets, through swap space on disk.
789\index{XNTuple}
790In the sample code below we show how to create a XNTuple
791object with four columns (double, double, int, string).
792Several entries (lines) are then appended to the table,
793which is saved to a PPF file.
794\begin{verbatim}
795#include "xntuple.h"
796// ...
797char * names[4] = {"X", "X2", "XInt","XStr"};
798// XNTuple (Table) creation with 4 columns, of integer,
799// double(2) and string type
800XNTuple xnt(2,0,1,1, names);
801// Filling the NTuple
802r_8 xd[2];
803int_4 xi[2];
804char xss[2][32];
805char * xs[2] = {xss[0], xss[1]} ;
806for(int i=0; i<50; i++) {
807 xi[0] = i; xd[0] = i+0.5; xd[1] = xd[0]*xd[0];
808 sprintf(xs[0],"X=%g", xd[0]);
809 xnt.Fill(xd, NULL, xi, xs);
810}
811// Printing table info
812cout << xnt ;
813// Saving object into a PPF file
814POutPersist po("xnt.ppf");
815po << xnt ;
816\end{verbatim}
817
818\subsection{Writing, viewing \dots }
819
820All these objects have been design to be written to or read from a persistent file.
821The following example shows how to write the previously created objects
822into such a file~:
823\begin{verbatim}
824//-- Writing
825{
826char *fileout = "myfile.ppf";
827string tag;
828POutPersist outppf(fileout);
829tag = "H"; outppf.PutObject(H,tag);
830tag = "H2"; outppf.PutObject(H2,tag);
831tag = "NT"; outppf.PutObject(NT,tag);
832} // closing ``}'' destroy ``outppf'' and automatically close the file !
833\end{verbatim}
834
835Sophya graphical tools (spiapp) can automatically display and operate
836all these objects.
837
838\newpage
839\section{Module NTools}
840
841This module provides elementary numerical tools for numerical integration,
842fitting, sorting and ODE solving. FFTs are also provided (Mayer,FFTPack).
843
844\subsection{Fitting}
845\index{Fitting} \index{Minimisation}
846Fitting is done with two classes {\tt GeneralFit} and {\tt GeneralFitData}
847and is based on the Levenberg-Marquardt method.
848\index{GeneralFit} \index{GeneralFitData}
849GeneralFitData is a class which provide a description of the data
850to be fitted. GeneralFit is the fitter class. Parametrized functions
851can be given as classes which inherit {\tt GeneralFunction}
852or as simple C functions. Classes of pre-defined functions are provided
853(see files fct1dfit.h and fct2dfit.h). The user interface is very close
854from that of the CERN {\tt Minuit} fitter.
855Number of objects (Histo, HProf \dots ) are interfaced with GeneralFit
856and can be easily fitted. \\
857Here is a very simple example for fitting the previously created NTuple
858with a Gaussian~:
859\begin{verbatim}
860#include "fct1dfit.h"
861// ...
862
863// Read from ppf file
864NTuple nt;
865{
866PInPersist pis("myfile.ppf");
867string tag = "NT"; pis.GetObject(nt,tag);
868}
869
870// Fill GeneralData
871GeneralData mGdata(nt.NEntry());
872for(int i=0; i<nt.NEntry(); i++)
873 mGdata.AddData1(xnt[1],xnt[2],xnt[3]); // Fill x, y and error on y
874mGData.PrintStatus();
875
876// Function for fitting : y = f(x) + noise
877Gauss1DPol mFunction; // gaussian + constant
878
879// Prepare for fit
880GeneralFit mFit(&mFunction); // create a fitter for the choosen function
881mFit.SetData(&mGData); // connect data to the fitter
882
883// Set and initialise the parameters (that's non-linear fitting!)
884// (num par, name, guess start, step, [limits min and max])
885mFit.SetParam(0,"high",90.,1..);
886mFit.SetParam(1,"xcenter",0.05,0.01);
887mFit.SetParam(2,"sigma",sig,0.05,0.01,10.);
888 // Give limits to avoid division by zero
889mFit.SetParam(3,"constant",0.,1.);
890
891// Fit and print result
892int rcfit = mFit.Fit();
893mFit.PrintFit();
894if(rcfit>0) {)
895 cout<<"Reduce_Chisquare = "<<mFit.GetChi2Red()
896 <<" nstep="<<mFit.GetNStep()<<" rc="<<rcfit<<endl;
897} else {
898 cout<<"Fit_Error, rc = "<<rcfit<<" nstep="<<mFit.GetNStep()<<endl;
899 mFit.PrintFitErr(rcfit);
900}
901
902// Get the result for further use
903TVector<r_8> ParResult = mFit.GetParm();
904cout<<ParResult;
905\end{verbatim}
906
907Much more usefull possibilities and detailed informations might be found
908in the HTML pages of the Sophya manual.
909
910\subsection{Polynomial}
911\index{Polynomial} \index{Poly} \index{Poly2}
912Polynomials of 1 or 2 variables are supported ({\tt Poly} and {\tt Poly2}).
913Various operations are supported~:
914\begin{itemize}
915\item elementary operations between polynomials $(+,-,*,/) $
916\item setting or getting coefficients
917\item computing the value of the polynomial for a given value
918 of the variable(s),
919\item derivating
920\item computing roots (degre 1 or 2)
921\item fitting the polynomial to vectors of data.
922\end{itemize}
923Here is an example of polynomial fitting~:
924\begin{verbatim}
925#include "poly.h"
926// ...
927Poly pol(2);
928pol[0] = 100.; pol[1] = 0.; pol[2] = 0.01; // Setting coefficients
929TVector<r_8> x(100);
930TVector<r_8> y(100);
931TVector<r_8> ey(100);
932for(int i=0;i<100;i++) {
933 x(i) = i;
934 ey(i) = 10.;
935 y(i) = pol((double) i) + ey(i)*NorRand();
936 ey(i) *= ey(i)
937}
938
939TVector<r_8> errcoef;
940Poly polfit;
941polfit.Fit(x,y,ey,2,errcoef);
942
943cout<<"Fit Result"<<polfit<<endl;
944cout<<"Errors :"<<errcoef;
945\end{verbatim}
946
947Similar operations can be done on polynomials with 2 variables.
948
949\subsection{Integration, Differential equations}
950\index{Integration}
951The NTools module provide also simple classes for numerical integration
952of functions and differential equations.
953\begin{figure}[hbt]
954\dclsbb{Integrator}{GLInteg}
955\dclsb{TrpzInteg}
956\end{figure}
957
958\index{GLInteg} \index{TrpzInteg}
959{\bf GLInteg} implements the integration through Gauss-Legendre method
960and {\bf TrpzInteg} implements trapeze integration. For {\bf TrpzInteg},
961number of steps specify the number of trapeze, and integration step,
962their width.
963The sample code below illustrates the use of TrpzInteg class:
964\begin{verbatim}
965#include "integ.h"
966// ......................................................
967// Function to be integrated
968double myf(double x)
969{
970// Simple a x + b x^2 (a=2 b=3)
971return (x*(2.+3.*x));
972}
973// ......................................................
974
975// Compute Integral(myf, 2., 5.) between xmin=2., xmax=5.
976TrpzInteg trpz(myf, 2., 5.);
977// We specify an integration step
978trpz.DX(0.01);
979// The integral can be computed as trpz.Value()
980double myf_integral = trpz.Value();
981// We could have used the cast operator :
982cout << "Integral[myf, 2., 5.]= " << (double)trpz << endl;
983// Limits can be specified through ValueBetween() method
984cout << "Integral[myf, 0., 4.]= " << trpz.ValueBetween(0.,4.) << endl;
985\end{verbatim}
986
987\subsection{Fourier transform (FFT)}
988\index{FFT} \index{FFTPackServer}
989An abstract interface for performing FFT operations is defined by the
990{\bf FFTServerInterface} class. The {\bf FFTPackSever} class implements
991one dimensional FFT, on real and complex data. FFTPackServer uses an
992adapted and extended version of FFTPack (available from netlib),
993translated in C, and can operate on single and double precision
994({\tt float, double}) data.
995
996The sample code below illustrates the use of FFTServers:
997\begin{verbatim}
998#include "fftpserver.h"
999 // ...
1000TVector<r_8> in(32);
1001TVector< complex<r_8> > out;
1002in = RandomSequence();
1003FFTPackServer ffts;
1004ffts.setNormalize(true); // To have normalized transforms
1005cout << " FFTServer info string= " << ffts.getInfo() << endl;
1006cout << "in= " << in << endl;
1007cout << " Calling ffts.FFTForward(in, out) : " << endl;
1008ffts.FFTForward(in, out);
1009cout << "out= " << out << endl;
1010\end{verbatim}
1011
1012\newpage
1013\section{Module SkyMap}
1014\begin{figure}[hbt]
1015\dclsbb{AnyDataObj}{PixelMap}
1016\dclsccc{PixelMap}{Sphericalmap}{SphereHEALPix}
1017\dclsc{SphereThetaPhi}
1018\dclsb{LocalMap}
1019\caption{partial class diagram for pixelization classes in Sophya}
1020\end{figure}
1021The {\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.
1022\subsection {Spherical maps}
1023There are two kinds of spherical maps according pixelization algorithms. SphereHEALPix represents spheres pixelized following the HEALPIix algorithm (E. Hivon, K. Gorski)
1024\footnote{see the HEALPix Homepage: http://www.eso.org/kgorski/healpix/ }
1025, 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) :
1026\index{\tcls{SphereHEALPix}}
1027\index{\tcls{SphereThetaPhi}}
1028
1029\begin{verbatim}
1030#include "spherehealpix.h"
1031// ...
1032SphereHEALPix<double> sph(8);
1033for (int k=0; k< sph.NbPixels(); k++) sph(k) = (double)(10*k);
1034\end{verbatim}
1035
1036SphereThetaPhi is used in a similar way with an argument representing number of slices in theta (Euler angle) for an hemisphere.
1037\index{\tcls{SphereThetaPhi}}
1038
1039\subsection {Local maps}
1040\index{\tcls{LocalMap}}
1041A 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).
1042
1043Internally, 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(...))
1044
1045The 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).
1046\begin{verbatim}
1047#include "localmap.h"
1048//..............
1049 LocalMap<r_4> locmap(4,5);
1050 for (int k=0; k<locmap.NbPixels();k++) locmap(k)=10.*k;
1051 locmap.SetOrigin();
1052 locmap.SetSize(30.,30.);
1053\end{verbatim}
1054
1055\subsection{Writing, viewing \dots }
1056
1057All these objects have been design to be written to or read from a persistant file.
1058The following example shows how to write the previously created objects
1059into such a file~:
1060\begin{verbatim}
1061//-- Writing
1062
1063#include "fiospherehealpix.h"
1064//................
1065
1066char *fileout = "myfile.ppf";
1067POutPersist outppf(fileout);
1068FIO_SphereHEALPix<r_8> outsph(sph);
1069outsph.Write(outppf);
1070FIO_LocalMap<r_8> outloc(locmap);
1071outloc.Write(outppf);
1072// It is also possible to use the << operator
1073POutPersist os("sph.ppf");
1074os << outsph;
1075os << outloc;
1076\end{verbatim}
1077
1078Sophya graphical tools (spiapp) can automatically display and operate
1079all these objects.
1080
1081\newpage
1082\section{Module Samba}
1083\index{Spherical Harmonics}
1084\index{SphericalTransformServer}
1085The 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...
1086\begin{verbatim}
1087#include "skymap.h"
1088#include "samba.h"
1089....................
1090
1091// Generate input spectra a + b* l + c * gaussienne(l, 50, 20)
1092int lmax = 92;
1093Vector clin(lmax);
1094for(int l=0; l<lmax; l++) {
1095 double xx = (l-50.)/10.;
1096 clin(l) = 1.e-2 -1.e-4*l + 0.1*exp(-xx*xx);
1097}
1098
1099// Compute map from spectra
1100SphericalTransformServer<r_8> ylmserver;
1101int m = 128; // HealPix pixelisation parameter
1102SphereHEALPix<r_8> map(m);
1103ylmserver.GenerateFromCl(map, m, clin, 0.);
1104// Compute power spectrum from map
1105Vector clout = ylmserver.DecomposeToCl(map, lmax, 0.);
1106\end{verbatim}
1107
1108\newpage
1109\section{Module SkyT}
1110\index{RadSpectra} \index{SpectralResponse}
1111The SkyT module is composed of two types of classes:
1112\begin{itemize}
1113\item{} one which corresponds to an emission spectrum of
1114radiation, which is called RadSpectra
1115\item{} one which corresponds to the spectral response
1116of a given detector (i.e. corresponding to a detector
1117filter in a given frequency domain), which is called
1118SpectralResponse.
1119\end{itemize}
1120\begin{figure}[hbt]
1121\dclsbb{RadSpectra}{RadSpectraVec}
1122\dclsb{BlackBody}
1123\dclsccc{AnyDataObj}{SpectralResponse}{SpecRespVec}
1124\dclsc{GaussianFilter}
1125\caption{partial class for SkyT module}
1126\end{figure}
1127
1128\begin{verbatim}
1129#include "skyt.h"
1130// ....
1131// Compute the flux from a blackbody at 2.73 K through a square filter
1132BlackBody myBB(2.73);
1133// We define a square filter from 100 - 200 GHz
1134SquareFilter mySF(100,200);
1135// Compute the filtered integrated flux :
1136double flux = myBB.filteredIntegratedFlux(mySF);
1137\end{verbatim}
1138
1139A more detailed description of SkyT module can be found in:
1140{\it The SkyMixer (SkyT and PMixer modules) - Sophya Note No 2. }
1141available also from Sophya Web site.
1142
1143\newpage
1144\section{Module FitsIOServer}
1145\begin{figure}[hbt]
1146\dclsbb{FitsFile}{FitsInFile}
1147\dclsb{FitsOutFile}
1148\end{figure}
1149\index{FITS} \index{FitsInFile} \index{FitsOutFile}
1150This 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 :
1151\begin{verbatim}
1152#include "spherehealpix.h"
1153#include "fitsspherehealpix.h"
1154#include "fitstarray.h"
1155#include "tmatrix.h"
1156//...........................
1157
1158int m=...;
1159SphereHEALPix<r_8> sph(m);
1160................
1161int dim1=...;
1162int dim2=...;
1163TMatrix<r_8> mat(dim1,dim2);
1164............
1165
1166FITS_SphereHEALPix<r_8> sph_temp(sph);
1167FITS_TArray<r_8> mat_temp(mat);
1168// writing
1169
1170FitsOutFile os("myfile.fits");
1171sph_temp.Write(os);
1172mat_temp.Write(os);
1173
1174// reading
1175FitsInFile is("myfile.fits");
1176sph_temp.Read(is);
1177mat_temp.Read(is);
1178SphereHEALPix<r_8> new_sph=(SphereHEALPix<r_8>)sph_temp;
1179TMatrix<r_8> new_mat=(TMatrix<r_8>)mat_temp;
1180................
1181
1182\end{verbatim}
1183
1184The operators {\tt operator << (FitsOutFile ...)} and
1185{\tt operator >> (FitsInFile ...)} are defined in order
1186to facilitate the FITS file operations:
1187\begin{verbatim}
1188// Writing an array object to a FITS file
1189#include "fitstarray.h"
1190FitsOutFile fio("arr.fits");
1191Matrix m(20,30);
1192m = 12345.;
1193fio << m;
1194// .....
1195// Reading a binary table to a XNTuple
1196#include "fitsxntuple.h"
1197XNTuple xn;
1198FitsInFile fii("table.fits");
1199fii >> xn;
1200\end{verbatim}
1201
1202
1203\newpage
1204\section{LinAlg and IFFTW modules}
1205An interface to use LAPACK library (available from {\tt http://www.netlib.org})
1206is implemented by the {\bf LapackServer} class, in module LinAlg.
1207\index{LapackServer}.
1208The sample code below shows how to use SVD (Singular Value Decomposition)
1209through LapackServer:
1210\begin{verbatim}
1211#include "intflapack.h"
1212// ...
1213// Use FortranMemoryMapping as default
1214BaseArray::SetDefaultMemoryMapping(BaseArray::FortranMemoryMapping);
1215// Create an fill the arrays A and its copy AA
1216int n = 20;
1217Matrix A(n , n), AA;
1218A = RandomSequence(RandomSequence::Gaussian, 0., 4.);
1219AA = A; // AA is a copy of A
1220// Compute the SVD decomposition
1221Vector S; // Vector of singular values
1222Matrix U, VT;
1223LapackServer<r_8> lpks;
1224lpks.SVD(AA, S, U, VT);
1225// We create a diagonal matrix using S
1226Matrix SM(n, n);
1227for(int k=0; k<n; k++) SM(k,k) = S(k);
1228// Check the result : A = U*SM*VT
1229Matrix diff = U*(SM*VT) - A;
1230double min, max;
1231diff.MinMax(min, max);
1232cout << " Min/Max difference Matrix (?=0) , Min= " << min
1233 << " Max= " << max << endl;
1234\end{verbatim}
1235
1236\index{FFTWServer}
1237The {\bf FFTWServer} class (in module FFTW) implements FFTServerInterface class
1238methods, for one dimensional and multi-dimensional Fourier
1239transforms on double precision data using the FFTW package
1240(available from {\tt http://www.fftw.org}).
1241
1242\newpage
1243\section{Building and installing Sophya}
1244Presently, the Sophya library compilation has been tested with the following
1245compiler/platform pairs:
1246
1247\begin{center}
1248\begin{tabular}{ll}
1249Compaq/DEC OSF1 & cxx (6.0 , 6.2) \\
1250Linux & g++ (2.91 , 2.95) \\
1251Linux & KCC (3.4) \\
1252Solaris & g++ (2.95) \\
1253SGI IRIX64 & CC \\
1254\end{tabular}
1255\end{center}
1256
1257Some of the modules in the Sophya package uses external libraries. The
1258{\bf FitsIOServer} is the example of such a module, where the {\tt libcfitsio.a}
1259is used.
1260The build procedure expects to find the include files and the libraries in: \\
1261{\tt \$EXTLIBDIR/Include/FitsIO } \\
1262{\tt \$EXTLIBDIR/`uname`-\$EROSCXX/Libs} \\
1263
1264The object files from a given Sophya module are grouped in an archive library
1265with the module's name ({\tt libmodulename.a}). All Sophya modules
1266 are grouped in a single shared library ({\tt libsophya.so}), while the
1267modules with reference to external libraries are grouped in
1268({\tt libextsophya.so}). The {\bf PI} and {\bf PIext} modules are
1269grouped in ({\tt libPI.so}).
1270
1271The environment variables {\bf DPCDEVREP}, {\bf EXTLIBDIR} and {\bf EROSCXX}
1272must be defined in order to install the Sophya package.
1273In the example below, we assume that we want to install Sophya from a
1274released (tagged) version in the source directory {\tt \$SRC} in the
1275{\tt /usr/local/Sophya} diretory, using {\tt g++}. We assume that
1276the external libraries directory tree has been set up in
1277{\tt /usr/local/ExtLibs/}. \\[3mm]
1278\centerline{
1279 \rule{20mm}{0.5mm}
1280 {\bf \large the use of GNU make is mandatory}
1281 \rule{20mm}{0.5mm} }
1282
1283\vspace*{3mm}
1284\begin{verbatim}
1285# We select our C++ compiler
1286csh> setenv EROSCXX g++
1287# Setup the build directory
1288csh> mkdir /usr/local/Sophya/
1289csh> setenv DPCDEVREP /usr/local/Sophya/
1290csh> setenv EXTLIBDIR /usr/local/ExtLibs/
1291# Use the top level makefile in Mgr/
1292csh> cd \$SRC
1293csh> cp Mgr/Makefile Makefile
1294# Step 1: Create the directory tree and copy the include files (.h)
1295csh> make depend
1296# Step 2: Compile the modules without external library reference
1297csh> make libs
1298# Step 3: Compile the modules WITH external library reference (optional)
1299csh> make extlibs
1300# Step 4: Build libsophya.so
1301csh> make slb
1302# Step 5: Build libextsophya.so (optional)
1303csh> make slbext
1304# Step 6: Compile the PI and PIext modules (optional)
1305csh> make PI
1306# Step 7: Build the corresponding shared library libPI.so (optional)
1307csh> make slbpi
1308\end{verbatim}
1309
1310To compile all modules and build the shared libraries, it is possible
1311to use:
1312\begin{verbatim}
1313# Step 2,3,6
1314csh> make all
1315# Step 4,5,7
1316csh> make slball
1317\end{verbatim}
1318
1319At this step, all libraries should have been made. Programs using
1320Sophya libraries can now be built:
1321\begin{verbatim}
1322# To compile test programs
1323csh> cd Tests
1324csh> make arrt ...
1325csh> cd ..
1326# To compile other programs, for example from the PMixer module
1327csh> cd PMixer
1328csh> make
1329csh> cd ..
1330# To build (s)piapp (libPI.so is needed)
1331csh> cd ProgPI
1332csh> make
1333csh> cd ..
1334\end{verbatim}
1335
1336\subsection{Mgr module}
1337This module contains scripts which can be used for generating the
1338makefiles for each module.
1339\begin{itemize}
1340\item {\bf Makefile} Top level Makefile for building the libraries.
1341\item {\bf Makefile.h} contains the definition of compilation flags for the
1342different compilers and systems. This file is used for building the
1343library and generating {\bf MakefileUser.h} (to be included in makefiles).
1344\item {\bf Makefile.slb} contains the rules for building shared libraries
1345for the different compilers and systems. (to be included in makefiles)
1346\item {\bf crerep\_sophya} c-shell script for creating the directory tree
1347under {\tt \$DPCBASEREP} and {\tt \$DPCDEVREP}
1348\item {\bf install\_sophya} c-shell script for installing the Sophya package.
1349Usually from {\tt \$DPCDEVREP} to {\tt \$DPCBASEREP}
1350\item {\bf mkmflien} c-shell script for making symbolic links or copying
1351include files to {\tt \$DPCDEVREP/Include} or {\tt \$DPCBASEREP/Include}
1352\item {\bf mkmf} c-shell script for generating module makefiles and the
1353top level makefile (named GNUmakefile)
1354\item {\bf mkmflib} c-shell script for generating each library module
1355makefile (named GNUmakefile)
1356\item {\bf mkmfprog} c-shell script for generating makefile for a module
1357containing the source for executable programs (named GNUmakefile).
1358\item {\bf mkmfPI} c-shell script for generating makefile for PI and PIext
1359modules (named GNUmakefile)
1360\item {\bf libdirs} List of Sophya modules without reference to external
1361libraries.
1362\item {\bf extlibdirs} List of Sophya modules with reference to external
1363libraries.
1364
1365\end{itemize}
1366
1367\newpage
1368\appendix
1369\section{SOPHYA Exceptions}
1370\index{Exception classes} \index{PThrowable} \index{PError} \index{PException}
1371SOPHYA library defines a set of exceptions which are used
1372for signalling error conditions. The figure below shows a partial
1373class diagram for exception classes in SOPHYA.
1374\begin{figure}[hbt]
1375\dclsbb{PThrowable}{PError}
1376\dclscc{PError}{AllocationError}
1377\dclscc{PError}{NullPtrError}
1378\dclscc{PError}{ForbiddenError}
1379\dclscc{PError}{AssertionFailedError}
1380\dclsbb{PThrowable}{PException}
1381\dclscc{PException}{IOExc}
1382\dclscc{PException}{SzMismatchError}
1383\dclscc{PException}{RangeCheckError}
1384\dclscc{PException}{ParmError}
1385\dclscc{PException}{TypeMismatchExc}
1386\dclscc{PException}{MathExc}
1387\dclscc{PException}{CaughtSignalExc}
1388\caption{partial class diagram for exception handling in Sophya}
1389\end{figure}
1390
1391For simple programs, it is a good practice to handle
1392the exceptions at least at high level, in the {\tt main()} function.
1393The example below shows the exception handling and the usage
1394of Sophya persistence.
1395
1396\input{ex1.inc}
1397
1398
1399\newpage
1400\addcontentsline{toc}{section}{Index}
1401\printindex
1402\end{document}
1403
Note: See TracBrowser for help on using the repository browser.