1 from __future__
import print_function
13 if os.path.join( os.environ[
'CMSSW_BASE'],
'src')
not in sys.path:
14 sys.path.append( os.path.join( os.environ[
'CMSSW_BASE'],
'src') )
18 payload2xmlCodeTemplate =
""" 20 #include "CondCore/Utilities/interface/Payload2XMLModule.h" 21 #include "CondCore/Utilities/src/CondFormats.h" 23 PAYLOAD_2XML_MODULE( %s ){ 24 PAYLOAD_2XML_CLASS( %s ); 29 buildFileTemplate =
""" 30 <flags CXXFLAGS="-Wno-sign-compare -Wno-unused-variable -Os"/> 31 <library file="%s" name="%s"> 32 <use name="CondCore/Utilities"/> 33 <use name="py3-pybind11"/> 48 if '<' in payloadType
and '>' in payloadType:
51 if '::' in payloadType:
52 ptype = payloadType.replace(
'::',
'_')
53 return "%s_%spayload2xml" %(
sanitize(ptype),prefix)
56 import pluginUtilities_payload2xml
as mod2XML
57 return mod2XML.boost_version_label()
64 if not os.path.exists( os.path.join( os.environ[
'CMSSW_BASE'],
'src') ):
65 raise Exception(
"Looks like you are not running in a CMSSW developer area, $CMSSW_BASE/src/ does not exist")
79 libName =
'pluginUtilities_payload2xml.so' 81 isReadOnlyRel = (os.environ[
'CMSSW_RELEASE_BASE'] ==
'')
83 logging.debug(
'Looks like the current working environment is a read-only release')
88 for cmsswBase
in [
'CMSSW_BASE',
'CMSSW_RELEASE_BASE',
'CMSSW_FULL_RELEASE_BASE']:
90 if not (cmsswBase
in os.environ
and os.environ[cmsswBase] !=
''):
92 libDir = os.path.join( os.environ[cmsswBase],
'lib', os.environ[
'SCRAM_ARCH'] )
93 libPath = os.path.join( libDir, libName )
94 if cmsswBase ==
'CMSSW_BASE':
96 foundLib = os.path.isfile( libPath )
98 logging.debug(
'Found built-in library with XML converters: %s' %libPath)
102 raise Exception(
'No built-in library found with XML converters (library name: %s).' %libName)
104 logging.debug(
'Importing built-in library %s' %libPath)
105 module = importlib.import_module( libName.replace(
'.so',
'') )
106 functors =
dir(module)
107 funcName = payloadType+
'2xml' 108 if funcName
in functors:
109 logging.info(
'XML converter for payload class %s found in the built-in library.' %payloadType)
110 return getattr( module, funcName)
113 raise Exception(
'No XML converter suitable for payload class %s has been found in the built-in library.' %payloadType)
115 libPath = os.path.join( devLibDir, libName )
116 if os.path.exists( libPath ):
117 logging.info(
'Found local library with XML converter for class %s' %payloadType)
118 module = importlib.import_module( libName.replace(
'.so',
'') )
119 return getattr( module, funcName)
120 logging.warning(
'No XML converter for payload class %s found in the built-in library.' %payloadType)
125 converter = self.
discover(payloadType)
126 if converter:
return converter
129 startTime = time.time()
132 pluginName =
'plugin%s' % libName
133 tmpLibName =
"Tmp_payload2xml" 134 tmpPluginName =
'plugin%s' %tmpLibName
136 libDir = os.path.join( os.environ[
"CMSSW_BASE"],
'lib', os.environ[
"SCRAM_ARCH"] )
137 tmpLibFile = os.path.join( libDir,tmpPluginName+
'.so' )
138 code = payload2xmlCodeTemplate %(pluginName,payloadType)
140 tmpSrcFileName =
'Local_2XML.cpp' 142 if ( os.path.exists( tmpDir ) ) :
143 msg =
'\nERROR: %s already exists, please remove if you did not create that manually !!' % tmpDir
146 logging.debug(
'Creating temporary package %s' %self.
_pl2xml_tmpDir)
147 os.makedirs( tmpDir+
'/plugins' )
149 buildFileName =
"%s/plugins/BuildFile.xml" % (tmpDir,)
150 with open(buildFileName,
'w')
as buildFile:
151 buildFile.write( buildFileTemplate %(tmpSrcFileName,tmpLibName) )
154 tmpSrcFilePath =
"%s/plugins/%s" % (tmpDir, tmpSrcFileName,)
155 with open(tmpSrcFilePath,
'w')
as codeFile:
159 cmd =
"source $CMS_PATH/cmsset_default.sh;" 160 cmd +=
"(cd %s ; scram b 2>&1 >build.log)" %tmpDir
161 pipe = subprocess.Popen( cmd, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
162 out, err = pipe.communicate()
163 ret = pipe.returncode
165 buildTime = time.time()-startTime
166 logging.info(
"Building done in %s sec., return code from build: %s" %(buildTime,ret) )
169 logging.error(
"Local build for xml dump failed.")
172 libFile = os.path.join(libDir,pluginName +
'.so')
173 shutil.copyfile(tmpLibFile,libFile)
175 module = importlib.import_module( pluginName )
176 funcName = payloadType+
'2xml' 177 functor = getattr( module, funcName )
183 Payload = session.get_dbtype(self.
conddb.Payload)
185 result = session.query(Payload.data, Payload.object_type).
filter(Payload.hash == payloadHash).
one()
186 data, plType = result
187 logging.info(
'Found payload of type %s' %plType)
189 convFuncName =
sanitize(plType)+
'2xml' 192 if xmlConverter
is not None:
194 resultXML = obj.write( data )
198 with open(destFile,
'a')
as outFile:
199 outFile.write(resultXML)
def __init__(self, condDBIn)
def localLibName(payloadType)
def payload2xml(self, session, payloadHash, destFile)
def replace(string, replacements)
def prepPayload2xml(self, payloadType)
def discover(self, payloadType)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
def split(sequence, size)
static std::string join(char **cmd)
def boost_version_for_this_release()