| 1 | // This may look like C code, but it is really -*- C++ -*-
 | 
|---|
| 2 | 
 | 
|---|
| 3 | // ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL
 | 
|---|
| 4 | //                               Eric Aubourg
 | 
|---|
| 5 | //                               Christophe Magneville
 | 
|---|
| 6 | //                               Reza Ansari
 | 
|---|
| 7 | // $Id: toiprocessor.h,v 1.21 2003-10-13 20:48:37 aubourg Exp $
 | 
|---|
| 8 | 
 | 
|---|
| 9 | 
 | 
|---|
| 10 | 
 | 
|---|
| 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>
 | 
|---|
| 20 | #include <iostream.h>
 | 
|---|
| 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 | 
 | 
|---|
| 50 |   virtual long  getMinOut();
 | 
|---|
| 51 |   virtual long  getMaxOut();
 | 
|---|
| 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 | 
 | 
|---|
| 69 |   // Les methodes qui suivent peut etre appelees par run
 | 
|---|
| 70 | protected:
 | 
|---|
| 71 | #ifndef NO_SOPHYA
 | 
|---|
| 72 |   /* ---- l'interface va etre modifiee, NE PAS UTILISER
 | 
|---|
| 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);
 | 
|---|
| 76 |           l'interface va etre modifiee, NE PAS UTILISER ---- */
 | 
|---|
| 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
 | 
|---|
| 82 |   double        getData(int toiIndex, long i);
 | 
|---|
| 83 |   void          getData(int toiIndex, long i, double &data, uint_8 &flag);
 | 
|---|
| 84 | 
 | 
|---|
| 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);
 | 
|---|
| 87 |   
 | 
|---|
| 88 |   //RZCMV  double        getError(int toiIndex, long i);
 | 
|---|
| 89 |   //RZCMV  int_4         getFlag(int toiIndex, long i);
 | 
|---|
| 90 | 
 | 
|---|
| 91 |   void          wontNeedBefore(long i);
 | 
|---|
| 92 |   long           wontNeedValue;
 | 
|---|
| 93 |   void          setNeededHistory(long nsamples); // -1 : disable
 | 
|---|
| 94 | 
 | 
|---|
| 95 |   void          putData(int toiIndex, long i, double value, uint_8 flag=0);
 | 
|---|
| 96 |   //RZCMV  void          putDataError(int toiIndex, long i, double value, 
 | 
|---|
| 97 |   //RZCMV                            double error, int_4 flag=0);
 | 
|---|
| 98 | 
 | 
|---|
| 99 |   void          putData(int toiIndex, long i, long n, double const* val,
 | 
|---|
| 100 |                         uint_8 const* flg=0);
 | 
|---|
| 101 | 
 | 
|---|
| 102 |   // Gestion des bornes pour les transformations de TOIs...
 | 
|---|
| 103 | public:  
 | 
|---|
| 104 |   // Methodes passees en public par Reza, 14/5/2002
 | 
|---|
| 105 |   virtual long   calcMinOut(); // Protected ?
 | 
|---|
| 106 |   virtual long   calcMaxOut(); // Protected ?
 | 
|---|
| 107 | 
 | 
|---|
| 108 |   virtual long   getMinIn();
 | 
|---|
| 109 |   virtual long   getMaxIn();
 | 
|---|
| 110 | protected:
 | 
|---|
| 111 |   // Implementation par defaut
 | 
|---|
| 112 |   long           minOut;    // Cache for calcMinOut() value. Protected ?
 | 
|---|
| 113 |   long           maxOut;    // Cache for calcMaxOut() value. Protected ?
 | 
|---|
| 114 | 
 | 
|---|
| 115 |   int           upExtra;  // MaxIn - MaxOut : extra samples for processing
 | 
|---|
| 116 |   int           lowExtra; // MinOut - MinIn : extra samples for processing
 | 
|---|
| 117 | 
 | 
|---|
| 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);
 | 
|---|
| 121 | 
 | 
|---|
| 122 |   int           neededHistory;
 | 
|---|
| 123 | 
 | 
|---|
| 124 | protected:
 | 
|---|
| 125 |   int           getInputTOIIndex(string toi);
 | 
|---|
| 126 |   int           getOutputTOIIndex(string toi);
 | 
|---|
| 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 | 
 | 
|---|
| 136 |   void          autoWontNeed(long iCur);
 | 
|---|
| 137 |   long           lastAWN;
 | 
|---|
| 138 | 
 | 
|---|
| 139 | 
 | 
|---|
| 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 | 
 | 
|---|
| 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 | 
 | 
|---|
| 151 |   //  Methodes rajoutees par Reza 11/3/2001
 | 
|---|
| 152 |   virtual void  PrintStatus(::ostream & os) ; // const plus tard
 | 
|---|
| 153 |   //  Fin rajout Reza 11/3/2001 
 | 
|---|
| 154 | 
 | 
|---|
| 155 |   virtual void  start();
 | 
|---|
| 156 |   
 | 
|---|
| 157 |   TOIProcessor();
 | 
|---|
| 158 |   virtual ~TOIProcessor();
 | 
|---|
| 159 |   
 | 
|---|
| 160 |   void setMinSn(long n) {forcedMinIn = n;}
 | 
|---|
| 161 |   void setMaxSn(long n) {forcedMaxIn = n;}
 | 
|---|
| 162 | 
 | 
|---|
| 163 |   // ajout vf 23/08/2002
 | 
|---|
| 164 |   TOI* getOutToi(string sortie);
 | 
|---|
| 165 | 
 | 
|---|
| 166 |   virtual void setName(string n) {name=n;}
 | 
|---|
| 167 | 
 | 
|---|
| 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 *);
 | 
|---|
| 200 |   void warnPutDone();
 | 
|---|
| 201 | };
 | 
|---|
| 202 | 
 | 
|---|
| 203 | inline ::ostream & operator << (::ostream & os, TOIProcessor /*const*/ & toip)
 | 
|---|
| 204 | { toip.PrintStatus(os); return os; }
 | 
|---|
| 205 | 
 | 
|---|
| 206 | 
 | 
|---|
| 207 | #endif
 | 
|---|
| 208 | 
 | 
|---|
| 209 | 
 | 
|---|
| 210 | 
 | 
|---|
| 211 | 
 | 
|---|
| 212 | 
 | 
|---|
| 213 | 
 | 
|---|
| 214 | 
 | 
|---|
| 215 | 
 | 
|---|