17 from multiprocessing
import Process, Queue
19 from Configurables
import LHCbApp
21 from ROOT
import TBuffer, TBufferFile, TFile
23 from GaudiPython
import AppMgr, gbl
35 tf = TFile(fname,
"REC")
39 importOptions(
"$ENV_PROJECT_SOURCE_DIR/RootCnv/options/Setup.opts")
46 ApplicationMgr(OutputLevel=ERROR, AppName=
"File Check - Serial vs Parallel")
54 pf = TFile(pname,
"REC")
55 sf = TFile(sname,
"REC")
57 pfks = pf.GetListOfKeys()
58 sfks = sf.GetListOfKeys()
59 pfkeys = list([pfk.GetName()
for pfk
in pfks])
61 sfkeys = list([sfk.GetName()
for sfk
in sfks])
67 if k.startswith(event):
69 elif k.startswith(
"##"):
77 if k.startswith(event):
79 elif k.startswith(
"##"):
87 print(
"Meta Data differs")
92 print(
"Event data differs")
100 print(
"Extra Data in parallel file : ", pExtra)
102 print(
"Extra Data in serial file : ", sExtra)
104 print(
"Files will have different sizes")
112 nkeys = len(d.keys())
116 if vals.count(v) > 1:
117 print(
"Dictionary cannot be switched, values not unique")
119 print(
"Dict has keys/values : %i/%i" % (nkeys, nvals))
122 for k, entry
in pairs:
136 print(
"Dictionary %s : " % (name))
137 for k
in iter(d.keys()):
138 print(
"\t", k,
"\t", d[k])
142 def Reader(readerType, filename, qacross, qToEngine):
159 header =
"/Event/Rec/Header"
169 eNumber = int(evt[header].evtNumber())
175 if readerType == SER:
182 elif readerType == PAR:
184 for serOrder
in iter(qacross.get,
None):
186 lsks = len(serOrder.keys())
187 lpks = len(order.keys())
188 print(
"Events in Files (serial/parallel) : %i / %i" % (lsks, lpks))
192 for i
in iter(serOrder.keys()):
193 if readerType == PAR:
194 i = order[serOrder[i]]
196 a.runSelectedEvents(fname, i)
200 ascii = dict([(l, (evt[l].__class__.__name__, evt[l].
__repr__()))
for l
in lst])
203 print(
"%s Reader Finished" % (readerType))
219 if pitem == sitem ==
None:
220 print(
"Termination Signals received ok")
223 print(
"pitem != sitem : ", pitem, sitem)
226 print(
"pitem != sitem : ", pitem, sitem)
230 print(
"Comparison Engine Finished")
232 print(
"Total Events Checked : %i" % (len(results)))
233 print(
"Perfect Matches : %i" % (sum(results)))
234 print(
"Errors : %i" % (len(results) - sum(results)))
247 ref =
"DataObject at 0x"
248 if a[:16] == b[:16] == ref:
263 if len(sks) == len(pks):
274 extras = list(set(pks) - set(sks))
276 if p[e][0] ==
"DataObject":
279 print(
"Extra Other thing found!", e, p[e][0])
294 if s[key][0] == p[key][0]:
299 if s[key][1] == p[key][1]:
314 print(
"Checking File Records")
316 parFSR = GetFSRdicts(par)
317 serFSR = GetFSRdicts(ser)
319 diff1 = set(parFSR[
"TimeSpanFSR"].iteritems()) - set(
320 serFSR[
"TimeSpanFSR"].iteritems()
322 diff2 = set(parFSR[
"EventCountFSR"].iteritems()) - set(
323 serFSR[
"EventCountFSR"].iteritems()
327 "\nDifferent entries in TimeSpanFSR: \t"
329 +
"\nDifferent entries in EventCountFSR:\t"
333 for k
in [
"LumiFSRBeamCrossing",
"LumiFSRBeam2",
"LumiFSRNoBeam"]:
334 diff3 = set(parFSR[k][
"key"]) - set(serFSR[k][
"key"])
335 diff4 = set(parFSR[k][
"incr"]) - set(serFSR[k][
"incr"])
336 diff5 = set(parFSR[k][
"integral"]) - set(serFSR[k][
"integral"])
338 "Different entries in "
355 for r
in lumi.runNumbers():
358 for f
in lumi.fileIDs():
361 sa = s.split(
"info (key/incr/integral) : ")[-1]
362 sa = sa.split(
"/")[:-1]
368 k, i, t = rec.split()
371 integral.append(int(t))
373 return (runs, files, key, incr, integral)
378 "TimeSpanFSR": {
"earliest": 0,
"latest": 0},
379 "LumiFSRBeamCrossing": {
"key": 0,
"incr": 0,
"integral": 0},
380 "LumiFSRBeam1": {
"key": 0,
"incr": 0,
"integral": 0},
381 "LumiFSRBeam2": {
"key": 0,
"incr": 0,
"integral": 0},
382 "LumiFSRNoBeam": {
"key": 0,
"incr": 0,
"integral": 0},
383 "EventCountFSR": {
"input": 0,
"output": 0,
"statusFlag": 0},
387 "from LumiAlgs.LumiFsrReaderConf import LumiFsrReaderConf as LumiFsrReader; LumiFsrReader().OutputLevel = INFO; LumiFsrReader().inputFiles = ['%s'] ;"
390 options +=
"LumiFsrReader().Persistency='ROOT'; LumiFsrReader().EvtMax = 1; from Configurables import LHCbApp; LHCbApp().Persistency='ROOT'; from Configurables import CondDB, DDDBConf;"
391 options +=
" CondDB().UseLatestTags=['%s']; DDDBConf(DataType='%s');" % (2011, 2011)
395 fsr = app.filerecordsvc()
397 lst = fsr.getHistoNames()
401 ob = fsr.retrieveObject(l)
404 assert ob.numberOfObjects() == 1
405 k = ob.containedObject(0)
406 runs, files, keys, increment, integral =
LumiFSR(k)
408 FSR[l[l.rfind(
"/") + 1 :]][
"runs"] = runs
409 FSR[l[l.rfind(
"/") + 1 :]][
"files"] = files
410 FSR[l[l.rfind(
"/") + 1 :]][
"key"] = keys
411 FSR[l[l.rfind(
"/") + 1 :]][
"incr"] = increment
412 FSR[l[l.rfind(
"/") + 1 :]][
"integral"] = integral
414 if "TimeSpanFSR" in l:
415 FSR[
"TimeSpanFSR"][
"earliest"] = ob.containedObject(0).earliest()
416 FSR[
"TimeSpanFSR"][
"latest"] = ob.containedObject(0).latest()
418 if "EventCountFSR" in l:
419 FSR[
"EventCountFSR"][
"input"] = ob.input()
420 FSR[
"EventCountFSR"][
"output"] = ob.output()
421 FSR[
"EventCountFSR"][
"statusFlag"] = ob.statusFlag()
433 print(
"Comparing File Records")
435 diff1 = set(parFSR[
"TimeSpanFSR"].iteritems()) - set(
436 serFSR[
"TimeSpanFSR"].iteritems()
438 diff2 = set(parFSR[
"EventCountFSR"].iteritems()) - set(
439 serFSR[
"EventCountFSR"].iteritems()
443 "\nDifferent entries in TimeSpanFSR: \t"
445 +
"\nDifferent entries in EventCountFSR:\t"
449 for k
in [
"LumiFSRBeamCrossing",
"LumiFSRBeam2",
"LumiFSRNoBeam"]:
450 diff3 = set(parFSR[k][
"key"]) - set(serFSR[k][
"key"])
451 diff4 = set(parFSR[k][
"incr"]) - set(serFSR[k][
"incr"])
452 diff5 = set(parFSR[k][
"integral"]) - set(serFSR[k][
"integral"])
454 "Different entries in "
464 print(
"\nParallel: \n" + str(parFSR))
465 print(
"\nSerial: \n" + str(serFSR))
468 if __name__ ==
"__main__":
473 "Please supply two arguments : > python loadFile <parallelFile> <serialFile>"
477 par =
"PFN:" + args[0]
478 ser =
"PFN:" + args[1]
479 print(
"Parallel File to be analysed : %s" % (par))
480 print(
"Serial File to be analysed : %s" % (ser))
489 par = Process(target=Reader, args=(PAR, par, qacross, pout))
490 ser = Process(target=Reader, args=(SER, ser, qacross, sout))
491 com = Process(target=ComparisonEngine, args=(pout, sout))
498 print(
"Check File Records")
506 sp = Process(target=GetFSRdict, args=(ser, sout))
507 pp = Process(target=GetFSRdict, args=(par, pout))
508 cp = Process(target=CompareFSR, args=(pout, sout))