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