[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
|
---|
[1765] | 7 | // $Id: toiprocessor.h,v 1.16 2001-11-14 14:12: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();
|
---|
| 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);
|
---|
[1743] | 64 |
|
---|
| 65 | void getData(int toiIndex, int i, int n, double* d);
|
---|
| 66 | void getData(int toiIndex, int i, int n, double* d, uint_8* f);
|
---|
[1462] | 67 |
|
---|
| 68 | //RZCMV double getError(int toiIndex, int i);
|
---|
| 69 | //RZCMV int_4 getFlag(int toiIndex, int i);
|
---|
[1365] | 70 |
|
---|
| 71 | void wontNeedBefore(int i);
|
---|
| 72 | int wontNeedValue;
|
---|
| 73 | void setNeededHistory(int nsamples); // -1 : disable
|
---|
| 74 |
|
---|
[1532] | 75 | void putData(int toiIndex, int i, double value, uint_8 flag=0);
|
---|
[1462] | 76 | //RZCMV void putDataError(int toiIndex, int i, double value,
|
---|
| 77 | //RZCMV double error, int_4 flag=0);
|
---|
[1365] | 78 |
|
---|
[1743] | 79 | void putData(int toiIndex, int i, int n, double const* val,
|
---|
| 80 | uint_8 const* flg=0);
|
---|
| 81 |
|
---|
[1365] | 82 | // Gestion des bornes pour les transformations de TOIs...
|
---|
| 83 | virtual int calcMinOut();
|
---|
| 84 | virtual int calcMaxOut();
|
---|
| 85 |
|
---|
| 86 | virtual int getMinOut();
|
---|
| 87 | virtual int getMaxOut();
|
---|
| 88 | int minOut;
|
---|
| 89 | int maxOut;
|
---|
| 90 |
|
---|
| 91 | virtual int getMinIn();
|
---|
| 92 | virtual int getMaxIn();
|
---|
| 93 | // Implementation par defaut
|
---|
| 94 | int upExtra;
|
---|
| 95 | int lowExtra;
|
---|
| 96 |
|
---|
| 97 | int neededHistory;
|
---|
| 98 |
|
---|
| 99 | protected:
|
---|
| 100 | int getInputTOIIndex(string toi);
|
---|
| 101 | int getOutputTOIIndex(string toi);
|
---|
[1437] | 102 |
|
---|
| 103 | // Methodes rajoutees par Reza 11/3/2001
|
---|
| 104 | TOI* getInputTOI(int toiIndex);
|
---|
| 105 | TOI* getOutputTOI(int toiIndex);
|
---|
| 106 | bool checkInputTOIIndex(int toiIndex);
|
---|
| 107 | bool checkOutputTOIIndex(int toiIndex);
|
---|
| 108 |
|
---|
| 109 | // Fin rajout Reza 11/3/2001
|
---|
| 110 |
|
---|
[1365] | 111 | void autoWontNeed(int iCur);
|
---|
| 112 | int lastAWN;
|
---|
| 113 |
|
---|
| 114 | public:
|
---|
| 115 | // Appele par les assembleurs de pipeline
|
---|
| 116 | virtual void addInput(string name, TOI* toi);
|
---|
| 117 | virtual void addOutput(string name, TOI* toi);
|
---|
| 118 |
|
---|
[1367] | 119 |
|
---|
| 120 | int getNIn() {chkinit(); return inIx.size();}
|
---|
| 121 | int getNOut() {chkinit(); return outIx.size();}
|
---|
| 122 | string getOutName(int i);
|
---|
| 123 | string getInName(int i);
|
---|
| 124 |
|
---|
[1437] | 125 | // Methodes rajoutees par Reza 11/3/2001
|
---|
[1762] | 126 | virtual void PrintStatus(::ostream & os) ; // const plus tard
|
---|
[1437] | 127 | // Fin rajout Reza 11/3/2001
|
---|
| 128 |
|
---|
[1365] | 129 | virtual void start();
|
---|
| 130 |
|
---|
| 131 | TOIProcessor();
|
---|
| 132 | virtual ~TOIProcessor();
|
---|
| 133 |
|
---|
| 134 | protected:
|
---|
| 135 |
|
---|
| 136 | map<string, int> inIx;
|
---|
| 137 | map<string, int> outIx;
|
---|
| 138 | TOI** inTOIs;
|
---|
| 139 | TOI** outTOIs;
|
---|
| 140 |
|
---|
| 141 | string name;
|
---|
| 142 | // Thread handling
|
---|
| 143 | pthread_t thread;
|
---|
| 144 | pthread_cond_t dataReady;
|
---|
| 145 | pthread_mutex_t mutex;
|
---|
| 146 | pthread_mutexattr_t mutattr;
|
---|
| 147 |
|
---|
| 148 | void lock() {
|
---|
| 149 | pthread_mutex_lock(&mutex);
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | void unlock() {
|
---|
| 153 | pthread_mutex_unlock(&mutex);
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | void wait() {
|
---|
| 157 | pthread_cond_wait(&dataReady, &mutex);
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | void notify();
|
---|
| 161 |
|
---|
| 162 |
|
---|
| 163 | friend class TOI;
|
---|
| 164 |
|
---|
| 165 | static void* ThreadStart(void *);
|
---|
[1689] | 166 | void warnPutDone();
|
---|
[1365] | 167 | };
|
---|
| 168 |
|
---|
[1762] | 169 | inline ::ostream & operator << (::ostream & os, TOIProcessor /*const*/ & toip)
|
---|
[1437] | 170 | { toip.PrintStatus(os); return os; }
|
---|
| 171 |
|
---|
| 172 |
|
---|
[1365] | 173 | #endif
|
---|
[1437] | 174 |
|
---|