11 from XML2Python
import xml2obj
18 'unsigned int' : [
'unsignedint',
'UInt32_t',
'uint32_t'],
19 'unsigned long': [
'unsignedlong'],
21 'float' : [
'Float_t'],
22 'double' : [
'Double_t'],
35 {
'GsfTracking' : [
'reco::GsfTrack(Collection|).*(MomentumConstraint|VertexConstraint)',
'Trajectory.*reco::GsfTrack']},
36 {
'ParallelAnalysis' : [
'examples::TrackAnalysisAlgorithm']},
37 {
'PatCandidates' : [
'pat::PATObject',
'pat::Lepton']},
38 {
'BTauReco' : [
'reco::SoftLeptonProperties',
'reco::SecondaryVertexTagInfo']},
39 {
'CastorReco' : [
'reco::CastorJet']},
40 {
'JetMatching' : [
'reco::JetFlavour',
'reco::MatchedPartons']},
41 {
'TrackingAnalysis' : [
'TrackingParticle']},
42 {
'Egamma' : [
'reco::ElectronID']},
43 {
'TopObjects' : [
'reco::CATopJetProperties']},
44 {
'TauReco' : [
'reco::L2TauIsolationInfo',
'reco::RecoTauPiZero',
'reco::BaseTau']},
45 {
'ValidationFormats' : [
'PGlobalDigi::.+',
'PGlobalRecHit::.+']},
46 {
'TrajectorySeed' : [
'TrajectorySeed']},
47 {
'TrackCandidate' : [
'TrackCandidate']},
48 {
'PatternTools' : [
'MomentumConstraint',
'VertexConstraint',
'Trajectory']},
49 {
'TrackerRecHit2D' : [
'SiStrip(Matched|)RecHit[12]D',
'SiTrackerGSRecHit[12]D',
'SiPixelRecHit']},
50 {
'MuonReco' : [
'reco::Muon(Ref|)(Vector|)']},
51 {
'MuonSeed' : [
'L3MuonTrajectorySeed']},
52 {
'HepMCCandidate' : [
'reco::GenParticle.*']},
53 {
'L1Trigger' : [
'l1extra::L1.+Particle']},
54 {
'TrackInfo' : [
'reco::TrackingRecHitInfo']},
55 {
'EgammaCandidates' : [
'reco::GsfElectron.*',
'reco::Photon.*']},
56 {
'HcalIsolatedTrack' : [
'reco::IsolatedPixelTrackCandidate',
'reco::EcalIsolatedParticleCandidate']},
57 {
'HcalRecHit' : [
'HFRecHit',
'HORecHit',
'ZDCRecHit',
'HBHERecHit']},
58 {
'PFRootEvent' : [
'EventColin::']},
59 {
'CaloTowers' : [
'CaloTower.*']},
60 {
'GsfTrackReco' : [
'GsfTrack.*']},
61 {
'METReco' : [
'reco::(Calo|PF|Gen|)MET',
'reco::PFClusterMET']},
62 {
'ParticleFlowReco' : [
'reco::RecoPFClusterRefCandidateRef.*']},
63 {
'ParticleFlowCandidate' : [
'reco::PFCandidateRef',
'reco::PFCandidateFwdRef',
'reco::PFCandidate']},
64 {
'PhysicsToolsObjects' : [
'PhysicsTools::Calibration']},
65 {
'RecoCandidate' : [
'reco::Candidate']},
66 {
'TrackReco' : [
'reco::Track',
'reco::TrackRef']},
67 {
'VertexReco' : [
'reco::Vertex']},
68 {
'TFWLiteSelectorTest' : [
'tfwliteselectortest']},
69 {
'PatCandidates' : [
'reco::RecoCandidate',
'pat::[A-Za-z]+Ref(Vector|)']},
70 {
'JetReco' : [
'reco::.*Jet',
'reco::.*Jet(Collection|Ref)']},
74 'LCGReflex/__gnu_cxx::__normal_iterator<std::basic_string<char>*,std::vector<std::basic_string<char>%>%>' : 1,
79 """ Searches through the requested directory looking at
80 'classes_def.xml' files looking for duplicate Reflex definitions."""
82 classNameRE = re.compile (
r'class\s+name\s*=\s*"([^"]*)"')
83 spacesRE = re.compile (
r'\s+')
84 stdRE = re.compile (
r'std::')
85 srcClassNameRE = re.compile (
r'(\w+)/src/classes_def.xml')
86 ignoreSrcRE = re.compile (
r'.*/FWCore/Skeletons/scripts/mkTemplates/.+')
87 braketRE = re.compile (
r'<.+>')
88 print "Searching for 'classes_def.xml' in '%s'." % os.path.join(os.environ.get(
'CMSSW_BASE'),
'src')
90 for srcDir
in [os.environ.get(
'CMSSW_BASE'),os.environ.get(
'CMSSW_RELEASE_BASE')]:
91 if not len(srcDir):
continue
92 for xml
in commands.getoutput (
'cd '+os.path.join(srcDir,
'src')+
'; find . -name "*classes_def.xml" -print').split (
'\n'):
93 if xml
and (
not xml
in xmlFiles):
96 pprint.pprint (xmlFiles)
102 for item
in equivDict:
104 for equiv
in item[pack]:
105 explicitREs.append( (re.compile(
r'\b' + equiv +
r'\b'),pack))
107 for filename
in xmlFiles:
108 if (
not filename)
or (ignoreSrcRE.match(filename)):
continue
109 match = srcClassNameRE.search (filename)
110 if not match:
continue
111 packageName = match.group(1)
112 xmlPackages.append (packageName)
113 matchString =
r'\b' + packageName +
r'\b'
114 packagesREs[packageName] = re.compile (matchString)
115 equivList = equivREs.setdefault (packageName, [])
116 for item
in equivDict:
117 for equiv
in item.get (packageName, []):
118 matchString = re.compile(
r'\b' + equiv +
r'\b')
119 equivList.append( (matchString, equiv) )
120 equivList.append( (packagesREs[packageName], packageName) )
122 ncdict = {
'class' :
'className'}
123 for filename
in xmlFiles:
124 if (
not filename)
or (ignoreSrcRE.match(filename)):
continue
131 lostMatch = srcClassNameRE.search (filename)
133 exceptName = lostMatch.group (1)
134 regexList = equivREs[exceptName]
135 xcount = len(regexList)-1
136 if not regexList[xcount][0].search (exceptName):
137 print '%s not found in' % exceptName,
138 print regexList[xcount][0]
142 print "filename", filename
144 filepath = os.path.join(os.environ.get(
'CMSSW_BASE'),
'src',filename)
145 if not os.path.exists(filepath):
146 filepath = os.path.join(os.environ.get(
'CMSSW_RELEASE_BASE'),
'src',filename)
147 xmlObj = xml2obj (filename = filepath,
149 nameChangeDict = ncdict)
150 except Exception
as detail:
151 print "File %s is malformed XML. Please fix." % filename
155 classList = xmlObj.selection.className
158 classList = xmlObj.className
161 print "**** SKIPPING '%s' - Doesn't seem to have proper information." % filename
163 for piece
in classList:
165 className = spacesRE.sub (
'', piece.name)
170 className = stdRE.sub (
'', className)
173 for typedef, tdList
in typedefsDict.iteritems():
175 className = re.sub (alias, typedef, className)
176 classDict.setdefault (className, set()).add (filename)
178 if not options.lostDefs:
180 localObjects.append (className)
181 if options.lazyLostDefs
and not braketRE.search (className):
183 matchString =
r'\b' + className +
r'\b'
184 simpleObjectREs.append( (re.compile (matchString), className ) )
185 for className
in localObjects:
189 for equivRE
in regexList:
191 if equivRE[0].search (className):
194 for simpleRE
in simpleObjectREs:
195 if simpleRE[0].search (className):
197 if options.verbose
and simpleRE[1] != className:
198 print " Using %s to ignore %s" \
199 % (simpleRE[1], className)
201 if foundEquiv:
continue
202 for exRes
in explicitREs:
203 if exRes[0].
search(className):
204 dupProblems +=
" %s : %s\n" % (exRes[1], className)
207 if foundEquiv:
continue
208 for packageName
in xmlPackages:
211 if packagesREs[packageName].search (className):
212 dupProblems +=
" %s : %s\n" % (packageName, className)
216 print '\n%s\n%s\n' % (filename, dupProblems)
219 for name, fileSet
in sorted( classDict.iteritems() ):
220 if len (fileSet) < 2:
223 fileList = list (fileSet)
225 for filename
in fileList:
234 """ Searches the edmpluginFile to find any duplicate
236 edmpluginFile = os.path.join(os.environ.get(
'CMSSW_BASE'),
'lib',os.environ.get(
'SCRAM_ARCH'),
'.edmplugincache')
237 if len (os.environ.get(
'CMSSW_RELEASE_BASE')):
238 edmpluginFile = edmpluginFile+
' ' + os.path.join(os.environ.get(
'CMSSW_RELEASE_BASE'),
'lib',os.environ.get(
'SCRAM_ARCH'),
'.edmplugincache')
239 cmd =
"cat %s | awk '{print $2\" \"$1}' | sort | uniq | awk '{print $1}' | sort | uniq -c | grep '2 ' | awk '{print $2}'" % edmpluginFile
240 output = commands.getoutput (cmd).
split(
'\n')
242 if ignoreEdmDP.has_key(line):
continue
243 line = line.replace(
"*",
"\*")
244 cmd =
"cat %s | grep ' %s ' | awk '{print $1}' | sort | uniq " % (edmpluginFile,line)
245 out1 = commands.getoutput (cmd).
split(
'\n')
249 print " **"+plugin+
"**"
252 if __name__ ==
"__main__":
254 parser = optparse.OptionParser (
"Usage: %prog [options]\n"\
255 "Searches classes_def.xml for wrong/duplicate "\
257 xmlGroup = optparse.OptionGroup (parser,
"ClassDef XML options")
258 dumpGroup = optparse.OptionGroup (parser,
"EdmPluginDump options")
259 xmlGroup.add_option (
'--dups', dest=
'dups', action=
'store_true',
261 help=
"Search for duplicate definitions")
262 xmlGroup.add_option (
'--lostDefs', dest=
'lostDefs', action=
'store_true',
264 help=
"Looks for definitions in the wrong libraries")
265 xmlGroup.add_option (
'--lazyLostDefs', dest=
'lazyLostDefs',
268 help=
"Will try to ignore as many lost defs as reasonable")
269 xmlGroup.add_option (
'--verbose', dest=
'verbose',
272 help=
"Prints out a lot of information")
273 xmlGroup.add_option (
'--showXMLs', dest=
'showXMLs', action=
'store_true',
275 help=
"Shows all 'classes_def.xml' files")
276 xmlGroup.add_option (
'--dir', dest=
'srcdir', type=
'string', default=
'',
278 dumpGroup.add_option (
'--edmPD', dest=
'edmPD', action=
'store_true',
280 help=
"Searches EDM Plugin Dump for duplicates")
281 dumpGroup.add_option (
'--edmFile', dest=
'edmFile', type=
'string',
284 parser.add_option_group (xmlGroup)
285 parser.add_option_group (dumpGroup)
286 (options, args) = parser.parse_args()
289 if options.lazyLostDefs:
290 options.lostDefs =
True
291 if options.showXMLs
or options.lostDefs
or options.dups:
294 searchDuplicatePlugins ()
def searchDuplicatePlugins