ATLAS Offline Software
Loading...
Searching...
No Matches
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
7import re
8import glob
9import json
10import argparse
11
12parser = 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.')
13parser.add_argument('referenceFile', metavar='referenceFile', type=str,
14 help='Reference file with duplicates to ignore.')
15args = parser.parse_args()
16
17
18functionDict = {}
19files = glob.glob('**/*onfig.py', recursive=True)
20files = files + glob.glob('**/*onfigNew.py', recursive=True)
21for 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
31duplicates = {}
32for item in functionDict.items():
33 if len(item[1]) > 1:
34 duplicates[item[0]]=list(item[1])
35
36with 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)
void print(char *figname, TCanvas *c1)
STL class.
bool add(const std::string &hname, TKey *tobj)
Definition fastadd.cxx:55