\documentclass[twoside,11pt]{article}
%  Package standard : Utilisation de caracteres accentues, mode francais et graphique
\usepackage{url}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{graphicx}
% package a mettre pour faire du pdf
\usepackage{palatino}

%  Extension de symboles mathematiques
\usepackage{amssymb}

%  Definition pour Docs Sophya
\usepackage{defsophya}



\begin{document}

\begin{titlepage}
%  The title page - top of the page with the title of the paper
\titrehp{Sophya  \\ An overview }
%  Authors list
\auteurs{
R. Ansari            &  ansari@lal.in2p3.fr       \\
G. Le Meur           &  lemeur@lal.in2p3.fr       \\
C. Magneville        &  cmv@hep.saclay.cea.fr     \\
S. Henrot-Versille   &  versille@in2p3.fr     
}
% \auteursall
%  The title page - bottom of the page with the paper number
\titrebp{1}
\end{titlepage}

\tableofcontents

\newpage

\section{Introduction}

   {\bf SOPHYA} ({\bf SO}ftware for {\bf PHY}sics {\bf A}nalysis) 
is a collection of C++ classes designed for numerical and
physics analysis software development. Our goal is to provide
easy to use, yet powerful classes which can be used by scientists.
We have decided to use as much as possible available 
numerical analysis libraries, encapsulating them whenever
possible.
  
  The SOPHYA design and implementation has been carried out
with the specific goal of providing the general framework for
the Planck-HFI data processing software. However, most of the 
packages presented here have a more general scope than the CMB analysis
and Planck surveyor mission problem.
  The source directory tree 
\footnote{ CVS server: cvsserver.lal.in2p3.fr:/projects/Eros/CVSEros} 
is organised into a number of modules. 

\begin{itemize}
\item[] {\bf Mgr/}  Scripts for code management, 
makefile generation and software installation
\item[] {\bf SysTools/} General architecture support classes such 
as {\tt PPersist, NDataBlock<T>}, and few utility classes 
({\tt DataCard, DVList} \ldots). 
\item[] {\bf TArray/} template numerical arrays, vectors and matrices
({\tt PixelMap<T> SphericalMap<T>} \ldots) 
\item[] {\bf NTools/} Some standard numerical analysis tools 
(linear, and non linear parameter fitting, FFT, \ldots)
\item[] {\bf HiStats/}  Histogram-ming and data set handling classes \\
({\tt Histo Histo2D NTuple XNTuple} \ldots)
\end{itemize}

The modules listed below are more tightly related to the 
CMB (Cosmic Microwave Background) data analysis problem:
\begin{itemize}
\item[] {\bf SkyMap/} Local and full sky maps, and few geometry 
handling utility classes. \\
({\tt PixelMap<T>, LocalMap<T>, SphericalMap<T>, \ldots})
\item[] {\bf SkyT/} 
classes for spectral emission and detector frequency response modelling \\
({\tt SpectralResponse, RadSpectra, BlackBody} \ldots)
\item[] {\bf Samba/} few classes for map and TOD analysis.
\item[] {\bf PMixer/} skymixer and related programs
\end{itemize}

The following modules contain the interface classes with 
external libraries:
\begin{itemize}
\item[] {\bf FitsIOServer/} Classes for handling file input-output 
in FITS format using the cfitsio library.
\item[] {\bf LinAlg/} Interface with Lapack linear algebra package
\item[] {\bf IFFTW/} Interface with FFTW package
\end{itemize}

Other modules:
\begin{itemize}
\item[] {\bf Tests/} Simple test programs
\item[] {\bf ProgPI/}  interactive analysis tool - It should be noted that 
this module uses the SOPHYA class library and is based on {\bf PI}
which is a C++ library defining a complete GUI program 
architecture. An additional module (PIext) define the interactive
analysis program framework and the interfaces with the objects
in SOPHYA.  The {\bf PI/} \footnote{the PI package documentation 
is available from {\bf http://www.lal.in2p3.fr/recherche/eros/PeidaDoc/} } 
and {\bf PIext/} modules are not currently part 
of the SOPHYA CVS structure.
\end{itemize}   

\newpage 

\section{Using Sophya}
Two environment variables {\bf DPCBASEREP} and {\bf EROSCXX} are used 
to define the path where the Sophya libraries and executable are installed.
{\bf DPCBASEREP} defines the base directory path and {\bf EROSCXX} the 
name of the C++ compiler. The complete path is built using {\bf DPCBASEREP},
the operating system name (as obtained by the {\tt uname} command), and
the compiler name. In the example below, we show the complete path
for a {\tt Linux} system, using the GNU g++ compiler:

\begin{itemize}
\item \$DPCBASEREP/Include : Include (.h) files
\item \$DPCBASEREP/Linux-g++/Libs : Path for the archive libraries (.a)
\item \$DPCBASEREP/Linux-g++/ShLibs : Shared library path (.so)
\item \$DPCBASEREP/Linux-g++/Exec : Executable file path
\end{itemize}

In order to use the shared libraries, the {\bf LD\_LIBRARY\_PATH} variable
should contain the Sophya shared library path 
({\tt \$DPCBASEREP/Linux-g++/ShLibs } when using g++ compiler on Linux)

The file {\tt \$DPCBASEREP/Include/MakefileUser.h} defines the compilation 
flag and the list of Sophya libraries. It should be included in the 
user's makefile. The default compilation rules assumes that the object (.o) 
and executable files would be put in the following diretories: \\
{\tt \$HOME/`uname`-\$EROSCXX/Objs} \\ 
{\tt \$HOME/`uname`-\$EROSCXX/Exec}.
In the case of a {\tt Linux} system and using {\tt g++} as the C++ compiler, 
these two directories would be translated to \\
{\tt \$HOME/Linux-g++/Objs} and {\tt \$HOME/Linux-g++/Exec}. 
The GNU make program should be used.
\par
The file {\tt \$DPCBASEREP/Include/makefile\_auto} defines the rules to compile
a given source program, and link it against the Sophya libraries to produce
an executable. The example below shows the steps to compile a program named
{\tt trivial.cc }.
\begin{verbatim}
csh> cp $DPCBASEREP/Include/makefile_auto makefile
csh> make trivial
\end{verbatim}
This command should compile the {\tt trivial.cc} file, 
and link it against the sophya libraries. The object and executable 
file names are: \\ 
{\tt \$HOME/`uname`-\$EROSCXX/Objs/trivial.o} \\
{\tt \$HOME/`uname`-\$EROSCXX/Exec/trivial}.
\par 
The file {\tt \$DPCBASEREP/Include/makefile\_example} provides another 
example makefile.


\newpage 

\section{Building and installing Sophya}
Presently, the Sophya library compilation has been tested with the following
compiler/platform pairs:

\begin{center}
\begin{tabular}{ll}
Compaq/DEC OSF1  &     cxx  (6.0 , 6.2)  \\
Linux            &     g++  (2.91 , 2.95)  \\
Linux            &     KCC  (3.4)   \\
Solaris          &     g++  (2.95)  \\
SGI IRIX64       &     CC           \\
\end{tabular}
\end{center}

Some of the modules in the Sophya package uses external libraries. The 
{\bf FitsIOServer} is the example of such a module, where the {\tt libcfitsio.a}
is used.
The build procedure expects to find the include files and the libraries in: \\
{\tt \$EXTLIBDIR/Include/FitsIO } \\
{\tt \$EXTLIBDIR/`uname`-\$EROSCXX/Libs} \\

The object files from a given Sophya module are grouped in an archive library 
with the module's name ({\tt libmodulename.a}). All Sophya modules 
 are grouped in a single shared library ({\tt libsophya.so}), while the 
modules with reference to external libraries are grouped in 
({\tt libextsophya.so}). The {\bf PI} and {\bf PIext} modules are 
grouped in ({\tt libPI.so}).

The environment variables {\bf DPCDEVREP}, {\bf EXTLIBDIR} and {\bf EROSCXX}
must be defined in order to install the Sophya package.
In the example below, we assume that we want to install Sophya from a 
released (tagged) version in the source directory {\tt \$SRC} in the
{\tt /usr/local/Sophya} diretory, using {\tt g++}. We assume that 
the external libraries directory tree has been set up in 
{\tt /usr/local/ExtLibs/}. \\[3mm]
\centerline{ 
	  \rule{20mm}{0.5mm} 
	{\bf \large the use of GNU make is mandatory} 
	\rule{20mm}{0.5mm} }

\vspace*{3mm}
\begin{verbatim}
# We select our C++ compiler
csh> setenv EROSCXX g++
# Setup the build directory
csh> mkdir /usr/local/Sophya/
csh> setenv DPCDEVREP /usr/local/Sophya/
csh> setenv EXTLIBDIR /usr/local/ExtLibs/
# Use the top level makefile in Mgr/ 
csh> cd $SRC
csh> cp Mgr/Makefile Makefile
# Step 1: Create the directory tree and copy the include files (.h)
csh> make depend
# Step 2: Compile the modules without external library reference
csh> make libs
# Step 3: Compile the modules WITH  external library reference (optional) 
csh> make extlibs
# Step 4: Build libsophya.so
csh> make slb
# Step 5: Build libextsophya.so (optional)
csh> make slbext
# Step 6: Compile the PI and PIext modules (optional)
csh> make PI
# Step 7: Build the corresponding shared library libPI.so (optional)
csh> make slbpi
\end{verbatim}

To compile all modules and build the shared libraries, it is possible 
to use:
\begin{verbatim}
# Step 2,3,6
csh> make all
# Step 4,5,7
csh> make slball
\end{verbatim}

At this step, all libraries sould have been made. Programs using
Sophya libraries can now be built:
\begin{verbatim}
# To compile test programs
csh> cd Tests
csh> make arrt ...
csh> cd ..
# To compile other programs, for example from the PMixer module
csh> cd PMixer
csh> make
csh> cd ..
# To build (s)piapp (libPI.so is needed)
csh> cd ProgPI
csh> make 
csh> cd ..
\end{verbatim}

\subsection{Mgr module}
This module contains scripts which can be used for generating the 
makefiles for each module.
\begin{itemize}
\item {\bf Makefile} Top level Makefile for builiding the libraries.
\item {\bf Makefile.h} contains the defintion of compilation flags for the 
different compilers and systems. This file is used for building the 
library and generating {\bf MakefileUser.h} (to be included in makefiles).
\item {\bf Makefile.slb} contains the rules for building shared libraries
for the different compilers and systems. (to be included in makefiles)
\item {\bf crerep\_sophya} c-shell script for creating the directory tree
under {\tt \$DPCBASEREP} and {\tt \$DPCDEVREP}
\item {\bf install\_sophya} c-shell script for installing the Sophya package.
Usually from {\tt \$DPCDEVREP} to {\tt \$DPCBASEREP}
\item {\bf mkmflien} c-shell script for making symbolic links or copying
include files to {\tt \$DPCDEVREP/Include} or {\tt \$DPCBASEREP/Include}
\item {\bf mkmf} c-shell script for generating module makefiles and the 
top level makefile (named GNUmakefile)
\item {\bf mkmflib} c-shell script for generating each library module 
makefile (named GNUmakefile)
\item {\bf mkmfprog} c-shell script for generating makefile for a module
containing the source for executable programs (named GNUmakefile).
\item {\bf mkmfPI} c-shell script for generating makefile for PI and PIext
modules (named GNUmakefile)
\item {\bf libdirs} List of Sophya modules without reference to external
libraries.
\item {\bf extlibdirs} List of Sophya modules with reference to external
libraries.

\end{itemize}
 
\newpage

\section{Learning Sophya through examples}
The examples here illustrates the basic 
usage of Sophya classes. Sophya documentation can be found at our web site: \\
{\bf http://hfi-l2.in2p3.fr}. 

\subsection{Using classes in SysTools}

{\bf SysTools} contains utility classes such as {\tt DataCards} or 
{\tt DVlist}, an hierarchy of exception classes for Sophya, a template
class {\tcls{NDataBlock}} for handling reference counting on numerical
arrays, as well as classes providing the services for implementing simple
serialization. For simple programs, it is a good practice to handle 
the exceptions at least at high level, in the {\tt main()} function. 
The example below shows the exception handling and the usage 
of Sophya persistence.
\vspace*{5mm}

\begin{figure}[hbt]
\dclsa{PPersist}
\dclsbb{PIOPersist}{PInPersist}
\dclsb{POutPersist}
\caption{partial class diagram for classes handling persistencein Sophya}
\end{figure}

\input{ex1.inc}

\subsection{Using arrays and matrices}
{\bf TArray} module contains template classes for handling standard 
operations on numerical arrays. Using the class {\tt \tcls{TArray} },
it is possible to create and manipulate up to 5-dimension numerical
arrays {\tt (int, float, double, complex, \ldots)}.   

\end{document}