ATLAS Offline Software
pathExtract.py
Go to the documentation of this file.
1 #!/usr/bin env python
2 # Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 
4 # arguments : list of run
5 
6 import subprocess as sp
7 import os
8 # Return the path of the output of tier0 monitoring
9 
10 def getStreamPrefix(stream):
11  prefix = {'express': 'express_', 'Egamma': 'physics_', 'CosmicCalo': 'physics_', 'JetTauEtmiss': 'physics_', 'Main': 'physics_', 'ZeroBias': 'physics_', 'MinBias': 'physics_', 'UPC': 'physics_', 'HardProbes':'physics_'}
12  if any(pref in stream for pref in prefix.values()):
13  # Prefix already in stream name
14  fullstream = stream
15  else:
16  fullstream = prefix[stream]+stream
17  return fullstream
18 
19 def returnEosHistPath(run, stream, amiTag, tag="data16_13TeV"):
20  path = '/eos/atlas/atlastier0/rucio/'+tag + \
21  '/'+getStreamPrefix(stream)+'/00'+str(run)+'/'
22  listOfDirs = [ path+p for p in os.listdir(path) ]
23  for iDir in listOfDirs:
24  if ("HIST.%s" % (amiTag) in iDir):
25  files = [ iDir+"/"+f for f in os.listdir(iDir) ]
26  if len(files) == 0:
27  return "FILE NOT FOUND"
28  elif len(files) > 1:
29  print("WARNING: pathExtract returning",len(files),"hist files, where one is expected in path",iDir)
30  return files[0]
31 
32  return "FILE NOT FOUND"
33 
34 # Return the path of the output of tier0 monitoring for a range of single LB (available only a couple of days after processing)
35 
36 
37 def returnEosHistPathLB(run, lb0, lb1, stream, amiTag, tag="data16_13TeV"):
38  path = '/eos/atlas/atlastier0/tzero/prod/'+tag + \
39  '/'+getStreamPrefix(stream)+'/00'+str(run)+'/'
40  P = sp.Popen(['/usr/bin/eos', 'ls', path], stdout=sp.PIPE, stderr=sp.PIPE)
41  p = P.communicate()[0].decode("utf-8")
42  listOfFiles = p.split('\n')
43 
44  pathList = []
45  for iFile in listOfFiles:
46  if ("recon.HIST.%s" % (amiTag) in iFile and "LOG" not in iFile):
47  path = '/eos/atlas/atlastier0/tzero/prod/'+tag+'/' + \
48  getStreamPrefix(stream)+'/00'+str(run)+'/'+iFile
49  P = sp.Popen(['/usr/bin/eos', 'ls', path],
50  stdout=sp.PIPE, stderr=sp.PIPE)
51  p = P.communicate()[0].decode("utf-8")
52  listOfFiles2 = p.split('\n')
53  for iFile2 in listOfFiles2:
54  if ("data" in iFile2):
55  ilb = int((iFile2.split("_lb")[1]).split("._")[0])
56 # print(iFile2,ilb)
57  if (lb0 <= ilb and ilb <= lb1):
58  path = '/eos/atlas/atlastier0/tzero/prod/'+tag+'/' + \
59  getStreamPrefix(stream)+'/00' + \
60  str(run)+'/'+iFile+'/'+iFile2
61  pathList.append(path)
62 
63  if len(pathList) > 0:
64  return pathList
65  else:
66  return "FILE NOT FOUND"
67 
68 # Return the list of TAGs files on EOS
69 
70 
71 def returnEosTagPath(run, stream, amiTag="f", tag="data16_13TeV"):
72  found = False
73  listOfFiles = []
74  path = '/eos/atlas/atlastier0/rucio/'+tag + \
75  '/'+getStreamPrefix(stream)+'/00'+str(run)+'/'
76  P = sp.Popen(['/usr/bin/eos', 'ls', path], stdout=sp.PIPE, stderr=sp.PIPE)
77  p = P.communicate()
78  if p[1] == '':
79  files = p[0].decode("utf-8")
80  files = files.split('\n')
81  for f in files:
82  dotAmiTag = ".%s" % (amiTag)
83  if ('TAG' in f and dotAmiTag in f):
84  path += f+'/'
85  found = True
86  break
87  if not found:
88  print('no TAG directory found in %s' % (path))
89  return
90 
91  P = sp.Popen(['/usr/bin/eos', 'ls', path], stdout=sp.PIPE, stderr=sp.PIPE)
92  p = P.communicate()
93  if p[1] == '':
94  files = p[0].decode("utf-8").split('\n')
95  for iFile in files:
96  if (len(iFile) > 0):
97  pathFile = path+iFile
98  listOfFiles.append(pathFile)
99  return listOfFiles
100 
101 # Return the list of LArNoise ntuple files on EOS
102 
103 
104 def returnEosLArNoisePath(run, stream, amiTag="f", tag="data16_13TeV"):
105  found = False
106  listOfFiles = []
107  path = '/eos/atlas/atlascerngroupdisk/det-larg/Tier0/perm/' + \
108  tag+'/'+getStreamPrefix(stream)+'/00'+str(run)+'/'
109  P = sp.Popen(['/usr/bin/eos', 'ls', path], stdout=sp.PIPE, stderr=sp.PIPE)
110  p = P.communicate()
111  if p[1] == '':
112  files = p[0].decode("utf-8")
113  files = files.split('\n')
114  for f in files:
115  dotAmiTag = ".%s" % (amiTag)
116  if ('LARNOISE' in f and dotAmiTag in f):
117  path += f+'/'
118  found = True
119  break
120  if not found:
121  print('no LARNOISE directory found in %s' % (path))
122  return
123 
124  P = sp.Popen(['/usr/bin/eos', 'ls', path], stdout=sp.PIPE, stderr=sp.PIPE)
125  p = P.communicate()
126  if p[1] == '':
127  files = p[0].decode("utf-8").split('\n')
128  for iFile in files:
129  if (len(iFile) > 0):
130  pathFile = path+iFile
131  listOfFiles.append(pathFile)
132  return listOfFiles
133 
134 # Return the list of ESDs files on EOS
135 
136 
137 def returnEosEsdPath(run, stream, amiTag="f", tag="data16_13TeV"):
138  found = False
139  listOfFiles = []
140  path = '/eos/atlas/atlastier0/rucio/'+tag + \
141  '/'+getStreamPrefix(stream)+'/00'+str(run)+'/'
142  P = sp.Popen(['/usr/bin/eos', 'ls', path], stdout=sp.PIPE, stderr=sp.PIPE)
143  p = P.communicate()
144  if p[1] == '':
145  files = p[0].decode("utf-8")
146  files = files.split('\n')
147  for f in files:
148  dotAmiTag = ".%s" % (amiTag)
149  if ('.ESD' in f and dotAmiTag in f):
150  path += f+'/'
151  found = True
152  break
153  if not found:
154  print('no ESD directory found in %s' % (path))
155  return
156 
157  P = sp.Popen(['/usr/bin/eos', 'ls', path], stdout=sp.PIPE, stderr=sp.PIPE)
158  p = P.communicate()
159  if p[1] == '':
160  files = p[0].decode("utf-8").split('\n')
161  for iFile in files:
162  if (len(iFile) > 0):
163  pathFile = path+iFile
164  listOfFiles.append(pathFile)
165  return listOfFiles
166 
167 # Return the list of all files stored on a local user directory
168 
169 
170 def returnFilesPath(directory=".", filterName=""):
171  listOfFiles = []
172  path = directory
173  P = sp.Popen(['ls', path], stdout=sp.PIPE, stderr=sp.PIPE)
174  p = P.communicate()
175  found = False
176  if p[1] == '':
177  files = p[0].decode("utf-8")
178  files = files.split('\n')
179  for f in files:
180  if filterName in f:
181  pathFile = path + f
182  listOfFiles.append(pathFile)
183  found = True
184 
185  if not found:
186  print('no file containing %f found in %s' % (filterName, path))
187  return
188 
189  return listOfFiles
AtlasMcWeight::decode
double decode(number_type binnedWeight)
Convert weight from unsigned to double.
Definition: AtlasMcWeight.cxx:32
python.pathExtract.returnEosHistPath
def returnEosHistPath(run, stream, amiTag, tag="data16_13TeV")
Definition: pathExtract.py:19
python.pathExtract.returnEosTagPath
def returnEosTagPath(run, stream, amiTag="f", tag="data16_13TeV")
Definition: pathExtract.py:71
python.pathExtract.getStreamPrefix
def getStreamPrefix(stream)
Definition: pathExtract.py:10
python.pathExtract.returnEosHistPathLB
def returnEosHistPathLB(run, lb0, lb1, stream, amiTag, tag="data16_13TeV")
Definition: pathExtract.py:37
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
python.pathExtract.returnEosEsdPath
def returnEosEsdPath(run, stream, amiTag="f", tag="data16_13TeV")
Definition: pathExtract.py:137
str
Definition: BTagTrackIpAccessor.cxx:11
python.pathExtract.returnFilesPath
def returnFilesPath(directory=".", filterName="")
Definition: pathExtract.py:170
python.pathExtract.returnEosLArNoisePath
def returnEosLArNoisePath(run, stream, amiTag="f", tag="data16_13TeV")
Definition: pathExtract.py:104
Trk::split
@ split
Definition: LayerMaterialProperties.h:38