3 from __future__
import print_function
10 from XML2Python
import xml2obj
11 from subprocess
import getoutput
17 'unsigned int' : [
'unsignedint',
'UInt32_t',
'uint32_t'],
18 'unsigned long': [
'unsignedlong'],
20 'float' : [
'Float_t'],
21 'double' : [
'Double_t'],
34 {
'SelectorUtils': [
'VersionedSelector']},
35 {
'Associations': [
'TTTrackTruthPair',
'edm::Wrapper.+edm::AssociationMap.+TrackingParticle']},
36 {
'TrajectoryState' : [
'TrajectoryStateOnSurface']},
37 {
'TrackTriggerAssociation' : [
'(TTClusterAssociationMap|TTStubAssociationMap|TTTrackAssociationMap|TrackingParticle).*Phase2TrackerDigi',
38 '(TTStub|TTCluster|TTTrack).*Phase2TrackerDigi.*TrackingParticle']},
39 {
'L1TrackTrigger' : [
'(TTStub|TTCluster|TTTrack).*Phase2TrackerDigi']},
40 {
'L1TCalorimeterPhase2' : [
'l1tp2::CaloTower.*']},
41 {
'L1TCalorimeter' : [
'l1t::CaloTower.*']},
42 {
'VertexFinder' : [
'l1tVertexFinder::Vertex']},
43 {
'GsfTracking' : [
'reco::GsfTrack(Collection|).*(MomentumConstraint|VertexConstraint)',
'Trajectory.*reco::GsfTrack']},
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']},
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',
'l1t::Vertex']},
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 {
'HGCRecHit' : [
'constHGCRecHit',
'HGCRecHit']},
80 {
'SiPixelObjects' : [
'SiPixelQuality.*']},
84 'LCGReflex/__gnu_cxx::__normal_iterator<std::basic_string<char>*,std::vector<std::basic_string<char>%>%>' : 1,
89 """ Searches through the requested directory looking at 90 'classes_def.xml' files looking for duplicate Reflex definitions.""" 92 classNameRE = re.compile (
r'class\s+name\s*=\s*"([^"]*)"')
93 spacesRE = re.compile (
r'\s+')
94 stdRE = re.compile (
r'std::')
95 srcClassNameRE = re.compile (
r'(\w+)/src/classes_def.*[.]xml')
96 ignoreSrcRE = re.compile (
r'.*/FWCore/Skeletons/scripts/mkTemplates/.+')
97 braketRE = re.compile (
r'<.+>')
98 print(
"Searching for 'classes_def.xml' in '%s'." % os.path.join(os.environ.get(
'CMSSW_BASE'),
'src'))
100 for srcDir
in [os.environ.get(
'CMSSW_BASE'),os.environ.get(
'CMSSW_RELEASE_BASE')]:
101 if not len(srcDir):
continue 102 for xml
in getoutput (
'cd '+os.path.join(srcDir,
'src')+
'; find . -name "*classes_def*.xml" -follow -print').split (
'\n'):
103 if xml
and (
not xml
in xmlFiles):
106 pprint.pprint (xmlFiles)
112 for item
in equivDict:
114 for equiv
in item[pack]:
115 explicitREs.append( (re.compile(
r'\b' + equiv +
r'\b'),pack))
117 for filename
in xmlFiles:
118 if (
not filename)
or (ignoreSrcRE.match(filename)):
continue 119 match = srcClassNameRE.search (filename)
120 if not match:
continue 121 packageName = match.group(1)
122 xmlPackages.append (packageName)
123 matchString =
r'\b' + packageName +
r'\b' 124 packagesREs[packageName] = re.compile (matchString)
125 equivList = equivREs.setdefault (packageName, [])
126 for item
in equivDict:
127 for equiv
in item.get (packageName, []):
128 matchString = re.compile(
r'\b' + equiv +
r'\b')
129 equivList.append( (matchString, equiv) )
130 equivList.append( (packagesREs[packageName], packageName) )
132 ncdict = {
'class' :
'className',
'function' :
'functionName'}
133 for filename
in xmlFiles:
134 if (
not filename)
or (ignoreSrcRE.match(filename)):
continue 141 lostMatch = srcClassNameRE.search (filename)
143 exceptName = lostMatch.group (1)
144 regexList = equivREs[exceptName]
145 xcount = len(regexList)-1
146 if not regexList[xcount][0].search (exceptName):
147 print(
'%s not found in' % exceptName, end=
' ')
148 print(regexList[xcount][0])
152 print(
"filename", filename)
154 filepath = os.path.join(os.environ.get(
'CMSSW_BASE'),
'src',filename)
155 if not os.path.exists(filepath):
156 filepath = os.path.join(os.environ.get(
'CMSSW_RELEASE_BASE'),
'src',filename)
157 xmlObj = xml2obj (filename = filepath,
159 nameChangeDict = ncdict)
160 except Exception
as detail:
161 print(
"File %s is malformed XML. Please fix." % filename)
165 classList = xmlObj.selection.className
168 classList = xmlObj.className
171 print(
"**** SKIPPING '%s' - Doesn't seem to have proper information." % filename)
174 classList = xmlObj.functionName
176 print(
"**** SKIPPING '%s' - Dosen't seem to have proper information(not class/function)." % filename)
178 for piece
in classList:
180 className = spacesRE.sub (
'', piece.name)
185 className = stdRE.sub (
'', className)
188 for typedef, tdList
in typedefsDict.items():
190 className = re.sub (alias, typedef, className)
191 classDict.setdefault (className, set()).add (filename)
193 if not options.lostDefs:
195 localObjects.append (className)
196 if options.lazyLostDefs
and not braketRE.search (className):
198 matchString =
r'\b' + className +
r'\b' 199 simpleObjectREs.append( (re.compile (matchString), className ) )
200 for className
in localObjects:
204 for equivRE
in regexList:
206 if equivRE[0].search (className):
209 for simpleRE
in simpleObjectREs:
210 if simpleRE[0].search (className):
212 if options.verbose
and simpleRE[1] != className:
213 print(
" Using %s to ignore %s" \
214 % (simpleRE[1], className))
216 if foundEquiv:
continue 217 for exRes
in explicitREs:
218 if exRes[0].
search(className):
219 dupProblems +=
" %s : %s\n" % (exRes[1], className)
222 if foundEquiv:
continue 223 for packageName
in xmlPackages:
226 if packagesREs[packageName].search (className):
227 dupProblems +=
" %s : %s\n" % (packageName, className)
231 print(
'\n%s\n%s\n' % (filename, dupProblems))
234 for name, fileSet
in sorted( classDict.items() ):
235 if len (fileSet) < 2:
238 fileList = sorted (fileSet)
239 for filename
in fileList:
248 """ Searches the edmpluginFile to find any duplicate 251 libenv =
'LD_LIBRARY_PATH' 252 if os.environ.get(
'SCRAM_ARCH').startswith(
'osx'): libenv =
'DYLD_FALLBACK_LIBRARY_PATH' 253 biglib =
'/biglib/'+os.environ.get(
'SCRAM_ARCH')
254 for libdir
in os.environ.get(libenv).
split(
':'):
255 if libdir.endswith(biglib):
continue 256 if os.path.exists(libdir+
'/.edmplugincache'): edmpluginFile = edmpluginFile +
' ' + libdir+
'/.edmplugincache' 257 if edmpluginFile ==
'': edmpluginFile = os.path.join(os.environ.get(
'CMSSW_BASE'),
'lib',os.environ.get(
'SCRAM_ARCH'),
'.edmplugincache')
258 cmd =
"cat %s | awk '{print $2\" \"$1}' | sort | uniq | awk '{print $1}' | sort | uniq -c | grep '2 ' | awk '{print $2}'" % edmpluginFile
259 output = getoutput (cmd).
split(
'\n')
261 if line
in ignoreEdmDP:
continue 262 line = line.replace(
"*",
"\*")
263 cmd =
"cat %s | grep ' %s ' | awk '{print $1}' | sort | uniq " % (edmpluginFile,line)
264 out1 = getoutput (cmd).
split(
'\n')
268 print(
" **"+plugin+
"**")
271 if __name__ ==
"__main__":
273 parser = optparse.OptionParser (
"Usage: %prog [options]\n"\
274 "Searches classes_def.xml for wrong/duplicate "\
276 xmlGroup = optparse.OptionGroup (parser,
"ClassDef XML options")
277 dumpGroup = optparse.OptionGroup (parser,
"EdmPluginDump options")
278 xmlGroup.add_option (
'--dups', dest=
'dups', action=
'store_true',
280 help=
"Search for duplicate definitions")
281 xmlGroup.add_option (
'--lostDefs', dest=
'lostDefs', action=
'store_true',
283 help=
"Looks for definitions in the wrong libraries")
284 xmlGroup.add_option (
'--lazyLostDefs', dest=
'lazyLostDefs',
287 help=
"Will try to ignore as many lost defs as reasonable")
288 xmlGroup.add_option (
'--verbose', dest=
'verbose',
291 help=
"Prints out a lot of information")
292 xmlGroup.add_option (
'--showXMLs', dest=
'showXMLs', action=
'store_true',
294 help=
"Shows all 'classes_def.xml' files")
295 xmlGroup.add_option (
'--dir', dest=
'srcdir', type=
'string', default=
'',
297 dumpGroup.add_option (
'--edmPD', dest=
'edmPD', action=
'store_true',
299 help=
"Searches EDM Plugin Dump for duplicates")
300 dumpGroup.add_option (
'--edmFile', dest=
'edmFile', type=
'string',
303 parser.add_option_group (xmlGroup)
304 parser.add_option_group (dumpGroup)
305 (options, args) = parser.parse_args()
308 if options.lazyLostDefs:
309 options.lostDefs =
True 310 if options.showXMLs
or options.lostDefs
or options.dups:
313 searchDuplicatePlugins ()
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def split(sequence, size)
def searchDuplicatePlugins()