validateGRLvsSAM.py
Go to the documentation of this file.
1 print "run : --- Validate GRL vs SAM"
2 ########################### Imports
3 import samweb_client
4 sam = samweb_client.SAMWebClient(experiment="nova")
5 import ProductionTestTools as tools
6 ########################### options
7 study = ["fd","nd","nd_stagger"]
8 study = ["fd"]
9 ########################### functions
10 def validate(grl,sam_def,sam_runs,nd=False,dq=True,verbose=False):
11  sam_query = "defname: %s and defname: %s"%(sam_def,sam_runs)
12  if dq: sam_query += " and dq.isgoodrun true"
13  sam_files = sam.listFiles(dimensions=sam_query)
14  print "run : Query: %s returned %i files"%(sam_query,len(sam_files))
15 
16  in_sam = {}
17  for sam_file in sam_files:
18  run = tools.findRun(sam_file)
19  subrun = tools.findSubRun(sam_file)
20  if run not in in_sam.keys(): in_sam[run] = []
21  in_sam[run].append(subrun)
22 
23  in_grl = {}
24  n_files = 0
25  for line in open(grl,"r").readlines():
26  run = int(line.split()[0])
27  subrun = int(line.split()[1])
28  if run not in in_grl.keys(): in_grl[run] = []
29  in_grl[run].append(subrun)
30  n_files +=1
31  print "run : GRL: %s contains %i files"%(grl,n_files)
32 
33  print "run : --- Checking for GRL in SAM"
34  grl_errors = 0
35  zero_events = 0
36  grl_keys = in_grl.keys()
37  grl_keys.sort()
38  for grl_run in grl_keys:
39  for grl_sub_run in in_grl[grl_run]:
40  if (grl_run not in in_sam.keys()) or \
41  (grl_sub_run not in in_sam[grl_run]):
42  # these can be dropped due to metadata problems
43  if nd:
44  raw_name = "neardet_r%08d_s%02d_t00.raw"%(grl_run,grl_sub_run)
45  else:
46  raw_name = "fardet_r%08d_s%02d_t00.raw"%(grl_run,grl_sub_run)
47  if verbose: print "run : checking metadata, using name: %s"%raw_name
48  metadata = sam.getMetadata(raw_name)
49  if verbose: print "run : total events: %i"%metadata["Online.TotalEvents"]
50  if metadata["Online.TotalEvents"] == 0:
51  if verbose: print "run : - 0 online total events"
52  zero_events+=1
53  continue
54  grl_errors+= 1
55  print "run : Error [%i] Run %i, subrun %i in GRL but not in SAM"%(grl_errors, grl_run,grl_sub_run)
56  print "run : --- Found %i error files and %i files with zero events"%(grl_errors,zero_events)
57 
58  print "run : --- Checking for SAM in GRL"
59  sam_errors = 0
60  sam_keys = in_sam.keys()
61  sam_keys.sort()
62  for sam_run in sam_keys:
63  for sam_sub_run in in_sam[sam_run]:
64  if (sam_run not in in_grl.keys()) or \
65  (sam_sub_run not in in_grl[sam_run]):
66  sam_errors += 1
67  print "run : Error [%i] Run %i, subrun %i in SAM but not in GRL"%(sam_errors,sam_run,sam_sub_run)
68  print "run : --- Found %i error files"%sam_errors
69 ########################### Run
70 ################### FD
71 if "fd" in study:
72  print "run : --- FD"
73  fd_grl = "/nova/app/users/rbpatter/runlists/fd_numi_subrunlist_20150320_30secadded.vec"
74  fd_sam_def = "prod_artdaq_S15-03-11_fd_numi"
75  fd_sam_runs = "FD_data_epoch_A_runs"
76  validate(fd_grl, fd_sam_def, fd_sam_runs)
77 ################### ND
78 if "nd" in study:
79  print "run : --- ND"
80  nd_grl = "/nova/app/users/rbpatter/runlists/nd_numi_subrunlist_20150318_30secadded.vec"
81  nd_sam_def = "prod_artdaq_S15-03-11_nd_numi"
82  nd_sam_runs = "ND_data_epoch_A_runs"
83  validate(nd_grl, nd_sam_def, nd_sam_runs, nd=True)
84 ################### ND stagger
85 if "nd_stagger" in study:
86  print "run : --- ND stagger"
87  nd_grl = "/nova/app/users/rbpatter/runlists/nd_numi_subrunlist_20150318_30secadded.vec"
88  nd_sam_def = "prod_artdaq_S15-03-11_stagger_nd_numi"
89  nd_sam_runs = "ND_data_epoch_A_runs"
90  validate(nd_grl, nd_sam_def, nd_sam_runs, nd=True)
91 ########################### Done
92 print "run : --- Done\n"
def validate(grl, sam_def, sam_runs, nd=False, dq=True, verbose=False)
functions
procfile open("FD_BRL_v0.txt")