| 1 | #include <unistd.h>
 | 
|---|
| 2 | #include "toi.h"
 | 
|---|
| 3 | #include "toiprocessor.h"
 | 
|---|
| 4 | #include "fitstoirdr.h"
 | 
|---|
| 5 | #include "fitstoiwtr.h"
 | 
|---|
| 6 | #include "toimanager.h"
 | 
|---|
| 7 | #include "toisegment.h"
 | 
|---|
| 8 | #include "sophyainit.h"
 | 
|---|
| 9 | #include "ktoibad.h"
 | 
|---|
| 10 | #include "smoothtoi.h"
 | 
|---|
| 11 | #include <stdexcept>
 | 
|---|
| 12 | 
 | 
|---|
| 13 | void usage(void);
 | 
|---|
| 14 | void usage(void) {
 | 
|---|
| 15 |  cout<<"tstktoibad [-h] [options] fits_in fits_out"
 | 
|---|
| 16 |  <<" -s sdeb,sfin"
 | 
|---|
| 17 |  <<" -b label_bolomuv"
 | 
|---|
| 18 |  <<" -d vmin,vmax"
 | 
|---|
| 19 |  <<" -g lg,lm,nsg,bupd"
 | 
|---|
| 20 |  <<" -a lmaround"
 | 
|---|
| 21 |  <<" -S lsmooth,sdeg"
 | 
|---|
| 22 |  <<" -p lp,sn1,sn2"
 | 
|---|
| 23 |  <<endl;
 | 
|---|
| 24 | }
 | 
|---|
| 25 | 
 | 
|---|
| 26 | int main(int narg, char** arg)
 | 
|---|
| 27 | {
 | 
|---|
| 28 |  int_4 sdeb=0,sfin=-1;
 | 
|---|
| 29 |  int_4 lp=1,sn1=-1,sn2=-1;
 | 
|---|
| 30 |  uint_4 lg=3,lm=15,bupd=1000,lmaround=10;
 | 
|---|
| 31 |  uint_4 lsmooth=1024,sdeg=2;
 | 
|---|
| 32 |  r_8 nsg=5.;
 | 
|---|
| 33 |  r_8 vmin=1.,vmax=-1.;
 | 
|---|
| 34 |  char *label_bolomuv = "boloMuV";
 | 
|---|
| 35 |   int c;
 | 
|---|
| 36 |  while((c = getopt(narg,arg,"hs:g:d:b:a:S:p:")) != -1) {
 | 
|---|
| 37 |   switch (c) {
 | 
|---|
| 38 |   case 's' :
 | 
|---|
| 39 |    sscanf(optarg,"%d,%d",&sdeb,&sfin);
 | 
|---|
| 40 |    break;
 | 
|---|
| 41 |   case 'd' :
 | 
|---|
| 42 |    sscanf(optarg,"%lf,%lf",&vmin,&vmax);
 | 
|---|
| 43 |    break;
 | 
|---|
| 44 |   case 'g' :
 | 
|---|
| 45 |    sscanf(optarg,"%d,%d,%lf,%d",&lg,&lm,&nsg,&bupd);
 | 
|---|
| 46 |    break;
 | 
|---|
| 47 |   case 'a' :
 | 
|---|
| 48 |    sscanf(optarg,"%d",&lmaround);
 | 
|---|
| 49 |    break;
 | 
|---|
| 50 |   case 'S' :
 | 
|---|
| 51 |    sscanf(optarg,"%d,%d",&lsmooth,&sdeg);
 | 
|---|
| 52 |    break;
 | 
|---|
| 53 |   case 'b' :
 | 
|---|
| 54 |     label_bolomuv = optarg;
 | 
|---|
| 55 |     break;
 | 
|---|
| 56 |   case 'p' :
 | 
|---|
| 57 |    sscanf(optarg,"%d,%d,%d",&lp,&sn1,&sn2);
 | 
|---|
| 58 |    break;
 | 
|---|
| 59 |   case 'h' :
 | 
|---|
| 60 |   default:
 | 
|---|
| 61 |    usage(); exit(1);
 | 
|---|
| 62 |   }
 | 
|---|
| 63 |  }
 | 
|---|
| 64 |  if(optind+1>=narg) {usage(); exit(2);}
 | 
|---|
| 65 |  char * fitsin  = arg[optind];
 | 
|---|
| 66 |  char * fitsout = arg[optind+1];
 | 
|---|
| 67 | 
 | 
|---|
| 68 |  SophyaInit();
 | 
|---|
| 69 |  TOIManager* mgr = TOIManager::getManager();
 | 
|---|
| 70 |  if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin);
 | 
|---|
| 71 |  cout<<"Resquested sampleNum: "<<sdeb<<" , "<<sfin<<endl;
 | 
|---|
| 72 | 
 | 
|---|
| 73 | 
 | 
|---|
| 74 |  //--------------------------------------------------------------------
 | 
|---|
| 75 |  try {
 | 
|---|
| 76 |  //--------------------------------------------------------------------
 | 
|---|
| 77 | 
 | 
|---|
| 78 |  ////// Lecteurs / ecriveurs FITS
 | 
|---|
| 79 |  // FITS reader
 | 
|---|
| 80 |  FITSTOIReader rfits(fitsin);
 | 
|---|
| 81 |  cout<<"Lecteur: created"<<endl;
 | 
|---|
| 82 | 
 | 
|---|
| 83 |  // FITS writer
 | 
|---|
| 84 |  FITSTOIWriter wfits(fitsout);
 | 
|---|
| 85 |  cout<<"Ecriveur: created"<<endl;
 | 
|---|
| 86 | 
 | 
|---|
| 87 |  ////// TOI processeurs
 | 
|---|
| 88 |  FlagOutOfRange flgout(vmin,vmax);
 | 
|---|
| 89 |  flgout.Print();
 | 
|---|
| 90 | 
 | 
|---|
| 91 |  FlagGlitch deglitch(lg,lm,nsg);
 | 
|---|
| 92 |  deglitch.SetBuffUpd(bupd);
 | 
|---|
| 93 |  deglitch.SetDebug(lp,sn1,sn2);
 | 
|---|
| 94 |  deglitch.Print();
 | 
|---|
| 95 | 
 | 
|---|
| 96 |  FlagAroundFlag flgaround(lm);
 | 
|---|
| 97 |  //flgaround.SetLimits(vmin,vmax);
 | 
|---|
| 98 |  flgaround.Print();
 | 
|---|
| 99 | 
 | 
|---|
| 100 |  DataSmooth dsmooth(lsmooth,sdeg);
 | 
|---|
| 101 |  dsmooth.Print();
 | 
|---|
| 102 | 
 | 
|---|
| 103 |  ////// Creation des tuyaux et des connections associees
 | 
|---|
| 104 |  int taille = 8192;
 | 
|---|
| 105 | 
 | 
|---|
| 106 |  // tuyau bolo pour entree processeur FlagOutOfRange
 | 
|---|
| 107 |  TOISegmented * toi0 = new TOISegmented("tuyau_bolo_0",taille);
 | 
|---|
| 108 |  rfits.addOutput(label_bolomuv,toi0);
 | 
|---|
| 109 |  flgout.addInput("DataIn",toi0);
 | 
|---|
| 110 | 
 | 
|---|
| 111 |  // tuyau bolo pour entree processeur FlagGlitch
 | 
|---|
| 112 |  TOISegmented * toi1 = new TOISegmented("tuyau_bolo_1",taille);
 | 
|---|
| 113 |  flgout.addOutput("DataOut",toi1);
 | 
|---|
| 114 |  deglitch.addInput("DataIn",toi1);
 | 
|---|
| 115 | 
 | 
|---|
| 116 |  // tuyau bolo pour entree processeur FlagAround
 | 
|---|
| 117 |  TOISegmented * toi2 = new TOISegmented("tuyau_bolo_2",taille);
 | 
|---|
| 118 |  deglitch.addOutput("DataOut",toi2);
 | 
|---|
| 119 |  flgaround.addInput("DataIn",toi2);
 | 
|---|
| 120 | 
 | 
|---|
| 121 |  // tuyau bolo pour smooth DataSmooth et fits writer
 | 
|---|
| 122 |  TOISegmented * toi3 = new TOISegmented("tuyau_bolo_3",taille);
 | 
|---|
| 123 |  flgaround.addOutput("DataOut",toi3);
 | 
|---|
| 124 |  dsmooth.addInput("DataIn",toi3);
 | 
|---|
| 125 |  wfits.addInput(label_bolomuv,toi3,true);
 | 
|---|
| 126 | 
 | 
|---|
| 127 |  // tuyau bolo pour entree fits writer
 | 
|---|
| 128 |  TOISegmented * toi31 = new TOISegmented("tuyau_bolo_31",taille);
 | 
|---|
| 129 |  dsmooth.addOutput("DataSmooth",toi31);
 | 
|---|
| 130 |  wfits.addInput("smbolo",toi31,true);
 | 
|---|
| 131 | 
 | 
|---|
| 132 |  // Print de status avant lancement des taches:
 | 
|---|
| 133 |  cout<<"----- FITSReaderTOI::PrintStatus() 1 : -----"<<endl;
 | 
|---|
| 134 |  rfits.PrintStatus(cout);
 | 
|---|
| 135 |  cout<<"----- FITSWriterTOI::PrintStatus() : -----"<<endl;
 | 
|---|
| 136 |  wfits.PrintStatus(cout);  
 | 
|---|
| 137 |  cout<<"----- TOISegmented::PrintStatus() : -----"<<endl;
 | 
|---|
| 138 |  toi0->PrintStatus(cout);  
 | 
|---|
| 139 |  toi1->PrintStatus(cout);  
 | 
|---|
| 140 |  toi2->PrintStatus(cout);  
 | 
|---|
| 141 |  toi3->PrintStatus(cout);  
 | 
|---|
| 142 |  toi31->PrintStatus(cout);  
 | 
|---|
| 143 |  cout<<"-----FlagOutOfRange ::PrintStatus() : -----"<<endl;
 | 
|---|
| 144 |  flgout.PrintStatus(cout);  
 | 
|---|
| 145 |  cout<<"-----FlagGlitch ::PrintStatus() : -----"<<endl;
 | 
|---|
| 146 |  deglitch.PrintStatus(cout);  
 | 
|---|
| 147 |  cout<<"-----FlagAround ::PrintStatus() : -----"<<endl;
 | 
|---|
| 148 |  flgaround.PrintStatus(cout);  
 | 
|---|
| 149 |  cout<<"-----DataSmooth ::PrintStatus() : -----"<<endl;
 | 
|---|
| 150 |  dsmooth.PrintStatus(cout);  
 | 
|---|
| 151 | 
 | 
|---|
| 152 |  // Lancement des taches
 | 
|---|
| 153 | 
 | 
|---|
| 154 |  rfits.start();
 | 
|---|
| 155 |  wfits.start();
 | 
|---|
| 156 |  flgout.start();  
 | 
|---|
| 157 |  deglitch.start();
 | 
|---|
| 158 |  flgaround.start();  
 | 
|---|
| 159 |  dsmooth.start();  
 | 
|---|
| 160 | 
 | 
|---|
| 161 |  // Gestion de la re-connection des threads
 | 
|---|
| 162 |  mgr->joinAll();
 | 
|---|
| 163 |  cout<<"End threads"<<endl;
 | 
|---|
| 164 | 
 | 
|---|
| 165 |  //--------------------------------------------------------------------
 | 
|---|
| 166 |  // Que fait on avec les exceptions qui ont ete lancees ?
 | 
|---|
| 167 |  } catch (PThrowable & exc) {    // Sophya exceptions
 | 
|---|
| 168 |   cout<<"\ntstktoibad: Catched Exception \n"<<(string)typeid(exc).name() 
 | 
|---|
| 169 |       <<" - Msg= "<<exc.Msg()<<endl;
 | 
|---|
| 170 |  } catch (const std::exception & sex) {    // Standard exceptions
 | 
|---|
| 171 |   cout<<"\ntstktoibad: Catched std::exception \n" 
 | 
|---|
| 172 |       <<(string)typeid(sex).name()<<endl; 
 | 
|---|
| 173 |  } catch (...) {    // Other exceptions
 | 
|---|
| 174 |   cout<<"\ntstktoibad: some other exception was caught ! "<<endl;
 | 
|---|
| 175 |  }
 | 
|---|
| 176 |  //--------------------------------------------------------------------
 | 
|---|
| 177 | 
 | 
|---|
| 178 |  return(0);
 | 
|---|
| 179 | }
 | 
|---|