source: Sophya/trunk/ArchTOIPipe/ProcWSophya/toi2map.cc@ 1788

Last change on this file since 1788 was 1786, checked in by aubourg, 24 years ago

debug bornes

File size: 7.4 KB
Line 
1// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
2// Eric Aubourg
3// Christophe Magneville
4// Reza Ansari
5// $Id: toi2map.cc,v 1.16 2001-11-26 15:13:38 aubourg Exp $
6
7#include "machdefs.h"
8#include "toimanager.h"
9#include "pexceptions.h"
10#include "ctimer.h"
11#include "toi2map.h"
12
13////////////////////////////////////////////////////////////////////////
14TOI2Map::TOI2Map(SphereHEALPix<r_8>* sph,SphereHEALPix<r_8>* wsph)
15 : mSph(sph), mWSph(wsph), mWSphInternal(false)
16{
17 SetEquinox();
18 SetCoorIn();
19 SetCoorOut();
20 SetTestFlag();
21 SetTestMin();
22 SetTestMax();
23
24 if(mSph->NbPixels()<1) {
25 cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mSph "
26 <<mSph->NbPixels()<<endl;
27 throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
28 }
29 mSph->SetPixels(0.);
30 int nlat = mSph->SizeIndex();
31
32 if(mWSph==NULL) {
33 mWSph = new SphereHEALPix<r_8>(nlat);
34 mWSphInternal = true;
35 } else {
36 mWSphInternal = false;
37 if(nlat != mWSph->SizeIndex()) mWSph->Resize(nlat);
38 }
39 if(mWSph->NbPixels()<1) {
40 cout<<"TOI2Map::TOI2Map() Bad number of pixels in sphere mWSph "
41 <<mWSph->NbPixels()<<endl;
42 throw ParmError("TOI2Map::TOI2Map() - Bad number of pixels in sphere");
43 }
44 mWSph->SetPixels(0);
45
46}
47
48TOI2Map::~TOI2Map()
49{
50 if(mWSph && mWSphInternal) delete mWSph;
51}
52
53////////////////////////////////////////////////////////////////////////
54void TOI2Map::Print(::ostream & os)
55{
56 os<<"TOI2Map::Print -- Sphere NLat = "<<mSph->SizeIndex()<<endl
57
58 <<" - Equinoxe="<<mActualYear<<endl
59
60 <<" - TypCoorIn: Gal("<<((mTypCoorIn&TypCoordGal)?1:0)
61 <<") Eq("<<((mTypCoorIn&TypCoordEq)?1:0)
62 <<") Deg("<<((mTypCoorIn&TypCoordDD)?1:0)
63 <<") Hour("<<((mTypCoorIn&TypCoordHD)?1:0)
64 <<") Rad("<<((mTypCoorIn&TypCoordRR)?1:0)<<")"<<endl
65
66 <<" - TypCoorOut: Gal("<<((mTypCoorOut&TypCoordGal)?1:0)
67 <<") Eq("<<((mTypCoorOut&TypCoordEq)?1:0)
68 <<") Deg("<<((mTypCoorOut&TypCoordDD)?1:0)
69 <<") Hour("<<((mTypCoorOut&TypCoordHD)?1:0)
70 <<") Rad("<<((mTypCoorOut&TypCoordRR)?1:0)<<")"<<endl
71
72 <<" - Tests: Flag("<<mTFlag<<") bad="<<mBadFlag
73 <<" / Value Min("<<mTMin<<")="<<mValMin
74 <<" , Max("<<mTMax<<")="<<mValMax<<endl;
75}
76
77////////////////////////////////////////////////////////////////////////
78void TOI2Map::init() {
79 cout << "TOI2Map::init" << endl;
80 declareInput("Coord1In"); // input index 0
81 declareInput("Coord2In"); // input index 1
82 declareInput("BoloIn"); // input index 2
83}
84
85////////////////////////////////////////////////////////////////////////
86// define SANS_BUFFER
87void TOI2Map::run()
88{
89long snb = getMinIn();
90long sne = getMaxIn();
91
92if(snb>sne) {
93 cout<<"TOI2Map::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
94 throw ParmError("TOI2Map::run() - Bad sample interval");
95}
96if(!checkInputTOIIndex(0) || !checkInputTOIIndex(1) || !checkInputTOIIndex(2)) {
97 cout<<"TOI2Map::run() - Input TOI (Coord1In or Coord2In or BoloIn) not connected! "<<endl;
98 throw ParmError("TOI2Map::run() Output TOI (Coord1In or Coord2In or BoloIn) not connected!");
99}
100if( !(mTypCoorIn&TypCoordEq || mTypCoorIn&TypCoordGal) ) {
101 cout<<"TOI2Map::run() - Input Coordinates not Eq or Gal! "<<endl;
102 throw ParmError("TOI2Map::run() - Input Coordinates not Eq or Gal!");
103}
104if( !(mTypCoorOut&TypCoordEq || mTypCoorOut&TypCoordGal) ) {
105 cout<<"TOI2Map::run() - Output Coordinates not Eq or Gal! "<<endl;
106 throw ParmError("TOI2Map::run() - Output Coordinates not Eq or Gal!");
107}
108
109//---------------------------------------------------------
110#define NFILL 25
111try {
112
113int ii;
114uint_4 mNSnFill=0, mNpixFill=0, NFill[NFILL];
115for(ii=0;ii<NFILL;ii++) NFill[ii]=0;
116double mjd = MJDfrYear(mActualYear);
117
118cout<<"TOI2Map::run() from "<<snb<<" to "<<sne;
119#ifndef SANS_BUFFER
120int bufsz = 100;
121uint_8* bfgbolo = new uint_8[bufsz];
122double* bbolo = new double[bufsz];
123double* bc1 = new double[bufsz];
124double* bc2 = new double[bufsz];
125int i0 = -1;
126cout<<" (getData() bufferized)"<<endl;
127#else
128cout<<" (getData() not bufferized)"<<endl;
129#endif
130
131// Remplissage des spheres
132for(int s=snb;s<=sne;s++) {
133 uint_8 fgbolo = 0;
134 double bolo,coord1,coord2;
135 // Equatoriales / Galactiques
136 // coord1,2 = alpha,delta / gLon,gLat
137
138#ifndef SANS_BUFFER
139 if(i0<0 || s<i0 || s>=i0+bufsz) {
140 i0 = s;
141 int nget = (sne-s+1<bufsz)? nget=sne-s+1: bufsz;
142 getData(0,i0,nget,bc1);
143 getData(1,i0,nget,bc2);
144 getData(2,i0,nget,bbolo,bfgbolo);
145 }
146 bolo = bbolo[s-i0]; fgbolo = bfgbolo[s-i0];
147 coord1 = bc1[s-i0]; coord2 = bc2[s-i0];
148#else
149 getData(2,s,bolo,fgbolo);
150 coord1 = getData(0,s);
151 coord2 = getData(1,s);
152#endif
153
154 // Comme il n'y a pas de toi en sortie, il faut dire
155 // aux processeur/toi que l'on a plus besoin des donnees.
156 if (s%100 == 0) wontNeedBefore(s-1);
157 if(mTFlag && fgbolo&mBadFlag) continue;
158 if(mTMin && bolo<mValMin) continue;
159 if(mTMax && bolo>mValMax) continue;
160
161 // sphere phi entre [0,2*Pi] en radians
162 // sphere theta entre [0,Pi] en radians
163 double phi=-1.,theta;
164 int crc = CoordConvertToStd(mTypCoorIn,coord1,coord2);
165
166 // On tente de remettre dans l'intervalle si on est hors intervalle
167 if ((mTypCoorIn&TypCoordEq) && (coord1<0))
168 coord1 += 24;
169 if ((mTypCoorIn&TypCoordEq) && (coord1>24))
170 coord1 -= 24;
171 if ((mTypCoorIn&TypCoordEq) && (coord2>90))
172 coord2 -= 180;
173 if ((mTypCoorIn&TypCoordEq) && (coord2<-90))
174 coord2 += 180;
175
176 if ((mTypCoorIn&TypCoordGal) && (coord1<0))
177 coord1 += 360;
178 if ((mTypCoorIn&TypCoordGal) && (coord1>360))
179 coord1 -= 360;
180 if ((mTypCoorIn&TypCoordGal) && (coord2>90))
181 coord2 -= 180;
182 if ((mTypCoorIn&TypCoordGal) && (coord2<-90))
183 coord2 += 180;
184
185 if(mTypCoorIn&TypCoordEq && mTypCoorOut&TypCoordGal) { // Eq -> Gal
186 EqtoGal(mjd,coord1,coord2,&coord1,&coord2);
187 phi = coord1 * M_PI/180.;
188 } else if(mTypCoorIn&TypCoordGal && mTypCoorOut&TypCoordEq) { // Gal -> Eq
189 GaltoEq(mjd,coord1,coord2,&coord1,&coord2);
190 phi = coord1 * M_PI/12.;
191 } else if(mTypCoorOut&TypCoordGal) { // Gal -> Gal
192 phi = coord1 * M_PI/180.;
193 } else if(mTypCoorOut&TypCoordEq) { // Eq -> Eq
194 phi = coord1 * M_PI/12.;
195 }
196 theta = (90.-coord2) * M_PI/180.;
197
198 if(phi<0. || phi>=2*M_PI || theta<0. || theta>=M_PI) {
199 cout << "out of range " << theta << " " << phi << " "
200 << coord1 << " " << coord2 << endl;
201 }
202
203
204 if(phi<0. || phi>=2*M_PI) continue;
205 if(theta<0. || theta>=M_PI) continue;
206
207 int_4 ipix = mSph->PixIndexSph(theta,phi);
208 (*mSph)(ipix) += bolo;
209 ((*mWSph)(ipix)) += 1;
210 mNSnFill++;
211}
212
213 cout<<"TOI2Map::run(): Fin de boucle sur les sampleNum"<<endl;
214
215// Remplissage des spheres
216 for(int_4 i=0;i<mSph->NbPixels();i++) {
217 r_8 wf = (*mWSph)(i);
218 if( wf > 0. ) {
219 mNpixFill++;
220 (*mSph)(i) /= wf;
221 }
222 int_4 nf = int_4(wf);
223 if(nf>=NFILL) nf=NFILL-1; NFill[nf]++;
224 }
225
226 cout<<"TOI2Map::run(): mNpixTot="<<mSph->NbPixels()
227 <<" mNpixFill="<<mNpixFill
228 <<" mNSnFill="<<mNSnFill<<endl
229 <<" --> FracSky="<<mNpixFill*100./(double)mSph->NbPixels()<<"%"
230 <<" NFill["<<NFILL<<"] ="<<endl;
231 for(ii=0;ii<NFILL;ii++) {cout<<NFill[ii]<<" "; if(ii%10==9) cout<<endl;}
232 cout<<endl;
233
234#ifndef SANS_BUFFER
235delete [] bbolo; delete [] bfgbolo;
236delete [] bc1; delete [] bc2;
237#endif
238
239//---------------------------------------------------------
240} catch (PException & exc) {
241 cout<<"TOI2Map: Catched Exception "<<(string)typeid(exc).name()
242 <<"\n .... Msg= "<<exc.Msg()<<endl;
243}
244
245return;
246}
Note: See TracBrowser for help on using the repository browser.