ATLAS Offline Software
checkPlugins.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4 
5 
9 
10 __author__ = "Sebastien Binet"
11 
12 import os
13 import sys
14 from PyUtils import Dso
15 
16 _suppression_dct = {
17  'TMath' : ('libCore.so', 'libMathCore.so'),
18  'string': ('libGaudiKernelDict.so',
19  'libCore.so',
20  'liblcg_PyCoolDict.so',
21  'libSTLAddRflx.so'),
22  'vector<vector<double> >': ('libMathCore.so',
23  'libAtlasSTLAddReflexDict.so'),
24  'RooStats': ('libHistFactory.so',
25  'libRooStats.so'),
26  'vector<unsigned int>': ('libSTLRflx.so',
27  'libSTLAddRflx.so'),
28  'vector<double>': ('libSTLRflx.so',
29  'libSTLAddRflx.so'),
30  }
31 
33  return os.environ.get('AtlasProject')
34 
35 
36 def printDb( db, detailedDump = False ):
37  if detailedDump : fct = lambda x: x
38  else: fct = os.path.basename
39  keys = list(db.keys())
40  keys.sort()
41  for k in keys:
42  print ("%s:" % k)
43  libs = db[k]
44  libs.sort()
45  for lib in libs:
46  print (" ",fct(lib))
47  return
48 
49 if __name__ == "__main__":
50 
51  from optparse import OptionParser
52  parser = OptionParser(usage="usage: %prog [options]")
53  parser.add_option(
54  "--capabilities",
55  dest = "capabilities",
56  default = None,
57  help = "Dump the capabilities of a given library (ex: libAthenaServices.so)"
58  )
59  parser.add_option(
60  "--dups",
61  dest = "checkDups",
62  default = None,
63  help = "Check if there is any duplicates among dictionaries for a given library"
64  )
65  parser.add_option(
66  "--dump-content",
67  dest = "dumpContent",
68  action = "store_true",
69  default = False,
70  help = "Dump the content of all the known plugins (dicts. and components)"
71  )
72  parser.add_option(
73  "--dso",
74  dest = "dumpDso",
75  action = "store_true",
76  default = False,
77  help = "Dump all the dsomap/rootmap files known to the Dso repository"
78  )
79  parser.add_option(
80  "--libs",
81  dest = "dumpLibs",
82  action = "store_true",
83  default = False,
84  help = "Dump all the libraries known to the Dso repository"
85  )
86  parser.add_option(
87  "--check-dict-dups",
88  action = "store_true",
89  default = False,
90  dest = "checkDictDuplicates",
91  help = "Check if there is any duplicates among dictionaries"
92  )
93  parser.add_option(
94  "--check-pf-dups",
95  action = "store_true",
96  default = False,
97  dest = "checkPfDuplicates",
98  help = "Check if there is any duplicates among components declared to the PluginSvc"
99  )
100  parser.add_option(
101  "--check-all-dups",
102  dest = "checkAllDuplicates",
103  action = "store_true",
104  default = False,
105  help = "Check dictionaries *and* components"
106  )
107  parser.add_option(
108  "--detailed-dump",
109  action = "store_true",
110  dest = "detailedDump",
111  default = False,
112  help = "Performs a detailed dump if duplicates are found"
113  )
114  parser.add_option(
115  "--pedantic",
116  action = "store_true",
117  dest = "isPedantic",
118  default = False,
119  help = "Pedantic mode: if a component is found in 2 libraries which have the same name (usual case of a developer working on a (set of) package(s)), it is still being reported as being duplicated"
120  )
121  parser.add_option(
122  "-l",
123  "--level",
124  dest = "logLvl",
125  default = "INFO",
126  help = "Logging level (aka verbosity)"
127  )
128 
129  (options, args) = parser.parse_args()
130 
131  print (":"*80)
132  print ("::: checkPlugins :::")
133  sc = 0
134  dsoDb = Dso.DsoDb()
135 
136  if len(args) > 0 and args[0][0] != "-":
137  options.capabilities = args[0]
138  pass
139 
140  if options.capabilities:
141  libName = options.capabilities
142  try:
143  capabilities = dsoDb.capabilities(libName)
144  print ("::: capabilities of [%s]" % libName)
145  print (os.linesep.join( [ " "+str(c) for c in capabilities ] ))
146  except ValueError:
147  sc = 1
148  pass
149 
150  if options.checkDups:
151  libName = options.checkDups
152  try:
153  print ("::: checking duplicates for [%s]..." % libName)
154  dups = dsoDb.duplicates(libName, pedantic = options.isPedantic)
155  for k in dups:
156  print (" -",k)
157  print (os.linesep.join( [ " "+str(v) for v in dups[k] ] ))
158  if len(dups.keys())>0: sc = 1
159  except ValueError:
160  sc = 1
161  pass
162 
163  if options.dumpContent:
164  print ("::: dumping content of all known plugins...")
165  entries = dsoDb.content( pedantic = options.isPedantic )
166  printDb(entries, options.detailedDump)
167  print ("::: known entries:",len(entries.keys()))
168 
169  if options.dumpLibs:
170  print ("::: dumping all known libraries...")
171  libs = dsoDb.libs(options.detailedDump)
172  for lib in libs:
173  print (" -",lib)
174  print ("::: known libs:",len(libs))
175 
176  if options.dumpDso:
177  print ("::: dumping all known dsomap/rootmap files...")
178  dsoFiles = [ dso for dso in dsoDb.dsoFiles]
179  dsoFiles.sort()
180  for dsoFile in dsoFiles:
181  if not options.detailedDump: dsoFile = os.path.basename(dsoFile)
182  print (" -",dsoFile)
183  print ("::: known dsos:",len(dsoFiles))
184 
185  if options.checkDictDuplicates or options.checkAllDuplicates:
186  print (":: checking dict. duplicates...")
187  dups = dsoDb.dictDuplicates( pedantic = options.isPedantic )
188  # restrict to just this project
189  #currProj = _currentProject()
190  #restrictedDups = {}
191  #for label, libPaths in dups.items():
192  # paths = [l for l in libPaths if ('/%s/' % currProj) in l]
193  # if paths:
194  # restrictedDups[label] = paths
195  #dups = restrictedDups
196 
197  sc = 0
198  suppression_log = []
199  for k in dups:
200  v = dups[k]
201 
202  # mark as error only if it isn't a know dup'
203  if k in _suppression_dct:
204  suppressed = [os.path.basename(ii) in _suppression_dct[k]
205  for ii in v]
206  if all(suppressed):
207  msg = "---> ignoring [%s]" % k
208  suppression_log.append(k[:])
209  #print (msg)
210  pass
211  else:
212  # that's a new one !
213  sc = 1
214  else:
215  # that's a new one !
216  sc = 1
217  #print ("---> NOT ignoring [%s]" % k)
218  printDb(dups, options.detailedDump)
219  if len(suppression_log):
220  print ("-"*40)
221  print ("## ignoring the following dups':")
222  for k in suppression_log:
223  print (" -",k)
224  print ("-"*40)
225  print ("## all dups:",len(dups.keys()))
226  print ("## dups:",len(dups.keys())-len(suppression_log))
227  if options.checkPfDuplicates or options.checkAllDuplicates:
228  print (":: checking (plugin factories) components duplicates...")
229  dups = dsoDb.pfDuplicates( pedantic = options.isPedantic )
230  if len(dups.keys()) > 0: sc = 1
231  printDb(dups, options.detailedDump)
232  print ("## dups:",len(dups.keys()))
233 
234  if sc != 0: print (":: ERROR !!")
235  else: print (":: All good.")
236 
237  print (":"*80)
238  sys.exit(sc)
python.AthDsoLogger.fct
fct
Definition: AthDsoLogger.py:42
checkPlugins.printDb
def printDb(db, detailedDump=False)
Definition: checkPlugins.py:36
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
str
Definition: BTagTrackIpAccessor.cxx:11
checkPlugins._currentProject
def _currentProject()
Definition: checkPlugins.py:32
Cut::all
@ all
Definition: SUSYToolsAlg.cxx:67