3 from __future__
import print_function
12 from XML2Python
import xml2obj
20 'unsigned int' : [
'unsignedint',
'UInt32_t',
'uint32_t'],
21 'unsigned long': [
'unsignedlong'],
23 'float' : [
'Float_t'],
24 'double' : [
'Double_t'],
37 {
'TrajectoryState' : [
'TrajectoryStateOnSurface']},
38 {
'TrackTriggerAssociation' : [
'(TTClusterAssociationMap|TTStubAssociationMap|TTTrackAssociationMap|TrackingParticle).*Phase2TrackerDigi',
39 '(TTStub|TTCluster|TTTrack).*Phase2TrackerDigi.*TrackingParticle']},
40 {
'L1TrackTrigger' : [
'(TTStub|TTCluster|TTTrack).*Phase2TrackerDigi']},
41 {
'L1TCalorimeter' : [
'l1t::CaloTower.*']},
42 {
'GsfTracking' : [
'reco::GsfTrack(Collection|).*(MomentumConstraint|VertexConstraint)',
'Trajectory.*reco::GsfTrack']},
43 {
'ParallelAnalysis' : [
'examples::TrackAnalysisAlgorithm']},
44 {
'PatCandidates' : [
'pat::PATObject',
'pat::Lepton',
'reco::RecoCandidate',
'pat::[A-Za-z]+Ref(Vector|)',
'pat::UserHolder']},
45 {
'BTauReco' : [
'reco::.*SoftLeptonTagInfo',
'reco::SoftLeptonProperties',
'reco::SecondaryVertexTagInfo',
'reco::IPTagInfo',
'reco::TemplatedSecondaryVertexTagInfo',
'reco::CATopJetProperties',
'reco::HTTTopJetProperties']},
46 {
'CastorReco' : [
'reco::CastorJet']},
47 {
'JetMatching' : [
'reco::JetFlavourInfo',
'reco::JetFlavour',
'reco::MatchedPartons']},
48 {
'RecoCandidate' : [
'reco::Candidate',
'edm::Wrapper.+edm::AssociationMap.+TrackingParticle']},
49 {
'TrackingAnalysis' : [
'TrackingParticle']},
50 {
'Egamma' : [
'reco::ElectronID']},
51 {
'TopObjects' : [
'reco::CATopJetProperties']},
52 {
'TauReco' : [
'reco::L2TauIsolationInfo',
'reco::RecoTauPiZero',
'reco::BaseTau']},
53 {
'ValidationFormats' : [
'PGlobalDigi::.+',
'PGlobalRecHit::.+']},
54 {
'TrajectorySeed' : [
'TrajectorySeed']},
55 {
'TrackCandidate' : [
'TrackCandidate']},
56 {
'PatternTools' : [
'MomentumConstraint',
'VertexConstraint',
'Trajectory']},
57 {
'TrackerRecHit2D' : [
'SiStrip(Matched|)RecHit[12]D',
'SiTrackerGSRecHit[12]D',
'SiPixelRecHit']},
58 {
'MuonReco' : [
'reco::Muon(Ref|)(Vector|)']},
59 {
'MuonSeed' : [
'L3MuonTrajectorySeed']},
60 {
'HepMCCandidate' : [
'reco::GenParticle.*']},
61 {
'L1Trigger' : [
'l1extra::L1.+Particle']},
62 {
'TrackInfo' : [
'reco::TrackingRecHitInfo']},
63 {
'EgammaCandidates' : [
'reco::GsfElectron.*',
'reco::Photon.*']},
64 {
'HcalIsolatedTrack' : [
'reco::IsolatedPixelTrackCandidate',
'reco::EcalIsolatedParticleCandidate',
'reco::HcalIsolatedTrackCandidate']},
65 {
'HcalRecHit' : [
'HFRecHit',
'HORecHit',
'ZDCRecHit',
'HBHERecHit']},
66 {
'PFRootEvent' : [
'EventColin::']},
67 {
'CaloTowers' : [
'CaloTower.*']},
68 {
'GsfTrackReco' : [
'GsfTrack.*']},
69 {
'METReco' : [
'reco::(Calo|PF|Gen|)MET',
'reco::PFClusterMET']},
70 {
'ParticleFlowReco' : [
'reco::RecoPFClusterRefCandidateRef.*']},
71 {
'ParticleFlowCandidate' : [
'reco::PFCandidateRef',
'reco::PFCandidateFwdRef',
'reco::PFCandidate']},
72 {
'PhysicsToolsObjects' : [
'PhysicsTools::Calibration']},
73 {
'TrackReco' : [
'reco::Track',
'reco::TrackRef']},
74 {
'VertexReco' : [
'reco::Vertex']},
75 {
'TFWLiteSelectorTest' : [
'tfwliteselectortest']},
76 {
'TauReco' : [
'reco::PFJetRef']},
77 {
'JetReco' : [
'reco::.*Jet',
'reco::.*Jet(Collection|Ref)']},
78 {
'HGCDigi' : [
'HGCSample']},
79 {
'SiPixelObjects' : [
'SiPixelQuality.*']},
83 'LCGReflex/__gnu_cxx::__normal_iterator<std::basic_string<char>*,std::vector<std::basic_string<char>%>%>' : 1,
88 """ Searches through the requested directory looking at 89 'classes_def.xml' files looking for duplicate Reflex definitions.""" 91 classNameRE = re.compile (
r'class\s+name\s*=\s*"([^"]*)"')
92 spacesRE = re.compile (
r'\s+')
93 stdRE = re.compile (
r'std::')
94 srcClassNameRE = re.compile (
r'(\w+)/src/classes_def.*[.]xml')
95 ignoreSrcRE = re.compile (
r'.*/FWCore/Skeletons/scripts/mkTemplates/.+')
96 braketRE = re.compile (
r'<.+>')
97 print(
"Searching for 'classes_def.xml' in '%s'." % os.path.join(os.environ.get(
'CMSSW_BASE'),
'src'))
99 for srcDir
in [os.environ.get(
'CMSSW_BASE'),os.environ.get(
'CMSSW_RELEASE_BASE')]:
100 if not len(srcDir):
continue 101 for xml
in commands.getoutput (
'cd '+os.path.join(srcDir,
'src')+
'; find . -name "*classes_def*.xml" -follow -print').split (
'\n'):
102 if xml
and (
not xml
in xmlFiles):
105 pprint.pprint (xmlFiles)
111 for item
in equivDict:
113 for equiv
in item[pack]:
114 explicitREs.append( (re.compile(
r'\b' + equiv +
r'\b'),pack))
116 for filename
in xmlFiles:
117 if (
not filename)
or (ignoreSrcRE.match(filename)):
continue 118 match = srcClassNameRE.search (filename)
119 if not match:
continue 120 packageName = match.group(1)
121 xmlPackages.append (packageName)
122 matchString =
r'\b' + packageName +
r'\b' 123 packagesREs[packageName] = re.compile (matchString)
124 equivList = equivREs.setdefault (packageName, [])
125 for item
in equivDict:
126 for equiv
in item.get (packageName, []):
127 matchString = re.compile(
r'\b' + equiv +
r'\b')
128 equivList.append( (matchString, equiv) )
129 equivList.append( (packagesREs[packageName], packageName) )
131 ncdict = {
'class' :
'className',
'function' :
'functionName'}
132 for filename
in xmlFiles:
133 if (
not filename)
or (ignoreSrcRE.match(filename)):
continue 140 lostMatch = srcClassNameRE.search (filename)
142 exceptName = lostMatch.group (1)
143 regexList = equivREs[exceptName]
144 xcount = len(regexList)-1
145 if not regexList[xcount][0].search (exceptName):
146 print(
'%s not found in' % exceptName, end=
' ')
147 print(regexList[xcount][0])
151 print(
"filename", filename)
153 filepath = os.path.join(os.environ.get(
'CMSSW_BASE'),
'src',filename)
154 if not os.path.exists(filepath):
155 filepath = os.path.join(os.environ.get(
'CMSSW_RELEASE_BASE'),
'src',filename)
156 xmlObj = xml2obj (filename = filepath,
158 nameChangeDict = ncdict)
159 except Exception
as detail:
160 print(
"File %s is malformed XML. Please fix." % filename)
164 classList = xmlObj.selection.className
167 classList = xmlObj.className
170 print(
"**** SKIPPING '%s' - Doesn't seem to have proper information." % filename)
173 classList = xmlObj.functionName
175 print(
"**** SKIPPING '%s' - Dosen't seem to have proper information(not class/function)." % filename)
177 for piece
in classList:
179 className = spacesRE.sub (
'', piece.name)
184 className = stdRE.sub (
'', className)
187 for typedef, tdList
in six.iteritems(typedefsDict):
189 className = re.sub (alias, typedef, className)
190 classDict.setdefault (className, set()).add (filename)
192 if not options.lostDefs:
194 localObjects.append (className)
195 if options.lazyLostDefs
and not braketRE.search (className):
197 matchString =
r'\b' + className +
r'\b' 198 simpleObjectREs.append( (re.compile (matchString), className ) )
199 for className
in localObjects:
203 for equivRE
in regexList:
205 if equivRE[0].search (className):
208 for simpleRE
in simpleObjectREs:
209 if simpleRE[0].search (className):
211 if options.verbose
and simpleRE[1] != className:
212 print(
" Using %s to ignore %s" \
213 % (simpleRE[1], className))
215 if foundEquiv:
continue 216 for exRes
in explicitREs:
217 if exRes[0].
search(className):
218 dupProblems +=
" %s : %s\n" % (exRes[1], className)
221 if foundEquiv:
continue 222 for packageName
in xmlPackages:
225 if packagesREs[packageName].search (className):
226 dupProblems +=
" %s : %s\n" % (packageName, className)
230 print(
'\n%s\n%s\n' % (filename, dupProblems))
233 for name, fileSet
in sorted( six.iteritems(classDict) ):
234 if len (fileSet) < 2:
237 fileList = sorted (fileSet)
238 for filename
in fileList:
247 """ Searches the edmpluginFile to find any duplicate 250 libenv =
'LD_LIBRARY_PATH' 251 if os.environ.get(
'SCRAM_ARCH').startswith(
'osx'): libenv =
'DYLD_FALLBACK_LIBRARY_PATH' 252 biglib =
'/biglib/'+os.environ.get(
'SCRAM_ARCH')
253 for libdir
in os.environ.get(libenv).
split(
':'):
254 if libdir.endswith(biglib):
continue 255 if os.path.exists(libdir+
'/.edmplugincache'): edmpluginFile = edmpluginFile +
' ' + libdir+
'/.edmplugincache' 256 if edmpluginFile ==
'': edmpluginFile = os.path.join(os.environ.get(
'CMSSW_BASE'),
'lib',os.environ.get(
'SCRAM_ARCH'),
'.edmplugincache')
257 cmd =
"cat %s | awk '{print $2\" \"$1}' | sort | uniq | awk '{print $1}' | sort | uniq -c | grep '2 ' | awk '{print $2}'" % edmpluginFile
258 output = commands.getoutput (cmd).
split(
'\n')
260 if line
in ignoreEdmDP:
continue 261 line = line.replace(
"*",
"\*")
262 cmd =
"cat %s | grep ' %s ' | awk '{print $1}' | sort | uniq " % (edmpluginFile,line)
263 out1 = commands.getoutput (cmd).
split(
'\n')
267 print(
" **"+plugin+
"**")
270 if __name__ ==
"__main__":
272 parser = optparse.OptionParser (
"Usage: %prog [options]\n"\
273 "Searches classes_def.xml for wrong/duplicate "\
275 xmlGroup = optparse.OptionGroup (parser,
"ClassDef XML options")
276 dumpGroup = optparse.OptionGroup (parser,
"EdmPluginDump options")
277 xmlGroup.add_option (
'--dups', dest=
'dups', action=
'store_true',
279 help=
"Search for duplicate definitions")
280 xmlGroup.add_option (
'--lostDefs', dest=
'lostDefs', action=
'store_true',
282 help=
"Looks for definitions in the wrong libraries")
283 xmlGroup.add_option (
'--lazyLostDefs', dest=
'lazyLostDefs',
286 help=
"Will try to ignore as many lost defs as reasonable")
287 xmlGroup.add_option (
'--verbose', dest=
'verbose',
290 help=
"Prints out a lot of information")
291 xmlGroup.add_option (
'--showXMLs', dest=
'showXMLs', action=
'store_true',
293 help=
"Shows all 'classes_def.xml' files")
294 xmlGroup.add_option (
'--dir', dest=
'srcdir', type=
'string', default=
'',
296 dumpGroup.add_option (
'--edmPD', dest=
'edmPD', action=
'store_true',
298 help=
"Searches EDM Plugin Dump for duplicates")
299 dumpGroup.add_option (
'--edmFile', dest=
'edmFile', type=
'string',
302 parser.add_option_group (xmlGroup)
303 parser.add_option_group (dumpGroup)
304 (options, args) = parser.parse_args()
307 if options.lazyLostDefs:
308 options.lostDefs =
True 309 if options.showXMLs
or options.lostDefs
or options.dups:
312 searchDuplicatePlugins ()
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
S & print(S &os, JobReport::InputFile const &f)
def searchDuplicatePlugins()