Go to the documentation of this file.00001
00002 '''
00003 Script prints out histogram names that are in one ROOT file but not in another.
00004
00005 Author: Albertas Gimbutas, Vilnius University (LT)
00006 e-mail: albertasgim@gmail.com
00007 '''
00008 from datetime import datetime, timedelta
00009 from optparse import OptionParser
00010
00011 def collect_directory_filenames(directory, names_list):
00012 """Adds current directory file (histogram) names to ``names_list``. Then
00013 recursively calls itself for every current directory sub-directories."""
00014 for key in directory.GetListOfKeys():
00015 subdir = directory.Get(key.GetName())
00016 if subdir:
00017 if subdir.IsFolder():
00018 collect_directory_filenames(subdir, names_list)
00019 else:
00020 filename = directory.GetPath().split(':')[1] + ': ' + subdir.GetName()
00021 names_list.add(filename)
00022
00023 def get_content(root_file_name):
00024 """Returns all file (histogram) names, which are found in <root_file_name>."""
00025 from ROOT import TFile
00026 root_file = TFile(root_file_name)
00027 root_directory = root_file.GetDirectory("DQMData")
00028 filename_set = set()
00029 collect_directory_filenames(root_directory, filename_set)
00030 root_file.Close()
00031 return filename_set
00032
00033 def dqm_diff(filename1, filename2):
00034 """Prints file (histogram) names that are in <file1> and not in <file2>."""
00035 print "Missing files:"
00036 content1 = get_content(filename1)
00037 content2 = get_content(filename2)
00038 printed = False
00039 for name in content1:
00040 if name not in content2:
00041 print " ->", name
00042 printed = True
00043 if not printed:
00044 print " All files match."
00045
00046
00047
00048 parser = OptionParser(usage='usage: %prog <root_file1> <root_file2> [options]')
00049 parser.add_option('-t', '--time', action='store_true', default=False,
00050 dest='show_exec_time', help='Show execution time.')
00051 (options, args) = parser.parse_args()
00052
00053
00054 if len(args) != 2:
00055 parser.error("You have to specify two root files. e.g. ``dqm_diff.py file1.root file2.root``.")
00056
00057
00058 start = datetime.now()
00059 dqm_diff(*args)
00060 if options.show_exec_time:
00061 print 'Execution time:', str(timedelta(seconds=(datetime.now() - start).seconds))