33from spt3g import core
44import time
55
6+ nframes = 1000
7+ verbose = False
8+
69# File to disk
10+ core .log_notice ("Writing %d frames to disk" % nframes )
711pipe = core .G3Pipeline ()
8- pipe .Add (core .G3InfiniteSource , type = core .G3FrameType .Timepoint , n = 10 )
12+ pipe .Add (core .G3InfiniteSource , type = core .G3FrameType .Timepoint , n = nframes )
913# Drop a wiring frame in the middle
1014count = 0
1115def addwiring (fr ):
@@ -25,16 +29,18 @@ def addinfo(fr):
2529 fr ['count' ] = n
2630 n += 1
2731pipe .Add (addinfo )
28- pipe .Add (core .Dump )
32+ if verbose :
33+ pipe .Add (core .Dump )
2934pipe .Add (core .G3Writer , filename = 'test.g3' )
30- pipe .Run ()
31- assert n == 10 , 'Wrong number of frames written (%d should be %d)' % (n , 10 )
35+ pipe .Run (profile = True )
36+ assert n == nframes , 'Wrong number of frames written (%d should be %d)' % (n , nframes )
3237
3338# And back from disk
34- print ( ' Reading' )
39+ core . log_notice ( " Reading %d frames from disk" % nframes )
3540pipe = core .G3Pipeline ()
3641pipe .Add (core .G3Reader , filename = 'test.g3' , track_filename = True )
37- pipe .Add (core .Dump )
42+ if verbose :
43+ pipe .Add (core .Dump )
3844n = 0
3945def checkinfo (fr ):
4046 global n
@@ -45,20 +51,21 @@ def checkinfo(fr):
4551 assert fr ._filename == 'test.g3' , 'Wrong filename'
4652 n += 1
4753pipe .Add (checkinfo )
48- pipe .Run ()
54+ pipe .Run (profile = True )
4955
50- assert n == 10 , 'Wrong number of frames read (%d should be %d)' % (n , 10 )
56+ assert n == nframes , 'Wrong number of frames read (%d should be %d)' % (n , nframes )
5157
5258# Skip empty files
59+ core .log_notice ("Reading %d frames from disk with empty files" % nframes )
5360with core .G3Writer ("empty.g3" ) as wr :
5461 pass
5562n = 0
5663pipe = core .G3Pipeline ()
5764pipe .Add (core .G3Reader , filename = ["empty.g3" , "test.g3" , "empty.g3" ], track_filename = True )
5865pipe .Add (checkinfo )
59- pipe .Run ()
66+ pipe .Run (profile = True )
6067
61- assert n == 10 , 'Wrong number of frames read (%d should be %d)' % (n , 10 )
68+ assert n == nframes , 'Wrong number of frames read (%d should be %d)' % (n , nframes )
6269
6370# Indexing
6471class CachingReader :
@@ -78,10 +85,12 @@ def __call__(self, frame):
7885
7986cacher = CachingReader ()
8087
88+ core .log_notice ("Reading %d frames from disk with frame indexing" % nframes )
8189pipe = core .G3Pipeline ()
8290pipe .Add (cacher )
83- pipe .Add (core .Dump )
84- pipe .Run ()
91+ if verbose :
92+ pipe .Add (core .Dump )
93+ pipe .Run (profile = True )
8594
8695assert cacher .w_pos is not None , 'Missing wiring frame'
8796
@@ -107,10 +116,12 @@ def __call__(self, frame):
107116
108117cached = CachedReader (start = cacher .w_pos )
109118
119+ core .log_notice ("Reading %d frames from disk with seek" % nframes )
110120pipe = core .G3Pipeline ()
111121pipe .Add (cached )
112- pipe .Add (core .Dump )
113- pipe .Run ()
122+ if verbose :
123+ pipe .Add (core .Dump )
124+ pipe .Run (profile = True )
114125
115126assert cached .pos is None , "Missing wiring frame"
116127
0 commit comments