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 {
'Associations': [
'TTTrackTruthPair']},
39 {
'TrajectoryState' : [
'TrajectoryStateOnSurface']},
40 {
'TrackTriggerAssociation' : [
'(TTClusterAssociationMap|TTStubAssociationMap|TTTrackAssociationMap|TrackingParticle).*Phase2TrackerDigi',
41 '(TTStub|TTCluster|TTTrack).*Phase2TrackerDigi.*TrackingParticle']},
42 {
'L1TrackTrigger' : [
'(TTStub|TTCluster|TTTrack).*Phase2TrackerDigi']},
43 {
'L1TCalorimeterPhase2' : [
'l1tp2::CaloTower.*']},
44 {
'L1TCalorimeter' : [
'l1t::CaloTower.*']},
45 {
'GsfTracking' : [
'reco::GsfTrack(Collection|).*(MomentumConstraint|VertexConstraint)',
'Trajectory.*reco::GsfTrack']},
46 {
'ParallelAnalysis' : [
'examples::TrackAnalysisAlgorithm']},
47 {
'PatCandidates' : [
'pat::PATObject',
'pat::Lepton',
'reco::RecoCandidate',
'pat::[A-Za-z]+Ref(Vector|)',
'pat::UserHolder']},
48 {
'BTauReco' : [
'reco::.*SoftLeptonTagInfo',
'reco::SoftLeptonProperties',
'reco::SecondaryVertexTagInfo',
'reco::IPTagInfo',
'reco::TemplatedSecondaryVertexTagInfo',
'reco::CATopJetProperties',
'reco::HTTTopJetProperties']},
49 {
'CastorReco' : [
'reco::CastorJet']},
50 {
'JetMatching' : [
'reco::JetFlavourInfo',
'reco::JetFlavour',
'reco::MatchedPartons']},
51 {
'RecoCandidate' : [
'reco::Candidate',
'edm::Wrapper.+edm::AssociationMap.+TrackingParticle']},
52 {
'TrackingAnalysis' : [
'TrackingParticle']},
53 {
'Egamma' : [
'reco::ElectronID']},
54 {
'TopObjects' : [
'reco::CATopJetProperties']},
55 {
'TauReco' : [
'reco::L2TauIsolationInfo',
'reco::RecoTauPiZero',
'reco::BaseTau']},
56 {
'ValidationFormats' : [
'PGlobalDigi::.+',
'PGlobalRecHit::.+']},
57 {
'TrajectorySeed' : [
'TrajectorySeed']},
58 {
'TrackCandidate' : [
'TrackCandidate']},
59 {
'PatternTools' : [
'MomentumConstraint',
'VertexConstraint',
'Trajectory']},
60 {
'TrackerRecHit2D' : [
'SiStrip(Matched|)RecHit[12]D',
'SiTrackerGSRecHit[12]D',
'SiPixelRecHit']},
61 {
'MuonReco' : [
'reco::Muon(Ref|)(Vector|)']},
62 {
'MuonSeed' : [
'L3MuonTrajectorySeed']},
63 {
'HepMCCandidate' : [
'reco::GenParticle.*']},
64 {
'L1Trigger' : [
'l1extra::L1.+Particle']},
65 {
'TrackInfo' : [
'reco::TrackingRecHitInfo']},
66 {
'EgammaCandidates' : [
'reco::GsfElectron.*',
'reco::Photon.*']},
67 {
'HcalIsolatedTrack' : [
'reco::IsolatedPixelTrackCandidate',
'reco::EcalIsolatedParticleCandidate',
'reco::HcalIsolatedTrackCandidate']},
68 {
'HcalRecHit' : [
'HFRecHit',
'HORecHit',
'ZDCRecHit',
'HBHERecHit']},
69 {
'PFRootEvent' : [
'EventColin::']},
70 {
'CaloTowers' : [
'CaloTower.*']},
71 {
'GsfTrackReco' : [
'GsfTrack.*']},
72 {
'METReco' : [
'reco::(Calo|PF|Gen|)MET',
'reco::PFClusterMET']},
73 {
'ParticleFlowReco' : [
'reco::RecoPFClusterRefCandidateRef.*']},
74 {
'ParticleFlowCandidate' : [
'reco::PFCandidateRef',
'reco::PFCandidateFwdRef',
'reco::PFCandidate']},
75 {
'PhysicsToolsObjects' : [
'PhysicsTools::Calibration']},
76 {
'TrackReco' : [
'reco::Track',
'reco::TrackRef']},
77 {
'VertexReco' : [
'reco::Vertex']},
78 {
'TFWLiteSelectorTest' : [
'tfwliteselectortest']},
79 {
'TauReco' : [
'reco::PFJetRef']},
80 {
'JetReco' : [
'reco::.*Jet',
'reco::.*Jet(Collection|Ref)']},
81 {
'HGCDigi' : [
'HGCSample']},
82 {
'HGCRecHit' : [
'constHGCRecHit',
'HGCRecHit']},
83 {
'SiPixelObjects' : [
'SiPixelQuality.*']},
87 'LCGReflex/__gnu_cxx::__normal_iterator<std::basic_string<char>*,std::vector<std::basic_string<char>%>%>' : 1,
92 """ Searches through the requested directory looking at
93 'classes_def.xml' files looking for duplicate Reflex definitions."""
95 classNameRE = re.compile (
r'class\s+name\s*=\s*"([^"]*)"')
96 spacesRE = re.compile (
r'\s+')
97 stdRE = re.compile (
r'std::')
98 srcClassNameRE = re.compile (
r'(\w+)/src/classes_def.*[.]xml')
99 ignoreSrcRE = re.compile (
r'.*/FWCore/Skeletons/scripts/mkTemplates/.+')
100 braketRE = re.compile (
r'<.+>')
101 print(
"Searching for 'classes_def.xml' in '%s'." % os.path.join(os.environ.get(
'CMSSW_BASE'),
'src'))
103 for srcDir
in [os.environ.get(
'CMSSW_BASE'),os.environ.get(
'CMSSW_RELEASE_BASE')]:
104 if not len(srcDir):
continue
105 for xml
in getoutput (
'cd '+os.path.join(srcDir,
'src')+
'; find . -name "*classes_def*.xml" -follow -print').split (
'\n'):
106 if xml
and (
not xml
in xmlFiles):
109 pprint.pprint (xmlFiles)
115 for item
in equivDict:
117 for equiv
in item[pack]:
118 explicitREs.append( (re.compile(
r'\b' + equiv +
r'\b'),pack))
120 for filename
in xmlFiles:
121 if (
not filename)
or (ignoreSrcRE.match(filename)):
continue
122 match = srcClassNameRE.search (filename)
123 if not match:
continue
124 packageName = match.group(1)
125 xmlPackages.append (packageName)
126 matchString =
r'\b' + packageName +
r'\b'
127 packagesREs[packageName] = re.compile (matchString)
128 equivList = equivREs.setdefault (packageName, [])
129 for item
in equivDict:
130 for equiv
in item.get (packageName, []):
131 matchString = re.compile(
r'\b' + equiv +
r'\b')
132 equivList.append( (matchString, equiv) )
133 equivList.append( (packagesREs[packageName], packageName) )
135 ncdict = {
'class' :
'className',
'function' :
'functionName'}
136 for filename
in xmlFiles:
137 if (
not filename)
or (ignoreSrcRE.match(filename)):
continue
144 lostMatch = srcClassNameRE.search (filename)
146 exceptName = lostMatch.group (1)
147 regexList = equivREs[exceptName]
148 xcount = len(regexList)-1
149 if not regexList[xcount][0].search (exceptName):
150 print(
'%s not found in' % exceptName, end=
' ')
151 print(regexList[xcount][0])
155 print(
"filename", filename)
157 filepath = os.path.join(os.environ.get(
'CMSSW_BASE'),
'src',filename)
158 if not os.path.exists(filepath):
159 filepath = os.path.join(os.environ.get(
'CMSSW_RELEASE_BASE'),
'src',filename)
160 xmlObj = xml2obj (filename = filepath,
162 nameChangeDict = ncdict)
163 except Exception
as detail:
164 print(
"File %s is malformed XML. Please fix." % filename)
168 classList = xmlObj.selection.className
171 classList = xmlObj.className
174 print(
"**** SKIPPING '%s' - Doesn't seem to have proper information." % filename)
177 classList = xmlObj.functionName
179 print(
"**** SKIPPING '%s' - Dosen't seem to have proper information(not class/function)." % filename)
181 for piece
in classList:
183 className = spacesRE.sub (
'', piece.name)
188 className = stdRE.sub (
'', className)
191 for typedef, tdList
in six.iteritems(typedefsDict):
193 className = re.sub (alias, typedef, className)
194 classDict.setdefault (className, set()).add (filename)
196 if not options.lostDefs:
198 localObjects.append (className)
199 if options.lazyLostDefs
and not braketRE.search (className):
201 matchString =
r'\b' + className +
r'\b'
202 simpleObjectREs.append( (re.compile (matchString), className ) )
203 for className
in localObjects:
207 for equivRE
in regexList:
209 if equivRE[0].search (className):
212 for simpleRE
in simpleObjectREs:
213 if simpleRE[0].search (className):
215 if options.verbose
and simpleRE[1] != className:
216 print(
" Using %s to ignore %s" \
217 % (simpleRE[1], className))
219 if foundEquiv:
continue
220 for exRes
in explicitREs:
221 if exRes[0].
search(className):
222 dupProblems +=
" %s : %s\n" % (exRes[1], className)
225 if foundEquiv:
continue
226 for packageName
in xmlPackages:
229 if packagesREs[packageName].search (className):
230 dupProblems +=
" %s : %s\n" % (packageName, className)
234 print(
'\n%s\n%s\n' % (filename, dupProblems))
237 for name, fileSet
in sorted( six.iteritems(classDict) ):
238 if len (fileSet) < 2:
241 fileList = sorted (fileSet)
242 for filename
in fileList:
251 """ Searches the edmpluginFile to find any duplicate
254 libenv =
'LD_LIBRARY_PATH'
255 if os.environ.get(
'SCRAM_ARCH').startswith(
'osx'): libenv =
'DYLD_FALLBACK_LIBRARY_PATH'
256 biglib =
'/biglib/'+os.environ.get(
'SCRAM_ARCH')
257 for libdir
in os.environ.get(libenv).
split(
':'):
258 if libdir.endswith(biglib):
continue
259 if os.path.exists(libdir+
'/.edmplugincache'): edmpluginFile = edmpluginFile +
' ' + libdir+
'/.edmplugincache'
260 if edmpluginFile ==
'': edmpluginFile = os.path.join(os.environ.get(
'CMSSW_BASE'),
'lib',os.environ.get(
'SCRAM_ARCH'),
'.edmplugincache')
261 cmd =
"cat %s | awk '{print $2\" \"$1}' | sort | uniq | awk '{print $1}' | sort | uniq -c | grep '2 ' | awk '{print $2}'" % edmpluginFile
262 output = getoutput (cmd).
split(
'\n')
264 if line
in ignoreEdmDP:
continue
265 line = line.replace(
"*",
"\*")
266 cmd =
"cat %s | grep ' %s ' | awk '{print $1}' | sort | uniq " % (edmpluginFile,line)
267 out1 = getoutput (cmd).
split(
'\n')
271 print(
" **"+plugin+
"**")
274 if __name__ ==
"__main__":
276 parser = optparse.OptionParser (
"Usage: %prog [options]\n"\
277 "Searches classes_def.xml for wrong/duplicate "\
279 xmlGroup = optparse.OptionGroup (parser,
"ClassDef XML options")
280 dumpGroup = optparse.OptionGroup (parser,
"EdmPluginDump options")
281 xmlGroup.add_option (
'--dups', dest=
'dups', action=
'store_true',
283 help=
"Search for duplicate definitions")
284 xmlGroup.add_option (
'--lostDefs', dest=
'lostDefs', action=
'store_true',
286 help=
"Looks for definitions in the wrong libraries")
287 xmlGroup.add_option (
'--lazyLostDefs', dest=
'lazyLostDefs',
290 help=
"Will try to ignore as many lost defs as reasonable")
291 xmlGroup.add_option (
'--verbose', dest=
'verbose',
294 help=
"Prints out a lot of information")
295 xmlGroup.add_option (
'--showXMLs', dest=
'showXMLs', action=
'store_true',
297 help=
"Shows all 'classes_def.xml' files")
298 xmlGroup.add_option (
'--dir', dest=
'srcdir', type=
'string', default=
'',
300 dumpGroup.add_option (
'--edmPD', dest=
'edmPD', action=
'store_true',
302 help=
"Searches EDM Plugin Dump for duplicates")
303 dumpGroup.add_option (
'--edmFile', dest=
'edmFile', type=
'string',
306 parser.add_option_group (xmlGroup)
307 parser.add_option_group (dumpGroup)
308 (options, args) = parser.parse_args()
311 if options.lazyLostDefs:
312 options.lostDefs =
True
313 if options.showXMLs
or options.lostDefs
or options.dups:
316 searchDuplicatePlugins ()