ATLAS Offline Software
pool_extractFileIdentifier.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 
5 # @file: pool_extractFileIdentifier.py
6 # @purpose: extract the GUID of a POOL file.
7 # Also speeds up greatly processing time by shrinking LD_LIBRARY_PATH
8 # @author: Sebastien Binet <binet@cern.ch>
9 # @date: March 2009
10 #
11 # @example:
12 #
13 # python pool_extractFileIdentifier.py aod.pool.root
14 #
15 # if pool_extractFileIdentifier.py has been made 'chmod +x' one can just do:
16 # ./pool_extractFileIdentifier.py aod.pool.root
17 
18 from __future__ import with_statement, print_function
19 
20 from future import standard_library
21 standard_library.install_aliases()
22 
23 def pool_extract(files):
24  print (":: extracting GUID for [%i] files... "% len(files))
25  import os
26  import subprocess
27  sc,exe = subprocess.getstatusoutput('which pool_extractFileIdentifier')
28  if sc != 0:
29  print (":: could not find 'pool_extractFileIdentifier' !")
30  print (exe)
31  return 1
32 
33  cmd = "%s %s" % (exe, " ".join(files))
34  sc, out = subprocess.getstatusoutput(cmd)
35 
36  out = os.linesep.join(
37  [o for o in out.splitlines()
38  if not (o.startswith("Warning in <TClass::TClass>: no dictionary for class ") or
39  o.startswith('Warning in <TEnvRec::ChangeValue>: duplicate entry'))]
40  )
41 
42  if sc != 0:
43  print (":: problem running pool_extractFileIdentifier:")
44  print (out)
45  return sc
46 
47  print (out)
48  print (":: extracting GUID for [%i] files... [done]" % len(files))
49  return sc
50 
51 if __name__ == "__main__":
52  import sys
53  from optparse import OptionParser
54  parser = OptionParser(usage="%prog file1.pool [file2.pool [...]]")
55  parser.add_option("-f", "--files",
56  dest = "files",
57  help = "(list of) files to extract the GUID(s) from")
58  options, args = parser.parse_args()
59 
60  files = list()
61  if len(args) > 0:
62  files = [ arg for arg in args if arg[0] != "-" ]
63  pass
64 
65  if options.files is None and len(files) == 0:
66  str(parser.print_help() or "")
67  print (":: You have to provide at least one POOL file to extract a GUID from:")
68  print (" shell> pool_extractFileIdentifier.py aod.pool")
69  sys.exit(1)
70 
71  if not (options.files is None):
72  import os
73  for f in options.files.split():
74  f = os.path.expandvars(os.path.expanduser(f))
75  files.append(f)
76 
77  sys.exit(pool_extract(files=files))
pool_extractFileIdentifier.pool_extract
def pool_extract(files)
Definition: pool_extractFileIdentifier.py:23
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
str
Definition: BTagTrackIpAccessor.cxx:11