@@ -50,7 +50,10 @@ class Looper(object):
50
50
def __init__ ( self , name ,
51
51
config ,
52
52
nEvents = None ,
53
- firstEvent = 0 , nPrint = 0 , timeReport = False ):
53
+ firstEvent = 0 ,
54
+ nPrint = 0 ,
55
+ timeReport = False ,
56
+ quiet = False ):
54
57
"""Handles the processing of an event sample.
55
58
An Analyzer is built for each Config.Analyzer present
56
59
in sequence. The Looper can then be used to process an event,
@@ -70,7 +73,8 @@ def __init__( self, name,
70
73
self .logger .addHandler (logging .FileHandler ('/' .join ([self .name ,
71
74
'log.txt' ])))
72
75
self .logger .propagate = False
73
- # self.logger.addHandler( logging.StreamHandler(sys.stdout) )
76
+ if not quiet :
77
+ self .logger .addHandler ( logging .StreamHandler (sys .stdout ) )
74
78
75
79
self .cfg_comp = config .components [0 ]
76
80
self .classes = {}
@@ -169,13 +173,23 @@ def loop(self):
169
173
170
174
except UserWarning :
171
175
print 'Stopped loop following a UserWarning exception'
172
- for analyzer in self .analyzers :
173
- analyzer .endLoop (self .setup )
176
+
174
177
info = self .logger .info
178
+ info ('number of events processed: {nEv}' .format (nEv = iEv + 1 ))
175
179
info ('' )
176
180
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 ("" )
179
193
180
194
def process (self , iEv ):
181
195
"""Run event processing for all analyzers in the sequence.
@@ -210,15 +224,6 @@ def write(self):
210
224
analyzer .write (self .setup )
211
225
self .setup .close ()
212
226
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
222
227
223
228
224
229
if __name__ == '__main__' :
@@ -242,6 +247,6 @@ def write(self):
242
247
cfg .config .components = [comp ]
243
248
events_class = cfg .config .events_class
244
249
245
- looper = Looper ( 'Loop' , cfg .config ,nPrint = 5 )
250
+ looper = Looper ( 'Loop' , cfg .config , nPrint = 5 )
246
251
looper .loop ()
247
252
looper .write ()
0 commit comments