ATLAS Offline Software
check_reflex.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 # @file PyUtils.scripts.check_reflex
4 # @purpose a script to check the definitions of (reflex) plugins
5 # across multiple so-called 'rootmap' files
6 # @author Sebastien Binet
7 # @date February 2010
8 
9 from __future__ import print_function
10 
11 __doc__ = """
12 a script to check the definitions of (reflex) plugins across multiple so-called 'rootmap' files
13 """
14 __author__ = "Sebastien Binet"
15 
16 
17 
18 import PyUtils.acmdlib as acmdlib
19 
20 @acmdlib.command(name='chk-rflx')
21 @acmdlib.argument(
22  '--capabilities',
23  nargs='?',
24  default=None,
25  help="Dump the capabilities of a given library (ex: libAthenaServices.so)")
26 @acmdlib.argument(
27  '--dups',
28  dest='chk_dups',
29  default=None,
30  help="Check if there is any duplicates among dictionaries for a given library")
31 @acmdlib.argument(
32  '--dump-content',
33  action='store_true',
34  default=False,
35  help="Dump the content of all the known plugins (dicts. and components)")
36 @acmdlib.argument(
37  "--dso",
38  dest = "dump_dso",
39  action = "store_true",
40  default = False,
41  help = "Dump all the dsomap/rootmap files known to the Dso repository")
42 @acmdlib.argument(
43  "--libs",
44  dest = "dump_libs",
45  action = "store_true",
46  default = False,
47  help = "Dump all the libraries known to the Dso repository")
48 @acmdlib.argument(
49  "--check-dict-dups",
50  action = "store_true",
51  default = False,
52  help = "Check if there is any duplicates among dictionaries")
53 @acmdlib.argument(
54  "--check-pf-dups",
55  action = "store_true",
56  default = False,
57  help = "Check if there is any duplicates among components declared to the PluginSvc")
58 @acmdlib.argument(
59  "--check-all-dups",
60  action = "store_true",
61  default = False,
62  help = "Check dictionaries *and* components")
63 @acmdlib.argument(
64  "--detailed-dump",
65  action = "store_true",
66  default = False,
67  help = "Performs a detailed dump if duplicates are found")
68 @acmdlib.argument(
69  "--pedantic",
70  action = "store_true",
71  default = False,
72  help = """Pedantic mode: if a component is found in 2 libraries which have
73  the same name (usual case of a developer working on a (set of) package(s)),
74  it is still being reported as being duplicated""")
75 @acmdlib.argument(
76  "-l",
77  "--level",
78  default = "INFO",
79  help = "Logging level (aka verbosity)")
80 def main(args):
81  """a script to check the definitions of (reflex) plugins
82  across multiple so-called 'rootmap' files
83  """
84  exitcode = 0
85 
86  print (":"*80)
87  print ("::: chk-rflx :::")
88 
89  import os
90  import PyUtils.Dso as Dso
91 
92  _suppression_dct = {
93  'TMath' : ('libCore.so', 'libMathCore.so'),
94  'string': ('libGaudiKernelDict.so',
95  'libCore.so',
96  'liblcg_PyCoolDict.so',
97  'libSTLAddRflx.so'),
98  '__pf__::CNV_71_9631': ('libDataModelTestDataReadCnvPoolCnv.so',
99  'libDataModelTestDataWriteCnvPoolCnv.so',),
100  '__pf__::CNV_71_9632': ('libDataModelTestDataReadCnvPoolCnv.so',
101  'libDataModelTestDataWriteCnvPoolCnv.so',),
102  '__pf__::CNV_71_9633': ('libDataModelTestDataReadCnvPoolCnv.so',
103  'libDataModelTestDataWriteCnvPoolCnv.so',),
104  '__pf__::CNV_71_9634': ('libDataModelTestDataReadCnvPoolCnv.so',
105  'libDataModelTestDataWriteCnvPoolCnv.so',),
106  '__pf__::CNV_71_9639': ('libDataModelTestDataReadCnvPoolCnv.so',
107  'libDataModelTestDataWriteCnvPoolCnv.so',),
108 
109  '__pf__::RootCollection': ('liblcg_RootCollection.so',
110  'libAthAnalysisTools.so',),
111 
112 
113  }
114 
115 
116  def print_db( db, detailedDump = False ):
117  if detailedDump : fct = lambda x: x
118  else: fct = os.path.basename
119  keys = db.keys()
120  keys.sort()
121  for k in keys:
122  print ("%s:" % k)
123  libs = db[k]
124  libs.sort()
125  for lib in libs:
126  print (" ",fct(lib))
127  return
128 
129  dsodb = Dso.DsoDb()
130 
131  if args.capabilities:
132  libname = args.capabilities
133  try:
134  capabilities = dsodb.capabilities(libname)
135  print ("::: capabilities of [%s]" % (libname,))
136  print (os.linesep.join([" %s"%c for c in capabilities]))
137  except ValueError:
138  exitcode = 1
139  pass
140 
141  if args.chk_dups:
142  libname = args.chk_dups
143  try:
144  print ("::: checking duplicates for [%s]..." % (libname,))
145  dups = dsodb.duplicates(libname, pedantic=args.pedantic)
146  for k in dups:
147  print (" -",k)
148  print (os.linesep.join([" %s"%v for v in dups[k]]))
149  if len(dups.keys())>0:
150  exitcode = 1
151  except ValueError:
152  exitcode = 1
153  pass
154 
155  if args.dump_content:
156  print ("::: dumping content of all known plugins...")
157  entries = dsodb.content(pedantic=args.pedantic)
158  print_db(entries, args.detailed_dump)
159  print ("::: known entries:",len(entries.keys()))
160 
161  if args.dump_libs:
162  print ("::: dumping all known libraries...")
163  libs = dsodb.libs(detailedDump=args.detailed_dump)
164  for lib in libs:
165  print (" -",lib)
166  print ("::: known libs:",len(libs))
167 
168  if args.dump_dso:
169  print ("::: dumping all known dso/rootmap files...")
170  dso_files = [dso for dso in dsodb.dsoFiles]
171  dso_files.sort()
172  for dso_file in dso_files:
173  if not args.detailed_dump:
174  dso_file = os.path.basename(dso_file)
175  print (" -",dso_file)
176  print ("::: known dsos:",len(dso_files))
177 
178  if args.check_dict_dups:
179  print (":: checking dict. duplicates...")
180  dups = dsodb.dictDuplicates(pedantic=args.pedantic)
181  suppression_log = []
182  for k in dups:
183  v = dups[k]
184  # mark as error only if it isn't a known dup'
185  if k in _suppression_dct:
186  suppressed = [os.path.basename(ii) in _suppression_dct[k]
187  for ii in v]
188  if all(suppressed):
189  suppression_log.append(k[:])
190  pass
191  else:
192  # that's a new one !!
193  exitcode = 1
194  else:
195  # that's a new one !!
196  exitcode = 1
197  # print ("---> NOT ignoring [%s]" % (k,))
198  print_db(dups, args.detailed_dump)
199  if len(suppression_log):
200  print ("-"*40)
201  print ("## ignoring the following dups':")
202  for k in suppression_log:
203  print (" -",k)
204  print ("-"*40)
205  print ("## all dups:",len(dups.keys()))
206  print ("## dups:",len(dups.keys())-len(suppression_log))
207 
208  if args.check_pf_dups:
209  print ("::: checking (plugin factories) components dups...")
210  dups = dsodb.pfDuplicates(pedantic=args.pedantic)
211  suppression_log = []
212  for k in dups:
213  v = dups[k]
214  # mark as error only if it isn't a known dup'
215  if k in _suppression_dct:
216  suppressed = [os.path.basename(ii) in _suppression_dct[k]
217  for ii in v]
218  if all(suppressed):
219  suppression_log.append(k[:])
220  pass
221  else:
222  # that's a new one !!
223  exitcode = 1
224  else:
225  # that's a new one !!
226  exitcode = 1
227  # print ("---> NOT ignoring [%s]" % (k,))
228  print_db(dups, args.detailed_dump)
229  if len(suppression_log):
230  print ("-"*40)
231  print ("## ignoring the following dups':")
232  for k in suppression_log:
233  print (" -",k)
234  print ("-"*40)
235  print ("## all dups:",len(dups.keys()))
236  print ("## dups:",len(dups.keys())-len(suppression_log))
237 
238  if args.check_all_dups:
239  print ("::: checking all components dups...")
240  dups = dsodb.pfDuplicates(pedantic=args.pedantic)
241  dups.update(dsodb.dictDuplicates(pedantic=args.pedantic))
242 
243  suppression_log = []
244  for k in dups:
245  v = dups[k]
246  # mark as error only if it isn't a known dup'
247  if k in _suppression_dct:
248  suppressed = [os.path.basename(ii) in _suppression_dct[k]
249  for ii in v]
250  if all(suppressed):
251  suppression_log.append(k[:])
252  pass
253  else:
254  # that's a new one !!
255  exitcode = 1
256  else:
257  # that's a new one !!
258  exitcode = 1
259  # print ("---> NOT ignoring [%s]" % (k,))
260  print_db(dups, args.detailed_dump)
261  if len(suppression_log):
262  print ("-"*40)
263  print ("## ignoring the following dups':")
264  for k in suppression_log:
265  print (" -",k)
266  print ("-"*40)
267  print ("## all dups:",len(dups.keys()))
268  print ("## dups:",len(dups.keys())-len(suppression_log))
269 
270  if exitcode:
271  print ("::: ERROR !!")
272  else:
273  print ("::: All good.")
274 
275  print (":"*80)
276  return exitcode
Cut::all
@ all
Definition: SUSYToolsAlg.cxx:67
python.AthDsoLogger.fct
fct
Definition: AthDsoLogger.py:43
python.Dso.DsoDb
Definition: Control/AthenaServices/python/Dso.py:42
python.scripts.check_reflex.main
def main(args)
Definition: check_reflex.py:80