- Timestamp:
- Dec 22, 2000, 5:53:02 PM (25 years ago)
- Location:
- trunk/SophyaLib/Manual
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/Manual/defsophya.sty
r978 r1362 2 2 % Definition of template class \tcls{Vector} --> Vector<T> 3 3 \newcommand{\tcls}[1] {#1$<$T$>$} 4 \newcommand{\tclsc}[2] {#1$<$#2$>$} 4 5 % Putting a class name in a box 5 6 \newcommand{\clsbox}[1] { \framebox[40mm][c]{\mbox{\rule[-1mm]{0mm}{5mm} \bf #1} } } -
trunk/SophyaLib/Manual/sophya.tex
r1360 r1362 15 15 \usepackage{defsophya} 16 16 17 17 % Constitution d'index 18 \usepackage{makeidx} 19 \makeindex 18 20 19 21 \begin{document} … … 32 34 % \auteursall 33 35 % 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} 34 40 \titrebp{1} 35 41 \end{titlepage} … … 41 47 \section{Introduction} 42 48 43 49 {\bf SOPHYA} ({\bf SO}ftware for {\bf PHY}sics {\bf A}nalysis) 44 50 is a collection of C++ classes designed for numerical and 45 51 physics analysis software development. Our goal is to provide … … 55 61 and Planck mission problem. 56 62 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} 58 64 is organised into a number of modules. 59 65 … … 112 118 113 119 \section{Using Sophya} 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} 114 125 Two environment variables {\bf DPCBASEREP} and {\bf EROSCXX} are used 115 126 to define the path where the Sophya libraries and executable are installed. … … 140 151 {\tt \$EXTLIBDIR/Linux-g++/Libs} \\ 141 152 153 \subsection{User makefiles} 142 154 The file {\tt \$DPCBASEREP/Include/MakefileUser.h} defines the compilation 143 155 flags and the list of Sophya libraries. It should be included in the … … 168 180 example makefile. 169 181 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 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 214 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} 259 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. 174 264 175 265 \section{Module SysTools} … … 183 273 184 274 \subsection{SOPHYA persistence} 275 \index{PPersist} \index{PInPersist} \index{POutPersist} 185 276 \begin{figure}[hbt] 186 277 \dclsa{PPersist} … … 210 301 211 302 \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} 212 308 The {\bf \tcls{NDataBlock}} is designed to handle reference counting 213 309 and sharing of memory blocs (contiguous arrays) for numerical data … … 242 338 \end{verbatim} 243 339 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 244 367 \subsection{Using DataCards} 368 \index{DataCards} 245 369 The {\bf DataCards} class can be used to read parameters from a file. 246 370 Each line in the file starting with \@ defines a set of values … … 262 386 263 387 \subsection{Dynamic linker} 388 \index{PDynLinkMgr} 264 389 The class {\bf PDynLinkMgr} can be used for managing shared libraries 265 390 at run time. The example below shows the run time linking of a function:\\ … … 279 404 280 405 \subsection{CxxCompilerLinker class} 406 \index{CxxCompilerLinker} 281 407 This class provides the services to compile C++ code and building 282 408 shared libraries, using the same compiler and options which have … … 300 426 301 427 \section{Module TArray} 428 \index{\tcls{TArray}} 302 429 {\bf TArray} module contains template classes for handling standard 303 430 operations on numerical arrays. Using the class {\tt \tcls{TArray} }, 304 431 it is possible to create and manipulate up to 5-dimension numerical 305 arrays {\tt (int, float, double, complex, \ldots)}. 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. 306 435 307 436 \begin{figure}[hbt] 308 437 \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} 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} 453 454 The example below shows basic usage of arrays: 455 \begin{verbatim} 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; 472 \end{verbatim} 473 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] 310 497 \dclsccc{\tcls{TArray}}{\tcls{TMatrix}}{\tcls{TVector}} 311 \caption{partial class diagram for arrays, matrices and vectors}312 498 \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} 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}. 326 502 327 503 Example of a simple low-pass filter on a one dimensional array (Vector) … … 497 673 needed (they used buffers on hard disk). 498 674 499 \subsection{Writing, seeing \dots }675 \subsection{Writing, viewing \dots } 500 676 501 677 All these objects have been design to be written to or read from a persistant file. … … 760 936 \newpage 761 937 \appendix 762 \section{Exception handling: An example} 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 763 960 For simple programs, it is a good practice to handle 764 961 the exceptions at least at high level, in the {\tt main()} function. … … 769 966 770 967 968 \newpage 969 \addcontentsline{toc}{section}{Index} 970 \printindex 771 971 \end{document} 972
Note:
See TracChangeset
for help on using the changeset viewer.