| [534] | 1 | // toiboloproducer.cc | 
|---|
|  | 2 | // Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999 | 
|---|
|  | 3 |  | 
|---|
|  | 4 | #include "toiboloproducer.h" | 
|---|
|  | 5 | #include "archexc.h" | 
|---|
|  | 6 | #include "requesthandler.h" | 
|---|
| [612] | 7 | #include "polfitclip.h" | 
|---|
| [534] | 8 |  | 
|---|
| [612] | 9 | #define boloMuV "boloMuV" | 
|---|
| [534] | 10 |  | 
|---|
|  | 11 |  | 
|---|
|  | 12 | TOIBoloProducer::TOIBoloProducer() { | 
|---|
| [634] | 13 | possibleTOIs.insert(TOI(boloMuV, TOI::all, "linfilt sqfilt total", "microVolts")); | 
|---|
| [534] | 14 | } | 
|---|
|  | 15 |  | 
|---|
| [612] | 16 | // No option == linfilt | 
|---|
|  | 17 |  | 
|---|
| [534] | 18 | string TOIBoloProducer::getName() { | 
|---|
| [612] | 19 | return("TOIBoloProducer 1.1"); | 
|---|
| [534] | 20 | } | 
|---|
|  | 21 |  | 
|---|
| [612] | 22 | int TOIBoloProducer::filtHalfRange = 20; | 
|---|
| [534] | 23 |  | 
|---|
| [612] | 24 |  | 
|---|
| [534] | 25 | void TOIBoloProducer::dataFeed(TOIProducer* source, TOI const& toi, long sampleNum, double value) { | 
|---|
| [634] | 26 | if (toi.name == "boloDACV") { | 
|---|
|  | 27 | boloDacV[toi.index] = value; | 
|---|
|  | 28 | } | 
|---|
|  | 29 |  | 
|---|
|  | 30 | if (toi.name == "boloRawMuV") { | 
|---|
| [534] | 31 | if (source->canGetValue(sampleNum-1, toi)) { | 
|---|
|  | 32 | value = (value + source->getValue(sampleNum-1, toi))/2.; | 
|---|
| [612] | 33 |  | 
|---|
|  | 34 | //TOI toi2 = toi; | 
|---|
|  | 35 | //toi2.name = boloMuV; | 
|---|
|  | 36 |  | 
|---|
|  | 37 | TOI toi2(boloMuV, toi.index, "sqfilt", toi.unit); | 
|---|
| [634] | 38 | if (isProducing(toi2)) | 
|---|
|  | 39 | computedValue(toi2, sampleNum, value); | 
|---|
|  | 40 |  | 
|---|
|  | 41 | toi2.options.insert("total"); toi2.findref(); | 
|---|
|  | 42 | if (isProducing(toi2)) { | 
|---|
|  | 43 | computedValue(toi2, sampleNum, boloDacV[toi.index] - value); | 
|---|
|  | 44 | } | 
|---|
| [534] | 45 | } | 
|---|
| [612] | 46 |  | 
|---|
|  | 47 | // $CHECK$ possible optimization : keep fit for several successive values | 
|---|
|  | 48 |  | 
|---|
|  | 49 | if (source->canGetValue(sampleNum-2*filtHalfRange, toi)) { | 
|---|
|  | 50 | PolFitClip fit(2*filtHalfRange,1); | 
|---|
|  | 51 | int s = sampleNum % 2 ? 1 : -1; | 
|---|
|  | 52 | for (int i=0; i<2*filtHalfRange-1; i++) { | 
|---|
|  | 53 | fit.addData(sampleNum - i, | 
|---|
|  | 54 | s*(source->getValue(sampleNum - i, toi) -  source->getValue(sampleNum - i -1, toi))/2); | 
|---|
|  | 55 | s = -s; | 
|---|
|  | 56 | } | 
|---|
|  | 57 | fit.doFit(); | 
|---|
|  | 58 | double y = source->getValue(sampleNum - filtHalfRange, toi); | 
|---|
|  | 59 | s = sampleNum % 2 ? 1 : -1; | 
|---|
|  | 60 | y =y - s*fit.value(sampleNum - filtHalfRange); | 
|---|
|  | 61 | TOI toi2(boloMuV, toi.index, "linfilt", toi.unit); | 
|---|
|  | 62 | if (isProducing(toi2)) | 
|---|
|  | 63 | computedValue(toi2, sampleNum - filtHalfRange, y); | 
|---|
| [634] | 64 | toi2.options.insert("total"); toi2.findref(); | 
|---|
|  | 65 | if (isProducing(toi2)) { | 
|---|
|  | 66 | computedValue(toi2, sampleNum - filtHalfRange, boloDacV[toi.index] - y); | 
|---|
|  | 67 | } | 
|---|
| [612] | 68 | TOI toi3(boloMuV, toi.index, "", toi.unit); | 
|---|
|  | 69 | if (isProducing(toi3)) | 
|---|
|  | 70 | computedValue(toi3, sampleNum - filtHalfRange, y); | 
|---|
| [675] | 71 | toi3.options.insert("total"); toi3.findref(); | 
|---|
| [634] | 72 | if (isProducing(toi3)) { | 
|---|
|  | 73 | computedValue(toi3, sampleNum - filtHalfRange, boloDacV[toi.index] - y); | 
|---|
|  | 74 | } | 
|---|
| [612] | 75 | } | 
|---|
| [634] | 76 | } | 
|---|
| [534] | 77 | } | 
|---|
|  | 78 |  | 
|---|
|  | 79 | set<TOI> TOIBoloProducer::reqTOIFor(TOI const& toi) { | 
|---|
|  | 80 | set<TOI> t; | 
|---|
| [612] | 81 | if (toi.name == boloMuV) { | 
|---|
|  | 82 | TOI toi2("boloRawMuV", toi.index); | 
|---|
| [534] | 83 | t.insert(toi2); | 
|---|
|  | 84 | } else { | 
|---|
|  | 85 | throw ArchExc("Cannot produce "+toi.name); | 
|---|
|  | 86 | } | 
|---|
| [634] | 87 | if (toi.options.find("total") != toi.options.end()) { | 
|---|
|  | 88 | TOI toi2("boloDACV", toi.index); | 
|---|
|  | 89 | t.insert(toi2); | 
|---|
|  | 90 | } | 
|---|
| [534] | 91 | return t; | 
|---|
|  | 92 | } | 
|---|
|  | 93 |  | 
|---|
|  | 94 |  | 
|---|
|  | 95 | void TOIBoloProducer::propagateLowBound(TOI const& toi, long sampleNum) { | 
|---|
|  | 96 | CHKPROD | 
|---|
| [555] | 97 | map<TOI, TOIProducer*> & need = neededTOIs[toi]; | 
|---|
| [534] | 98 | int hlen = 1; | 
|---|
|  | 99 | for (map<TOI, TOIProducer*>::iterator i = need.begin(); i != need.end(); i++) { | 
|---|
|  | 100 | (*i).second->wontNeedEarlier((*i).first, this, sampleNum-hlen); | 
|---|
|  | 101 | } | 
|---|
|  | 102 | } | 
|---|
|  | 103 |  | 
|---|
|  | 104 |  | 
|---|
|  | 105 |  | 
|---|