6 from PROCTools.getFileLists
import tctPath, findTCTFiles
8 from ROOT
import TFile,TTree
9 from PROCTools.diffTAGTree
import diffTTree
12 os.environ[
'STAGE_SVCCLASS']=
"atlascerngroupdisk"
13 os.environ[
'STAGE_HOST']=
"castoratlast3"
15 ignoreTrees=
set((
"CollectionMetadata",))
18 if rName.startswith(
"/castor"):
19 rFile=TFile.Open(
"root://castoratlas/"+rName)
20 elif rName.startswith(
"/eos"):
21 rFile=TFile.Open(
"root://eosatlas.cern.ch/"+rName)
23 rFile=TFile.Open(rName)
25 if vName.startswith(
"/castor"):
26 vFile=TFile.Open(
"root://castoratlas/"+vName)
27 elif vName.startswith(
"/eos"):
28 vFile=TFile.Open(
"root://eosatlas.cern.ch/"+vName)
30 vFile=TFile.Open(vName)
33 print (
"Failed to open reference file",rName)
37 print (
"Failed to open validation file",vName)
41 for k
in rFile.GetListOfKeys():
42 rKeys.add(k.GetName())
44 for k
in vFile.GetListOfKeys():
45 vKeys.add(k.GetName())
52 print (
"ERROR no common trees names found in files",rName,vName)
60 if not isinstance(rTree,TTree):
62 if not isinstance(vTree,TTree):
64 print (
"Comparing TTree",k)
70 def diffPoolFiles(ref,chk,details,toIgnore = ['RecoTimingObj_p1_RAWtoESD_timings', 'RecoTimingObj_p1_ESDtoAOD_timings']):
71 import PyUtils.PoolFile
as PF
73 df = PF.DiffFiles( refFileName = ref, chkFileName = chk, ignoreList = toIgnore)
77 df.printSummary(details)
81 print (
"Exception caught while diff'ing POOL files")
87 ref_nlines =
open(ref).readlines()
88 chk_nlines =
open(chk).readlines()
89 if len(ref_nlines) == len(chk_nlines):
91 print (
"same number of lines!")
93 print (ref,
" has ",len(ref_nlines),
" lines." )
94 print (chk,
" has ",len(chk_nlines),
" lines.")
104 print (
"Exception caught while comparinging jobReport(_RecoTrf)?.gpickle files")
108 if __name__ ==
"__main__":
109 if len(sys.argv)<3
or sys.argv[1]==
"-h" or sys.argv[1]==
"--help":
110 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>")
111 print (
" Example: compareTCTs.py --nRef=15.6.X.Y --nVal=15.6.X.Y-VAL --rel=rel_4")
125 opts,args=getopt.getopt(sys.argv[1:],
"b",[
"nRef=",
"nVal=",
"rRef=",
"rVal=",
"rel=",
"nightly=",
"details=",
"file=",
"sum=",
"refPath=",
"valPath=",
"diff-root="])
127 if o==
"--nRef": nRef=a
128 if o==
"--nVal": nVal=a
129 if o==
"--rRef": rRef=a
130 if o==
"--rVal": rVal=a
131 if o==
"--nightly": nRef=nVal=a
132 if o==
"--rel": rVal=rRef=a
133 if o==
"--details": detailsFN=a
134 if o==
"--file": filePattern+=(a,)
135 if o==
"--sum": sumFileName=a
136 if o==
"--refPath": refPath=a
137 if o==
"--valPath": valPath=a
139 if a==
"True": diffroot=
True
143 print (
"Reference nightly not defined! Please use --nRef parameter!")
147 print (
"Reference nightly number not defined! Please use --rRef parameter!")
152 print (
"Validation nightly not defined! Please use --nVal parameter!")
155 print (
"Validation nightly number not defined! Please use --rVal parameter!")
158 if len(filePattern)==0:
159 filePattern+=(
".*myESD.*pool.root$",
".*myRDO.*pool.root$",
".*myAOD.*pool.root$",
"myTAG.*.root$",
"jobReport(_RecoTrf)?.gpickle$")
161 for i
in range(len(filePattern)):
163 if filePattern[i].
upper()==
"ROOT":
164 filePattern[i]=
"*root$"
165 elif filePattern[i].
upper()==
"POOL":
166 filePattern[i]=
"*.pool.root$"
167 elif filePattern[i].
upper()==
"ESD":
168 filePattern[i]=
".*myESD.*pool.root$"
169 elif filePattern[i].
upper()==
"RDO":
170 filePattern[i]=
".*myRDO.*pool.root$"
171 elif filePattern[i].
upper()==
"AOD":
172 filePattern[i]=
".*myAOD.*pool.root$"
173 elif filePattern[i].
upper()==
"TAGCOMM":
174 filePattern[i]=
"myTAGCOMM.*root$"
175 elif filePattern[i]==
"TAG":
176 filePattern[i]=
"myTAG.*.root$"
177 elif filePattern[i].
upper()==
"NONE":
182 print (
"Comparing files matching:" )
187 for fP
in filePattern:
188 if fP.find(
"pool") == -1:
189 allPatterns.append(fP)
191 allPatterns.insert(0, fP)
199 if not os.access(refPath, os.R_OK):
200 print (
"Can't access output of reference TCT at",refPath)
203 if not os.access(valPath, os.R_OK):
204 print (
"Can't access output of validation TCT at",valPath)
207 msg =
"Reference TCT:\n"
208 msg += refPath +
"\n"
209 msg +=
"Validation TCT:\n"
210 msg += valPath +
"\n"
213 if detailsFN
is not None:
219 ff = findTCTFiles(refPath,valPath)
220 tctlist=ff.getCommonChains()
221 print (
"Output from findTCTFile.getCommonChains():")
227 for pattern
in allPatterns:
230 filesToCompare = ff.findFiles(pattern)
231 print (
"Will now look for files matching pattern:", pattern)
232 print (
"The found files to compare:", filesToCompare)
233 print (
"Comparing files matching [%s]" % pattern)
234 Summary +=
"Comparing files matching [%s]\n" % pattern
236 for name,rv
in six.iteritems (filesToCompare):
238 print (
"Chain %s: Found %i files matching [%s]" % (name,len(rv),pattern))
240 fileName=r.split(
'/')[-1]
241 print (
"Comparing files",fileName,
"of TCT",name)
243 if (fileName.endswith(
".pool.root")
and not fileName.startswith(
"myTAG")):
244 if(r.startswith(
"/eos")): r =
"root://eosatlas.cern.ch/"+r
245 if(v.startswith(
"/eos")): v =
"root://eosatlas.cern.ch/"+v
248 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")
249 os.system(
"cat tmp.txt|grep -v sync")
250 os.system(
"rm -f tmp.txt")
252 elif fileName.endswith(
".root"):
256 stat=os.system(
"diffTAGTree.py "+r+
" "+v+
" > tmp.txt")
257 os.system(
"cat tmp.txt|grep -v sync")
258 os.system(
"rm -f tmp.txt")
260 elif fileName.endswith(
".pickle"):
264 print (
"ERROR: Don't know how to compare",fileName)
268 if name
not in statPerChain:
269 statPerChain[name]=
False
271 statPerChain[name]|=
False
272 print (
"Files are identical")
274 statPerChain[name]=
True
276 print (
"Files are not identical")
278 Summary+=
"Found %i identical files and %i different files\n" % (nIdenticalFiles, nDifferentFiles)
279 print (
"Found %i identical files and %i different files\n" % (nIdenticalFiles, nDifferentFiles))
281 if details
is not None:
282 details.write(Summary)
290 for (name,info)
in six.iteritems (tctlist):
292 if len(info)<2:
continue
293 print (
"\n"+name+
":")
294 if (info[0].loglines>0
and info[1].loglines>0):
295 ratio=100.0*(info[1].loglines-info[0].loglines)/info[0].loglines
296 ln=
"\tLoglines: %i -> %i (%.2f)" % (info[0].loglines,info[1].loglines,ratio)
299 complain+=name+
" "+ln+
"***\n"
302 if len(info[0].cpulist)>4
and len(info[1].cpulist)>4:
304 cpu_r=info[0].cpulist[1]
305 cpu_v=info[1].cpulist[1]
306 if (cpu_r>0
and cpu_v>0):
307 ratio=100.0*(cpu_v-cpu_r)/cpu_r
308 ln=
"\tESD CPU: %i -> %i (%.2f%%)" % (cpu_r,cpu_v,ratio)
311 complain+=name+
" "+ln+
"***\n"
316 cpu_r=info[0].cpulist[4]
317 cpu_v=info[1].cpulist[4]
318 if (cpu_r>0
and cpu_v>0):
319 ratio=100.0*(cpu_v-cpu_r)/cpu_r
320 ln=
"\tAOD CPU: %i -> %i (%.2f%%)" % (cpu_r,cpu_v,ratio)
323 complain+=name+
" "+ln+
"***\n"
327 if len(info[0].memlist)>4
and len(info[1].memlist)>4:
328 mem_r=info[0].memlist[1]
329 mem_v=info[1].memlist[1]
330 if (mem_r>0
and mem_v>0):
331 ratio=100.0*(mem_v-mem_r)/mem_r
332 ln=
"\tESD MEM: %i -> %i (%.2f%%)" % (mem_r,mem_v,ratio)
335 complain+=name+
" "+ln+
"***\n"
339 mem_r=info[0].memlist[4]
340 mem_v=info[1].memlist[4]
341 if (mem_r>0
and mem_v>0):
342 ratio=100.0*(mem_v-mem_r)/mem_r
343 ln=
"\tAOD MEM: %i -> %i (%.2f%%)" % (mem_r,mem_v,ratio)
346 complain+=name+
" "+ln+
"***\n"
351 for f,s
in six.iteritems (statPerChain):
353 print (
"%-70s CHANGED" % f)
356 print (
"%-70s IDENTICAL" % f)
358 if sumFileName
is not None:
360 for f,s
in six.iteritems (statPerChain):
365 line +=
"IDENTICAL\n"
368 sumFile.write(
"\n\n")
369 sumFile.write(complain)