ATLAS Offline Software
grepCompFactory.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 #
4 # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
5 #
6 
7 import re
8 import glob
9 import json
10 import argparse
11 
12 parser = argparse.ArgumentParser(description='Find duplicate config for athena modules in the current and all subfolders. Scans files ending in *onfig.py or *onfigNew.py. Ignores duplicates listed in given reference file.')
13 parser.add_argument('referenceFile', metavar='referenceFile', type=str,
14  help='Reference file with duplicates to ignore.')
15 args = parser.parse_args()
16 
17 
18 functionDict = {}
19 files = glob.glob('**/*onfig.py', recursive=True)
20 files = files + glob.glob('**/*onfigNew.py', recursive=True)
21 for file in files:
22  for line in open(file, 'r', encoding="utf-8"):
23  match = re.search(r"CompFactory\.(\w+\.?\w+) ?\‍(", line)
24  if match:
25  fun = match.group(1)
26  if fun in functionDict:
27  functionDict[fun].add(file)
28  else:
29  functionDict[fun] = {file}
30 
31 duplicates = {}
32 for item in functionDict.items():
33  if len(item[1]) > 1:
34  duplicates[item[0]]=list(item[1])
35 
36 with open(args.referenceFile) as f:
37  ref = json.loads(f.read())
38  addedDuplicates = {}
39  removedDuplicates = {}
40  for refItem in ref.items():
41  if refItem[0] not in duplicates.keys():
42  removedDuplicates[refItem[0]]=refItem[1]
43  continue
44  newRemoved = list(set(refItem[1]) - set(duplicates[refItem[0]]))
45  if len(newRemoved) > 0:
46  removedDuplicates[refItem[0]]= newRemoved
47  newAdded = list(set(duplicates[refItem[0]]) - set(refItem[1]))
48  if len(newAdded) > 0:
49  addedDuplicates[refItem[0]] = newAdded
50  del duplicates[refItem[0]]
51  if len(duplicates) > 0:
52  addedDuplicates.update(duplicates)
53 
54  if len(addedDuplicates) > 0:
55  print("New module instance created which is also created in other configuration file(s), please consider using an existing instance (or update the reference file using generateReferenceFile.py):")
56  print(addedDuplicates)
57  if len(removedDuplicates) > 0:
58  print("Please update the reference file, expected duplicates are not found:")
59  print(removedDuplicates)
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
Trk::open
@ open
Definition: BinningType.h:40