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