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

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

Petits ajouts dans la doc sophya.tex (concernant fitsinoutfile << en particulier) , Reza 11/08/2006

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