1 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
---|
2 | // Eric Aubourg
|
---|
3 | // Christophe Magneville
|
---|
4 | // Reza Ansari
|
---|
5 | // $Id: toiprocessor.cc,v 1.26 2002-09-09 15:33:15 aubourg Exp $
|
---|
6 |
|
---|
7 | #include "toiprocessor.h"
|
---|
8 | #include "toimanager.h"
|
---|
9 | #include <pthread.h>
|
---|
10 | #include <typeinfo> // ajout pour linux
|
---|
11 | #ifdef HAVE_VALUES_H
|
---|
12 | #include <values.h>
|
---|
13 | #endif
|
---|
14 |
|
---|
15 | #ifndef MAXINT
|
---|
16 | #define MAXINT 2147483647
|
---|
17 | #endif
|
---|
18 |
|
---|
19 | #ifdef HAVE_STDINT_H
|
---|
20 | #include <stdint.h>
|
---|
21 | #endif
|
---|
22 |
|
---|
23 | #ifdef WITH_SOPHYA
|
---|
24 | #include "pexceptions.h"
|
---|
25 | #else
|
---|
26 | #include "apexceptions.h"
|
---|
27 | #endif
|
---|
28 |
|
---|
29 | #define pthread_mutexattr_setkind_np pthread_mutexattr_settype
|
---|
30 |
|
---|
31 |
|
---|
32 | TOIProcessor::TOIProcessor() {
|
---|
33 | //cout << "TOIProcessor::TOIProcessor" << endl;
|
---|
34 | outTOIs = NULL;
|
---|
35 | inTOIs = NULL;
|
---|
36 | inited=false;
|
---|
37 |
|
---|
38 | upExtra = 0;
|
---|
39 | lowExtra = 0;
|
---|
40 | minOut = -1;
|
---|
41 | maxOut = -1;
|
---|
42 | forcedMinIn = -1;
|
---|
43 | forcedMaxIn = -1;
|
---|
44 | neededHistory = 1000;
|
---|
45 | lastAWN = 0;
|
---|
46 | wontNeedValue = -1;
|
---|
47 |
|
---|
48 |
|
---|
49 | // ajout vf 23/07/2002
|
---|
50 | cout << "Creating processor" << endl;
|
---|
51 | // Pour referencer un TOIProcessor, il faut recuperer le TOIManager correspondant
|
---|
52 | TOIManager::getManager()->registerProcessor(this);
|
---|
53 |
|
---|
54 | // initialisation des limites du sample (par defaut tout le fichier)
|
---|
55 | snBegin = 0;
|
---|
56 | snEnd = MAXINT;
|
---|
57 | snMin=MAXINT;
|
---|
58 | snMax=0;
|
---|
59 | // par defaut aucune condition
|
---|
60 | requestedSample = false;
|
---|
61 |
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 |
|
---|
66 | TOIProcessor::~TOIProcessor() {
|
---|
67 | delete[] outTOIs;
|
---|
68 | delete[] inTOIs;
|
---|
69 | //if (mutex)
|
---|
70 | pthread_mutex_destroy(&mutex);
|
---|
71 | //if (dataReady)
|
---|
72 | pthread_cond_destroy(&dataReady);
|
---|
73 | // Il ne faut apparemment pas appeler pthread_detach si on a fait join avant
|
---|
74 | // Extrait du man (Reza - Mai 2002)
|
---|
75 | //man: The pthread_join(3) routine also detaches the target thread after
|
---|
76 | //man: pthread_join(3) returns successfully.
|
---|
77 | // pthread_detach(thread); $CHECK$ - Reza Mai 2002
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 | void TOIProcessor::init() {
|
---|
82 | //cout << "TOIProcessor::init" << endl;
|
---|
83 | }
|
---|
84 |
|
---|
85 | void TOIProcessor::afterinit() {
|
---|
86 | int i;
|
---|
87 | inTOIs = new (TOI*[inIx.size()]);
|
---|
88 | for(i=0; i<inIx.size(); i++)
|
---|
89 | inTOIs[i] = NULL; // Protection-Initialisation - Reza 11/3/2001
|
---|
90 | outTOIs = new (TOI*[outIx.size()]);
|
---|
91 | for(i=0; i<outIx.size(); i++)
|
---|
92 | outTOIs[i] = NULL; // Protection-Initialisation - Reza 11/3/2001
|
---|
93 | }
|
---|
94 |
|
---|
95 | int TOIProcessor::getMinOut() {
|
---|
96 | /*
|
---|
97 | //cout << name << "minout" << endl;
|
---|
98 | if (minOut < 0) minOut = calcMinOut();
|
---|
99 | //cout << name << "minout=" << minOut << endl;
|
---|
100 | return minOut;
|
---|
101 | */
|
---|
102 | return snBegin + lowExtra;
|
---|
103 | }
|
---|
104 |
|
---|
105 | int TOIProcessor::getMaxOut() {
|
---|
106 | /*
|
---|
107 | //cout << name << "maxout" << endl;
|
---|
108 | if (maxOut < 0) maxOut = calcMaxOut();
|
---|
109 | //cout << name << "maxout=" << maxOut << endl;
|
---|
110 | return maxOut;
|
---|
111 | */
|
---|
112 | return snEnd - upExtra;
|
---|
113 | }
|
---|
114 |
|
---|
115 | int TOIProcessor::calcMinOut() {
|
---|
116 | return getMinIn() + lowExtra;
|
---|
117 | }
|
---|
118 |
|
---|
119 | int TOIProcessor::calcMaxOut() {
|
---|
120 | return getMaxIn() - upExtra;
|
---|
121 | }
|
---|
122 |
|
---|
123 | int TOIProcessor::getMinIn() {
|
---|
124 | /*
|
---|
125 | int nIn = inIx.size();
|
---|
126 | int minIn = 0;
|
---|
127 | for (int i=0; i<nIn; i++) {
|
---|
128 | TOI* toi = inTOIs[i];
|
---|
129 | if (toi == NULL) continue; // Protection - Reza 13/3/2001
|
---|
130 | int x = toi->getMinSn();
|
---|
131 | if (x > minIn) minIn = x;
|
---|
132 | }
|
---|
133 | if (forcedMinIn > 0 && forcedMinIn > minIn) minIn = forcedMinIn;
|
---|
134 | return minIn;
|
---|
135 | */
|
---|
136 | return snBegin;
|
---|
137 | }
|
---|
138 |
|
---|
139 | int TOIProcessor::getMaxIn() {
|
---|
140 | /*
|
---|
141 | int_4 nIn = inIx.size();
|
---|
142 | int_4 maxIn = MAXINT;
|
---|
143 | for (int i=0; i<nIn; i++) {
|
---|
144 | TOI* toi = inTOIs[i];
|
---|
145 | if (toi == NULL) continue; // Protection - Reza 13/3/2001
|
---|
146 | int_4 x = toi->getMaxSn();
|
---|
147 | if (x < maxIn) maxIn = x;
|
---|
148 | }
|
---|
149 | if (forcedMaxIn > 0 && forcedMaxIn < maxIn) maxIn = forcedMaxIn;
|
---|
150 | return maxIn;
|
---|
151 | */
|
---|
152 | return snEnd;
|
---|
153 | }
|
---|
154 |
|
---|
155 |
|
---|
156 | int TOIProcessor::declareInput(string toi) {
|
---|
157 | if (inIx.find(toi) != inIx.end())
|
---|
158 | throw DuplicateIdExc("TOIProcessor::declareInput : "+toi+" already declared");
|
---|
159 | int i = inIx.size();
|
---|
160 | inIx[toi] = i;
|
---|
161 | return i;
|
---|
162 | }
|
---|
163 |
|
---|
164 | int TOIProcessor::declareOutput(string toi) {
|
---|
165 | if (outIx.find(toi) != outIx.end())
|
---|
166 | throw DuplicateIdExc("TOIProcessor::declareInput : "+toi+" already declared");
|
---|
167 | int i = outIx.size();
|
---|
168 | outIx[toi] = i;
|
---|
169 | return i;
|
---|
170 | }
|
---|
171 |
|
---|
172 | int TOIProcessor::getInputTOIIndex(string toi) {
|
---|
173 | chkinit();
|
---|
174 | map<string, int>::iterator i = inIx.find(toi);
|
---|
175 | if (i == inIx.end()) return -1;
|
---|
176 | return (*i).second;
|
---|
177 | }
|
---|
178 |
|
---|
179 | int TOIProcessor::getOutputTOIIndex(string toi) {
|
---|
180 | chkinit();
|
---|
181 | map<string, int>::iterator i = outIx.find(toi);
|
---|
182 | if (i == outIx.end()) return -1;
|
---|
183 | return (*i).second;
|
---|
184 | }
|
---|
185 |
|
---|
186 | // Methodes rajoutees par Reza 11/3/2001
|
---|
187 | TOI* TOIProcessor::getInputTOI(int toiIndex) {
|
---|
188 | // chkinit();
|
---|
189 | if (toiIndex >= inIx.size())
|
---|
190 | throw RangeCheckError("TOIProcessor::getInputTOI() out of bound toiIndex");
|
---|
191 | TOI* toi = inTOIs[toiIndex];
|
---|
192 | if (toi == NULL)
|
---|
193 | throw NullPtrError("TOIProcessor::getInputTOI() - Not assigned TOI !");
|
---|
194 | return(toi);
|
---|
195 | }
|
---|
196 |
|
---|
197 | TOI* TOIProcessor::getOutputTOI(int toiIndex) {
|
---|
198 | // chkinit();
|
---|
199 | if (toiIndex >= outIx.size())
|
---|
200 | throw RangeCheckError("TOIProcessor::getOutputTOI() out of bound toiIndex");
|
---|
201 | TOI* toi = outTOIs[toiIndex];
|
---|
202 | // if (toi == NULL)
|
---|
203 | // throw NullPtrError("TOIProcessor::getOutputTOI() - Not assigned TOI !");
|
---|
204 | return(toi);
|
---|
205 | }
|
---|
206 |
|
---|
207 | bool TOIProcessor::checkInputTOIIndex(int toiIndex) {
|
---|
208 | if (toiIndex >= inIx.size()) return false;
|
---|
209 | if (inTOIs[toiIndex] == NULL) return false;
|
---|
210 | return true;
|
---|
211 | }
|
---|
212 |
|
---|
213 | bool TOIProcessor::checkOutputTOIIndex(int toiIndex) {
|
---|
214 | if (toiIndex >= outIx.size()) return false;
|
---|
215 | if (outTOIs[toiIndex] == NULL) return false;
|
---|
216 | return true;
|
---|
217 | }
|
---|
218 |
|
---|
219 | void TOIProcessor::PrintStatus(::ostream & os)
|
---|
220 | {
|
---|
221 | chkinit();
|
---|
222 | os << " TOIProcessor::PrintStatus() - Name= " << name
|
---|
223 | << " MinIn=" << getMinIn() << " MaxIn=" << getMaxIn() << endl;
|
---|
224 | os << " --- Inputs N= " << inIx.size() << endl;
|
---|
225 | int k;
|
---|
226 | for(k=0; k<inIx.size(); k++) {
|
---|
227 | os << "Input[" << k << "] : " << getInName(k) ;
|
---|
228 | if (inTOIs[k] != NULL)
|
---|
229 | os << " Connected TOI " << inTOIs[k]->getName() << endl;
|
---|
230 | else os << " NO TOI " << endl;
|
---|
231 | }
|
---|
232 | os << " --- Outputs N= " << outIx.size() << endl;
|
---|
233 | for(k=0; k<outIx.size(); k++) {
|
---|
234 | os << "Output[" << k << "] : " << getOutName(k) ;
|
---|
235 | if (outTOIs[k] != NULL)
|
---|
236 | os << " Connected TOI " << outTOIs[k]->getName() << endl;
|
---|
237 | else os << " NO TOI " << endl;
|
---|
238 | }
|
---|
239 | os << endl;
|
---|
240 | return;
|
---|
241 | }
|
---|
242 |
|
---|
243 | // Fin rajout Reza 11/3/2001
|
---|
244 |
|
---|
245 | void TOIProcessor::addInput(string name, TOI* toi) {
|
---|
246 | chkinit();
|
---|
247 | map<string, int>::iterator i = inIx.find(name);
|
---|
248 | if (i == inIx.end()) throw NotFoundExc("TOIProcessor::addInput "+
|
---|
249 | name+" not declared");
|
---|
250 | inTOIs[(*i).second] = toi;
|
---|
251 | toi->addConsumer(this); // $CHECK$ Reza 13/3/2001
|
---|
252 | }
|
---|
253 |
|
---|
254 | void TOIProcessor::addOutput(string name, TOI* toi) {
|
---|
255 | chkinit();
|
---|
256 | map<string, int>::iterator i = outIx.find(name);
|
---|
257 | if (i == outIx.end()) throw NotFoundExc("TOIProcessor::addOutput "+
|
---|
258 | name+" not declared");
|
---|
259 | toi->setProducer(this);
|
---|
260 | outTOIs[(*i).second] = toi;
|
---|
261 | }
|
---|
262 |
|
---|
263 | string TOIProcessor::getOutName(int i) {
|
---|
264 | if (i > outIx.size()) throw RangeCheckError("TOIProcessor::getOutName "
|
---|
265 | " out of bound");
|
---|
266 | map<string, int>::iterator j;
|
---|
267 | for(j=outIx.begin(); j!= outIx.end(); j++)
|
---|
268 | if ((*j).second == i) return (*j).first;
|
---|
269 |
|
---|
270 | throw RangeCheckError("TOIProcessor::getOutName Not found index !");
|
---|
271 | }
|
---|
272 |
|
---|
273 | string TOIProcessor::getInName(int i) {
|
---|
274 | if (i > inIx.size()) throw RangeCheckError("TOIProcessor::getInName "
|
---|
275 | " out of bound");
|
---|
276 | map<string, int>::iterator j;
|
---|
277 | for(j=inIx.begin(); j!= inIx.end(); j++)
|
---|
278 | if ((*j).second == i) return (*j).first;
|
---|
279 |
|
---|
280 | throw RangeCheckError("TOIProcessor::getOutName Not found index !");
|
---|
281 | }
|
---|
282 |
|
---|
283 | void TOIProcessor::run() {
|
---|
284 |
|
---|
285 | }
|
---|
286 |
|
---|
287 | void TOIProcessor::warnPutDone() {
|
---|
288 | int n = outIx.size();
|
---|
289 | for (int i=0; i<n; i++) {
|
---|
290 | TOI* toi = outTOIs[i];
|
---|
291 | if (toi) {
|
---|
292 | toi->putDone();
|
---|
293 | }
|
---|
294 | }
|
---|
295 | }
|
---|
296 |
|
---|
297 | void* TOIProcessor::ThreadStart(void* arg) {
|
---|
298 |
|
---|
299 | TOIProcessor* p = (TOIProcessor*) arg;
|
---|
300 | // cout << p->name << " new thread running " << pthread_self() << endl;
|
---|
301 | try {
|
---|
302 | p->run();
|
---|
303 | }
|
---|
304 | catch (PThrowable & exc) {
|
---|
305 | cerr << "\n TOIProcessor::ThreadStart() Catched Exception TOIProcessor@"
|
---|
306 | << hex << p << dec << "\n"
|
---|
307 | << (string)typeid(exc).name()
|
---|
308 | << " - Msg= " << exc.Msg() << endl;
|
---|
309 | }
|
---|
310 | catch (const std::exception & sex) {
|
---|
311 | cerr << "\n TOIProcessor::ThreadStart() Catched std::exception TOIProcessor@"
|
---|
312 | << hex << p << dec << "\n"
|
---|
313 | << (string)typeid(sex).name() << endl;
|
---|
314 | }
|
---|
315 | catch (...) {
|
---|
316 | cerr << "\n TOIProcessor::ThreadStart() Catched ... exception TOIProcessor@"
|
---|
317 | << hex << p << dec << endl;
|
---|
318 | }
|
---|
319 | p->warnPutDone();
|
---|
320 | pthread_exit(NULL);
|
---|
321 | // cout << p->name << " thread done " << pthread_self() << endl;
|
---|
322 | return NULL;
|
---|
323 | }
|
---|
324 |
|
---|
325 | #ifdef Linux
|
---|
326 | #define pthread_mutexattr_settype pthread_mutexattr_setkind_np
|
---|
327 | #define PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK_NP
|
---|
328 | #define pthread_mutex_setname_np(a,b,c)
|
---|
329 | #define pthread_cond_setname_np(a,b,c)
|
---|
330 | #endif
|
---|
331 |
|
---|
332 | void TOIProcessor::start() {
|
---|
333 | pthread_cond_init(&dataReady, NULL);
|
---|
334 | pthread_mutexattr_init(&mutattr);
|
---|
335 | // pthread_mutexattr_settype(&mutattr, PTHREAD_MUTEX_ERRORCHECK);
|
---|
336 | pthread_mutex_init(&mutex, &mutattr);
|
---|
337 | //pthread_mutex_setname_np(&mutex, (name + "_proc_mutex").c_str(), 0);
|
---|
338 | //pthread_cond_setname_np(&dataReady, (name + "_proc_cond").c_str(), 0);
|
---|
339 | //cout << name << " starting thread " << &thread << endl;
|
---|
340 | pthread_create(&thread, NULL, ThreadStart, this);
|
---|
341 | TOIManager::getManager()->addThread(&thread);
|
---|
342 | }
|
---|
343 |
|
---|
344 | #ifndef NO_SOPHYA
|
---|
345 | /* ---- l'interface va etre modifiee, NE PAS UTILISER
|
---|
346 | Array TOIProcessor::getData(int toiIndex, int iStart, int iEnd) {
|
---|
347 | TOI* toi = getInputTOI(toiIndex);
|
---|
348 | toi->waitForData(iStart, iEnd);
|
---|
349 | return toi->getData(iStart, iEnd);
|
---|
350 | }
|
---|
351 |
|
---|
352 | Array TOIProcessor::getError(int toiIndex, int iStart, int iEnd) {
|
---|
353 | TOI* toi = getInputTOI(toiIndex);
|
---|
354 | toi->waitForData(iStart, iEnd);
|
---|
355 | return toi->getError(iStart, iEnd);
|
---|
356 | }
|
---|
357 |
|
---|
358 | TArray<int_4> TOIProcessor::getFlag(int toiIndex, int iStart, int iEnd) {
|
---|
359 | TOI* toi = getInputTOI(toiIndex);
|
---|
360 | toi->waitForData(iStart, iEnd);
|
---|
361 | return toi->getFlag(iStart, iEnd);
|
---|
362 | }
|
---|
363 | l'interface va etre modifiee, NE PAS UTILISER ---- */
|
---|
364 | #endif
|
---|
365 |
|
---|
366 | double TOIProcessor::getData(int toiIndex, int i) {
|
---|
367 | TOI* toi = getInputTOI(toiIndex);
|
---|
368 | if (toi->needSyncOldWay()) toi->waitForData(i); // seulement pour autre que segmented
|
---|
369 | autoWontNeed(i);
|
---|
370 | return toi->getData(i);
|
---|
371 | }
|
---|
372 |
|
---|
373 | void TOIProcessor::getData(int toiIndex, int i, double &data, uint_8 &flag)
|
---|
374 | {
|
---|
375 | TOI* toi = getInputTOI(toiIndex);
|
---|
376 | if (toi->needSyncOldWay()) toi->waitForData(i); // seulement pour autre que segmented
|
---|
377 | toi->getData(i, data, flag);
|
---|
378 | autoWontNeed(i);
|
---|
379 | return;
|
---|
380 | }
|
---|
381 |
|
---|
382 | void TOIProcessor::getData(int toiIndex, int i, int n, double* d)
|
---|
383 | {
|
---|
384 | TOI* toi = getInputTOI(toiIndex);
|
---|
385 | if (toi->needSyncOldWay()) toi->waitForData(i+n); // seulement pour autre que segmented
|
---|
386 | toi->getData(i, n, d);
|
---|
387 | autoWontNeed(i);
|
---|
388 | return;
|
---|
389 | }
|
---|
390 |
|
---|
391 | void TOIProcessor::getData(int toiIndex, int i, int n, double* d, uint_8* f)
|
---|
392 | {
|
---|
393 | TOI* toi = getInputTOI(toiIndex);
|
---|
394 | if (toi->needSyncOldWay()) toi->waitForData(i+n); // seulement pour autre que segmented
|
---|
395 | toi->getData(i, n, d, f);
|
---|
396 | autoWontNeed(i);
|
---|
397 | return;
|
---|
398 | }
|
---|
399 |
|
---|
400 |
|
---|
401 | /*RZCMV
|
---|
402 | double TOIProcessor::getError(int toiIndex, int i) {
|
---|
403 | TOI* toi = getInputTOI(toiIndex);
|
---|
404 | toi->waitForData(i);
|
---|
405 | return toi->getError(i);
|
---|
406 | }
|
---|
407 |
|
---|
408 | int_4 TOIProcessor::getFlag(int toiIndex, int i) {
|
---|
409 | TOI* toi = getInputTOI(toiIndex);
|
---|
410 | toi->waitForData(i);
|
---|
411 | return toi->getFlag(i);
|
---|
412 | }
|
---|
413 | */
|
---|
414 |
|
---|
415 | void TOIProcessor::setNeededHistory(int nsamples) {
|
---|
416 | neededHistory = nsamples;
|
---|
417 | }
|
---|
418 |
|
---|
419 | void TOIProcessor::wontNeedBefore(int i) {
|
---|
420 | if (i<wontNeedValue) return;
|
---|
421 | wontNeedValue = i;
|
---|
422 | for (int j=0; j< (int) inIx.size(); j++) {
|
---|
423 | // $CHECK$ Reza 6/5/2001 Protection sur non connected TOI
|
---|
424 | if (inTOIs[j]) inTOIs[j]->wontNeedBefore(i);
|
---|
425 | }
|
---|
426 | }
|
---|
427 |
|
---|
428 | void TOIProcessor::autoWontNeed(int iCur) {
|
---|
429 | if (neededHistory <=0) return;
|
---|
430 | if (iCur < lastAWN + neededHistory/10) return;
|
---|
431 | lastAWN = iCur;
|
---|
432 | // cout << name << " wontNeedBefore " << iCur-neededHistory << endl;
|
---|
433 | wontNeedBefore(iCur-neededHistory);
|
---|
434 | }
|
---|
435 |
|
---|
436 | void TOIProcessor::notify() {
|
---|
437 | lock();
|
---|
438 | pthread_cond_broadcast(&dataReady);
|
---|
439 | unlock();
|
---|
440 | }
|
---|
441 |
|
---|
442 |
|
---|
443 | void TOIProcessor::putData(int toiIndex, int i, double value, uint_8 flg) {
|
---|
444 | TOI* toi = getOutputTOI(toiIndex);
|
---|
445 | if (toi == NULL) return;
|
---|
446 | toi->putData(i, value, flg);
|
---|
447 | // autoWontNeed(i); // now done on getData
|
---|
448 | if (toi->needSyncOldWay()) notify(); // seulement pour non segmented
|
---|
449 | }
|
---|
450 |
|
---|
451 | void TOIProcessor::putData(int toiIndex, int i, int n, double const* val,
|
---|
452 | uint_8 const* flg) {
|
---|
453 | TOI* toi = getOutputTOI(toiIndex);
|
---|
454 | if (toi == NULL) return;
|
---|
455 | toi->putData(i, n, val, flg);
|
---|
456 | if (toi->needSyncOldWay()) notify(); // seulement pour non segmented
|
---|
457 | }
|
---|
458 |
|
---|
459 | /*RZCMV
|
---|
460 | void TOIProcessor::putDataError(int toiIndex, int i, double value,
|
---|
461 | double error, int_4 flg) {
|
---|
462 | TOI* toi = getOutputTOI(toiIndex);
|
---|
463 | if (toi == NULL)
|
---|
464 | throw NullPtrError("TOIProcessor::putDataError() - Not assigned TOI !");
|
---|
465 | toi->putDataError(i, value, error, flg);
|
---|
466 | autoWontNeed(i);
|
---|
467 | notify();
|
---|
468 | }
|
---|
469 | */
|
---|
470 |
|
---|
471 |
|
---|
472 | // ajout vf 29/07/2002
|
---|
473 |
|
---|
474 | // parametrage de l'echantillon a produire (sans verification)
|
---|
475 | void TOIProcessor::setRequestedSample(long begin, long end) {
|
---|
476 | requestedSample = true;
|
---|
477 | snBegin = begin;
|
---|
478 | snEnd = end;
|
---|
479 | // snMin = snBegin;
|
---|
480 | // snMax = snEnd;
|
---|
481 | }
|
---|
482 |
|
---|
483 |
|
---|
484 | bool TOIProcessor::checkSampleLimits(int pass)
|
---|
485 | {
|
---|
486 | long minTmp=MAXINT;
|
---|
487 | long maxTmp=-1;
|
---|
488 |
|
---|
489 | return checkSampleLimits(minTmp, maxTmp, pass);
|
---|
490 |
|
---|
491 | cout << "toiprocessor : limites verifiees : " << snBegin << " , " << snEnd << " : " << endl;
|
---|
492 | }
|
---|
493 |
|
---|
494 |
|
---|
495 |
|
---|
496 |
|
---|
497 | bool TOIProcessor::checkSampleLimits(long& min, long& max, int pass)
|
---|
498 | {
|
---|
499 | bool sample_input_ok=true;
|
---|
500 | bool sample_ok=true;
|
---|
501 |
|
---|
502 | /* cout << "check " << pass << " " << name << " in " << min << " - " << max << " ; "
|
---|
503 | << snMin << " - " << snMax << " ; "
|
---|
504 | << snBegin << " - " << snEnd << endl;*/
|
---|
505 |
|
---|
506 | if (pass == 3) {
|
---|
507 | if (snMin < snMax) {
|
---|
508 | snBegin = snMin;
|
---|
509 | snEnd = snMax;
|
---|
510 | }
|
---|
511 | return true;
|
---|
512 | }
|
---|
513 |
|
---|
514 | // on verifie qu'on peut effectivement produire
|
---|
515 |
|
---|
516 | if (min < snBegin) {
|
---|
517 | min = snBegin;
|
---|
518 | }
|
---|
519 |
|
---|
520 | if (max > snEnd) {
|
---|
521 | max = snEnd;
|
---|
522 | }
|
---|
523 |
|
---|
524 | bool noConst = (min>max);
|
---|
525 |
|
---|
526 | if (pass == 2 && noConst) {
|
---|
527 | min = snBegin;
|
---|
528 | max = snEnd;
|
---|
529 | }
|
---|
530 |
|
---|
531 |
|
---|
532 | int n = inIx.size();
|
---|
533 | // parcours de toutes les entrees et mise a jour au plus restrictif
|
---|
534 | for (int i=0; i<n; i++) {
|
---|
535 | TOI* toi = inTOIs[i];
|
---|
536 | if (toi) {
|
---|
537 | // mise a jour des limites avec les marges si definies
|
---|
538 | long min_Input;
|
---|
539 | long max_Input;
|
---|
540 | if (min>0) {
|
---|
541 | min_Input = min - lowExtra;
|
---|
542 | } else {
|
---|
543 | min_Input = min;
|
---|
544 | }
|
---|
545 | if (max<MAXINT) {
|
---|
546 | max_Input = max + upExtra;
|
---|
547 | } else {
|
---|
548 | max_Input = max;
|
---|
549 | }
|
---|
550 | // propagation des limites
|
---|
551 | sample_input_ok = toi->checkSampleLimits(min_Input, max_Input, pass);
|
---|
552 |
|
---|
553 | //Ajustement des limites si plus restrictif
|
---|
554 | if (min < max) {
|
---|
555 | // On nous a demande des bornes ->
|
---|
556 | if ((min_Input + lowExtra) > min) {
|
---|
557 | min = min_Input + lowExtra;
|
---|
558 | }
|
---|
559 | if ((max_Input - upExtra) < max) {
|
---|
560 | max = max_Input - upExtra;
|
---|
561 | }
|
---|
562 | } else {
|
---|
563 | // On nous demande tout ce qu'on peut faire -> MAJ snBegin
|
---|
564 | if ((min_Input + lowExtra) > snBegin) {
|
---|
565 | snBegin = min_Input + lowExtra;
|
---|
566 | }
|
---|
567 | if ((max_Input - upExtra) < snEnd) {
|
---|
568 | snEnd = max_Input - upExtra;
|
---|
569 | }
|
---|
570 | }
|
---|
571 | if (sample_input_ok == false) {
|
---|
572 | sample_ok = false;
|
---|
573 | }
|
---|
574 | }
|
---|
575 | }
|
---|
576 |
|
---|
577 |
|
---|
578 |
|
---|
579 |
|
---|
580 | //Ajustement des limites si intervalle plus large
|
---|
581 | if (!noConst) {
|
---|
582 | if (min < snMin) {
|
---|
583 | snMin = min;
|
---|
584 | }
|
---|
585 | if (max > snMax) {
|
---|
586 | snMax = max;
|
---|
587 | }
|
---|
588 | }
|
---|
589 |
|
---|
590 | min=min<snMin?snMin:min;
|
---|
591 | max=max>snMax?snMax:max;
|
---|
592 |
|
---|
593 |
|
---|
594 | // cas sans contraintes, on retourne nos bornes
|
---|
595 | if (min>max) {
|
---|
596 | min = snBegin;
|
---|
597 | max = snEnd;
|
---|
598 | }
|
---|
599 |
|
---|
600 | /* cout << "check " << pass << " " << name << " out " << min << " - " << max << " ; "
|
---|
601 | << snMin << " - " << snMax << " ; "
|
---|
602 | << snBegin << " - " << snEnd << endl;*/
|
---|
603 | return sample_ok;
|
---|
604 | }
|
---|
605 |
|
---|
606 |
|
---|
607 |
|
---|
608 |
|
---|
609 | // pour verification si le processeur est parametre
|
---|
610 | bool TOIProcessor::getRequested()
|
---|
611 | {
|
---|
612 | return requestedSample;
|
---|
613 | }
|
---|
614 |
|
---|
615 | // affichage des limites
|
---|
616 | void TOIProcessor::printLimits()
|
---|
617 | {
|
---|
618 | cout << "toiprocessor " << name <<" : limites calculees : " << snBegin << " , " << snEnd << endl;
|
---|
619 | }
|
---|
620 |
|
---|
621 | TOI* TOIProcessor::getOutToi(string sortie)
|
---|
622 | {
|
---|
623 | // recherche du nom de la sortie et verification si le toi existe deja
|
---|
624 | map<string, int>::iterator i = outIx.find(sortie);
|
---|
625 | if (i == outIx.end()) {
|
---|
626 | return NULL;
|
---|
627 | } else {
|
---|
628 | return outTOIs[(*i).second];
|
---|
629 | }
|
---|
630 | }
|
---|
631 |
|
---|
632 |
|
---|
633 |
|
---|
634 |
|
---|
635 |
|
---|
636 |
|
---|
637 |
|
---|
638 |
|
---|
639 |
|
---|