source: Sophya/trunk/ArchTOIPipe/ProcWSophya/genwproc.cc@ 1496

Last change on this file since 1496 was 1496, checked in by ansari, 24 years ago

2eme version de genwproc + programme de test rz+cmv 16/5/2001

File size: 10.6 KB
Line 
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// #define DEBUGGENW 1
10
11// -------------------------------------------------------------
12// Class GenWindowTOIProcessor : generic processor with window
13// -------------------------------------------------------------
14
15////////////////////////////////////////////////////////////////
16GenWindowTOIProcessor::GenWindowTOIProcessor(int nbinput,int nboutput
17 ,int wsz, int wstep, int wsztot)
18{
19 if(nbinput<1) throw ParmError("GenWindowTOIProcessor::Creator nbinput<1 !");
20 if(nboutput<0) nboutput=0;
21 if(wsz<2) throw ParmError("GenWindowTOIProcessor::Creator wsz<2 !");
22 if(wsz%2==0) wsz++;
23 if(wstep<1) wstep=1;
24 if(wsztot<wsz) wsztot = 2*wsz; // CMV prise de decision wsztot / wstep
25
26 NbInput = nbinput;
27 NbOutput = nboutput;
28 WSize = wsz;
29 WStep = wstep;
30 WSizeTot = wsztot;
31
32 SNdeb = SNend = StartSample = CurWtIndex = -1;
33 TotNsCount = 0;
34
35 SetDefaultValue();
36
37 TVector<r_8> vr8(1); // CMV+RZ supprimer taille(1) apres correction de
38 TVector<int_8> vi8(1); // constructeur copie de TArray (taille nulle)
39
40 int k;
41 for(k=0;k<NbInput;k++) {
42 WDataIn.push_back(vr8);
43 WFlagIn.push_back(vi8);
44 WInFlg.push_back(false);
45 }
46 if(NbOutput) for(k=0;k<NbOutput;k++) {
47 WDataOut.push_back(vr8);
48 WFlagOut.push_back(vi8);
49 WOutFlg.push_back(false);
50 WPutOutFlg.push_back(false);
51 WPutOutOwnVector.push_back(false);
52 OutSample.push_back(0);
53 }
54}
55
56GenWindowTOIProcessor::~GenWindowTOIProcessor()
57{
58}
59
60////////////////////////////////////////////////////////////////
61void GenWindowTOIProcessor::PrintStatus(ostream & os)
62{
63 os<<"\n ------------------------------------------------------ \n"
64 <<" GenWindowTOIProcessor::PrintStatus() - ["
65 <<NbInput<<","<<NbOutput<<"] (wtot="<<WSizeTot
66 <<" WindowSize="<<GetWSize()
67 <<" WStep= "<<GetWStep()<<endl;
68 TOIProcessor::PrintStatus(os);
69 os<<"ProcessedSampleCount="<<ProcessedSampleCount()<<endl;
70 os<<"------------------------------------------------------ "<<endl;
71}
72
73////////////////////////////////////////////////////////////////
74TVector<r_8> GenWindowTOIProcessor::GetWData(int numtoi)
75{
76 if(numtoi<0 || numtoi>=NbInput)
77 throw RangeCheckError("GenWindowTOIProcessor::GetWData : toi out of range !");
78 if(!WInFlg[numtoi])
79 throw ParmError("GenWindowTOIProcessor::GetWData : toi not connected!");
80 return (WDataIn[numtoi])(Range(StartWtIndex(),0,WSize));
81}
82
83TVector<int_8> GenWindowTOIProcessor::GetWFlag(int numtoi)
84{
85 if(numtoi<0 || numtoi>=NbInput)
86 throw RangeCheckError("GenWindowTOIProcessor::GetWFlag : toi out of range !");
87 if(!WInFlg[numtoi])
88 throw ParmError("GenWindowTOIProcessor::GetWFlag : toi not connected!");
89 return (WFlagIn[numtoi])(Range(StartWtIndex(),0,WSize));
90}
91
92r_8 * GenWindowTOIProcessor::GetWDataPointer(int numtoi)
93{
94 if(numtoi<0 || numtoi>=NbInput)
95 throw RangeCheckError("GenWindowTOIProcessor::GetWDataPointer : toi out of range !");
96 if(!WInFlg[numtoi])
97 throw ParmError("GenWindowTOIProcessor::GetWDataPointer : toi not connected!");
98 return (WDataIn[numtoi].Data()+StartWtIndex());
99
100}
101
102int_8 * GenWindowTOIProcessor::GetWFlagPointer(int numtoi)
103{
104 if(numtoi<0 || numtoi>=NbInput)
105 throw RangeCheckError("GenWindowTOIProcessor::GetWFlagPointer : toi out of range !");
106 if(!WInFlg[numtoi])
107 throw ParmError("GenWindowTOIProcessor::GetWFlagPointer : toi not connected!");
108 return (WFlagIn[numtoi].Data()+StartWtIndex());
109}
110
111void GenWindowTOIProcessor::GetData(int numtoi, int_8 numsample, r_8 & data, int_8 & flag)
112{
113 if(numtoi<0 || numtoi>=NbInput)
114 throw RangeCheckError("GenWindowTOIProcessor::GetData : toi out of range !");
115 if(!WInFlg[numtoi])
116 throw ParmError("GenWindowTOIProcessor::GetData : toi not connected!");
117 int_8 k = numsample-GetStartSample();
118 if ((k<0) || (k >= GetWSize()))
119 throw RangeCheckError("GenWindowTOIProcessor::GetData : numsample out of window!");
120 k += StartWtIndex();
121 data = (WDataIn[numtoi])(k);
122 flag = (WFlagIn[numtoi])(k);
123}
124
125////////////////////////////////////////////////////////////////
126void GenWindowTOIProcessor::PutWData(int numtoi,int_8 numsample
127 ,TVector<r_8>& data,TVector<int_8>& flag)
128{
129 if(numtoi<0 || numtoi>=NbOutput)
130 throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi out of range !");
131 if(!WOutFlg[numtoi])
132 throw ParmError("GenWindowTOIProcessor::PutWFlag : toi not connected!");
133 if(data.Size()!=flag.Size())
134 throw ParmError("GenWindowTOIProcessor::PutWFlag : data.Size()!=flag.Size()!");
135 if(data.Size() == 0)
136 throw ParmError("GenWindowTOIProcessor::PutWFlag : data.Size()==0 !");
137 WDataOut[numtoi].Share(data);
138 WFlagOut[numtoi].Share(flag);
139 OutSample[numtoi] = numsample;
140 WPutOutFlg[numtoi] = true;
141 WPutOutOwnVector[numtoi] = false;
142}
143
144void GenWindowTOIProcessor::PutWData(int numtoi,int_8 numsample
145 ,r_8 data,int_8 flag)
146{
147 if(numtoi<0 || numtoi>=NbOutput)
148 throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi out of range !");
149 if(!WOutFlg[numtoi])
150 throw ParmError("GenWindowTOIProcessor::PutWFlag : toi not connected!");
151 if (!WPutOutOwnVector[numtoi]) {
152 WDataOut[numtoi].Realloc(1,BaseArray::SameVectorType,true);
153 WFlagOut[numtoi].Realloc(1,BaseArray::SameVectorType,true);
154 WPutOutOwnVector[numtoi] = true;
155 }
156 (WDataOut[numtoi])(0) = data;
157 (WFlagOut[numtoi])(0) = flag;
158 OutSample[numtoi] = numsample;
159 WPutOutFlg[numtoi] = true;
160}
161
162////////////////////////////////////////////////////////////////
163void GenWindowTOIProcessor::UserInit(int_8 kstart)
164{
165 cout<<"GenWindowTOIProcessor::UserInit() Default implementation does nothing"<<endl;
166}
167
168void GenWindowTOIProcessor::UserProc(int_8 ks)
169{
170 cout<<"GenWindowTOIProcessor:UserProc() Default implementation does nothing"<<endl;
171}
172
173void GenWindowTOIProcessor::UserEnd(int_8 kend)
174{
175 cout<<"GenWindowTOIProcessor::UserEnd() Default implementation does nothing"<<endl;
176}
177
178////////////////////////////////////////////////////////////////
179void GenWindowTOIProcessor::init()
180{
181 cout << "GenWindowTOIProcessor::init" << endl;
182 char buff[64];
183 int k;
184 for(k=0; k<NbInput; k++) {
185 sprintf(buff,"in%d", k);
186 declareInput(buff);
187 }
188 for(k=0; k<NbOutput; k++) {
189 sprintf(buff,"out%d",k);
190 declareOutput(buff);
191 }
192 name = "GenWindowTOIProcessor";
193 // upExtra = 1; $CHECK a quoi ca sert EA?
194}
195
196void GenWindowTOIProcessor::run()
197{
198 // TOIManager* mgr = TOIManager::getManager();
199 SNdeb = getMinIn();
200 SNend = getMaxIn();
201 if(SNend-SNdeb<WSize)
202 throw ParmError("GenWindowTOIProcessor::run : sne-snb<WSize !");
203
204 // Allocation des tailles pour les vecteurs
205 int kc, nc=0;
206 for(kc=0;kc<NbInput;kc++) {
207 if( !(WInFlg[kc]=checkInputTOIIndex(kc)) ) continue;
208 WDataIn[kc].ReSize(WSizeTot);
209 WFlagIn[kc].ReSize(WSizeTot);
210 nc++;
211 }
212 if(nc==0) {
213 cerr<<" GenWindowTOIProcessor::run() - No input TOI connected!"<<endl;
214 throw ParmError("GenWindowTOIProcessor::run() No input TOI connected!");
215 }
216 for(kc=0;kc<NbOutput;kc++) WOutFlg[kc] = checkOutputTOIIndex(kc);
217
218 // Lecture des samples et remplissage des vecteurs
219 cout<<"GenWindowTOIProcessor::run() SNRange="<<SNdeb<<" - "<<SNend<<endl;
220 try {
221 Timer tm("GenWindowTOIProcessor::run()");
222 for(int_8 ks=SNdeb;ks<=SNend;ks++) { // CMV gerer le += step
223 Remplissage(ks);
224 if (ks == SNdeb) {
225 UserInit(ks);
226 Ecriture();
227 }
228 if ((ks-SNdeb)%WStep == 0) {
229 UserProc(ks);
230 // Il faut traiter les ecritures en sortie
231 Ecriture();
232 }
233 TotNsCount++;
234 }
235 UserEnd(SNend);
236 Ecriture();
237 cout << " GenWindowTOIProcessor::run() - End of processing " << endl;
238
239 } catch(PException & exc) {
240 cerr<<"GenWindowTOIProcessor::run Catched Exception "<<(string)typeid(exc).name()
241 <<"\n .... Msg= "<<exc.Msg()<<endl;
242 }
243}
244
245////////////////////////////////////////////////////////////////
246void GenWindowTOIProcessor::Remplissage(int_8 ks)
247// INPUT:
248// ks : numero du sample CENTRAL
249// samples : sn-ws/2 sn sn+ws/2
250// fenetre : 0 ws/2+1 ws-1
251{
252#ifdef DEBUGGENW
253 cout << "GenWindowTOIProcessor::Remplissage(" << ks << ") CurWtIndex=" << CurWtIndex << endl;
254#endif
255
256if(ks<SNdeb || ks>SNend) {
257 cerr << "GenWindowTOIProcessor::remplissage/Erreur : ks(=" << ks << ") <"
258 << SNdeb << " || ks>" << SNend << endl;
259 throw RangeCheckError("GenWindowTOIProcessor::remplissage : ks<SNdeb || ks>SNend !");
260 }
261int_8 wsz2=WSize/2;
262
263StartSample = ks - wsz2; // peut etre < snb au debut
264
265// Premier remplissage ???? Gestion de la borne inferieure
266if(CurWtIndex<0) {
267#ifdef DEBUGGENW
268 cout << "GenWindowTOIProcessor::Remplissage 1ere fois" << endl;
269#endif
270 CurWtIndex = 0;
271 for(int_8 k=ks-wsz2; k<=ks+wsz2; k++) { // Lecture TOI
272 for(int kc=0; kc<NbInput; kc++) {
273 if(!WInFlg[kc]) continue;
274 if(k>=SNdeb && k<=SNend) {
275 getData(kc,k,(WDataIn[kc])(CurWtIndex), (WFlagIn[kc])(CurWtIndex));
276 } else {
277 (WDataIn[kc])(CurWtIndex) = R8DefVal;
278 (WFlagIn[kc])(CurWtIndex) = I8DefVal;
279 }
280 }
281 CurWtIndex++;
282 }
283 return;
284}
285
286// CMV gere decalage seulement si step < wsize sinon copie.
287// Faut-il decaler ????
288if(CurWtIndex == WSizeTot) { // On decale
289#ifdef DEBUGGENW
290 cout << "GenWindowTOIProcessor::Remplissage Decalage " << endl;
291#endif
292 for(int kc=0; kc<NbInput; kc++) {
293 if(!WInFlg[kc]) continue;
294 for(int_8 k=1;k<WSize;k++) { // un en moins car on va remplir apres
295 (WDataIn[kc])(k-1) = (WDataIn[kc])(WSizeTot-WSize+k);
296 (WFlagIn[kc])(k-1) = (WFlagIn[kc])(WSizeTot-WSize+k);
297 }
298 }
299 CurWtIndex = WSize-1;
300}
301
302// Remplissage de ks+wsz2 (dernier element de la fenetre pour ks central)
303int_8 kse = ks+wsz2;
304#ifdef DEBUGGENW
305 cout << "GenWindowTOIProcessor::Normal fill " << endl;
306#endif
307for(int kc=0; kc<NbInput; kc++) {
308 if(!WInFlg[kc]) continue;
309 if(kse>=SNdeb && kse<=SNend) {
310 getData(kc,kse,(WDataIn[kc])(CurWtIndex),(WFlagIn[kc])(CurWtIndex));
311 } else {
312 (WDataIn[kc])(CurWtIndex) = R8DefVal;
313 (WFlagIn[kc])(CurWtIndex) = I8DefVal;
314 }
315}
316CurWtIndex++;
317
318return;
319}
320
321void GenWindowTOIProcessor::Ecriture()
322{
323 int_8 maxlenout = 0;
324 int kc;
325 for(kc=0; kc<NbOutput; kc++)
326 if(WOutFlg[kc] && WPutOutFlg[kc] && (WDataOut[kc].Size() > maxlenout) )
327 maxlenout = WDataOut[kc].Size();
328
329 for(int_8 k=0; k<maxlenout; k++) {
330 for(int kc=0; kc<NbOutput; kc++) {
331 if(!WOutFlg[kc]) continue;
332 if(!WPutOutFlg[kc]) continue;
333 if(k>=WDataOut[kc].Size()) continue;
334 putData(kc, k+OutSample[kc], (WDataOut[kc])(k), (WFlagOut[kc])(k));
335 }
336 }
337 for(kc=0; kc<NbOutput; kc++) WPutOutFlg[kc] = false;
338}
Note: See TracBrowser for help on using the repository browser.