Changeset 307 in Sophya for trunk/SophyaLib/NTools/generaldata.cc
- Timestamp:
- May 19, 1999, 5:58:06 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/NTools/generaldata.cc
r244 r307 3 3 #include <stdlib.h> 4 4 #include <iostream.h> 5 #include <values.h> 5 6 #include <math.h> 6 7 #include <string.h> … … 11 12 #endif 12 13 13 #include "perrors.h"14 14 #include "nbtri.h" 15 15 #include "generalfit.h" 16 16 #include "generaldata.h" 17 #include "pexceptions.h" 18 #include "objfio.h" 19 20 using namespace PlanckDPC; 17 21 18 22 //================================================================ … … 52 56 , BuffVar(NULL), BuffVarR4(NULL) 53 57 { 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) 58 try { 59 Alloc(nVar,ndatalloc,errx); 60 } catch(PException e) { 61 cout << "Exception : " << typeid(e).name() << " " << e.Msg() << endl; 62 throw; 63 } 64 } 65 66 //++ 67 GeneralFitData::GeneralFitData(const GeneralFitData& data, bool clean) 65 68 // 66 69 // Constructeur par copie. Si ``clean'' est ``true'' … … 74 77 , BuffVar(NULL), BuffVarR4(NULL) 75 78 { 76 TRY{77 78 } CATCHALL{79 cout<<"GeneralFitData::GeneralFitData Impossible d'allouer l'espace"<<endl;80 THROW_SAME;81 } ENDTRY 79 try { 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 } 82 85 83 86 // Remplissage … … 113 116 114 117 //++ 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_CONSTRUCTOR126 }127 128 //++129 118 GeneralFitData::~GeneralFitData() 130 119 // … … 153 142 mNDataAlloc = ndatalloc; 154 143 155 TRY{144 try { 156 145 mXP = new r_8[nVar*ndatalloc]; 157 146 if(mOk_EXP) mErrXP = new r_8[nVar*ndatalloc]; … … 161 150 BuffVar = new r_8[2*nVar+3]; 162 151 BuffVarR4 = (r_4 *) BuffVar; 163 } CATCHALL{164 THROW_SAME;165 } ENDTRY152 } catch(PException e) { 153 throw(AllocationError("GeneralFitData::Alloc allocation error\n")); 154 } 166 155 } 167 156 … … 824 813 ////////////////////////////////////////////////////////////////////// 825 814 //++ 826 GeneralFitData *GeneralFitData::FitResidus(GeneralFit& gfit)815 GeneralFitData GeneralFitData::FitResidus(GeneralFit& gfit) 827 816 // 828 817 // Retourne une classe contenant les residus du fit ``gfit''. 829 818 //-- 830 819 { 831 if(gfit.GetNVar()!=mNVar) return NULL; 820 if(gfit.GetNVar()!=mNVar) 821 throw(SzMismatchError("GeneralFitData::FitResidus: size mismatch\n")); 832 822 return gfit.DataResidus(true); 833 823 } 834 824 835 825 //++ 836 GeneralFitData *GeneralFitData::FitFunction(GeneralFit& gfit)826 GeneralFitData GeneralFitData::FitFunction(GeneralFit& gfit) 837 827 // 838 828 // Retourne une classe contenant la function du fit ``gfit''. 839 829 //-- 840 830 { 841 if(gfit.GetNVar()!=mNVar) return NULL; 831 if(gfit.GetNVar()!=mNVar) 832 throw(SzMismatchError("GeneralFitData::FitFunction: size mismatch\n")); 842 833 return gfit.DataFunction(true); 843 834 } … … 922 913 ////////////////////////////////////////////////////////////////////// 923 914 //++ 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 999 FIO_GeneralFitData::FIO_GeneralFitData() 1000 { 1001 dobj=new GeneralFitData; 1002 ownobj=true; 1003 } 1004 1005 FIO_GeneralFitData::FIO_GeneralFitData(string const & filename) 1006 { 1007 dobj=new GeneralFitData; 1008 ownobj=true; 1009 Read(filename); 1010 } 1011 1012 FIO_GeneralFitData::FIO_GeneralFitData(const GeneralFitData & obj) 1013 { 1014 dobj = new GeneralFitData(obj); 1015 ownobj=true; 1016 } 1017 1018 FIO_GeneralFitData::FIO_GeneralFitData(GeneralFitData * obj) 1019 { 1020 dobj = obj; 1021 ownobj=false; 1022 } 1023 1024 FIO_GeneralFitData::~FIO_GeneralFitData() 1025 { 1026 if (ownobj && dobj) delete dobj; 1027 } 1028 1029 AnyDataObj* FIO_GeneralFitData::DataObj() 1030 { 1031 return(dobj); 1032 } 1033 1034 void FIO_GeneralFitData::ReadSelf(PInPersist& is) 1035 { 1036 char strg[256]; 1037 1038 if(dobj==NULL) dobj=new GeneralFitData; 1039 else dobj->Delete(); 1040 1041 // Lecture entete 1042 is.GetLine(strg, 255); 1043 1044 // Ecriture des valeurs de definitions 1045 int_4 nvar,ndatalloc,ndata,ndatagood; 1046 is.Get(nvar); 1047 is.Get(ndatalloc); 1048 is.Get(ndata); 1049 is.Get(ndatagood); 1050 is.Get(dobj->mOk_EXP); 1051 if(nvar<=0 || ndatalloc<=0 || ndata<=0 || ndatagood<0 || ndatalloc<ndata) return; 1052 1053 // Allocation de la place (attention Alloc efface mNData,mNDataGood); 1054 dobj->Alloc(nvar,ndatalloc,-1); 1055 dobj->mNData = ndata; 1056 dobj->mNDataGood = ndatagood; 1057 1058 // Lecture des datas 1059 is.GetLine(strg, 255); 1060 int blen = dobj->mNVar + 3; 1061 if(dobj->mOk_EXP) blen += dobj->mNVar; 1062 double *buff = new double[blen]; 1063 for(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 } 1073 delete [] buff; 1074 1075 return; 1076 } 1077 1078 void FIO_GeneralFitData::WriteSelf(POutPersist& os) const 1079 { 1080 if (dobj == NULL) return; 929 1081 char strg[256]; 930 1082 931 1083 // Ecriture entete pour identifier facilement 932 1084 sprintf(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); 1086 os.PutLine(strg); 935 1087 936 1088 // 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;1089 os.Put(dobj->mNVar); 1090 os.Put(dobj->mNDataAlloc); 1091 os.Put(dobj->mNData); 1092 os.Put(dobj->mNDataGood); 1093 os.Put(dobj->mOk_EXP); 1094 if(dobj->mNVar<=0 || dobj->mNDataAlloc<=0 || dobj->mNData<=0 || dobj->mNDataGood<0) return; 943 1095 944 1096 // Ecriture des datas (on n'ecrit que mNData / mNDataAlloc) 945 1097 sprintf(strg 946 1098 ,"GeneralFitData: Abscisses, Ordonnee, Erreur Ordonnee, Flag, Erreur Abscisses"); 947 s.PutLine(strg);948 949 int blen = mNVar + 3;950 if( mOk_EXP) blen +=mNVar;1099 os.PutLine(strg); 1100 1101 int blen = dobj->mNVar + 3; 1102 if(dobj->mOk_EXP) blen += dobj->mNVar; 951 1103 double *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);1104 for(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); 959 1111 } 960 1112 delete [] buff; … … 962 1114 return; 963 1115 } 964 965 //////////////////////////////////////////////////////////////////////966 //++967 void GeneralFitData::ReadSelf(PInPersist& s)968 //969 // Lecture ppersist970 //--971 {972 char strg[256];973 974 Delete();975 976 // Lecture entete977 s.GetLine(strg, 255);978 979 // Ecriture des valeurs de definitions980 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 datas994 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() const1015 // Retourne la place restante dans la structure (nombre de1016 // donnees que l'on peut encore stoquer).1017 //--1018 //++1019 // inline int NVar() const1020 // Retourne le nombre de variables Xi1021 //--1022 //++1023 // inline int NData()1024 // Retourne le nombre de donnees1025 //--1026 //++1027 // inline int NDataGood() const1028 // Retourne le nombre de bonnes donnees (utilisees pour le fit)1029 //--1030 //++1031 // inline int NDataAlloc() const1032 // Retourne la place maximale allouee pour les donnees1033 //--1034 //++1035 // inline unsigned short int IsValid(int i) const1036 // Retourne 1 si point valide, sinon 01037 //--1038 //++1039 // inline bool HasXErrors()1040 // Retourne ``true'' si il y a des erreurs sur les variables1041 // d'abscisse, ``false'' sinon.1042 //--1043 //++1044 // inline double X1(int i) const1045 // Retourne l'abscisse pour 1 dimension (y=f(x)) donnee I1046 //--1047 //++1048 // inline double X(int i) const1049 // Retourne la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I1050 //--1051 //++1052 // inline double Y(int i) const1053 // Retourne la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I1054 //--1055 //++1056 // inline double Z(int i) const1057 // Retourne la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I1058 //--1059 //++1060 // inline double Absc(int j,int i) const1061 // Retourne la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I1062 //--1063 //++1064 // inline double Val(int i) const1065 // Retourne la valeur de la Ieme donnee1066 //--1067 //++1068 // inline double EX1(int i) const1069 // Retourne l'erreur (dx) sur l'abscisse pour 1 dimension (y=f(x)) donnee I1070 //--1071 //++1072 // inline double EX(int i) const1073 // Retourne l'erreur (dx) sur la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I1074 //--1075 //++1076 // inline double EY(int i) const1077 // Retourne l'erreur (dy) sur la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I1078 //--1079 //++1080 // inline double EZ(int i) const1081 // Retourne l'erreur (dz) sur la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I1082 //--1083 //++1084 // inline double EAbsc(int j,int i) const1085 // Retourne l'erreur (dxj) sur la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I1086 //--1087 //++1088 // inline double EVal(int i) const {return mErr[i];}1089 // Retourne l'erreur de la Ieme donnee1090 //--
Note:
See TracChangeset
for help on using the changeset viewer.