| [350] | 1 | // toiinterpolator.cc | 
|---|
| [555] | 2 | // Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999 | 
|---|
| [350] | 3 |  | 
|---|
|  | 4 |  | 
|---|
| [315] | 5 | #include "toiinterpolator.h" | 
|---|
| [555] | 6 | #include "toimanager.h" | 
|---|
|  | 7 | #include "archexc.h" | 
|---|
| [315] | 8 |  | 
|---|
| [555] | 9 | TOIInterpolator::TOIInterpolator() { | 
|---|
| [315] | 10 | } | 
|---|
|  | 11 |  | 
|---|
| [555] | 12 |  | 
|---|
|  | 13 | string TOIInterpolator::getName() { | 
|---|
|  | 14 | return("TOIInterpolator 1.0"); | 
|---|
| [315] | 15 | } | 
|---|
|  | 16 |  | 
|---|
| [555] | 17 | bool 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; | 
|---|
| [315] | 37 | } | 
|---|
|  | 38 |  | 
|---|
| [555] | 39 | set<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; | 
|---|
| [315] | 44 | } | 
|---|
|  | 45 |  | 
|---|
| [555] | 46 | bool 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; | 
|---|
| [315] | 50 |  | 
|---|
| [555] | 51 | if (prod->canGetValue(sampleNum, inTOI)) return true; // direct | 
|---|
|  | 52 | if (prod->canGetPrevValue(sampleNum, inTOI) && | 
|---|
|  | 53 | prod->canGetNextValue(sampleNum, inTOI)) return true; | 
|---|
|  | 54 | return false; | 
|---|
| [315] | 55 | } | 
|---|
|  | 56 |  | 
|---|
| [555] | 57 | bool 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; | 
|---|
| [342] | 67 | } | 
|---|
|  | 68 |  | 
|---|
| [555] | 69 | double 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; | 
|---|
| [342] | 73 |  | 
|---|
| [555] | 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); | 
|---|
| [315] | 86 | } | 
|---|
|  | 87 |  | 
|---|
| [555] | 88 |  | 
|---|
|  | 89 | void 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 |  | 
|---|