Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 13:02:36

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