[1738] | 1 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
---|
| 2 | // Eric Aubourg
|
---|
| 3 | // Christophe Magneville
|
---|
| 4 | // Reza Ansari
|
---|
[2454] | 5 | // $Id: toi.cc,v 1.13 2003-11-14 12:34:55 aubourg Exp $
|
---|
[1738] | 6 |
|
---|
[1365] | 7 | #include "toiprocessor.h"
|
---|
| 8 | #include "toi.h"
|
---|
| 9 | #include <pthread.h>
|
---|
| 10 |
|
---|
| 11 | #ifdef WITH_SOPHYA
|
---|
| 12 | #include "pexceptions.h"
|
---|
| 13 | #else
|
---|
| 14 | #include "apexceptions.h"
|
---|
| 15 | #endif
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | TOI::TOI() {
|
---|
| 19 | TOIInit();
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | TOI::TOI(string n) {
|
---|
| 23 | name = n;
|
---|
| 24 | TOIInit();
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | void TOI::TOIInit() {
|
---|
| 28 | pthread_mutex_init(&mutex, NULL);
|
---|
[1437] | 29 | // ----- Rajouts Reza 12/3/2001
|
---|
| 30 | pthread_cond_init(&condv, NULL);
|
---|
| 31 | fgwaitput = fgwaitget = false;
|
---|
| 32 | fgsigput = fgsigget = false;
|
---|
| 33 | countwaitput = countwaitget = 0;
|
---|
| 34 | // Fin rajouts Reza 12/3/2001 ------
|
---|
[1365] | 35 | // pthread_mutex_setname_np(&mutex, (name + "_toi_mutex").c_str(), 0);
|
---|
| 36 | defaultValue = 0;
|
---|
| 37 | producer = NULL;
|
---|
| 38 | dbg = false;
|
---|
[1740] | 39 | syncOldWay = true;
|
---|
[1365] | 40 | }
|
---|
| 41 |
|
---|
| 42 | TOI::~TOI() {
|
---|
| 43 | pthread_mutex_destroy(&mutex);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[1762] | 46 | void TOI::PrintStatus(::ostream & os) const
|
---|
[1437] | 47 | {
|
---|
| 48 | os << "TOI::PrintStatus() - Name=" << getName() << endl;
|
---|
| 49 | os << " WaitStatus: Put/" ;
|
---|
| 50 | if (isPutWaiting()) os << "Waiting " ;
|
---|
| 51 | else os << "Running ";
|
---|
| 52 | os << " PutCountWait= " << getCountWaitPut() << endl;
|
---|
| 53 | os << " WaitStatus: Get/" ;
|
---|
| 54 | if (isGetWaiting()) os << "Waiting " ;
|
---|
| 55 | else os << "Running ";
|
---|
| 56 | os << " GetCountWait= " << getCountWaitGet() << endl;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 |
|
---|
[1365] | 60 | void TOI::setProducer(TOIProcessor* p) {
|
---|
| 61 | if (producer)
|
---|
| 62 | throw DuplicateIdExc("TOI::setProducer : producer already defined");
|
---|
| 63 | producer = p;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | void TOI::addConsumer(TOIProcessor* p) {
|
---|
| 67 | consumers.push_back(p);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[2454] | 70 | long TOI::getMinSn(){
|
---|
[1365] | 71 | return producer->getMinOut();
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[2454] | 74 | long TOI::getMaxSn(){
|
---|
[1365] | 75 | return producer->getMaxOut();
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[2187] | 78 |
|
---|
| 79 | // ajout vf 31/07/2002
|
---|
| 80 | bool TOI::checkSampleLimits(long& Min, long& Max, int pass)
|
---|
| 81 | {
|
---|
| 82 | // propagation de la sortie du TOI vers son entree pour test des limites
|
---|
| 83 | return producer->checkSampleLimits(Min, Max, pass);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 | // fin ajout vf
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 |
|
---|
[1464] | 96 | /*
|
---|
| 97 | RZCMV ----- l'interface va etre modifiee, NE PAS UTILISER
|
---|
| 98 | #ifndef NO_SOPHYA
|
---|
[2454] | 99 | Array TOI::getError(long iStart, long iEnd) {
|
---|
[1365] | 100 | if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
|
---|
[1464] | 101 | return errorTOI->getData(iStart, iEnd);
|
---|
[1365] | 102 | }
|
---|
[2454] | 103 | Array TOI::getData(long iStart, long iEnd) {
|
---|
[1464] | 104 | lock();
|
---|
| 105 | Array a = doGetData(iStart, iEnd);
|
---|
| 106 | unlock();
|
---|
| 107 | if (fgsigput) { fgsigput = false; broadcast(); }
|
---|
| 108 | return a;
|
---|
| 109 | }
|
---|
[2454] | 110 | TArray<int_4> TOI::getFlag(long iStart, long iEnd) {
|
---|
[1464] | 111 | lock();
|
---|
| 112 | TArray<int_4> a = doGetFlag(iStart, iEnd);
|
---|
| 113 | unlock();
|
---|
| 114 | if (fgsigput) { fgsigput = false; broadcast(); }
|
---|
| 115 | return a;
|
---|
| 116 | }
|
---|
[1365] | 117 | #endif
|
---|
[1464] | 118 | l'interface va etre modifiee, NE PAS UTILISER ----
|
---|
| 119 | */
|
---|
[1365] | 120 |
|
---|
[1464] | 121 |
|
---|
| 122 | /*
|
---|
| 123 | RZCMV ------- A revoir les getError() ...
|
---|
[2454] | 124 | double TOI::getError(long i) {
|
---|
[1365] | 125 | if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
|
---|
| 126 | return errorTOI->getData(i);
|
---|
| 127 | }
|
---|
| 128 |
|
---|
[2454] | 129 | void TOI::putDataError(long i, double value, double error, int_4 flag) {
|
---|
[1365] | 130 | if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
|
---|
| 131 | putData(i, value, flag);
|
---|
| 132 | errorTOI->putData(i, value, flag);
|
---|
| 133 | }
|
---|
| 134 |
|
---|
[1462] | 135 | */
|
---|
| 136 |
|
---|
[2454] | 137 | double TOI::getData(long i) { /* deprecated, overriden in toisegment */
|
---|
[1365] | 138 | lock();
|
---|
[1532] | 139 | uint_8 flg;
|
---|
[1462] | 140 | double dat;
|
---|
| 141 | doGetData(i, dat, flg);
|
---|
[1365] | 142 | unlock();
|
---|
[1437] | 143 | if (fgsigput) { fgsigput = false; broadcast(); }
|
---|
[1365] | 144 | return dat;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
[2454] | 147 | void TOI::getData(long i, double &data, uint_8 &flag) { /* deprecated, overriden in toisegment */
|
---|
[1462] | 148 | lock();
|
---|
| 149 | doGetData(i, data, flag);
|
---|
| 150 | unlock();
|
---|
| 151 | if (fgsigput) { fgsigput = false; broadcast(); }
|
---|
| 152 | return;
|
---|
| 153 | }
|
---|
[1365] | 154 |
|
---|
[2454] | 155 | void TOI::getData(long i, int n, double* data, uint_8* flg) {
|
---|
[1742] | 156 | cerr << "TOI::getData [double*] unimplemented" << endl;
|
---|
| 157 | exit(-1);
|
---|
| 158 | }
|
---|
[1365] | 159 |
|
---|
[2454] | 160 | void TOI::putData(long i, int n, double const* var, uint_8 const* flg) {
|
---|
[1742] | 161 | cerr << "TOI::putData [double*] unimplemented" << endl;
|
---|
| 162 | exit(-1);
|
---|
| 163 | }
|
---|
| 164 |
|
---|
[2454] | 165 | void TOI::putData(long i, double value, uint_8 flag) { /* deprecated, overriden in toisegment */
|
---|
[1365] | 166 | lock();
|
---|
| 167 | doPutData(i, value, flag);
|
---|
| 168 | unlock();
|
---|
[1437] | 169 | if (fgsigget) { fgsigget = false; broadcast(); }
|
---|
[1365] | 170 | }
|
---|
| 171 |
|
---|
[2454] | 172 | void TOI::waitForData(long iStart, long iEnd) { /* deprecated, overriden in toisegment */
|
---|
[1365] | 173 | if (producer == NULL) throw NotFoundExc("TOI has no producer !");
|
---|
| 174 |
|
---|
| 175 | DataStatus s = isDataAvail(iStart, iEnd);
|
---|
| 176 | if (s == DATA_OK) {
|
---|
| 177 | return;
|
---|
| 178 | }
|
---|
| 179 | if (s == DATA_DELETED) {
|
---|
| 180 | throw NotFoundExc("Data has been purged !");
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | producer->lock();
|
---|
| 184 | while (isDataAvailNL(iStart, iEnd) == DATA_NOT_YET) {
|
---|
| 185 | producer->wait();
|
---|
| 186 | }
|
---|
| 187 | producer->unlock();
|
---|
| 188 | return;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
[2454] | 191 | void TOI::waitForData(long i) { /* deprecated, overriden in toisegment */
|
---|
[1365] | 192 | waitForData(i,i);
|
---|
| 193 | }
|
---|
| 194 |
|
---|
[1742] | 195 | void TOI::waitForAnyData() { /* deprecated, overriden in toisegment */
|
---|
[1365] | 196 | if (! hasSomeData()) {
|
---|
| 197 | producer->lock();
|
---|
| 198 | producer->wait();
|
---|
| 199 | producer->unlock();
|
---|
| 200 | }
|
---|
| 201 | }
|
---|
| 202 |
|
---|
[2454] | 203 | TOI::DataStatus TOI::isDataAvail(long i) {
|
---|
[1365] | 204 | lock();
|
---|
| 205 | DataStatus stat = isDataAvailNL(i);
|
---|
| 206 | unlock();
|
---|
| 207 | return stat;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
[2454] | 210 | TOI::DataStatus TOI::isDataAvail(long i, long j) {
|
---|
[1365] | 211 | lock();
|
---|
| 212 | DataStatus stat = isDataAvailNL(i,j);
|
---|
| 213 | unlock();
|
---|
| 214 | return stat;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
[2454] | 217 | TOI::DataStatus TOI::isDataAvailNL(long i) {
|
---|
[1365] | 218 | return isDataAvailNL(i,i);
|
---|
| 219 | }
|
---|
| 220 |
|
---|
[2454] | 221 | void TOI::wontNeedBefore(long i) { /* deprecated, overriden in toisegment */
|
---|
| 222 | long j=i;
|
---|
[1365] | 223 | for (vector<TOIProcessor*>::iterator k = consumers.begin();
|
---|
| 224 | k != consumers.end(); k++) {
|
---|
| 225 | if ((*k)->wontNeedValue < j) j = (*k)->wontNeedValue;
|
---|
| 226 | }
|
---|
| 227 | lock();
|
---|
| 228 | doWontNeedBefore(j);
|
---|
| 229 | unlock();
|
---|
| 230 | }
|
---|
| 231 |
|
---|
[2454] | 232 | void TOI::doWontNeedBefore(long i) {
|
---|
[1365] | 233 | }
|
---|
| 234 |
|
---|
| 235 |
|
---|
[2187] | 236 |
|
---|
| 237 |
|
---|
| 238 |
|
---|
| 239 |
|
---|
| 240 |
|
---|
| 241 |
|
---|
| 242 |
|
---|
| 243 |
|
---|
| 244 |
|
---|
| 245 |
|
---|
| 246 |
|
---|
| 247 |
|
---|
| 248 |
|
---|