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