Ignore:
Timestamp:
Nov 9, 1999, 3:04:05 PM (26 years ago)
Author:
ansari
Message:

portage cxx en cours

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Poubelle/archTOI.old/toiinterpolator.cc

    r350 r555  
    11// toiinterpolator.cc
    2 // Eric Aubourg         CEA/DAPNIA/SPP   juillet 1999
     2// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
    33
    44
    55#include "toiinterpolator.h"
     6#include "toimanager.h"
     7#include "archexc.h"
    68
    7 void TOIInterpolator::enterValue(double value, long sample)
    8 {
    9   // $CHECK$ sample > back.sample
    10   if (!hist.empty() && sample == hist.back().t) return; // pour eviter /0
    11   hist.push_back(pair(value, sample));
     9TOIInterpolator::TOIInterpolator() {
    1210}
    1311
    14 bool TOIInterpolator::needMoreDataFor(long sample)
    15 {
    16   if (hist.empty()) return true;
    17   int xx = hist.back().t;
    18   return (hist.empty() || sample > xx);
     12
     13string TOIInterpolator::getName() {
     14  return("TOIInterpolator 1.0");
    1915}
    2016
    21 bool TOIInterpolator::canGet(long sample)
    22 {
    23   return (!hist.empty() && (sample >= hist.front().t && sample <= hist.back().t));
     17bool TOIInterpolator::canProduce(TOI const& toi) {
     18  // 1. Already in cache ?
     19  map<TOI, map<TOI, TOIProducer*> >::const_iterator j = neededTOIs.find(toi);
     20  if (j != neededTOIs.end()) return true;
     21
     22  // 2. Should have interp
     23  if (toi.options.find("interp") == toi.options.end()) return false;
     24 
     25  // 3. Can get non interp
     26  TOI toi2 = toi;
     27  toi2.options.erase("interp");
     28  TOIProducer* prod = TOIManager::findTOIProducer(toi2);
     29  set<string> opts = prod->getAvailOptions(toi2);
     30  if (opts.find("interp") != opts.end()) return false; // already handled
     31  if (opts.find("repet") != opts.end()) return false;  // not compatible !
     32 
     33  map<TOI, TOIProducer*> fullInputTOI;
     34  fullInputTOI[toi2] = prod;
     35  neededTOIs[toi] = fullInputTOI;
     36  return true;
    2437}
    2538
    26 double TOIInterpolator::getEValue(long sample) // can forget before sample
    27 {
    28   if (!canGet(sample)) return -9.e99;   // user should have checked before
    29   deque<pair>::iterator i = hist.begin();
    30   while ((*i).t < sample) i++;
    31   if ((*i).t > sample) i--;
    32   double value = (*i).val;
    33   if (i != hist.begin()) {
    34     i--;
    35     hist.erase(hist.begin(), i);
    36   }
    37   return value;
     39set<TOI> TOIInterpolator::reqTOIFor(TOI const& toi) {
     40  set<TOI> x;
     41  if (!canProduce(toi)) return x;
     42  x.insert((*neededTOIs[toi].begin()).first);
     43  return x;
    3844}
    3945
    40 double TOIInterpolator::getIValue(long sample) // can forget before sample
    41 {
    42   if (!canGet(sample)) return -9.e99;   // user should have checked before
     46bool TOIInterpolator::canGetValue(long sampleNum, TOI const& toi) {
     47  map<TOI, TOIProducer*> & inp = neededTOIs[toi];
     48  TOIProducer* prod  = (*inp.begin()).second;
     49  TOI const&   inTOI = (*inp.begin()).first;
    4350 
    44   deque<pair>::iterator i = hist.begin();
    45   while ((*i).t < sample) i++;
    46   double value;
    47   if ((*i).t == sample) {
    48     value = (*i).val;
    49   } else {   
    50     long samp2 = (*i).t;
    51     double val2 = (*i).val;
    52     i--;
    53     long samp1 = (*i).t;
    54     double val1 = (*i).val;
    55     value = val1 + (val2-val1)*(sample-samp1)/(samp2-samp1);
    56   }
    57   if (i != hist.begin()) {
    58     i--;
    59     hist.erase(hist.begin(), i);
    60   }
    61   return value;
    62 }
    63 
    64 bool TOIInterpolator::isNewValue(long sample)
    65 {
    66   deque<pair>::iterator i = hist.begin();
    67   while (i!=hist.end()) {
    68     if ((*i).t == sample) return true;
    69     if ((*i).t > sample) return false;
    70     i++;
    71   }
     51  if (prod->canGetValue(sampleNum, inTOI)) return true; // direct
     52  if (prod->canGetPrevValue(sampleNum, inTOI) &&
     53      prod->canGetNextValue(sampleNum, inTOI)) return true;
    7254  return false;
    7355}
    7456
    75 
    76 long TOIInterpolator::nextSample(long sampleMin)
    77 {
    78   for (deque<pair>::iterator i = hist.begin(); i<hist.end(); i++)
    79     if ((*i).t >= sampleMin) return (*i).t;
    80   return -1;
     57bool TOIInterpolator::canGetValueLater(long sampleNum, TOI const& toi) {
     58  map<TOI, TOIProducer*> & inp = neededTOIs[toi];
     59  TOIProducer* prod  = (*inp.begin()).second;
     60  TOI const&   inTOI = (*inp.begin()).first;
     61 
     62  if (prod->canGetValue(sampleNum, inTOI)) return false; // direct
     63  if (prod->canGetValueLater(sampleNum, inTOI)) return true; // direct
     64  if (!prod->canGetPrevValue(sampleNum, inTOI)) return false; // no hope
     65  if (prod->canGetNextValue(sampleNum, inTOI)) return false; // can get now
     66  return true;
    8167}
    8268
     69double TOIInterpolator::getValue(long sampleNum, TOI const& toi) {
     70  map<TOI, TOIProducer*> & inp = neededTOIs[toi];
     71  TOIProducer* prod  = (*inp.begin()).second;
     72  TOI const&   inTOI = (*inp.begin()).first;
     73
     74  if (prod->canGetValue(sampleNum, inTOI))
     75     return prod->getValue(sampleNum, inTOI); // direct
     76     
     77  long sn1 = sampleNum;
     78  double v1 = prod->getPrevValue(sn1, inTOI);
     79 
     80  long sn2 = sampleNum;
     81  double v2 = prod->getNextValue(sn2, inTOI);
     82
     83  if (sn1 == sn2) throw ArchExc("Inconsistence in interp, sn1==sn2");
     84
     85  return v1 + (v2-v1) * (sampleNum-sn1) / (sn2-sn1);
     86}
     87
     88
     89void TOIInterpolator::propagateLowBound(TOI const& toi, long sampleNum) {
     90  CHKPROD
     91  map<TOI, TOIProducer*> & inp = neededTOIs[toi];
     92  TOIProducer* prod  = (*inp.begin()).second;
     93  TOI const&   inTOI = (*inp.begin()).first;
     94  if (prod->canGetPrevValue(sampleNum,toi)) {
     95    prod->getPrevValue(sampleNum, toi);
     96    sampleNum--;
     97    prod->wontNeedEarlier(toi, this, sampleNum);
     98  }
     99}
     100
Note: See TracChangeset for help on using the changeset viewer.