source: Sophya/trunk/ArchTOIPipe/Kernel/toiprocessor.h@ 1787

Last change on this file since 1787 was 1787, checked in by aubourg, 24 years ago

parallel mapmaking

File size: 4.6 KB
Line 
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.17 2001-11-26 15:13:48 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"
24using namespace SOPHYA;
25#endif
26
27#include "toi.h"
28
29
30class TOIProcessor {
31public:
32 virtual void init();
33 // Les methodes qui suivent peuvent etre appelees par init
34protected:
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
47public:
48 virtual void run();
49 // Les methodes qui suivent peut etre appelees par run
50protected:
51#ifndef NO_SOPHYA
52 /* ---- l'interface va etre modifiee, NE PAS UTILISER
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);
56 l'interface va etre modifiee, NE PAS UTILISER ---- */
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);
63 void getData(int toiIndex, int i, double &data, uint_8 &flag);
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);
67
68 //RZCMV double getError(int toiIndex, int i);
69 //RZCMV int_4 getFlag(int toiIndex, int i);
70
71 void wontNeedBefore(int i);
72 int wontNeedValue;
73 void setNeededHistory(int nsamples); // -1 : disable
74
75 void putData(int toiIndex, int i, double value, uint_8 flag=0);
76 //RZCMV void putDataError(int toiIndex, int i, double value,
77 //RZCMV double error, int_4 flag=0);
78
79 void putData(int toiIndex, int i, int n, double const* val,
80 uint_8 const* flg=0);
81
82 // Gestion des bornes pour les transformations de TOIs...
83 virtual int calcMinOut(); // Protected ?
84 virtual int calcMaxOut(); // Protected ?
85
86 virtual int getMinOut();
87 virtual int getMaxOut();
88 int minOut; // Cache for calcMinOut() value. Protected ?
89 int maxOut; // Cache for calcMaxOut() value. Protected ?
90
91 virtual int getMinIn();
92 virtual int getMaxIn();
93 // Implementation par defaut
94 int upExtra; // MaxIn - MaxOut : extra samples for processing
95 int lowExtra; // MinOut - MinIn : extra samples for processing
96
97 int forcedMinIn; // to process a subset of data
98 int forcedMaxIn; // to process a subset of data
99 void setSampleSubset(int min, int max);
100
101 int neededHistory;
102
103protected:
104 int getInputTOIIndex(string toi);
105 int getOutputTOIIndex(string toi);
106
107 // Methodes rajoutees par Reza 11/3/2001
108 TOI* getInputTOI(int toiIndex);
109 TOI* getOutputTOI(int toiIndex);
110 bool checkInputTOIIndex(int toiIndex);
111 bool checkOutputTOIIndex(int toiIndex);
112
113 // Fin rajout Reza 11/3/2001
114
115 void autoWontNeed(int iCur);
116 int lastAWN;
117
118public:
119 // Appele par les assembleurs de pipeline
120 virtual void addInput(string name, TOI* toi);
121 virtual void addOutput(string name, TOI* toi);
122
123
124 int getNIn() {chkinit(); return inIx.size();}
125 int getNOut() {chkinit(); return outIx.size();}
126 string getOutName(int i);
127 string getInName(int i);
128
129 // Methodes rajoutees par Reza 11/3/2001
130 virtual void PrintStatus(::ostream & os) ; // const plus tard
131 // Fin rajout Reza 11/3/2001
132
133 virtual void start();
134
135 TOIProcessor();
136 virtual ~TOIProcessor();
137
138protected:
139
140 map<string, int> inIx;
141 map<string, int> outIx;
142 TOI** inTOIs;
143 TOI** outTOIs;
144
145 string name;
146 // Thread handling
147 pthread_t thread;
148 pthread_cond_t dataReady;
149 pthread_mutex_t mutex;
150 pthread_mutexattr_t mutattr;
151
152 void lock() {
153 pthread_mutex_lock(&mutex);
154 }
155
156 void unlock() {
157 pthread_mutex_unlock(&mutex);
158 }
159
160 void wait() {
161 pthread_cond_wait(&dataReady, &mutex);
162 }
163
164 void notify();
165
166
167 friend class TOI;
168
169 static void* ThreadStart(void *);
170 void warnPutDone();
171};
172
173inline ::ostream & operator << (::ostream & os, TOIProcessor /*const*/ & toip)
174{ toip.PrintStatus(os); return os; }
175
176
177#endif
178
Note: See TracBrowser for help on using the repository browser.