| [2615] | 1 | #include "sopnamsp.h" | 
|---|
| [295] | 2 | #include "machdefs.h" | 
|---|
|  | 3 | #include <stdlib.h> | 
|---|
|  | 4 | #include <typeinfo> | 
|---|
| [2322] | 5 | #include <iostream> | 
|---|
| [295] | 6 | #include <string> | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #include "nommatvecadapter.h" | 
|---|
| [1905] | 9 | #include "piyfxdrw.h" | 
|---|
| [295] | 10 | #include "pipodrw.h" | 
|---|
|  | 11 |  | 
|---|
|  | 12 | //--------------------------------------------------------------- | 
|---|
|  | 13 | // Class Adaptateur d'objet (Pour NamedObjMgr) d'objet Vector | 
|---|
|  | 14 | //--------------------------------------------------------------- | 
|---|
|  | 15 |  | 
|---|
|  | 16 | /* --Methode-- */ | 
|---|
|  | 17 | NOMAdapter_Vector::NOMAdapter_Vector(Vector* o) | 
|---|
|  | 18 | : NObjMgrAdapter(o) | 
|---|
|  | 19 | { | 
|---|
|  | 20 | mVec = o; | 
|---|
|  | 21 | } | 
|---|
|  | 22 |  | 
|---|
|  | 23 | /* --Methode-- */ | 
|---|
|  | 24 | NOMAdapter_Vector::~NOMAdapter_Vector() | 
|---|
|  | 25 | { | 
|---|
|  | 26 | } | 
|---|
|  | 27 |  | 
|---|
|  | 28 | /* --Methode-- */ | 
|---|
|  | 29 | NObjMgrAdapter* NOMAdapter_Vector::Clone(AnyDataObj* o) | 
|---|
|  | 30 | { | 
|---|
|  | 31 | Vector* v = dynamic_cast<Vector *>(o); | 
|---|
|  | 32 | if (v) return ( new NOMAdapter_Vector(v) ); | 
|---|
|  | 33 | return ( new NObjMgrAdapter(o) ); | 
|---|
|  | 34 | } | 
|---|
|  | 35 |  | 
|---|
| [463] | 36 | /* --Methode-- */ | 
|---|
| [1165] | 37 | string NOMAdapter_Vector::GetDataObjType() | 
|---|
| [463] | 38 | { | 
|---|
| [1165] | 39 | return("Vector "); | 
|---|
|  | 40 | } | 
|---|
|  | 41 |  | 
|---|
|  | 42 | /* --Methode-- */ | 
|---|
| [1315] | 43 | AnyDataObj* NOMAdapter_Vector::CloneDataObj(bool /*share*/) | 
|---|
| [1165] | 44 | { | 
|---|
| [463] | 45 | return ( new Vector(*mVec) ); | 
|---|
|  | 46 | } | 
|---|
| [295] | 47 |  | 
|---|
| [463] | 48 |  | 
|---|
| [295] | 49 | /* --Methode-- */ | 
|---|
|  | 50 | void NOMAdapter_Vector::SavePPF(POutPersist& pos, string const & nom) | 
|---|
|  | 51 | { | 
|---|
|  | 52 | #ifdef SANS_EVOLPLANCK | 
|---|
|  | 53 | // PEIDA-EROS L'histo est lui-meme PPersist | 
|---|
|  | 54 | string tag = nom;  // A cause de const | 
|---|
|  | 55 | mVec->Write(pos,0,tag); | 
|---|
|  | 56 | #else | 
|---|
|  | 57 | string s = typeid(*mObj).name(); | 
|---|
|  | 58 | cout << "NOMAdapter_Vector::SavePPF() - Error : Not supported for " << s << endl; | 
|---|
|  | 59 | #endif | 
|---|
|  | 60 | } | 
|---|
|  | 61 |  | 
|---|
|  | 62 | /* --Methode-- */ | 
|---|
|  | 63 | void NOMAdapter_Vector::Print(ostream& os) | 
|---|
|  | 64 | { | 
|---|
|  | 65 | os << (*mVec); | 
|---|
|  | 66 | } | 
|---|
|  | 67 |  | 
|---|
|  | 68 | /* --Methode-- */ | 
|---|
|  | 69 | PIDrawer* NOMAdapter_Vector::GetDrawer(string & dopt) | 
|---|
|  | 70 | { | 
|---|
| [1971] | 71 | dopt = "thinline " + dopt; | 
|---|
| [295] | 72 | return( new PIYfXDrawer( new POVectorAdapter(mVec, false), NULL, true) ); | 
|---|
|  | 73 | } | 
|---|
|  | 74 |  | 
|---|
|  | 75 | /* --Methode-- */ | 
|---|
| [344] | 76 | NTupleInterface* NOMAdapter_Vector::GetNTupleInterface(bool& adel) | 
|---|
| [295] | 77 | { | 
|---|
| [344] | 78 | adel = true; | 
|---|
| [295] | 79 | return( new NTupInt_Vector(mVec) ); | 
|---|
|  | 80 | } | 
|---|
|  | 81 |  | 
|---|
|  | 82 |  | 
|---|
| [1207] | 83 | /* --Methode-- */ | 
|---|
|  | 84 | GeneralFitData* NOMAdapter_Vector::GetGeneralFitData(bool& adel | 
|---|
|  | 85 | ,GeneralFitData::FitErrType errtype,double errscale,double errmin | 
|---|
|  | 86 | ,int i1,int i2,int j1,int j2) | 
|---|
|  | 87 | { | 
|---|
|  | 88 | adel = false; | 
|---|
|  | 89 | if(!mVec) return(NULL); | 
|---|
|  | 90 |  | 
|---|
|  | 91 | int n = mVec->NElts(); | 
|---|
|  | 92 | if(n<=0) return(NULL); | 
|---|
|  | 93 |  | 
|---|
|  | 94 | i1 = (i1<0||i1>=n)? 0: i1; | 
|---|
|  | 95 | i2 = (i2<0||i2>=n||i2<i1)? n-1: i2; | 
|---|
|  | 96 |  | 
|---|
|  | 97 | GeneralFitData* mGData = new GeneralFitData(1,i2-i1+1,0); | 
|---|
|  | 98 | adel = true; | 
|---|
|  | 99 |  | 
|---|
|  | 100 | for(int i=i1;i<=i2;i++) { | 
|---|
|  | 101 | double x = (double) i; | 
|---|
|  | 102 | double f = (*mVec)(i); | 
|---|
|  | 103 | double e = 1.; | 
|---|
|  | 104 | e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin); | 
|---|
|  | 105 | mGData->AddData1(x,f,e); | 
|---|
|  | 106 | } | 
|---|
|  | 107 |  | 
|---|
|  | 108 | return mGData; | 
|---|
|  | 109 | } | 
|---|
|  | 110 |  | 
|---|
|  | 111 | AnyDataObj* NOMAdapter_Vector::FitResidusObj(GeneralFit& mfit) | 
|---|
|  | 112 | { | 
|---|
|  | 113 | Vector* v = NULL; | 
|---|
|  | 114 | v = mVec->FitResidus(mfit); | 
|---|
|  | 115 | return v; | 
|---|
|  | 116 | } | 
|---|
|  | 117 |  | 
|---|
|  | 118 | AnyDataObj* NOMAdapter_Vector::FitFunctionObj(GeneralFit& mfit) | 
|---|
|  | 119 | { | 
|---|
|  | 120 | Vector* v = NULL; | 
|---|
|  | 121 | v = mVec->FitFunction(mfit); | 
|---|
|  | 122 | return v; | 
|---|
|  | 123 | } | 
|---|
|  | 124 |  | 
|---|
| [295] | 125 | // ------------------------------------------------------------- | 
|---|
|  | 126 |  | 
|---|
|  | 127 | /* --Methode-- */ | 
|---|
|  | 128 | NTupInt_Vector::NTupInt_Vector(Vector* v) | 
|---|
|  | 129 | { | 
|---|
|  | 130 | mVec = v; | 
|---|
|  | 131 | } | 
|---|
|  | 132 |  | 
|---|
|  | 133 | /* --Methode-- */ | 
|---|
|  | 134 | NTupInt_Vector::~NTupInt_Vector() | 
|---|
|  | 135 | { | 
|---|
|  | 136 | } | 
|---|
|  | 137 |  | 
|---|
|  | 138 | /* --Methode-- */ | 
|---|
| [326] | 139 | uint_4 NTupInt_Vector::NbLines() const | 
|---|
| [295] | 140 | { | 
|---|
|  | 141 | return(mVec->NElts()); | 
|---|
|  | 142 | } | 
|---|
|  | 143 |  | 
|---|
|  | 144 | /* --Methode-- */ | 
|---|
| [326] | 145 | uint_4 NTupInt_Vector::NbColumns() const | 
|---|
| [295] | 146 | { | 
|---|
|  | 147 | return(2); | 
|---|
|  | 148 | } | 
|---|
|  | 149 |  | 
|---|
|  | 150 | /* --Methode-- */ | 
|---|
| [326] | 151 | r_8* NTupInt_Vector::GetLineD(int n) const | 
|---|
| [295] | 152 | { | 
|---|
|  | 153 | int i; | 
|---|
|  | 154 | if ((n < 0) || (n >= mVec->NElts() )) | 
|---|
|  | 155 | for(i=0; i<2; i++)  mRet[i] = 0.; | 
|---|
|  | 156 | else { | 
|---|
|  | 157 | mRet[0] = n;  mRet[1] = (*mVec)(n); | 
|---|
|  | 158 | } | 
|---|
|  | 159 | return(mRet); | 
|---|
|  | 160 | } | 
|---|
|  | 161 |  | 
|---|
|  | 162 | /* --Methode-- */ | 
|---|
| [326] | 163 | string NTupInt_Vector::VarList_C(const char* nx) const | 
|---|
| [295] | 164 | { | 
|---|
|  | 165 | string nomx; | 
|---|
|  | 166 | if (nx) nomx = nx; | 
|---|
|  | 167 | else nomx = "_xh_"; | 
|---|
|  | 168 | string vardec = "double i,val; \n"; | 
|---|
|  | 169 | vardec += "i = " + nomx + "[0];  val = " + nomx + "[1]; \n"; | 
|---|
|  | 170 | return(vardec); | 
|---|
|  | 171 | } | 
|---|
|  | 172 |  | 
|---|
|  | 173 |  | 
|---|
|  | 174 | //--------------------------------------------------------------- | 
|---|
|  | 175 | // Class Adaptateur d'objet (Pour NamedObjMgr) d'objet Matrix | 
|---|
|  | 176 | //--------------------------------------------------------------- | 
|---|
|  | 177 |  | 
|---|
|  | 178 |  | 
|---|
|  | 179 | /* --Methode-- */ | 
|---|
|  | 180 | NOMAdapter_Matrix::NOMAdapter_Matrix(Matrix* o) | 
|---|
|  | 181 | : NObjMgrAdapter(o) | 
|---|
|  | 182 | { | 
|---|
|  | 183 | mMtx = o; | 
|---|
|  | 184 | } | 
|---|
|  | 185 |  | 
|---|
|  | 186 | /* --Methode-- */ | 
|---|
|  | 187 | NOMAdapter_Matrix::~NOMAdapter_Matrix() | 
|---|
|  | 188 | { | 
|---|
|  | 189 | } | 
|---|
|  | 190 |  | 
|---|
|  | 191 | /* --Methode-- */ | 
|---|
|  | 192 | NObjMgrAdapter* NOMAdapter_Matrix::Clone(AnyDataObj* o) | 
|---|
|  | 193 | { | 
|---|
|  | 194 | Matrix* m = dynamic_cast<Matrix *>(o); | 
|---|
|  | 195 | if (m) return ( new NOMAdapter_Matrix(m) ); | 
|---|
|  | 196 | return ( new NObjMgrAdapter(o) ); | 
|---|
|  | 197 | } | 
|---|
|  | 198 |  | 
|---|
| [463] | 199 | /* --Methode-- */ | 
|---|
| [1165] | 200 | string NOMAdapter_Matrix::GetDataObjType() | 
|---|
| [463] | 201 | { | 
|---|
| [1165] | 202 | return("Matrix "); | 
|---|
|  | 203 | } | 
|---|
|  | 204 |  | 
|---|
|  | 205 | /* --Methode-- */ | 
|---|
| [1315] | 206 | AnyDataObj* NOMAdapter_Matrix::CloneDataObj(bool /*share*/) | 
|---|
| [1165] | 207 | { | 
|---|
| [463] | 208 | return ( new Matrix(*mMtx) ); | 
|---|
|  | 209 | } | 
|---|
| [295] | 210 |  | 
|---|
|  | 211 | /* --Methode-- */ | 
|---|
|  | 212 | void NOMAdapter_Matrix::SavePPF(POutPersist& pos, string const & nom) | 
|---|
|  | 213 | { | 
|---|
|  | 214 | #ifdef SANS_EVOLPLANCK | 
|---|
|  | 215 | // PEIDA-EROS L'histo est lui-meme PPersist | 
|---|
|  | 216 | string tag = nom;  // A cause de const | 
|---|
|  | 217 | mMtx->Write(pos,0,tag); | 
|---|
|  | 218 | #else | 
|---|
|  | 219 | string s = typeid(*mObj).name(); | 
|---|
|  | 220 | cout << "NOMAdapter_Matrix::SavePPF() - Error : Not supported for " << s << endl; | 
|---|
|  | 221 | #endif | 
|---|
|  | 222 | } | 
|---|
|  | 223 |  | 
|---|
|  | 224 | /* --Methode-- */ | 
|---|
|  | 225 | void NOMAdapter_Matrix::Print(ostream& os) | 
|---|
|  | 226 | { | 
|---|
|  | 227 | os << (*mMtx); | 
|---|
|  | 228 | } | 
|---|
|  | 229 |  | 
|---|
|  | 230 |  | 
|---|
|  | 231 | /* --Methode-- */ | 
|---|
|  | 232 | P2DArrayAdapter* NOMAdapter_Matrix::Get2DArray(string &) | 
|---|
|  | 233 | { | 
|---|
|  | 234 | return ( new POMatrixAdapter(mMtx, false) ); | 
|---|
|  | 235 | } | 
|---|
|  | 236 |  | 
|---|
|  | 237 | /* --Methode-- */ | 
|---|
| [344] | 238 | NTupleInterface* NOMAdapter_Matrix::GetNTupleInterface(bool& adel) | 
|---|
| [295] | 239 | { | 
|---|
| [344] | 240 | adel = true; | 
|---|
| [295] | 241 | return( new NTupInt_Matrix(mMtx) ); | 
|---|
|  | 242 | } | 
|---|
|  | 243 |  | 
|---|
| [1207] | 244 | /* --Methode-- */ | 
|---|
|  | 245 | GeneralFitData* NOMAdapter_Matrix::GetGeneralFitData(bool& adel | 
|---|
|  | 246 | ,GeneralFitData::FitErrType errtype,double errscale,double errmin | 
|---|
|  | 247 | ,int i1,int i2,int j1,int j2) | 
|---|
|  | 248 | { | 
|---|
|  | 249 | adel = false; | 
|---|
|  | 250 | if(!mMtx) return(NULL); | 
|---|
| [295] | 251 |  | 
|---|
| [1207] | 252 | int nx = mMtx->NRows(); | 
|---|
|  | 253 | int ny = mMtx->NCol(); | 
|---|
|  | 254 | if(nx<=0 || ny<=0) return(NULL); | 
|---|
| [295] | 255 |  | 
|---|
| [1207] | 256 | i1 = (i1<0||i1>=nx)? 0: i1; | 
|---|
|  | 257 | i2 = (i2<0||i2>=nx||i2<i1)? nx-1: i2; | 
|---|
|  | 258 | j1 = (j1<0||j1>=ny)? 0: j1; | 
|---|
|  | 259 | j2 = (j2<0||j2>=ny||j2<j1)? ny-1: j2; | 
|---|
|  | 260 |  | 
|---|
|  | 261 | GeneralFitData* mGData = new GeneralFitData(2,(i2-i1+1)*(j2-j1+1),0); | 
|---|
|  | 262 | adel = true; | 
|---|
|  | 263 |  | 
|---|
|  | 264 | for(int i=i1;i<=i2;i++) for(int j=j1;j<=j2;j++) { | 
|---|
|  | 265 | double x = (double) i; | 
|---|
|  | 266 | double y = (double) j; | 
|---|
|  | 267 | double f = (*mMtx)(i,j); | 
|---|
|  | 268 | double e = 1.; | 
|---|
|  | 269 | e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin); | 
|---|
|  | 270 | mGData->AddData2(x,y,f,e); | 
|---|
|  | 271 | } | 
|---|
|  | 272 |  | 
|---|
|  | 273 | return mGData; | 
|---|
|  | 274 | } | 
|---|
|  | 275 |  | 
|---|
|  | 276 | AnyDataObj* NOMAdapter_Matrix::FitResidusObj(GeneralFit& mfit) | 
|---|
|  | 277 | { | 
|---|
|  | 278 | Matrix* m = NULL; | 
|---|
|  | 279 | m = mMtx->FitResidus(mfit); | 
|---|
|  | 280 | return m; | 
|---|
|  | 281 | } | 
|---|
|  | 282 |  | 
|---|
|  | 283 | AnyDataObj* NOMAdapter_Matrix::FitFunctionObj(GeneralFit& mfit) | 
|---|
|  | 284 | { | 
|---|
|  | 285 | Matrix* m = NULL; | 
|---|
|  | 286 | m = mMtx->FitFunction(mfit); | 
|---|
|  | 287 | return m; | 
|---|
|  | 288 | } | 
|---|
|  | 289 |  | 
|---|
| [295] | 290 | // ------------------------------------------------------------- | 
|---|
|  | 291 |  | 
|---|
|  | 292 | /* --Methode-- */ | 
|---|
|  | 293 | NTupInt_Matrix::NTupInt_Matrix(Matrix* m) | 
|---|
|  | 294 | { | 
|---|
|  | 295 | mMtx = m; | 
|---|
|  | 296 | } | 
|---|
|  | 297 |  | 
|---|
|  | 298 | /* --Methode-- */ | 
|---|
|  | 299 | NTupInt_Matrix::~NTupInt_Matrix() | 
|---|
|  | 300 | { | 
|---|
|  | 301 | } | 
|---|
|  | 302 |  | 
|---|
|  | 303 | /* --Methode-- */ | 
|---|
| [326] | 304 | uint_4 NTupInt_Matrix::NbLines() const | 
|---|
| [295] | 305 | { | 
|---|
|  | 306 | return( mMtx->NRows()*mMtx->NCol() ); | 
|---|
|  | 307 | } | 
|---|
|  | 308 |  | 
|---|
|  | 309 | /* --Methode-- */ | 
|---|
| [326] | 310 | uint_4 NTupInt_Matrix::NbColumns() const | 
|---|
| [295] | 311 | { | 
|---|
|  | 312 | return(3); | 
|---|
|  | 313 | } | 
|---|
|  | 314 |  | 
|---|
|  | 315 | /* --Methode-- */ | 
|---|
| [326] | 316 | r_8* NTupInt_Matrix::GetLineD(int n) const | 
|---|
| [295] | 317 | { | 
|---|
|  | 318 | int i,j; | 
|---|
|  | 319 | if ((n < 0) || (n >= mMtx->NRows()*mMtx->NCol() )) | 
|---|
|  | 320 | for(i=0; i<3; i++)  mRet[i] = 0.; | 
|---|
|  | 321 | else { | 
|---|
|  | 322 | i = n/mMtx->NCol(); j = n%mMtx->NCol(); | 
|---|
|  | 323 | mRet[0] = i;  mRet[1] = j;  mRet[2] = (*mMtx)(i,j); | 
|---|
|  | 324 | } | 
|---|
|  | 325 | return(mRet); | 
|---|
|  | 326 | } | 
|---|
|  | 327 |  | 
|---|
|  | 328 | /* --Methode-- */ | 
|---|
| [326] | 329 | string NTupInt_Matrix::VarList_C(const char* nx) const | 
|---|
| [295] | 330 | { | 
|---|
|  | 331 | string nomx; | 
|---|
|  | 332 | if (nx) nomx = nx; | 
|---|
|  | 333 | else nomx = "_xh_"; | 
|---|
|  | 334 | string vardec = "double i,j,val; \n"; | 
|---|
|  | 335 | vardec += "i = " + nomx + "[0]; j = " + nomx + "[1];  val = " + nomx + "[2]; \n"; | 
|---|
|  | 336 | return(vardec); | 
|---|
|  | 337 | } | 
|---|