source: Sophya/trunk/Poubelle/archTOI.old/sststarfinder.cc@ 671

Last change on this file since 671 was 635, checked in by ansari, 26 years ago

warnings linux egcs, et struct Horloge

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