| 1 | //#define TOISEQBUFFERED | 
|---|
| 2 |  | 
|---|
| 3 | #include <unistd.h> | 
|---|
| 4 | #include "toi.h" | 
|---|
| 5 | #include "toiprocessor.h" | 
|---|
| 6 | #include "fitstoirdr.h" | 
|---|
| 7 | #include "fitstoiwtr.h" | 
|---|
| 8 | #include "toimanager.h" | 
|---|
| 9 | #ifdef TOISEQBUFFERED | 
|---|
| 10 | #include "toiseqbuff.h" | 
|---|
| 11 | #else | 
|---|
| 12 | #include "toisegment.h" | 
|---|
| 13 | #endif | 
|---|
| 14 |  | 
|---|
| 15 | #include "sambainit.h" | 
|---|
| 16 | #include "map2toi.h" | 
|---|
| 17 | #include "fitsspherehealpix.h" | 
|---|
| 18 | #include "timing.h" | 
|---|
| 19 |  | 
|---|
| 20 | #include <stdexcept> | 
|---|
| 21 |  | 
|---|
| 22 | void usage(void); | 
|---|
| 23 | void usage(void) { | 
|---|
| 24 | cout<<"tstmap2toi [-h] [-p lp] [-s samplemin,samplemax] [-w data_window_size]"<<endl | 
|---|
| 25 | <<"           [-a label_coord1In] [-d label_coord2In] [-b label_bolomuv]"<<endl | 
|---|
| 26 | <<"           [-i c,h] [-m c,h] [-C] "<<endl | 
|---|
| 27 | <<"           fitsin_point fitsphere fitsout"<<endl | 
|---|
| 28 | <<" -p lp : print level (def=0)"<<endl | 
|---|
| 29 | <<" -s samplemin,samplemax : sample range to be treated (def=all)"<<endl | 
|---|
| 30 | <<" -w data_window_size : window size for pipe (def=8192)"<<endl | 
|---|
| 31 | <<" -a label_coord1 : label fits for alpha/gLong (def=coord1)"<<endl | 
|---|
| 32 | <<" -d label_coord2 : label fits for delta/gLat (def=coord2)"<<endl | 
|---|
| 33 | <<"          coord1 = alpha or gLong ; coord2 = delta or gLat"<<endl | 
|---|
| 34 | <<" -b label_bolomuv : label fits for bolo value (def=boloMuV)"<<endl | 
|---|
| 35 | <<" -i cin : coordIn caracteristics (def=\"gdcdl\")"<<endl | 
|---|
| 36 | <<" -m cmap : idem -i for Sphere (def=\"g\")"<<endl | 
|---|
| 37 | <<" -e equi : equinoxe en annee (def=2000.)"<<endl | 
|---|
| 38 | <<" -I : sampleNum are implicit in fits files (def=no)"<<endl | 
|---|
| 39 | <<" -C : Copy ccordIn to output  fits file (def=no)"<<endl | 
|---|
| 40 | <<" fitsin_point : fits file for pointing"<<endl | 
|---|
| 41 | <<" fitsphere : fits file for input Healpix sphere"<<endl | 
|---|
| 42 | <<" fitsout : fits file for output"<<endl; | 
|---|
| 43 | return; | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | //////////////////////////////////////////////////////////////// | 
|---|
| 47 | int main(int narg, char** arg) { | 
|---|
| 48 |  | 
|---|
| 49 | TOIManager* mgr = TOIManager::getManager(); | 
|---|
| 50 |  | 
|---|
| 51 | //-- Decodage arguments | 
|---|
| 52 | int lp = 0, width = 8192; | 
|---|
| 53 | char *label_coord1 = "coord1", *label_coord2 = "coord2", *label_bolomuv = "boloMuV"; | 
|---|
| 54 | char *tcoorin="gdcdl", *tcoormap="g"; | 
|---|
| 55 | double equi=2000.; | 
|---|
| 56 | long sdeb,sfin; | 
|---|
| 57 | bool snimplicit = false; | 
|---|
| 58 | bool fgcopycoord = false; | 
|---|
| 59 | int c; | 
|---|
| 60 | while((c = getopt(narg,arg,"hIp:s:w:a:d:b:i:m:e:")) != -1) { | 
|---|
| 61 | switch (c) { | 
|---|
| 62 | case 's' : | 
|---|
| 63 | sscanf(optarg,"%ld,%ld",&sdeb,&sfin); | 
|---|
| 64 | cout<<"Requested Samples from "<<sdeb<<" , "<<sfin<<endl; | 
|---|
| 65 | if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin); | 
|---|
| 66 | else {cout<<"Bad sample interval "<<endl; exit(1);} | 
|---|
| 67 | break; | 
|---|
| 68 | case 'w' : | 
|---|
| 69 | sscanf(optarg,"%d",&width); | 
|---|
| 70 | if(width<=0) width=8192; | 
|---|
| 71 | cout<<"Data window size "<<width<<endl; | 
|---|
| 72 | break; | 
|---|
| 73 | case 'p' : | 
|---|
| 74 | sscanf(optarg,"%d",&lp); | 
|---|
| 75 | if(lp<0) lp=0; | 
|---|
| 76 | break; | 
|---|
| 77 | case 'a' : | 
|---|
| 78 | label_coord1 = optarg; | 
|---|
| 79 | break; | 
|---|
| 80 | case 'd' : | 
|---|
| 81 | label_coord2 = optarg; | 
|---|
| 82 | break; | 
|---|
| 83 | case 'b' : | 
|---|
| 84 | label_bolomuv = optarg; | 
|---|
| 85 | break; | 
|---|
| 86 | case 'i' : | 
|---|
| 87 | tcoorin = optarg; | 
|---|
| 88 | break; | 
|---|
| 89 | case 'm' : | 
|---|
| 90 | tcoormap = optarg; | 
|---|
| 91 | break; | 
|---|
| 92 | case 'e' : | 
|---|
| 93 | sscanf(optarg,"%lf",&equi); | 
|---|
| 94 | break; | 
|---|
| 95 | case 'I' : | 
|---|
| 96 | snimplicit = true; | 
|---|
| 97 | break; | 
|---|
| 98 | case 'C' : | 
|---|
| 99 | fgcopycoord = true; | 
|---|
| 100 | break; | 
|---|
| 101 | case 'h' : | 
|---|
| 102 | default: | 
|---|
| 103 | usage(); exit(1); | 
|---|
| 104 | } | 
|---|
| 105 | } | 
|---|
| 106 | if(optind+2>=narg) {usage(); exit(2);} | 
|---|
| 107 | char * fitsin_point    = arg[optind]; | 
|---|
| 108 | string const fitsphere = arg[optind+1]; | 
|---|
| 109 | char * fitsout         = arg[optind+2]; | 
|---|
| 110 |  | 
|---|
| 111 | cout<<">>>> tstmap2toi:"<<endl | 
|---|
| 112 | <<"Pipe Window Size "<<width<<endl | 
|---|
| 113 | <<"Fits OutFile "<<fitsout<<endl | 
|---|
| 114 | <<"  ...label_bolomuv "<<label_bolomuv<<endl; | 
|---|
| 115 | cout<<"Fits Infile Pointing "<<fitsin_point<<endl | 
|---|
| 116 | <<"  ...label_coord1 "<<label_coord1<<endl | 
|---|
| 117 | <<"  ...label_coord2 "<<label_coord2<<endl | 
|---|
| 118 | <<"  ...... ctype="<<tcoorin<<endl; | 
|---|
| 119 | cout<<"Fits Healpix Sphere "<<fitsphere<<endl | 
|---|
| 120 | <<"  ...... ctype="<<tcoormap<<endl; | 
|---|
| 121 | cout<<"Equinoxe "<<equi<<" years"<<endl; | 
|---|
| 122 |  | 
|---|
| 123 | SophyaInit(); | 
|---|
| 124 | InitTim(); | 
|---|
| 125 |  | 
|---|
| 126 | //-------------------------------------------------------------------- | 
|---|
| 127 | try { | 
|---|
| 128 | //-------------------------------------------------------------------- | 
|---|
| 129 |  | 
|---|
| 130 | // FITS reader et writer | 
|---|
| 131 | FITSTOIReader rfits(fitsin_point); | 
|---|
| 132 | if(snimplicit) rfits.setImplicitSN(); | 
|---|
| 133 | int ncol = rfits.getNOut(); | 
|---|
| 134 | cout<<"Number of columns in fits Infile Pointing : "<<ncol<<endl; | 
|---|
| 135 | if(ncol<2) exit(3); | 
|---|
| 136 |  | 
|---|
| 137 | FITSTOIWriter wfits(fitsout); | 
|---|
| 138 | if(snimplicit) wfits.setImplicitSN(); | 
|---|
| 139 | //wfits.setOutFlags(true); | 
|---|
| 140 | cout << "fits reader and writer created"<<endl; | 
|---|
| 141 |  | 
|---|
| 142 | // Lecture de la sphere Healpix | 
|---|
| 143 | SphereHEALPix<r_8> sph; | 
|---|
| 144 | FitsInFile sfits(fitsphere); | 
|---|
| 145 | sfits >> sph; | 
|---|
| 146 | cout<<"SphereHEALPix: Type de map : "<<sph.TypeOfMap()<<endl | 
|---|
| 147 | <<"               Nombre de pixels : "<<sph.NbPixels()<<endl; | 
|---|
| 148 |  | 
|---|
| 149 | // TOI Processor | 
|---|
| 150 | Map2TOI m2toi(sph); | 
|---|
| 151 | cout<<"Map2TOI created"<<endl; | 
|---|
| 152 | m2toi.SetEquinox(equi); | 
|---|
| 153 | m2toi.SetCoorIn(tcoorin); | 
|---|
| 154 | m2toi.SetCoorMap(tcoormap); | 
|---|
| 155 | m2toi.Print(cout); | 
|---|
| 156 |  | 
|---|
| 157 | // Definition des tuyaux | 
|---|
| 158 | #ifdef TOISEQBUFFERED | 
|---|
| 159 | cout<<">>>> Using TOISeqBuffered"<<endl; | 
|---|
| 160 | TOISeqBuffered * toicoord1in = new TOISeqBuffered("toi_coord1_in",width); | 
|---|
| 161 | #else | 
|---|
| 162 | cout<<">>>> Using TOISegmented"<<endl; | 
|---|
| 163 | TOISegmented * toicoord1in = new TOISegmented("toi_coord1_in",width); | 
|---|
| 164 | #endif | 
|---|
| 165 | // toicoord1in->setDebugLevel(1); | 
|---|
| 166 | rfits.addOutput(label_coord1,toicoord1in); | 
|---|
| 167 | m2toi.addInput("Coord1In",toicoord1in); | 
|---|
| 168 |  | 
|---|
| 169 | if (fgcopycoord) { | 
|---|
| 170 | #ifdef TOISEQBUFFERED | 
|---|
| 171 | TOISeqBuffered * toicoord1out = new TOISeqBuffered("toi_coord1_out",width); | 
|---|
| 172 | #else | 
|---|
| 173 | TOISegmented * toicoord1out = new TOISegmented("toi_coord1_out",width); | 
|---|
| 174 | #endif | 
|---|
| 175 | m2toi.addOutput("Coord1Out",toicoord1out); | 
|---|
| 176 | wfits.addInput(label_coord1,toicoord1out); | 
|---|
| 177 | } | 
|---|
| 178 |  | 
|---|
| 179 | #ifdef TOISEQBUFFERED | 
|---|
| 180 | TOISeqBuffered * toicoord2in = new TOISeqBuffered("toi_coord2_in",width); | 
|---|
| 181 | #else | 
|---|
| 182 | TOISegmented * toicoord2in = new TOISegmented("toi_coord2_in",width); | 
|---|
| 183 | #endif | 
|---|
| 184 | // toicoord2in->setDebugLevel(1); | 
|---|
| 185 | rfits.addOutput(label_coord2,toicoord2in); | 
|---|
| 186 | m2toi.addInput("Coord2In",toicoord2in); | 
|---|
| 187 |  | 
|---|
| 188 | if (fgcopycoord) { | 
|---|
| 189 | #ifdef TOISEQBUFFERED | 
|---|
| 190 | TOISeqBuffered * toicoord2out = new TOISeqBuffered("toi_coord2_out",width); | 
|---|
| 191 | #else | 
|---|
| 192 | TOISegmented * toicoord2out = new TOISegmented("toi_coord2_out",width); | 
|---|
| 193 | #endif | 
|---|
| 194 | m2toi.addOutput("Coord2Out",toicoord2out); | 
|---|
| 195 | wfits.addInput(label_coord2,toicoord2out); | 
|---|
| 196 | } | 
|---|
| 197 |  | 
|---|
| 198 | #ifdef TOISEQBUFFERED | 
|---|
| 199 | TOISeqBuffered * toibolout = new TOISeqBuffered("toi_bolo_out",width); | 
|---|
| 200 | #else | 
|---|
| 201 | TOISegmented * toibolout = new TOISegmented("toi_bolo_out",width); | 
|---|
| 202 | #endif | 
|---|
| 203 | // toibolout->setDebugLevel(1); | 
|---|
| 204 | m2toi.addOutput("BoloOut",toibolout); | 
|---|
| 205 | wfits.addInput(label_bolomuv,toibolout); | 
|---|
| 206 |  | 
|---|
| 207 | // Run | 
|---|
| 208 | cout<<"----- FITSReaderTOI::PrintStatus() : -----"<<endl; | 
|---|
| 209 | rfits.PrintStatus(cout); | 
|---|
| 210 | cout<<"----- FITSWriterTOI::PrintStatus() : -----"<<endl; | 
|---|
| 211 | wfits.PrintStatus(cout); | 
|---|
| 212 |  | 
|---|
| 213 | PrtTim("starting threads"); | 
|---|
| 214 | rfits.start(); | 
|---|
| 215 | m2toi.start(); | 
|---|
| 216 | wfits.start(); | 
|---|
| 217 |  | 
|---|
| 218 | //if(lp>1) for(int jjjj=0;jjjj<5;jjjj++) { | 
|---|
| 219 | //  cout<<*toicoord1in; | 
|---|
| 220 | //  cout<<*toibolout; | 
|---|
| 221 | //  sleep(2); | 
|---|
| 222 | //} | 
|---|
| 223 |  | 
|---|
| 224 | //  Affichage de l'avancement des TOIProcessors | 
|---|
| 225 | ProcSampleCounter<Map2TOI>  stats(m2toi); | 
|---|
| 226 | stats.InfoMessage() = "tstmap2toi/Info"; | 
|---|
| 227 | stats.PrintStats(); | 
|---|
| 228 |  | 
|---|
| 229 | mgr->joinAll(); | 
|---|
| 230 | PrtTim("End threads"); | 
|---|
| 231 |  | 
|---|
| 232 | //-------------------------------------------------------------------- | 
|---|
| 233 | } catch (PThrowable & exc) { | 
|---|
| 234 | cout<<"\ntstmap2toi: Catched Exception \n"<<(string)typeid(exc).name() | 
|---|
| 235 | <<" - Msg= "<<exc.Msg()<<endl; | 
|---|
| 236 | } catch (const std::exception & sex) { | 
|---|
| 237 | cout<<"\ntstmap2toi: Catched std::exception \n" | 
|---|
| 238 | <<(string)typeid(sex).name()<<endl; | 
|---|
| 239 | } catch (...) { | 
|---|
| 240 | cout<<"\ntstmap2toi: some other exception was caught ! "<<endl; | 
|---|
| 241 | } | 
|---|
| 242 | //-------------------------------------------------------------------- | 
|---|
| 243 |  | 
|---|
| 244 | exit(0); | 
|---|
| 245 | } | 
|---|