| 1 | // ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL
 | 
|---|
| 2 | //                               Eric Aubourg
 | 
|---|
| 3 | //                               Christophe Magneville
 | 
|---|
| 4 | //                               Reza Ansari
 | 
|---|
| 5 | // $Id: toiregwindow.cc,v 1.3 2001-11-08 15:47:46 aubourg Exp $
 | 
|---|
| 6 | 
 | 
|---|
| 7 | #include "toiprocessor.h"
 | 
|---|
| 8 | #include "toiregwindow.h"
 | 
|---|
| 9 | #include <pthread.h>
 | 
|---|
| 10 | 
 | 
|---|
| 11 | #ifdef WITH_SOPHYA
 | 
|---|
| 12 | #include "pexceptions.h"
 | 
|---|
| 13 | #else
 | 
|---|
| 14 | #include "apexceptions.h"
 | 
|---|
| 15 | #endif
 | 
|---|
| 16 | 
 | 
|---|
| 17 | #define CHKSYNC(ctx)  
 | 
|---|
| 18 | //  if (((TOIRegularWindow*)this)->data.size() != ((TOIRegularWindow*)this)->flags.size())        \
 | 
|---|
| 19 | //    cout << ctx << ((TOIRegularWindow*)this)->data.size() << "  " <<  \
 | 
|---|
| 20 | //      ((TOIRegularWindow*)this)->flags.size() << endl;  \
 | 
|---|
| 21 | 
 | 
|---|
| 22 | // ------------------------------------------------------------
 | 
|---|
| 23 | // --------------------  TOIRegularWindow  --------------------
 | 
|---|
| 24 | // ------------------------------------------------------------
 | 
|---|
| 25 | 
 | 
|---|
| 26 | 
 | 
|---|
| 27 | TOIRegularWindow::TOIRegularWindow() {
 | 
|---|
| 28 |   i0 = -1;
 | 
|---|
| 29 | }
 | 
|---|
| 30 | 
 | 
|---|
| 31 | TOIRegularWindow::TOIRegularWindow(string nm) {
 | 
|---|
| 32 |   i0 = -1;
 | 
|---|
| 33 |   setName(nm);
 | 
|---|
| 34 | }
 | 
|---|
| 35 | 
 | 
|---|
| 36 | TOIRegularWindow::~TOIRegularWindow() {
 | 
|---|
| 37 | }
 | 
|---|
| 38 | 
 | 
|---|
| 39 | TOI::DataStatus TOIRegularWindow::isDataAvailNL(int iStart, int iEnd) {
 | 
|---|
| 40 |   if (iEnd >= i0 + (long)data.size()) return DATA_NOT_YET;
 | 
|---|
| 41 |   if (iStart < i0) return DATA_DELETED;
 | 
|---|
| 42 |   return DATA_OK;
 | 
|---|
| 43 | }
 | 
|---|
| 44 | 
 | 
|---|
| 45 | TOI::DataStatus TOIRegularWindow::isDataAvailNL(int i) {
 | 
|---|
| 46 |   return TOI::isDataAvailNL(i);
 | 
|---|
| 47 | }
 | 
|---|
| 48 | 
 | 
|---|
| 49 | 
 | 
|---|
| 50 | void TOIRegularWindow::doWontNeedBefore(int i) {
 | 
|---|
| 51 |   if (i>= i0 + (long)data.size())
 | 
|---|
| 52 |     i = i0 + (long)data.size() - 1;
 | 
|---|
| 53 |   if (i>i0) {  // don't empty list
 | 
|---|
| 54 |     int osz = data.size();
 | 
|---|
| 55 |     data.erase(data.begin(), data.begin()+(i-i0));
 | 
|---|
| 56 |     flags.erase(flags.begin(), flags.begin()+(i-i0));
 | 
|---|
| 57 |     i0 = i;
 | 
|---|
| 58 |   }
 | 
|---|
| 59 | }
 | 
|---|
| 60 | 
 | 
|---|
| 61 | 
 | 
|---|
| 62 | 
 | 
|---|
| 63 | #ifndef NO_SOPHYA
 | 
|---|
| 64 |   /* ----- l'interface va etre modifiee, NE PAS UTILISER
 | 
|---|
| 65 | Array TOIRegularWindow::doGetData(int iStart, int iEnd) {
 | 
|---|
| 66 |   if (!isDataAvailNL(iStart, iEnd)) {
 | 
|---|
| 67 |     throw RangeCheckError("TOI::getData : data not available");
 | 
|---|
| 68 |   }
 | 
|---|
| 69 |   Array dat(iEnd - iStart + 1);
 | 
|---|
| 70 |   long j0 = iStart - i0;
 | 
|---|
| 71 |   for (int i=0; i<iEnd-iStart+1; i++) {
 | 
|---|
| 72 |     dat[i] = data[i+j0];
 | 
|---|
| 73 |   }
 | 
|---|
| 74 |   return dat;
 | 
|---|
| 75 | }
 | 
|---|
| 76 | TArray<int_4> TOIRegularWindow::doGetFlag(int iStart, int iEnd) {
 | 
|---|
| 77 |   if (isDataAvailNL(iStart, iEnd) != DATA_OK) throw RangeCheckError("TOI::getData : data not available");
 | 
|---|
| 78 |   TArray<int_4> dat(iEnd - iStart + 1);
 | 
|---|
| 79 |   long j0 = iStart - i0;
 | 
|---|
| 80 |   for (int i=0; i<iEnd-iStart+1; i++) {
 | 
|---|
| 81 |     dat[i] = flags[i+j0];
 | 
|---|
| 82 |   }
 | 
|---|
| 83 |   return dat;
 | 
|---|
| 84 | }
 | 
|---|
| 85 |   l'interface va etre modifiee, NE PAS UTILISER ----- */
 | 
|---|
| 86 | #endif
 | 
|---|
| 87 | 
 | 
|---|
| 88 | void TOIRegularWindow::doGetData(int i, double & val, uint_8 & flg) {
 | 
|---|
| 89 |   if (isDataAvailNL(i) != DATA_OK) {
 | 
|---|
| 90 |     cerr << "TOI::getData : data not available " << i << endl;
 | 
|---|
| 91 |     throw RangeCheckError("TOI::getData : data not available");
 | 
|---|
| 92 |   }
 | 
|---|
| 93 | 
 | 
|---|
| 94 |   val = data[i - i0];
 | 
|---|
| 95 |   flg = flags[i - i0];
 | 
|---|
| 96 | 
 | 
|---|
| 97 | }
 | 
|---|
| 98 | 
 | 
|---|
| 99 | 
 | 
|---|
| 100 | /*RZCMV
 | 
|---|
| 101 | int_4 TOIRegularWindow::doGetFlag(int i) {
 | 
|---|
| 102 |   if (isDataAvailNL(i) != DATA_OK) {
 | 
|---|
| 103 |     cerr << "TOI::getFlag : data not available " << i << endl;
 | 
|---|
| 104 |     throw RangeCheckError("TOI::getFlag : data not available");
 | 
|---|
| 105 |   }
 | 
|---|
| 106 |   return flags[i - i0]; 
 | 
|---|
| 107 | }
 | 
|---|
| 108 | */
 | 
|---|
| 109 | 
 | 
|---|
| 110 | 
 | 
|---|
| 111 | 
 | 
|---|
| 112 | void TOIRegularWindow::doPutData(int i, double value, uint_8 flag) {
 | 
|---|
| 113 |   uint_8 flgdef = 0;
 | 
|---|
| 114 |   if (i0 == -1) {
 | 
|---|
| 115 |     data.insert(data.begin(), 1,  defaultValue);
 | 
|---|
| 116 |     flags.insert(flags.begin(), 1,  flgdef);
 | 
|---|
| 117 |     i0 = i;
 | 
|---|
| 118 |   } else if (i<i0) {
 | 
|---|
| 119 |     data.insert(data.begin(), i0-i, defaultValue); 
 | 
|---|
| 120 |     flags.insert(flags.begin(), i0-i, flgdef);
 | 
|---|
| 121 |     i0 = i;
 | 
|---|
| 122 |   } else if (i>=i0+(int)data.size()) {
 | 
|---|
| 123 |     data.insert(data.end(), (long)  (i-(i0+data.size())+1), defaultValue);
 | 
|---|
| 124 |     flags.insert(flags.end(), (long) (i-(i0+flags.size())+1), flgdef);
 | 
|---|
| 125 |   }
 | 
|---|
| 126 |   data[i-i0] = value;
 | 
|---|
| 127 |   flags[i-i0] = flag;  
 | 
|---|
| 128 | }
 | 
|---|
| 129 | 
 | 
|---|
| 130 | 
 | 
|---|
| 131 | bool TOIRegularWindow::hasSomeData() {
 | 
|---|
| 132 |   lock();
 | 
|---|
| 133 |   bool x = !data.empty();
 | 
|---|
| 134 |   unlock();
 | 
|---|
| 135 |   return x;
 | 
|---|
| 136 | }
 | 
|---|
| 137 | 
 | 
|---|
| 138 | int TOIRegularWindow::nextDataAvail(int iAfter) {
 | 
|---|
| 139 |   lock();
 | 
|---|
| 140 |   if (iAfter >= i0 + (long)data.size()) {unlock(); return -1;}
 | 
|---|
| 141 |   if (iAfter < i0) {unlock(); return i0;}
 | 
|---|
| 142 |   unlock();
 | 
|---|
| 143 |   return iAfter+1;
 | 
|---|
| 144 | }
 | 
|---|
| 145 | 
 | 
|---|
| 146 | 
 | 
|---|
| 147 | /*  A faire, le nettoyage (heuristique selon demandes ?, guide ? ) */
 | 
|---|
| 148 |                  
 | 
|---|
| 149 | 
 | 
|---|