filelisting.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 os
6 import samweb_cli
7 from ROOT import TFile, gDirectory
8 
9 samweb = samweb_cli.SAMWebClient(experiment='dune')
10 
11 files = samweb.listFiles("defname: %s " % (sys.argv[1]))
12 
13 run = -1
14 totalevts = -1
15 #print files
16 for file in files:
17  #print (file)
18  loc = samweb.locateFile(file)
19  if run == -1:
20  metadata = samweb.getMetadata(file)
21  #print (metadata)
22  if metadata['file_type'] != 'mc':
23  totalevts = 0
24  run = metadata['runs'][0][0]
25  #print (run)
26  else:
27  totalevts = 0
28  run = 0
29  f = open("input_run%s.txt" % run, "w")
30  pnfs = loc[0]['full_path'][8:]
31  stream = os.popen("pnfsToXRootD %s/%s" % (pnfs,file))
32  xroot = stream.read()
33  #print(xroot)
34  tfile = TFile.Open(xroot.strip())
35  mytree = gDirectory.Get('michelremoving2/Event')
36  totalevts += mytree.GetEntries()
37  #print(mytree.GetEntries())
38  #print (xroot)
39  f.write(xroot)
40  #print("File name: %s, total events: %s" % (file, totalevts))
41 #f.close()
42 
43 print(totalevts)
int open(const char *, int)
Opens a file descriptor.