6 from PROCTools.getFileLists
import tctPath, findTCTFiles
8 from ROOT
import TFile,TTree
9 from PROCTools.diffTAGTree
import diffTTree
11 os.environ[
'STAGE_SVCCLASS']=
"atlascerngroupdisk"
12 os.environ[
'STAGE_HOST']=
"castoratlast3"
14 ignoreTrees=
set((
"CollectionMetadata",))
17 if rName.startswith(
"/castor"):
18 rFile=TFile.Open(
"root://castoratlas/"+rName)
19 elif rName.startswith(
"/eos"):
20 rFile=TFile.Open(
"root://eosatlas.cern.ch/"+rName)
22 rFile=TFile.Open(rName)
24 if vName.startswith(
"/castor"):
25 vFile=TFile.Open(
"root://castoratlas/"+vName)
26 elif vName.startswith(
"/eos"):
27 vFile=TFile.Open(
"root://eosatlas.cern.ch/"+vName)
29 vFile=TFile.Open(vName)
32 print (
"Failed to open reference file",rName)
36 print (
"Failed to open validation file",vName)
40 for k
in rFile.GetListOfKeys():
41 rKeys.add(k.GetName())
43 for k
in vFile.GetListOfKeys():
44 vKeys.add(k.GetName())
51 print (
"ERROR no common trees names found in files",rName,vName)
59 if not isinstance(rTree,TTree):
61 if not isinstance(vTree,TTree):
63 print (
"Comparing TTree",k)
69 def diffPoolFiles(ref,chk,details,toIgnore = ['RecoTimingObj_p1_RAWtoESD_timings', 'RecoTimingObj_p1_ESDtoAOD_timings']):
70 import PyUtils.PoolFile
as PF
72 df = PF.DiffFiles( refFileName = ref, chkFileName = chk, ignoreList = toIgnore)
76 df.printSummary(details)
80 print (
"Exception caught while diff'ing POOL files")
86 ref_nlines =
open(ref).readlines()
87 chk_nlines =
open(chk).readlines()
88 if len(ref_nlines) == len(chk_nlines):
90 print (
"same number of lines!")
92 print (ref,
" has ",len(ref_nlines),
" lines." )
93 print (chk,
" has ",len(chk_nlines),
" lines.")
103 print (
"Exception caught while comparinging jobReport(_RecoTrf)?.gpickle files")
107 if __name__ ==
"__main__":
108 if len(sys.argv)<3
or sys.argv[1]==
"-h" or sys.argv[1]==
"--help":
109 print (
"Usage: compareTCTs.py --nRef=<refernce nightly number> --nVal=<validation nightly number> --rRef=<reference nightly> --rVal=<validation nightly> --details=<text file> --file=<pattern> --sum=<summary file> --refPath=<path to ref-nightly> --valPath=<path to val-nightly>")
110 print (
" Example: compareTCTs.py --nRef=15.6.X.Y --nVal=15.6.X.Y-VAL --rel=rel_4")
124 opts,args=getopt.getopt(sys.argv[1:],
"b",[
"nRef=",
"nVal=",
"rRef=",
"rVal=",
"rel=",
"nightly=",
"details=",
"file=",
"sum=",
"refPath=",
"valPath=",
"diff-root="])
126 if o==
"--nRef": nRef=a
127 if o==
"--nVal": nVal=a
128 if o==
"--rRef": rRef=a
129 if o==
"--rVal": rVal=a
130 if o==
"--nightly": nRef=nVal=a
131 if o==
"--rel": rVal=rRef=a
132 if o==
"--details": detailsFN=a
133 if o==
"--file": filePattern+=(a,)
134 if o==
"--sum": sumFileName=a
135 if o==
"--refPath": refPath=a
136 if o==
"--valPath": valPath=a
138 if a==
"True": diffroot=
True
142 print (
"Reference nightly not defined! Please use --nRef parameter!")
146 print (
"Reference nightly number not defined! Please use --rRef parameter!")
151 print (
"Validation nightly not defined! Please use --nVal parameter!")
154 print (
"Validation nightly number not defined! Please use --rVal parameter!")
157 if len(filePattern)==0:
158 filePattern+=(
".*myESD.*pool.root$",
".*myRDO.*pool.root$",
".*myAOD.*pool.root$",
"myTAG.*.root$",
"jobReport(_RecoTrf)?.gpickle$")
160 for i
in range(len(filePattern)):
162 if filePattern[i].
upper()==
"ROOT":
163 filePattern[i]=
"*root$"
164 elif filePattern[i].
upper()==
"POOL":
165 filePattern[i]=
"*.pool.root$"
166 elif filePattern[i].
upper()==
"ESD":
167 filePattern[i]=
".*myESD.*pool.root$"
168 elif filePattern[i].
upper()==
"RDO":
169 filePattern[i]=
".*myRDO.*pool.root$"
170 elif filePattern[i].
upper()==
"AOD":
171 filePattern[i]=
".*myAOD.*pool.root$"
172 elif filePattern[i].
upper()==
"TAGCOMM":
173 filePattern[i]=
"myTAGCOMM.*root$"
174 elif filePattern[i]==
"TAG":
175 filePattern[i]=
"myTAG.*.root$"
176 elif filePattern[i].
upper()==
"NONE":
181 print (
"Comparing files matching:" )
186 for fP
in filePattern:
187 if fP.find(
"pool") == -1:
188 allPatterns.append(fP)
190 allPatterns.insert(0, fP)
198 if not os.access(refPath, os.R_OK):
199 print (
"Can't access output of reference TCT at",refPath)
202 if not os.access(valPath, os.R_OK):
203 print (
"Can't access output of validation TCT at",valPath)
206 msg =
"Reference TCT:\n"
207 msg += refPath +
"\n"
208 msg +=
"Validation TCT:\n"
209 msg += valPath +
"\n"
212 if detailsFN
is not None:
218 ff = findTCTFiles(refPath,valPath)
219 tctlist=ff.getCommonChains()
220 print (
"Output from findTCTFile.getCommonChains():")
226 for pattern
in allPatterns:
229 filesToCompare = ff.findFiles(pattern)
230 print (
"Will now look for files matching pattern:", pattern)
231 print (
"The found files to compare:", filesToCompare)
232 print (
"Comparing files matching [%s]" % pattern)
233 Summary +=
"Comparing files matching [%s]\n" % pattern
235 for name,rv
in filesToCompare.items():
237 print (
"Chain %s: Found %i files matching [%s]" % (name,len(rv),pattern))
239 fileName=r.split(
'/')[-1]
240 print (
"Comparing files",fileName,
"of TCT",name)
242 if (fileName.endswith(
".pool.root")
and not fileName.startswith(
"myTAG")):
243 if(r.startswith(
"/eos")): r =
"root://eosatlas.cern.ch/"+r
244 if(v.startswith(
"/eos")): v =
"root://eosatlas.cern.ch/"+v
247 stat=os.system(
"acmd.py diff-root "+r+
" "+v+
" --error-mode resilient --ignore-leaves HITStoRDO_timings RecoTimingObj_p1_HITStoRDO_timings RecoTimingObj_p1_RAWtoESD_mems RecoTimingObj_p1_RAWtoESD_timings RAWtoESD_mems RAWtoESD_timings ESDtoAOD_mems ESDtoAOD_timings RAWtoALL_mems RAWtoALL_timings RecoTimingObj_p1_RAWtoALL_mems RecoTimingObj_p1_RAWtoALL_timings --entries 10 > tmp.txt")
248 os.system(
"cat tmp.txt|grep -v sync")
249 os.system(
"rm -f tmp.txt")
251 elif fileName.endswith(
".root"):
255 stat=os.system(
"diffTAGTree.py "+r+
" "+v+
" > tmp.txt")
256 os.system(
"cat tmp.txt|grep -v sync")
257 os.system(
"rm -f tmp.txt")
259 elif fileName.endswith(
".pickle"):
263 print (
"ERROR: Don't know how to compare",fileName)
267 if name
not in statPerChain:
268 statPerChain[name]=
False
270 statPerChain[name]|=
False
271 print (
"Files are identical")
273 statPerChain[name]=
True
275 print (
"Files are not identical")
277 Summary+=
"Found %i identical files and %i different files\n" % (nIdenticalFiles, nDifferentFiles)
278 print (
"Found %i identical files and %i different files\n" % (nIdenticalFiles, nDifferentFiles))
280 if details
is not None:
281 details.write(Summary)
289 for (name,info)
in tctlist.items():
291 if len(info)<2:
continue
292 print (
"\n"+name+
":")
293 if (info[0].loglines>0
and info[1].loglines>0):
294 ratio=100.0*(info[1].loglines-info[0].loglines)/info[0].loglines
295 ln=
"\tLoglines: %i -> %i (%.2f)" % (info[0].loglines,info[1].loglines,ratio)
298 complain+=name+
" "+ln+
"***\n"
301 if len(info[0].cpulist)>4
and len(info[1].cpulist)>4:
303 cpu_r=info[0].cpulist[1]
304 cpu_v=info[1].cpulist[1]
305 if (cpu_r>0
and cpu_v>0):
306 ratio=100.0*(cpu_v-cpu_r)/cpu_r
307 ln=
"\tESD CPU: %i -> %i (%.2f%%)" % (cpu_r,cpu_v,ratio)
310 complain+=name+
" "+ln+
"***\n"
315 cpu_r=info[0].cpulist[4]
316 cpu_v=info[1].cpulist[4]
317 if (cpu_r>0
and cpu_v>0):
318 ratio=100.0*(cpu_v-cpu_r)/cpu_r
319 ln=
"\tAOD CPU: %i -> %i (%.2f%%)" % (cpu_r,cpu_v,ratio)
322 complain+=name+
" "+ln+
"***\n"
326 if len(info[0].memlist)>4
and len(info[1].memlist)>4:
327 mem_r=info[0].memlist[1]
328 mem_v=info[1].memlist[1]
329 if (mem_r>0
and mem_v>0):
330 ratio=100.0*(mem_v-mem_r)/mem_r
331 ln=
"\tESD MEM: %i -> %i (%.2f%%)" % (mem_r,mem_v,ratio)
334 complain+=name+
" "+ln+
"***\n"
338 mem_r=info[0].memlist[4]
339 mem_v=info[1].memlist[4]
340 if (mem_r>0
and mem_v>0):
341 ratio=100.0*(mem_v-mem_r)/mem_r
342 ln=
"\tAOD MEM: %i -> %i (%.2f%%)" % (mem_r,mem_v,ratio)
345 complain+=name+
" "+ln+
"***\n"
350 for f,s
in statPerChain.items():
352 print (
"%-70s CHANGED" % f)
355 print (
"%-70s IDENTICAL" % f)
357 if sumFileName
is not None:
359 for f,s
in statPerChain.items():
364 line +=
"IDENTICAL\n"
367 sumFile.write(
"\n\n")
368 sumFile.write(complain)