getreco.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import print_function
4 import sys
5 import samweb_cli
6 from subprocess import Popen, PIPE
7 import os
8 
9 # usage: getreco.py <run_number> <event_number>
10 
11 samweb = samweb_cli.SAMWebClient(experiment='dune')
12 
13 files = samweb.listFiles("run_number %s " % (sys.argv[1]) + "and run_type protodune-sp and data_tier raw")
14 
15 #print (files)
16 for file in files:
17  #print (file)
18  events = samweb.getURL('/files/metadata/event_numbers', {'file_name': file}).json()
19  if int(sys.argv[2]) in events :
20  print ("Raw: ", file, '--nskip',events.index(int(sys.argv[2])))
21  print ("Locations:")
22  cmd = ["samweb", "locate-file", file]
23  p = Popen(cmd, stdout=PIPE, stderr=PIPE)
24  stdout, stderr = p.communicate()
25  if not stderr:
26  print (stdout.decode('ascii'))
27  print ("Access URLs:")
28  cmd = ["samweb", "get-file-access-url", file, "--schema=xroot"]
29  p = Popen(cmd, stdout=PIPE, stderr=PIPE)
30  stdout, stderr = p.communicate()
31  if not stderr:
32  print (stdout.decode('ascii'))
33  filename = os.path.splitext(file)[0]
34  recofiles = samweb.listFiles("run_number %s " % (sys.argv[1]) + "and run_type protodune-sp and (data_tier full-reconstructed or data_tier reco-recalibrated)")
35  for recofile in recofiles:
36  if filename+'_' in recofile:
37  print ("Reco: ", recofile, '--nskip',events.index(int(sys.argv[2])))
38  print ("Locations:")
39  cmd = ["samweb", "locate-file", recofile]
40  p = Popen(cmd, stdout=PIPE, stderr=PIPE)
41  stdout, stderr = p.communicate()
42  if not stderr:
43  print (stdout.decode('ascii'))
44  print ("Access URLs:")
45  cmd = ["samweb", "get-file-access-url", recofile, "--schema=xroot"]
46  p = Popen(cmd, stdout=PIPE, stderr=PIPE)
47  stdout, stderr = p.communicate()
48  if not stderr:
49  print (stdout.decode('ascii'))
50 
51 
52 #from subprocess import Popen, PIPE
53 #import sys
54 #
55 #command = ["getfile.py", str(sys.argv[1]), str(sys.argv[2])]
56 #
57 #p = Popen(command, stdout=PIPE, stderr=PIPE)
58 #stdout, stderr = p.communicate()
59 #
60 #if not stderr:
61 # #should just be one line
62 # line = stdout.split("\n")[0]
63 # print ("Raw: ", line)
64 #
65 # nskip = line.split(" ")[1:]
66 # raw = line.split(" ")[0]
67 # sub = raw.split("_")[3] + "_" + raw.split("_")[4].strip(".root")
68 #
69 # print (nskip, raw, sub)
70 #
71 # #find the runset for the run
72 # cmd = ["samweb", "list-definitions"]
73 # p = Popen(cmd, stdout=PIPE, stderr=PIPE)
74 # stdout, stderr = p.communicate()
75 # if not stderr:
76 # for d in stdout.split("\n"):
77 # if "reco-unified" in d and str(sys.argv[1]) in d:
78 #
79 # cmd = ["samweb", "list-files", "defname:", d]
80 #
81 # p = Popen(cmd, stdout=PIPE, stderr=PIPE)
82 # stdout, stderr = p.communicate()
83 # if not stderr:
84 # for f in stdout.split("\n"):
85 # if raw.strip(".root") in f:
86 # print ("Reco:", f, nskip[0], nskip[1] )
87 # print(" ")
88 # print ("Locations:")
89 #
90 # cmd = ["samweb", "locate-file", f]
91 # p = Popen(cmd, stdout=PIPE, stderr=PIPE)
92 # stdout, stderr = p.communicate()
93 # if not stderr:
94 # print (stdout)
95 #
96 # print(" ")
97 # print ("Access URLs:")
98 # cmd = ["samweb", "get-file-access-url", f, "--schema=xroot"]
99 # p = Popen(cmd, stdout=PIPE, stderr=PIPE)
100 # stdout, stderr = p.communicate()
101 # if not stderr:
102 # print (stdout)
103 # else: print stderr
104