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 private:
00063 cStatistic *back;
00064
00065 public:
00068
00072 cTransientDetection(const cTransientDetection& r) : cObject() {setName(r.name());operator=(r);}
00073
00077 explicit cTransientDetection(const char *name=NULL) : cObject(name) {}
00078
00082 virtual ~cTransientDetection() {}
00083
00087 cTransientDetection& operator=(const cTransientDetection&) {copyNotSupported();return *this;}
00089
00092
00093
00094
00100 virtual int netPack();
00101
00107 virtual int netUnpack();
00109
00112
00116 virtual void collect(double val) = 0;
00117
00121 virtual bool detected() const = 0;
00122
00126 virtual void reset() = 0;
00127
00132 virtual void stop() = 0;
00133
00138 virtual void start() = 0;
00140
00143
00148 virtual void setHostObject(cStatistic *ptr) {back = ptr;}
00149
00153 virtual cStatistic *hostObject() const {return back;}
00155 };
00156
00157
00158
00164 class SIM_API cAccuracyDetection : public cObject
00165 {
00166 private:
00167 cStatistic *back;
00168
00169 public:
00172
00176 cAccuracyDetection(const cAccuracyDetection& r) : cObject() {setName(r.name());operator=(r);}
00177
00181 explicit cAccuracyDetection(const char *name=NULL) : cObject(name) {}
00182
00186 virtual ~cAccuracyDetection() {}
00187
00191 cAccuracyDetection& operator=(const cAccuracyDetection&) {copyNotSupported();return *this;}
00193
00196
00197
00198
00204 virtual int netPack();
00205
00211 virtual int netUnpack();
00213
00216
00220 virtual void collect(double val) = 0;
00221
00225 virtual bool detected() const = 0;
00226
00230 virtual void reset() = 0;
00231
00236 virtual void stop() = 0;
00237
00242 virtual void start() = 0;
00244
00247
00252 virtual void setHostObject(cStatistic *ptr) {back = ptr;}
00253
00257 virtual cStatistic *hostObject() const {return back;}
00259 };
00260
00261
00262
00270 class SIM_API cTDExpandingWindows : public cTransientDetection
00271 {
00272 private:
00273 bool go;
00274 bool transval;
00275 double accuracy;
00276 int minwinds;
00277 double windexp;
00278 int repeats;
00279 int detreps;
00280 int size;
00281 struct xy {double x; double y; xy *next;};
00282 xy *func;
00283 PostTDFunc pdf;
00284 void *pdfdata;
00285
00286 private:
00287
00288 void detectTransient();
00289
00290 public:
00293
00297 cTDExpandingWindows(const cTDExpandingWindows& r);
00298
00302 explicit cTDExpandingWindows(const char *name=NULL,
00303 int reps=3, int minw=4, double wind=1.3, double acc=0.3,
00304 PostTDFunc f=NULL,void *p=NULL);
00305
00309 virtual ~cTDExpandingWindows();
00310
00315 cTDExpandingWindows& operator=(const cTDExpandingWindows& res);
00317
00320
00325 virtual cObject *dup() const {return new cTDExpandingWindows(*this);}
00327
00330
00334 virtual void collect(double val);
00335
00339 virtual bool detected() const {return transval;}
00340
00344 virtual void reset();
00345
00349 virtual void stop() {go = false;}
00350
00355 virtual void start() {go = true;}
00357
00360
00365
00366 void setPostDetectFunction(PostTDFunc f, void *p) {pdf = f; pdfdata = p;}
00367
00371 void setParameters(int reps=3, int minw=4,
00372 double wind=1.3, double acc=0.3);
00374 };
00375
00376
00377
00378
00386 class SIM_API cADByStddev : public cAccuracyDetection
00387 {
00388 private:
00389 bool go;
00390 bool resaccval;
00391 double accuracy;
00392 long int sctr;
00393 double ssum,sqrsum;
00394 int repeats, detreps;
00395 PostADFunc pdf;
00396 void *pdfdata;
00397
00398 private:
00399
00400 void detectAccuracy();
00401
00402
00403 double stddev();
00404
00405 public:
00408
00412 cADByStddev(const cADByStddev& r);
00413
00417 explicit cADByStddev(const char *name=NULL,
00418 double acc=0.01, int reps=3,
00419 PostADFunc f=NULL, void *p=NULL);
00420
00424 virtual ~cADByStddev() {}
00425
00430 cADByStddev& operator=(const cADByStddev& res);
00432
00435
00440 virtual cObject *dup() const {return new cADByStddev(*this);}
00442
00445
00449 virtual void collect(double val);
00450
00454 virtual bool detected() const {return resaccval;}
00455
00459 virtual void reset();
00460
00464 virtual void stop() {go=false;}
00465
00470 virtual void start() {go=true;}
00472
00475
00480
00481 void setPostDetectFunction(PostADFunc f, void *p) {pdf=f; pdfdata=p;}
00482
00486 void setParameters(double acc=0.1, int reps=3)
00487 {accuracy=acc; repeats=detreps=reps;}
00489 };
00490
00491 #endif
00492