[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
|
---|
| 7 | // $Id: toiprocessor.h,v 1.10 2001-11-08 15:47:46 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>
|
---|
| 19 | #include <map>
|
---|
[1410] | 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();
|
---|
| 49 | // Les methodes qui suivent peut etre appelees par run
|
---|
| 50 | protected:
|
---|
| 51 | #ifndef NO_SOPHYA
|
---|
[1464] | 52 | /* ---- l'interface va etre modifiee, NE PAS UTILISER
|
---|
[1365] | 53 | Array getData(int toiIndex, int iStart, int iEnd);
|
---|
| 54 | Array getError(int toiIndex, int iStart, int iEnd);
|
---|
| 55 | TArray<int_4> getFlag(int toiIndex, int iStart, int iEnd);
|
---|
[1464] | 56 | l'interface va etre modifiee, NE PAS UTILISER ---- */
|
---|
[1365] | 57 | #endif
|
---|
| 58 | // si multiple input (indexed input), tableau 2D.
|
---|
| 59 |
|
---|
| 60 | // Les methodes qui suivent ne peuvent etre
|
---|
| 61 | // utilisees que sur des entrees simples
|
---|
| 62 | double getData(int toiIndex, int i);
|
---|
[1532] | 63 | void getData(int toiIndex, int i, double &data, uint_8 &flag);
|
---|
[1462] | 64 |
|
---|
| 65 | //RZCMV double getError(int toiIndex, int i);
|
---|
| 66 | //RZCMV int_4 getFlag(int toiIndex, int i);
|
---|
[1365] | 67 |
|
---|
| 68 | void wontNeedBefore(int i);
|
---|
| 69 | int wontNeedValue;
|
---|
| 70 | void setNeededHistory(int nsamples); // -1 : disable
|
---|
| 71 |
|
---|
[1532] | 72 | void putData(int toiIndex, int i, double value, uint_8 flag=0);
|
---|
[1462] | 73 | //RZCMV void putDataError(int toiIndex, int i, double value,
|
---|
| 74 | //RZCMV double error, int_4 flag=0);
|
---|
[1365] | 75 |
|
---|
| 76 | // Gestion des bornes pour les transformations de TOIs...
|
---|
| 77 | virtual int calcMinOut();
|
---|
| 78 | virtual int calcMaxOut();
|
---|
| 79 |
|
---|
| 80 | virtual int getMinOut();
|
---|
| 81 | virtual int getMaxOut();
|
---|
| 82 | int minOut;
|
---|
| 83 | int maxOut;
|
---|
| 84 |
|
---|
| 85 | virtual int getMinIn();
|
---|
| 86 | virtual int getMaxIn();
|
---|
| 87 | // Implementation par defaut
|
---|
| 88 | int upExtra;
|
---|
| 89 | int lowExtra;
|
---|
| 90 |
|
---|
| 91 | int neededHistory;
|
---|
| 92 |
|
---|
| 93 | protected:
|
---|
| 94 | int getInputTOIIndex(string toi);
|
---|
| 95 | int getOutputTOIIndex(string toi);
|
---|
[1437] | 96 |
|
---|
| 97 | // Methodes rajoutees par Reza 11/3/2001
|
---|
| 98 | TOI* getInputTOI(int toiIndex);
|
---|
| 99 | TOI* getOutputTOI(int toiIndex);
|
---|
| 100 | bool checkInputTOIIndex(int toiIndex);
|
---|
| 101 | bool checkOutputTOIIndex(int toiIndex);
|
---|
| 102 |
|
---|
| 103 | // Fin rajout Reza 11/3/2001
|
---|
| 104 |
|
---|
[1365] | 105 | void autoWontNeed(int iCur);
|
---|
| 106 | int lastAWN;
|
---|
| 107 |
|
---|
| 108 | public:
|
---|
| 109 | // Appele par les assembleurs de pipeline
|
---|
| 110 | virtual void addInput(string name, TOI* toi);
|
---|
| 111 | virtual void addOutput(string name, TOI* toi);
|
---|
| 112 |
|
---|
[1367] | 113 |
|
---|
| 114 | int getNIn() {chkinit(); return inIx.size();}
|
---|
| 115 | int getNOut() {chkinit(); return outIx.size();}
|
---|
| 116 | string getOutName(int i);
|
---|
| 117 | string getInName(int i);
|
---|
| 118 |
|
---|
[1437] | 119 | // Methodes rajoutees par Reza 11/3/2001
|
---|
[1443] | 120 | virtual void PrintStatus(ostream & os) ; // const plus tard
|
---|
[1437] | 121 | // Fin rajout Reza 11/3/2001
|
---|
| 122 |
|
---|
[1365] | 123 | virtual void start();
|
---|
| 124 |
|
---|
| 125 | TOIProcessor();
|
---|
| 126 | virtual ~TOIProcessor();
|
---|
| 127 |
|
---|
| 128 | protected:
|
---|
| 129 |
|
---|
| 130 | map<string, int> inIx;
|
---|
| 131 | map<string, int> outIx;
|
---|
| 132 | TOI** inTOIs;
|
---|
| 133 | TOI** outTOIs;
|
---|
| 134 |
|
---|
| 135 | string name;
|
---|
| 136 | // Thread handling
|
---|
| 137 | pthread_t thread;
|
---|
| 138 | pthread_cond_t dataReady;
|
---|
| 139 | pthread_mutex_t mutex;
|
---|
| 140 | pthread_mutexattr_t mutattr;
|
---|
| 141 |
|
---|
| 142 | void lock() {
|
---|
| 143 | pthread_mutex_lock(&mutex);
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | void unlock() {
|
---|
| 147 | pthread_mutex_unlock(&mutex);
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | void wait() {
|
---|
| 151 | pthread_cond_wait(&dataReady, &mutex);
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | void notify();
|
---|
| 155 |
|
---|
| 156 |
|
---|
| 157 | friend class TOI;
|
---|
| 158 |
|
---|
| 159 | static void* ThreadStart(void *);
|
---|
[1689] | 160 | void warnPutDone();
|
---|
[1365] | 161 | };
|
---|
| 162 |
|
---|
[1437] | 163 | inline ostream & operator << (ostream & os, TOIProcessor /*const*/ & toip)
|
---|
| 164 | { toip.PrintStatus(os); return os; }
|
---|
| 165 |
|
---|
| 166 |
|
---|
[1365] | 167 | #endif
|
---|
[1437] | 168 |
|
---|