Changeset 1362 in Sophya for trunk


Ignore:
Timestamp:
Dec 22, 2000, 5:53:02 PM (25 years ago)
Author:
ansari
Message:

MAJ documentation Reza 22/12/2000

Location:
trunk/SophyaLib/Manual
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/Manual/defsophya.sty

    r978 r1362  
    22%  Definition of template class \tcls{Vector} --> Vector<T>
    33\newcommand{\tcls}[1] {#1$<$T$>$}   
     4\newcommand{\tclsc}[2] {#1$<$#2$>$}   
    45%  Putting a class name in a box
    56\newcommand{\clsbox}[1] { \framebox[40mm][c]{\mbox{\rule[-1mm]{0mm}{5mm} \bf #1} } }
  • trunk/SophyaLib/Manual/sophya.tex

    r1360 r1362  
    1515\usepackage{defsophya}
    1616
    17 
     17%  Constitution d'index
     18\usepackage{makeidx}
     19\makeindex     
    1820
    1921\begin{document}
     
    3234% \auteursall
    3335%  The title page - bottom of the page with the paper number
     36\vspace{1cm}
     37\begin{center}
     38{\bf \Large Document being updated !}
     39\end{center}
    3440\titrebp{1}
    3541\end{titlepage}
     
    4147\section{Introduction}
    4248
    43    {\bf SOPHYA} ({\bf SO}ftware for {\bf PHY}sics {\bf A}nalysis)
     49{\bf SOPHYA} ({\bf SO}ftware for {\bf PHY}sics {\bf A}nalysis)
    4450is a collection of C++ classes designed for numerical and
    4551physics analysis software development. Our goal is to provide
     
    5561and Planck mission problem.
    5662  The source directory tree
    57 \footnote{ CVS server: cvsserver.lal.in2p3.fr:/projects/Eros/CVSPlanck}
     63\footnote{ CVS: cvsserver.lal.in2p3.fr:/exp/eros/CVSPlanck}
    5864is organised into a number of modules.
    5965
     
    112118
    113119\section{Using Sophya}
     120Basic usage of Sophya classes are described in in the following sections.
     121Complete Sophya documentation can be found at our web site: \\
     122{\bf http://hfi-l2.in2p3.fr}.
     123
     124\subsection{Environment variables}
    114125Two environment variables {\bf DPCBASEREP} and {\bf EROSCXX} are used
    115126to define the path where the Sophya libraries and executable are installed.
     
    140151{\tt \$EXTLIBDIR/Linux-g++/Libs} \\
    141152
     153\subsection{User makefiles}
    142154The file {\tt \$DPCBASEREP/Include/MakefileUser.h} defines the compilation
    143155flags and the list of Sophya libraries. It should be included in the
     
    168180example makefile.
    169181
    170 Basic usage of Sophya classes are described in in the following sections.
    171 Complete Sophya documentation can be found at our web site: \\
    172 {\bf http://hfi-l2.in2p3.fr}.
    173 
     182\subsection{the runcxx program}
     183\index{runcxx}
     184{\bf runcxx} is a simple program which can be used to compile, link
     185and run simple C++ programs. It handles the creation of a
     186complete program file, containing the basic set C++ include files,
     187the necessary include files for SOPHYA SysTools, TArray, HiStats
     188and NTools modules, and the main program with exception handling.
     189Other Sophya modules can be included using the {\tt -import} flag.
     190\begin{verbatim}
     191csh> runcxx -h
     192SOPHYA 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}
     202Most examples in this manual can be tested using runcxx. The
     203example below shows how to compile, link and run a sample
     204code.
     205\begin{verbatim}
     206//  File example.icc
     207Matrix a(3,3);
     208a = IdentityMatrix(1.);
     209cout << a ;
     210// Executing this sample code
     211csh> runcxx -f example.icc
     212\end{verbatim}
     213 
     214
     215\section{Copy constructor and assignment operator}
     216In C++, objects can be copied by assignment or by initialization.
     217Copying by initialization corresponds to creating an object and
     218initializing its value through the copy constructor.
     219The copy constructor has its first argument as a reference, or
     220const reference to the object's class type. It can have 
     221more arguments, if default values are provided.
     222Copying by assignment applies to an existing object and
     223is performed through the assignment operator (=).
     224The copy constructor implements this for identical type objects:
     225\begin{verbatim}
     226class MyObject {
     227public:
     228  MyObject();      // Default constructor
     229  MyObject(MyObject const & a);  // Copy constructor
     230  MyObject & operator = (MyObject const & a) // Assignment operator
     231}
     232\end{verbatim}
     233The copy constructors play an important role, as they are
     234called when class objects are passed by value,
     235returned 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
     239MyObject f(MyObject x)
     240{
     241  MyObject r;
     242  ...
     243  return(r);  // Copy constructor is called here
     244}
     245// Calling the function :
     246MyObject a;
     247f(a);        // Copy constructor called for a
     248\end{verbatim}
     249It should be noted that the C++ syntax is ambiguous for the
     250assignment operator. {\tt MyObject x; x=y; } and
     251{\tt MyObject x=y;} have different meaning.
     252\begin{verbatim}
     253MyObject a;        // default constructor call
     254MyObject b(a);     // copy constructor call
     255MyObject bb = a;   // identical to bb(a) : copy constructor call
     256MyObject c;        // default constructor call
     257c = a;             // assignment operator call
     258\end{verbatim}
     259
     260As a general rule in SOPHYA, objects which implements
     261reference sharing on their data members have a copy constructor
     262which shares the data, while the assignment operator copies or
     263duplicate the data.
    174264
    175265\section{Module SysTools}
     
    183273
    184274\subsection{SOPHYA persistence}
     275\index{PPersist} \index{PInPersist} \index{POutPersist}
    185276\begin{figure}[hbt]
    186277\dclsa{PPersist}
     
    210301
    211302\subsection{\tcls{NDataBlock}}
     303\index{\tcls{NDataBlock}}
     304\begin{figure}[hbt]
     305\dclsbb{AnyDataObj}{\tcls{NDataBlock}}
     306\dclsbb{PPersist}{\tcls{FIO\_NDataBlock}}
     307\end{figure}
    212308The {\bf \tcls{NDataBlock}} is designed to handle reference counting
    213309and sharing of memory blocs (contiguous arrays) for numerical data
     
    242338\end{verbatim}
    243339
     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}
     346The {\bf DVList} class objects can be used to create and manage list
     347of values, associated with names. A list of pairs of (MuTyV, name(string))
     348is maintained by DVList objects. {\bf MuTyV} is a simple class
     349capable of holding string, integer, float or complex values,
     350providing easy conversion methods between these objects.
     351\begin{verbatim}
     352// Using MuTyV objects
     353MuTyV s("hello");  // string type value
     354MuTyV x;
     355x = "3.14159626";    // string type value, ascii representation for Pi
     356double d = x;        // x converted to double = 3.141596
     357x = 314;             // x contains the integer value = 314
     358// Using DVList
     359DVList  dvl;
     360dvl("Pi") = 3.14159626;            // float value, named Pi
     361dvl("Log2") = 0.30102999;          // float value, named Log2
     362dvl("FileName") = "myfile.fits";   // string value, named myfile.fits
     363// Printing DVList object
     364cout << dvl;
     365\end{verbatim}
     366
    244367\subsection{Using DataCards}
     368\index{DataCards}
    245369The {\bf DataCards} class can be used to read parameters from a file.
    246370Each line in the file starting with \@ defines a set of values
     
    262386
    263387\subsection{Dynamic linker}
     388\index{PDynLinkMgr}
    264389The class {\bf PDynLinkMgr} can be used for managing shared libraries
    265390at run time. The example below shows the run time linking of a function:\\
     
    279404
    280405\subsection{CxxCompilerLinker class}
     406\index{CxxCompilerLinker}
    281407This class provides the services to compile C++ code and building
    282408shared libraries, using the same compiler and options which have
     
    300426
    301427\section{Module TArray}
     428\index{\tcls{TArray}}
    302429{\bf TArray} module contains template classes for handling standard
    303430operations on numerical arrays. Using the class {\tt \tcls{TArray} },
    304431it is possible to create and manipulate up to 5-dimension numerical
    305 arrays {\tt (int, float, double, complex, \ldots)}.   
     432arrays {\tt (int, float, double, complex, \ldots)}. The include
     433file {\tt array.h} declares all the classes and definitions
     434in module TArray. 
    306435
    307436\begin{figure}[hbt]
    308437\dclsccc{AnyDataObj}{BaseArray}{\tcls{TArray}}
    309 \ldots \\
     438\dclsbb{PPersist}{\tcls{FIO\_TArray}}
     439\end{figure}
     440
     441
     442\subsection{Using arrays}
     443\index{Sequence} \index{RandomSequence} \index{RegularSequence}
     444\index{EnumeratedSequence}
     445The example below shows basic usage of arrays, creation, initialization
     446and arithmetic operations. Different kind of {\bf Sequence} objects
     447can be used for initializing arrays.
     448\begin{figure}[hbt]
     449\dclsbb{Sequence}{RandomSequence}
     450\dclsb{RegularSequence}
     451\dclsb{EnumeratedSequence}
     452\end{figure}
     453
     454The example below shows basic usage of arrays:
     455\begin{verbatim}
     456// Creating and initializing a 1-D array of integers
     457TArray<int> ia(5);
     458EnumeratedSequence es;
     459es = 24, 35, 46, 57, 68;
     460ia = es;
     461cout << "Array<int> ia = " << ia;
     462// 2-D array of float filled with random numbers 
     463// 2-D array of floats
     464TArray<r_4> b(6,4), c(6,4);
     465// Initializing b with a constant
     466b = 2.71828;
     467// Filling c with random numbers 
     468c = RandomSequence();
     469// Arithmetic operations
     470TArray<r_4> d = b+0.3f*c;
     471cout << "Array<float> d = " << d;
     472\end{verbatim}
     473
     474The copy constructor shares the array data, while the assignment operator
     475copies the array elements, as illustrated in the following example:
     476\begin{verbatim}
     477TArray<int> a1(4,3);
     478a1 = RegularSequence(0,2);
     479// Array a2 and a1 shares their data
     480TArray<int> a2(a1);
     481// a3 and a1 have the same size and identical elements
     482TArray<int> a3;
     483a3 = a1;
     484// Changing one of the a2 elements
     485a2(1,1,0) = 555;
     486// a1(1,1) is also changed to 555, but not a3(1,1)
     487cout << "Array<int> a1 = " << a1;
     488cout << "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]
    310497\dclsccc{\tcls{TArray}}{\tcls{TMatrix}}{\tcls{TVector}}
    311 \caption{partial class diagram for arrays, matrices and vectors}
    312498\end{figure}
    313 
    314 
    315 \subsection{Using arrays}
    316 
    317 The example below shows basic usage of arrays:
    318 \begin{verbatim}
    319 #include "array.h"
    320 // ...
    321 // Creation , filling of a Matrix
    322   TMatrix<r_4> ma(7,9);
    323   ma = RegularSequence(0.1, 0.05);   
    324   cout << "\n ma = " << ma << endl;
    325 \end{verbatim}
     499Vectors and matrices are 2 dimensional arrays. The array size
     500along one dimension is equal 1 for vectors. Column vectors
     501have {\tt NCols() = 1} and row vectors have {\tt NRows() = 1}.
    326502
    327503Example of a simple low-pass filter on a one dimensional array (Vector)
     
    497673needed (they used buffers on hard disk).
    498674
    499 \subsection{Writing, seeing \dots }
     675\subsection{Writing, viewing \dots }
    500676
    501677All these objects have been design to be written to or read from a persistant file.
     
    760936\newpage
    761937\appendix
    762 \section{Exception handling: An example}
     938\section{SOPHYA Exceptions}
     939\index{Exception classes} \index{PThrowable} \index{PError} \index{PException}
     940SOPHYA library defines a set of exceptions which are used
     941for signaling error conditions. The figure below shows a partial
     942class 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
    763960For simple programs, it is a good practice to handle
    764961the exceptions at least at high level, in the {\tt main()} function.
     
    769966
    770967
     968\newpage
     969\addcontentsline{toc}{section}{Index}
     970\printindex
    771971\end{document}
     972 
Note: See TracChangeset for help on using the changeset viewer.