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).*Phase2TrackerDigi',
39 '(TTStub|TTCluster|TTTrack).*Phase2TrackerDigi']},
40 {
'L1TCalorimeter' : [
'l1t::CaloTower.*']},
41 {
'GsfTracking' : [
'reco::GsfTrack(Collection|).*(MomentumConstraint|VertexConstraint)',
'Trajectory.*reco::GsfTrack']},
42 {
'ParallelAnalysis' : [
'examples::TrackAnalysisAlgorithm']},
43 {
'PatCandidates' : [
'pat::PATObject',
'pat::Lepton']},
44 {
'BTauReco' : [
'reco::.*SoftLeptonTagInfo',
'reco::SoftLeptonProperties',
'reco::SecondaryVertexTagInfo',
'reco::IPTagInfo',
'reco::TemplatedSecondaryVertexTagInfo',
'reco::CATopJetProperties',
'reco::HTTTopJetProperties']},
45 {
'CastorReco' : [
'reco::CastorJet']},
46 {
'JetMatching' : [
'reco::JetFlavourInfo',
'reco::JetFlavour',
'reco::MatchedPartons']},
47 {
'TrackingAnalysis' : [
'TrackingParticle']},
48 {
'Egamma' : [
'reco::ElectronID']},
49 {
'TopObjects' : [
'reco::CATopJetProperties']},
50 {
'TauReco' : [
'reco::L2TauIsolationInfo',
'reco::RecoTauPiZero',
'reco::BaseTau']},
51 {
'ValidationFormats' : [
'PGlobalDigi::.+',
'PGlobalRecHit::.+']},
52 {
'TrajectorySeed' : [
'TrajectorySeed']},
53 {
'TrackCandidate' : [
'TrackCandidate']},
54 {
'PatternTools' : [
'MomentumConstraint',
'VertexConstraint',
'Trajectory']},
55 {
'TrackerRecHit2D' : [
'SiStrip(Matched|)RecHit[12]D',
'SiTrackerGSRecHit[12]D',
'SiPixelRecHit']},
56 {
'MuonReco' : [
'reco::Muon(Ref|)(Vector|)']},
57 {
'MuonSeed' : [
'L3MuonTrajectorySeed']},
58 {
'HepMCCandidate' : [
'reco::GenParticle.*']},
59 {
'L1Trigger' : [
'l1extra::L1.+Particle']},
60 {
'TrackInfo' : [
'reco::TrackingRecHitInfo']},
61 {
'EgammaCandidates' : [
'reco::GsfElectron.*',
'reco::Photon.*']},
62 {
'HcalIsolatedTrack' : [
'reco::IsolatedPixelTrackCandidate',
'reco::EcalIsolatedParticleCandidate',
'reco::HcalIsolatedTrackCandidate']},
63 {
'HcalRecHit' : [
'HFRecHit',
'HORecHit',
'ZDCRecHit',
'HBHERecHit']},
64 {
'PFRootEvent' : [
'EventColin::']},
65 {
'CaloTowers' : [
'CaloTower.*']},
66 {
'GsfTrackReco' : [
'GsfTrack.*']},
67 {
'METReco' : [
'reco::(Calo|PF|Gen|)MET',
'reco::PFClusterMET']},
68 {
'ParticleFlowReco' : [
'reco::RecoPFClusterRefCandidateRef.*']},
69 {
'ParticleFlowCandidate' : [
'reco::PFCandidateRef',
'reco::PFCandidateFwdRef',
'reco::PFCandidate']},
70 {
'PhysicsToolsObjects' : [
'PhysicsTools::Calibration']},
71 {
'RecoCandidate' : [
'reco::Candidate']},
72 {
'TrackReco' : [
'reco::Track',
'reco::TrackRef']},
73 {
'VertexReco' : [
'reco::Vertex']},
74 {
'TFWLiteSelectorTest' : [
'tfwliteselectortest']},
75 {
'PatCandidates' : [
'reco::RecoCandidate',
'pat::[A-Za-z]+Ref(Vector|)']},
76 {
'TauReco' : [
'reco::PFJetRef']},
77 {
'JetReco' : [
'reco::.*Jet',
'reco::.*Jet(Collection|Ref)']},
78 {
'HGCDigi' : [
'HGCSample']},
82 'LCGReflex/__gnu_cxx::__normal_iterator<std::basic_string<char>*,std::vector<std::basic_string<char>%>%>' : 1,
87 """ Searches through the requested directory looking at 88 'classes_def.xml' files looking for duplicate Reflex definitions.""" 90 classNameRE = re.compile (
r'class\s+name\s*=\s*"([^"]*)"')
91 spacesRE = re.compile (
r'\s+')
92 stdRE = re.compile (
r'std::')
93 srcClassNameRE = re.compile (
r'(\w+)/src/classes_def.*[.]xml')
94 ignoreSrcRE = re.compile (
r'.*/FWCore/Skeletons/scripts/mkTemplates/.+')
95 braketRE = re.compile (
r'<.+>')
96 print(
"Searching for 'classes_def.xml' in '%s'." % os.path.join(os.environ.get(
'CMSSW_BASE'),
'src'))
98 for srcDir
in [os.environ.get(
'CMSSW_BASE'),os.environ.get(
'CMSSW_RELEASE_BASE')]:
99 if not len(srcDir):
continue 100 for xml
in commands.getoutput (
'cd '+os.path.join(srcDir,
'src')+
'; find . -name "*classes_def*.xml" -follow -print').split (
'\n'):
101 if xml
and (
not xml
in xmlFiles):
104 pprint.pprint (xmlFiles)
110 for item
in equivDict:
112 for equiv
in item[pack]:
113 explicitREs.append( (re.compile(
r'\b' + equiv +
r'\b'),pack))
115 for filename
in xmlFiles:
116 if (
not filename)
or (ignoreSrcRE.match(filename)):
continue 117 match = srcClassNameRE.search (filename)
118 if not match:
continue 119 packageName = match.group(1)
120 xmlPackages.append (packageName)
121 matchString =
r'\b' + packageName +
r'\b' 122 packagesREs[packageName] = re.compile (matchString)
123 equivList = equivREs.setdefault (packageName, [])
124 for item
in equivDict:
125 for equiv
in item.get (packageName, []):
126 matchString = re.compile(
r'\b' + equiv +
r'\b')
127 equivList.append( (matchString, equiv) )
128 equivList.append( (packagesREs[packageName], packageName) )
130 ncdict = {
'class' :
'className',
'function' :
'functionName'}
131 for filename
in xmlFiles:
132 if (
not filename)
or (ignoreSrcRE.match(filename)):
continue 139 lostMatch = srcClassNameRE.search (filename)
141 exceptName = lostMatch.group (1)
142 regexList = equivREs[exceptName]
143 xcount = len(regexList)-1
144 if not regexList[xcount][0].search (exceptName):
145 print(
'%s not found in' % exceptName, end=
' ')
146 print(regexList[xcount][0])
150 print(
"filename", filename)
152 filepath = os.path.join(os.environ.get(
'CMSSW_BASE'),
'src',filename)
153 if not os.path.exists(filepath):
154 filepath = os.path.join(os.environ.get(
'CMSSW_RELEASE_BASE'),
'src',filename)
155 xmlObj = xml2obj (filename = filepath,
157 nameChangeDict = ncdict)
158 except Exception
as detail:
159 print(
"File %s is malformed XML. Please fix." % filename)
163 classList = xmlObj.selection.className
166 classList = xmlObj.className
169 print(
"**** SKIPPING '%s' - Doesn't seem to have proper information." % filename)
172 classList = xmlObj.functionName
174 print(
"**** SKIPPING '%s' - Dosen't seem to have proper information(not class/function)." % filename)
176 for piece
in classList:
178 className = spacesRE.sub (
'', piece.name)
183 className = stdRE.sub (
'', className)
186 for typedef, tdList
in six.iteritems(typedefsDict):
188 className = re.sub (alias, typedef, className)
189 classDict.setdefault (className, set()).add (filename)
191 if not options.lostDefs:
193 localObjects.append (className)
194 if options.lazyLostDefs
and not braketRE.search (className):
196 matchString =
r'\b' + className +
r'\b' 197 simpleObjectREs.append( (re.compile (matchString), className ) )
198 for className
in localObjects:
202 for equivRE
in regexList:
204 if equivRE[0].search (className):
207 for simpleRE
in simpleObjectREs:
208 if simpleRE[0].search (className):
210 if options.verbose
and simpleRE[1] != className:
211 print(
" Using %s to ignore %s" \
212 % (simpleRE[1], className))
214 if foundEquiv:
continue 215 for exRes
in explicitREs:
216 if exRes[0].
search(className):
217 dupProblems +=
" %s : %s\n" % (exRes[1], className)
220 if foundEquiv:
continue 221 for packageName
in xmlPackages:
224 if packagesREs[packageName].search (className):
225 dupProblems +=
" %s : %s\n" % (packageName, className)
229 print(
'\n%s\n%s\n' % (filename, dupProblems))
232 for name, fileSet
in sorted( six.iteritems(classDict) ):
233 if len (fileSet) < 2:
236 fileList = sorted (fileSet)
237 for filename
in fileList:
246 """ Searches the edmpluginFile to find any duplicate 249 libenv =
'LD_LIBRARY_PATH' 250 if os.environ.get(
'SCRAM_ARCH').startswith(
'osx'): libenv =
'DYLD_FALLBACK_LIBRARY_PATH' 251 biglib =
'/biglib/'+os.environ.get(
'SCRAM_ARCH')
252 for libdir
in os.environ.get(libenv).
split(
':'):
253 if libdir.endswith(biglib):
continue 254 if os.path.exists(libdir+
'/.edmplugincache'): edmpluginFile = edmpluginFile +
' ' + libdir+
'/.edmplugincache' 255 if edmpluginFile ==
'': edmpluginFile = os.path.join(os.environ.get(
'CMSSW_BASE'),
'lib',os.environ.get(
'SCRAM_ARCH'),
'.edmplugincache')
256 cmd =
"cat %s | awk '{print $2\" \"$1}' | sort | uniq | awk '{print $1}' | sort | uniq -c | grep '2 ' | awk '{print $2}'" % edmpluginFile
257 output = commands.getoutput (cmd).
split(
'\n')
259 if line
in ignoreEdmDP:
continue 260 line = line.replace(
"*",
"\*")
261 cmd =
"cat %s | grep ' %s ' | awk '{print $1}' | sort | uniq " % (edmpluginFile,line)
262 out1 = commands.getoutput (cmd).
split(
'\n')
266 print(
" **"+plugin+
"**")
269 if __name__ ==
"__main__":
271 parser = optparse.OptionParser (
"Usage: %prog [options]\n"\
272 "Searches classes_def.xml for wrong/duplicate "\
274 xmlGroup = optparse.OptionGroup (parser,
"ClassDef XML options")
275 dumpGroup = optparse.OptionGroup (parser,
"EdmPluginDump options")
276 xmlGroup.add_option (
'--dups', dest=
'dups', action=
'store_true',
278 help=
"Search for duplicate definitions")
279 xmlGroup.add_option (
'--lostDefs', dest=
'lostDefs', action=
'store_true',
281 help=
"Looks for definitions in the wrong libraries")
282 xmlGroup.add_option (
'--lazyLostDefs', dest=
'lazyLostDefs',
285 help=
"Will try to ignore as many lost defs as reasonable")
286 xmlGroup.add_option (
'--verbose', dest=
'verbose',
289 help=
"Prints out a lot of information")
290 xmlGroup.add_option (
'--showXMLs', dest=
'showXMLs', action=
'store_true',
292 help=
"Shows all 'classes_def.xml' files")
293 xmlGroup.add_option (
'--dir', dest=
'srcdir', type=
'string', default=
'',
295 dumpGroup.add_option (
'--edmPD', dest=
'edmPD', action=
'store_true',
297 help=
"Searches EDM Plugin Dump for duplicates")
298 dumpGroup.add_option (
'--edmFile', dest=
'edmFile', type=
'string',
301 parser.add_option_group (xmlGroup)
302 parser.add_option_group (dumpGroup)
303 (options, args) = parser.parse_args()
306 if options.lazyLostDefs:
307 options.lostDefs =
True 308 if options.showXMLs
or options.lostDefs
or options.dups:
311 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()