3 from __future__
import print_function
10 from XML2Python
import xml2obj
13 from subprocess
import getoutput
15 from commands
import getoutput
21 'unsigned int' : [
'unsignedint',
'UInt32_t',
'uint32_t'],
22 'unsigned long': [
'unsignedlong'],
24 'float' : [
'Float_t'],
25 'double' : [
'Double_t'],
38 {
'TrajectoryState' : [
'TrajectoryStateOnSurface']},
39 {
'TrackTriggerAssociation' : [
'(TTClusterAssociationMap|TTStubAssociationMap|TTTrackAssociationMap|TrackingParticle).*Phase2TrackerDigi',
40 '(TTStub|TTCluster|TTTrack).*Phase2TrackerDigi.*TrackingParticle']},
41 {
'L1TrackTrigger' : [
'(TTStub|TTCluster|TTTrack).*Phase2TrackerDigi']},
42 {
'L1TCalorimeterPhase2' : [
'l1tp2::CaloTower.*']},
43 {
'L1TCalorimeter' : [
'l1t::CaloTower.*']},
44 {
'GsfTracking' : [
'reco::GsfTrack(Collection|).*(MomentumConstraint|VertexConstraint)',
'Trajectory.*reco::GsfTrack']},
45 {
'ParallelAnalysis' : [
'examples::TrackAnalysisAlgorithm']},
46 {
'PatCandidates' : [
'pat::PATObject',
'pat::Lepton',
'reco::RecoCandidate',
'pat::[A-Za-z]+Ref(Vector|)',
'pat::UserHolder']},
47 {
'BTauReco' : [
'reco::.*SoftLeptonTagInfo',
'reco::SoftLeptonProperties',
'reco::SecondaryVertexTagInfo',
'reco::IPTagInfo',
'reco::TemplatedSecondaryVertexTagInfo',
'reco::CATopJetProperties',
'reco::HTTTopJetProperties']},
48 {
'CastorReco' : [
'reco::CastorJet']},
49 {
'JetMatching' : [
'reco::JetFlavourInfo',
'reco::JetFlavour',
'reco::MatchedPartons']},
50 {
'RecoCandidate' : [
'reco::Candidate',
'edm::Wrapper.+edm::AssociationMap.+TrackingParticle']},
51 {
'TrackingAnalysis' : [
'TrackingParticle']},
52 {
'Egamma' : [
'reco::ElectronID']},
53 {
'TopObjects' : [
'reco::CATopJetProperties']},
54 {
'TauReco' : [
'reco::L2TauIsolationInfo',
'reco::RecoTauPiZero',
'reco::BaseTau']},
55 {
'ValidationFormats' : [
'PGlobalDigi::.+',
'PGlobalRecHit::.+']},
56 {
'TrajectorySeed' : [
'TrajectorySeed']},
57 {
'TrackCandidate' : [
'TrackCandidate']},
58 {
'PatternTools' : [
'MomentumConstraint',
'VertexConstraint',
'Trajectory']},
59 {
'TrackerRecHit2D' : [
'SiStrip(Matched|)RecHit[12]D',
'SiTrackerGSRecHit[12]D',
'SiPixelRecHit']},
60 {
'MuonReco' : [
'reco::Muon(Ref|)(Vector|)']},
61 {
'MuonSeed' : [
'L3MuonTrajectorySeed']},
62 {
'HepMCCandidate' : [
'reco::GenParticle.*']},
63 {
'L1Trigger' : [
'l1extra::L1.+Particle']},
64 {
'TrackInfo' : [
'reco::TrackingRecHitInfo']},
65 {
'EgammaCandidates' : [
'reco::GsfElectron.*',
'reco::Photon.*']},
66 {
'HcalIsolatedTrack' : [
'reco::IsolatedPixelTrackCandidate',
'reco::EcalIsolatedParticleCandidate',
'reco::HcalIsolatedTrackCandidate']},
67 {
'HcalRecHit' : [
'HFRecHit',
'HORecHit',
'ZDCRecHit',
'HBHERecHit']},
68 {
'PFRootEvent' : [
'EventColin::']},
69 {
'CaloTowers' : [
'CaloTower.*']},
70 {
'GsfTrackReco' : [
'GsfTrack.*']},
71 {
'METReco' : [
'reco::(Calo|PF|Gen|)MET',
'reco::PFClusterMET']},
72 {
'ParticleFlowReco' : [
'reco::RecoPFClusterRefCandidateRef.*']},
73 {
'ParticleFlowCandidate' : [
'reco::PFCandidateRef',
'reco::PFCandidateFwdRef',
'reco::PFCandidate']},
74 {
'PhysicsToolsObjects' : [
'PhysicsTools::Calibration']},
75 {
'TrackReco' : [
'reco::Track',
'reco::TrackRef']},
76 {
'VertexReco' : [
'reco::Vertex']},
77 {
'TFWLiteSelectorTest' : [
'tfwliteselectortest']},
78 {
'TauReco' : [
'reco::PFJetRef']},
79 {
'JetReco' : [
'reco::.*Jet',
'reco::.*Jet(Collection|Ref)']},
80 {
'HGCDigi' : [
'HGCSample']},
81 {
'SiPixelObjects' : [
'SiPixelQuality.*']},
85 'LCGReflex/__gnu_cxx::__normal_iterator<std::basic_string<char>*,std::vector<std::basic_string<char>%>%>' : 1,
90 """ Searches through the requested directory looking at
91 'classes_def.xml' files looking for duplicate Reflex definitions."""
93 classNameRE = re.compile (
r'class\s+name\s*=\s*"([^"]*)"')
94 spacesRE = re.compile (
r'\s+')
95 stdRE = re.compile (
r'std::')
96 srcClassNameRE = re.compile (
r'(\w+)/src/classes_def.*[.]xml')
97 ignoreSrcRE = re.compile (
r'.*/FWCore/Skeletons/scripts/mkTemplates/.+')
98 braketRE = re.compile (
r'<.+>')
99 print(
"Searching for 'classes_def.xml' in '%s'." % os.path.join(os.environ.get(
'CMSSW_BASE'),
'src'))
101 for srcDir
in [os.environ.get(
'CMSSW_BASE'),os.environ.get(
'CMSSW_RELEASE_BASE')]:
102 if not len(srcDir):
continue
103 for xml
in getoutput (
'cd '+os.path.join(srcDir,
'src')+
'; find . -name "*classes_def*.xml" -follow -print').split (
'\n'):
104 if xml
and (
not xml
in xmlFiles):
107 pprint.pprint (xmlFiles)
113 for item
in equivDict:
115 for equiv
in item[pack]:
116 explicitREs.append( (re.compile(
r'\b' + equiv +
r'\b'),pack))
118 for filename
in xmlFiles:
119 if (
not filename)
or (ignoreSrcRE.match(filename)):
continue
120 match = srcClassNameRE.search (filename)
121 if not match:
continue
122 packageName = match.group(1)
123 xmlPackages.append (packageName)
124 matchString =
r'\b' + packageName +
r'\b'
125 packagesREs[packageName] = re.compile (matchString)
126 equivList = equivREs.setdefault (packageName, [])
127 for item
in equivDict:
128 for equiv
in item.get (packageName, []):
129 matchString = re.compile(
r'\b' + equiv +
r'\b')
130 equivList.append( (matchString, equiv) )
131 equivList.append( (packagesREs[packageName], packageName) )
133 ncdict = {
'class' :
'className',
'function' :
'functionName'}
134 for filename
in xmlFiles:
135 if (
not filename)
or (ignoreSrcRE.match(filename)):
continue
142 lostMatch = srcClassNameRE.search (filename)
144 exceptName = lostMatch.group (1)
145 regexList = equivREs[exceptName]
146 xcount = len(regexList)-1
147 if not regexList[xcount][0].search (exceptName):
148 print(
'%s not found in' % exceptName, end=
' ')
149 print(regexList[xcount][0])
153 print(
"filename", filename)
155 filepath = os.path.join(os.environ.get(
'CMSSW_BASE'),
'src',filename)
156 if not os.path.exists(filepath):
157 filepath = os.path.join(os.environ.get(
'CMSSW_RELEASE_BASE'),
'src',filename)
158 xmlObj = xml2obj (filename = filepath,
160 nameChangeDict = ncdict)
161 except Exception
as detail:
162 print(
"File %s is malformed XML. Please fix." % filename)
166 classList = xmlObj.selection.className
169 classList = xmlObj.className
172 print(
"**** SKIPPING '%s' - Doesn't seem to have proper information." % filename)
175 classList = xmlObj.functionName
177 print(
"**** SKIPPING '%s' - Dosen't seem to have proper information(not class/function)." % filename)
179 for piece
in classList:
181 className = spacesRE.sub (
'', piece.name)
186 className = stdRE.sub (
'', className)
189 for typedef, tdList
in six.iteritems(typedefsDict):
191 className = re.sub (alias, typedef, className)
192 classDict.setdefault (className, set()).add (filename)
194 if not options.lostDefs:
196 localObjects.append (className)
197 if options.lazyLostDefs
and not braketRE.search (className):
199 matchString =
r'\b' + className +
r'\b'
200 simpleObjectREs.append( (re.compile (matchString), className ) )
201 for className
in localObjects:
205 for equivRE
in regexList:
207 if equivRE[0].search (className):
210 for simpleRE
in simpleObjectREs:
211 if simpleRE[0].search (className):
213 if options.verbose
and simpleRE[1] != className:
214 print(
" Using %s to ignore %s" \
215 % (simpleRE[1], className))
217 if foundEquiv:
continue
218 for exRes
in explicitREs:
219 if exRes[0].
search(className):
220 dupProblems +=
" %s : %s\n" % (exRes[1], className)
223 if foundEquiv:
continue
224 for packageName
in xmlPackages:
227 if packagesREs[packageName].search (className):
228 dupProblems +=
" %s : %s\n" % (packageName, className)
232 print(
'\n%s\n%s\n' % (filename, dupProblems))
235 for name, fileSet
in sorted( six.iteritems(classDict) ):
236 if len (fileSet) < 2:
239 fileList = sorted (fileSet)
240 for filename
in fileList:
249 """ Searches the edmpluginFile to find any duplicate
252 libenv =
'LD_LIBRARY_PATH'
253 if os.environ.get(
'SCRAM_ARCH').startswith(
'osx'): libenv =
'DYLD_FALLBACK_LIBRARY_PATH'
254 biglib =
'/biglib/'+os.environ.get(
'SCRAM_ARCH')
255 for libdir
in os.environ.get(libenv).
split(
':'):
256 if libdir.endswith(biglib):
continue
257 if os.path.exists(libdir+
'/.edmplugincache'): edmpluginFile = edmpluginFile +
' ' + libdir+
'/.edmplugincache'
258 if edmpluginFile ==
'': edmpluginFile = os.path.join(os.environ.get(
'CMSSW_BASE'),
'lib',os.environ.get(
'SCRAM_ARCH'),
'.edmplugincache')
259 cmd =
"cat %s | awk '{print $2\" \"$1}' | sort | uniq | awk '{print $1}' | sort | uniq -c | grep '2 ' | awk '{print $2}'" % edmpluginFile
260 output = getoutput (cmd).
split(
'\n')
262 if line
in ignoreEdmDP:
continue
263 line = line.replace(
"*",
"\*")
264 cmd =
"cat %s | grep ' %s ' | awk '{print $1}' | sort | uniq " % (edmpluginFile,line)
265 out1 = getoutput (cmd).
split(
'\n')
269 print(
" **"+plugin+
"**")
272 if __name__ ==
"__main__":
274 parser = optparse.OptionParser (
"Usage: %prog [options]\n"\
275 "Searches classes_def.xml for wrong/duplicate "\
277 xmlGroup = optparse.OptionGroup (parser,
"ClassDef XML options")
278 dumpGroup = optparse.OptionGroup (parser,
"EdmPluginDump options")
279 xmlGroup.add_option (
'--dups', dest=
'dups', action=
'store_true',
281 help=
"Search for duplicate definitions")
282 xmlGroup.add_option (
'--lostDefs', dest=
'lostDefs', action=
'store_true',
284 help=
"Looks for definitions in the wrong libraries")
285 xmlGroup.add_option (
'--lazyLostDefs', dest=
'lazyLostDefs',
288 help=
"Will try to ignore as many lost defs as reasonable")
289 xmlGroup.add_option (
'--verbose', dest=
'verbose',
292 help=
"Prints out a lot of information")
293 xmlGroup.add_option (
'--showXMLs', dest=
'showXMLs', action=
'store_true',
295 help=
"Shows all 'classes_def.xml' files")
296 xmlGroup.add_option (
'--dir', dest=
'srcdir', type=
'string', default=
'',
298 dumpGroup.add_option (
'--edmPD', dest=
'edmPD', action=
'store_true',
300 help=
"Searches EDM Plugin Dump for duplicates")
301 dumpGroup.add_option (
'--edmFile', dest=
'edmFile', type=
'string',
304 parser.add_option_group (xmlGroup)
305 parser.add_option_group (dumpGroup)
306 (options, args) = parser.parse_args()
309 if options.lazyLostDefs:
310 options.lostDefs =
True
311 if options.showXMLs
or options.lostDefs
or options.dups:
314 searchDuplicatePlugins ()