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

Last change on this file since 1365 was 1365, checked in by aubourg, 25 years ago

pipeline TOI archeops

File size: 2.8 KB
Line 
1// This may look like C code, but it is really -*- C++ -*-
2
3
4#ifndef TOIPROCESSOR_H
5#define TOIPROCESSOR_H
6
7#include "config.h"
8
9#include <pthread.h>
10
11#include <string>
12#include <map>
13#include <iostream>
14
15#ifndef NO_SOPHYA
16#include "tarray.h"
17using namespace SOPHYA;
18#endif
19
20#include "toi.h"
21
22
23class TOIProcessor {
24public:
25 virtual void init();
26 // Les methodes qui suivent peuvent etre appelees par init
27protected:
28 int declareInput(string toi);
29 int declareOutput(string toi);
30
31 // void declareMultInput(string toi);
32 // Question : multiple output ?
33
34 void chkinit() {
35 if (!inited) {init(); afterinit(); inited=true;}
36 }
37 bool inited;
38 virtual void afterinit();
39
40public:
41 virtual void run();
42 // Les methodes qui suivent peut etre appelees par run
43protected:
44#ifndef NO_SOPHYA
45 Array getData(int toiIndex, int iStart, int iEnd);
46 Array getError(int toiIndex, int iStart, int iEnd);
47 TArray<int_4> getFlag(int toiIndex, int iStart, int iEnd);
48#endif
49 // si multiple input (indexed input), tableau 2D.
50
51 // Les methodes qui suivent ne peuvent etre
52 // utilisees que sur des entrees simples
53 double getData(int toiIndex, int i);
54 double getError(int toiIndex, int i);
55 int_4 getFlag(int toiIndex, int i);
56
57 void wontNeedBefore(int i);
58 int wontNeedValue;
59 void setNeededHistory(int nsamples); // -1 : disable
60
61 void putData(int toiIndex, int i, double value, int_4 flag=0);
62 void putDataError(int toiIndex, int i, double value,
63 double error, int_4 flag=0);
64
65 // Gestion des bornes pour les transformations de TOIs...
66 virtual int calcMinOut();
67 virtual int calcMaxOut();
68
69 virtual int getMinOut();
70 virtual int getMaxOut();
71 int minOut;
72 int maxOut;
73
74 virtual int getMinIn();
75 virtual int getMaxIn();
76 // Implementation par defaut
77 int upExtra;
78 int lowExtra;
79
80 int neededHistory;
81
82protected:
83 int getInputTOIIndex(string toi);
84 int getOutputTOIIndex(string toi);
85 void autoWontNeed(int iCur);
86 int lastAWN;
87
88public:
89 // Appele par les assembleurs de pipeline
90 virtual void addInput(string name, TOI* toi);
91 virtual void addOutput(string name, TOI* toi);
92
93 virtual void start();
94
95 TOIProcessor();
96 virtual ~TOIProcessor();
97
98protected:
99
100 map<string, int> inIx;
101 map<string, int> outIx;
102 TOI** inTOIs;
103 TOI** outTOIs;
104
105 string name;
106 // Thread handling
107 pthread_t thread;
108 pthread_cond_t dataReady;
109 pthread_mutex_t mutex;
110 pthread_mutexattr_t mutattr;
111
112 void lock() {
113 pthread_mutex_lock(&mutex);
114 }
115
116 void unlock() {
117 pthread_mutex_unlock(&mutex);
118 }
119
120 void wait() {
121 pthread_cond_wait(&dataReady, &mutex);
122 }
123
124 void notify();
125
126
127 friend class TOI;
128
129 static void* ThreadStart(void *);
130};
131
132#endif
Note: See TracBrowser for help on using the repository browser.