Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-01 23:40:23

0001 #! /usr/bin/env python3
0002 
0003 from FWCore.ParameterSet.pfnInPath import pfnInPath
0004 import FWCore.ParameterSet.Config as cms
0005 import sys
0006 import os
0007 import re
0008 
0009 if os.getenv('LOCAL_TOP_DIR') == None:
0010     print("The environment variable LOCAL_TOP_DIR must be set to run this script")
0011     print("Usually setting it equal to the value of CMSSW_BASE will do what you want")
0012     print("In the context of a unit test this variable is always set automatically")
0013     sys.exit(1)
0014 
0015 # get the list of XML files from the cfi file
0016 process = cms.Process("TEST")
0017 cfiFile = 'Geometry/CMSCommonData/cmsIdealGeometryXML_cfi'
0018 if len(sys.argv) > 1:
0019     cfiFile = sys.argv[1]
0020 process.load(cfiFile)
0021 xmlFiles = process.es_sources['XMLIdealGeometryESSource'].geomXMLFiles.value()
0022 
0023 def callDOMCount(schemaPath, xmlPath):
0024     xmlFilename = os.path.basename(xmlPath)
0025     xmlFile = open(xmlPath, 'r')
0026     tmpXMLFile = open(xmlFilename, 'w')
0027     # Inside each XML file, there is a path to the schema file.
0028     # We modify this path in a copy of the XML file for two reasons.
0029     # The XML file might be in a package checked out in a working release
0030     # area and the schema file might not be checked out or vice versa.
0031     # This allows DOMCount to run in spite of that. The second reason
0032     # is that the relative path is erroneous in many of the XML files
0033     # and has to be fixed.
0034     for line in xmlFile.readlines():
0035         line = line.replace("../../../../../DetectorDescription/Schema/DDLSchema.xsd",schemaPath)
0036         line = line.replace("../../../../DetectorDescription/Schema/DDLSchema.xsd",schemaPath)
0037         line = line.replace("../../../DetectorDescription/Schema/DDLSchema.xsd",schemaPath)
0038         line = line.replace("../../DetectorDescription/Schema/DDLSchema.xsd",schemaPath)
0039         line = line.replace("../DetectorDescription/Schema/DDLSchema.xsd",schemaPath)
0040         tmpXMLFile.write(line)
0041     tmpXMLFile.close()
0042     xmlFile.close()
0043 
0044     # Run DOMCount
0045     command = 'DOMCount -v=always -n -s -f %s' % (xmlFilename)
0046     os.system ( command )
0047 
0048     # Cleanup
0049     os.system ("rm %s" % (xmlFilename))
0050 
0051 # Find the schema file
0052 schema = pfnInPath("DetectorDescription/Schema/DDLSchema.xsd").replace('file:','')
0053 print("schema file is:")
0054 print(schema)
0055 sys.stdout.flush()
0056 
0057 # Loop over the XML files listed in the cfi file and find them
0058 # NOTE: Now that the files are in an external package, they will
0059 # not be in a 'LOCAL_TOP_DIR'. Checking them for each IB may not
0060 # be needed.
0061 #
0062 ## for name in xmlFiles:
0063 ##     fullpath = '%s/src/%s' % (os.environ['LOCAL_TOP_DIR'], name)
0064 ##     if os.path.isfile(fullpath):
0065 ##         callDOMCount(schema, fullpath)
0066 ##     else:
0067 ##         # It is an error if the file is not there but the package is
0068 ##         packageDirectory =  os.environ['LOCAL_TOP_DIR'] + '/src/' + re.split('/', name)[0] + '/' + re.split('/', name)[1]
0069 ##         if os.path.isdir(packageDirectory):
0070 ##             print 'Error, xml file not found:'
0071 ##             print fullpath
0072 ##             print 'Package is there but the xml file is not'
0073 ##             sys.stdout.flush()
0074 ##             continue
0075 
0076 ##         # if there is a base release then try to find the file there
0077 ##         fullpath = '%s/src/%s' % (os.getenv('CMSSW_RELEASE_BASE'), name)
0078 ##         if os.path.isfile(fullpath):
0079 ##              callDOMCount(schema, fullpath)
0080 ##         else:
0081 ##             print 'Error, xml file not found'
0082 ##             print name
0083 ##             sys.stdout.flush()