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