| [556] | 1 | // toirepeater.cc | 
|---|
|  | 2 | // Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999 | 
|---|
|  | 3 |  | 
|---|
|  | 4 |  | 
|---|
|  | 5 | #include "toirepeater.h" | 
|---|
|  | 6 | #include "toimanager.h" | 
|---|
|  | 7 | #include "archexc.h" | 
|---|
|  | 8 |  | 
|---|
|  | 9 | TOIRepeater::TOIRepeater() { | 
|---|
|  | 10 | } | 
|---|
|  | 11 |  | 
|---|
|  | 12 |  | 
|---|
|  | 13 | string TOIRepeater::getName() { | 
|---|
|  | 14 | return("TOIRepeater 1.0"); | 
|---|
|  | 15 | } | 
|---|
|  | 16 |  | 
|---|
|  | 17 | bool TOIRepeater::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 repet | 
|---|
|  | 23 | if (toi.options.find("repet") == toi.options.end()) return false; | 
|---|
|  | 24 |  | 
|---|
|  | 25 | // 3. Can get non interp | 
|---|
|  | 26 | TOI toi2 = toi; | 
|---|
|  | 27 | toi2.options.erase("repet"); | 
|---|
|  | 28 | TOIProducer* prod = TOIManager::findTOIProducer(toi2); | 
|---|
|  | 29 | set<string> opts = prod->getAvailOptions(toi2); | 
|---|
|  | 30 | if (opts.find("repet") != opts.end()) return false; // already handled | 
|---|
|  | 31 | if (opts.find("interp") != opts.end()) return false;  // not compatible ! | 
|---|
|  | 32 |  | 
|---|
|  | 33 | map<TOI, TOIProducer*> fullInputTOI; | 
|---|
|  | 34 | fullInputTOI[toi2] = prod; | 
|---|
|  | 35 | neededTOIs[toi] = fullInputTOI; | 
|---|
|  | 36 | return true; | 
|---|
|  | 37 | } | 
|---|
|  | 38 |  | 
|---|
|  | 39 | set<TOI> TOIRepeater::reqTOIFor(TOI const& toi) { | 
|---|
|  | 40 | set<TOI> x; | 
|---|
|  | 41 | if (!canProduce(toi)) return x; | 
|---|
|  | 42 | x.insert((*neededTOIs[toi].begin()).first); | 
|---|
|  | 43 | return x; | 
|---|
|  | 44 | } | 
|---|
|  | 45 |  | 
|---|
|  | 46 | bool TOIRepeater::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; | 
|---|
|  | 50 |  | 
|---|
|  | 51 | if (prod->canGetValue(sampleNum, inTOI)) return true; // direct | 
|---|
|  | 52 | if (prod->canGetPrevValue(sampleNum, inTOI)) return true; | 
|---|
|  | 53 | return false; | 
|---|
|  | 54 | } | 
|---|
|  | 55 |  | 
|---|
|  | 56 | bool TOIRepeater::canGetValueLater(long sampleNum, TOI const& toi) { | 
|---|
|  | 57 | map<TOI, TOIProducer*> & inp = neededTOIs[toi]; | 
|---|
|  | 58 | TOIProducer* prod  = (*inp.begin()).second; | 
|---|
|  | 59 | TOI const&   inTOI = (*inp.begin()).first; | 
|---|
|  | 60 |  | 
|---|
|  | 61 | if (prod->canGetValue(sampleNum, inTOI)) return false; // direct | 
|---|
|  | 62 | if (prod->canGetValueLater(sampleNum, inTOI)) return true; // direct | 
|---|
|  | 63 | //if (prod->canGetPrevValue(sampleNum, inTOI)) return false; // can get now | 
|---|
|  | 64 | return false; | 
|---|
|  | 65 | } | 
|---|
|  | 66 |  | 
|---|
|  | 67 | double TOIRepeater::getValue(long sampleNum, TOI const& toi) { | 
|---|
|  | 68 | map<TOI, TOIProducer*> & inp = neededTOIs[toi]; | 
|---|
|  | 69 | TOIProducer* prod  = (*inp.begin()).second; | 
|---|
|  | 70 | TOI const&   inTOI = (*inp.begin()).first; | 
|---|
|  | 71 |  | 
|---|
|  | 72 | if (prod->canGetValue(sampleNum, inTOI)) | 
|---|
|  | 73 | return prod->getValue(sampleNum, inTOI); // direct | 
|---|
|  | 74 |  | 
|---|
|  | 75 | long sn1 = sampleNum; | 
|---|
|  | 76 | double v1 = prod->getPrevValue(sn1, inTOI); | 
|---|
|  | 77 |  | 
|---|
|  | 78 | return v1; | 
|---|
|  | 79 | } | 
|---|
|  | 80 |  | 
|---|
|  | 81 |  | 
|---|
|  | 82 | void TOIRepeater::propagateLowBound(TOI const& toi, long sampleNum) { | 
|---|
|  | 83 | CHKPROD | 
|---|
|  | 84 | map<TOI, TOIProducer*> & inp = neededTOIs[toi]; | 
|---|
|  | 85 | TOIProducer* prod  = (*inp.begin()).second; | 
|---|
|  | 86 | TOI const&   inTOI = (*inp.begin()).first; | 
|---|
|  | 87 | if (prod->canGetPrevValue(sampleNum,toi)) { | 
|---|
|  | 88 | prod->getPrevValue(sampleNum, toi); | 
|---|
|  | 89 | sampleNum--; | 
|---|
|  | 90 | prod->wontNeedEarlier(toi, this, sampleNum); | 
|---|
|  | 91 | } | 
|---|
|  | 92 | } | 
|---|
|  | 93 |  | 
|---|