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

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

Quelques ajouts ds la doc generale SOPHYA (TimeStamp, scanfits ...) , Reza 29/6/2006

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