[887] | 1 | \documentclass[twoside,11pt]{article}
|
---|
| 2 | % Package standard : Utilisation de caracteres accentues, mode francais et graphique
|
---|
[988] | 3 | \usepackage{url}
|
---|
[887] | 4 | \usepackage[latin1]{inputenc}
|
---|
| 5 | \usepackage[T1]{fontenc}
|
---|
| 6 | \usepackage[english]{babel}
|
---|
| 7 | \usepackage{graphicx}
|
---|
| 8 | % package a mettre pour faire du pdf
|
---|
[978] | 9 | \usepackage{palatino}
|
---|
[887] | 10 |
|
---|
| 11 | % Extension de symboles mathematiques
|
---|
| 12 | \usepackage{amssymb}
|
---|
| 13 |
|
---|
[988] | 14 | % Definition pour Docs Sophya
|
---|
[974] | 15 | \usepackage{defsophya}
|
---|
| 16 |
|
---|
[1362] | 17 | % Constitution d'index
|
---|
| 18 | \usepackage{makeidx}
|
---|
| 19 | \makeindex
|
---|
[887] | 20 |
|
---|
| 21 | \begin{document}
|
---|
| 22 |
|
---|
| 23 | \begin{titlepage}
|
---|
[988] | 24 | % The title page - top of the page with the title of the paper
|
---|
[978] | 25 | \titrehp{Sophya \\ An overview }
|
---|
[988] | 26 | % Authors list
|
---|
[978] | 27 | \auteurs{
|
---|
[988] | 28 | R. Ansari & ansari@lal.in2p3.fr \\
|
---|
[1340] | 29 | E. Aubourg & aubourg@hep.saclay.cea.fr \\
|
---|
[988] | 30 | G. Le Meur & lemeur@lal.in2p3.fr \\
|
---|
| 31 | C. Magneville & cmv@hep.saclay.cea.fr \\
|
---|
| 32 | S. Henrot-Versille & versille@in2p3.fr
|
---|
[887] | 33 | }
|
---|
[978] | 34 | % \auteursall
|
---|
[988] | 35 | % The title page - bottom of the page with the paper number
|
---|
[1362] | 36 | \vspace{1cm}
|
---|
| 37 | \begin{center}
|
---|
| 38 | {\bf \Large Document being updated !}
|
---|
| 39 | \end{center}
|
---|
[988] | 40 | \titrebp{1}
|
---|
[887] | 41 | \end{titlepage}
|
---|
| 42 |
|
---|
| 43 | \tableofcontents
|
---|
| 44 |
|
---|
| 45 | \newpage
|
---|
| 46 |
|
---|
| 47 | \section{Introduction}
|
---|
| 48 |
|
---|
[1362] | 49 | {\bf SOPHYA} ({\bf SO}ftware for {\bf PHY}sics {\bf A}nalysis)
|
---|
[887] | 50 | is a collection of C++ classes designed for numerical and
|
---|
| 51 | physics analysis software development. Our goal is to provide
|
---|
| 52 | easy to use, yet powerful classes which can be used by scientists.
|
---|
| 53 | We have decided to use as much as possible available
|
---|
| 54 | numerical analysis libraries, encapsulating them whenever
|
---|
| 55 | possible.
|
---|
| 56 |
|
---|
| 57 | The SOPHYA design and implementation has been carried out
|
---|
| 58 | with the specific goal of providing the general framework for
|
---|
| 59 | the Planck-HFI data processing software. However, most of the
|
---|
[978] | 60 | packages presented here have a more general scope than the CMB analysis
|
---|
[1340] | 61 | and Planck mission problem.
|
---|
[887] | 62 | The source directory tree
|
---|
[1362] | 63 | \footnote{ CVS: cvsserver.lal.in2p3.fr:/exp/eros/CVSPlanck}
|
---|
[887] | 64 | is organised into a number of modules.
|
---|
| 65 |
|
---|
| 66 | \begin{itemize}
|
---|
| 67 | \item[] {\bf Mgr/} Scripts for code management,
|
---|
| 68 | makefile generation and software installation
|
---|
| 69 | \item[] {\bf SysTools/} General architecture support classes such
|
---|
| 70 | as {\tt PPersist, NDataBlock<T>}, and few utility classes
|
---|
| 71 | ({\tt DataCard, DVList} \ldots).
|
---|
[1340] | 72 | \item[] {\bf TArray/} template numerical arrays, vectors and matrices \\
|
---|
[988] | 73 | ({\tt PixelMap<T> SphericalMap<T>} \ldots)
|
---|
[887] | 74 | \item[] {\bf NTools/} Some standard numerical analysis tools
|
---|
| 75 | (linear, and non linear parameter fitting, FFT, \ldots)
|
---|
| 76 | \item[] {\bf HiStats/} Histogram-ming and data set handling classes \\
|
---|
| 77 | ({\tt Histo Histo2D NTuple XNTuple} \ldots)
|
---|
| 78 | \end{itemize}
|
---|
| 79 |
|
---|
[978] | 80 | The modules listed below are more tightly related to the
|
---|
| 81 | CMB (Cosmic Microwave Background) data analysis problem:
|
---|
[887] | 82 | \begin{itemize}
|
---|
[988] | 83 | \item[] {\bf SkyMap/} Local and full sky maps, and few geometry
|
---|
| 84 | handling utility classes. \\
|
---|
| 85 | ({\tt PixelMap<T>, LocalMap<T>, SphericalMap<T>, \ldots})
|
---|
[887] | 86 | \item[] {\bf SkyT/}
|
---|
| 87 | classes for spectral emission and detector frequency response modelling \\
|
---|
| 88 | ({\tt SpectralResponse, RadSpectra, BlackBody} \ldots)
|
---|
[1340] | 89 | \item[] {\bf Samba/} Spherical harmonic analysis.
|
---|
[887] | 90 | \end{itemize}
|
---|
| 91 |
|
---|
[978] | 92 | The following modules contain the interface classes with
|
---|
| 93 | external libraries:
|
---|
[887] | 94 | \begin{itemize}
|
---|
[988] | 95 | \item[] {\bf FitsIOServer/} Classes for handling file input-output
|
---|
[887] | 96 | in FITS format using the cfitsio library.
|
---|
| 97 | \item[] {\bf LinAlg/} Interface with Lapack linear algebra package
|
---|
[1340] | 98 | \item[] {\bf IFFTW/} Interface with FFTW package (libfftw.a)
|
---|
[887] | 99 | \end{itemize}
|
---|
| 100 |
|
---|
| 101 | Other modules:
|
---|
| 102 | \begin{itemize}
|
---|
| 103 | \item[] {\bf Tests/} Simple test programs
|
---|
[1340] | 104 | \item[] {\bf PrgUtil/} Various utility programs (runcxx, scanppf, scanfits, \ldots)
|
---|
| 105 | \item[] {\bf PMixer/} skymixer and related programs
|
---|
[887] | 106 | \item[] {\bf ProgPI/} interactive analysis tool - It should be noted that
|
---|
| 107 | this module uses the SOPHYA class library and is based on {\bf PI}
|
---|
| 108 | which is a C++ library defining a complete GUI program
|
---|
| 109 | architecture. An additional module (PIext) define the interactive
|
---|
| 110 | analysis program framework and the interfaces with the objects
|
---|
| 111 | in SOPHYA. The {\bf PI/} \footnote{the PI package documentation
|
---|
[988] | 112 | is available from {\bf http://www.lal.in2p3.fr/recherche/eros/PeidaDoc/} }
|
---|
[887] | 113 | and {\bf PIext/} modules are not currently part
|
---|
| 114 | of the SOPHYA CVS structure.
|
---|
| 115 | \end{itemize}
|
---|
| 116 |
|
---|
[988] | 117 | \newpage
|
---|
| 118 |
|
---|
[978] | 119 | \section{Using Sophya}
|
---|
[1362] | 120 | Basic usage of Sophya classes are described in in the following sections.
|
---|
| 121 | Complete Sophya documentation can be found at our web site: \\
|
---|
| 122 | {\bf http://hfi-l2.in2p3.fr}.
|
---|
| 123 |
|
---|
| 124 | \subsection{Environment variables}
|
---|
[978] | 125 | Two environment variables {\bf DPCBASEREP} and {\bf EROSCXX} are used
|
---|
| 126 | to define the path where the Sophya libraries and executable are installed.
|
---|
| 127 | {\bf DPCBASEREP} defines the base directory path and {\bf EROSCXX} the
|
---|
| 128 | name of the C++ compiler. The complete path is built using {\bf DPCBASEREP},
|
---|
| 129 | the operating system name (as obtained by the {\tt uname} command), and
|
---|
[1340] | 130 | the compiler name. In the example below, we show the complete path
|
---|
[978] | 131 | for a {\tt Linux} system, using the GNU g++ compiler:
|
---|
| 132 |
|
---|
| 133 | \begin{itemize}
|
---|
| 134 | \item \$DPCBASEREP/Include : Include (.h) files
|
---|
| 135 | \item \$DPCBASEREP/Linux-g++/Libs : Path for the archive libraries (.a)
|
---|
| 136 | \item \$DPCBASEREP/Linux-g++/ShLibs : Shared library path (.so)
|
---|
| 137 | \item \$DPCBASEREP/Linux-g++/Exec : Executable file path
|
---|
| 138 | \end{itemize}
|
---|
| 139 |
|
---|
| 140 | In order to use the shared libraries, the {\bf LD\_LIBRARY\_PATH} variable
|
---|
| 141 | should contain the Sophya shared library path
|
---|
| 142 | ({\tt \$DPCBASEREP/Linux-g++/ShLibs } when using g++ compiler on Linux)
|
---|
| 143 |
|
---|
[1340] | 144 | For modules using external libraries, the {\bf EXTLIBDIR}
|
---|
| 145 | environment variable should contain the path to these libraries
|
---|
| 146 | and corresponding include files.
|
---|
| 147 | C-FitsIO anf FFTW include files should be accessible through: \\
|
---|
| 148 | {\tt \$EXTLIBDIR/Include/FitsIO } \\
|
---|
| 149 | {\tt \$EXTLIBDIR/Include/FFTW } \\
|
---|
| 150 | The corresponding libraries are expected to be found in: \\
|
---|
| 151 | {\tt \$EXTLIBDIR/Linux-g++/Libs} \\
|
---|
| 152 |
|
---|
[1362] | 153 | \subsection{User makefiles}
|
---|
[978] | 154 | The file {\tt \$DPCBASEREP/Include/MakefileUser.h} defines the compilation
|
---|
[1299] | 155 | flags and the list of Sophya libraries. It should be included in the
|
---|
[978] | 156 | user's makefile. The default compilation rules assumes that the object (.o)
|
---|
| 157 | and executable files would be put in the following diretories: \\
|
---|
| 158 | {\tt \$HOME/`uname`-\$EROSCXX/Objs} \\
|
---|
| 159 | {\tt \$HOME/`uname`-\$EROSCXX/Exec}.
|
---|
| 160 | In the case of a {\tt Linux} system and using {\tt g++} as the C++ compiler,
|
---|
| 161 | these two directories would be translated to \\
|
---|
| 162 | {\tt \$HOME/Linux-g++/Objs} and {\tt \$HOME/Linux-g++/Exec}.
|
---|
| 163 | The GNU make program should be used.
|
---|
| 164 | \par
|
---|
| 165 | The file {\tt \$DPCBASEREP/Include/makefile\_auto} defines the rules to compile
|
---|
| 166 | a given source program, and link it against the Sophya libraries to produce
|
---|
| 167 | an executable. The example below shows the steps to compile a program named
|
---|
| 168 | {\tt trivial.cc }.
|
---|
| 169 | \begin{verbatim}
|
---|
[1299] | 170 | csh> cp \$DPCBASEREP/Include/makefile_auto makefile
|
---|
[978] | 171 | csh> make trivial
|
---|
| 172 | \end{verbatim}
|
---|
[988] | 173 | This command should compile the {\tt trivial.cc} file,
|
---|
| 174 | and link it against the sophya libraries. The object and executable
|
---|
| 175 | file names are: \\
|
---|
| 176 | {\tt \$HOME/`uname`-\$EROSCXX/Objs/trivial.o} \\
|
---|
| 177 | {\tt \$HOME/`uname`-\$EROSCXX/Exec/trivial}.
|
---|
[978] | 178 | \par
|
---|
| 179 | The file {\tt \$DPCBASEREP/Include/makefile\_example} provides another
|
---|
| 180 | example makefile.
|
---|
| 181 |
|
---|
[1362] | 182 | \subsection{the runcxx program}
|
---|
| 183 | \index{runcxx}
|
---|
| 184 | {\bf runcxx} is a simple program which can be used to compile, link
|
---|
| 185 | and run simple C++ programs. It handles the creation of a
|
---|
| 186 | complete program file, containing the basic set C++ include files,
|
---|
| 187 | the necessary include files for SOPHYA SysTools, TArray, HiStats
|
---|
| 188 | and NTools modules, and the main program with exception handling.
|
---|
| 189 | Other Sophya modules can be included using the {\tt -import} flag.
|
---|
| 190 | \begin{verbatim}
|
---|
| 191 | csh> runcxx -h
|
---|
| 192 | SOPHYA Version 0.9 Revision 97 (V_Oct2000) -- Nov 9 2000 16:20:52 cxx
|
---|
| 193 | runcxx : compiling and running of a piece of C++ code
|
---|
| 194 | Usage: runcxx [-compopt CompileOptions] [-linkopt LinkOptions]
|
---|
| 195 | [-tmpdir TmpDirectory] [-f C++CodeFileName]
|
---|
| 196 | [-inc includefile] [-inc includefile ...]
|
---|
| 197 | [-import modulename] [-import modulename ...]
|
---|
| 198 | [-uarg UserArg1 UserArg2 ...]
|
---|
| 199 | if no file name is specified, read from standard input
|
---|
| 200 | modulenames: SkyMap, Samba, SkyT, FitsIOServer, LinAlg, IFFTW
|
---|
| 201 | \end{verbatim}
|
---|
| 202 | Most examples in this manual can be tested using runcxx. The
|
---|
| 203 | example below shows how to compile, link and run a sample
|
---|
| 204 | code.
|
---|
| 205 | \begin{verbatim}
|
---|
| 206 | // File example.icc
|
---|
| 207 | Matrix a(3,3);
|
---|
| 208 | a = IdentityMatrix(1.);
|
---|
| 209 | cout << a ;
|
---|
| 210 | // Executing this sample code
|
---|
| 211 | csh> runcxx -f example.icc
|
---|
| 212 | \end{verbatim}
|
---|
| 213 |
|
---|
[978] | 214 |
|
---|
[1362] | 215 | \section{Copy constructor and assignment operator}
|
---|
| 216 | In C++, objects can be copied by assignment or by initialization.
|
---|
| 217 | Copying by initialization corresponds to creating an object and
|
---|
| 218 | initializing its value through the copy constructor.
|
---|
| 219 | The copy constructor has its first argument as a reference, or
|
---|
| 220 | const reference to the object's class type. It can have
|
---|
| 221 | more arguments, if default values are provided.
|
---|
| 222 | Copying by assignment applies to an existing object and
|
---|
| 223 | is performed through the assignment operator (=).
|
---|
| 224 | The copy constructor implements this for identical type objects:
|
---|
| 225 | \begin{verbatim}
|
---|
| 226 | class MyObject {
|
---|
| 227 | public:
|
---|
| 228 | MyObject(); // Default constructor
|
---|
| 229 | MyObject(MyObject const & a); // Copy constructor
|
---|
| 230 | MyObject & operator = (MyObject const & a) // Assignment operator
|
---|
| 231 | }
|
---|
| 232 | \end{verbatim}
|
---|
| 233 | The copy constructors play an important role, as they are
|
---|
| 234 | called when class objects are passed by value,
|
---|
| 235 | returned by value, or thrown as an exception.
|
---|
| 236 | \begin{verbatim}
|
---|
| 237 | // A function declaration with an argument of type MyObject,
|
---|
| 238 | // passed by value, and returning a MyObject
|
---|
| 239 | MyObject f(MyObject x)
|
---|
| 240 | {
|
---|
| 241 | MyObject r;
|
---|
| 242 | ...
|
---|
| 243 | return(r); // Copy constructor is called here
|
---|
| 244 | }
|
---|
| 245 | // Calling the function :
|
---|
| 246 | MyObject a;
|
---|
| 247 | f(a); // Copy constructor called for a
|
---|
| 248 | \end{verbatim}
|
---|
| 249 | It should be noted that the C++ syntax is ambiguous for the
|
---|
| 250 | assignment operator. {\tt MyObject x; x=y; } and
|
---|
| 251 | {\tt MyObject x=y;} have different meaning.
|
---|
| 252 | \begin{verbatim}
|
---|
| 253 | MyObject a; // default constructor call
|
---|
| 254 | MyObject b(a); // copy constructor call
|
---|
| 255 | MyObject bb = a; // identical to bb(a) : copy constructor call
|
---|
| 256 | MyObject c; // default constructor call
|
---|
| 257 | c = a; // assignment operator call
|
---|
| 258 | \end{verbatim}
|
---|
[1299] | 259 |
|
---|
[1362] | 260 | As a general rule in SOPHYA, objects which implements
|
---|
| 261 | reference sharing on their data members have a copy constructor
|
---|
| 262 | which shares the data, while the assignment operator copies or
|
---|
| 263 | duplicate the data.
|
---|
| 264 |
|
---|
[1299] | 265 | \section{Module SysTools}
|
---|
| 266 |
|
---|
| 267 | {\bf SysTools} contains utility classes such as {\tt DataCards} or
|
---|
| 268 | {\tt DVlist}, an hierarchy of exception classes for Sophya, a template
|
---|
| 269 | class {\tcls{NDataBlock}} for handling reference counting on numerical
|
---|
| 270 | arrays, as well as classes providing the services for implementing simple
|
---|
| 271 | serialization.
|
---|
| 272 | \vspace*{5mm}
|
---|
| 273 |
|
---|
[1340] | 274 | \subsection{SOPHYA persistence}
|
---|
[1362] | 275 | \index{PPersist} \index{PInPersist} \index{POutPersist}
|
---|
[1299] | 276 | \begin{figure}[hbt]
|
---|
| 277 | \dclsa{PPersist}
|
---|
| 278 | \dclsbb{PIOPersist}{PInPersist}
|
---|
| 279 | \dclsb{POutPersist}
|
---|
| 280 | \caption{partial class diagram for classes handling persistence in Sophya}
|
---|
| 281 | \end{figure}
|
---|
[1340] | 282 | A simple persistence mechanism is defined in SOPHYA. Its main
|
---|
| 283 | features are:
|
---|
| 284 | \begin{itemize}
|
---|
| 285 | \item[] Portable file format, containing the description of the data structures
|
---|
| 286 | and object hierarchy. \\
|
---|
| 287 | {\bf PPF} {\bf P}ortable {\bf P}ersistence file {\bf F}ormat.
|
---|
| 288 | \item[] Handling of read/write for mutiply referenced objects.
|
---|
| 289 | \item[] All write operations are carried using sequential access only. This
|
---|
| 290 | holds also for read operations, unless positional tags are used.
|
---|
| 291 | SOPHYA persistence services can thus be used to transfer objects
|
---|
| 292 | through network links.
|
---|
[1360] | 293 | \item[] The serialisation (reading/writing) for objects for a given class
|
---|
| 294 | is implemented through a delegate object. The delegate class inherits
|
---|
| 295 | from {\tt PPersist} class.
|
---|
[1340] | 296 | \end{itemize}
|
---|
[1360] | 297 | A complete description of SOPHYA persistence mechanism and guidelines
|
---|
| 298 | for writing delegate classes for handling object persistence is beyond
|
---|
| 299 | the scope of this document. The example in the next paragraph shows
|
---|
| 300 | simple use of SOPHYA persistence.
|
---|
| 301 |
|
---|
| 302 | \subsection{\tcls{NDataBlock}}
|
---|
[1362] | 303 | \index{\tcls{NDataBlock}}
|
---|
| 304 | \begin{figure}[hbt]
|
---|
| 305 | \dclsbb{AnyDataObj}{\tcls{NDataBlock}}
|
---|
| 306 | \dclsbb{PPersist}{\tcls{FIO\_NDataBlock}}
|
---|
| 307 | \end{figure}
|
---|
[1360] | 308 | The {\bf \tcls{NDataBlock}} is designed to handle reference counting
|
---|
| 309 | and sharing of memory blocs (contiguous arrays) for numerical data
|
---|
| 310 | types. Initialisation, resizing, basic arithmetic operations, as
|
---|
| 311 | well as persistence handling services are provided.
|
---|
| 312 | The persistence handler class ({\tt \tcls{FIO\_NDataBlock}}) insures
|
---|
| 313 | that a single copy of data is written for multiply referenced objects,
|
---|
| 314 | and the data is shared among objects when reading.
|
---|
| 315 | \par
|
---|
| 316 | The example below shows writing of NDataBlock objects through the
|
---|
| 317 | use of overloaded operator $ << $ :
|
---|
[1340] | 318 | \begin{verbatim}
|
---|
| 319 | #include "fiondblock.h"
|
---|
| 320 | // ...
|
---|
| 321 | POutPersist pos("aa.ppf");
|
---|
| 322 | NDataBlock<r_4> rdb(40);
|
---|
| 323 | rdb = 567.89;
|
---|
| 324 | pos << rdb;
|
---|
| 325 | // We can also use the PutObject method
|
---|
| 326 | NDataBlock<int_4> idb(20);
|
---|
| 327 | idb = 123;
|
---|
| 328 | pos.PutObject(idb);
|
---|
| 329 | \end{verbatim}
|
---|
| 330 | The following sample programs show the reading of the created PPF file :
|
---|
| 331 | \begin{verbatim}
|
---|
| 332 | PInPersist pis("aa.ppf");
|
---|
| 333 | NDataBlock<r_4> rdb;
|
---|
| 334 | pis >> rdb;
|
---|
| 335 | cout << rdb;
|
---|
| 336 | NDataBlock<int_4> idb;
|
---|
| 337 | cout << idb;
|
---|
| 338 | \end{verbatim}
|
---|
[1299] | 339 |
|
---|
[1362] | 340 | \subsection{Using DVList}
|
---|
| 341 | \index{DVList} \index{MuTyV}
|
---|
| 342 | \begin{figure}[hbt]
|
---|
| 343 | \dclsbb{AnyDataObj}{DVList}
|
---|
| 344 | \dclsbb{PPersist}{\tclsc{ObjFileIO}{DVList}}
|
---|
| 345 | \end{figure}
|
---|
| 346 | The {\bf DVList} class objects can be used to create and manage list
|
---|
| 347 | of values, associated with names. A list of pairs of (MuTyV, name(string))
|
---|
| 348 | is maintained by DVList objects. {\bf MuTyV} is a simple class
|
---|
| 349 | capable of holding string, integer, float or complex values,
|
---|
| 350 | providing easy conversion methods between these objects.
|
---|
| 351 | \begin{verbatim}
|
---|
| 352 | // Using MuTyV objects
|
---|
| 353 | MuTyV s("hello"); // string type value
|
---|
| 354 | MuTyV x;
|
---|
| 355 | x = "3.14159626"; // string type value, ascii representation for Pi
|
---|
| 356 | double d = x; // x converted to double = 3.141596
|
---|
| 357 | x = 314; // x contains the integer value = 314
|
---|
| 358 | // Using DVList
|
---|
| 359 | DVList dvl;
|
---|
| 360 | dvl("Pi") = 3.14159626; // float value, named Pi
|
---|
| 361 | dvl("Log2") = 0.30102999; // float value, named Log2
|
---|
| 362 | dvl("FileName") = "myfile.fits"; // string value, named myfile.fits
|
---|
| 363 | // Printing DVList object
|
---|
| 364 | cout << dvl;
|
---|
| 365 | \end{verbatim}
|
---|
| 366 |
|
---|
[1299] | 367 | \subsection{Using DataCards}
|
---|
[1362] | 368 | \index{DataCards}
|
---|
[1299] | 369 | The {\bf DataCards} class can be used to read parameters from a file.
|
---|
| 370 | Each line in the file starting with \@ defines a set of values
|
---|
| 371 | associated with a keyword. In the example below, we read the
|
---|
| 372 | parameters corresponding with the keyword {\tt SIZE} from the
|
---|
| 373 | file {\tt ex.d}. We suppose that {\tt ex.d} contains the line: \\
|
---|
| 374 | {\tt @SIZE 400 250} \\
|
---|
| 375 | \begin{verbatim}
|
---|
| 376 | #include "datacards.h"
|
---|
| 377 | // ...
|
---|
| 378 | // Initializing DataCards object dc from file ex.d
|
---|
| 379 | DataCards dc( "ex.d" );
|
---|
| 380 | // Getting the first and second parameters for keyword size
|
---|
| 381 | // We define a default value 100
|
---|
| 382 | int size_x = dc.IParam("SIZE", 0, 100);
|
---|
| 383 | int size_y = dc.IParam("SIZE", 1, 100);
|
---|
| 384 | cout << " size_x= " << size_x << " size_y= " << size_y << endl;
|
---|
| 385 | \end{verbatim}
|
---|
| 386 |
|
---|
| 387 | \subsection{Dynamic linker}
|
---|
[1362] | 388 | \index{PDynLinkMgr}
|
---|
[1299] | 389 | The class {\bf PDynLinkMgr} can be used for managing shared libraries
|
---|
| 390 | at run time. The example below shows the run time linking of a function:\\
|
---|
| 391 | {\tt extern "C" { void myfunc(); } } \\
|
---|
| 392 | \begin{verbatim}
|
---|
| 393 | #include "pdlmgr.h"
|
---|
| 394 | // ...
|
---|
| 395 | string soname = "mylib.so";
|
---|
| 396 | string funcname = "myfunc";
|
---|
| 397 | PDynLinkMgr dyl(soname);
|
---|
| 398 | DlFunction f = dyl.GetFunction(funcname);
|
---|
| 399 | if (f != NULL) {
|
---|
| 400 | // Calling the function
|
---|
| 401 | f();
|
---|
| 402 | }
|
---|
| 403 | \end{verbatim}
|
---|
| 404 |
|
---|
[1360] | 405 | \subsection{CxxCompilerLinker class}
|
---|
[1362] | 406 | \index{CxxCompilerLinker}
|
---|
[1360] | 407 | This class provides the services to compile C++ code and building
|
---|
| 408 | shared libraries, using the same compiler and options which have
|
---|
| 409 | been used to create the SOPHYA shared library.
|
---|
| 410 | The sample program below illustrates using this class to build
|
---|
| 411 | the shared library (myfunc.so) from the source file myfunc.cc :
|
---|
| 412 | \begin{verbatim}
|
---|
| 413 | #include "cxxcmplnk.h"
|
---|
| 414 | // ...
|
---|
| 415 | string flnm = "myfunc.cc";
|
---|
| 416 | string oname, soname;
|
---|
| 417 | int rc;
|
---|
| 418 | CxxCompilerLinker cxx;
|
---|
| 419 | // The Compile method provides a default object file name
|
---|
| 420 | rc = cxx.Compile(flnm, oname);
|
---|
| 421 | if (rc != 0 ) { // Error when compiling ... }
|
---|
| 422 | // The BuildSO method provides a default shared object file name
|
---|
| 423 | rc = cxx.BuildSO(oname, soname);
|
---|
| 424 | if (rc != 0 ) { // Error when creating shared object ... }
|
---|
| 425 | \end{verbatim}
|
---|
| 426 |
|
---|
[1299] | 427 | \section{Module TArray}
|
---|
[1362] | 428 | \index{\tcls{TArray}}
|
---|
[1299] | 429 | {\bf TArray} module contains template classes for handling standard
|
---|
| 430 | operations on numerical arrays. Using the class {\tt \tcls{TArray} },
|
---|
| 431 | it is possible to create and manipulate up to 5-dimension numerical
|
---|
[1362] | 432 | arrays {\tt (int, float, double, complex, \ldots)}. The include
|
---|
| 433 | file {\tt array.h} declares all the classes and definitions
|
---|
| 434 | in module TArray.
|
---|
[1299] | 435 |
|
---|
| 436 | \begin{figure}[hbt]
|
---|
| 437 | \dclsccc{AnyDataObj}{BaseArray}{\tcls{TArray}}
|
---|
[1362] | 438 | \dclsbb{PPersist}{\tcls{FIO\_TArray}}
|
---|
[1299] | 439 | \end{figure}
|
---|
| 440 |
|
---|
[1360] | 441 |
|
---|
[1299] | 442 | \subsection{Using arrays}
|
---|
[1362] | 443 | \index{Sequence} \index{RandomSequence} \index{RegularSequence}
|
---|
| 444 | \index{EnumeratedSequence}
|
---|
| 445 | The example below shows basic usage of arrays, creation, initialization
|
---|
| 446 | and arithmetic operations. Different kind of {\bf Sequence} objects
|
---|
| 447 | can be used for initializing arrays.
|
---|
| 448 | \begin{figure}[hbt]
|
---|
| 449 | \dclsbb{Sequence}{RandomSequence}
|
---|
| 450 | \dclsb{RegularSequence}
|
---|
| 451 | \dclsb{EnumeratedSequence}
|
---|
| 452 | \end{figure}
|
---|
[1299] | 453 |
|
---|
[1340] | 454 | The example below shows basic usage of arrays:
|
---|
| 455 | \begin{verbatim}
|
---|
[1362] | 456 | // Creating and initializing a 1-D array of integers
|
---|
| 457 | TArray<int> ia(5);
|
---|
| 458 | EnumeratedSequence es;
|
---|
| 459 | es = 24, 35, 46, 57, 68;
|
---|
| 460 | ia = es;
|
---|
| 461 | cout << "Array<int> ia = " << ia;
|
---|
| 462 | // 2-D array of float filled with random numbers
|
---|
| 463 | // 2-D array of floats
|
---|
| 464 | TArray<r_4> b(6,4), c(6,4);
|
---|
| 465 | // Initializing b with a constant
|
---|
| 466 | b = 2.71828;
|
---|
| 467 | // Filling c with random numbers
|
---|
| 468 | c = RandomSequence();
|
---|
| 469 | // Arithmetic operations
|
---|
| 470 | TArray<r_4> d = b+0.3f*c;
|
---|
| 471 | cout << "Array<float> d = " << d;
|
---|
[1340] | 472 | \end{verbatim}
|
---|
| 473 |
|
---|
[1362] | 474 | The copy constructor shares the array data, while the assignment operator
|
---|
| 475 | copies the array elements, as illustrated in the following example:
|
---|
| 476 | \begin{verbatim}
|
---|
| 477 | TArray<int> a1(4,3);
|
---|
| 478 | a1 = RegularSequence(0,2);
|
---|
| 479 | // Array a2 and a1 shares their data
|
---|
| 480 | TArray<int> a2(a1);
|
---|
| 481 | // a3 and a1 have the same size and identical elements
|
---|
| 482 | TArray<int> a3;
|
---|
| 483 | a3 = a1;
|
---|
| 484 | // Changing one of the a2 elements
|
---|
| 485 | a2(1,1,0) = 555;
|
---|
| 486 | // a1(1,1) is also changed to 555, but not a3(1,1)
|
---|
| 487 | cout << "Array<int> a1 = " << a1;
|
---|
| 488 | cout << "Array<int> a3 = " << a3;
|
---|
| 489 | \end{verbatim}
|
---|
| 490 |
|
---|
| 491 | \subsection{Working with sub-arrays and Ranges}
|
---|
| 492 |
|
---|
| 493 |
|
---|
| 494 | \subsection{Matrices and vectors}
|
---|
| 495 | \index{\tcls{TMatrix}} \index{\tcls{TVector}}
|
---|
| 496 | \begin{figure}[hbt]
|
---|
| 497 | \dclsccc{\tcls{TArray}}{\tcls{TMatrix}}{\tcls{TVector}}
|
---|
| 498 | \end{figure}
|
---|
| 499 | Vectors and matrices are 2 dimensional arrays. The array size
|
---|
| 500 | along one dimension is equal 1 for vectors. Column vectors
|
---|
| 501 | have {\tt NCols() = 1} and row vectors have {\tt NRows() = 1}.
|
---|
| 502 |
|
---|
[1340] | 503 | Example of a simple low-pass filter on a one dimensional array (Vector)
|
---|
| 504 | \begin{verbatim}
|
---|
| 505 | // Input Vector containing a noisy periodic signal
|
---|
| 506 | Vector in(1024), out(1024);
|
---|
| 507 | in = RandomSequence(RandomSequence::Gaussian, 0., 1.);
|
---|
| 508 | for(int kk=0; kk<in.Size(); kk++)
|
---|
| 509 | in(kk) += 2*sin(kk*0.05);
|
---|
| 510 | // Compute the output vector by a simple low pass filter
|
---|
| 511 | Vector out(1024);
|
---|
| 512 | int w = 2;
|
---|
| 513 | for(int k=w; k<in.Size()-w; k++)
|
---|
| 514 | out(k) = in(Range(k-w, k+w).Sum()/(2.*w+1.);
|
---|
| 515 | \end{verbatim}
|
---|
| 516 |
|
---|
[1360] | 517 | \subsection{Memory organisation}
|
---|
| 518 | {\tt \tcls{TArray} } can handle numerical arrays with various memory
|
---|
| 519 | organisation, as long as the spacing (steps) along each axis is
|
---|
| 520 | regular. The five axis are labeled X,Y,Z,T,U. The examples below
|
---|
| 521 | illustrates the memory location for a 2-dimensional, $N_x=4 \times N_y=3$.
|
---|
| 522 | The first index is along the X axis and the second index along the Y axis.
|
---|
| 523 | \begin{verbatim}
|
---|
| 524 | | (0,0) (0,1) (0,2) (0,3) |
|
---|
| 525 | | (1,0) (1,1) (1,2) (1,3) |
|
---|
| 526 | | (2,0) (2,1) (2,2) (2,3) |
|
---|
| 527 | \end{verbatim}
|
---|
| 528 | In the first case, the array is completely packed
|
---|
| 529 | ($Step_X=1, Step_Y=N_X=4$), with zero offset,
|
---|
| 530 | while in the second case, $Step_X=2, Step_Y=10, Offset=10$:
|
---|
| 531 | \begin{verbatim}
|
---|
| 532 | | 0 1 2 3 | | 10 12 14 16 |
|
---|
| 533 | Ex1 | 4 5 6 7 | Ex2 | 20 22 24 26 |
|
---|
| 534 | | 8 9 10 11 | | 30 32 34 36 |
|
---|
| 535 | \end{verbatim}
|
---|
| 536 |
|
---|
| 537 | For matrices and vectors, an optional argument ({\tt MemoryMapping})
|
---|
| 538 | can be used to select the memory mapping, where two basic schemes
|
---|
| 539 | are available: \\
|
---|
| 540 | {\tt CMemoryMapping} and {\tt FortranMemoryMapping}. \\
|
---|
| 541 | In the case where {\tt CMemoryMapping} is used, a given matrix line
|
---|
| 542 | is packed in memory, while the columns are packed when
|
---|
| 543 | {\tt FortranMemoryMapping} is used. The first index when addressing
|
---|
| 544 | the matrix elements (line number index) runs along
|
---|
| 545 | the Y-axis if {\tt CMemoryMapping} is used, and along the X-axis
|
---|
| 546 | in the case of {\tt FortranMemoryMapping}.
|
---|
| 547 | Arithmetic operations between matrices
|
---|
| 548 | with different memory organisation is allowed as long as
|
---|
| 549 | the two matrices have the same sizes (Number of rows and columns).
|
---|
| 550 | The following code example and the corresponding output illustrates
|
---|
| 551 | these two memory mappings.
|
---|
| 552 | \begin{verbatim}
|
---|
| 553 | TArray<r_4> X(4,2);
|
---|
| 554 | X = RegularSequence(1,1);
|
---|
| 555 | cout << "Array X= " << X << endl;
|
---|
| 556 | TMatrix<r_4> X_C(X, true, BaseArray::CMemoryMapping);
|
---|
| 557 | cout << "Matrix X_C (CMemoryMapping) = " << X_C << endl;
|
---|
| 558 | TMatrix<r_4> X_F(X, true, BaseArray::FortranMemoryMapping);
|
---|
| 559 | cout << "Matrix X_F (FortranMemoryMapping) = " << X_F << endl;
|
---|
| 560 | \end{verbatim}
|
---|
| 561 | This code would produce the following output (X\_F = Transpose(X\_C)) :
|
---|
| 562 | \begin{verbatim}
|
---|
| 563 | Array X=
|
---|
| 564 | --- TArray<f> ND=2 SizeX*Y*...= 4x2 ---
|
---|
| 565 | 1, 2, 3, 4
|
---|
| 566 | 5, 6, 7, 8
|
---|
| 567 |
|
---|
| 568 | Matrix X_C (CMemoryMapping) =
|
---|
| 569 | --- TMatrix<f>(NRows=2, NCols=4) ND=2 SizeX*Y*...= 4x2 ---
|
---|
| 570 | 1, 2, 3, 4
|
---|
| 571 | 5, 6, 7, 8
|
---|
| 572 |
|
---|
| 573 | Matrix X_F (FortranMemoryMapping) =
|
---|
| 574 | --- TMatrix<f>(NRows=4, NCols=2) ND=2 SizeX*Y*...= 4x2 ---
|
---|
| 575 | 1, 5
|
---|
| 576 | 2, 6
|
---|
| 577 | 3, 7
|
---|
| 578 | 4, 8
|
---|
| 579 | \end{verbatim}
|
---|
| 580 |
|
---|
[988] | 581 | \newpage
|
---|
| 582 |
|
---|
[1299] | 583 | \section{Module HiStats}
|
---|
| 584 | \begin{figure}[hbt]
|
---|
| 585 | \dclsccc{AnyDataObj}{Histo}{HProf}
|
---|
| 586 | \dclsbb{AnyDataObj}{Histo2D}
|
---|
| 587 | \dclsbb{AnyDataObj}{Ntuple}
|
---|
| 588 | \dclsb{XNtuple}
|
---|
| 589 | \caption{partial class diagram for histograms and ntuples}
|
---|
| 590 | \end{figure}
|
---|
| 591 |
|
---|
[1347] | 592 | {\bf HiStats} contains classes for creating, filling, printing and
|
---|
| 593 | doing various operations on one or two dimensional histograms
|
---|
| 594 | {\tt Histo} and {\tt Histo2D} as well as profile histograms {\tt HProf}. \\
|
---|
| 595 | This module also contains {\tt NTuple} and {\tt XNTuple} which are
|
---|
| 596 | more or less the same that the binary FITS tables.
|
---|
| 597 |
|
---|
| 598 | \subsection{1D Histograms}
|
---|
| 599 |
|
---|
| 600 | For 1D histograms, various numerical methods are provided such as
|
---|
| 601 | computing means and sigmas, finding maxima, fitting, rebinning,
|
---|
| 602 | integrating \dots \\
|
---|
| 603 | The example below shows creating and filling a one dimensionnal histogram
|
---|
| 604 | of 100 bins from $-5.$ to $+5.$ to create a gaussian normal distribution
|
---|
| 605 | with errors~:
|
---|
| 606 | \begin{verbatim}
|
---|
| 607 | #include "histos.h"
|
---|
| 608 | // ...
|
---|
| 609 | Histo H(-0.5,0.5,100);
|
---|
| 610 | H.Errors();
|
---|
| 611 | for(int i=0;i<25000;i++) {
|
---|
| 612 | double x = NorRand();
|
---|
| 613 | H.Add(x);
|
---|
| 614 | }
|
---|
| 615 | H.Print(80);
|
---|
| 616 | \end{verbatim}
|
---|
| 617 |
|
---|
| 618 | \subsection{2D Histograms}
|
---|
| 619 |
|
---|
| 620 | Much of these operations are also valid for 2D histograms. 1D projection
|
---|
| 621 | or slices can be set~:
|
---|
| 622 | \begin{verbatim}
|
---|
| 623 | #include "histos2.h"
|
---|
| 624 | // ...
|
---|
| 625 | Histo H2(-1.,1.,100,0.,60.,50);
|
---|
| 626 | H2.SetProjX(); // create the 1D histo for X projection
|
---|
| 627 | H2.SetBandX(25.,35.); // create 1D histo projection for 25.<y<35.
|
---|
| 628 | H2.SetBandX(35.,45.); // create 1D histo projection for 35.<y<45.
|
---|
| 629 | H2.SetBandX(40.,55.); // create 1D histo projection for 40.<y<55.
|
---|
| 630 | //... fill H2 with what ever you want
|
---|
| 631 | H2.Print();
|
---|
| 632 | Histo *hx = H2.HProjX();
|
---|
| 633 | hx->Print(80);
|
---|
| 634 | Histo *hbx2 = HBandX(1); // Get the second X band (35.<y<45.)
|
---|
| 635 | hbx2->Print(80);
|
---|
| 636 | \end{verbatim}
|
---|
| 637 |
|
---|
| 638 | \subsection{Profile Histograms}
|
---|
| 639 |
|
---|
| 640 | Profiles histograms contains the mean and the sigma of the distribution
|
---|
| 641 | of the values filled in each bin. The sigma can be changed to
|
---|
| 642 | the error on the mean. When filled, the profile histogram looks
|
---|
| 643 | like a 1D histogram and much of the operations that can be done on 1D histo
|
---|
| 644 | may be applied onto profile histograms.
|
---|
| 645 |
|
---|
| 646 | \subsection{Ntuples}
|
---|
| 647 |
|
---|
| 648 | NTuple are memory resident tables of 32 bits floating values (float).
|
---|
| 649 | They are arranged in columns. Each line is often called an event.
|
---|
| 650 | These objects are frequently used to analyze data.
|
---|
| 651 | Graphicals tools (spiapp) can plot a column against an other one
|
---|
| 652 | with respect to various selection cuts. \\
|
---|
| 653 | Here is an example of creation and filling~:
|
---|
| 654 | \begin{verbatim}
|
---|
| 655 | #include "ntuple.h"
|
---|
| 656 | #include "srandgen.h"
|
---|
| 657 | // ...
|
---|
| 658 | char* nament[4] = {"i","x","y","ey"};
|
---|
| 659 | r_4 xnt[4];
|
---|
| 660 | NTuple NT(4,nament);
|
---|
| 661 | for(i=0;i<5000;i++) {
|
---|
| 662 | xnt[0] = i+1;
|
---|
| 663 | xnt[1] = 5.*drandpm1(); // a random value between -5 and +5
|
---|
| 664 | xnt[2] = 100.*exp(-0.5*xnt[1]*xnt[1]) + 1.;
|
---|
| 665 | xnt[3] = sqrt(xnt[2]);
|
---|
| 666 | xnt[2] += xnt[3] * NorRand(); // add a random gaussian error
|
---|
| 667 | NT.Fill(xnt);
|
---|
| 668 | }
|
---|
| 669 | \end{verbatim}
|
---|
| 670 |
|
---|
| 671 | XNtuple are sophisticated NTuple : they accept various types
|
---|
| 672 | of column values (float,double,int,...) and can be as big as
|
---|
| 673 | needed (they used buffers on hard disk).
|
---|
| 674 |
|
---|
[1362] | 675 | \subsection{Writing, viewing \dots }
|
---|
[1347] | 676 |
|
---|
| 677 | All these objects have been design to be written to or read from a persistant file.
|
---|
| 678 | The following example shows how to write the previously created objects
|
---|
| 679 | into such a file~:
|
---|
| 680 | \begin{verbatim}
|
---|
| 681 | //-- Writing
|
---|
| 682 | {
|
---|
| 683 | char *fileout = "myfile.ppf";
|
---|
| 684 | string tag;
|
---|
| 685 | POutPersist outppf(fileout);
|
---|
| 686 | tag = "H"; outppf.PutObject(H,tag);
|
---|
| 687 | tag = "H2"; outppf.PutObject(H2,tag);
|
---|
| 688 | tag = "NT"; outppf.PutObject(NT,tag);
|
---|
| 689 | } // closing ``}'' destroy ``outppf'' and automatically close the file !
|
---|
| 690 | \end{verbatim}
|
---|
| 691 |
|
---|
| 692 | Sophya graphical tools (spiapp) can automatically display and operate
|
---|
| 693 | all these objects.
|
---|
| 694 |
|
---|
[1299] | 695 | \section{Module SkyMap}
|
---|
| 696 |
|
---|
| 697 | \section{Module NTools}
|
---|
| 698 |
|
---|
[1347] | 699 | This module provides elementary numerical tools for numerical integration,
|
---|
| 700 | fitting, sorting and ODE solving. FFTs are also provided (Mayer,FFTPack).
|
---|
| 701 |
|
---|
| 702 | \subsection{Fitting}
|
---|
| 703 |
|
---|
| 704 | Fitting is done with two classes {\tt GeneralFit} and {\tt GeneralFitData}
|
---|
| 705 | and is based on the Levenberg-Marquardt method.
|
---|
| 706 | GeneralFitData is a class which provide a description of the data
|
---|
| 707 | to be fitted. GeneralFit is the fitter class. Parametrized functions
|
---|
| 708 | can be given as classes which inherit {\tt GeneralFunction}
|
---|
| 709 | or as simple C functions. Classes of pre-defined functions are provided
|
---|
| 710 | (see files fct1dfit.h and fct2dfit.h). The user interface is very close
|
---|
| 711 | from that of the CERN {\tt Minuit} fitter.
|
---|
| 712 | Number of objects (Histo, HProf \dots ) are interfaced with GeneralFit
|
---|
| 713 | and can be easily fitted. \\
|
---|
| 714 | Here is a very simple example for fitting the previously created NTuple
|
---|
| 715 | with a gaussian~:
|
---|
| 716 | \begin{verbatim}
|
---|
| 717 | #include "fct1dfit.h"
|
---|
| 718 | // ...
|
---|
| 719 |
|
---|
| 720 | // Read from ppf file
|
---|
| 721 | NTuple nt;
|
---|
| 722 | {
|
---|
| 723 | PInPersist pis("myfile.ppf");
|
---|
| 724 | string tag = "NT"; pis.GetObject(nt,tag);
|
---|
| 725 | }
|
---|
| 726 |
|
---|
| 727 | // Fill GeneralData
|
---|
| 728 | GeneralData mGdata(nt.NEntry());
|
---|
| 729 | for(int i=0; i<nt.NEntry(); i++)
|
---|
| 730 | mGdata.AddData1(xnt[1],xnt[2],xnt[3]); // Fill x, y and error on y
|
---|
| 731 | mGData.PrintStatus();
|
---|
| 732 |
|
---|
| 733 | // Function for fitting : y = f(x) + noise
|
---|
| 734 | Gauss1DPol mFunction; // gaussian + constant
|
---|
| 735 |
|
---|
| 736 | // Prepare for fit
|
---|
| 737 | GeneralFit mFit(&mFunction); // create a fitter for the choosen function
|
---|
| 738 | mFit.SetData(&mGData); // connect data to the fitter
|
---|
| 739 |
|
---|
| 740 | // Set and initialize the parameters (that's non-linear fitting!)
|
---|
| 741 | // (num par, name, guess start, step, [limits min and max])
|
---|
| 742 | mFit.SetParam(0,"high",90.,1..);
|
---|
| 743 | mFit.SetParam(1,"xcenter",0.05,0.01);
|
---|
| 744 | mFit.SetParam(2,"sigma",sig,0.05,0.01,10.);
|
---|
| 745 | // Give limits to avoid division by zero
|
---|
| 746 | mFit.SetParam(3,"constant",0.,1.);
|
---|
| 747 |
|
---|
| 748 | // Fit and print result
|
---|
| 749 | int rcfit = mFit.Fit();
|
---|
| 750 | mFit.PrintFit();
|
---|
| 751 | if(rcfit>0) {)
|
---|
| 752 | cout<<"Reduce_Chisquare = "<<mFit.GetChi2Red()
|
---|
| 753 | <<" nstep="<<mFit.GetNStep()<<" rc="<<rcfit<<endl;
|
---|
| 754 | } else {
|
---|
| 755 | cout<<"Fit_Error, rc = "<<rcfit<<" nstep="<<mFit.GetNStep()<<endl;
|
---|
| 756 | mFit.PrintFitErr(rcfit);
|
---|
| 757 | }
|
---|
| 758 |
|
---|
| 759 | // Get the result for further use
|
---|
| 760 | TVector<r_8> ParResult = mFit.GetParm();
|
---|
| 761 | cout<<ParResult;
|
---|
| 762 | \end{verbatim}
|
---|
| 763 |
|
---|
| 764 | Much more usefull possibilities and detailed informations might be found
|
---|
| 765 | in the HTML pages of the Sophya manual.
|
---|
| 766 |
|
---|
[1350] | 767 | \subsection{Polynomial}
|
---|
[1347] | 768 |
|
---|
[1350] | 769 | Polynomials of 1 or 2 variables are supported ({\tt Poly} and {\tt Poly2}).
|
---|
| 770 | Various operations are supported~:
|
---|
| 771 | \begin{itemize}
|
---|
| 772 | \item elementary operations between polynomials $(+,-,*,/) $
|
---|
| 773 | \item setting or getting coefficients
|
---|
| 774 | \item computing the value of the polynomial for a given value
|
---|
| 775 | of the variable(s),
|
---|
| 776 | \item derivating
|
---|
| 777 | \item computing roots (degre 1 or 2)
|
---|
| 778 | \item fitting the polynomial to vectors of data.
|
---|
| 779 | \end{itemize}
|
---|
| 780 | Here is an example of polynomial fitting~:
|
---|
| 781 | \begin{verbatim}
|
---|
| 782 | #include "poly.h"
|
---|
| 783 | // ...
|
---|
| 784 | Poly pol(2);
|
---|
| 785 | pol[0] = 100.; pol[1] = 0.; pol[2] = 0.01; // Setting coefficients
|
---|
| 786 | TVector<r_8> x(100);
|
---|
| 787 | TVector<r_8> y(100);
|
---|
| 788 | TVector<r_8> ey(100);
|
---|
| 789 | for(int i=0;i<100;i++) {
|
---|
| 790 | x(i) = i;
|
---|
| 791 | ey(i) = 10.;
|
---|
| 792 | y(i) = pol((double) i) + ey(i)*NorRand();
|
---|
| 793 | ey(i) *= ey(i)
|
---|
| 794 | }
|
---|
| 795 |
|
---|
| 796 | TVector<r_8> errcoef;
|
---|
| 797 | Poly polfit;
|
---|
| 798 | polfit.Fit(x,y,ey,2,errcoef);
|
---|
| 799 |
|
---|
| 800 | cout<<"Fit Result"<<polfit<<endl;
|
---|
| 801 | cout<<"Errors :"<<errcoef;
|
---|
| 802 | \end{verbatim}
|
---|
| 803 |
|
---|
| 804 | Similar operations can be done on polynomials with 2 variables.
|
---|
| 805 |
|
---|
[1299] | 806 | \section{Module Samba}
|
---|
| 807 |
|
---|
| 808 | \section{Module SkyT}
|
---|
| 809 |
|
---|
| 810 |
|
---|
[1340] | 811 | \newpage
|
---|
[978] | 812 | \section{Building and installing Sophya}
|
---|
| 813 | Presently, the Sophya library compilation has been tested with the following
|
---|
| 814 | compiler/platform pairs:
|
---|
| 815 |
|
---|
| 816 | \begin{center}
|
---|
| 817 | \begin{tabular}{ll}
|
---|
| 818 | Compaq/DEC OSF1 & cxx (6.0 , 6.2) \\
|
---|
| 819 | Linux & g++ (2.91 , 2.95) \\
|
---|
| 820 | Linux & KCC (3.4) \\
|
---|
| 821 | Solaris & g++ (2.95) \\
|
---|
| 822 | SGI IRIX64 & CC \\
|
---|
| 823 | \end{tabular}
|
---|
| 824 | \end{center}
|
---|
| 825 |
|
---|
| 826 | Some of the modules in the Sophya package uses external libraries. The
|
---|
| 827 | {\bf FitsIOServer} is the example of such a module, where the {\tt libcfitsio.a}
|
---|
| 828 | is used.
|
---|
| 829 | The build procedure expects to find the include files and the libraries in: \\
|
---|
| 830 | {\tt \$EXTLIBDIR/Include/FitsIO } \\
|
---|
| 831 | {\tt \$EXTLIBDIR/`uname`-\$EROSCXX/Libs} \\
|
---|
| 832 |
|
---|
| 833 | The object files from a given Sophya module are grouped in an archive library
|
---|
| 834 | with the module's name ({\tt libmodulename.a}). All Sophya modules
|
---|
| 835 | are grouped in a single shared library ({\tt libsophya.so}), while the
|
---|
| 836 | modules with reference to external libraries are grouped in
|
---|
| 837 | ({\tt libextsophya.so}). The {\bf PI} and {\bf PIext} modules are
|
---|
| 838 | grouped in ({\tt libPI.so}).
|
---|
| 839 |
|
---|
| 840 | The environment variables {\bf DPCDEVREP}, {\bf EXTLIBDIR} and {\bf EROSCXX}
|
---|
| 841 | must be defined in order to install the Sophya package.
|
---|
| 842 | In the example below, we assume that we want to install Sophya from a
|
---|
| 843 | released (tagged) version in the source directory {\tt \$SRC} in the
|
---|
| 844 | {\tt /usr/local/Sophya} diretory, using {\tt g++}. We assume that
|
---|
| 845 | the external libraries directory tree has been set up in
|
---|
| 846 | {\tt /usr/local/ExtLibs/}. \\[3mm]
|
---|
[988] | 847 | \centerline{
|
---|
| 848 | \rule{20mm}{0.5mm}
|
---|
| 849 | {\bf \large the use of GNU make is mandatory}
|
---|
| 850 | \rule{20mm}{0.5mm} }
|
---|
[1299] | 851 |
|
---|
[978] | 852 | \vspace*{3mm}
|
---|
| 853 | \begin{verbatim}
|
---|
| 854 | # We select our C++ compiler
|
---|
| 855 | csh> setenv EROSCXX g++
|
---|
| 856 | # Setup the build directory
|
---|
| 857 | csh> mkdir /usr/local/Sophya/
|
---|
| 858 | csh> setenv DPCDEVREP /usr/local/Sophya/
|
---|
| 859 | csh> setenv EXTLIBDIR /usr/local/ExtLibs/
|
---|
| 860 | # Use the top level makefile in Mgr/
|
---|
[1299] | 861 | csh> cd \$SRC
|
---|
[978] | 862 | csh> cp Mgr/Makefile Makefile
|
---|
| 863 | # Step 1: Create the directory tree and copy the include files (.h)
|
---|
| 864 | csh> make depend
|
---|
| 865 | # Step 2: Compile the modules without external library reference
|
---|
| 866 | csh> make libs
|
---|
| 867 | # Step 3: Compile the modules WITH external library reference (optional)
|
---|
| 868 | csh> make extlibs
|
---|
| 869 | # Step 4: Build libsophya.so
|
---|
| 870 | csh> make slb
|
---|
| 871 | # Step 5: Build libextsophya.so (optional)
|
---|
| 872 | csh> make slbext
|
---|
| 873 | # Step 6: Compile the PI and PIext modules (optional)
|
---|
| 874 | csh> make PI
|
---|
| 875 | # Step 7: Build the corresponding shared library libPI.so (optional)
|
---|
| 876 | csh> make slbpi
|
---|
| 877 | \end{verbatim}
|
---|
| 878 |
|
---|
| 879 | To compile all modules and build the shared libraries, it is possible
|
---|
| 880 | to use:
|
---|
| 881 | \begin{verbatim}
|
---|
| 882 | # Step 2,3,6
|
---|
| 883 | csh> make all
|
---|
| 884 | # Step 4,5,7
|
---|
[1292] | 885 | csh> make slball
|
---|
[978] | 886 | \end{verbatim}
|
---|
| 887 |
|
---|
| 888 | At this step, all libraries sould have been made. Programs using
|
---|
| 889 | Sophya libraries can now be built:
|
---|
| 890 | \begin{verbatim}
|
---|
| 891 | # To compile test programs
|
---|
| 892 | csh> cd Tests
|
---|
| 893 | csh> make arrt ...
|
---|
| 894 | csh> cd ..
|
---|
| 895 | # To compile other programs, for example from the PMixer module
|
---|
| 896 | csh> cd PMixer
|
---|
| 897 | csh> make
|
---|
| 898 | csh> cd ..
|
---|
| 899 | # To build (s)piapp (libPI.so is needed)
|
---|
| 900 | csh> cd ProgPI
|
---|
| 901 | csh> make
|
---|
| 902 | csh> cd ..
|
---|
| 903 | \end{verbatim}
|
---|
| 904 |
|
---|
[988] | 905 | \subsection{Mgr module}
|
---|
| 906 | This module contains scripts which can be used for generating the
|
---|
| 907 | makefiles for each module.
|
---|
| 908 | \begin{itemize}
|
---|
| 909 | \item {\bf Makefile} Top level Makefile for builiding the libraries.
|
---|
| 910 | \item {\bf Makefile.h} contains the defintion of compilation flags for the
|
---|
| 911 | different compilers and systems. This file is used for building the
|
---|
| 912 | library and generating {\bf MakefileUser.h} (to be included in makefiles).
|
---|
| 913 | \item {\bf Makefile.slb} contains the rules for building shared libraries
|
---|
| 914 | for the different compilers and systems. (to be included in makefiles)
|
---|
| 915 | \item {\bf crerep\_sophya} c-shell script for creating the directory tree
|
---|
| 916 | under {\tt \$DPCBASEREP} and {\tt \$DPCDEVREP}
|
---|
| 917 | \item {\bf install\_sophya} c-shell script for installing the Sophya package.
|
---|
| 918 | Usually from {\tt \$DPCDEVREP} to {\tt \$DPCBASEREP}
|
---|
| 919 | \item {\bf mkmflien} c-shell script for making symbolic links or copying
|
---|
| 920 | include files to {\tt \$DPCDEVREP/Include} or {\tt \$DPCBASEREP/Include}
|
---|
| 921 | \item {\bf mkmf} c-shell script for generating module makefiles and the
|
---|
| 922 | top level makefile (named GNUmakefile)
|
---|
| 923 | \item {\bf mkmflib} c-shell script for generating each library module
|
---|
| 924 | makefile (named GNUmakefile)
|
---|
| 925 | \item {\bf mkmfprog} c-shell script for generating makefile for a module
|
---|
| 926 | containing the source for executable programs (named GNUmakefile).
|
---|
| 927 | \item {\bf mkmfPI} c-shell script for generating makefile for PI and PIext
|
---|
| 928 | modules (named GNUmakefile)
|
---|
| 929 | \item {\bf libdirs} List of Sophya modules without reference to external
|
---|
| 930 | libraries.
|
---|
| 931 | \item {\bf extlibdirs} List of Sophya modules with reference to external
|
---|
| 932 | libraries.
|
---|
[887] | 933 |
|
---|
[988] | 934 | \end{itemize}
|
---|
| 935 |
|
---|
| 936 | \newpage
|
---|
[1299] | 937 | \appendix
|
---|
[1362] | 938 | \section{SOPHYA Exceptions}
|
---|
| 939 | \index{Exception classes} \index{PThrowable} \index{PError} \index{PException}
|
---|
| 940 | SOPHYA library defines a set of exceptions which are used
|
---|
| 941 | for signaling error conditions. The figure below shows a partial
|
---|
| 942 | class diagram for exception classes in SOPHYA.
|
---|
| 943 | \begin{figure}[hbt]
|
---|
| 944 | \dclsbb{PThrowable}{PError}
|
---|
| 945 | \dclscc{PError}{AllocationError}
|
---|
| 946 | \dclscc{PError}{NullPtrError}
|
---|
| 947 | \dclscc{PError}{ForbiddenError}
|
---|
| 948 | \dclscc{PError}{AssertionFailedError}
|
---|
| 949 | \dclsbb{PThrowable}{PException}
|
---|
| 950 | \dclscc{PException}{IOExc}
|
---|
| 951 | \dclscc{PException}{SzMismatchError}
|
---|
| 952 | \dclscc{PException}{RangeCheckError}
|
---|
| 953 | \dclscc{PException}{ParmError}
|
---|
| 954 | \dclscc{PException}{TypeMismatchExc}
|
---|
| 955 | \dclscc{PException}{MathExc}
|
---|
| 956 | \dclscc{PException}{CaughtSignalExc}
|
---|
| 957 | \caption{partial class diagram for exception handling in Sophya}
|
---|
| 958 | \end{figure}
|
---|
| 959 |
|
---|
[1299] | 960 | For simple programs, it is a good practice to handle
|
---|
[988] | 961 | the exceptions at least at high level, in the {\tt main()} function.
|
---|
| 962 | The example below shows the exception handling and the usage
|
---|
| 963 | of Sophya persistence.
|
---|
[1299] | 964 |
|
---|
[988] | 965 | \input{ex1.inc}
|
---|
[887] | 966 |
|
---|
[1292] | 967 |
|
---|
[1362] | 968 | \newpage
|
---|
| 969 | \addcontentsline{toc}{section}{Index}
|
---|
| 970 | \printindex
|
---|
[1299] | 971 | \end{document}
|
---|
[1362] | 972 |
|
---|