CMS 3D CMS Logo

Functions | Variables
ValidationMatrix Namespace Reference

Functions

def add_to_blacklist (blacklist, pattern, target, blist_piece)
 
def call_compare_using_files (args)
 
def check_root_files (names_list)
 
def count_alive_processes (p_list)
 
def do_comparisons_threaded (options)
 
def do_html (options, hashing_flag, standalone)
 
def do_reports (indir)
 
def get_clean_fileanames (ref_samples, test_samples)
 
def get_filenames_from_pool (all_samples)
 
def get_roofiles_in_dir (directory)
 
def guess_blacklists (samples, ver1, ver2, hlt)
 
def guess_params (ref_filenames, test_filenames)
 
def name2globaltag (filename)
 
def name2run (filename)
 
def name2runskim (filename)
 
def name2sample (filename)
 
def name2version (filename)
 

Variables

 action
 —HASHING—## More...
 
 all_samples
 
 args
 
 argv
 
 default
 
 dest
 
 help
 
 hlt
 
 in_dir
 
 n_processes
 
 n_threads
 
 options
 
 out_dir
 
 parser
 
 ref_samples
 
 run
 
 stat_test
 
 test_samples
 
 test_threshold
 
 usage
 

Function Documentation

◆ add_to_blacklist()

def ValidationMatrix.add_to_blacklist (   blacklist,
  pattern,
  target,
  blist_piece 
)

Definition at line 127 of file ValidationMatrix.py.

References cond::persistency.search().

Referenced by guess_blacklists().

127 def add_to_blacklist(blacklist, pattern, target, blist_piece):
128  int_pattern=pattern
129  int_pattern=pattern.strip()
130  flip_condition=False
131  if int_pattern[0]=='!':
132  int_pattern=int_pattern[1:]
133  flip_condition=True
134 
135  condition = search(int_pattern,target)!=None
136  if flip_condition:
137  condition = not condition
138 
139  if condition:
140  #print "Found %s in %s" %(pattern,target)
141  if blacklist!="": # if not the first, add a comma
142  blacklist+=","
143  blacklist+=blist_piece
144  #else:
145  #print " NOT Found %s in %s" %(pattern,target)
146  return blacklist
147 
148 #-------------------------------------------------------------------------------
149 
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:21
def add_to_blacklist(blacklist, pattern, target, blist_piece)

◆ call_compare_using_files()

def ValidationMatrix.call_compare_using_files (   args)
Creates shell command to compare two files using compare_using_files.py
script and calls it.

Definition at line 274 of file ValidationMatrix.py.

References guess_blacklists(), name2globaltag(), name2version(), and print().

274 def call_compare_using_files(args):
275  """Creates shell command to compare two files using compare_using_files.py
276  script and calls it."""
277  sample, ref_filename, test_filename, options = args
278  gt = name2globaltag(ref_filename)
279  blacklists=guess_blacklists([sample],name2version(ref_filename),name2version(test_filename),options.hlt)
280  command = " compare_using_files.py "
281  command+= "%s %s " %(ref_filename,test_filename)
282  command+= " -C -R "
283  if options.do_pngs:
284  command+= " -p "
285  command+= " -o %s_%s " %(sample, gt)
286  # Change threshold to an experimental and empirical value of 10^-5
287  command+= " --specify_run "
288  if options.stat_test in ["Bin2Bin", "BinToBin"]:
289  options.test_threshold = 0.9999
290  command+= " -t %s " %options.test_threshold
291  command+= " -s %s " %options.stat_test
292 
293  # Inspect the HLT directories
294  if options.hlt:
295  command+=" -d HLT "
296 
297  if options.hash_name:
298  command += " --hash_name "
299 
300  if options.blacklist_file:
301  command += " --use_black_file "
302 
303  if options.standalone:
304  command += " --standalone "
305  if len(blacklists[sample]) >0:
306  command+= '-B %s ' %blacklists[sample]
307  print("\nExecuting -- %s" %command)
308 
309  process=call([x for x in command.split(" ") if len(x)>0])
310  return process
311 
312 
313 #--------------------------------------------------------------------------------
314 
def name2globaltag(filename)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def call_compare_using_files(args)
def name2version(filename)
def guess_blacklists(samples, ver1, ver2, hlt)

◆ check_root_files()

def ValidationMatrix.check_root_files (   names_list)

Definition at line 118 of file ValidationMatrix.py.

References print().

Referenced by get_clean_fileanames().

118 def check_root_files(names_list):
119  for name in names_list:
120  if not name.endswith(".root"):
121  print("File %s does not seem to be a rootfile. Please check.")
122  return False
123  return True
124 
125 #-------------------------------------------------------------------------------
126 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def check_root_files(names_list)

◆ count_alive_processes()

def ValidationMatrix.count_alive_processes (   p_list)

Definition at line 269 of file ValidationMatrix.py.

269 def count_alive_processes(p_list):
270  return len([p for p in p_list if p.returncode==None])
271 
272 #-------------------------------------------------------------------------------
273 
def count_alive_processes(p_list)

◆ do_comparisons_threaded()

def ValidationMatrix.do_comparisons_threaded (   options)

Definition at line 315 of file ValidationMatrix.py.

References get_clean_fileanames(), get_filenames_from_pool(), guess_params(), createfilelist.int, genParticles_cff.map, print(), cond::persistency.search(), and reco.zip().

315 def do_comparisons_threaded(options):
316 
317  n_processes= int(options.n_processes)
318 
319  ref_filenames=[]
320  test_filenames=[]
321 
322  if len(options.all_samples)>0:
323  ref_filenames,test_filenames=get_filenames_from_pool(options.all_samples)
324  else:
325  ref_filenames,test_filenames=get_clean_fileanames(options.ref_samples,options.test_samples)
326 
327  # make the paths absolute
328  ref_filenames=list(map(os.path.abspath,ref_filenames))
329  test_filenames=list(map(os.path.abspath,test_filenames))
330 
331  samples,cmssw_version1,cmssw_version2=guess_params(ref_filenames,test_filenames)
332 
333  if len(samples)==0:
334  print("No Samples found... Quitting")
335  return 0
336 
337 # blacklists=guess_blacklists(samples,cmssw_version1,cmssw_version2,options.hlt)
338 
339  # Launch the single comparisons
340  original_dir=os.getcwd()
341 
342  outdir=options.out_dir
343  if len(outdir)==0:
344  print("Creating automatic outdir:", end=' ')
345  outdir="%sVS%s" %(cmssw_version1,cmssw_version2)
346  print(outdir)
347  if len(options.input_dir)==0:
348  print("Creating automatic indir:", end=' ')
349  options.input_dir=outdir
350  print(options.input_dir)
351 
352  if not os.path.exists(outdir):
353  os.mkdir(outdir)
354  os.chdir(outdir)
355 
356  # adjust the number of threads
357  n_comparisons=len(ref_filenames)
358  if n_comparisons < n_processes:
359  print("Less comparisons than possible processes: reducing n processes to", end=' ')
360  n_processes=n_comparisons
361  #elif n_processes/n_comparisons == 0:
362  #print "More comparisons than possible processes, can be done in N rounds: reducing n processes to",
363  #original_nprocesses=n_processes
364  #first=True
365  #n_bunches=0
366  #while first or n_processes > original_nprocesses:
367  #n_processes=n_comparisons/2
368  #if n_comparisons%2 !=0:
369  #n_processes+=1
370  #first=False
371 
372  #print n_processes
373  #print n_processes
374 
375  # Test if we treat data
376  skim_name=""
377  if search("20[01]",cmssw_version1)!=None:
378  skim_name=cmssw_version1.split("_")[-1]
379 
380  running_subprocesses=[]
381  process_counter=0
382  #print ref_filenames
383 
384 
385  pool = Pool(n_processes)
386  args_iterable = [list(args) + [options] for args in zip(samples, ref_filenames, test_filenames)]
387  pool.map(call_compare_using_files, args_iterable)
388  # move the pickles on the top, hack
389  os.system("mv */*pkl .")
390 
391  os.chdir("..")
392 #-------------------------------------------------------------------------------
def guess_params(ref_filenames, test_filenames)
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:21
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float zip(ConstView const &tracks, int32_t i)
Definition: TracksSoA.h:90
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def get_filenames_from_pool(all_samples)
def get_clean_fileanames(ref_samples, test_samples)
def do_comparisons_threaded(options)

◆ do_html()

def ValidationMatrix.do_html (   options,
  hashing_flag,
  standalone 
)

Definition at line 421 of file ValidationMatrix.py.

References do_reports(), directories2html.make_summary_table(), and print().

421 def do_html(options, hashing_flag, standalone):
422 
423  if options.reports:
424  print("Preparing reports for the single files...")
425  do_reports(options.input_dir)
426  # Do the summary page
427  aggregation_rules={}
428  aggregation_rules_twiki={}
429  # check which aggregation rules are to be used
430  if options.hlt:
431  print("Aggregating directories according to HLT rules")
432  aggregation_rules=definitions.aggr_pairs_dict['HLT']
433  aggregation_rules_twiki=definitions.aggr_pairs_twiki_dict['HLT']
434  else:
435  aggregation_rules=definitions.aggr_pairs_dict['reco']
436  aggregation_rules_twiki=definitions.aggr_pairs_twiki_dict['reco']
437  table_html = make_summary_table(options.input_dir,aggregation_rules,aggregation_rules_twiki, hashing_flag, standalone)
438 
439  # create summary html file
440  ofile = open("RelMonSummary.html","w")
441  ofile.write(table_html)
442  ofile.close()
443 
444 #-------------------------------------------------------------------------------
445 
def do_html(options, hashing_flag, standalone)
def make_summary_table(indir, aggregation_rules, aggregation_rules_twiki, hashing_flag, standalone_flag)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ do_reports()

def ValidationMatrix.do_reports (   indir)

Definition at line 393 of file ValidationMatrix.py.

References createfilelist.int, and print().

Referenced by do_html().

393 def do_reports(indir):
394  #print indir
395  os.chdir(indir)
396  pkl_list=[x for x in os.listdir("./") if ".pkl" in x]
397  running_subprocesses=[]
398  n_processes=int(options.n_processes)
399  process_counter=0
400  for pklfilename in pkl_list:
401  command = "compare_using_files.py "
402  command+= "-R "
403  if options.do_pngs:
404  command+= " -p "
405  command+= "-P %s " %pklfilename
406  command+= "-o %s " %pklfilename[:-4]
407  print("Executing %s" %command)
408  process=call([x for x in command.split(" ") if len(x)>0])
409  process_counter+=1
410  # add it to the list
411  running_subprocesses.append(process)
412  if process_counter>=n_processes:
413  process_counter=0
414  for p in running_subprocesses:
415  #print "Waiting for %s" %p.name
416  p.wait()
417 
418  os.chdir("..")
419 
420 #-------------------------------------------------------------------------------
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ get_clean_fileanames()

def ValidationMatrix.get_clean_fileanames (   ref_samples,
  test_samples 
)

Definition at line 254 of file ValidationMatrix.py.

References check_root_files(), beamvalidation.exit(), genParticles_cff.map, and print().

Referenced by do_comparisons_threaded().

254 def get_clean_fileanames(ref_samples,test_samples):
255  # Process the samples starting from the names
256  ref_filenames=list(map(lambda s:s.strip(),ref_samples.split(",")))
257  test_filenames=list(map(lambda s:s.strip(),test_samples.split(",")))
258 
259  if len(ref_filenames)!=len(test_filenames):
260  print("The numebr of reference and test files does not seem to be the same. Please check.")
261  exit(2)
262 
263  if not (check_root_files(ref_filenames) and check_root_files(test_filenames)):
264  exit(2)
265  return ref_filenames,test_filenames
266 
267 #-------------------------------------------------------------------------------
268 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def check_root_files(names_list)
def get_clean_fileanames(ref_samples, test_samples)
def exit(msg="")

◆ get_filenames_from_pool()

def ValidationMatrix.get_filenames_from_pool (   all_samples)

Definition at line 200 of file ValidationMatrix.py.

References get_roofiles_in_dir(), utils.make_files_pairs(), print(), FastTimerService_cff.range, and reco.zip().

Referenced by do_comparisons_threaded().

200 def get_filenames_from_pool(all_samples):
201 
202  # get a list of the files
203  files_list=get_roofiles_in_dir(all_samples)
204 
205  if len(files_list)==0:
206  print("Zero files found in directory %s!" %all_samples)
207  return [],[]
208 
209  # Are they an even number?
210  for name in files_list:
211  print("* ",name)
212  if len(files_list)%2!=0:
213  print("The numbuer of file is not even... Trying to recover a catastrophe.")
214 
215  files_list=make_files_pairs(files_list)
216 
217  # Try to couple them according to their sample
218  ref_filenames=[]
219  test_filenames=[]
220  #files_list.sort(key=name2version)
221  #files_list.sort(key=name2sample)
222  #files_list.sort(key=name2run)
223  for iname in range(len(files_list)):
224  filename=files_list[iname]
225  if iname%2==0:
226  ref_filenames.append(filename)
227  else:
228  test_filenames.append(filename)
229 
230  print("The guess would be the following:")
231  for ref,test in zip(ref_filenames,test_filenames):
232  refbasedir=os.path.dirname(ref)
233  testbasedir=os.path.dirname(test)
234  dir_to_print=refbasedir
235  if refbasedir!=testbasedir:
236  dir_to_print="%s and %s" %(refbasedir,testbasedir)
237  print("* Directory: %s " %dir_to_print)
238  refname=os.path.basename(ref)
239  testname=os.path.basename(test)
240  print(" o %s" %refname)
241  print(" o %s" %testname)
242 
243  #is_ok=ask_ok("Is that ok?")
244  #if not is_ok:
245  #print "Manual input needed then!"
246  #exit(2)
247 
248 
249  return ref_filenames,test_filenames
250 
251 
252 #-------------------------------------------------------------------------------
253 
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float zip(ConstView const &tracks, int32_t i)
Definition: TracksSoA.h:90
def get_roofiles_in_dir(directory)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def get_filenames_from_pool(all_samples)
def make_files_pairs(files, verbose=True)
Definition: utils.py:573

◆ get_roofiles_in_dir()

def ValidationMatrix.get_roofiles_in_dir (   directory)

Definition at line 191 of file ValidationMatrix.py.

References genParticles_cff.map, and print().

Referenced by get_filenames_from_pool().

191 def get_roofiles_in_dir(directory):
192  print(directory)
193  files_list = [s for s in os.listdir(directory) if s.endswith(".root")]
194  files_list_path=map(lambda s: os.path.join(directory,s), files_list)
195 
196  return files_list_path
197 
198 #-------------------------------------------------------------------------------
199 
def get_roofiles_in_dir(directory)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ guess_blacklists()

def ValidationMatrix.guess_blacklists (   samples,
  ver1,
  ver2,
  hlt 
)
Build a blacklist for each sample accordind to a set of rules

Definition at line 150 of file ValidationMatrix.py.

References add_to_blacklist(), print(), and cond::persistency.search().

Referenced by call_compare_using_files().

150 def guess_blacklists(samples,ver1,ver2,hlt):
151  """Build a blacklist for each sample accordind to a set of rules
152  """
153  blacklists={}
154  for sample in samples:
155  blacklists[sample]="FED@1,AlcaBeamMonitor@1,HLT@1,AlCaReco@1"
156 
157  # HLT
158  if hlt: #HLT
159  blacklists[sample]+=",AlCaEcalPi0@2"
160  if not search("2010+|2011+|2012+|2015+",ver1):
161  print("We are treating MC files for the HLT")
162  for pattern,blist in definitions.hlt_mc_pattern_blist_pairs:
163  blacklists[sample]=add_to_blacklist(blacklists[sample],pattern,sample,blist)
164  else:
165  print("We are treating Data files for the HLT")
166  # at the moment it does not make sense since hlt is ran already
167 
168  else: #RECO
169  #Monte Carlo
170  if not search("2010+|2011+|2012+",ver1):
171  print("We are treating MC files")
172 
173  for pattern,blist in definitions.mc_pattern_blist_pairs:
174  blacklists[sample]=add_to_blacklist(blacklists[sample],pattern,sample,blist)
175 # print "MC RECO"
176  #print blacklists[sample]
177 
178  # Data
179  else:
180  print("We are treating Data files:")
181  blacklists[sample]+=",By__Lumi__Section@-1,AlCaReco@1"
182  for pattern,blist in definitions.data_pattern_blist_pairs:
183  blacklists[sample]=add_to_blacklist(blacklists[sample],pattern,ver1,blist)
184 # print "DATA RECO: %s %s %s -->%s" %( ver1, pattern, blist, blacklists[sample])
185 
186 
187  return blacklists
188 
189 #-------------------------------------------------------------------------------
190 
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:21
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def guess_blacklists(samples, ver1, ver2, hlt)
def add_to_blacklist(blacklist, pattern, target, blist_piece)

◆ guess_params()

def ValidationMatrix.guess_params (   ref_filenames,
  test_filenames 
)

Definition at line 69 of file ValidationMatrix.py.

References genParticles_cff.map, name2sample(), name2version(), print(), cond::persistency.search(), and reco.zip().

Referenced by do_comparisons_threaded().

69 def guess_params(ref_filenames,test_filenames):
70 
71  if len(ref_filenames)*len(test_filenames)==0:
72  print("Empty reference and test filenames lists!")
73  return [],"",""
74 
75  samples=[]
76  ref_versions=[]
77  test_versions=[]
78 
79  for ref, test in zip(map(os.path.basename,ref_filenames),map(os.path.basename,test_filenames)):
80 
81  ref_sample=name2sample(ref)
82  ref_version=name2version(ref)
83  test_sample=name2sample(test)
84  test_version=name2version(test)
85 
86  print(" ## sample 1: %s vs sample 2: %s"%(ref_sample, test_sample))
87 
88  if ref_sample!=test_sample:
89  print("Files %s and %s do not seem to be relative to the same sample." %(ref, test))
90  # exit(2)
91 
92  # Slightly modify for data
93  if search("20[01]",ref_version)!=None:
94  ref_sample+=ref_version.split("_")[-1]
95  samples.append(ref_sample)
96 
97  # append the versions
98  ref_versions.append(ref_version)
99  test_versions.append(test_version)
100 
101  # Check if ref and test versions are always the same.
102  ref_versions=list(set(ref_versions))
103  test_versions=list(set(test_versions))
104 
105  #for versions in ref_versions,test_versions:
106  #if len(versions)!=1:
107  #print "More than one kind of CMSSW version selected (%s)" %versions
108  #exit(2)
109 
110  cmssw_version1=ref_versions[0]
111  cmssw_version2=test_versions[0]
112 
113  return samples,cmssw_version1,cmssw_version2
114 
115 
116 #-------------------------------------------------------------------------------
117 
def guess_params(ref_filenames, test_filenames)
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:21
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float zip(ConstView const &tracks, int32_t i)
Definition: TracksSoA.h:90
def name2sample(filename)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def name2version(filename)

◆ name2globaltag()

def ValidationMatrix.name2globaltag (   filename)

Definition at line 63 of file ValidationMatrix.py.

References submitPVValidationJobs.split().

Referenced by call_compare_using_files().

63 def name2globaltag(filename):
64  namebase = os.path.basename(filename)
65  return namebase.split("__")[2].split("-")[1] #returns GT from file basename
66 
67 #-------------------------------------------------------------------------------
68 
def name2globaltag(filename)

◆ name2run()

def ValidationMatrix.name2run (   filename)

Definition at line 51 of file ValidationMatrix.py.

References submitPVValidationJobs.split().

Referenced by name2runskim().

51 def name2run(filename):
52  namebase=os.path.basename(filename)
53  return namebase.split("__")[0].split("_")[2]
54 
def name2run(filename)

◆ name2runskim()

def ValidationMatrix.name2runskim (   filename)

Definition at line 55 of file ValidationMatrix.py.

References name2run(), name2version(), and submitPVValidationJobs.split().

55 def name2runskim(filename):
56  run=name2run(filename)
57  skim=name2version(filename).split("_")[-1]
58  # remove skim version
59  if "-v" in skim:
60  skim = skim[:skim.rfind('-v')]
61  return "%s_%s"%(run,skim)
62 
def name2run(filename)
def name2version(filename)
def name2runskim(filename)

◆ name2sample()

def ValidationMatrix.name2sample (   filename)

Definition at line 43 of file ValidationMatrix.py.

Referenced by guess_params().

43 def name2sample(filename):
44  namebase=os.path.basename(filename)
45  return namebase.split("__")[1]
46 
def name2sample(filename)

◆ name2version()

def ValidationMatrix.name2version (   filename)

Definition at line 47 of file ValidationMatrix.py.

Referenced by call_compare_using_files(), guess_params(), and name2runskim().

47 def name2version(filename):
48  namebase=os.path.basename(filename)
49  return namebase.split("__")[2]
50 
def name2version(filename)

Variable Documentation

◆ action

ValidationMatrix.action

—HASHING—##

– USE CSS files in web access, for stand-alone usage –##

–Blacklist File –##

Definition at line 466 of file ValidationMatrix.py.

◆ all_samples

ValidationMatrix.all_samples

Definition at line 451 of file ValidationMatrix.py.

◆ args

ValidationMatrix.args

Definition at line 555 of file ValidationMatrix.py.

◆ argv

ValidationMatrix.argv

Definition at line 25 of file ValidationMatrix.py.

◆ default

ValidationMatrix.default

Definition at line 468 of file ValidationMatrix.py.

◆ dest

ValidationMatrix.dest

Definition at line 467 of file ValidationMatrix.py.

◆ help

ValidationMatrix.help

Definition at line 469 of file ValidationMatrix.py.

◆ hlt

ValidationMatrix.hlt

◆ in_dir

ValidationMatrix.in_dir

Definition at line 454 of file ValidationMatrix.py.

◆ n_processes

ValidationMatrix.n_processes

Definition at line 452 of file ValidationMatrix.py.

◆ n_threads

ValidationMatrix.n_threads

Definition at line 455 of file ValidationMatrix.py.

◆ options

ValidationMatrix.options

Definition at line 555 of file ValidationMatrix.py.

◆ out_dir

ValidationMatrix.out_dir

Definition at line 453 of file ValidationMatrix.py.

◆ parser

ValidationMatrix.parser

Definition at line 463 of file ValidationMatrix.py.

◆ ref_samples

ValidationMatrix.ref_samples

Definition at line 449 of file ValidationMatrix.py.

◆ run

ValidationMatrix.run

Definition at line 456 of file ValidationMatrix.py.

◆ stat_test

ValidationMatrix.stat_test

Definition at line 457 of file ValidationMatrix.py.

◆ test_samples

ValidationMatrix.test_samples

Definition at line 450 of file ValidationMatrix.py.

◆ test_threshold

ValidationMatrix.test_threshold

Definition at line 458 of file ValidationMatrix.py.

◆ usage

ValidationMatrix.usage

Definition at line 463 of file ValidationMatrix.py.