Skip to content

Commit d697926

Browse files
df7cbmsdemlei
authored andcommitted
Add smoc_disc(order, theta, phi, radius)
We get the function from libhealpix-cxx-dev, while still using healpix_bare for the basic pixel operations
1 parent 5e7f90b commit d697926

File tree

9 files changed

+107
-1
lines changed

9 files changed

+107
-1
lines changed

.gitlab-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ stages:
44
.build: &build
55
stage: build
66
image: credativ/postgresql-build:${PGVERSION}
7+
before_script:
8+
- apt-get -y install libhealpix-cxx-dev
79
script:
810
- make
911
- make install

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dist: xenial
1919
before_install:
2020
# extra apt.pg.o.sh options added in version 204, travis currently has 199 (2019-11-27)
2121
- sudo apt-get -qq update
22-
- sudo apt-get -y install postgresql-common
22+
- sudo apt-get -y install postgresql-common libhealpix-cxx-dev
2323

2424
install:
2525
- sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -p -v $PG_SUPPORTED_VERSIONS -i

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ else
6363
include $(top_srcdir)/contrib/contrib-global.mk
6464
endif
6565

66+
override CPPFLAGS += -I/usr/include/healpix_cxx
67+
SHLIB_LINK += -lhealpix_cxx
6668
# link a second time as PGXS does not allow to change the linker
6769
PGS_LINKER = g++ $(CXXFLAGS) $(filter-out $(CC) $(CFLAGS), $(LINK.shared))
6870
pgs_link: $(shlib) $(OBJS) | $(SHLIB_PREREQS)

expected/moc.out

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,33 @@ SELECT intersection(moc) FROM (VALUES ('0/1-4'::smoc), ('0/2-5'), (NULL)) sub(mo
559559
0/2-4
560560
(1 row)
561561

562+
SELECT smoc_disc(0, 0, 0, 1);
563+
smoc_disc
564+
-----------
565+
0/0-3
566+
(1 row)
567+
568+
SELECT smoc_disc(1, 0, 0, 1);
569+
smoc_disc
570+
----------------------
571+
1/1-3,5-7,9-11,13-15
572+
(1 row)
573+
574+
SELECT smoc_disc(2, 0, 0, 1);
575+
smoc_disc
576+
------------------------------------------------------------
577+
1/3,7,11,15 2/5-7,9-11,21-23,25-27,37-39,41-43,53-55,57-59
578+
(1 row)
579+
580+
SELECT smoc_disc(0, 0, 0, 3.2);
581+
smoc_disc
582+
-----------
583+
0/0-11
584+
(1 row)
585+
586+
SELECT smoc_disc(2, 0, 0, 3.2);
587+
smoc_disc
588+
-----------
589+
0/0-11
590+
(1 row)
591+

moc.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ PG_FUNCTION_INFO_V1(smoc_superset_spoint);
2222
PG_FUNCTION_INFO_V1(smoc_not_superset_spoint);
2323
PG_FUNCTION_INFO_V1(smoc_union);
2424
PG_FUNCTION_INFO_V1(smoc_intersection);
25+
PG_FUNCTION_INFO_V1(smoc_disc);
2526

2627
int32 smoc_output_type = 0;
2728

@@ -702,3 +703,30 @@ smoc_intersection(PG_FUNCTION_ARGS)
702703
PG_RETURN_NULL();
703704
}
704705
}
706+
707+
Datum
708+
smoc_disc(PG_FUNCTION_ARGS)
709+
{
710+
int order = PG_GETARG_INT32(0);
711+
double theta = PG_GETARG_FLOAT8(1);
712+
double phi = PG_GETARG_FLOAT8(2);
713+
double radius = PG_GETARG_FLOAT8(3);
714+
void* moc_in_context = create_moc_in_context(moc_error_out);
715+
int32 moc_size;
716+
Smoc* moc_ret;
717+
718+
moc_disc(moc_in_context, order, theta, phi, radius, moc_error_out);
719+
720+
moc_size = VARHDRSZ + get_moc_size(moc_in_context, moc_error_out);
721+
moc_ret = (Smoc*) palloc0(moc_size);
722+
SET_VARSIZE(moc_ret, moc_size);
723+
724+
if (create_moc_release_context(moc_in_context, moc_ret, moc_error_out))
725+
PG_RETURN_POINTER(moc_ret);
726+
else
727+
{
728+
ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR),
729+
errmsg("Internal error in creation of MOC from disc")));
730+
PG_RETURN_NULL();
731+
}
732+
}

pgs_moc_ops.sql.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,9 @@ CREATE AGGREGATE intersection (smoc) (
6363
SFUNC = smoc_intersection,
6464
STYPE = smoc
6565
);
66+
67+
CREATE FUNCTION smoc_disc ("order" int, theta double precision, phi double precision, radius double precision)
68+
RETURNS smoc
69+
AS 'MODULE_PATHNAME'
70+
LANGUAGE C
71+
STRICT;

pgs_process_moc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ void
146146
moc_intersection(void* moc_in_context, Smoc* moc_a, int32 moc_a_end, Smoc* moc_b, int32 moc_b_end,
147147
pgs_error_handler error_out);
148148

149+
void
150+
moc_disc(void* moc_in_context, long order, double theta, double phi, double radius,
151+
pgs_error_handler error_out);
152+
149153
#ifdef __cplusplus
150154
}
151155
#endif

process_moc.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <exception>
1414
#include <stdexcept>
1515

16+
#include <healpix_base.h>
17+
1618
#include "pgs_process_moc.h"
1719

1820
#define LAYDEB 0
@@ -921,3 +923,29 @@ moc_intersection(void* moc_in_context, Smoc* moc_a, int32 moc_a_end, Smoc* moc_b
921923
}
922924
PGS_CATCH
923925
}
926+
927+
void
928+
moc_disc(void* moc_in_context, long order, double theta, double phi, double radius,
929+
pgs_error_handler error_out)
930+
{
931+
moc_input* p = static_cast<moc_input*>(moc_in_context);
932+
moc_input & m = *p;
933+
PGS_TRY
934+
rangeset<int64> pixset;
935+
Healpix_Base2 hp(order, NEST);
936+
pointing p(theta, phi);
937+
938+
hp.query_disc(p, radius, pixset);
939+
940+
for (tsize j = 0; j < pixset.nranges(); j++)
941+
{
942+
hpint64 first = pixset.ivbegin(j);
943+
hpint64 last = pixset.ivend(j);
944+
healpix_convert(first, order); // convert to order 29
945+
healpix_convert(last, order);
946+
moc_map_entry input(first, last);
947+
m.input_map.insert(m.input_map.end(), input);
948+
}
949+
950+
PGS_CATCH
951+
}

sql/moc.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,9 @@ SELECT smoc_intersection('1/1,4-6', '1/3-5 2/8');
124124
SELECT '0/1'::smoc * '1/3,5,7,9' AS intersection;
125125
SELECT '1/9,11,13,15'::smoc * '0/1,2' AS intersection;
126126
SELECT intersection(moc) FROM (VALUES ('0/1-4'::smoc), ('0/2-5'), (NULL)) sub(moc);
127+
128+
SELECT smoc_disc(0, 0, 0, 1);
129+
SELECT smoc_disc(1, 0, 0, 1);
130+
SELECT smoc_disc(2, 0, 0, 1);
131+
SELECT smoc_disc(0, 0, 0, 3.2);
132+
SELECT smoc_disc(2, 0, 0, 3.2);

0 commit comments

Comments
 (0)