Skip to content

Commit

Permalink
Track source filename for G3Frame objects that are read in using G3Re…
Browse files Browse the repository at this point in the history
…ader
  • Loading branch information
arahlin committed Sep 6, 2023
1 parent 0c5986b commit 1ab341a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/include/core/G3Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class G3Frame {

FrameType type;

// Source filename (if output from G3Reader)
std::string filename;

// Add and remove data from the frame. Note that retrieved data is
// const. Get<> is like operator [], except that it does a dynamic
// cast to a type for you.
Expand Down
1 change: 1 addition & 0 deletions core/src/G3Reader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void G3Reader::Process(G3FramePtr frame, std::deque<G3FramePtr> &out)
if (_save != nullptr)
PyEval_RestoreThread(_save);

frame->filename = cur_file_;
out.push_back(frame);
n_frames_read_++;
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/python.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ BOOST_PYTHON_MODULE(core)
.def("__init__", bp::make_constructor(g3frame_char_constructor, bp::default_call_policies(), bp::args("adhoctypecode")), "Create a frame with an ad-hoc (non-standard) type code. Use sparingly and with care.")
.def_readwrite("type", &G3Frame::type, "Type code for frame. "
"See general G3Frame docstring.")
.def_readonly("filename", &G3Frame::filename, "Source filename for frame, "
"if read in using G3Reader. This attribute is fragile, use at your own risk.")
.def("__setitem__", &g3frame_python_put)
.def("__getitem__", &g3frame_python_get)
.def("keys", &g3frame_keys, "Returns a list of keys in the frame.")
Expand Down
2 changes: 2 additions & 0 deletions doc/frames.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Frames have fast serialization to and from disk (see the G3Reader and G3Writer m

Each frame has a type defined under the ``core.G3FrameType`` namespace. These are meant to indicate different types of data (calibration vs. scan data, for example) and, in general, many types of frames will be interleaved in the same data stream. A good general rule for whether data should be in a different frame type is to consider the rates at which the data change: data that change at the same speed (e.g. bolometer data and pointing) should share a frame, while data that change at different speeds (e.g. calibration constants and bolometer data) should be separated.

Each frame also has a ``filename`` attribute, which is set when frames are read in using the ``core.G3Reader`` pipeline module. This attribute is not serialized with the frame, so will be an empty string when used with pickling or multiprocessing.

A brief description of the intention of each frame type follows along with a table containing a representative minimal set of data likely to be contained by a frame of a given type. The list is neither exhaustive nor truly minimal: other data can and will be present and some of the data listed here may have been removed or renamed. Neither is this an exhaustive list of frame types: any single character code can be [ab]used as a frame type for special purpose tools.

.. contents:: Contents
Expand Down
1 change: 1 addition & 0 deletions gcp/src/ARCFileReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ void ARCFileReader::Process(G3FramePtr frame, std::deque<G3FramePtr> &out)
outframe->Put(temp->first, templ);
}

outframe->filename = cur_file_;
out.push_back(outframe);

delete [] buffer;
Expand Down

0 comments on commit 1ab341a

Please sign in to comment.