00001
00033 #ifndef __FLOATFUN_H
00034 #define __FLOATFUN_H
00035
00036 #ifndef __FLOATFUNBASE_H
00037 #include "jbltools/sfh/FloatFunBase.h"
00038 #endif
00039
00040 #ifndef __JBLMATH_H
00041 #include "jbltools/sfh/JBLMath.h"
00042 #endif
00043
00044 #include "jbltools/sfh/BaseCutBase.h"
00045 #include "jbltools/sfh/BaseCutPoR.h"
00046 #include "jbltools/sfh/FillIteratorPoR.h"
00047 #include "jbltools/sfh/FloatFunPoR.h"
00048 #include "jbltools/sfh/ROListPoR.h"
00049
00050
00052 class ConstFun : public FloatFun {
00053 public:
00054
00055 explicit ConstFun (Float_FF c_,
00056 const char *name_ = 0
00057 )
00058 : FloatFun (name_ ? name_ : str(c_).c_str(), str(c_)),
00059 c(c_)
00060 {}
00062 ConstFun (Float_FF c_,
00063 const std::string &name_
00064 )
00065 : FloatFun (name_, str(c_)),
00066 c(c_)
00067 {}
00069 virtual Float_FF operator() () const { return c; }
00070 protected:
00071 Float_FF c;
00072
00073 virtual ~ConstFun() {}
00074 };
00075
00076
00077
00078
00079
00080
00081
00082
00083 class UnityFun : public ConstFun {
00084 public:
00085 UnityFun () : ConstFun (1., "1.0") {}
00086 protected:
00088 virtual ~UnityFun() {}
00089 };
00090
00091
00093
00098 class FloatFunComp: public BaseCut {
00099 public:
00100 FloatFunComp (const std::string& name_) : BaseCut (name_) {}
00101 virtual Float_FF lhsValue() const = 0;
00102 virtual Float_FF rhsValue() const = 0;
00103 };
00104
00105
00106
00107
00108
00110
00111 FloatFun& operator+ (const FloatFun& lhs_, const FloatFun& rhs_);
00112
00114
00115 FloatFun& operator+ (const FloatFun& lhs_, Float_FF rhs_);
00116
00118
00119 FloatFun& operator+ (Float_FF lhs_, const FloatFun& rhs_);
00120
00122
00123 FloatFun& operator- (const FloatFun& lhs_, const FloatFun& rhs_);
00124
00126
00127 FloatFun& operator- (const FloatFun& lhs_, Float_FF rhs_);
00129
00130 FloatFun& operator- (Float_FF lhs_, const FloatFun& rhs_);
00131
00133
00134 FloatFun& operator- (const FloatFun& arg_);
00135
00137
00138 FloatFun& operator+ (FloatFun& arg_);
00139 const FloatFun& operator+ (const FloatFun& arg_);
00140
00141
00143
00144 FloatFun& operator* (const FloatFun& lhs_, const FloatFun& rhs_);
00145
00147
00148 FloatFun& operator* (Float_FF lhs_, const FloatFun& rhs_);
00149
00151
00152 FloatFun& operator* (const FloatFun& lhs_, Float_FF rhs_);
00153
00155
00157
00158
00159 FloatFun& operator/ (const FloatFun& lhs_, const FloatFun& rhs_);
00160
00162
00163 FloatFun& operator/ (Float_FF lhs_, const FloatFun& rhs_);
00164
00166
00167 FloatFun& operator/ (const FloatFun& lhs_, Float_FF rhs_);
00168
00169
00171
00172 FloatFun& abs (const FloatFun& arg_);
00173
00175
00176 FloatFun& acos (const FloatFun& arg_);
00177
00178
00179
00180
00181
00183
00184 FloatFun& asin (const FloatFun& arg_);
00185
00186
00187
00188
00189
00191
00192 FloatFun& atan (const FloatFun& arg_);
00193
00194
00195
00196
00197
00199
00200 FloatFun& atan2 (const FloatFun& arg1, const FloatFun& arg2);
00201
00203
00204 FloatFun& ceil (const FloatFun& arg_);
00205
00207
00208 FloatFun& cos (const FloatFun& arg_);
00209
00211
00212 FloatFun& cosh (const FloatFun& arg_);
00213
00215
00216 FloatFun& exp (const FloatFun& arg_);
00217
00219
00220 FloatFun& fabs (const FloatFun& arg_);
00221
00223
00224 FloatFun& floor (const FloatFun& arg_);
00225
00227
00228 FloatFun& log (const FloatFun& arg_);
00229
00231
00232 FloatFun& log10 (const FloatFun& arg_);
00233
00235
00236 FloatFun& pow (const FloatFun& arg1_, const FloatFun& arg2_);
00237
00239
00240 FloatFun& sin (const FloatFun& arg_);
00241
00243
00244 FloatFun& sinh (const FloatFun& arg_);
00245
00246 <<<<<<< FloatFun.h
00247
00248
00249 class FloatFloatFunLessEqual: public FloatFloatFunComp {
00250 public:
00251 FloatFloatFunLessEqual (float lhs_,
00252 const FloatFun& rhs_
00253 )
00254 : FloatFloatFunComp (lhs_, rhs_, "%8f<=(%s)") {}
00255
00257 virtual bool operator() () const {
00258 return lhs <= rhs();
00259 }
00260 protected:
00262 virtual ~FloatFloatFunLessEqual() {}
00263 };
00264
00265
00266
00267 class FloatFloatFunGreater: public FloatFloatFunComp {
00268 public:
00269 FloatFloatFunGreater (float lhs_,
00270 const FloatFun& rhs_
00271 )
00272 : FloatFloatFunComp (lhs_, rhs_, "%8f>(%s)") {}
00273
00275 virtual bool operator() () const {
00276 return lhs > rhs();
00277 }
00278 protected:
00280 virtual ~FloatFloatFunGreater() {}
00281 };
00282
00283
00284
00285 class FloatFloatFunGreaterEqual: public FloatFloatFunComp {
00286 public:
00287 FloatFloatFunGreaterEqual (float lhs_,
00288 const FloatFun& rhs_
00289 )
00290 : FloatFloatFunComp (lhs_, rhs_, "%8f>=(%s)") {}
00291
00293 virtual bool operator() () const {
00294 return lhs >= rhs();
00295 }
00296 protected:
00298 virtual ~FloatFloatFunGreaterEqual() {}
00299 };
00300
00301
00302
00303 class FloatFloatFunEqual: public FloatFloatFunComp {
00304 public:
00305 FloatFloatFunEqual (float lhs_,
00306 const FloatFun& rhs_
00307 )
00308 : FloatFloatFunComp (lhs_, rhs_, "%8f==(%s)") {}
00309
00311 virtual bool operator() () const {
00312 return lhs == rhs();
00313 }
00314 protected:
00316 virtual ~FloatFloatFunEqual() {}
00317 };
00318
00319
00320
00321 class FloatFloatFunNotEqual: public FloatFloatFunComp {
00322 public:
00323 FloatFloatFunNotEqual (float lhs_,
00324 const FloatFun& rhs_
00325 )
00326 : FloatFloatFunComp (lhs_, rhs_, "%8f!=(%s)") {}
00327
00329 virtual bool operator() () const {
00330 return lhs != rhs();
00331 }
00332 protected:
00334 virtual ~FloatFloatFunNotEqual() {}
00335 };
00336
00337
00338
00339
00340
00341
00342
00343
00344 class FloatFunFloatComp: public FloatFunComp {
00345 public:
00347 FloatFunFloatComp (const FloatFun& lhs_,
00348 float rhs_,
00349 const char *format="FloatFunFloatComp(%s,float)"
00350 );
00351 virtual float lhsValue() const {
00352 return lhs();
00353 }
00354 virtual float rhsValue() const {
00355 return rhs;
00356 }
00357
00358 virtual const FillIterator *getIterator() const {
00359 return lhs.getIterator();
00360 }
00361
00363 virtual const char *getName() const { return name; }
00364 protected:
00365 virtual ~FloatFunFloatComp() {
00366 delete[] name;
00367 name = 0;
00368 }
00369
00370
00371 const FloatFun& lhs;
00372 float rhs;
00373 char *name;
00374 private:
00376 FloatFunFloatComp (const FloatFunFloatComp& source);
00378 FloatFunFloatComp& operator= (const FloatFunFloatComp& source);
00379 };
00380
00381
00382
00383 class FloatFunFloatLess: public FloatFunFloatComp {
00384 public:
00385 FloatFunFloatLess (const FloatFun& lhs_,
00386 float rhs_
00387 )
00388 : FloatFunFloatComp (lhs_, rhs_, "(%s)<%8f") {}
00389
00391 virtual bool operator() () const {
00392 return lhs() < rhs;
00393 }
00394 protected:
00396 virtual ~FloatFunFloatLess() {}
00397 };
00398
00399
00400
00401 class FloatFunFloatLessEqual: public FloatFunFloatComp {
00402 public:
00403 FloatFunFloatLessEqual (const FloatFun& lhs_,
00404 float rhs_
00405 )
00406 : FloatFunFloatComp (lhs_, rhs_, "(%s)<=%8f") {}
00407
00409 virtual bool operator() () const {
00410 return lhs() <= rhs;
00411 }
00412 protected:
00414 virtual ~FloatFunFloatLessEqual() {}
00415 };
00416
00417
00418
00419 class FloatFunFloatGreater: public FloatFunFloatComp {
00420 public:
00421 FloatFunFloatGreater (const FloatFun& lhs_,
00422 float rhs_
00423 )
00424 : FloatFunFloatComp (lhs_, rhs_, "(%s)>%8f") {}
00425
00427 virtual bool operator() () const {
00428 return lhs() > rhs;
00429 }
00430 protected:
00432 virtual ~FloatFunFloatGreater() {}
00433 };
00434
00435
00436
00437 class FloatFunFloatGreaterEqual: public FloatFunFloatComp {
00438 public:
00439 FloatFunFloatGreaterEqual (const FloatFun& lhs_,
00440 float rhs_
00441 )
00442 : FloatFunFloatComp (lhs_, rhs_, "(%s)>=%8f") {}
00443
00445 virtual bool operator() () const {
00446 return lhs() >= rhs;
00447 }
00448 protected:
00450 virtual ~FloatFunFloatGreaterEqual() {}
00451 };
00452
00453
00454
00455 class FloatFunFloatEqual: public FloatFunFloatComp {
00456 public:
00457 FloatFunFloatEqual (const FloatFun& lhs_,
00458 float rhs_
00459 )
00460 : FloatFunFloatComp (lhs_, rhs_, "(%s)==%8f") {}
00461
00463 virtual bool operator() () const {
00464 return lhs() == rhs;
00465 }
00466 protected:
00468 virtual ~FloatFunFloatEqual() {}
00469 };
00470
00471
00472
00473 class FloatFunFloatNotEqual: public FloatFunFloatComp {
00474 public:
00475 FloatFunFloatNotEqual (const FloatFun& lhs_,
00476 float rhs_
00477 )
00478 : FloatFunFloatComp (lhs_, rhs_, "(%s)!=%8f") {}
00479
00481 virtual bool operator() () const {
00482 return lhs() != rhs;
00483 }
00484 protected:
00486 virtual ~FloatFunFloatNotEqual() {}
00487 };
00488
00489
00490 class CollectiveFloatFun: public FloatFun {
00491 public:
00492 CollectiveFloatFun (const FloatFunPoR& fun_=0,
00493 const BaseCutPoR& cut_=0,
00494 const FillIteratorPoR& intiter_=0,
00495 const FillIteratorPoR& extiter_=0,
00496 const char *format="(CollectiveFloatFun(%s,%s,%s,%s)"
00497 );
00498 virtual const FillIterator *getIterator() const {
00499 return extiter;
00500 }
00501
00503 virtual const char *getName() const { return name; }
00504
00505 protected:
00506 virtual ~CollectiveFloatFun() {
00507 delete[] name;
00508 name = 0;
00509 }
00510 void checkIterators();
00511 void makeName(const char *format);
00512
00513 const FloatFun *fun;
00514 const BaseCut *cut;
00515 FillIterator *intiter;
00516 const FillIterator *extiter;
00517 char *name;
00518 private:
00520 CollectiveFloatFun(const CollectiveFloatFun& source);
00522 CollectiveFloatFun& operator= (const CollectiveFloatFun& source);
00523 };
00524
00525
00526 class MaxFloatFun: public CollectiveFloatFun {
00527 public:
00528 MaxFloatFun (const FloatFunPoR& fun_=0,
00529 const BaseCutPoR& cut_=0,
00530 const FillIteratorPoR& intiter_=0,
00531 const FillIteratorPoR& extiter_=0
00532 )
00533 : CollectiveFloatFun (fun_, cut_, intiter_, extiter_, "max(%s,%s,%s,%s)")
00534 {}
00535
00536 virtual float operator() () const;
00537 protected:
00538 virtual ~MaxFloatFun() {}
00539 };
00540
00541
00542 class MinFloatFun: public CollectiveFloatFun {
00543 public:
00544 MinFloatFun (const FloatFunPoR& fun_=0,
00545 const BaseCutPoR& cut_=0,
00546 const FillIteratorPoR& intiter_=0,
00547 const FillIteratorPoR& extiter_=0
00548 )
00549 : CollectiveFloatFun (fun_, cut_, intiter_, extiter_, "min(%s,%s,%s,%s)")
00550 {}
00551
00552 virtual float operator() () const;
00553 protected:
00554 virtual ~MinFloatFun() {}
00555 };
00556
00557
00558 class SumFloatFun: public CollectiveFloatFun {
00559 public:
00560 SumFloatFun (const FloatFunPoR& fun_=0,
00561 const BaseCutPoR& cut_=0,
00562 const FillIteratorPoR& intiter_=0,
00563 const FillIteratorPoR& extiter_=0
00564 )
00565 : CollectiveFloatFun (fun_, cut_, intiter_, extiter_, "sum(%s,%s,%s,%s)")
00566 {}
00567
00568 virtual float operator() () const;
00569 protected:
00570 virtual ~SumFloatFun() {}
00571 };
00572
00573
00574 class AverageFloatFun: public CollectiveFloatFun {
00575 public:
00576 AverageFloatFun (const FloatFunPoR& fun_=0,
00577 const BaseCutPoR& cut_=0,
00578 const FillIteratorPoR& intiter_=0,
00579 const FillIteratorPoR& extiter_=0
00580 )
00581 : CollectiveFloatFun (fun_, cut_, intiter_, extiter_, "average(%s,%s,%s,%s)")
00582 {}
00583
00584 virtual float operator() () const;
00585 protected:
00586 virtual ~AverageFloatFun() {}
00587 };
00588
00589
00590 class CachedFloatFun: public FloatFun, public CachedO {
00591 public:
00593 CachedFloatFun (const ROListPoR& rol,
00594 const FloatFun& arg_
00595 );
00596
00598 virtual float operator() () const;
00599
00601 virtual void invalidateCache() { cacheValid = false; }
00602
00604 virtual const char *getName() const { return CachedFloatFun::name; }
00605
00606 protected:
00608 virtual ~CachedFloatFun() {
00609 delete[] name;
00610 name = 0;
00611 }
00612
00613
00614 const FloatFun& arg;
00615 mutable bool cacheValid;
00616 mutable float cachedValue;
00617 char *name;
00618
00619 private:
00621 CachedFloatFun (const CachedFloatFun& rhs);
00623 CachedFloatFun& operator= (const CachedFloatFun& rhs);
00624 };
00625
00626 class CachedFloatFunIt: public FloatFun, public CachedO {
00627 public:
00629 CachedFloatFunIt (const ROListPoR& rol,
00630 const FloatFun& arg_,
00631 const FillIterator& iter_
00632 );
00633
00635 virtual float operator() () const;
00636
00638 virtual const FillIterator *getIterator() const {
00639 return &iter;
00640 }
00641
00643 virtual void invalidateCache() {
00644 cacheValid.resize(0);
00645 cachedValues.resize(0);
00646 }
00647
00649 virtual const char *getName() const { return name; }
00650
00651 protected:
00653 void growCache (unsigned int s) const;
00654
00656 virtual ~CachedFloatFunIt() {
00657 delete[] name;
00658 name = 0;
00659 }
00660
00661
00662 const FloatFun& arg;
00663 const FillIterator& iter;
00664 mutable std::vector<bool> cacheValid;
00665 mutable std::vector<float> cachedValues;
00666 char *name;
00667
00668 private:
00670 CachedFloatFunIt (const CachedFloatFunIt& rhs);
00672 CachedFloatFunIt& operator= (const CachedFloatFunIt& rhs);
00673 };
00674
00675
00676
00677
00679
00682 inline FloatFun& operator+ (const FloatFun& lhs_, const FloatFun& rhs_) {
00683 return *new SumOfTwoFuns (lhs_, rhs_);
00684 }
00685
00687
00690 inline FloatFun& operator+ (const FloatFun& lhs_, float rhs_) {
00691 return *new ScalarSumFloatFun (rhs_, lhs_);
00692 }
00694
00697 inline FloatFun& operator+ (float lhs_, const FloatFun& rhs_) {
00698 return *new ScalarSumFloatFun (lhs_, rhs_);
00699 }
00700
00702
00705 inline FloatFun& operator- (const FloatFun& lhs_, const FloatFun& rhs_) {
00706 return *new DiffOfTwoFuns (lhs_, rhs_);
00707 }
00709
00712 inline FloatFun& operator- (const FloatFun& lhs_, float rhs_) {
00713 return *new ScalarSumFloatFun (-rhs_, lhs_, 1, NamedO::str('(')+lhs_.getName()+")-"+NamedO::str(rhs_));
00714 }
00716
00719 inline FloatFun& operator- (float lhs_, const FloatFun& rhs_) {
00720 return *new ScalarSumFloatFun (lhs_, rhs_, -1, NamedO::str(lhs_)+"-("+rhs_.getName()+')');
00721 }
00722
00724
00727 inline FloatFun& operator- (const FloatFun& arg_) {
00728 return *new ScalarProductFloatFun ("-", -1, arg_);
00729 }
00730
00731
00733
00736 inline FloatFun& operator* (const FloatFun& lhs_, const FloatFun& rhs_) {
00737 if (&lhs_ == &rhs_) return *new SquareFloatFun (lhs_);
00738 return *new ProdOfTwoFuns (lhs_, rhs_);
00739 }
00740
00742
00745 inline FloatFun& operator* (float lhs_, const FloatFun& rhs_) {
00746 return *new ScalarProductFloatFun (lhs_, rhs_);
00747 }
00749
00752 inline FloatFun& operator* (const FloatFun& lhs_, float rhs_) {
00753 return *new ScalarProductFloatFun (rhs_, lhs_);
00754 }
00756
00759 =======
00761
00762 FloatFun& sqrt (const FloatFun& arg_);
00763 >>>>>>> 1.25
00764
00766
00767 FloatFun& tan (const FloatFun& arg_);
00768
00770
00771 FloatFun& tanh (const FloatFun& arg_);
00772
00774
00775 FloatFun& square (const FloatFun& arg_);
00776
00778
00779 FloatFun& rad (const FloatFun& arg_);
00780
00782
00783 FloatFun& deg (const FloatFun& arg_);
00784
00785
00786
00787
00788
00789
00794 FloatFunComp& operator< (const FloatFun& lhs_, const FloatFun& rhs_);
00795
00800 FloatFunComp& operator> (const FloatFun& lhs_, const FloatFun& rhs_);
00801
00806 FloatFunComp& operator<= (const FloatFun& lhs_, const FloatFun& rhs_);
00807
00812 FloatFunComp& operator>= (const FloatFun& lhs_, const FloatFun& rhs_);
00813
00818 FloatFunComp& operator== (const FloatFun& lhs_, const FloatFun& rhs_);
00819
00824 FloatFunComp& operator!= (const FloatFun& lhs_, const FloatFun& rhs_);
00825
00826
00827
00828
00833 FloatFunComp& operator< (Float_FF lhs_, const FloatFun& rhs_);
00834
00839 FloatFunComp& operator<= (Float_FF lhs_, const FloatFun& rhs_);
00840
00845 FloatFunComp& operator> (Float_FF lhs_, const FloatFun& rhs_);
00846
00851 FloatFunComp& operator>= (Float_FF lhs_, const FloatFun& rhs_);
00852
00857 FloatFunComp& operator== (Float_FF lhs_, const FloatFun& rhs_);
00858
00863 FloatFunComp& operator!= (Float_FF lhs_, const FloatFun& rhs_);
00864
00865
00866
00871 FloatFunComp& operator< (const FloatFun& lhs_, Float_FF rhs_);
00872
00877 FloatFunComp& operator<= (const FloatFun& lhs_, Float_FF rhs_);
00878
00883 FloatFunComp& operator> (const FloatFun& lhs_, Float_FF rhs_);
00884
00889 FloatFunComp& operator>= (const FloatFun& lhs_, Float_FF rhs_);
00890
00895 FloatFunComp& operator== (const FloatFun& lhs_, Float_FF rhs_);
00896
00901 FloatFunComp& operator!= (const FloatFun& lhs_, Float_FF rhs_);
00902
00903
00904
00905
00906
00911 FloatFunComp& operator< (const FloatFunComp& lhs_, const FloatFun& rhs_);
00912
00917 FloatFunComp& operator<= (const FloatFunComp& lhs_, const FloatFun& rhs_);
00918
00923 FloatFunComp& operator> (const FloatFunComp& lhs_, const FloatFun& rhs_);
00924
00929 FloatFunComp& operator>= (const FloatFunComp& lhs_, const FloatFun& rhs_);
00930
00935 FloatFunComp& operator== (const FloatFunComp& lhs_, const FloatFun& rhs_);
00936
00941 FloatFunComp& operator!= (const FloatFunComp& lhs_, const FloatFun& rhs_);
00942
00947 FloatFunComp& operator< (const FloatFunComp& lhs_, Float_FF rhs_);
00952 FloatFunComp& operator<= (const FloatFunComp& lhs_, Float_FF rhs_);
00957 FloatFunComp& operator> (const FloatFunComp& lhs_, Float_FF rhs_);
00962 FloatFunComp& operator>= (const FloatFunComp& lhs_, Float_FF rhs_);
00967 FloatFunComp& operator== (const FloatFunComp& lhs_, Float_FF rhs_);
00972 FloatFunComp& operator!= (const FloatFunComp& lhs_, Float_FF rhs_);
00973
00978 FloatFun& max (const FloatFunPoRConst& fun,
00979 const BaseCutPoRConst& cut=0,
00980 const FillIteratorPoR& intiter=0,
00981 const FillIteratorPoRConst& extiter=0
00982 );
00983
00988 FloatFun& min (const FloatFunPoRConst& fun,
00989 const BaseCutPoRConst& cut=0,
00990 const FillIteratorPoR& intiter=0,
00991 const FillIteratorPoRConst& extiter=0
00992 );
00993
00998 FloatFun& sum (const FloatFunPoRConst& fun,
00999 const BaseCutPoRConst& cut=0,
01000 const FillIteratorPoR& intiter=0,
01001 const FillIteratorPoRConst& extiter=0
01002 );
01003
01008 FloatFun& average (const FloatFunPoRConst& fun,
01009 const BaseCutPoRConst& cut=0,
01010 const FillIteratorPoR& intiter=0,
01011 const FillIteratorPoRConst& extiter=0
01012 );
01013
01018 FloatFun& cached (const ROListPoR& rol,
01019 const FloatFunPoR& fun,
01020 const FillIteratorPoR& iter=0
01021 );
01022
01023 #endif