source: Sophya/trunk/ArchTOIPipe/Kernel/toi.cc@ 2228

Last change on this file since 2228 was 2187, checked in by aubourg, 23 years ago

Vivien, limites processors et connect

File size: 5.2 KB
RevLine 
[1738]1// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
2// Eric Aubourg
3// Christophe Magneville
4// Reza Ansari
[2187]5// $Id: toi.cc,v 1.12 2002-09-09 15:33:14 aubourg Exp $
[1738]6
[1365]7#include "toiprocessor.h"
8#include "toi.h"
9#include <pthread.h>
10
11#ifdef WITH_SOPHYA
12#include "pexceptions.h"
13#else
14#include "apexceptions.h"
15#endif
16
17
18TOI::TOI() {
19 TOIInit();
20}
21
22TOI::TOI(string n) {
23 name = n;
24 TOIInit();
25}
26
27void TOI::TOIInit() {
28 pthread_mutex_init(&mutex, NULL);
[1437]29 // ----- Rajouts Reza 12/3/2001
30 pthread_cond_init(&condv, NULL);
31 fgwaitput = fgwaitget = false;
32 fgsigput = fgsigget = false;
33 countwaitput = countwaitget = 0;
34 // Fin rajouts Reza 12/3/2001 ------
[1365]35// pthread_mutex_setname_np(&mutex, (name + "_toi_mutex").c_str(), 0);
36 defaultValue = 0;
37 producer = NULL;
38 dbg = false;
[1740]39 syncOldWay = true;
[1365]40}
41
42TOI::~TOI() {
43 pthread_mutex_destroy(&mutex);
44}
45
[1762]46void TOI::PrintStatus(::ostream & os) const
[1437]47{
48 os << "TOI::PrintStatus() - Name=" << getName() << endl;
49 os << " WaitStatus: Put/" ;
50 if (isPutWaiting()) os << "Waiting " ;
51 else os << "Running ";
52 os << " PutCountWait= " << getCountWaitPut() << endl;
53 os << " WaitStatus: Get/" ;
54 if (isGetWaiting()) os << "Waiting " ;
55 else os << "Running ";
56 os << " GetCountWait= " << getCountWaitGet() << endl;
57}
58
59
[1365]60void TOI::setProducer(TOIProcessor* p) {
61 if (producer)
62 throw DuplicateIdExc("TOI::setProducer : producer already defined");
63 producer = p;
64}
65
66void TOI::addConsumer(TOIProcessor* p) {
67 consumers.push_back(p);
68}
69
70int TOI::getMinSn(){
71 return producer->getMinOut();
72}
73
74int TOI::getMaxSn(){
75 return producer->getMaxOut();
76}
77
[2187]78
79// ajout vf 31/07/2002
80bool TOI::checkSampleLimits(long& Min, long& Max, int pass)
81{
82 // propagation de la sortie du TOI vers son entree pour test des limites
83 return producer->checkSampleLimits(Min, Max, pass);
84}
85
86
87// fin ajout vf
88
89
90
91
92
93
94
95
[1464]96/*
97 RZCMV ----- l'interface va etre modifiee, NE PAS UTILISER
98#ifndef NO_SOPHYA
[1365]99Array TOI::getError(int iStart, int iEnd) {
100 if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
[1464]101 return errorTOI->getData(iStart, iEnd);
[1365]102}
[1464]103Array TOI::getData(int iStart, int iEnd) {
104 lock();
105 Array a = doGetData(iStart, iEnd);
106 unlock();
107 if (fgsigput) { fgsigput = false; broadcast(); }
108 return a;
109}
110TArray<int_4> TOI::getFlag(int iStart, int iEnd) {
111 lock();
112 TArray<int_4> a = doGetFlag(iStart, iEnd);
113 unlock();
114 if (fgsigput) { fgsigput = false; broadcast(); }
115 return a;
116}
[1365]117#endif
[1464]118 l'interface va etre modifiee, NE PAS UTILISER ----
119*/
[1365]120
[1464]121
122/*
123RZCMV ------- A revoir les getError() ...
[1365]124double TOI::getError(int i) {
125 if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
126 return errorTOI->getData(i);
127}
128
129void TOI::putDataError(int i, double value, double error, int_4 flag) {
130 if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
131 putData(i, value, flag);
132 errorTOI->putData(i, value, flag);
133}
134
[1462]135*/
136
[1742]137double TOI::getData(int i) { /* deprecated, overriden in toisegment */
[1365]138 lock();
[1532]139 uint_8 flg;
[1462]140 double dat;
141 doGetData(i, dat, flg);
[1365]142 unlock();
[1437]143 if (fgsigput) { fgsigput = false; broadcast(); }
[1365]144 return dat;
145}
146
[1742]147void TOI::getData(int i, double &data, uint_8 &flag) { /* deprecated, overriden in toisegment */
[1462]148 lock();
149 doGetData(i, data, flag);
150 unlock();
151 if (fgsigput) { fgsigput = false; broadcast(); }
152 return;
153}
[1365]154
[1742]155void TOI::getData(int i, int n, double* data, uint_8* flg) {
156 cerr << "TOI::getData [double*] unimplemented" << endl;
157 exit(-1);
158}
[1365]159
[1742]160void TOI::putData(int i, int n, double const* var, uint_8 const* flg) {
161 cerr << "TOI::putData [double*] unimplemented" << endl;
162 exit(-1);
163}
164
165void TOI::putData(int i, double value, uint_8 flag) { /* deprecated, overriden in toisegment */
[1365]166 lock();
167 doPutData(i, value, flag);
168 unlock();
[1437]169 if (fgsigget) { fgsigget = false; broadcast(); }
[1365]170}
171
[1742]172void TOI::waitForData(int iStart, int iEnd) { /* deprecated, overriden in toisegment */
[1365]173 if (producer == NULL) throw NotFoundExc("TOI has no producer !");
174
175 DataStatus s = isDataAvail(iStart, iEnd);
176 if (s == DATA_OK) {
177 return;
178 }
179 if (s == DATA_DELETED) {
180 throw NotFoundExc("Data has been purged !");
181 }
182
183 producer->lock();
184 while (isDataAvailNL(iStart, iEnd) == DATA_NOT_YET) {
185 producer->wait();
186 }
187 producer->unlock();
188 return;
189}
190
[1742]191void TOI::waitForData(int i) { /* deprecated, overriden in toisegment */
[1365]192 waitForData(i,i);
193}
194
[1742]195void TOI::waitForAnyData() { /* deprecated, overriden in toisegment */
[1365]196 if (! hasSomeData()) {
197 producer->lock();
198 producer->wait();
199 producer->unlock();
200 }
201}
202
203TOI::DataStatus TOI::isDataAvail(int i) {
204 lock();
205 DataStatus stat = isDataAvailNL(i);
206 unlock();
207 return stat;
208}
209
210TOI::DataStatus TOI::isDataAvail(int i, int j) {
211 lock();
212 DataStatus stat = isDataAvailNL(i,j);
213 unlock();
214 return stat;
215}
216
217TOI::DataStatus TOI::isDataAvailNL(int i) {
218 return isDataAvailNL(i,i);
219}
220
[1742]221void TOI::wontNeedBefore(int i) { /* deprecated, overriden in toisegment */
[1365]222 int j=i;
223 for (vector<TOIProcessor*>::iterator k = consumers.begin();
224 k != consumers.end(); k++) {
225 if ((*k)->wontNeedValue < j) j = (*k)->wontNeedValue;
226 }
227 lock();
228 doWontNeedBefore(j);
229 unlock();
230}
231
232void TOI::doWontNeedBefore(int i) {
233}
234
235
[2187]236
237
238
239
240
241
242
243
244
245
246
247
248
Note: See TracBrowser for help on using the repository browser.