| [1365] | 1 | // This may look like C code, but it is really -*- C++ -*- | 
|---|
|  | 2 |  | 
|---|
| [1738] | 3 | // ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL | 
|---|
|  | 4 | //                               Eric Aubourg | 
|---|
|  | 5 | //                               Christophe Magneville | 
|---|
|  | 6 | //                               Reza Ansari | 
|---|
| [1800] | 7 | // $Id: toiprocessor.h,v 1.18 2001-11-29 18:19:32 aubourg Exp $ | 
|---|
| [1365] | 8 |  | 
|---|
| [1738] | 9 |  | 
|---|
|  | 10 |  | 
|---|
| [1365] | 11 | #ifndef TOIPROCESSOR_H | 
|---|
|  | 12 | #define TOIPROCESSOR_H | 
|---|
|  | 13 |  | 
|---|
|  | 14 | #include "config.h" | 
|---|
|  | 15 |  | 
|---|
|  | 16 | #include <pthread.h> | 
|---|
|  | 17 |  | 
|---|
|  | 18 | #include <string> | 
|---|
| [1765] | 19 | #include <map> | 
|---|
| [1759] | 20 | #include <iostream.h> | 
|---|
| [1365] | 21 |  | 
|---|
|  | 22 | #ifndef NO_SOPHYA | 
|---|
|  | 23 | #include "tarray.h" | 
|---|
|  | 24 | using namespace SOPHYA; | 
|---|
|  | 25 | #endif | 
|---|
|  | 26 |  | 
|---|
|  | 27 | #include "toi.h" | 
|---|
|  | 28 |  | 
|---|
|  | 29 |  | 
|---|
|  | 30 | class TOIProcessor { | 
|---|
|  | 31 | public: | 
|---|
|  | 32 | virtual void init(); | 
|---|
|  | 33 | // Les methodes qui suivent peuvent etre appelees par init | 
|---|
|  | 34 | protected: | 
|---|
|  | 35 | int declareInput(string toi); | 
|---|
|  | 36 | int declareOutput(string toi); | 
|---|
|  | 37 |  | 
|---|
|  | 38 | // void declareMultInput(string toi); | 
|---|
|  | 39 | // Question : multiple output ? | 
|---|
|  | 40 |  | 
|---|
|  | 41 | void chkinit() { | 
|---|
|  | 42 | if (!inited) {init(); afterinit(); inited=true;} | 
|---|
|  | 43 | } | 
|---|
|  | 44 | bool inited; | 
|---|
|  | 45 | virtual void afterinit(); | 
|---|
|  | 46 |  | 
|---|
|  | 47 | public: | 
|---|
|  | 48 | virtual void run(); | 
|---|
| [1800] | 49 |  | 
|---|
|  | 50 | virtual int   getMinOut(); | 
|---|
|  | 51 | virtual int   getMaxOut(); | 
|---|
| [1365] | 52 | // Les methodes qui suivent peut etre appelees par run | 
|---|
|  | 53 | protected: | 
|---|
|  | 54 | #ifndef NO_SOPHYA | 
|---|
| [1464] | 55 | /* ---- l'interface va etre modifiee, NE PAS UTILISER | 
|---|
| [1365] | 56 | Array         getData(int toiIndex, int iStart, int iEnd); | 
|---|
|  | 57 | Array         getError(int toiIndex, int iStart, int iEnd); | 
|---|
|  | 58 | TArray<int_4> getFlag(int toiIndex, int iStart, int iEnd); | 
|---|
| [1464] | 59 | l'interface va etre modifiee, NE PAS UTILISER ---- */ | 
|---|
| [1365] | 60 | #endif | 
|---|
|  | 61 | // si multiple input (indexed input), tableau 2D. | 
|---|
|  | 62 |  | 
|---|
|  | 63 | // Les methodes qui suivent ne peuvent etre | 
|---|
|  | 64 | // utilisees que sur des entrees simples | 
|---|
|  | 65 | double        getData(int toiIndex, int i); | 
|---|
| [1532] | 66 | void          getData(int toiIndex, int i, double &data, uint_8 &flag); | 
|---|
| [1743] | 67 |  | 
|---|
|  | 68 | void          getData(int toiIndex, int i, int n, double* d); | 
|---|
|  | 69 | void          getData(int toiIndex, int i, int n, double* d, uint_8* f); | 
|---|
| [1462] | 70 |  | 
|---|
|  | 71 | //RZCMV  double        getError(int toiIndex, int i); | 
|---|
|  | 72 | //RZCMV  int_4         getFlag(int toiIndex, int i); | 
|---|
| [1365] | 73 |  | 
|---|
|  | 74 | void          wontNeedBefore(int i); | 
|---|
|  | 75 | int           wontNeedValue; | 
|---|
|  | 76 | void          setNeededHistory(int nsamples); // -1 : disable | 
|---|
|  | 77 |  | 
|---|
| [1532] | 78 | void          putData(int toiIndex, int i, double value, uint_8 flag=0); | 
|---|
| [1462] | 79 | //RZCMV  void          putDataError(int toiIndex, int i, double value, | 
|---|
|  | 80 | //RZCMV                            double error, int_4 flag=0); | 
|---|
| [1365] | 81 |  | 
|---|
| [1743] | 82 | void          putData(int toiIndex, int i, int n, double const* val, | 
|---|
|  | 83 | uint_8 const* flg=0); | 
|---|
|  | 84 |  | 
|---|
| [1365] | 85 | // Gestion des bornes pour les transformations de TOIs... | 
|---|
| [1787] | 86 | virtual int   calcMinOut(); // Protected ? | 
|---|
|  | 87 | virtual int   calcMaxOut(); // Protected ? | 
|---|
|  | 88 | int           minOut;    // Cache for calcMinOut() value. Protected ? | 
|---|
|  | 89 | int           maxOut;    // Cache for calcMaxOut() value. Protected ? | 
|---|
| [1365] | 90 |  | 
|---|
|  | 91 | virtual int   getMinIn(); | 
|---|
|  | 92 | virtual int   getMaxIn(); | 
|---|
|  | 93 | // Implementation par defaut | 
|---|
| [1787] | 94 | int           upExtra;  // MaxIn - MaxOut : extra samples for processing | 
|---|
|  | 95 | int           lowExtra; // MinOut - MinIn : extra samples for processing | 
|---|
| [1365] | 96 |  | 
|---|
| [1787] | 97 | int           forcedMinIn; // to process a subset of data | 
|---|
|  | 98 | int           forcedMaxIn; // to process a subset of data | 
|---|
|  | 99 | void          setSampleSubset(int min, int max); | 
|---|
|  | 100 |  | 
|---|
| [1365] | 101 | int           neededHistory; | 
|---|
|  | 102 |  | 
|---|
|  | 103 | protected: | 
|---|
|  | 104 | int           getInputTOIIndex(string toi); | 
|---|
|  | 105 | int           getOutputTOIIndex(string toi); | 
|---|
| [1437] | 106 |  | 
|---|
|  | 107 | //  Methodes rajoutees par Reza 11/3/2001 | 
|---|
|  | 108 | TOI*          getInputTOI(int toiIndex); | 
|---|
|  | 109 | TOI*          getOutputTOI(int toiIndex); | 
|---|
|  | 110 | bool          checkInputTOIIndex(int toiIndex); | 
|---|
|  | 111 | bool          checkOutputTOIIndex(int toiIndex); | 
|---|
|  | 112 |  | 
|---|
|  | 113 | //  Fin rajout Reza 11/3/2001 | 
|---|
|  | 114 |  | 
|---|
| [1365] | 115 | void          autoWontNeed(int iCur); | 
|---|
|  | 116 | int           lastAWN; | 
|---|
|  | 117 |  | 
|---|
|  | 118 | public: | 
|---|
|  | 119 | // Appele par les assembleurs de pipeline | 
|---|
|  | 120 | virtual void  addInput(string name, TOI* toi); | 
|---|
|  | 121 | virtual void  addOutput(string name, TOI* toi); | 
|---|
|  | 122 |  | 
|---|
| [1367] | 123 |  | 
|---|
|  | 124 | int getNIn()  {chkinit(); return inIx.size();} | 
|---|
|  | 125 | int getNOut() {chkinit(); return outIx.size();} | 
|---|
|  | 126 | string getOutName(int i); | 
|---|
|  | 127 | string getInName(int i); | 
|---|
|  | 128 |  | 
|---|
| [1437] | 129 | //  Methodes rajoutees par Reza 11/3/2001 | 
|---|
| [1762] | 130 | virtual void  PrintStatus(::ostream & os) ; // const plus tard | 
|---|
| [1437] | 131 | //  Fin rajout Reza 11/3/2001 | 
|---|
|  | 132 |  | 
|---|
| [1365] | 133 | virtual void  start(); | 
|---|
|  | 134 |  | 
|---|
|  | 135 | TOIProcessor(); | 
|---|
|  | 136 | virtual ~TOIProcessor(); | 
|---|
| [1800] | 137 |  | 
|---|
|  | 138 | void setMinSn(int n) {forcedMinIn = n;} | 
|---|
|  | 139 | void setMaxSn(int n) {forcedMaxIn = n;} | 
|---|
| [1365] | 140 |  | 
|---|
|  | 141 | protected: | 
|---|
|  | 142 |  | 
|---|
|  | 143 | map<string, int> inIx; | 
|---|
|  | 144 | map<string, int> outIx; | 
|---|
|  | 145 | TOI**  inTOIs; | 
|---|
|  | 146 | TOI**  outTOIs; | 
|---|
|  | 147 |  | 
|---|
|  | 148 | string name; | 
|---|
|  | 149 | // Thread handling | 
|---|
|  | 150 | pthread_t        thread; | 
|---|
|  | 151 | pthread_cond_t   dataReady; | 
|---|
|  | 152 | pthread_mutex_t  mutex; | 
|---|
|  | 153 | pthread_mutexattr_t mutattr; | 
|---|
|  | 154 |  | 
|---|
|  | 155 | void lock() { | 
|---|
|  | 156 | pthread_mutex_lock(&mutex); | 
|---|
|  | 157 | } | 
|---|
|  | 158 |  | 
|---|
|  | 159 | void unlock() { | 
|---|
|  | 160 | pthread_mutex_unlock(&mutex); | 
|---|
|  | 161 | } | 
|---|
|  | 162 |  | 
|---|
|  | 163 | void wait()   { | 
|---|
|  | 164 | pthread_cond_wait(&dataReady, &mutex); | 
|---|
|  | 165 | } | 
|---|
|  | 166 |  | 
|---|
|  | 167 | void notify(); | 
|---|
|  | 168 |  | 
|---|
|  | 169 |  | 
|---|
|  | 170 | friend class TOI; | 
|---|
|  | 171 |  | 
|---|
|  | 172 | static void* ThreadStart(void *); | 
|---|
| [1689] | 173 | void warnPutDone(); | 
|---|
| [1365] | 174 | }; | 
|---|
|  | 175 |  | 
|---|
| [1762] | 176 | inline ::ostream & operator << (::ostream & os, TOIProcessor /*const*/ & toip) | 
|---|
| [1437] | 177 | { toip.PrintStatus(os); return os; } | 
|---|
|  | 178 |  | 
|---|
|  | 179 |  | 
|---|
| [1365] | 180 | #endif | 
|---|
| [1437] | 181 |  | 
|---|