Changeset 307 in Sophya for trunk/SophyaLib/NTools/generaldata.cc


Ignore:
Timestamp:
May 19, 1999, 5:58:06 PM (26 years ago)
Author:
ansari
Message:

FIO_... + grosses modifs cmv 19/5/99

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/NTools/generaldata.cc

    r244 r307  
    33#include <stdlib.h>
    44#include <iostream.h>
     5#include <values.h>
    56#include <math.h>
    67#include <string.h>
     
    1112#endif
    1213
    13 #include "perrors.h"
    1414#include "nbtri.h"
    1515#include "generalfit.h"
    1616#include "generaldata.h"
     17#include "pexceptions.h"
     18#include "objfio.h"
     19
     20using namespace PlanckDPC;
    1721
    1822//================================================================
     
    5256  , BuffVar(NULL), BuffVarR4(NULL)
    5357{
    54  TRY {
    55    Alloc(nVar,ndatalloc,errx);
    56  } CATCHALL {
    57    cout<<"GeneralFitData::GeneralFitData Impossible d'allouer l'espace"<<endl;
    58    THROW_SAME;
    59  } ENDTRY
    60  END_CONSTRUCTOR
    61 }
    62 
    63 //++
    64 GeneralFitData::GeneralFitData(GeneralFitData& data, bool clean)
     58try {
     59  Alloc(nVar,ndatalloc,errx);
     60} catch(PException e) {
     61  cout << "Exception : " << typeid(e).name() << " " << e.Msg() << endl;
     62  throw;
     63}
     64}
     65
     66//++
     67GeneralFitData::GeneralFitData(const GeneralFitData& data, bool clean)
    6568//
    6669//      Constructeur par copie. Si ``clean'' est ``true''
     
    7477  , BuffVar(NULL), BuffVarR4(NULL)
    7578{
    76  TRY {
    77    Alloc(data.mNVar,((clean)?data.mNDataGood:data.mNDataAlloc),((data.mErrXP)?1:0));
    78  } CATCHALL {
    79    cout<<"GeneralFitData::GeneralFitData Impossible d'allouer l'espace"<<endl;
    80    THROW_SAME;
    81  } ENDTRY
     79try {
     80  Alloc(data.mNVar,((clean)?data.mNDataGood:data.mNDataAlloc),((data.mErrXP)?1:0));
     81} catch(PException e) {
     82  cout << "Exception : " << typeid(e).name() << " " << e.Msg() << endl;
     83  throw;
     84}
    8285
    8386 // Remplissage
     
    113116
    114117//++
    115 GeneralFitData::GeneralFitData(char *flnm)
    116 //
    117 //      Constructeur par lecture d'un fichier ppersist..
    118 //--
    119   : mNVar(0), mNDataAlloc(0), mNData(0), mNDataGood(0), mOk_EXP(0)
    120   , mXP(NULL), mErrXP(NULL), mF(NULL), mErr(NULL), mOK(NULL)
    121   , BuffVar(NULL), BuffVarR4(NULL)
    122 {
    123   PInPersist s(flnm);
    124   Read(s);
    125   END_CONSTRUCTOR
    126 }
    127 
    128 //++
    129118GeneralFitData::~GeneralFitData()
    130119//
     
    153142mNDataAlloc = ndatalloc;
    154143
    155 TRY {
     144try {
    156145  mXP  = new r_8[nVar*ndatalloc];
    157146  if(mOk_EXP) mErrXP  = new r_8[nVar*ndatalloc];
     
    161150  BuffVar   = new r_8[2*nVar+3];
    162151  BuffVarR4 = (r_4 *) BuffVar;
    163 } CATCHALL {
    164   THROW_SAME;
    165 } ENDTRY
     152} catch(PException e) {
     153  throw(AllocationError("GeneralFitData::Alloc allocation error\n"));
     154}
    166155}
    167156
     
    824813//////////////////////////////////////////////////////////////////////
    825814//++
    826 GeneralFitData* GeneralFitData::FitResidus(GeneralFit& gfit)
     815GeneralFitData GeneralFitData::FitResidus(GeneralFit& gfit)
    827816//
    828817//      Retourne une classe contenant les residus du fit ``gfit''.
    829818//--
    830819{
    831 if(gfit.GetNVar()!=mNVar) return NULL;
     820if(gfit.GetNVar()!=mNVar)
     821  throw(SzMismatchError("GeneralFitData::FitResidus: size mismatch\n"));
    832822return gfit.DataResidus(true);
    833823}
    834824
    835825//++
    836 GeneralFitData* GeneralFitData::FitFunction(GeneralFit& gfit)
     826GeneralFitData GeneralFitData::FitFunction(GeneralFit& gfit)
    837827//
    838828//      Retourne une classe contenant la function du fit ``gfit''.
    839829//--
    840830{
    841 if(gfit.GetNVar()!=mNVar) return NULL;
     831if(gfit.GetNVar()!=mNVar)
     832  throw(SzMismatchError("GeneralFitData::FitFunction: size mismatch\n"));
    842833return gfit.DataFunction(true);
    843834}
     
    922913//////////////////////////////////////////////////////////////////////
    923914//++
    924 void GeneralFitData::WriteSelf(POutPersist& s)  const
    925 //
    926 //      Ecriture ppersist
    927 //--
    928 {
     915// int inline int GetSpaceFree() const
     916//      Retourne la place restante dans la structure (nombre de
     917//      donnees que l'on peut encore stoquer).
     918//--
     919//++
     920// inline int  NVar()       const
     921//      Retourne le nombre de variables Xi
     922//--
     923//++
     924// inline int  NData()
     925//      Retourne le nombre de donnees
     926//--
     927//++
     928// inline int  NDataGood()  const
     929//      Retourne le nombre de bonnes donnees (utilisees pour le fit)
     930//--
     931//++
     932// inline int  NDataAlloc() const
     933//      Retourne la place maximale allouee pour les donnees
     934//--
     935//++
     936// inline unsigned short int IsValid(int i) const
     937//      Retourne 1 si point valide, sinon 0
     938//--
     939//++
     940// inline bool HasXErrors()
     941//      Retourne ``true'' si il y a des erreurs sur les variables
     942//      d'abscisse, ``false'' sinon.
     943//--
     944//++
     945// inline double X1(int i) const
     946//      Retourne l'abscisse pour 1 dimension (y=f(x)) donnee I
     947//--
     948//++
     949// inline double X(int i) const
     950//      Retourne la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I
     951//--
     952//++
     953// inline double Y(int i) const
     954//      Retourne la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I
     955//--
     956//++
     957// inline double Z(int i) const
     958//      Retourne la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I
     959//--
     960//++
     961// inline double Absc(int j,int i) const
     962//      Retourne la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I
     963//--
     964//++
     965// inline double Val(int i) const
     966//      Retourne la valeur de la Ieme donnee
     967//--
     968//++
     969// inline double EX1(int i) const
     970//      Retourne l'erreur (dx) sur l'abscisse pour 1 dimension (y=f(x)) donnee I
     971//--
     972//++
     973// inline double EX(int i) const
     974//      Retourne l'erreur (dx) sur la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I
     975//--
     976//++
     977// inline double EY(int i) const
     978//      Retourne l'erreur (dy) sur la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I
     979//--
     980//++
     981// inline double EZ(int i) const
     982//      Retourne l'erreur (dz) sur la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I
     983//--
     984//++
     985// inline double EAbsc(int j,int i) const
     986//      Retourne l'erreur (dxj) sur la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I
     987//--
     988//++
     989// inline double EVal(int i) const {return mErr[i];}
     990//      Retourne l'erreur de la Ieme donnee
     991//--
     992
     993///////////////////////////////////////////////////////////
     994// --------------------------------------------------------
     995//   Les objets delegues pour la gestion de persistance
     996// --------------------------------------------------------
     997///////////////////////////////////////////////////////////
     998
     999FIO_GeneralFitData::FIO_GeneralFitData()
     1000{
     1001dobj=new GeneralFitData;
     1002ownobj=true;
     1003}
     1004
     1005FIO_GeneralFitData::FIO_GeneralFitData(string const & filename)
     1006{
     1007dobj=new GeneralFitData;
     1008ownobj=true;
     1009Read(filename);
     1010}
     1011
     1012FIO_GeneralFitData::FIO_GeneralFitData(const GeneralFitData & obj)
     1013{
     1014dobj = new GeneralFitData(obj);
     1015ownobj=true;
     1016}
     1017
     1018FIO_GeneralFitData::FIO_GeneralFitData(GeneralFitData * obj)
     1019{
     1020dobj = obj;
     1021ownobj=false;
     1022}
     1023
     1024FIO_GeneralFitData::~FIO_GeneralFitData()
     1025{
     1026if (ownobj && dobj) delete dobj;
     1027}
     1028
     1029AnyDataObj* FIO_GeneralFitData::DataObj()
     1030{
     1031return(dobj);
     1032}
     1033
     1034void FIO_GeneralFitData::ReadSelf(PInPersist& is)
     1035{
     1036char strg[256];
     1037
     1038if(dobj==NULL) dobj=new GeneralFitData;
     1039  else         dobj->Delete();
     1040
     1041// Lecture entete
     1042is.GetLine(strg, 255);
     1043
     1044// Ecriture des valeurs de definitions
     1045int_4 nvar,ndatalloc,ndata,ndatagood;
     1046is.Get(nvar);
     1047is.Get(ndatalloc);
     1048is.Get(ndata);
     1049is.Get(ndatagood);
     1050is.Get(dobj->mOk_EXP);
     1051if(nvar<=0 || ndatalloc<=0 || ndata<=0 || ndatagood<0 || ndatalloc<ndata) return;
     1052
     1053// Allocation de la place (attention Alloc efface mNData,mNDataGood);
     1054dobj->Alloc(nvar,ndatalloc,-1);
     1055dobj->mNData = ndata;
     1056dobj->mNDataGood = ndatagood;
     1057
     1058// Lecture des datas
     1059is.GetLine(strg, 255);
     1060int blen = dobj->mNVar + 3;
     1061if(dobj->mOk_EXP) blen += dobj->mNVar;
     1062double *buff = new double[blen];
     1063for(int i=0;i<dobj->mNData;i++) {
     1064  is.Get(buff, blen);
     1065  int ip = i*dobj->mNVar;
     1066  {for(int j=0;j<dobj->mNVar;j++)  dobj->mXP[ip+j] = buff[j];}
     1067  dobj->mF[i] = buff[dobj->mNVar];
     1068  dobj->mErr[i] = buff[dobj->mNVar+1];
     1069  dobj->mOK[i] = (uint_2)(buff[dobj->mNVar+2]+0.01);
     1070  if(dobj->mOk_EXP) {for(int j=0;j<dobj->mNVar;j++)
     1071                        dobj->mErrXP[ip+j] = buff[dobj->mNVar+3+j];}
     1072}
     1073delete [] buff;
     1074
     1075return;
     1076}
     1077
     1078void FIO_GeneralFitData::WriteSelf(POutPersist& os) const
     1079{
     1080if (dobj == NULL)   return;
    9291081char strg[256];
    9301082
    9311083// Ecriture entete pour identifier facilement
    9321084sprintf(strg,"GeneralFitData: NVar=%d NDataAlloc=%d NData=%d NDataGood=%d Ok_EXP=%d"
    933        ,mNVar,mNDataAlloc,mNData,mNDataGood,mOk_EXP);
    934 s.PutLine(strg);
     1085       ,dobj->mNVar,dobj->mNDataAlloc,dobj->mNData,dobj->mNDataGood,dobj->mOk_EXP);
     1086os.PutLine(strg);
    9351087
    9361088// Ecriture des valeurs de definitions
    937 s.PutI4(mNVar);
    938 s.PutI4(mNDataAlloc);
    939 s.PutI4(mNData);
    940 s.PutI4(mNDataGood);
    941 s.PutU2(mOk_EXP);
    942 if(mNVar<=0 || mNDataAlloc<=0 || mNData<=0 || mNDataGood<0) return;
     1089os.Put(dobj->mNVar);
     1090os.Put(dobj->mNDataAlloc);
     1091os.Put(dobj->mNData);
     1092os.Put(dobj->mNDataGood);
     1093os.Put(dobj->mOk_EXP);
     1094if(dobj->mNVar<=0 || dobj->mNDataAlloc<=0 || dobj->mNData<=0 || dobj->mNDataGood<0) return;
    9431095
    9441096// Ecriture des datas (on n'ecrit que mNData / mNDataAlloc)
    9451097sprintf(strg
    9461098       ,"GeneralFitData: Abscisses, Ordonnee, Erreur Ordonnee, Flag, Erreur Abscisses");
    947 s.PutLine(strg);
    948 
    949 int blen = mNVar + 3;
    950 if(mOk_EXP) blen += mNVar;
     1099os.PutLine(strg);
     1100
     1101int blen = dobj->mNVar + 3;
     1102if(dobj->mOk_EXP) blen += dobj->mNVar;
    9511103double *buff = new double[blen];
    952 for(int i=0;i<mNData;i++) {
    953   {for(int j=0;j<mNVar;j++) buff[j] = Absc(j,i);}
    954   buff[mNVar] = Val(i);
    955   buff[mNVar+1] = EVal(i);
    956   buff[mNVar+2] = (double) IsValid(i);
    957   if(mOk_EXP) {for(int j=0;j<mNVar;j++) buff[mNVar+3+j] = EAbsc(j,i);}
    958   s.PutR8s(buff, blen);
     1104for(int i=0;i<dobj->mNData;i++) {
     1105  {for(int j=0;j<dobj->mNVar;j++) buff[j] = dobj->Absc(j,i);}
     1106  buff[dobj->mNVar] = dobj->Val(i);
     1107  buff[dobj->mNVar+1] = dobj->EVal(i);
     1108  buff[dobj->mNVar+2] = (double) dobj->IsValid(i);
     1109  if(dobj->mOk_EXP) {for(int j=0;j<dobj->mNVar;j++) buff[dobj->mNVar+3+j] = dobj->EAbsc(j,i);}
     1110  os.Put(buff, blen);
    9591111}
    9601112delete [] buff;
     
    9621114return;
    9631115}
    964 
    965 //////////////////////////////////////////////////////////////////////
    966 //++
    967 void GeneralFitData::ReadSelf(PInPersist& s)
    968 //
    969 //      Lecture ppersist
    970 //--
    971 {
    972 char strg[256];
    973 
    974 Delete();
    975 
    976 // Lecture entete
    977 s.GetLine(strg, 255);
    978 
    979 // Ecriture des valeurs de definitions
    980 int_4 nvar,ndatalloc,ndata,ndatagood;
    981 s.GetI4(nvar);
    982 s.GetI4(ndatalloc);
    983 s.GetI4(ndata);
    984 s.GetI4(ndatagood);
    985 s.GetU2(mOk_EXP);
    986 if(nvar<=0 || ndatalloc<=0 || ndata<=0 || ndatagood<0 || ndatalloc<ndata) return;
    987 
    988 // Allocation de la place (attention Alloc efface mNData,mNDataGood);
    989 Alloc(nvar,ndatalloc,-1);
    990 mNData = ndata;
    991 mNDataGood = ndatagood;
    992 
    993 // Lecture des datas
    994 s.GetLine(strg, 255);
    995 int blen = mNVar + 3;
    996 if(mOk_EXP) blen += mNVar;
    997 double *buff = new double[blen];
    998 for(int i=0;i<mNData;i++) {
    999   s.GetR8s(buff, blen);
    1000   int ip = i*mNVar;
    1001   {for(int j=0;j<mNVar;j++)  mXP[ip+j] = buff[j];}
    1002   mF[i] = buff[mNVar];
    1003   mErr[i] = buff[mNVar+1];
    1004   mOK[i] = (uint_2)(buff[mNVar+2]+0.01);
    1005   if(mOk_EXP) {for(int j=0;j<mNVar;j++) mErrXP[ip+j] = buff[mNVar+3+j];}
    1006 }
    1007 delete [] buff;
    1008 
    1009 return;
    1010 }
    1011 
    1012 //////////////////////////////////////////////////////////////////////
    1013 //++
    1014 // int inline int GetSpaceFree() const
    1015 //      Retourne la place restante dans la structure (nombre de
    1016 //      donnees que l'on peut encore stoquer).
    1017 //--
    1018 //++
    1019 // inline int  NVar()       const
    1020 //      Retourne le nombre de variables Xi
    1021 //--
    1022 //++
    1023 // inline int  NData()
    1024 //      Retourne le nombre de donnees
    1025 //--
    1026 //++
    1027 // inline int  NDataGood()  const
    1028 //      Retourne le nombre de bonnes donnees (utilisees pour le fit)
    1029 //--
    1030 //++
    1031 // inline int  NDataAlloc() const
    1032 //      Retourne la place maximale allouee pour les donnees
    1033 //--
    1034 //++
    1035 // inline unsigned short int IsValid(int i) const
    1036 //      Retourne 1 si point valide, sinon 0
    1037 //--
    1038 //++
    1039 // inline bool HasXErrors()
    1040 //      Retourne ``true'' si il y a des erreurs sur les variables
    1041 //      d'abscisse, ``false'' sinon.
    1042 //--
    1043 //++
    1044 // inline double X1(int i) const
    1045 //      Retourne l'abscisse pour 1 dimension (y=f(x)) donnee I
    1046 //--
    1047 //++
    1048 // inline double X(int i) const
    1049 //      Retourne la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I
    1050 //--
    1051 //++
    1052 // inline double Y(int i) const
    1053 //      Retourne la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I
    1054 //--
    1055 //++
    1056 // inline double Z(int i) const
    1057 //      Retourne la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I
    1058 //--
    1059 //++
    1060 // inline double Absc(int j,int i) const
    1061 //      Retourne la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I
    1062 //--
    1063 //++
    1064 // inline double Val(int i) const
    1065 //      Retourne la valeur de la Ieme donnee
    1066 //--
    1067 //++
    1068 // inline double EX1(int i) const
    1069 //      Retourne l'erreur (dx) sur l'abscisse pour 1 dimension (y=f(x)) donnee I
    1070 //--
    1071 //++
    1072 // inline double EX(int i) const
    1073 //      Retourne l'erreur (dx) sur la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I
    1074 //--
    1075 //++
    1076 // inline double EY(int i) const
    1077 //      Retourne l'erreur (dy) sur la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I
    1078 //--
    1079 //++
    1080 // inline double EZ(int i) const
    1081 //      Retourne l'erreur (dz) sur la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I
    1082 //--
    1083 //++
    1084 // inline double EAbsc(int j,int i) const
    1085 //      Retourne l'erreur (dxj) sur la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I
    1086 //--
    1087 //++
    1088 // inline double EVal(int i) const {return mErr[i];}
    1089 //      Retourne l'erreur de la Ieme donnee
    1090 //--
Note: See TracChangeset for help on using the changeset viewer.