Skip to content

Commit 61e4f12

Browse files
committed
finalized more silent printout
1 parent 37445f8 commit 61e4f12

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

framework/looper.py

+21-16
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ class Looper(object):
5050
def __init__( self, name,
5151
config,
5252
nEvents=None,
53-
firstEvent=0, nPrint=0, timeReport=False ):
53+
firstEvent=0,
54+
nPrint=0,
55+
timeReport=False,
56+
quiet=False):
5457
"""Handles the processing of an event sample.
5558
An Analyzer is built for each Config.Analyzer present
5659
in sequence. The Looper can then be used to process an event,
@@ -70,7 +73,8 @@ def __init__( self, name,
7073
self.logger.addHandler(logging.FileHandler('/'.join([self.name,
7174
'log.txt'])))
7275
self.logger.propagate = False
73-
# self.logger.addHandler( logging.StreamHandler(sys.stdout) )
76+
if not quiet:
77+
self.logger.addHandler( logging.StreamHandler(sys.stdout) )
7478

7579
self.cfg_comp = config.components[0]
7680
self.classes = {}
@@ -169,13 +173,23 @@ def loop(self):
169173

170174
except UserWarning:
171175
print 'Stopped loop following a UserWarning exception'
172-
for analyzer in self.analyzers:
173-
analyzer.endLoop(self.setup)
176+
174177
info = self.logger.info
178+
info('number of events processed: {nEv}'.format(nEv=iEv+1))
175179
info('')
176180
info( self.cfg_comp )
177-
info('')
178-
info('number of events processed: {nEv}'.format(nEv=iEv+1))
181+
info('')
182+
for analyzer in self.analyzers:
183+
analyzer.endLoop(self.setup)
184+
if self.timeReport:
185+
allev = max([x['events'] for x in self.timeReport])
186+
info = self.logger.info
187+
info("\n ---- TimeReport (all times in ms; first evt is skipped) ---- ")
188+
info("%9s %9s %9s %9s %s" % ("processed","all evts","time/proc", " time/all", "analyer"))
189+
info("%9s %9s %9s %9s %s" % ("---------","--------","---------", "---------", "-------------"))
190+
for ana,rep in zip(self.analyzers,self.timeReport):
191+
info( "%9d %9d %10.2f %10.2f %s" % ( rep['events'], allev, 1000*rep['time']/(rep['events']-1) if rep['events']>1 else 0, 1000*rep['time']/(allev-1) if allev > 1 else 0, ana.name))
192+
info("")
179193

180194
def process(self, iEv ):
181195
"""Run event processing for all analyzers in the sequence.
@@ -210,15 +224,6 @@ def write(self):
210224
analyzer.write(self.setup)
211225
self.setup.close()
212226

213-
if self.timeReport:
214-
allev = max([x['events'] for x in self.timeReport])
215-
print "\n ---- TimeReport (all times in ms; first evt is skipped) ---- "
216-
print "%9s %9s %9s %9s %s" % ("processed","all evts","time/proc", " time/all", "analyer")
217-
print "%9s %9s %9s %9s %s" % ("---------","--------","---------", "---------", "-------------")
218-
for ana,rep in zip(self.analyzers,self.timeReport):
219-
print "%9d %9d %10.2f %10.2f %s" % ( rep['events'], allev, 1000*rep['time']/(rep['events']-1) if rep['events']>1 else 0, 1000*rep['time']/(allev-1) if allev > 1 else 0, ana.name)
220-
print ""
221-
pass
222227

223228

224229
if __name__ == '__main__':
@@ -242,6 +247,6 @@ def write(self):
242247
cfg.config.components=[comp]
243248
events_class = cfg.config.events_class
244249

245-
looper = Looper( 'Loop', cfg.config,nPrint = 5)
250+
looper = Looper( 'Loop', cfg.config, nPrint = 5)
246251
looper.loop()
247252
looper.write()

scripts/heppy_loop.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def runLoop( comp, outDir, config, options):
3131
loop = Looper( fullName,
3232
config,
3333
options.nevents, 0,
34-
nPrint = options.nprint)
34+
nPrint = options.nprint,
35+
timeReport = True,
36+
quiet=options.quiet)
3537
# print loop
3638
if options.iEvent is None:
3739
loop.loop()
@@ -169,7 +171,12 @@ def main( options, args ):
169171
action='store_true',
170172
help="don't ask questions in case output directory already exists.",
171173
default=False)
172-
174+
parser.add_option("-q", "--quiet",
175+
dest="quiet",
176+
action='store_true',
177+
help="do not print log messages to screen.",
178+
default=False)
179+
173180
(options,args) = parser.parse_args()
174181

175182
main(options, args)

test/simple_example_cfg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@
5656
services = services,
5757
events_class = Events )
5858

59-
print config
59+
# print config

0 commit comments

Comments
 (0)