[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
|
---|
[2000] | 7 | // $Id: toiprocessor.h,v 1.19 2002-05-14 13:06:57 ansari 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...
|
---|
[2000] | 86 | public:
|
---|
| 87 | // Methodes passees en public par Reza, 14/5/2002
|
---|
[1787] | 88 | virtual int calcMinOut(); // Protected ?
|
---|
| 89 | virtual int calcMaxOut(); // Protected ?
|
---|
[1365] | 90 |
|
---|
| 91 | virtual int getMinIn();
|
---|
| 92 | virtual int getMaxIn();
|
---|
[2000] | 93 | protected:
|
---|
[1365] | 94 | // Implementation par defaut
|
---|
[2000] | 95 | int minOut; // Cache for calcMinOut() value. Protected ?
|
---|
| 96 | int maxOut; // Cache for calcMaxOut() value. Protected ?
|
---|
| 97 |
|
---|
[1787] | 98 | int upExtra; // MaxIn - MaxOut : extra samples for processing
|
---|
| 99 | int lowExtra; // MinOut - MinIn : extra samples for processing
|
---|
[1365] | 100 |
|
---|
[1787] | 101 | int forcedMinIn; // to process a subset of data
|
---|
| 102 | int forcedMaxIn; // to process a subset of data
|
---|
| 103 | void setSampleSubset(int min, int max);
|
---|
| 104 |
|
---|
[1365] | 105 | int neededHistory;
|
---|
| 106 |
|
---|
| 107 | protected:
|
---|
| 108 | int getInputTOIIndex(string toi);
|
---|
| 109 | int getOutputTOIIndex(string toi);
|
---|
[1437] | 110 |
|
---|
| 111 | // Methodes rajoutees par Reza 11/3/2001
|
---|
| 112 | TOI* getInputTOI(int toiIndex);
|
---|
| 113 | TOI* getOutputTOI(int toiIndex);
|
---|
| 114 | bool checkInputTOIIndex(int toiIndex);
|
---|
| 115 | bool checkOutputTOIIndex(int toiIndex);
|
---|
| 116 |
|
---|
| 117 | // Fin rajout Reza 11/3/2001
|
---|
| 118 |
|
---|
[1365] | 119 | void autoWontNeed(int iCur);
|
---|
| 120 | int lastAWN;
|
---|
| 121 |
|
---|
| 122 | public:
|
---|
| 123 | // Appele par les assembleurs de pipeline
|
---|
| 124 | virtual void addInput(string name, TOI* toi);
|
---|
| 125 | virtual void addOutput(string name, TOI* toi);
|
---|
| 126 |
|
---|
[1367] | 127 |
|
---|
| 128 | int getNIn() {chkinit(); return inIx.size();}
|
---|
| 129 | int getNOut() {chkinit(); return outIx.size();}
|
---|
| 130 | string getOutName(int i);
|
---|
| 131 | string getInName(int i);
|
---|
| 132 |
|
---|
[1437] | 133 | // Methodes rajoutees par Reza 11/3/2001
|
---|
[1762] | 134 | virtual void PrintStatus(::ostream & os) ; // const plus tard
|
---|
[1437] | 135 | // Fin rajout Reza 11/3/2001
|
---|
| 136 |
|
---|
[1365] | 137 | virtual void start();
|
---|
| 138 |
|
---|
| 139 | TOIProcessor();
|
---|
| 140 | virtual ~TOIProcessor();
|
---|
[1800] | 141 |
|
---|
| 142 | void setMinSn(int n) {forcedMinIn = n;}
|
---|
| 143 | void setMaxSn(int n) {forcedMaxIn = n;}
|
---|
[1365] | 144 |
|
---|
| 145 | protected:
|
---|
| 146 |
|
---|
| 147 | map<string, int> inIx;
|
---|
| 148 | map<string, int> outIx;
|
---|
| 149 | TOI** inTOIs;
|
---|
| 150 | TOI** outTOIs;
|
---|
| 151 |
|
---|
| 152 | string name;
|
---|
| 153 | // Thread handling
|
---|
| 154 | pthread_t thread;
|
---|
| 155 | pthread_cond_t dataReady;
|
---|
| 156 | pthread_mutex_t mutex;
|
---|
| 157 | pthread_mutexattr_t mutattr;
|
---|
| 158 |
|
---|
| 159 | void lock() {
|
---|
| 160 | pthread_mutex_lock(&mutex);
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | void unlock() {
|
---|
| 164 | pthread_mutex_unlock(&mutex);
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | void wait() {
|
---|
| 168 | pthread_cond_wait(&dataReady, &mutex);
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | void notify();
|
---|
| 172 |
|
---|
| 173 |
|
---|
| 174 | friend class TOI;
|
---|
| 175 |
|
---|
| 176 | static void* ThreadStart(void *);
|
---|
[1689] | 177 | void warnPutDone();
|
---|
[1365] | 178 | };
|
---|
| 179 |
|
---|
[1762] | 180 | inline ::ostream & operator << (::ostream & os, TOIProcessor /*const*/ & toip)
|
---|
[1437] | 181 | { toip.PrintStatus(os); return os; }
|
---|
| 182 |
|
---|
| 183 |
|
---|
[1365] | 184 | #endif
|
---|
[1437] | 185 |
|
---|