|
Gaudi Framework, version v23r4 |
| Home | Generated: Mon Sep 17 2012 |
Functions | |
| def | checkKeys |
| def | CompareTrees |
| def | switchDict |
| def | printDict |
| def | Reader |
| def | ComparisonEngine |
| def | checkForAddressDifference |
| def | compareEvents |
| def | CheckFileRecords |
| def | LumiFSR |
| def | GetFSRdict |
| def | CompareFSR |
Variables | |
| string | PAR = 'PARALLEL' |
| string | SER = 'SERIAL' |
| args = sys.argv | |
| string | par = 'PFN:' |
| string | ser = 'PFN:' |
| list | pname = par[4:] |
| list | sname = ser[4:] |
| tuple | qacross = Queue() |
| tuple | pout = Queue() |
| tuple | sout = Queue() |
| tuple | com = Process( target = ComparisonEngine, args = ( pout, sout ) ) |
| tuple | sp = Process( target = GetFSRdict, args = ( ser, sout ) ) |
| tuple | pp = Process( target = GetFSRdict, args = ( par, pout ) ) |
| tuple | cp = Process( target = CompareFSR, args = ( pout, sout ) ) |
| def compareOutputFiles::CheckFileRecords | ( | par, | |
| ser | |||
| ) |
Definition at line 251 of file compareOutputFiles.py.
00252 : 00253 00254 print "Checking File Records" 00255 00256 parFSR = GetFSRdicts( par ) 00257 serFSR = GetFSRdicts( ser ) 00258 00259 00260 00261 diff1 = set( parFSR["TimeSpanFSR"].iteritems() ) - set( serFSR["TimeSpanFSR"].iteritems() ) 00262 diff2 = set( parFSR["EventCountFSR"].iteritems() ) - set( serFSR["EventCountFSR"].iteritems() ) 00263 00264 print "\nDifferent entries in TimeSpanFSR: \t" + str( len( diff1 ) ) + "\nDifferent entries in EventCountFSR:\t" + str( len( diff2 ) ) 00265 00266 for k in ["LumiFSRBeamCrossing", "LumiFSRBeam2", "LumiFSRNoBeam"]: 00267 diff3 = set( parFSR[k]["key"] ) - set( serFSR[k]["key"] ) 00268 diff4 = set( parFSR[k]["incr"] ) - set( serFSR[k]["incr"] ) 00269 diff5 = set( parFSR[k]["integral"] ) - set( serFSR[k]["integral"] ) 00270 print "Different entries in " + str( k ) + ": \tkey: " + str( len( diff3 ) ) + " increment: " + str( len( diff4 ) ) + " integral: " + str( len( diff5 ) ) 00271
| def compareOutputFiles::checkForAddressDifference | ( | a, | |
| b | |||
| ) |
Definition at line 194 of file compareOutputFiles.py.
00195 : 00196 # the __repr__() method for Event Data Objects will return a generic 00197 # string "DataObject at 0xADDRESS" for non-Pythonised objects 00198 # If these objects have the same path, they are equal, but this 00199 # cannot be tested with "==" in Python, as the memory address will 00200 # be different for the two different DataObjects, so this method 00201 # will check if the difference is in the address 00202 # 00203 # args : a, b two string representations 00204 ref = 'DataObject at 0x' 00205 if a[:16] == b[:16] == ref : return True 00206 else : return False 00207
| def compareOutputFiles::checkKeys | ( | name ) |
Definition at line 15 of file compareOutputFiles.py.
00016 : 00017 # Check the TTree keys in each file 00018 fname = name[4:] # TFile doesn't need the "PFN:" prefix 00019 tf = TFile( fname, 'REC' ) 00020 00021 00022 00023 00024 00025 importOptions( '$STDOPTS/LHCbApplication.opts' ) 00026 #importOptions( '$GAUDIPOOLDBROOT/options/GaudiPoolDbRoot.opts' ) 00027 importOptions( '$GAUDICNVROOT/options/Setup.opts' ) 00028 00029 00030 OutputStream( "DstWriter" ).Output = '' 00031 HistogramPersistencySvc().OutputFile = '' 00032 MessageSvc( OutputLevel = ERROR ) 00033 EventSelector().PrintFreq = 100 00034 00035 ApplicationMgr( OutputLevel = ERROR, 00036 AppName = 'File Check - Serial vs Parallel' ) 00037 # TopAlg = ['UnpackMCParticle', 'UnpackMCVertex'] )
| def compareOutputFiles::compareEvents | ( | s, | |
| p | |||
| ) |
Definition at line 208 of file compareOutputFiles.py.
00209 : 00210 # events in form of dictionary, with form 00211 # d[ path ] = tuple( className, string_repr ) 00212 00213 # check 1 : number of keys (paths) 00214 sks = s.keys() ; pks = p.keys() 00215 sks.sort() ; pks.sort() 00216 if len( sks ) == len( pks ) : pass 00217 else : 00218 # There may be extra keys in the parallel file 00219 # example: DstWriter may ask for /Event/Prev/MC/Header#1 00220 # but in TESSerializer, *all* DataObjects will be sent 00221 # including /Event/Prev and /Event/Prev/MC 00222 00223 # check for extra keys in the parallel file which are just containing DataObjects 00224 # if found, remove them 00225 00226 extras = list( set( pks ) - set( sks ) ) 00227 for e in extras : 00228 if p[e][0] == 'DataObject' : pks.remove( e ) 00229 else : print 'Extra Other thing found!', e, p[e][0] ; return False 00230 00231 # check 2 : same paths? 00232 if sks == pks : pass 00233 else : return False 00234 00235 # check 3 : check the content 00236 l = len( sks ) 00237 diffs = [] 00238 for i in xrange( l ) : 00239 key = sks[i] 00240 # compare class name 00241 if s[key][0] == p[key][0] : pass 00242 else : diffs.append( key ) 00243 # compare string representation 00244 if s[key][1] == p[key][1] : pass 00245 elif checkForAddressDifference( p[key][1], s[key][1] ) : pass 00246 else : diffs.append( key ) 00247 00248 # finish 00249 if diffs : return False 00250 else : return True
| def compareOutputFiles::CompareFSR | ( | pout, | |
| sout | |||
| ) |
Definition at line 356 of file compareOutputFiles.py.
00357 : 00358 00359 parFSR = pout.get() 00360 serFSR = sout.get() 00361 00362 print "Comparing File Records" 00363 00364 diff1 = set( parFSR["TimeSpanFSR"].iteritems() ) - set( serFSR["TimeSpanFSR"].iteritems() ) 00365 diff2 = set( parFSR["EventCountFSR"].iteritems() ) - set( serFSR["EventCountFSR"].iteritems() ) 00366 00367 print "\nDifferent entries in TimeSpanFSR: \t" + str( len( diff1 ) ) + "\nDifferent entries in EventCountFSR:\t" + str( len( diff2 ) ) 00368 00369 for k in ["LumiFSRBeamCrossing", "LumiFSRBeam2", "LumiFSRNoBeam"]: 00370 diff3 = set( parFSR[k]['key'] ) - set( serFSR[k]['key'] ) 00371 diff4 = set( parFSR[k]['incr'] ) - set( serFSR[k]['incr'] ) 00372 diff5 = set( parFSR[k]['integral'] ) - set( serFSR[k]["integral"] ) 00373 print "Different entries in " + str( k ) + ": \tkey: " + str( len( diff3 ) ) + " increment: " + str( len( diff4 ) ) + " integral: " + str( len( diff5 ) ) 00374 00375 00376 print "\nParallel: \n" + str( parFSR ) 00377 print "\nSerial: \n" + str( serFSR )
| def compareOutputFiles::CompareTrees | ( | pname, | |
| sname | |||
| ) |
Definition at line 41 of file compareOutputFiles.py.
00042 : 00043 pf = TFile( pname, 'REC' ) 00044 sf = TFile( sname, 'REC' ) 00045 event = '_Event' 00046 pfks = pf.GetListOfKeys() 00047 sfks = sf.GetListOfKeys() 00048 pfkeys = list( [pfk.GetName() for pfk in pfks] ) ; pfkeys.sort() 00049 sfkeys = list( [sfk.GetName() for sfk in sfks] ) ; sfkeys.sort() 00050 pMeta = [] ; pEvent = [] ; pOther = [] 00051 for k in pfkeys : 00052 if k.startswith( event ) : pEvent.append( k ) 00053 elif k.startswith( '##' ) : pMeta.append( k ) 00054 else : pOther.append( k ) 00055 sMeta = [] ; sEvent = [] ; sOther = [] 00056 for k in sfkeys : 00057 if k.startswith( event ) : sEvent.append( k ) 00058 elif k.startswith( '##' ) : sMeta.append( k ) 00059 else : sOther.append( k ) 00060 00061 if pMeta == sMeta : pass 00062 else : print 'Meta Data differs' 00063 00064 if pEvent == sEvent : pass 00065 else : print 'Event data differs' 00066 00067 if pOther != sOther : 00068 pset = set( pOther ) 00069 sset = set( sOther ) 00070 pExtra = pset - sset 00071 sExtra = sset - pset 00072 if pExtra : print 'Extra Data in parallel file : ', pExtra 00073 if sExtra : print 'Extra Data in serial file : ', sExtra 00074 if sExtra or pExtra : print 'Files will have different sizes' 00075 pf.Close() 00076 sf.Close()
| def compareOutputFiles::ComparisonEngine | ( | pQueue, | |
| sQueue | |||
| ) |
Definition at line 169 of file compareOutputFiles.py.
00170 : 00171 # The Comparison Engine runs on a seperate forked process and receives 00172 # events in pairs, one each from Serial FileReader and Parallel FileReader 00173 # 00174 # The events arrive in Dictionary Format, d[path]=(className, string_repr) 00175 # and are compared using the compareEvents method 00176 # 00177 # Results are stored in an array of bools (PerfectMatch=True, Diff=False) 00178 # 00179 results = [] 00180 while True : 00181 pitem = pQueue.get() 00182 sitem = sQueue.get() 00183 if pitem == sitem == None : print 'Termination Signals received ok' ; break 00184 elif pitem == None : print 'pitem != sitem : ', pitem, sitem ; break 00185 elif sitem == None : print 'pitem != sitem : ', pitem, sitem ; break 00186 results.append( compareEvents( pitem, sitem ) ) 00187 print '=' * 80 00188 print 'Comparison Engine Finished' 00189 print '-' * 80 00190 print 'Total Events Checked : %i' % ( len( results ) ) 00191 print 'Perfect Matches : %i' % ( sum( results ) ) 00192 print 'Errors : %i' % ( len( results ) - sum( results ) ) 00193 print '=' * 80
| def compareOutputFiles::GetFSRdict | ( | filename, | |
| queue | |||
| ) |
Definition at line 300 of file compareOutputFiles.py.
00301 : 00302 00303 00304 FSR = { "TimeSpanFSR" : {'earliest': 0, 'latest': 0}, 00305 "LumiFSRBeamCrossing" : {'key': 0, 'incr': 0, 'integral':0}, 00306 "LumiFSRBeam1" : {'key': 0, 'incr': 0, 'integral':0}, 00307 "LumiFSRBeam2" : {'key': 0, 'incr': 0, 'integral':0}, 00308 "LumiFSRNoBeam" : {'key': 0, 'incr': 0, 'integral':0}, 00309 "EventCountFSR" : {'input': 0, 'output': 0, 'statusFlag': 0}} 00310 00311 options = "from LumiAlgs.LumiFsrReaderConf import LumiFsrReaderConf as LumiFsrReader; LumiFsrReader().OutputLevel = INFO; LumiFsrReader().inputFiles = ['%s'] ;" %filename 00312 options += "LumiFsrReader().Persistency='ROOT'; LumiFsrReader().EvtMax = 1; from Configurables import LHCbApp; LHCbApp().Persistency='ROOT'; from Configurables import CondDB, DDDBConf;" 00313 options += " CondDB().UseLatestTags=['%s']; DDDBConf(DataType='%s');"%( 2011, 2011 ) 00314 exec options 00315 app = AppMgr() 00316 app.run( 1 ) 00317 fsr = app.filerecordsvc() 00318 00319 lst = fsr.getHistoNames() 00320 00321 if lst : 00322 for l in lst : 00323 00324 ob = fsr.retrieveObject( l ) 00325 00326 00327 if "LumiFSR" in l: 00328 00329 assert ob.numberOfObjects() == 1 00330 k = ob.containedObject( 0 ) 00331 runs, files, keys, increment, integral = LumiFSR( k ) 00332 00333 FSR[l[l.rfind( '/' ) + 1:]]['runs'] = runs 00334 FSR[l[l.rfind( '/' ) + 1:]]['files'] = files 00335 FSR[l[l.rfind( '/' ) + 1:]]['key'] = keys 00336 FSR[l[l.rfind( '/' ) + 1:]]['incr'] = increment 00337 FSR[l[l.rfind( '/' ) + 1:]]['integral'] = integral 00338 00339 00340 00341 if "TimeSpanFSR" in l: 00342 00343 FSR["TimeSpanFSR"]['earliest'] = ob.containedObject( 0 ).earliest() 00344 FSR["TimeSpanFSR"]['latest'] = ob.containedObject( 0 ).latest() 00345 00346 if "EventCountFSR" in l: 00347 00348 FSR["EventCountFSR"]['input'] = ob.input() 00349 FSR["EventCountFSR"]['output'] = ob.output() 00350 FSR["EventCountFSR"]['statusFlag'] = ob.statusFlag() 00351 00352 app.stop() 00353 app.finalize() 00354 00355 queue.put( FSR )
| def compareOutputFiles::LumiFSR | ( | lumi ) |
Definition at line 272 of file compareOutputFiles.py.
00273 : 00274 00275 runs = [] 00276 files = [] 00277 info = {} 00278 keys = [] 00279 00280 for r in lumi.runNumbers() : 00281 runs.append( r ) 00282 00283 for f in lumi.fileIDs() : 00284 files.append( f ) 00285 s = str( lumi ) 00286 sa = s.split( "info (key/incr/integral) : " )[-1] 00287 sa = sa.split( '/' )[:-1] 00288 00289 key = [] 00290 incr = [] 00291 integral = [] 00292 for rec in sa : 00293 k, i, t = rec.split() 00294 key.append( int( k ) ) 00295 incr.append( int( i ) ) 00296 integral.append( int( t ) ) 00297 00298 return ( runs, files, key, incr, integral ) 00299
| def compareOutputFiles::printDict | ( | d, | |
name = 'unspecified' |
|||
| ) |
Definition at line 94 of file compareOutputFiles.py.
| def compareOutputFiles::Reader | ( | readerType, | |
| filename, | |||
| qacross, | |||
| qToEngine | |||
| ) |
Definition at line 109 of file compareOutputFiles.py.
00110 : 00111 # 00112 # Process for reading a file 00113 # One process for reading Serial File, another for Parallel File 00114 # 00115 # First the order of events is determined, (parallel != serial, usually) 00116 # 00117 # Then the events are run *in order* using AppMgr().runSelectedEvents(pfn, evtNumber) 00118 # on both Serial-Reader and Parallel-Reader processes. 00119 # 00120 # The string repr of everything in the TES is placed in a dictionary and 00121 # sent to the comparison Process, which compares the two dictionaries 00122 # 00123 a = AppMgr() 00124 sel = a.evtsel() 00125 evt = a.evtsvc() 00126 00127 header = '/Event/Rec/Header' 00128 sel.open( filename ) 00129 ct = 0 00130 order = {} 00131 fname = filename[4:] # runSelectedEvents doesn't need the "PFN:" prefix 00132 00133 # determine the ordering 00134 while True : 00135 a.run( 1 ) 00136 if evt[header] : 00137 eNumber = int( evt[header].evtNumber() ) 00138 order[eNumber] = ct 00139 ct += 1 00140 else : break 00141 00142 if readerType == SER : 00143 # send the ordering details to the parallel-reader 00144 order = switchDict( order ) 00145 qacross.put( order ) 00146 qacross.put( None ) 00147 # changeName 00148 serOrder = order 00149 elif readerType == PAR : 00150 # receive the serial ordering from queue, and send ordering to SerialReader 00151 for serOrder in iter( qacross.get, None ) : pass 00152 lsks = len( serOrder.keys() ) 00153 lpks = len( order.keys() ) 00154 print 'Events in Files (serial/parallel) : %i / %i' % ( lsks, lpks ) 00155 00156 # now run files in the order specified by the serial ordering 00157 # and send them one by one to the comparison engine 00158 for i in iter( serOrder.keys() ) : 00159 if readerType == PAR : i = order[serOrder[i]] 00160 00161 a.runSelectedEvents( fname, i ) 00162 lst = evt.getList() 00163 00164 lst.sort() 00165 ascii = dict( [ ( l, ( evt[l].__class__.__name__, evt[l].__repr__() ) ) for l in lst ] ) 00166 qToEngine.put( ascii ) 00167 qToEngine.put( None ) 00168 print '%s Reader Finished' % ( readerType )
| def compareOutputFiles::switchDict | ( | d ) |
Definition at line 77 of file compareOutputFiles.py.
00078 : 00079 # switch a dictionary around ; make the values the keys, and vice versa 00080 # only works if all values are unique 00081 nkeys = len( d.keys() ) 00082 vals = d.values() 00083 nvals = len( vals ) 00084 for v in vals : 00085 if vals.count( v ) > 1 : 00086 print 'Dictionary cannot be switched, values not unique' 00087 return None 00088 print 'Dict has keys/values : %i/%i' % ( nkeys, nvals ) 00089 pairs = d.items() # returns (key, val) tuples in a list 00090 newd = {} 00091 for k, entry in pairs : newd[entry] = k 00092 return newd 00093
| compareOutputFiles::args = sys.argv |
Definition at line 380 of file compareOutputFiles.py.
| tuple compareOutputFiles::com = Process( target = ComparisonEngine, args = ( pout, sout ) ) |
Definition at line 401 of file compareOutputFiles.py.
| tuple compareOutputFiles::cp = Process( target = CompareFSR, args = ( pout, sout ) ) |
Definition at line 418 of file compareOutputFiles.py.
| list compareOutputFiles::par = 'PFN:' |
Definition at line 386 of file compareOutputFiles.py.
| string compareOutputFiles::PAR = 'PARALLEL' |
Definition at line 38 of file compareOutputFiles.py.
| list compareOutputFiles::pname = par[4:] |
Definition at line 392 of file compareOutputFiles.py.
| tuple compareOutputFiles::pout = Queue() |
Definition at line 396 of file compareOutputFiles.py.
| tuple compareOutputFiles::pp = Process( target = GetFSRdict, args = ( par, pout ) ) |
Definition at line 417 of file compareOutputFiles.py.
| tuple compareOutputFiles::qacross = Queue() |
Definition at line 395 of file compareOutputFiles.py.
| string compareOutputFiles::SER = 'SERIAL' |
Definition at line 39 of file compareOutputFiles.py.
| list compareOutputFiles::ser = 'PFN:' |
Definition at line 387 of file compareOutputFiles.py.
| list compareOutputFiles::sname = ser[4:] |
Definition at line 393 of file compareOutputFiles.py.
| tuple compareOutputFiles::sout = Queue() |
Definition at line 397 of file compareOutputFiles.py.
| tuple compareOutputFiles::sp = Process( target = GetFSRdict, args = ( ser, sout ) ) |
Definition at line 416 of file compareOutputFiles.py.