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