[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
|
---|
[2448] | 7 | // $Id: toiprocessor.h,v 1.21 2003-10-13 20:48:37 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 |
|
---|
[2448] | 50 | virtual long getMinOut();
|
---|
| 51 | virtual long getMaxOut();
|
---|
[2187] | 52 |
|
---|
| 53 | // rajout vf 29/07/2002
|
---|
| 54 | virtual void setRequestedSample(long begin, long end);
|
---|
| 55 | virtual bool getRequested();
|
---|
| 56 | virtual bool checkSampleLimits(int pass);
|
---|
| 57 | virtual void printLimits();
|
---|
| 58 |
|
---|
| 59 | // rajout vf 29/07/2002
|
---|
| 60 | protected:
|
---|
| 61 | bool requestedSample;
|
---|
| 62 | long snBegin;
|
---|
| 63 | long snEnd;
|
---|
| 64 | long snMin;
|
---|
| 65 | long snMax;
|
---|
| 66 | virtual bool checkSampleLimits(long &min, long &max, int pass);
|
---|
| 67 |
|
---|
| 68 |
|
---|
[1365] | 69 | // Les methodes qui suivent peut etre appelees par run
|
---|
| 70 | protected:
|
---|
| 71 | #ifndef NO_SOPHYA
|
---|
[1464] | 72 | /* ---- l'interface va etre modifiee, NE PAS UTILISER
|
---|
[2448] | 73 | Array getData(int toiIndex, long iStart, long iEnd);
|
---|
| 74 | Array getError(int toiIndex, long iStart, long iEnd);
|
---|
| 75 | TArray<int_4> getFlag(int toiIndex, long iStart, long iEnd);
|
---|
[1464] | 76 | l'interface va etre modifiee, NE PAS UTILISER ---- */
|
---|
[1365] | 77 | #endif
|
---|
| 78 | // si multiple input (indexed input), tableau 2D.
|
---|
| 79 |
|
---|
| 80 | // Les methodes qui suivent ne peuvent etre
|
---|
| 81 | // utilisees que sur des entrees simples
|
---|
[2448] | 82 | double getData(int toiIndex, long i);
|
---|
| 83 | void getData(int toiIndex, long i, double &data, uint_8 &flag);
|
---|
[1743] | 84 |
|
---|
[2448] | 85 | void getData(int toiIndex, long i, long n, double* d);
|
---|
| 86 | void getData(int toiIndex, long i, long n, double* d, uint_8* f);
|
---|
[1462] | 87 |
|
---|
[2448] | 88 | //RZCMV double getError(int toiIndex, long i);
|
---|
| 89 | //RZCMV int_4 getFlag(int toiIndex, long i);
|
---|
[1365] | 90 |
|
---|
[2448] | 91 | void wontNeedBefore(long i);
|
---|
| 92 | long wontNeedValue;
|
---|
| 93 | void setNeededHistory(long nsamples); // -1 : disable
|
---|
[1365] | 94 |
|
---|
[2448] | 95 | void putData(int toiIndex, long i, double value, uint_8 flag=0);
|
---|
| 96 | //RZCMV void putDataError(int toiIndex, long i, double value,
|
---|
[1462] | 97 | //RZCMV double error, int_4 flag=0);
|
---|
[1365] | 98 |
|
---|
[2448] | 99 | void putData(int toiIndex, long i, long n, double const* val,
|
---|
[1743] | 100 | uint_8 const* flg=0);
|
---|
| 101 |
|
---|
[1365] | 102 | // Gestion des bornes pour les transformations de TOIs...
|
---|
[2000] | 103 | public:
|
---|
| 104 | // Methodes passees en public par Reza, 14/5/2002
|
---|
[2448] | 105 | virtual long calcMinOut(); // Protected ?
|
---|
| 106 | virtual long calcMaxOut(); // Protected ?
|
---|
[1365] | 107 |
|
---|
[2448] | 108 | virtual long getMinIn();
|
---|
| 109 | virtual long getMaxIn();
|
---|
[2000] | 110 | protected:
|
---|
[1365] | 111 | // Implementation par defaut
|
---|
[2448] | 112 | long minOut; // Cache for calcMinOut() value. Protected ?
|
---|
| 113 | long maxOut; // Cache for calcMaxOut() value. Protected ?
|
---|
[2000] | 114 |
|
---|
[1787] | 115 | int upExtra; // MaxIn - MaxOut : extra samples for processing
|
---|
| 116 | int lowExtra; // MinOut - MinIn : extra samples for processing
|
---|
[1365] | 117 |
|
---|
[2448] | 118 | long forcedMinIn; // to process a subset of data
|
---|
| 119 | long forcedMaxIn; // to process a subset of data
|
---|
| 120 | void setSampleSubset(long min, long max);
|
---|
[1787] | 121 |
|
---|
[1365] | 122 | int neededHistory;
|
---|
| 123 |
|
---|
| 124 | protected:
|
---|
| 125 | int getInputTOIIndex(string toi);
|
---|
| 126 | int getOutputTOIIndex(string toi);
|
---|
[1437] | 127 |
|
---|
| 128 | // Methodes rajoutees par Reza 11/3/2001
|
---|
| 129 | TOI* getInputTOI(int toiIndex);
|
---|
| 130 | TOI* getOutputTOI(int toiIndex);
|
---|
| 131 | bool checkInputTOIIndex(int toiIndex);
|
---|
| 132 | bool checkOutputTOIIndex(int toiIndex);
|
---|
| 133 |
|
---|
| 134 | // Fin rajout Reza 11/3/2001
|
---|
| 135 |
|
---|
[2448] | 136 | void autoWontNeed(long iCur);
|
---|
| 137 | long lastAWN;
|
---|
[1365] | 138 |
|
---|
[2187] | 139 |
|
---|
[1365] | 140 | public:
|
---|
| 141 | // Appele par les assembleurs de pipeline
|
---|
| 142 | virtual void addInput(string name, TOI* toi);
|
---|
| 143 | virtual void addOutput(string name, TOI* toi);
|
---|
| 144 |
|
---|
[1367] | 145 |
|
---|
| 146 | int getNIn() {chkinit(); return inIx.size();}
|
---|
| 147 | int getNOut() {chkinit(); return outIx.size();}
|
---|
| 148 | string getOutName(int i);
|
---|
| 149 | string getInName(int i);
|
---|
| 150 |
|
---|
[1437] | 151 | // Methodes rajoutees par Reza 11/3/2001
|
---|
[1762] | 152 | virtual void PrintStatus(::ostream & os) ; // const plus tard
|
---|
[1437] | 153 | // Fin rajout Reza 11/3/2001
|
---|
| 154 |
|
---|
[1365] | 155 | virtual void start();
|
---|
| 156 |
|
---|
| 157 | TOIProcessor();
|
---|
| 158 | virtual ~TOIProcessor();
|
---|
[1800] | 159 |
|
---|
[2448] | 160 | void setMinSn(long n) {forcedMinIn = n;}
|
---|
| 161 | void setMaxSn(long n) {forcedMaxIn = n;}
|
---|
[1365] | 162 |
|
---|
[2187] | 163 | // ajout vf 23/08/2002
|
---|
| 164 | TOI* getOutToi(string sortie);
|
---|
| 165 |
|
---|
| 166 | virtual void setName(string n) {name=n;}
|
---|
| 167 |
|
---|
[1365] | 168 | protected:
|
---|
| 169 |
|
---|
| 170 | map<string, int> inIx;
|
---|
| 171 | map<string, int> outIx;
|
---|
| 172 | TOI** inTOIs;
|
---|
| 173 | TOI** outTOIs;
|
---|
| 174 |
|
---|
| 175 | string name;
|
---|
| 176 | // Thread handling
|
---|
| 177 | pthread_t thread;
|
---|
| 178 | pthread_cond_t dataReady;
|
---|
| 179 | pthread_mutex_t mutex;
|
---|
| 180 | pthread_mutexattr_t mutattr;
|
---|
| 181 |
|
---|
| 182 | void lock() {
|
---|
| 183 | pthread_mutex_lock(&mutex);
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | void unlock() {
|
---|
| 187 | pthread_mutex_unlock(&mutex);
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | void wait() {
|
---|
| 191 | pthread_cond_wait(&dataReady, &mutex);
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | void notify();
|
---|
| 195 |
|
---|
| 196 |
|
---|
| 197 | friend class TOI;
|
---|
| 198 |
|
---|
| 199 | static void* ThreadStart(void *);
|
---|
[1689] | 200 | void warnPutDone();
|
---|
[1365] | 201 | };
|
---|
| 202 |
|
---|
[1762] | 203 | inline ::ostream & operator << (::ostream & os, TOIProcessor /*const*/ & toip)
|
---|
[1437] | 204 | { toip.PrintStatus(os); return os; }
|
---|
| 205 |
|
---|
| 206 |
|
---|
[1365] | 207 | #endif
|
---|
[1437] | 208 |
|
---|
[2187] | 209 |
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 |
|
---|
| 213 |
|
---|
| 214 |
|
---|
| 215 |
|
---|