1 | #include "array.h"
|
---|
2 | #include <math.h>
|
---|
3 | #include "genwproc.h"
|
---|
4 | #include "toimanager.h"
|
---|
5 | #include "pexceptions.h"
|
---|
6 | #include "ctimer.h"
|
---|
7 |
|
---|
8 | // -------------------------------------------------------------
|
---|
9 | // Class GenWindowTOIProcessor : generic processor with window
|
---|
10 | // -------------------------------------------------------------
|
---|
11 |
|
---|
12 | ////////////////////////////////////////////////////////////////
|
---|
13 | GenWindowTOIProcessor::GenWindowTOIProcessor(int nbinput,int nboutput
|
---|
14 | ,int wsz, int wstep, int wsztot)
|
---|
15 | {
|
---|
16 | if(nbinput<1) throw ParmError("GenWindowTOIProcessor::Creator nbinput<1 !");
|
---|
17 | if(nboutput<0) nboutput=0;
|
---|
18 | if(wsz<2) throw ParmError("GenWindowTOIProcessor::Creator wsz<2 !");
|
---|
19 | if(wsz%2==0) wsz++;
|
---|
20 | if(wstep<1) wstep=1;
|
---|
21 | if(wsztot<wsz) wsztot = 2*wsz;
|
---|
22 |
|
---|
23 | NbInput = nbinput;
|
---|
24 | NbOutput = nboutput;
|
---|
25 | WSize = wsz;
|
---|
26 | WStep = wstep;
|
---|
27 | WSizeTot = wsztot;
|
---|
28 |
|
---|
29 | SNdeb = SNend = StartSample = CurSnInd = -1;
|
---|
30 | TotNsCount = 0;
|
---|
31 |
|
---|
32 | TVector<r_8> vr8;
|
---|
33 | TVector<int_8> vi8;
|
---|
34 |
|
---|
35 | int k;
|
---|
36 | for(k=0;k<NbInput;k++) {
|
---|
37 | WDataIn.push_back(vr8);
|
---|
38 | WFlagIn.push_back(vi8);
|
---|
39 | WInFlg.push_back(false);
|
---|
40 | }
|
---|
41 | if(NbOutput) for(k=0;k<NbOutput;k++) {
|
---|
42 | WDataOut.push_back(vr8);
|
---|
43 | WFlagOut.push_back(vi8);
|
---|
44 | WOutFlg.push_back(false);
|
---|
45 | WPutOutFlg.push_back(false);
|
---|
46 | OutSample.push_back(0);
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | GenWindowTOIProcessor::~GenWindowTOIProcessor()
|
---|
51 | {
|
---|
52 | }
|
---|
53 |
|
---|
54 | ////////////////////////////////////////////////////////////////
|
---|
55 | void GenWindowTOIProcessor::PrintStatus(ostream & os)
|
---|
56 | {
|
---|
57 | os<<"\n ------------------------------------------------------ \n"
|
---|
58 | <<" GenWindowTOIProcessor::PrintStatus() - ["
|
---|
59 | <<NbInput<<","<<NbOutput<<"] (wtot="<<WSizeTot
|
---|
60 | <<" WindowSize="<<GetWSize()
|
---|
61 | <<" WStep= "<<GetWStep()<<endl;
|
---|
62 | TOIProcessor::PrintStatus(os);
|
---|
63 | os<<"ProcessedSampleCount="<<ProcessedSampleCount()<<endl;
|
---|
64 | os<<"------------------------------------------------------ "<<endl;
|
---|
65 | }
|
---|
66 |
|
---|
67 | ////////////////////////////////////////////////////////////////
|
---|
68 | TVector<r_8> GenWindowTOIProcessor::GetWData(int numtoi)
|
---|
69 | {
|
---|
70 | if(numtoi<0 || numtoi>=NbInput)
|
---|
71 | throw RangeCheckError("GenWindowTOIProcessor::GetWData : toi out of range !");
|
---|
72 | if(!WInFlg[numtoi])
|
---|
73 | throw RangeCheckError("GenWindowTOIProcessor::GetWData : toi not connected!");
|
---|
74 | return WDataIn[numtoi];
|
---|
75 | }
|
---|
76 |
|
---|
77 | TVector<int_8> GenWindowTOIProcessor::GetWFlag(int numtoi)
|
---|
78 | {
|
---|
79 | if(numtoi<0 || numtoi>=NbInput)
|
---|
80 | throw RangeCheckError("GenWindowTOIProcessor::GetWFlag : toi out of range !");
|
---|
81 | if(!WInFlg[numtoi])
|
---|
82 | throw RangeCheckError("GenWindowTOIProcessor::GetWFlag : toi not connected!");
|
---|
83 | return WFlagIn[numtoi];
|
---|
84 | }
|
---|
85 |
|
---|
86 | ////////////////////////////////////////////////////////////////
|
---|
87 | void GenWindowTOIProcessor::PutWData(int numtoi,int_8 numsample
|
---|
88 | ,TVector<r_8>& data,TVector<int_8>& flag)
|
---|
89 | {
|
---|
90 | if(numtoi<0 || numtoi>=NbOutput)
|
---|
91 | throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi out of range !");
|
---|
92 | if(!WOutFlg[numtoi])
|
---|
93 | throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi not connected!");
|
---|
94 | if(data.Size()!=flag.Size())
|
---|
95 | throw ParmError("GenWindowTOIProcessor::PutWFlag : data.Size()!=flag.Size()!");
|
---|
96 | WDataOut[numtoi].Share(data);
|
---|
97 | WFlagOut[numtoi].Share(flag);
|
---|
98 | OutSample[numtoi] = numsample;
|
---|
99 | WPutOutFlg[numtoi] = true;
|
---|
100 | }
|
---|
101 |
|
---|
102 | void GenWindowTOIProcessor::PutWData(int numtoi,int_8 numsample
|
---|
103 | ,r_8 data,int_8 flag)
|
---|
104 | {
|
---|
105 | if(numtoi<0 || numtoi>=NbOutput)
|
---|
106 | throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi out of range !");
|
---|
107 | if(!WOutFlg[numtoi])
|
---|
108 | throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi not connected!");
|
---|
109 | WDataOut[numtoi].Realloc(1,BaseArray::SameVectorType,true);
|
---|
110 | (WDataOut[numtoi])(0) = data;
|
---|
111 | WFlagOut[numtoi].Realloc(1,BaseArray::SameVectorType,true);
|
---|
112 | (WFlagOut[numtoi])(0) = flag;
|
---|
113 | OutSample[numtoi] = numsample;
|
---|
114 | WPutOutFlg[numtoi] = true;
|
---|
115 | }
|
---|
116 |
|
---|
117 | ////////////////////////////////////////////////////////////////
|
---|
118 | void GenWindowTOIProcessor::UserInit()
|
---|
119 | {
|
---|
120 | cout<<"GenWindowTOIProcessor::UserInit() Default implementation does nothing"<<endl;
|
---|
121 | }
|
---|
122 |
|
---|
123 | void GenWindowTOIProcessor::UserProc()
|
---|
124 | {
|
---|
125 | cout<<"GenWindowTOIProcessor:UserProc() Default implementation does nothing"<<endl;
|
---|
126 | }
|
---|
127 |
|
---|
128 | void GenWindowTOIProcessor::UserEnd()
|
---|
129 | {
|
---|
130 | cout<<"GenWindowTOIProcessor::UserEnd() Default implementation does nothing"<<endl;
|
---|
131 | }
|
---|
132 |
|
---|
133 | ////////////////////////////////////////////////////////////////
|
---|
134 | void GenWindowTOIProcessor::init()
|
---|
135 | {
|
---|
136 | cout << "GenWindowTOIProcessor::init" << endl;
|
---|
137 | char buff[64];
|
---|
138 | int k;
|
---|
139 | for(k=0; k<NbInput; k++) {
|
---|
140 | sprintf(buff,"in%d", k);
|
---|
141 | declareInput(buff);
|
---|
142 | }
|
---|
143 | for(k=0; k<NbOutput; k++) {
|
---|
144 | sprintf(buff,"out%d",k);
|
---|
145 | declareOutput(buff);
|
---|
146 | }
|
---|
147 | name = "GenWindowTOIProcessor";
|
---|
148 | // upExtra = 1; $CHECK a quoi ca sert EA?
|
---|
149 | }
|
---|
150 |
|
---|
151 | void GenWindowTOIProcessor::run()
|
---|
152 | {
|
---|
153 | // TOIManager* mgr = TOIManager::getManager();
|
---|
154 | int_8 SNdeb = getMinIn();
|
---|
155 | int_8 SNend = getMaxIn();
|
---|
156 | if(SNend-SNdeb<WSize)
|
---|
157 | throw RangeCheckError("GenWindowTOIProcessor::run : sne-snb<WSize !");
|
---|
158 |
|
---|
159 | // Allocation des tailles pour les vecteurs
|
---|
160 | int kc, nc=0;
|
---|
161 | for(kc=0;kc<NbInput;kc++) {
|
---|
162 | if( !(WInFlg[kc]=checkInputTOIIndex(kc)) ) continue;
|
---|
163 | WDataIn[kc].ReSize(WSizeTot);
|
---|
164 | WFlagIn[kc].ReSize(WSizeTot);
|
---|
165 | nc++;
|
---|
166 | }
|
---|
167 | if(nc==0) {
|
---|
168 | cerr<<" GenWindowTOIProcessor::run() - No input TOI connected!"<<endl;
|
---|
169 | throw ParmError("GenWindowTOIProcessor::run() No input TOI connected!");
|
---|
170 | }
|
---|
171 | for(kc=0;kc<NbOutput;kc++)
|
---|
172 | WOutFlg[kc] = checkOutputTOIIndex(kc);
|
---|
173 |
|
---|
174 | // Lecture des samples et remplissage des vecteurs
|
---|
175 | cout<<"GenWindowTOIProcessor::run() SNRange="<<SNdeb<<" - "<<SNend<<endl;
|
---|
176 | try {
|
---|
177 | Timer tm("GenWindowTOIProcessor::run()");
|
---|
178 | int_8 ki = -1;
|
---|
179 |
|
---|
180 | for(int_8 ks=SNdeb;ks<=SNend;ks++) {
|
---|
181 | Remplissage(ks);
|
---|
182 | TotNsCount++;
|
---|
183 | }
|
---|
184 | cout << " GenWindowTOIProcessor::run() - End of processing " << endl;
|
---|
185 |
|
---|
186 | } catch(PException & exc) {
|
---|
187 | cerr<<"GenWindowTOIProcessor: Catched Exception "<<(string)typeid(exc).name()
|
---|
188 | <<"\n .... Msg= "<<exc.Msg()<<endl;
|
---|
189 | }
|
---|
190 | }
|
---|
191 |
|
---|
192 | ////////////////////////////////////////////////////////////////
|
---|
193 | void GenWindowTOIProcessor::Remplissage(int_8 ks)
|
---|
194 | // INPUT:
|
---|
195 | // ks : numero du sample CENTRAL
|
---|
196 | // samples : sn-ws/2 sn sn+ws/2
|
---|
197 | // fenetre : 0 ws/2+1 ws-1
|
---|
198 | // ki : index des vecteurs a remplir.
|
---|
199 | // C'est l'index ou on veut remplir la donnee
|
---|
200 | // dans un vecteur (fictif) de taille WSize.
|
---|
201 | // La routine gere le decalage dans le grand buffer WSizeTot.
|
---|
202 | // Si ki depasse la taille maximale permise on decale, sinon on ne fait rien
|
---|
203 | // RETURN:
|
---|
204 | // numero du PROCHAIN index a remplir (ki+1 si pas decale !)
|
---|
205 | {
|
---|
206 | if(ks<SNdeb || ks>SNend)
|
---|
207 | throw RangeCheckError("GenWindowTOIProcessor::remplissage : ks<SNdeb || ks>SNend !");
|
---|
208 |
|
---|
209 | int_8 wsz2=WSize/2;
|
---|
210 |
|
---|
211 | StartSample = ks - wsz2; // peut etre < snb au debut
|
---|
212 |
|
---|
213 | // Premier remplissage ???? Gestion de la borne inferieure
|
---|
214 | if(CurSnInd<0) {
|
---|
215 | CurSnInd = 0;
|
---|
216 | for(int_8 k=ks-wsz2; k<=ks+wsz2; k++) { // Lecture TOI
|
---|
217 | for(int kc=0; kc<NbInput; kc++) {
|
---|
218 | if(!WInFlg[kc]) continue;
|
---|
219 | if(k>=SNdeb && k<=SNend) {
|
---|
220 | getData(kc,k,(WDataIn[kc])(CurSnInd), (WFlagIn[kc])(CurSnInd));
|
---|
221 | } else {
|
---|
222 | (WDataIn[kc])(CurSnInd) = (r_8) 0.;
|
---|
223 | (WFlagIn[kc])(CurSnInd) = (int_8) 0;
|
---|
224 | }
|
---|
225 | }
|
---|
226 | CurSnInd++;
|
---|
227 | }
|
---|
228 | return;
|
---|
229 | }
|
---|
230 |
|
---|
231 | // Faut-il decaler ????
|
---|
232 | if(CurSnInd == WSizeTot) { // On decale
|
---|
233 | for(int kc=0; kc<NbInput; kc++) {
|
---|
234 | if(!WInFlg[kc]) continue;
|
---|
235 | for(int_8 k=1;k<WSize;k++) { // un en moins car on va remplir apres
|
---|
236 | (WDataIn[kc])(k-1) = (WDataIn[kc])(WSizeTot-WSize+k);
|
---|
237 | (WFlagIn[kc])(k-1) = (WFlagIn[kc])(WSizeTot-WSize+k);
|
---|
238 | }
|
---|
239 | }
|
---|
240 | CurSnInd = WSize-1;
|
---|
241 | }
|
---|
242 |
|
---|
243 | // Remplissage de ks+wsz2 (dernier element de la fenetre pour ks central)
|
---|
244 | int_8 kse = ks+wsz2;
|
---|
245 | for(int kc=0; kc<NbInput; kc++) {
|
---|
246 | if(!WInFlg[kc]) continue;
|
---|
247 | if(kse>=SNdeb && kse<=SNend) {
|
---|
248 | getData(kc,kse,(WDataIn[kc])(CurSnInd),(WFlagIn[kc])(CurSnInd));
|
---|
249 | } else {
|
---|
250 | (WDataIn[kc])(CurSnInd) = (r_8) 0.;
|
---|
251 | (WFlagIn[kc])(CurSnInd) = (int_8) 0;
|
---|
252 | }
|
---|
253 | }
|
---|
254 | CurSnInd++;
|
---|
255 |
|
---|
256 | return;
|
---|
257 | }
|
---|