| 1 | // toiboloproducer.cc
 | 
|---|
| 2 | // Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
 | 
|---|
| 3 | 
 | 
|---|
| 4 | #include "toiboloproducer.h"
 | 
|---|
| 5 | #include "archexc.h"
 | 
|---|
| 6 | #include "requesthandler.h"
 | 
|---|
| 7 | #include "polfitclip.h"
 | 
|---|
| 8 | 
 | 
|---|
| 9 | #define boloMuV "boloMuV"
 | 
|---|
| 10 | 
 | 
|---|
| 11 | 
 | 
|---|
| 12 | TOIBoloProducer::TOIBoloProducer() {
 | 
|---|
| 13 |   possibleTOIs.insert(TOI(boloMuV, TOI::all, "linfilt sqfilt total", "microVolts"));  
 | 
|---|
| 14 | }
 | 
|---|
| 15 | 
 | 
|---|
| 16 | // No option == linfilt
 | 
|---|
| 17 | 
 | 
|---|
| 18 | string TOIBoloProducer::getName() {
 | 
|---|
| 19 |   return("TOIBoloProducer 1.1");
 | 
|---|
| 20 | }
 | 
|---|
| 21 | 
 | 
|---|
| 22 | int TOIBoloProducer::filtHalfRange = 20;
 | 
|---|
| 23 | 
 | 
|---|
| 24 | 
 | 
|---|
| 25 | void TOIBoloProducer::dataFeed(TOIProducer* source, TOI const& toi, long sampleNum, double value) {
 | 
|---|
| 26 |  if (toi.name == "boloDACV") {
 | 
|---|
| 27 |     boloDacV[toi.index] = value;
 | 
|---|
| 28 |  }
 | 
|---|
| 29 | 
 | 
|---|
| 30 |  if (toi.name == "boloRawMuV") {
 | 
|---|
| 31 |   if (source->canGetValue(sampleNum-1, toi)) {
 | 
|---|
| 32 |     value = (value + source->getValue(sampleNum-1, toi))/2.;
 | 
|---|
| 33 |     
 | 
|---|
| 34 |     //TOI toi2 = toi;
 | 
|---|
| 35 |     //toi2.name = boloMuV;
 | 
|---|
| 36 | 
 | 
|---|
| 37 |     TOI toi2(boloMuV, toi.index, "sqfilt", toi.unit);
 | 
|---|
| 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 |     }
 | 
|---|
| 45 |   }
 | 
|---|
| 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);
 | 
|---|
| 64 |     toi2.options.insert("total"); toi2.findref();
 | 
|---|
| 65 |     if (isProducing(toi2)) {
 | 
|---|
| 66 |       computedValue(toi2, sampleNum - filtHalfRange, boloDacV[toi.index] - y);
 | 
|---|
| 67 |     }
 | 
|---|
| 68 |     TOI toi3(boloMuV, toi.index, "", toi.unit);
 | 
|---|
| 69 |     if (isProducing(toi3))
 | 
|---|
| 70 |       computedValue(toi3, sampleNum - filtHalfRange, y);
 | 
|---|
| 71 |     toi3.options.insert("total"); toi3.findref();
 | 
|---|
| 72 |     if (isProducing(toi3)) {
 | 
|---|
| 73 |       computedValue(toi3, sampleNum - filtHalfRange, boloDacV[toi.index] - y);
 | 
|---|
| 74 |     }
 | 
|---|
| 75 |   }
 | 
|---|
| 76 |  }
 | 
|---|
| 77 | }
 | 
|---|
| 78 | 
 | 
|---|
| 79 | set<TOI> TOIBoloProducer::reqTOIFor(TOI const& toi) {
 | 
|---|
| 80 |   set<TOI> t; 
 | 
|---|
| 81 |   if (toi.name == boloMuV) {
 | 
|---|
| 82 |     TOI toi2("boloRawMuV", toi.index);
 | 
|---|
| 83 |     t.insert(toi2);
 | 
|---|
| 84 |   } else {
 | 
|---|
| 85 |     throw ArchExc("Cannot produce "+toi.name);
 | 
|---|
| 86 |   }
 | 
|---|
| 87 |   if (toi.options.find("total") != toi.options.end()) {
 | 
|---|
| 88 |     TOI toi2("boloDACV", toi.index);
 | 
|---|
| 89 |     t.insert(toi2);
 | 
|---|
| 90 |   }
 | 
|---|
| 91 |   return t;
 | 
|---|
| 92 | }
 | 
|---|
| 93 | 
 | 
|---|
| 94 | 
 | 
|---|
| 95 | void TOIBoloProducer::propagateLowBound(TOI const& toi, long sampleNum) {
 | 
|---|
| 96 |   CHKPROD
 | 
|---|
| 97 |   map<TOI, TOIProducer*> & need = neededTOIs[toi];
 | 
|---|
| 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 | 
 | 
|---|