Back to home page

Project CMSSW displayed by LXR

 
 

    


Warning, /FWCore/Utilities/scripts/edmCheckClassTransients is written in an unsupported language. File is not indexed.

0001 #!  /usr/bin/env python3
0002 import string
0003 import re
0004 import collections 
0005 
0006 classtransients = collections.defaultdict(list)
0007 
0008 classtransients['edm::AssociationMap'].append('transientMap_')
0009 classtransients['edm::AssociationVector'].append('transientVector_')
0010 
0011 
0012 
0013 class RMParser(object):
0014     """Parses the rootmap file(s) for a package looking for class declarations of edm template classes
0015     which contain member(s) which must be labeled transient="true" in classes_def.xml
0016     """
0017     
0018     def __init__(self,filelist):
0019         self._files = filelist
0020         self.cnames = collections.defaultdict(list)
0021         self._presentClass = None
0022         self.readRootMap()
0023     def readRootMap(self):
0024         for filename in self._files:
0025           f = open(filename)
0026           for line in f:
0027             cname=""
0028             if re.search("^class",line): cname = re.sub("class ","",line)
0029             if re.search("^struct",line): cname = re.sub("struct ","",line)
0030             for key in classtransients.keys():
0031                if re.search(r'^%s<' % key, cname):
0032                    n_name = " ".join(line.split())
0033                    self.cnames[key].append(n_name)
0034           f.close()
0035 
0036 def checkTrans(templname,name):
0037     c = ROOT.TClass.GetClass(name)
0038     if not c:
0039         print ("Info: Could no load dictionary for class '"+name+"' because of typedef(s) in the name.")
0040         return 0
0041     nerrs=0
0042     for trans in classtransients[templname]:
0043       tdm = c.GetDataMember(trans)
0044       retval = False
0045       if tdm : retval = tdm.IsPersistent()
0046       if retval == True : 
0047           print ("Error: field='"+trans+"' must be labeled transient=\"true\" in classes_def.xml for "+name+" or the equivalent class name with typedefs.")
0048           nerrs+=1
0049     return nerrs
0050 
0051 #Setup the options
0052 from argparse import ArgumentParser
0053 oparser = ArgumentParser()
0054 oparser.add_argument("-l","--lib", dest="library", type=str,
0055                      help="specify the library to load")
0056 oparser.add_argument("-f","--rootmap", dest="rmfiles", action="append", type=str, default=[],
0057                      help="specify the rootmap file(s) to read")
0058 
0059 options=oparser.parse_args()
0060 
0061 #Need to not have ROOT load .rootlogon.(C|py) since it can cause interference.
0062 import ROOT
0063 ROOT.PyConfig.DisableRootLogon = True
0064 
0065 #Keep ROOT from trying to use X11
0066 ROOT.gROOT.SetBatch(True)
0067 ROOT.gROOT.ProcessLine(".autodict")
0068 if options.library is None:
0069     print ("Transient member check requires a specific library")
0070 else:
0071     if ROOT.gSystem.Load(options.library) < 0 :
0072         raise RuntimeError("failed to load library '"+options.library+"'")
0073 
0074 p = RMParser(options.rmfiles)
0075 
0076 nerrs = 0
0077 for key in p.cnames.keys():
0078     for value in p.cnames[key]:
0079         nerrs += checkTrans(key,value)
0080 
0081 if nerrs > 0 : 
0082     print ("Error: edm template class member must be labeled transient=\"true\" in classes_def.xml. Check log for specific template and member name.")
0083     import sys
0084     sys.exit(1)