MIDAS
Loading...
Searching...
No Matches
MidasHistoryBinnedBuffer Class Reference

#include <history.h>

Inheritance diagram for MidasHistoryBinnedBuffer:
Collaboration diagram for MidasHistoryBinnedBuffer:

Public Member Functions

 MidasHistoryBinnedBuffer (time_t first_time, time_t last_time, int num_bins)
 
 ~MidasHistoryBinnedBuffer ()
 
void Start ()
 
void Add (time_t t, double v)
 
void Finish ()
 
- Public Member Functions inherited from MidasHistoryBufferInterface
 MidasHistoryBufferInterface ()
 
virtual ~MidasHistoryBufferInterface ()
 

Public Attributes

int fNumBins = 0
 
time_t fFirstTime = 0
 
time_t fLastTime = 0
 
int fNumEntries = 0
 
double * fSum0 = NULL
 
double * fSum1 = NULL
 
double * fSum2 = NULL
 
int * fCount = NULL
 
double * fMean = NULL
 
double * fRms = NULL
 
double * fMin = NULL
 
double * fMax = NULL
 
time_t * fBinsFirstTime = NULL
 
double * fBinsFirstValue = NULL
 
time_t * fBinsLastTime = NULL
 
double * fBinsLastValue = NULL
 
time_t * fLastTimePtr = NULL
 
double * fLastValuePtr = NULL
 

Detailed Description

Definition at line 69 of file history.h.

Constructor & Destructor Documentation

◆ MidasHistoryBinnedBuffer()

MidasHistoryBinnedBuffer::MidasHistoryBinnedBuffer ( time_t  first_time,
time_t  last_time,
int  num_bins 
)

Definition at line 3336 of file history_schema.cxx.

3337{
3338 fNumEntries = 0;
3339
3340 fNumBins = num_bins;
3341 fFirstTime = first_time;
3343
3344 fSum0 = new double[num_bins];
3345 fSum1 = new double[num_bins];
3346 fSum2 = new double[num_bins];
3347
3348 for (int i=0; i<num_bins; i++) {
3349 fSum0[i] = 0;
3350 fSum1[i] = 0;
3351 fSum2[i] = 0;
3352 }
3353}
DWORD last_time
Definition mana.cxx:3070
INT i
Definition mdump.cxx:32

◆ ~MidasHistoryBinnedBuffer()

MidasHistoryBinnedBuffer::~MidasHistoryBinnedBuffer ( )

Definition at line 3355 of file history_schema.cxx.

3356{
3357 delete fSum0; fSum0 = NULL;
3358 delete fSum1; fSum1 = NULL;
3359 delete fSum2; fSum2 = NULL;
3360 // poison the pointers
3361 fCount = NULL;
3362 fMean = NULL;
3363 fRms = NULL;
3364 fMin = NULL;
3365 fMax = NULL;
3366 fBinsFirstTime = NULL;
3367 fBinsFirstValue = NULL;
3368 fBinsLastTime = NULL;
3369 fBinsLastValue = NULL;
3370 fLastTimePtr = NULL;
3371 fLastValuePtr = NULL;
3372}

Member Function Documentation

◆ Add()

void MidasHistoryBinnedBuffer::Add ( time_t  t,
double  v 
)
virtual

Implements MidasHistoryBufferInterface.

Definition at line 3396 of file history_schema.cxx.

3397{
3398 if (t < fFirstTime)
3399 return;
3400 if (t > fLastTime)
3401 return;
3402
3403 fNumEntries++;
3404
3405 double a = (double)(t - fFirstTime);
3406 double b = (double)(fLastTime - fFirstTime);
3407 double fbin = fNumBins*a/b;
3408
3409 int ibin = (int)fbin;
3410
3411 if (ibin < 0)
3412 ibin = 0;
3413 else if (ibin >= fNumBins)
3414 ibin = fNumBins-1;
3415
3416 if (fSum0[ibin] == 0) {
3417 if (fMin)
3418 fMin[ibin] = v;
3419 if (fMax)
3420 fMax[ibin] = v;
3421 if (fBinsFirstTime)
3422 fBinsFirstTime[ibin] = t;
3423 if (fBinsFirstValue)
3424 fBinsFirstValue[ibin] = v;
3425 if (fBinsLastTime)
3426 fBinsLastTime[ibin] = t;
3427 if (fBinsLastValue)
3428 fBinsLastValue[ibin] = v;
3429 if (fLastTimePtr)
3430 *fLastTimePtr = t;
3431 if (fLastValuePtr)
3432 *fLastValuePtr = v;
3433 }
3434
3435 fSum0[ibin] += 1.0;
3436 fSum1[ibin] += v;
3437 fSum2[ibin] += v*v;
3438
3439 if (fMin)
3440 if (v < fMin[ibin])
3441 fMin[ibin] = v;
3442
3443 if (fMax)
3444 if (v > fMax[ibin])
3445 fMax[ibin] = v;
3446
3447 // NOTE: this assumes t and v are sorted by time.
3448 if (fBinsLastTime)
3449 fBinsLastTime[ibin] = t;
3450 if (fBinsLastValue)
3451 fBinsLastValue[ibin] = v;
3452
3453 if (fLastTimePtr)
3454 if (t > *fLastTimePtr) {
3455 *fLastTimePtr = t;
3456 if (fLastValuePtr)
3457 *fLastValuePtr = v;
3458 }
3459}

◆ Finish()

void MidasHistoryBinnedBuffer::Finish ( )

Definition at line 3461 of file history_schema.cxx.

3462{
3463 for (int i=0; i<fNumBins; i++) {
3464 double num = fSum0[i];
3465 double mean = 0;
3466 double variance = 0;
3467 if (num > 0) {
3468 mean = fSum1[i]/num;
3469 variance = fSum2[i]/num-mean*mean;
3470 }
3471 double rms = 0;
3472 if (variance > 0)
3473 rms = sqrt(variance);
3474
3475 if (fCount)
3476 fCount[i] = (int)num;
3477
3478 if (fMean)
3479 fMean[i] = mean;
3480
3481 if (fRms)
3482 fRms[i] = rms;
3483
3484 if (num == 0) {
3485 if (fMin)
3486 fMin[i] = 0;
3487 if (fMax)
3488 fMax[i] = 0;
3489 }
3490 }
3491}
Here is the caller graph for this function:

◆ Start()

void MidasHistoryBinnedBuffer::Start ( )

Definition at line 3374 of file history_schema.cxx.

3375{
3376 for (int ibin = 0; ibin < fNumBins; ibin++) {
3377 if (fMin)
3378 fMin[ibin] = 0;
3379 if (fMax)
3380 fMax[ibin] = 0;
3381 if (fBinsFirstTime)
3382 fBinsFirstTime[ibin] = 0;
3383 if (fBinsFirstValue)
3384 fBinsFirstValue[ibin] = 0;
3385 if (fBinsLastTime)
3386 fBinsLastTime[ibin] = 0;
3387 if (fBinsLastValue)
3388 fBinsLastValue[ibin] = 0;
3389 }
3390 if (fLastTimePtr)
3391 *fLastTimePtr = 0;
3392 if (fLastValuePtr)
3393 *fLastValuePtr = 0;
3394}
Here is the caller graph for this function:

Member Data Documentation

◆ fBinsFirstTime

time_t* MidasHistoryBinnedBuffer::fBinsFirstTime = NULL

Definition at line 88 of file history.h.

◆ fBinsFirstValue

double* MidasHistoryBinnedBuffer::fBinsFirstValue = NULL

Definition at line 89 of file history.h.

◆ fBinsLastTime

time_t* MidasHistoryBinnedBuffer::fBinsLastTime = NULL

Definition at line 90 of file history.h.

◆ fBinsLastValue

double* MidasHistoryBinnedBuffer::fBinsLastValue = NULL

Definition at line 91 of file history.h.

◆ fCount

int* MidasHistoryBinnedBuffer::fCount = NULL

Definition at line 82 of file history.h.

◆ fFirstTime

time_t MidasHistoryBinnedBuffer::fFirstTime = 0

Definition at line 73 of file history.h.

◆ fLastTime

time_t MidasHistoryBinnedBuffer::fLastTime = 0

Definition at line 74 of file history.h.

◆ fLastTimePtr

time_t* MidasHistoryBinnedBuffer::fLastTimePtr = NULL

Definition at line 93 of file history.h.

◆ fLastValuePtr

double* MidasHistoryBinnedBuffer::fLastValuePtr = NULL

Definition at line 94 of file history.h.

◆ fMax

double* MidasHistoryBinnedBuffer::fMax = NULL

Definition at line 86 of file history.h.

◆ fMean

double* MidasHistoryBinnedBuffer::fMean = NULL

Definition at line 83 of file history.h.

◆ fMin

double* MidasHistoryBinnedBuffer::fMin = NULL

Definition at line 85 of file history.h.

◆ fNumBins

int MidasHistoryBinnedBuffer::fNumBins = 0

Definition at line 72 of file history.h.

◆ fNumEntries

int MidasHistoryBinnedBuffer::fNumEntries = 0

Definition at line 76 of file history.h.

◆ fRms

double* MidasHistoryBinnedBuffer::fRms = NULL

Definition at line 84 of file history.h.

◆ fSum0

double* MidasHistoryBinnedBuffer::fSum0 = NULL

Definition at line 77 of file history.h.

◆ fSum1

double* MidasHistoryBinnedBuffer::fSum1 = NULL

Definition at line 78 of file history.h.

◆ fSum2

double* MidasHistoryBinnedBuffer::fSum2 = NULL

Definition at line 79 of file history.h.


The documentation for this class was generated from the following files: