Skip to content

Commit dc94c8b

Browse files
committed
Straggler modules and enums
1 parent 58a89ce commit dc94c8b

File tree

6 files changed

+62
-76
lines changed

6 files changed

+62
-76
lines changed

core/src/G3EventBuilder.cxx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ void G3EventBuilder::ProcessThread(G3EventBuilder *builder)
104104
}
105105
}
106106

107-
108107
PYBINDINGS("core", scope) {
109-
py::class_<G3EventBuilder, py::bases<G3Module>, G3EventBuilderPtr,
110-
boost::noncopyable>("G3EventBuilder", py::no_init)
111-
;
112-
}
113-
108+
register_g3module<G3EventBuilder>(scope, "G3EventBuilder");
109+
};

core/src/G3MultiFileWriter.cxx

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -162,31 +162,29 @@ void G3MultiFileWriter::Process(G3FramePtr frame, std::deque<G3FramePtr> &out)
162162
}
163163

164164
PYBINDINGS("core", scope) {
165-
py::class_<G3MultiFileWriter, py::bases<G3Module>, std::shared_ptr<G3MultiFileWriter>,
166-
boost::noncopyable>("G3MultiFileWriter",
167-
"Writes frames to disk into a sequence of files. Once a file exceeds "
168-
"the number of bytes specified in size_limit, it will start a new file. "
169-
"Files are named based on filename. If passed a string for filename "
170-
"with a printf-style specifier, that specifier will be replaced by a "
171-
"zero-indexed sequence number. For example, outfile-%03u.g3.gz would "
172-
"produce a sequence of files named outfile-000.g3.gz, outfile-001.g3.gz, "
173-
"etc. Alternatively, you can pass a callable that is passed the first "
174-
"frame in the new file and the sequence number and returns a path to "
175-
"the new file. Any frames besides Timepoint and Scan frames have the "
176-
"most recent frame of each type prepended to all new files.\n\n"
177-
"More complex behavior can be obtained with the optional divide_on "
178-
"argument. This can be an iterable of frame types (e.g. "
179-
"[core.G3FrameType.Observation]) or a callable. In the iterable case, "
180-
"the presence of any frame with a type in the list will cause the "
181-
"creation of a new file even if the file size threshold has not yet "
182-
"been met. This is useful to create files based on, for example, "
183-
"observation boundaries. For more flexibility, you can also pass a "
184-
"python callable as divide_on. This callable will be passed each "
185-
"frame in turn. If it returns True (or something with positive "
186-
"truth-value), a new file will be started at that frame.",
187-
py::init<py::object, size_t, py::optional<py::object, size_t> >((py::arg("filename"),
188-
py::arg("size_limit"), py::arg("divide_on")=py::object(), py::arg("buffersize")=1024*1024)))
189-
.def_readonly("current_file", &G3MultiFileWriter::CurrentFile)
190-
.def_readonly("__g3module__", true)
191-
;
165+
register_g3module<G3MultiFileWriter>(scope, "G3MultiFileWriter",
166+
"Writes frames to disk into a sequence of files. Once a file exceeds "
167+
"the number of bytes specified in size_limit, it will start a new file. "
168+
"Files are named based on filename. If passed a string for filename "
169+
"with a printf-style specifier, that specifier will be replaced by a "
170+
"zero-indexed sequence number. For example, outfile-%03u.g3.gz would "
171+
"produce a sequence of files named outfile-000.g3.gz, outfile-001.g3.gz, "
172+
"etc. Alternatively, you can pass a callable that is passed the first "
173+
"frame in the new file and the sequence number and returns a path to "
174+
"the new file. Any frames besides Timepoint and Scan frames have the "
175+
"most recent frame of each type prepended to all new files.\n\n"
176+
"More complex behavior can be obtained with the optional divide_on "
177+
"argument. This can be an iterable of frame types (e.g. "
178+
"[core.G3FrameType.Observation]) or a callable. In the iterable case, "
179+
"the presence of any frame with a type in the list will cause the "
180+
"creation of a new file even if the file size threshold has not yet "
181+
"been met. This is useful to create files based on, for example, "
182+
"observation boundaries. For more flexibility, you can also pass a "
183+
"python callable as divide_on. This callable will be passed each "
184+
"frame in turn. If it returns True (or something with positive "
185+
"truth-value), a new file will be started at that frame.")
186+
.def(py::init<py::object, size_t, py::object, size_t>((py::arg("filename"),
187+
py::arg("size_limit"), py::arg("divide_on")=py::object(),
188+
py::arg("buffersize")=1024*1024)))
189+
.def_readonly("current_file", &G3MultiFileWriter::CurrentFile);
192190
}

core/src/G3Reader.cxx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,19 @@ off_t G3Reader::Tell() {
109109
}
110110

111111
PYBINDINGS("core", scope) {
112-
// Instead of EXPORT_G3MODULE since there are two constructors
113-
py::class_<G3Reader, py::bases<G3Module>, std::shared_ptr<G3Reader>,
114-
boost::noncopyable>("G3Reader",
115-
"Read frames from disk. Takes either the path to a file to read "
116-
"or an iterable of files to be read in sequence. If "
117-
"n_frames_to_read is greater than zero, will stop after "
118-
"n_frames_to_read frames rather than at the end of the file[s]. "
119-
"The timeout parameter can used to enable socket timeout for tcp "
120-
"streams, resulting in EOF behavior on expiry; unfortunately this "
121-
"cannot be used for polling, you have to close the connection. "
122-
"Use the `tell` and `seek` methods to record the position of and "
123-
"seek to the beginning of a particular frame in the file. Set "
124-
"track_filename to True to record the filename for each frame in "
125-
"the ._filename attribute (fragile).",
126-
py::init<std::string, int, float, bool, size_t>((py::arg("filename"),
112+
register_g3module<G3Reader>(scope, "G3Reader",
113+
"Read frames from disk. Takes either the path to a file to read "
114+
"or an iterable of files to be read in sequence. If "
115+
"n_frames_to_read is greater than zero, will stop after "
116+
"n_frames_to_read frames rather than at the end of the file[s]. "
117+
"The timeout parameter can used to enable socket timeout for tcp "
118+
"streams, resulting in EOF behavior on expiry; unfortunately this "
119+
"cannot be used for polling, you have to close the connection. "
120+
"Use the `tell` and `seek` methods to record the position of and "
121+
"seek to the beginning of a particular frame in the file. Set "
122+
"track_filename to True to record the filename for each frame in "
123+
"the ._filename attribute (fragile).")
124+
.def(py::init<std::string, int, float, bool, size_t>((py::arg("filename"),
127125
py::arg("n_frames_to_read")=0, py::arg("timeout")=-1.,
128126
py::arg("track_filename")=false, py::arg("buffersize")=1024*1024)))
129127
.def(py::init<std::vector<std::string>, int, float, bool, size_t>((
@@ -133,8 +131,6 @@ PYBINDINGS("core", scope) {
133131
"Return the current byte offset from start of stream.")
134132
.def("seek", &G3Reader::Seek,
135133
"Position the stream read pointer at specific byte offset. "
136-
"Note that once EOF is reached, seek does not work anymore.")
137-
.def_readonly("__g3module__", true)
138-
;
134+
"Note that once EOF is reached, seek does not work anymore.");
139135
}
140136

core/src/G3Writer.cxx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,17 @@ off_t G3Writer::Tell() {
4040
}
4141

4242
PYBINDINGS("core", scope) {
43-
// Instead of EXPORT_G3MODULE since there is an extra Flush function
44-
py::class_<G3Writer, py::bases<G3Module>, std::shared_ptr<G3Writer>,
45-
boost::noncopyable>("G3Writer",
46-
"Writes frames to disk. Frames will be written to the file specified by "
47-
"filename. If filename ends in .gz, output will be compressed using gzip. "
48-
"To write only some types of frames, pass a list of the desired frame "
49-
"types to the second optional argument (streams). If no streams argument "
50-
"is given, writes all types of frames. If append is set to True, will "
51-
"append frames to its output file rather than overwriting it.",
52-
py::init<std::string, std::vector<G3Frame::FrameType>, bool, size_t>((py::arg("filename"),
53-
py::arg("streams")=std::vector<G3Frame::FrameType>(), py::arg("append")=false,
54-
py::arg("buffersize")=1024*1024)))
55-
.def("flush", &G3Writer::Flush)
56-
.def("tell", &G3Writer::Tell)
57-
.def_readonly("__g3module__", true)
43+
register_g3module<G3Writer>(scope, "G3Writer",
44+
"Writes frames to disk. Frames will be written to the file specified by "
45+
"filename. If filename ends in .gz, output will be compressed using gzip. "
46+
"To write only some types of frames, pass a list of the desired frame "
47+
"types to the second optional argument (streams). If no streams argument "
48+
"is given, writes all types of frames. If append is set to True, will "
49+
"append frames to its output file rather than overwriting it.")
50+
.def(py::init<std::string, std::vector<G3Frame::FrameType>, bool, size_t>((
51+
py::arg("filename"), py::arg("streams")=std::vector<G3Frame::FrameType>(),
52+
py::arg("append")=false, py::arg("buffersize")=1024*1024)))
53+
.def("flush", &G3Writer::Flush)
54+
.def("tell", &G3Writer::Tell)
5855
;
5956
}

gcp/src/ACUStatus.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static bool operator == (const ACUStatus &a, const ACUStatus &b) {
6969
}
7070

7171
PYBINDINGS("gcp", scope) {
72-
py::enum_<enum ACUStatus::ACUState>("ACUState")
72+
register_enum<ACUStatus::ACUState>(scope, "ACUState")
7373
.value("IDLE", ACUStatus::IDLE)
7474
.value("TRACKING", ACUStatus::TRACKING)
7575
.value("WAIT_RESTART", ACUStatus::WAIT_RESTART)

gcp/src/ARCFileReader.cxx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -860,20 +860,19 @@ PYBINDINGS("gcp", scope) {
860860
;
861861

862862
// Instead of EXPORT_G3MODULE since there are two constructors
863-
py::class_<ARCFileReader, py::bases<G3Module>, std::shared_ptr<ARCFileReader>,
864-
boost::noncopyable>("ARCFileReader",
863+
register_g3module<ARCFileReader>(scope, "ARCFileReader",
865864
"Read GCP archive file (or files if you pass an iterable of paths). "
866865
"For non-SPT ARC file formats, please set Experiment to the "
867866
"appropriate value. Set track_filename to True to record the "
868-
"filename for each frame in the ._filename attribute (fragile).",
869-
py::init<std::string, Experiment, float, bool, size_t>((py::arg("filename"),
870-
py::arg("experiment")=Experiment::SPT, py::arg("timeout")=-1.,
871-
py::arg("track_filename")=false, py::arg("buffersize")=1024*1024)))
872-
.def(py::init<std::vector<std::string>, Experiment, float, bool, size_t>(
873-
(py::arg("filename"), py::arg("experiment")=Experiment::SPT,
867+
"filename for each frame in the ._filename attribute (fragile).")
868+
.def(py::init<std::string, Experiment, float, bool, size_t>((
869+
py::arg("filename"), py::arg("experiment")=Experiment::SPT,
870+
py::arg("timeout")=-1., py::arg("track_filename")=false,
871+
py::arg("buffersize")=1024*1024)))
872+
.def(py::init<std::vector<std::string>, Experiment, float, bool, size_t>((
873+
py::arg("filename"), py::arg("experiment")=Experiment::SPT,
874874
py::arg("timeout")=-1., py::arg("track_filename")=false,
875875
py::arg("buffersize")=1024*1024)))
876-
.def_readonly("__g3module__", true)
877876
;
878877
}
879878

0 commit comments

Comments
 (0)