CMS 3D CMS Logo

VIDSelectorValidator.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import md5
3 import ROOT
4 
5 # load FWLite C++ libraries
6 ROOT.gSystem.Load("libFWCoreFWLite.so")
7 ROOT.gSystem.Load("libDataFormatsFWLite.so")
8 ROOT.FWLiteEnabler.enable()
9 
10 #cms python data types
11 import FWCore.ParameterSet.Config as cms
12 
13 # load FWlite python libraries
14 from DataFormats.FWLite import Handle, Events
15 
16 #hasher= md5.new()
17 #
18 #hasher.update('hello world')
19 #
20 #print hasher.digest()
21 #print hasher.hexdigest()
22 
24  def __init__(self, selector, collection_type, collection_name):
25  self.__hasher = md5.new()
26  self.__selector = selector
27  self.__colltype = collection_type
28  self.__collname = collection_name
29  self.__signalfiles = []
31  self.__mixfiles = []
32 
33  def setSignalFiles(self, files):
34  if not isinstance(files,list):
35  raise Exception('BadFileInput','You need to give "setSignalFiles" a list of strings')
36  self.__signalfiles = files[:]
37 
38  def setBackgroundFiles(self, files):
39  if not isinstance(files,list):
40  raise Exception('BadFileInput','You need to give "setBackgroundFiles" a list of strings')
41  self.__backgroundfiles = files[:]
42 
43  def setMixFiles(self, files):
44  if not isinstance(files,list):
45  raise Exception('BadFileInput','You need to give "setMixFiles" a list of strings')
46  self.__mixfiles = files[:]
47 
48  def runValidation(self):
49  samples = {}
50  samples['signal'] = self.__signalfiles
51  samples['background'] = self.__backgroundfiles
52  samples['mix'] = self.__mixfiles
53 
54  select = self.__selector
55 
56  print('running validation for: %s'%(select.name()))
57 
58  # checksum of the input files
59  if not len(samples['signal'] + samples['background'] + samples['mix']):
60  raise Exception('NoInputFiles','There were no input files given, cannot validate!')
61 
62  for key in sorted(samples.keys()):
63  self.processInputList(samples[key],key)
64 
65  print('input files checksum: %s'%(self.__hasher.hexdigest()))
66 
67  for key in sorted(samples.keys()):
68  if len(samples[key]):
69  local_hash = md5.new()
70  self.processEvents(samples[key],key,local_hash)
71  self.__hasher.update(local_hash.hexdigest())
72 
73  print('event processing checksum: %s'%(self.__hasher.hexdigest()))
74 
75  self.__hasher.update(select.md5String())
76 
77  print('total checksum: %s'%(self.__hasher.hexdigest()))
78 
79  def processInputList(self,the_list,name):
80  for item in the_list:
81  self.__hasher.update(item)
82  print('Input %s file: %s'%(name,item))
83 
84  def processEvents(self,the_list,name,hasher):
85  #data products
86  handle, productLabel = Handle(self.__colltype), self.__collname
87 
88  #now loop over the events in each category
89  events = Events(the_list)
90  n_pass, n_fail = 0,0
91 
92  sub_cutnames = []
93  sub_hashes = []
94  for idstring in repr(self.__selector).split('\n'):
95  if idstring == '': continue
96  sub_cutnames.append(idstring.split()[2]) # gets the cutname
97  sub_hashes.append(md5.new(idstring))
98 
99  for event in events:
100  event.getByLabel(productLabel,handle)
101  for i,obj in enumerate(handle.product()):
102  if self.__selector(handle.product(),i,event):
103  n_pass += 1
104  else:
105  n_fail += 1
106  icut = 0
107  for idstring in repr(self.__selector).split('\n'):
108  if idstring == '': continue
109  sub_hashes[icut].update(idstring)
110  icut += 1
111 
112  for sub_hash in sub_hashes:
113  hasher.update(sub_hash.hexdigest())
114 
115  hasher.update(str(n_pass))
116  hasher.update(str(n_fail))
117  print('%s sample pass : fail : hash -> %d : %d : %s'%(name,n_pass,n_fail,hasher.hexdigest()))
118  print('%s sample cut breakdown:'%(name))
119  for i,sub_hash in enumerate(sub_hashes):
120  print('\t%s hash -> %s'%(sub_cutnames[i],sub_hash.hexdigest()))
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
#define update(a, b)
def __init__(self, selector, collection_type, collection_name)
def processEvents(self, the_list, name, hasher)
#define str(s)
double split
Definition: MVATrainer.cc:139