Changeset 490 in Sophya for trunk/SophyaLib/NTools/generaldata.cc
- Timestamp:
- Oct 21, 1999, 5:25:53 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/NTools/generaldata.cc
r307 r490 8 8 #include <string> 9 9 10 #if defined(__KCC__) 11 using std::string ; 12 #endif 13 10 #include "strutil.h" 14 11 #include "nbtri.h" 15 12 #include "generalfit.h" … … 134 131 //-- 135 132 { 136 DBASSERT( nVar>0 && ndatalloc>0 );133 ASSERT( nVar>0 && ndatalloc>0 ); 137 134 138 135 Delete(); … … 176 173 //-- 177 174 { 178 DBASSERT(ptr >= 0 && ptr < mNDataAlloc);175 ASSERT(ptr >= 0 && ptr < mNDataAlloc); 179 176 mNData = ptr; 180 177 mNDataGood = 0; … … 190 187 //-- 191 188 { 192 DBASSERT(i >= 0 && i < mNData);189 ASSERT(i >= 0 && i < mNData); 193 190 194 191 if( ! mOK[i] ) return; … … 203 200 //-- 204 201 { 205 DBASSERT(i1 >= 0 && i1 < mNData);206 DBASSERT(i2 >= 0 && i2 < mNData);207 DBASSERT(i1 <= i2 );202 ASSERT(i1 >= 0 && i1 < mNData); 203 ASSERT(i2 >= 0 && i2 < mNData); 204 ASSERT(i1 <= i2 ); 208 205 209 206 for(int i=i1;i<=i2;i++) KillData(i); … … 217 214 //-- 218 215 { 219 DBASSERT(i >= 0 && i < mNData);216 ASSERT(i >= 0 && i < mNData); 220 217 221 218 if( mOK[i] ) return; … … 234 231 //-- 235 232 { 236 DBASSERT(i1 >= 0 && i1 < mNData);237 DBASSERT(i2 >= 0 && i2 < mNData);238 DBASSERT(i1 <= i2 );233 ASSERT(i1 >= 0 && i1 < mNData); 234 ASSERT(i2 >= 0 && i2 < mNData); 235 ASSERT(i1 <= i2 ); 239 236 240 237 for(int i=i1;i<=i2;i++) ValidData(i); … … 281 278 //-- 282 279 { 283 DBASSERT(i>=0 && i<mNData);280 ASSERT(i>=0 && i<mNData); 284 281 bool ok = true; 285 282 … … 335 332 //-- 336 333 { 337 DBASSERT(mNData < mNDataAlloc);334 ASSERT(mNData < mNDataAlloc); 338 335 bool ok = true; 339 336 … … 377 374 //-- 378 375 { 379 DBASSERT(nData>0 && mNData+nData<=mNDataAlloc);376 ASSERT(nData>0 && mNData+nData<=mNDataAlloc); 380 377 381 378 for(int i=0;i<nData;i++) { … … 394 391 //-- 395 392 { 396 DBASSERT(nData>0 && mNData+nData<=mNDataAlloc);393 ASSERT(nData>0 && mNData+nData<=mNDataAlloc); 397 394 398 395 for(int i=0;i<nData;i++) { … … 411 408 //-- 412 409 { 413 DBASSERT(nData>0 && mNData+nData<=mNDataAlloc);410 ASSERT(nData>0 && mNData+nData<=mNDataAlloc); 414 411 415 412 for(int i=0;i<nData;i++) { … … 429 426 //-- 430 427 { 431 DBASSERT(nData>0 && mNData+nData<=mNDataAlloc);428 ASSERT(nData>0 && mNData+nData<=mNDataAlloc); 432 429 433 430 for(int i=0;i<nData;i++) { … … 454 451 //-- 455 452 { 456 DBASSERT(nData>0 && mNData+nData<=mNDataAlloc);453 ASSERT(nData>0 && mNData+nData<=mNDataAlloc); 457 454 if(mOk_EXP && !errxp) {for(int j=0;j<mNVar;j++) BuffVar[mNVar+j] = Def_ErrX;} 458 455 … … 473 470 //-- 474 471 { 475 DBASSERT(nData>0 && mNData+nData<=mNDataAlloc);472 ASSERT(nData>0 && mNData+nData<=mNDataAlloc); 476 473 477 474 if(mOk_EXP && !errxp) {for(int j=0;j<mNVar;j++) BuffVar[mNVar+j] = Def_ErrX;} … … 506 503 //-- 507 504 { 508 DBASSERT(i>=0 && i<mNData);505 ASSERT(i>=0 && i<mNData); 509 506 510 507 cout<<" "<<i<<" F( "; … … 540 537 //-- 541 538 { 542 DBASSERT(mNData>0);539 ASSERT(mNData>0); 543 540 544 541 PrintData(0,mNData-1); 545 542 } 546 543 547 ////////////////////////////////////////////////////////////////////// 548 //++ 549 int GeneralFitData::GetMinMax(int var,int& imin,int& imax) 544 //++ 545 void GeneralFitData::Show(ostream& os) const 546 // 547 // Impression de l'etat de la structure de donnees avec bornes sur "s" 548 //-- 549 { 550 double min,max; 551 os<<"GeneralFitData:: NVar,ErrX="<<mNVar<<","<<mOk_EXP 552 <<" Data: "<<mNData<<" Good,Alloc="<<mNDataGood<<","<<mNDataAlloc<<endl; 553 for(int k=0;k<2*NVar()+3;k++) { 554 GetMinMax(k,min,max); 555 os<<" - "<<k<<" "<<ColumnName(k)<<" , "<<min<<","<<max<<endl; 556 } 557 return; 558 } 559 560 ////////////////////////////////////////////////////////////////////// 561 //++ 562 int GeneralFitData::GetMnMx(int var,int& imin,int& imax) const 550 563 // 551 564 // Retourne les numeros des points de valeurs minimum et maximum … … 582 595 583 596 //++ 584 int GeneralFitData::GetM inMax(int var,double& min,double& max)597 int GeneralFitData::GetMnMx(int var,double& min,double& max) const 585 598 // 586 599 // Retourne le minimum et le maximum de la variable ``var'' 587 // (cf commentaires GetM inMax).600 // (cf commentaires GetMnMx). 588 601 //-- 589 602 { 590 603 min = 1.; max = -1.; 591 604 int imin,imax; 592 int ntest = GetM inMax(var,imin,imax);605 int ntest = GetMnMx(var,imin,imax); 593 606 if(ntest<=0) return ntest; 594 607 int ix = var/10; … … 615 628 // 616 629 // Retourne la moyenne et le sigma de la variable ``var'' 617 // (cf commentaires GetM inMax).630 // (cf commentaires GetMnMx). 618 631 //| - Return : nombre de donnees utilisees, -1 si pb, -2 si sigma<0. 619 632 //| - Seuls les points valides de valeur entre min,max sont utilises. … … 655 668 // 656 669 // Retourne le mode de la variable ``var'' 657 // (cf commentaires GetM inMax).670 // (cf commentaires GetMnMx). 658 671 //| - Return : nombre de donnees utilisees, -1 si pb. 659 672 //| - Seuls les points valides de valeur entre min,max sont utilises. … … 876 889 ////////////////////////////////////////////////////////////////////// 877 890 //++ 891 // int inline int GetSpaceFree() const 892 // Retourne la place restante dans la structure (nombre de 893 // donnees que l'on peut encore stoquer). 894 //-- 895 //++ 896 // inline int NVar() const 897 // Retourne le nombre de variables Xi 898 //-- 899 //++ 900 // inline int NData() 901 // Retourne le nombre de donnees 902 //-- 903 //++ 904 // inline int NDataGood() const 905 // Retourne le nombre de bonnes donnees (utilisees pour le fit) 906 //-- 907 //++ 908 // inline int NDataAlloc() const 909 // Retourne la place maximale allouee pour les donnees 910 //-- 911 //++ 912 // inline unsigned short int IsValid(int i) const 913 // Retourne 1 si point valide, sinon 0 914 //-- 915 //++ 916 // inline bool HasXErrors() 917 // Retourne ``true'' si il y a des erreurs sur les variables 918 // d'abscisse, ``false'' sinon. 919 //-- 920 //++ 921 // inline double X1(int i) const 922 // Retourne l'abscisse pour 1 dimension (y=f(x)) donnee I 923 //-- 924 //++ 925 // inline double X(int i) const 926 // Retourne la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I 927 //-- 928 //++ 929 // inline double Y(int i) const 930 // Retourne la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I 931 //-- 932 //++ 933 // inline double Z(int i) const 934 // Retourne la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I 935 //-- 936 //++ 937 // inline double Absc(int j,int i) const 938 // Retourne la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I 939 //-- 940 //++ 941 // inline double Val(int i) const 942 // Retourne la valeur de la Ieme donnee 943 //-- 944 //++ 945 // inline double EX1(int i) const 946 // Retourne l'erreur (dx) sur l'abscisse pour 1 dimension (y=f(x)) donnee I 947 //-- 948 //++ 949 // inline double EX(int i) const 950 // Retourne l'erreur (dx) sur la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I 951 //-- 952 //++ 953 // inline double EY(int i) const 954 // Retourne l'erreur (dy) sur la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I 955 //-- 956 //++ 957 // inline double EZ(int i) const 958 // Retourne l'erreur (dz) sur la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I 959 //-- 960 //++ 961 // inline double EAbsc(int j,int i) const 962 // Retourne l'erreur (dxj) sur la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I 963 //-- 964 //++ 965 // inline double EVal(int i) const {return mErr[i];} 966 // Retourne l'erreur de la Ieme donnee 967 //-- 968 969 970 ////////////////////////////////////////////////////////////////////// 971 // ------- Implementation de l interface NTuple --------- 972 973 uint_4 GeneralFitData::NbLines() const 974 { 975 return(NData()); 976 } 977 978 //++ 979 uint_4 GeneralFitData::NbColumns() const 980 // 981 // Retourne le nombre de colonnes du ntuple equivalent: 982 //| Exemple: on a une fonction sur un espace a 4 dimensions: 983 //| "x0,x1,x2,x3 , ex0,ex1,ex2,ex3 , y, ey , ok" 984 //| 0 1 2 3 4 5 6 7 8 9 10 985 //| | | | | | | | 986 //| 0 nv-1 nv 2*nv-1 2*nv 2*nv+1 2*nv+2 987 //| soit 2*nvar+3 variables/colonnes. 988 //-- 989 { 990 return(2*NVar()+3); 991 } 992 993 r_8 * GeneralFitData::GetLineD(int n) const 994 { 995 return(GetVec(n,NULL)); 996 } 997 998 r_8 GeneralFitData::GetCell(int n, int k) const 999 { 1000 if(k<0 || k>=2*NVar()+3) return 0.; 1001 r_8 * val = GetVec(n,NULL); 1002 return val[k]; 1003 } 1004 1005 r_8 GeneralFitData::GetCell(int n, string const & nom) const 1006 { 1007 int k = ColumnIndex(nom); 1008 return(GetCell(n,k)); 1009 } 1010 1011 //++ 1012 void GeneralFitData::GetMinMax(int k, double& min, double& max) const 1013 // 1014 // Retourne le minimum et le maximum de la variable `k'. 1015 //-- 1016 { 1017 int var; 1018 if(k<0 || k>=2*NVar()+3) return; 1019 else if(k<NVar()) var = 10*k+2; // Variable Xi 1020 else if(k<2*NVar()) var = 10*(k-NVar())+3; // Variable EXi 1021 else if(k==2*NVar()) var = 0; // Variable Y 1022 else if(k==2*NVar()+1) var = 1; // Variable EY 1023 else {min=0.; max=1.; return;} // Variable Ok 1024 GetMnMx(var,min,max); 1025 return; 1026 } 1027 1028 void GeneralFitData::GetMinMax(string const & nom, double& min, double& max) const 1029 { 1030 int k = ColumnIndex(nom); 1031 GetMinMax(k,min,max); 1032 } 1033 1034 int GeneralFitData::ColumnIndex(string const & nom) const 1035 { 1036 char str[64]; int k = -1; 1037 strcpy(str,nom.c_str()); strip(str,'L',' '); 1038 if(str[0]=='y') return 2*NVar(); 1039 if(str[0]=='o') return 2*NVar()+2; 1040 if(str[0]=='x') {sscanf(str,"x%d",&k); return k;} 1041 if(str[0]=='e') 1042 if(str[1]=='y') return 2*NVar()+1; 1043 else if(str[1]=='x') {sscanf(str,"ex%d",&k); return NVar()+k;} 1044 return -1; 1045 } 1046 1047 string GeneralFitData::ColumnName(int k) const 1048 { 1049 if(k==2*NVar()) return string("y"); 1050 else if(k==2*NVar()+1) return string("ey"); 1051 else if(k==2*NVar()+2) return string("ok"); 1052 else if(k<0 || k>=2*NVar()+3) return string(""); 1053 1054 char str[64] = ""; 1055 if(k<NVar()) sprintf(str,"x%d",k); 1056 else if(k<2*NVar()) sprintf(str,"ex%d",k-NVar()); 1057 return string(str); 1058 } 1059 1060 //++ 878 1061 string GeneralFitData::VarList_C(const char* nomx) const 879 1062 // … … 911 1094 } 912 1095 913 //////////////////////////////////////////////////////////////////////914 //++915 // int inline int GetSpaceFree() const916 // Retourne la place restante dans la structure (nombre de917 // donnees que l'on peut encore stoquer).918 //--919 //++920 // inline int NVar() const921 // Retourne le nombre de variables Xi922 //--923 //++924 // inline int NData()925 // Retourne le nombre de donnees926 //--927 //++928 // inline int NDataGood() const929 // Retourne le nombre de bonnes donnees (utilisees pour le fit)930 //--931 //++932 // inline int NDataAlloc() const933 // Retourne la place maximale allouee pour les donnees934 //--935 //++936 // inline unsigned short int IsValid(int i) const937 // Retourne 1 si point valide, sinon 0938 //--939 //++940 // inline bool HasXErrors()941 // Retourne ``true'' si il y a des erreurs sur les variables942 // d'abscisse, ``false'' sinon.943 //--944 //++945 // inline double X1(int i) const946 // Retourne l'abscisse pour 1 dimension (y=f(x)) donnee I947 //--948 //++949 // inline double X(int i) const950 // Retourne la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I951 //--952 //++953 // inline double Y(int i) const954 // Retourne la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I955 //--956 //++957 // inline double Z(int i) const958 // Retourne la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I959 //--960 //++961 // inline double Absc(int j,int i) const962 // Retourne la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I963 //--964 //++965 // inline double Val(int i) const966 // Retourne la valeur de la Ieme donnee967 //--968 //++969 // inline double EX1(int i) const970 // Retourne l'erreur (dx) sur l'abscisse pour 1 dimension (y=f(x)) donnee I971 //--972 //++973 // inline double EX(int i) const974 // Retourne l'erreur (dx) sur la 1er abscisse (X) pour (v=f(x,y,z,...)) donnee I975 //--976 //++977 // inline double EY(int i) const978 // Retourne l'erreur (dy) sur la 2sd abscisse (Y) pour (v=f(x,y,z,...)) donnee I979 //--980 //++981 // inline double EZ(int i) const982 // Retourne l'erreur (dz) sur la 3ieme abscisse (Z) pour (v=f(x,y,z,...)) donnee I983 //--984 //++985 // inline double EAbsc(int j,int i) const986 // Retourne l'erreur (dxj) sur la Jieme abscisse (Xj) pour (v=f(x0,x1,x2,...)) donnee I987 //--988 //++989 // inline double EVal(int i) const {return mErr[i];}990 // Retourne l'erreur de la Ieme donnee991 //--992 993 1096 /////////////////////////////////////////////////////////// 994 1097 // -------------------------------------------------------- … … 997 1100 /////////////////////////////////////////////////////////// 998 1101 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) 1102 1103 void ObjFileIO<GeneralFitData>::ReadSelf(PInPersist& is) 1035 1104 { 1036 1105 char strg[256]; … … 1076 1145 } 1077 1146 1078 void FIO_GeneralFitData::WriteSelf(POutPersist& os) const1147 void ObjFileIO<GeneralFitData>::WriteSelf(POutPersist& os) const 1079 1148 { 1080 1149 if (dobj == NULL) return; … … 1114 1183 return; 1115 1184 } 1185 1186 1187 #ifdef __CXX_PRAGMA_TEMPLATES__ 1188 #pragma define_template ObjFileIO<GeneralFitData> 1189 #endif 1190 1191 #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) 1192 template class ObjFileIO<GeneralFitData>; 1193 #endif
Note:
See TracChangeset
for help on using the changeset viewer.