[534] | 1 | // sststarfinder.cc
|
---|
| 2 | // Eric Aubourg & Dominique Yvon CEA/DAPNIA/SPP octobre 1999
|
---|
| 3 |
|
---|
| 4 | #include "sststarfinder.h"
|
---|
| 5 | #include "pisteetoile.h"
|
---|
| 6 | #include "toimanager.h"
|
---|
| 7 | #include "archparam.h"
|
---|
| 8 |
|
---|
| 9 | ofstream SSTStarFinder::sstchass("SSTChassLogFile");
|
---|
| 10 | bool SSTStarFinder::sstchassinit=false;
|
---|
| 11 |
|
---|
| 12 | #define sstStarCount "sstStarCount"
|
---|
| 13 | #define sstStarZ "sstStarZ"
|
---|
| 14 | #define sstStarF "sstStarF"
|
---|
| 15 | #define sstStarSN "sstStarSN"
|
---|
| 16 | #define sstStarUTC "sstStarUTC"
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | SSTStarFinder::SSTStarFinder() {
|
---|
| 20 | lastFedSample = -1;
|
---|
| 21 | lastAnaSample = -1;
|
---|
| 22 | lastContSample = -1;
|
---|
| 23 | lastKeptSample = -1;
|
---|
| 24 |
|
---|
| 25 | findStarConstruct();
|
---|
| 26 |
|
---|
| 27 | TOIProducer* prod = TOIManager::findTOIProducer(TOI("sstDiode",0));
|
---|
| 28 | if (!prod) {
|
---|
| 29 | cerr << "SSTStarFinder : cannot find producer for sstDiode" << endl;
|
---|
| 30 | exit(-1);
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | sstprod = dynamic_cast<TOILLSSTProducer*>(prod);
|
---|
| 34 | if (!sstprod) {
|
---|
| 35 | cerr << "SSTStarFinder : producer for sstDiode is not a TOILLSSTProducer" << endl;
|
---|
| 36 | exit(-1);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | sstprod->registerProcessor(this);
|
---|
| 40 |
|
---|
| 41 | possibleTOIs.insert(TOI(sstStarCount, TOI::all, "", "integer"));
|
---|
| 42 | possibleTOIs.insert(TOI(sstStarZ, TOI::all, "", "integer"));
|
---|
| 43 | possibleTOIs.insert(TOI(sstStarF, TOI::all, "", "ADU"));
|
---|
| 44 | possibleTOIs.insert(TOI(sstStarSN, TOI::all, "", "samplenum"));
|
---|
| 45 | possibleTOIs.insert(TOI(sstStarUTC, TOI::all, "", "hours"));
|
---|
| 46 |
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | SSTStarFinder::~SSTStarFinder(){
|
---|
| 50 | findStarDestruct();
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | string SSTStarFinder::getName() {
|
---|
| 54 | return("SSTStarFinder 1.0");
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | void SSTStarFinder::addTOI(TOI& toi, TOIAbsorber* client) {
|
---|
| 58 | TOIProducer::addTOI(toi, client);
|
---|
| 59 | TOIManager::activateLLProducer(sstprod);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | void SSTStarFinder::Has2Bars(bool has, int eo)
|
---|
| 63 | {
|
---|
| 64 | has2bars = has;
|
---|
| 65 | elecOffset = eo;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | #ifdef SSTStatLog
|
---|
| 69 | static ofstream sststat("SSTStatLog");
|
---|
| 70 | static int compteurBlock=0;
|
---|
| 71 | static int nbStar=0;
|
---|
| 72 | #include "ssthardware.h"
|
---|
| 73 | #include "archparam.h"
|
---|
| 74 | #endif
|
---|
| 75 |
|
---|
| 76 | void SSTStarFinder::findStarConstruct() {
|
---|
| 77 | PisteBar=new PisteEtoile*[NbPhotDiodBarette];
|
---|
| 78 | for(int i=0; i<NbPhotDiodBarette; i++) PisteBar[i]=new PisteEtoile(i);
|
---|
| 79 | StarHistoryMap.clear();
|
---|
| 80 | if (!sstchassinit) {
|
---|
| 81 | sstchass<<SSTEtoile::printHeader()<<endl;
|
---|
| 82 | sstchassinit = true;
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | void SSTStarFinder::findStarDestruct() {
|
---|
| 87 | for(int i=0; i<NbPhotDiodBarette; i++) {
|
---|
| 88 | delete PisteBar[i];
|
---|
| 89 | }
|
---|
| 90 | delete[] PisteBar;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | void SSTStarFinder::dataFeed(long sampleNum, int* diodeSignal) {
|
---|
| 94 | if (producedTOIs.empty()) return;
|
---|
| 95 | if (sampleNum == lastFedSample+1) {
|
---|
| 96 | for(int i=0;i<NbPhotDiodBarette; i++) {
|
---|
| 97 | PisteBar[i]->push(diodeSignal+i,1);
|
---|
| 98 | }
|
---|
| 99 | lastFedSample++;
|
---|
| 100 | } else {
|
---|
| 101 | for(int i=0;i<NbPhotDiodBarette; i++) {
|
---|
| 102 | PisteBar[i]->fill(diodeSignal+i,sampleNum,1);
|
---|
| 103 | }
|
---|
| 104 | lastFedSample = lastContSample = sampleNum;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | if ((sampleNum >= lastAnaSample+8) && (sampleNum - lastContSample >= 40)) {
|
---|
| 108 | lastAnaSample = sampleNum;
|
---|
| 109 | if (lastKeptSample<0) lastKeptSample = sampleNum-8;
|
---|
| 110 | for(int i=0;i<NbPhotDiodBarette; i++) {
|
---|
| 111 | if (PisteBar[i]->traque()) { // On a trouve!
|
---|
| 112 | SSTEtoile star = PisteBar[i]->DonneEtoile();
|
---|
| 113 | StarHistoryMap[star.TEchan]=star;
|
---|
| 114 | gotStar(star);
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | void SSTStarFinder::registerProcessor(SSTStarProcessor* p) {
|
---|
| 121 | processors.push_back(p);
|
---|
| 122 | TOIManager::activateLLProducer(sstprod);
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | int SSTStarFinder::getNumbStar(int iSampl) {
|
---|
| 126 | StarHistIter IterLow=StarHistoryMap.lower_bound((double)iSampl);
|
---|
| 127 | StarHistIter IterHigh=StarHistoryMap.upper_bound((double)(iSampl+1.));
|
---|
| 128 | int Compteur=0;
|
---|
| 129 | while (!(IterLow==IterHigh)) {IterLow++; Compteur++;}
|
---|
| 130 | return Compteur;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | double SSTStarFinder::getStarF(int iSampl, int istar){
|
---|
| 134 | if( (getNumbStar(iSampl)==0)||(getNumbStar(iSampl)<=istar)) return -1;
|
---|
| 135 | else {
|
---|
| 136 | StarHistIter IterLow=StarHistoryMap.lower_bound((double)iSampl);
|
---|
| 137 | while(!(istar==0)) {
|
---|
| 138 | IterLow++;
|
---|
| 139 | istar--;
|
---|
| 140 | }
|
---|
| 141 | return (double) ((*IterLow).second).InpCurrent;
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 |
|
---|
| 146 | int SSTStarFinder::getStarZ(int iSampl, int istar) {
|
---|
| 147 | if( (getNumbStar(iSampl)==0)||(getNumbStar(iSampl)<=istar)) return -1;
|
---|
| 148 | StarHistIter IterLow=StarHistoryMap.lower_bound((double)iSampl);
|
---|
| 149 | while(!(istar==0)) {
|
---|
| 150 | IterLow++;
|
---|
| 151 | istar--;
|
---|
| 152 | }
|
---|
| 153 | return ((*IterLow).second).NoDiode;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | double SSTStarFinder::getStarTime(int iSampl, int istar) {
|
---|
| 157 | if( (getNumbStar(iSampl)==0)||(getNumbStar(iSampl)<=istar)) return -1;
|
---|
| 158 | StarHistIter IterLow=StarHistoryMap.lower_bound((double)iSampl);
|
---|
| 159 | while(!(istar==0)) {
|
---|
| 160 | IterLow++;
|
---|
| 161 | istar--;
|
---|
| 162 | }
|
---|
| 163 | return ((*IterLow).second).TEchan;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 |
|
---|
| 167 | void SSTStarFinder::gotStar(SSTEtoile const& star) {
|
---|
| 168 | for (vector<SSTStarProcessor*>::iterator i = processors.begin();
|
---|
| 169 | i != processors.end(); i++) {
|
---|
| 170 | (*i)->dataFeed(star);
|
---|
| 171 | }
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 |
|
---|
| 175 | // $CHECK$ we handle correctly only the first star
|
---|
| 176 | long SSTStarFinder::firstSampleNum(TOI const&) {
|
---|
| 177 | if (StarHistoryMap.empty()) return -1;
|
---|
| 178 | StarHistIter i = StarHistoryMap.begin();
|
---|
| 179 | return floor((*i).second.TEchan);
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | long SSTStarFinder::lastSampleNum(TOI const&) {
|
---|
| 183 | if (StarHistoryMap.empty()) return -1;
|
---|
| 184 | StarHistIter i = StarHistoryMap.end();
|
---|
| 185 | i--;
|
---|
| 186 | return floor((*i).second.TEchan);
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | bool SSTStarFinder::canGetValue(long sampleNum, TOI const& toi) {
|
---|
| 190 | if (sampleNum < lastKeptSample) return false;
|
---|
| 191 | if (sampleNum > lastAnaSample) return false;
|
---|
| 192 | if (toi.name == sstStarCount) return true;
|
---|
| 193 | if (getNumbStar(sampleNum) > toi.index) return true;
|
---|
| 194 | return false;
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | // $CHECK$ not done properly, complicated !!!
|
---|
| 198 | bool SSTStarFinder::canGetPrevValue(long sampleNum, TOI const& toi) {
|
---|
| 199 | return canGetValue(sampleNum-1, toi);
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | bool SSTStarFinder::canGetNextValue(long sampleNum, TOI const& toi) {
|
---|
| 203 | return canGetValue(sampleNum+1, toi);
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | bool SSTStarFinder::canGetValueLater(long sampleNum, TOI const&) {
|
---|
| 207 | return sampleNum > lastAnaSample;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | double SSTStarFinder::getPrevValue(long& sampleNum, TOI const& toi) {
|
---|
| 211 | return getValue(--sampleNum, toi);
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | double SSTStarFinder::getNextValue(long& sampleNum, TOI const& toi) {
|
---|
| 215 | return getValue(++sampleNum, toi);
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | double SSTStarFinder::getValue(long sampleNum, TOI const& toi) {
|
---|
| 219 | if (sampleNum < lastKeptSample) return -1;
|
---|
| 220 | if (sampleNum > lastAnaSample) return -1;
|
---|
| 221 | if (toi.name == sstStarCount) {
|
---|
| 222 | return getNumbStar(sampleNum);
|
---|
| 223 | }
|
---|
| 224 | if (toi.name == sstStarF) {
|
---|
| 225 | return getStarF(sampleNum, toi.index);
|
---|
| 226 | }
|
---|
| 227 | if (toi.name == sstStarZ) {
|
---|
| 228 | return getStarZ(sampleNum, toi.index);
|
---|
| 229 | }
|
---|
| 230 | if (toi.name == sstStarSN) {
|
---|
| 231 | return getStarTime(sampleNum, toi.index);
|
---|
| 232 | }
|
---|
| 233 | if (toi.name == sstStarUTC) {
|
---|
| 234 | return archParam.acq.SN2UTC(getStarTime(sampleNum, toi.index));
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | return -1;
|
---|
| 238 | }
|
---|
| 239 |
|
---|
| 240 | long SSTStarFinder::wontNeedEarlier(TOI const& toi, TOIAbsorber* client, long t) {
|
---|
| 241 | long oldT = lastNeededSample[toi.ref][client];
|
---|
| 242 | if (t<oldT) return -1;
|
---|
| 243 | lastNeededSample[toi.ref][client] = t;
|
---|
| 244 | map<TOIAbsorber*, long> m = lastNeededSample[toi.ref];
|
---|
| 245 | long min=999999999L;
|
---|
| 246 | for (map<TOIAbsorber*, long>::iterator i = m.begin(); i != m.end(); i++) {
|
---|
| 247 | if ((*i).second < min) min = (*i).second;
|
---|
| 248 | }
|
---|
| 249 | while(!StarHistoryMap.empty() && (*StarHistoryMap.begin()).first < min) StarHistoryMap.erase(StarHistoryMap.begin());
|
---|
| 250 | lastKeptSample=min;
|
---|
| 251 | return min;
|
---|
| 252 | }
|
---|