Changeset 3752 in Sophya for trunk/SophyaProg


Ignore:
Timestamp:
Mar 3, 2010, 9:48:20 PM (16 years ago)
Author:
ansari
Message:

Amelioration du programme tobjio.cc ( Tests I/O PPF ), ajout test systematique R/W PPF des TArray<T> , Reza 03/03/2010

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaProg/Tests/tobjio.cc

    r3572 r3752  
    1515#include "fmath.h"
    1616#include "srandgen.h"
     17#include "tarray.h"
     18#include "arrctcast.h"
    1719#include "fioarr.h"
    18 
    19 
     20#include "timing.h"
     21
     22#include <typeinfo>
     23#include <datatype.h>
     24
     25/* ------------------------------------------------------------------
     26  Programme de test des fonctionalites de persistance (PPF) de SOPHYA
     27  (C) LAL/IN2P3-CNRS, Univ. Paris Sud,   IRFU-CEA   1999-2010
     28  SOPHYA::PPersist ....
     29  Utilisation:
     30  csh> tobjio --> mini help
     31  csh> tobjio A
     32  csh> tobjio B
     33*/
     34
     35static int ppftstA();
     36static int ppftstB();
     37
     38/* -- Main program -- */
    2039int main(int narg, char* arg[])
    2140{
    2241
     42int rc = 0;
     43if (narg < 2) {
     44  cout << " Usage: tobjio A/B \n"
     45       << "   A : Create tobjio.ppf file containing Histo/NTuple/Array \n"
     46       << "   B : Check PPF I/O on TArray<T> \n" << endl;
     47  return 1;
     48}
     49string opt = arg[1];
     50try {
    2351  SophyaInit();
    24 
     52  InitTim();
    2553  cout << "Hash check, OMatrix : " << hex << PIOPersist::Hash("OMatrix") << dec << endl;
    26 
     54  if (opt=="A")  rc = ppftstA();
     55  else rc = ppftstB();
     56}
     57catch (PThrowable & exc) {
     58  cerr << " tobjio.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
     59       << " - Msg= " << exc.Msg() << endl;
     60  rc = 99;
     61 }
     62catch (std::exception & e) {
     63  cerr << " tobjio.cc: Catched std::exception what()=" << e.what() << endl;
     64  rc=98;
     65 }
     66catch (...) {
     67  cerr << " tobjio.cc: some other exception (...) was caught ! " << endl;
     68  rc = 97;
     69}
     70PrtTim("End tobjio " );
     71cout << " ---- Programme tobjio.cc-  FIN  (Rc=" << rc << ") --- " << endl;
     72return rc;
     73
     74}
     75
     76
     77
     78
     79static sa_size_t NX = 15;
     80static sa_size_t NY = 20;
     81
     82/* --Fonction-- */
     83template <class T>
     84int ckppf_arr(T x)
     85{
     86  int rc=0;
     87  cout << " ---- ckppf_arr ----- T= " << typeid(x).name() << " , "
     88       << DataTypeInfo<T>::getTypeName() << endl;
     89  TArray<T> a(10,12);
     90  a = RegularSequence();
     91  {
     92    POutPersist po("arrtobj.ppf");
     93    po << a;
     94  }
     95  TArray<T> b;
     96  {
     97    PInPersist pin("arrtobj.ppf");
     98    pin >> b;
     99  }
     100  TArray<T> d = a-b;
     101  T min, max;
     102  d.MinMax(min,max);
     103  cout << "  diff d=a-b, Min=" << min << " Max=" << max << endl;
     104  if ((min != T(0))||(max != T(0)))  rc=9;
     105  if (rc==0)
     106    cout << " ===>>> PPF I/O TArray< " << DataTypeInfo<T>::getTypeName() << " > OK " << endl;
     107  else
     108    cout << " ===>>> PPF I/O TArray< " << DataTypeInfo<T>::getTypeName() << " > ERROR !!!! " << endl;
     109  return rc;
     110}
     111
     112/* --Fonction-- */
     113template <class T>
     114int ckppf_arrZ(T x)
     115{
     116  int rc=0;
     117  cout << " ---- ckppf_arrZ ----- complex< T= " << typeid(x).name() << " , "
     118       << DataTypeInfo<T>::getTypeName() << " > " << endl;
     119  TArray< complex<T> > a(10,12);
     120  TArray<T> rea = SDRealPart(a);
     121  TArray<T> ima = SDImagPart(a);
     122 
     123  rea = RegularSequence();
     124  ima = RegularSequence(0.5,2.);
     125  {
     126    POutPersist po("arrtobj.ppf");
     127    po << a;
     128  }
     129  TArray< complex<T> > b;
     130  {
     131    PInPersist pin("arrtobj.ppf");
     132    pin >> b;
     133  }
     134  TArray< complex<T> > d = a-b;
     135  T remin, remax;
     136  SDRealPart(d).MinMax(remin, remax);
     137  T immin, immax;
     138  SDImagPart(d).MinMax(immin, immax);
     139
     140  cout << "  diff real[d=a-b], Min=" << remin << " Max=" << remax << endl;
     141  cout << "  diff imag[d=a-b], Min=" << immin << " Max=" << immax << endl;
     142  if ((remin != T(0))||(remax != T(0)) ||
     143      (immin != T(0))||(immax != T(0)) )  rc=9;
     144  if (rc==0)
     145    cout << " ===>>> PPF I/O TArray< complex<" << DataTypeInfo<T>::getTypeName() << " > > OK " << endl;
     146  else
     147    cout << " ===>>> PPF I/O TArray< complex< " << DataTypeInfo<T>::getTypeName() << " > > ERROR !!!! " << endl;
     148  return rc;
     149}
     150
     151/* --Fonction-- */
     152int ppftstB()
     153{
     154  int rcg=0;
     155  int rc;
     156  int_4 i=1;
     157  int_8 l=1;
     158  r_4 f=1.;
     159  r_8 d=1.;
     160  rc=ckppf_arr(i);
     161  if (rc!=0) rcg+=10;
     162  rc=ckppf_arr(l);
     163  if (rc!=0) rcg+=10;
     164  rc=ckppf_arr(f);
     165  if (rc!=0) rcg+=10;
     166  rc=ckppf_arr(d);
     167  if (rc!=0) rcg+=10;
     168  rc=ckppf_arrZ(f);
     169  if (rc!=0) rcg+=10;
     170  rc=ckppf_arrZ(d);
     171  if (rc!=0) rcg+=10;
     172#ifdef SO_LDBLE128
     173  r_16 ld=1.;
     174  rc=ckppf_arr(ld);
     175  if (rc!=0) rcg+=10;
     176  rc=ckppf_arrZ(ld);
     177  if (rc!=0) rcg+=10;
     178#endif
     179  return rcg;
     180}
     181
     182
     183/* --Fonction-- */
     184int ppftstA()
     185{
    27186  cout << "Test Creation / PPersist Save NTuple, Histo, ..." << endl;
    28187
     
    169328  cout << "Writing " << nom << endl;
    170329  }
    171 
    172   cout << " End --- exit .... " << endl;
    173 }
    174 
     330  return 0;
     331}
     332
Note: See TracChangeset for help on using the changeset viewer.