Skip to content

Commit 561ab9c

Browse files
committed
Shim class for loading G3SuperTimestream objects from disk
This PR is the first step in integrating the G3SuperTimestream class used by the Simons Observatory team into the core library. This class is a very thin wrapper around the core G3TimestreamMap class. It is designed only to load G3SuperTimestream objects from G3 files on disk for immediate conversion to G3TimestreamMap objects. It is also not exposed to the public or python API.
1 parent 9e9c2d9 commit 561ab9c

File tree

5 files changed

+417
-17
lines changed

5 files changed

+417
-17
lines changed

core/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ add_spt3g_library(core SHARED
1010
src/G3Pipeline.cxx src/G3Writer.cxx src/G3Reader.cxx
1111
src/G3InfiniteSource.cxx src/G3Logging.cxx src/G3PrintfLogger.cxx
1212
src/G3Data.cxx src/G3Vector.cxx src/G3Map.cxx src/G3Timestream.cxx
13-
src/G3Timesample.cxx
13+
src/G3Timesample.cxx src/G3SuperTimestream.cxx
1414
src/G3TriggeredBuilder.cxx src/G3MultiFileWriter.cxx src/dataio.cxx
1515
src/compression.cxx src/crc32.c ${CORE_EXTRA_SRCS}
1616
src/G3NetworkSender.cxx src/G3SyslogLogger.cxx
@@ -40,6 +40,11 @@ if(FLAC_FOUND)
4040
target_link_libraries(core PRIVATE FLAC::FLAC)
4141
endif()
4242

43+
find_package(OpenMP)
44+
if(OpenMP_FOUND)
45+
target_link_libraries(core PRIVATE OpenMP::OpenMP_CXX)
46+
endif()
47+
4348
# Link against Z library
4449
if(NOT DEFINED WITH_ZLIB)
4550
set(WITH_ZLIB TRUE CACHE BOOL "Enable gzip fie compression")

core/include/core/G3Timestream.h

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -245,25 +245,32 @@ class G3TimestreamMap : public G3FrameObject,
245245
G3Time start, G3Time stop,
246246
G3Timestream::TimestreamUnits units=G3Timestream::None,
247247
int compression_level=0){
248-
if(!std::is_sorted(keys.begin(), keys.end()))
248+
G3TimestreamMap map;
249+
map.FromBuffer(keys, n_samples, data, start, stop, units, compression_level);
250+
return map;
251+
}
252+
253+
template<typename SampleType>
254+
void FromBuffer(const std::vector<std::string>& keys, std::size_t n_samples,
255+
std::shared_ptr<SampleType[]> data, G3Time start, G3Time stop,
256+
G3Timestream::TimestreamUnits units=G3Timestream::None, int compression_level=0) {
257+
if (!std::is_sorted(keys.begin(), keys.end()))
249258
throw std::runtime_error("G3TimestreamMap::MakeCompact: keys must be sorted");
250259
const auto data_type=G3Timestream::TimeStreamTypeResolver<SampleType>::type_tag;
251-
G3TimestreamMap map;
252-
std::size_t offset=0;
253-
for(const auto& key : keys){
254-
auto ts=std::make_shared<G3Timestream>(0);
255-
ts->start=start;
256-
ts->stop=stop;
257-
ts->units=units;
258-
ts->use_flac_=compression_level;
259-
ts->root_data_ref_=data;
260-
ts->data_=data.get()+offset;
261-
ts->data_type_=data_type;
262-
ts->len_=n_samples;
263-
map.emplace(key, std::move(ts));
264-
offset+=n_samples;
260+
std::size_t offset = 0;
261+
for (const auto& key : keys) {
262+
auto ts = std::make_shared<G3Timestream>(0);
263+
ts->start = start;
264+
ts->stop = stop;
265+
ts->units = units;
266+
ts->use_flac_ = compression_level;
267+
ts->root_data_ref_ = data;
268+
ts->data_ = data.get() + offset;
269+
ts->data_type_ = data_type;
270+
ts->len_ = n_samples;
271+
emplace(key, std::move(ts));
272+
offset += n_samples;
265273
}
266-
return map;
267274
}
268275

269276
template <class A> void serialize(A &ar, unsigned v);

core/src/G3Frame.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <G3Frame.h>
22
#include <G3Data.h>
33
#include <G3Quat.h>
4+
#include "G3SuperTimestream.h"
45
#include <serialization.h>
56
#include <pybindings.h>
67

@@ -358,6 +359,12 @@ void G3Frame::blob_decode(struct blob_container &blob)
358359
G3BufferInputStream is(*blob.blob);
359360
cereal::PortableBinaryInputArchive item_ar(is);
360361
item_ar >> make_nvp("val", ptr);
362+
363+
// Convert to public type
364+
auto v = std::dynamic_pointer_cast<G3SuperTimestream>(ptr);
365+
if (!!v)
366+
ptr = std::make_shared<G3TimestreamMap>(*v);
367+
361368
blob.frameobject = ptr;
362369

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

0 commit comments

Comments
 (0)