Skip to content

Commit 23a1947

Browse files
committed
Add a casting specialization to hide G3SuperTimestream entirely from user space
Rearrange, no need for header
1 parent 984c786 commit 23a1947

File tree

4 files changed

+48
-55
lines changed

4 files changed

+48
-55
lines changed

core/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ if(NOT WITHOUT_SUPERTIMESTREAM)
5252
if(OpenMP_FOUND)
5353
target_link_libraries(core PRIVATE OpenMP::OpenMP_CXX)
5454
endif()
55-
56-
target_compile_definitions(core PRIVATE -DHAS_SUPERTIMESTREAM)
5755
endif()
5856

5957
# Link against Z library

core/src/G3Frame.cxx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#include <G3Frame.h>
22
#include <G3Data.h>
33
#include <G3Quat.h>
4-
#ifdef HAS_SUPERTIMESTREAM
5-
#include "G3SuperTimestream.h"
6-
#endif
74
#include <serialization.h>
85
#include <pybindings.h>
96

@@ -361,14 +358,6 @@ void G3Frame::blob_decode(struct blob_container &blob)
361358
G3BufferInputStream is(*blob.blob);
362359
cereal::PortableBinaryInputArchive item_ar(is);
363360
item_ar >> make_nvp("val", ptr);
364-
365-
#ifdef HAS_SUPERTIMESTREAM
366-
// Convert to public type
367-
auto v = std::dynamic_pointer_cast<G3SuperTimestream>(ptr);
368-
if (!!v)
369-
ptr = std::make_shared<G3TimestreamMap>(*v);
370-
#endif
371-
372361
blob.frameobject = ptr;
373362

374363
// Drop really big (> 128 MB) blobs at decode time. The savings

core/src/G3SuperTimestream.cxx

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,50 @@
1+
#include <G3Logging.h>
2+
#include <G3Timestream.h>
13
#include <serialization.h>
2-
#include "G3SuperTimestream.h"
4+
5+
/*
6+
This is a minimal implementation of the Simons Observatory timestream storage
7+
class, to enable reading legacy data from disk and convert directly to
8+
G3TimestreamMap. This class is only visible to the serialization library.
9+
*/
10+
11+
class G3SuperTimestream : public G3TimestreamMap {
12+
private:
13+
G3SuperTimestream() {};
14+
15+
friend class cereal::access;
16+
17+
template <class A> void load(A &ar, unsigned v) {
18+
log_fatal("Library missing FLAC or BZip2 compression");
19+
}
20+
21+
template <class A> void save(A &ar, unsigned v) const {
22+
log_fatal("Convert to G3TimestreamMap to serialize");
23+
}
24+
25+
SET_LOGGER("G3SuperTimestream");
26+
};
27+
28+
namespace cereal {
29+
template <class A> struct specialize<A, G3SuperTimestream,
30+
cereal::specialization::member_load_save> {};
31+
32+
// Convert to G3TimestreamMap before handing off to the user
33+
namespace detail {
34+
template <> inline std::shared_ptr<void>
35+
PolymorphicCasters::upcast(std::shared_ptr<G3SuperTimestream> const & dptr,
36+
std::type_info const & baseInfo) {
37+
return PolymorphicCasters::upcast(
38+
std::make_shared<G3TimestreamMap>(*dptr), baseInfo);
39+
}
40+
}
41+
}
42+
43+
G3_SERIALIZABLE(G3SuperTimestream, 0);
44+
45+
// Everything below is just the deserialization implementation, largely copied
46+
// wholesale from the simonsobs/so3g library, and rearranged to handle decompression
47+
// immediately on load.
348

449
#if defined(G3_HAS_FLAC) && defined(BZIP2_FOUND)
550

@@ -187,7 +232,8 @@ void fill_gaps(struct flac_helper *fh, const std::vector<bool> &gaps, double fil
187232
dest[didx] = (!gaps[didx] && sidx < fh->count) ? src[sidx++] : fillval;
188233
}
189234

190-
template <class A> void G3SuperTimestream::load(A &ar, unsigned v)
235+
template <>
236+
void G3SuperTimestream::load(cereal::PortableBinaryInputArchive &ar, unsigned v)
191237
{
192238
G3_CHECK_VERSION(v);
193239
using namespace cereal;
@@ -406,19 +452,5 @@ template <class A> void G3SuperTimestream::load(A &ar, unsigned v)
406452
} // omp parallel
407453
}
408454

409-
#else
410-
411-
template <class A> void G3SuperTimestream::load(A &ar, unsigned v)
412-
{
413-
log_fatal("Library missing FLAC or BZip2 compression");
414-
}
415-
416455
#endif
417456

418-
// Save directly to a G3TimestreamMap object
419-
template <class A> void G3SuperTimestream::save(A &ar, unsigned v) const
420-
{
421-
log_fatal("Convert to G3Timestream map to serialize");
422-
}
423-
424-
G3_SPLIT_SERIALIZABLE_CODE(G3SuperTimestream);

core/src/G3SuperTimestream.h

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)