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 {
'TrackTriggerAssociation' : [
'TTClusterAssociationMap',
'TTStubAssociationMap',
'(TTStub|TTCluster).*edm::refhelper::FindForDetSetVector.*Phase2TrackerDigi.*']},
36 {
'L1TCalorimeter' : [
'l1t::CaloTower.*']},
37 {
'GsfTracking' : [
'reco::GsfTrack(Collection|).*(MomentumConstraint|VertexConstraint)',
'Trajectory.*reco::GsfTrack']},
38 {
'ParallelAnalysis' : [
'examples::TrackAnalysisAlgorithm']},
39 {
'PatCandidates' : [
'pat::PATObject',
'pat::Lepton']},
40 {
'BTauReco' : [
'reco::.*SoftLeptonTagInfo',
'reco::SoftLeptonProperties',
'reco::SecondaryVertexTagInfo',
'reco::IPTagInfo',
'reco::TemplatedSecondaryVertexTagInfo',
'reco::CATopJetProperties',
'reco::HTTTopJetProperties']},
41 {
'CastorReco' : [
'reco::CastorJet']},
42 {
'JetMatching' : [
'reco::JetFlavourInfo',
'reco::JetFlavour',
'reco::MatchedPartons']},
43 {
'TrackingAnalysis' : [
'TrackingParticle']},
44 {
'Egamma' : [
'reco::ElectronID']},
45 {
'TopObjects' : [
'reco::CATopJetProperties']},
46 {
'TauReco' : [
'reco::L2TauIsolationInfo',
'reco::RecoTauPiZero',
'reco::BaseTau']},
47 {
'ValidationFormats' : [
'PGlobalDigi::.+',
'PGlobalRecHit::.+']},
48 {
'TrajectorySeed' : [
'TrajectorySeed']},
49 {
'TrackCandidate' : [
'TrackCandidate']},
50 {
'PatternTools' : [
'MomentumConstraint',
'VertexConstraint',
'Trajectory']},
51 {
'TrackerRecHit2D' : [
'SiStrip(Matched|)RecHit[12]D',
'SiTrackerGSRecHit[12]D',
'SiPixelRecHit']},
52 {
'MuonReco' : [
'reco::Muon(Ref|)(Vector|)']},
53 {
'MuonSeed' : [
'L3MuonTrajectorySeed']},
54 {
'HepMCCandidate' : [
'reco::GenParticle.*']},
55 {
'L1Trigger' : [
'l1extra::L1.+Particle']},
56 {
'TrackInfo' : [
'reco::TrackingRecHitInfo']},
57 {
'EgammaCandidates' : [
'reco::GsfElectron.*',
'reco::Photon.*']},
58 {
'HcalIsolatedTrack' : [
'reco::IsolatedPixelTrackCandidate',
'reco::EcalIsolatedParticleCandidate',
'reco::HcalIsolatedTrackCandidate']},
59 {
'HcalRecHit' : [
'HFRecHit',
'HORecHit',
'ZDCRecHit',
'HBHERecHit']},
60 {
'PFRootEvent' : [
'EventColin::']},
61 {
'CaloTowers' : [
'CaloTower.*']},
62 {
'GsfTrackReco' : [
'GsfTrack.*']},
63 {
'METReco' : [
'reco::(Calo|PF|Gen|)MET',
'reco::PFClusterMET']},
64 {
'ParticleFlowReco' : [
'reco::RecoPFClusterRefCandidateRef.*']},
65 {
'ParticleFlowCandidate' : [
'reco::PFCandidateRef',
'reco::PFCandidateFwdRef',
'reco::PFCandidate']},
66 {
'PhysicsToolsObjects' : [
'PhysicsTools::Calibration']},
67 {
'RecoCandidate' : [
'reco::Candidate']},
68 {
'TrackReco' : [
'reco::Track',
'reco::TrackRef']},
69 {
'VertexReco' : [
'reco::Vertex']},
70 {
'TFWLiteSelectorTest' : [
'tfwliteselectortest']},
71 {
'PatCandidates' : [
'reco::RecoCandidate',
'pat::[A-Za-z]+Ref(Vector|)']},
72 {
'JetReco' : [
'reco::.*Jet',
'reco::.*Jet(Collection|Ref)']},
73 {
'HGCDigi' : [
'HGCSample']},
77 'LCGReflex/__gnu_cxx::__normal_iterator<std::basic_string<char>*,std::vector<std::basic_string<char>%>%>' : 1,
82 """ Searches through the requested directory looking at
83 'classes_def.xml' files looking for duplicate Reflex definitions."""
85 classNameRE = re.compile (
r'class\s+name\s*=\s*"([^"]*)"')
86 spacesRE = re.compile (
r'\s+')
87 stdRE = re.compile (
r'std::')
88 srcClassNameRE = re.compile (
r'(\w+)/src/classes_def.xml')
89 ignoreSrcRE = re.compile (
r'.*/FWCore/Skeletons/scripts/mkTemplates/.+')
90 braketRE = re.compile (
r'<.+>')
91 print "Searching for 'classes_def.xml' in '%s'." % os.path.join(os.environ.get(
'CMSSW_BASE'),
'src')
93 for srcDir
in [os.environ.get(
'CMSSW_BASE'),os.environ.get(
'CMSSW_RELEASE_BASE')]:
94 if not len(srcDir):
continue
95 for xml
in commands.getoutput (
'cd '+os.path.join(srcDir,
'src')+
'; find . -name "*classes_def.xml" -follow -print').split (
'\n'):
96 if xml
and (
not xml
in xmlFiles):
99 pprint.pprint (xmlFiles)
105 for item
in equivDict:
107 for equiv
in item[pack]:
108 explicitREs.append( (re.compile(
r'\b' + equiv +
r'\b'),pack))
110 for filename
in xmlFiles:
111 if (
not filename)
or (ignoreSrcRE.match(filename)):
continue
112 match = srcClassNameRE.search (filename)
113 if not match:
continue
114 packageName = match.group(1)
115 xmlPackages.append (packageName)
116 matchString =
r'\b' + packageName +
r'\b'
117 packagesREs[packageName] = re.compile (matchString)
118 equivList = equivREs.setdefault (packageName, [])
119 for item
in equivDict:
120 for equiv
in item.get (packageName, []):
121 matchString = re.compile(
r'\b' + equiv +
r'\b')
122 equivList.append( (matchString, equiv) )
123 equivList.append( (packagesREs[packageName], packageName) )
125 ncdict = {
'class' :
'className',
'function' :
'functionName'}
126 for filename
in xmlFiles:
127 if (
not filename)
or (ignoreSrcRE.match(filename)):
continue
134 lostMatch = srcClassNameRE.search (filename)
136 exceptName = lostMatch.group (1)
137 regexList = equivREs[exceptName]
138 xcount = len(regexList)-1
139 if not regexList[xcount][0].search (exceptName):
140 print '%s not found in' % exceptName,
141 print regexList[xcount][0]
145 print "filename", filename
147 filepath = os.path.join(os.environ.get(
'CMSSW_BASE'),
'src',filename)
148 if not os.path.exists(filepath):
149 filepath = os.path.join(os.environ.get(
'CMSSW_RELEASE_BASE'),
'src',filename)
150 xmlObj = xml2obj (filename = filepath,
152 nameChangeDict = ncdict)
153 except Exception
as detail:
154 print "File %s is malformed XML. Please fix." % filename
158 classList = xmlObj.selection.className
161 classList = xmlObj.className
164 print "**** SKIPPING '%s' - Doesn't seem to have proper information." % filename
167 classList = xmlObj.functionName
169 print "**** SKIPPING '%s' - Dosen't seem to have proper information(not class/function)." % filename
171 for piece
in classList:
173 className = spacesRE.sub (
'', piece.name)
178 className = stdRE.sub (
'', className)
181 for typedef, tdList
in typedefsDict.iteritems():
183 className = re.sub (alias, typedef, className)
184 classDict.setdefault (className, set()).add (filename)
186 if not options.lostDefs:
188 localObjects.append (className)
189 if options.lazyLostDefs
and not braketRE.search (className):
191 matchString =
r'\b' + className +
r'\b'
192 simpleObjectREs.append( (re.compile (matchString), className ) )
193 for className
in localObjects:
197 for equivRE
in regexList:
199 if equivRE[0].search (className):
202 for simpleRE
in simpleObjectREs:
203 if simpleRE[0].search (className):
205 if options.verbose
and simpleRE[1] != className:
206 print " Using %s to ignore %s" \
207 % (simpleRE[1], className)
209 if foundEquiv:
continue
210 for exRes
in explicitREs:
211 if exRes[0].
search(className):
212 dupProblems +=
" %s : %s\n" % (exRes[1], className)
215 if foundEquiv:
continue
216 for packageName
in xmlPackages:
219 if packagesREs[packageName].search (className):
220 dupProblems +=
" %s : %s\n" % (packageName, className)
224 print '\n%s\n%s\n' % (filename, dupProblems)
227 for name, fileSet
in sorted( classDict.iteritems() ):
228 if len (fileSet) < 2:
231 fileList = list (fileSet)
233 for filename
in fileList:
242 """ Searches the edmpluginFile to find any duplicate
245 libenv =
'LD_LIBRARY_PATH'
246 if os.environ.get(
'SCRAM_ARCH').startswith(
'osx'): libenv =
'DYLD_FALLBACK_LIBRARY_PATH'
247 biglib =
'/biglib/'+os.environ.get(
'SCRAM_ARCH')
248 for libdir
in os.environ.get(libenv).
split(
':'):
249 if libdir.endswith(biglib):
continue
250 if os.path.exists(libdir+
'/.edmplugincache'): edmpluginFile = edmpluginFile +
' ' + libdir+
'/.edmplugincache'
251 if edmpluginFile ==
'': edmpluginFile = os.path.join(os.environ.get(
'CMSSW_BASE'),
'lib',os.environ.get(
'SCRAM_ARCH'),
'.edmplugincache')
252 cmd =
"cat %s | awk '{print $2\" \"$1}' | sort | uniq | awk '{print $1}' | sort | uniq -c | grep '2 ' | awk '{print $2}'" % edmpluginFile
253 output = commands.getoutput (cmd).
split(
'\n')
255 if line
in ignoreEdmDP:
continue
256 line = line.replace(
"*",
"\*")
257 cmd =
"cat %s | grep ' %s ' | awk '{print $1}' | sort | uniq " % (edmpluginFile,line)
258 out1 = commands.getoutput (cmd).
split(
'\n')
262 print " **"+plugin+
"**"
265 if __name__ ==
"__main__":
267 parser = optparse.OptionParser (
"Usage: %prog [options]\n"\
268 "Searches classes_def.xml for wrong/duplicate "\
270 xmlGroup = optparse.OptionGroup (parser,
"ClassDef XML options")
271 dumpGroup = optparse.OptionGroup (parser,
"EdmPluginDump options")
272 xmlGroup.add_option (
'--dups', dest=
'dups', action=
'store_true',
274 help=
"Search for duplicate definitions")
275 xmlGroup.add_option (
'--lostDefs', dest=
'lostDefs', action=
'store_true',
277 help=
"Looks for definitions in the wrong libraries")
278 xmlGroup.add_option (
'--lazyLostDefs', dest=
'lazyLostDefs',
281 help=
"Will try to ignore as many lost defs as reasonable")
282 xmlGroup.add_option (
'--verbose', dest=
'verbose',
285 help=
"Prints out a lot of information")
286 xmlGroup.add_option (
'--showXMLs', dest=
'showXMLs', action=
'store_true',
288 help=
"Shows all 'classes_def.xml' files")
289 xmlGroup.add_option (
'--dir', dest=
'srcdir', type=
'string', default=
'',
291 dumpGroup.add_option (
'--edmPD', dest=
'edmPD', action=
'store_true',
293 help=
"Searches EDM Plugin Dump for duplicates")
294 dumpGroup.add_option (
'--edmFile', dest=
'edmFile', type=
'string',
297 parser.add_option_group (xmlGroup)
298 parser.add_option_group (dumpGroup)
299 (options, args) = parser.parse_args()
302 if options.lazyLostDefs:
303 options.lostDefs =
True
304 if options.showXMLs
or options.lostDefs
or options.dups:
307 searchDuplicatePlugins ()
def searchDuplicatePlugins
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)