00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef __CDETECT_H
00027 #define __CDETECT_H
00028
00029 #include "cobject.h"
00030 #include "cstat.h"
00031
00032
00033 class cTransientDetection;
00034 class cAccuracyDetection;
00035 class cTDExpandingWindows;
00036 class cADByStddev;
00037
00038
00039 class cStatistic;
00040
00045 typedef void (*PostTDFunc)(cTransientDetection *, void *);
00046
00051 typedef void (*PostADFunc)(cAccuracyDetection *, void *);
00052
00053
00054
00060 class SIM_API cTransientDetection : public cObject
00061 {
00062 protected:
00063 cStatistic *back;
00064 PostTDFunc pdf;
00065 void *pdfdata;
00066
00067 public:
00070
00074 cTransientDetection(const cTransientDetection& r) : cObject() {setName(r.name());operator=(r);}
00075
00079 explicit cTransientDetection(const char *name=NULL) : cObject(name) {}
00080
00084 virtual ~cTransientDetection() {}
00085
00089 cTransientDetection& operator=(const cTransientDetection&) {copyNotSupported();return *this;}
00091
00094
00095
00097
00100
00104 virtual void collect(double val) = 0;
00105
00109 virtual bool detected() const = 0;
00110
00114 virtual void reset() = 0;
00115
00120 virtual void stop() = 0;
00121
00126 virtual void start() = 0;
00127
00132 void setPostDetectFunction(PostTDFunc f, void *p) {pdf = f; pdfdata = p;}
00134
00137
00142 virtual void setHostObject(cStatistic *ptr) {back = ptr;}
00143
00147 virtual cStatistic *hostObject() const {return back;}
00149 };
00150
00151
00152
00158 class SIM_API cAccuracyDetection : public cObject
00159 {
00160 protected:
00161 cStatistic *back;
00162 PostADFunc pdf;
00163 void *pdfdata;
00164
00165 public:
00168
00172 cAccuracyDetection(const cAccuracyDetection& r) : cObject() {setName(r.name());operator=(r);}
00173
00177 explicit cAccuracyDetection(const char *name=NULL) : cObject(name) {}
00178
00182 virtual ~cAccuracyDetection() {}
00183
00187 cAccuracyDetection& operator=(const cAccuracyDetection&) {copyNotSupported();return *this;}
00189
00192
00193
00195
00198
00202 virtual void collect(double val) = 0;
00203
00207 virtual bool detected() const = 0;
00208
00212 virtual void reset() = 0;
00213
00218 virtual void stop() = 0;
00219
00224 virtual void start() = 0;
00225
00230 void setPostDetectFunction(PostADFunc f, void *p) {pdf=f; pdfdata=p;}
00232
00235
00240 virtual void setHostObject(cStatistic *ptr) {back = ptr;}
00241
00245 virtual cStatistic *hostObject() const {return back;}
00247 };
00248
00249
00250
00258 class SIM_API cTDExpandingWindows : public cTransientDetection
00259 {
00260 private:
00261 bool go;
00262 bool transval;
00263 double accuracy;
00264 int minwinds;
00265 double windexp;
00266 int repeats;
00267 int detreps;
00268 int size;
00269 struct xy {double x; double y; xy *next;};
00270 xy *func;
00271
00272 private:
00273
00274 void detectTransient();
00275
00276 public:
00279
00283 cTDExpandingWindows(const cTDExpandingWindows& r);
00284
00288 explicit cTDExpandingWindows(const char *name=NULL,
00289 int reps=3, int minw=4, double wind=1.3, double acc=0.3,
00290 PostTDFunc f=NULL,void *p=NULL);
00291
00295 virtual ~cTDExpandingWindows();
00296
00301 cTDExpandingWindows& operator=(const cTDExpandingWindows& res);
00303
00306
00311 virtual cPolymorphic *dup() const {return new cTDExpandingWindows(*this);}
00313
00316
00320 virtual void collect(double val);
00321
00325 virtual bool detected() const {return transval;}
00326
00330 virtual void reset();
00331
00335 virtual void stop() {go = false;}
00336
00341 virtual void start() {go = true;}
00343
00349 void setParameters(int reps=3, int minw=4,
00350 double wind=1.3, double acc=0.3);
00352 };
00353
00354
00355
00356
00364 class SIM_API cADByStddev : public cAccuracyDetection
00365 {
00366 private:
00367 bool go;
00368 bool resaccval;
00369 double accuracy;
00370 long int sctr;
00371 double ssum,sqrsum;
00372 int repeats, detreps;
00373
00374 private:
00375
00376 void detectAccuracy();
00377
00378
00379 double stddev();
00380
00381 public:
00384
00388 cADByStddev(const cADByStddev& r);
00389
00393 explicit cADByStddev(const char *name=NULL,
00394 double acc=0.01, int reps=3,
00395 PostADFunc f=NULL, void *p=NULL);
00396
00400 virtual ~cADByStddev() {}
00401
00406 cADByStddev& operator=(const cADByStddev& res);
00408
00411
00416 virtual cPolymorphic *dup() const {return new cADByStddev(*this);}
00418
00421
00425 virtual void collect(double val);
00426
00430 virtual bool detected() const {return resaccval;}
00431
00435 virtual void reset();
00436
00440 virtual void stop() {go=false;}
00441
00446 virtual void start() {go=true;}
00448
00451
00455 void setParameters(double acc=0.1, int reps=3)
00456 {accuracy=acc; repeats=detreps=reps;}
00458 };
00459
00460 #endif
00461