Changeset 1437 in Sophya


Ignore:
Timestamp:
Mar 12, 2001, 7:00:28 PM (25 years ago)
Author:
ansari
Message:

Protections diverses dans TOIProcessor et FITSTOIReader/Writer
Ajout d'un TOI (TOISeqBuffered) avec gestion d'un buffer entre put/get
Ajout de processeurs de test (RZTOIProc...) , programme test associe
et SMakefile (pour compil avec SOPHYA)

Reza 12/3/2001

Location:
trunk/ArchTOIPipe
Files:
7 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/ArchTOIPipe/Kernel/fitstoirdr.cc

    r1367 r1437  
    103103    //    if (sn < mgr->getRequestedBegin()+10) cout << "rdr out " << sn << endl;
    104104    for (int j=1; j<=ncols; j++) {
     105      if ( !checkOutputTOIIndex(j-1) )  continue;  // Reza - Si TOI non connecte
    105106      fits_lock();
    106107      fits_read_col_dbl(fptr,j+1,i+1,1,1,0,&y,&anyNul,&fstatus);
  • trunk/ArchTOIPipe/Kernel/fitstoiwtr.cc

    r1410 r1437  
    9292      fits_unlock();
    9393      for (int i=0; i<ndata; i++) {
    94         double x = getData(i, sn);
     94        double x = -9.e19;  // $CHECK$ - Reza valeur par defaut !
     95        if (checkInputTOIIndex(i)) x = getData(i, sn);
    9596        fits_lock();
    9697        if (outFlags) {
    9798          fits_write_col_dbl(fptr, 2*i+2, fitsLine, 1, 1, &x, &fstatus);
    98           x = getFlag(i, sn);
     99          if (checkInputTOIIndex(i))   x = getFlag(i, sn);
     100          else x = -9.e19;  // $CHECK$ - Reza valeur par defaut !
    99101          fits_write_col_dbl(fptr, 2*i+3, fitsLine, 1, 1, &x, &fstatus);
    100102        } else {
  • trunk/ArchTOIPipe/Kernel/toi.cc

    r1370 r1437  
    2525void TOI::TOIInit() {
    2626  pthread_mutex_init(&mutex, NULL);
     27  //   ----- Rajouts Reza 12/3/2001
     28  pthread_cond_init(&condv, NULL);
     29  fgwaitput = fgwaitget = false;
     30  fgsigput = fgsigget = false;
     31  countwaitput = countwaitget = 0;
     32  //  Fin rajouts Reza 12/3/2001 ------
    2733//  pthread_mutex_setname_np(&mutex, (name + "_toi_mutex").c_str(), 0);
    2834  defaultValue = 0;
     
    3541}
    3642
     43void TOI::PrintStatus(ostream & os) const
     44{
     45  os << "TOI::PrintStatus() - Name=" << getName() << endl;
     46  os << " WaitStatus: Put/" ;
     47  if (isPutWaiting()) os << "Waiting " ;
     48  else os << "Running ";
     49  os << " PutCountWait= " << getCountWaitPut() << endl;
     50  os << " WaitStatus: Get/" ;
     51  if (isGetWaiting()) os << "Waiting " ;
     52  else os << "Running ";
     53  os << " GetCountWait= " << getCountWaitGet() << endl;
     54}
     55
     56
    3757void TOI::setProducer(TOIProcessor* p) {
    3858  if (producer)
     
    7696  Array a = doGetData(iStart, iEnd);
    7797  unlock();
     98  if (fgsigput) { fgsigput = false; broadcast(); }
    7899  return a;
    79100}
     
    84105  double dat = doGetData(i);
    85106  unlock();
     107  if (fgsigput) { fgsigput = false; broadcast(); }
    86108  return dat;
    87109}
     
    93115  TArray<int_4> a = doGetFlag(iStart, iEnd);
    94116  unlock();
     117  if (fgsigput) { fgsigput = false; broadcast(); }
    95118  return a;
    96119}
     
    101124  int_4 f = doGetFlag(i);
    102125  unlock();
     126  if (fgsigput) { fgsigput = false; broadcast(); }
    103127  return f;
    104128}
     
    110134  doPutData(i, value, flag);
    111135  unlock();
     136  if (fgsigget) { fgsigget = false; broadcast(); }
    112137}
    113138
  • trunk/ArchTOIPipe/Kernel/toi.h

    r1365 r1437  
    2626  TOI(string name);
    2727  virtual ~TOI();
     28
     29  //   ----- Rajouts Reza 12/3/2001
     30  virtual void PrintStatus(ostream & os) const;
     31  //  Fin rajouts Reza 12/3/2001 ------
    2832
    2933#ifdef WITH_SOPHYA
     
    5559
    5660  void setName(string n) {name =n;}
    57   string getName() {return name;}
     61  string getName() const {return name;}
    5862
    5963protected:
    6064  TOI*                  errorTOI;
    6165  pthread_mutex_t       mutex;
     66  //   ----- Rajouts Reza 12/3/2001
     67  pthread_cond_t        condv;
     68  bool                  fgwaitput;
     69  bool                  fgwaitget;
     70  bool                  fgsigput;
     71  bool                  fgsigget;
     72  int                   countwaitput;
     73  int                   countwaitget;
     74  //  Fin rajouts Reza 12/3/2001 ------
     75
    6276  TOIProcessor*         producer;
    6377  vector<TOIProcessor*> consumers;
     
    86100  void  TOIInit();
    87101
     102  // Il faut faire attention avec mutex et condv, si TOI cree sur le stack !
     103  // Il faut donc faire new TOI  -    Reza 11/3/2001
    88104  void lock() {pthread_mutex_lock(&mutex);}
    89105  void unlock() {pthread_mutex_unlock(&mutex);}
    90106
     107  //   ----- Rajouts Reza 12/3/2001
     108  void wait() {pthread_cond_wait(&condv, &mutex);}
     109  void signal() {pthread_cond_signal(&condv);}
     110  void broadcast() {pthread_cond_broadcast(&condv);}
     111  inline void waitPut()
     112    {fgwaitput=true; countwaitput++; pthread_cond_wait(&condv, &mutex);}
     113  inline void waitGet()
     114    {fgwaitget=true; countwaitget++; pthread_cond_wait(&condv, &mutex);}
     115  inline bool isPutWaiting() const { return fgwaitput; }
     116  inline bool isGetWaiting() const { return fgwaitget; }
     117  inline void signalPut() {fgsigput=true;}
     118  inline void signalGet() {fgsigget=true;}
     119  inline void cleanWaitPut() { fgsigput = fgwaitput = false; }
     120  inline void cleanWaitGet() { fgsigget = fgwaitget = false; }
     121
     122public:
     123  inline int  getCountWaitPut() const { return countwaitput; }
     124  inline int  getCountWaitGet() const { return countwaitget; }
     125  //  Fin rajouts Reza 12/3/2001 ------
     126
    91127};
     128
     129inline ostream & operator << (ostream & os, TOI const & toi)
     130{ toi.PrintStatus(os); return os; }
    92131
    93132class TOIRegular : public TOI {
     
    101140  TOIRegularWindow();
    102141  TOIRegularWindow(string nm);
    103   ~TOIRegularWindow();
     142  virtual ~TOIRegularWindow();
    104143
    105144  virtual DataStatus isDataAvailNL(int iStart, int iEnd);
     
    112151  long          i0;
    113152  double defaultValue;
    114   
     153 
    115154#ifdef WITH_SOPHYA
    116155  virtual Array         doGetData(int iStart, int iEnd);
  • trunk/ArchTOIPipe/Kernel/toiprocessor.cc

    r1367 r1437  
    4444
    4545void TOIProcessor::afterinit() {
     46  int i;
    4647  inTOIs = new (TOI*[inIx.size()]);
     48  for(i=0; i<inIx.size(); i++)
     49    inTOIs[i] = NULL;
    4750  outTOIs = new (TOI*[outIx.size()]);
     51  for(i=0; i<outIx.size(); i++)
     52    outTOIs[i] = NULL;
    4853}
    4954
     
    123128}
    124129
     130//  Methodes rajoutees par Reza 11/3/2001
     131TOI* TOIProcessor::getInputTOI(int toiIndex) {
     132  //  chkinit();
     133  if (toiIndex >= inIx.size())
     134    throw RangeCheckError("TOIProcessor::getInputTOI() out of bound toiIndex");
     135  TOI* toi = inTOIs[toiIndex];
     136  if (toi == NULL)
     137    throw NullPtrError("TOIProcessor::getInputTOI() - Not assigned TOI !");
     138  return(toi);
     139}
     140
     141TOI* TOIProcessor::getOutputTOI(int toiIndex) {
     142  //  chkinit();
     143  if (toiIndex >= outIx.size())
     144    throw RangeCheckError("TOIProcessor::getOutputTOI() out of bound toiIndex");
     145  TOI* toi = outTOIs[toiIndex];
     146  if (toi == NULL)
     147    throw NullPtrError("TOIProcessor::getOutputTOI() - Not assigned TOI !");
     148  return(toi);
     149}
     150
     151bool TOIProcessor::checkInputTOIIndex(int toiIndex) {
     152  if (toiIndex >= inIx.size()) return false;
     153  if (inTOIs[toiIndex] == NULL) return false;
     154  return true;
     155}
     156
     157bool TOIProcessor::checkOutputTOIIndex(int toiIndex) {
     158  if (toiIndex >= outIx.size()) return false;
     159  if (outTOIs[toiIndex] == NULL) return false;
     160  return true;
     161}
     162
     163void TOIProcessor::PrintStatus(ostream & os)
     164{
     165  os << " TOIProcessor::PrintStatus() - Name= " << name
     166     << " MinIn=" << getMinIn() << " MaxIn=" << getMaxIn() << endl;
     167  os << " --- Inputs N= " << inIx.size() << endl;
     168  int k;
     169  for(k=0; k<inIx.size(); k++) {
     170    os << "Input[" << k << "] : " <<  getInName(k) ;
     171    if (inTOIs[k] != NULL)
     172      os << " Connected TOI " << inTOIs[k]->getName() << endl;
     173    else os << " NO TOI " << endl;
     174  }
     175  os << " --- Outputs N= " << outIx.size() << endl;
     176  for(k=0; k<outIx.size(); k++) {
     177    os << "Output[" << k << "] : " <<  getOutName(k) ;
     178    if (outTOIs[k] != NULL)
     179      os << " Connected TOI " << outTOIs[k]->getName() << endl;
     180    else os << " NO TOI " << endl;
     181  }
     182  os << endl;
     183  return;
     184}
     185
     186//  Fin rajout Reza 11/3/2001
     187
    125188void TOIProcessor::addInput(string name, TOI* toi) {
    126189  chkinit();
     
    143206  if (i > outIx.size()) throw RangeCheckError("TOIProcessor::getOutName "
    144207                                             " out of bound");
    145   map<string, int>::iterator j = outIx.begin();
    146   while (i) {i--; j++;};
    147   return (*j).first;
     208  map<string, int>::iterator j;
     209  for(j=outIx.begin(); j!= outIx.end(); j++)
     210    if ((*j).second == i)  return (*j).first;
     211
     212  throw RangeCheckError("TOIProcessor::getOutName  Not found index !");
    148213}
    149214
     
    151216  if (i > inIx.size()) throw RangeCheckError("TOIProcessor::getInName "
    152217                                             " out of bound");
    153   map<string, int>::iterator j = inIx.begin();
    154   while (i) {i--; j++;};
    155   return (*j).first;
     218  map<string, int>::iterator j;
     219  for(j=inIx.begin(); j!= inIx.end(); j++)
     220    if ((*j).second == i)  return (*j).first;
     221
     222  throw RangeCheckError("TOIProcessor::getOutName  Not found index !");
    156223}
    157224
     
    189256#ifndef NO_SOPHYA
    190257Array TOIProcessor::getData(int toiIndex, int iStart, int iEnd) {
    191   TOI* toi = inTOIs[toiIndex];
     258  TOI* toi = getInputTOI(toiIndex);
    192259  toi->waitForData(iStart, iEnd);
    193260  return toi->getData(iStart, iEnd);
     
    195262
    196263Array TOIProcessor::getError(int toiIndex, int iStart, int iEnd) {
    197   TOI* toi = inTOIs[toiIndex];
     264  TOI* toi = getInputTOI(toiIndex);
    198265  toi->waitForData(iStart, iEnd);
    199266  return toi->getError(iStart, iEnd);
     
    201268
    202269TArray<int_4> TOIProcessor::getFlag(int toiIndex, int iStart, int iEnd) {
    203   TOI* toi = inTOIs[toiIndex];
     270  TOI* toi = getInputTOI(toiIndex);
    204271  toi->waitForData(iStart, iEnd);
    205272  return toi->getFlag(iStart, iEnd);
     
    208275
    209276double TOIProcessor::getData(int toiIndex, int i) {
    210   TOI* toi = inTOIs[toiIndex];
     277  TOI* toi = getInputTOI(toiIndex);
    211278  toi->waitForData(i);
    212279  return toi->getData(i);
     
    214281
    215282double TOIProcessor::getError(int toiIndex, int i) {
    216   TOI* toi = inTOIs[toiIndex];
     283  TOI* toi = getInputTOI(toiIndex);
    217284  toi->waitForData(i);
    218285  return toi->getError(i);
     
    220287
    221288int_4 TOIProcessor::getFlag(int toiIndex, int i) {
    222   TOI* toi = inTOIs[toiIndex];
     289  TOI* toi = getInputTOI(toiIndex);
    223290  toi->waitForData(i);
    224291  return toi->getFlag(i);
     
    257324
    258325void TOIProcessor::putData(int toiIndex, int i, double value, int_4 flg) {
    259   TOI* toi = outTOIs[toiIndex];
     326  TOI* toi = getOutputTOI(toiIndex);
    260327  toi->putData(i, value, flg);
    261328  autoWontNeed(i);
     
    266333void TOIProcessor::putDataError(int toiIndex, int i, double value,
    267334                                double error, int_4 flg) {
    268   TOI* toi = outTOIs[toiIndex];
     335  TOI* toi = getOutputTOI(toiIndex);
     336  if (toi == NULL)
     337    throw NullPtrError("TOIProcessor::putDataError() - Not assigned TOI !");
    269338  toi->putDataError(i, value, error, flg);
    270339  autoWontNeed(i);
  • trunk/ArchTOIPipe/Kernel/toiprocessor.h

    r1410 r1437  
    8383  int           getInputTOIIndex(string toi);
    8484  int           getOutputTOIIndex(string toi);
     85
     86  //  Methodes rajoutees par Reza 11/3/2001
     87  TOI*          getInputTOI(int toiIndex);
     88  TOI*          getOutputTOI(int toiIndex);
     89  bool          checkInputTOIIndex(int toiIndex);
     90  bool          checkOutputTOIIndex(int toiIndex);
     91
     92  //  Fin rajout Reza 11/3/2001
     93
    8594  void          autoWontNeed(int iCur);
    8695  int           lastAWN;
     
    96105  string getOutName(int i);
    97106  string getInName(int i);
     107
     108  //  Methodes rajoutees par Reza 11/3/2001
     109  void          PrintStatus(ostream & os) ; // const plus tard
     110  //  Fin rajout Reza 11/3/2001
    98111
    99112  virtual void  start();
     
    136149};
    137150
     151inline ostream & operator << (ostream & os, TOIProcessor /*const*/ & toip)
     152{ toip.PrintStatus(os); return os; }
     153
     154
    138155#endif
     156
  • trunk/ArchTOIPipe/TestPipes/fits2asc.cc

    r1368 r1437  
    55#include "asciitoiwtr.h"
    66
    7 void main(int argc, char** argv) {
     7int main(int argc, char** argv) {
    88  TOIManager* mgr = TOIManager::getManager();
    99  //  mgr->setRequestedSample(11680920,11710584);
     
    2626
    2727  mgr->joinAll();
     28
     29  return(0);
    2830}
  • trunk/ArchTOIPipe/TestPipes/tsttoi.cc

    r1365 r1437  
    3333  cout << "joining" << endl;
    3434  mgr->joinAll();
     35  return(0);
    3536}
  • trunk/ArchTOIPipe/TestPipes/tsttoi2.cc

    r1370 r1437  
    66#include "toimanager.h"
    77
    8 void main(int argc, char** argv) {
     8int main(int argc, char** argv) {
    99  cout << "tsttoi starting" << endl;
    1010  TOIManager* mgr = TOIManager::getManager();
     
    2323
    2424  mgr->joinAll();
     25
     26  return(0);
    2527}
Note: See TracChangeset for help on using the changeset viewer.