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