CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Public Attributes | Private Attributes
cond2xml.CondXmlProcessor Class Reference
Inheritance diagram for cond2xml.CondXmlProcessor:

Public Member Functions

def __del__
 
def __init__
 
def discover
 
def payload2xml
 
def prepPayload2xml
 

Public Attributes

 conddb
 
 doCleanup
 
 fakePkgName
 

Private Attributes

 _pl2xml_tmpDir
 

Detailed Description

Definition at line 59 of file cond2xml.py.

Constructor & Destructor Documentation

def cond2xml.CondXmlProcessor.__init__ (   self,
  condDBIn 
)

Definition at line 61 of file cond2xml.py.

61 
62  def __init__(self, condDBIn):
63  self.conddb = condDBIn
64 
65  if not os.path.exists( os.path.join( os.environ['CMSSW_BASE'], 'src') ):
66  raise Exception("Looks like you are not running in a CMSSW developer area, $CMSSW_BASE/src/ does not exist")
67 
68  self.fakePkgName = "fakeSubSys4pl/fakePkg4pl"
69  self._pl2xml_tmpDir = os.path.join( os.environ['CMSSW_BASE'], 'src', self.fakePkgName )
70 
71  self.doCleanup = False
def cond2xml.CondXmlProcessor.__del__ (   self)

Definition at line 72 of file cond2xml.py.

References cond2xml.CondXmlProcessor.doCleanup, and join().

72 
73  def __del__(self):
74 
75  if self.doCleanup:
76  shutil.rmtree( '/'.join( self._pl2xml_tmpDir.split('/')[:-1] ) )
77  return
static std::string join(char **cmd)
Definition: RemoteFile.cc:19

Member Function Documentation

def cond2xml.CondXmlProcessor.discover (   self,
  payloadType 
)

Definition at line 78 of file cond2xml.py.

References DeadROC_duringRun.dir, and cond2xml.localLibName().

Referenced by cond2xml.CondXmlProcessor.prepPayload2xml().

78 
79  def discover(self, payloadType):
80 
81  libName = 'pluginUtilities_payload2xml.so'
82  # first search: developer area or main release
83  libDir = os.path.join( os.environ["CMSSW_BASE"], 'lib', os.environ["SCRAM_ARCH"] )
84  devLibDir = libDir
85  libPath = os.path.join( devLibDir, libName )
86  releaseBase = os.environ["CMSSW_RELEASE_BASE"]
87  devCheckout = (releaseBase != '')
88  if not devCheckout:
89  logging.debug('Looks like the current working environment is a read-only release')
90  if not os.path.exists( libPath ) and devCheckout:
91  # main release ( for dev checkouts )
92  libDir = os.path.join( releaseBase, 'lib', os.environ["SCRAM_ARCH"] )
93  libPath = os.path.join( libDir, libName )
94  if not os.path.exists( libPath ):
95  if "CMSSW_FULL_RELEASE_BASE" in os.environ:
96  libDir = os.path.join( os.environ["CMSSW_FULL_RELEASE_BASE"], 'lib', os.environ["SCRAM_ARCH"] )
97  libPath = os.path.join( libDir, libName )
98  if not os.path.exists( libPath ):
99  # it should never happen!
100  raise Exception('No built-in library %s found with XML converters.' %libPath)
101  logging.debug("Importing built-in library %s" %libPath)
102  module = importlib.import_module( libName.replace('.so', '') )
103  functors = dir(module)
104  funcName = payloadType+'2xml'
105  if funcName in functors:
106  logging.info('XML converter for payload class %s found in the built-in library.' %payloadType)
107  return getattr( module, funcName)
108  if not devCheckout:
109  # give-up if it is a read-only release...
110  raise Exception('No XML converter suitable for payload class %s has been found in the built-in library.')
111  libName = 'plugin%s.so' %localLibName( payloadType )
112  libPath = os.path.join( devLibDir, libName )
113  if os.path.exists( libPath ):
114  logging.info('Found local library with XML converter for class %s' %payloadType )
115  module = importlib.import_module( libName.replace('.so', '') )
116  return getattr( module, funcName)
117  logging.warning('No XML converter for payload class %s found in the built-in library.' %payloadType)
118  return None
def localLibName
Definition: cond2xml.py:45
def cond2xml.CondXmlProcessor.payload2xml (   self,
  session,
  payloadHash,
  destFile 
)

Definition at line 177 of file cond2xml.py.

References alcazmumu_cfi.filter, cond2xml.CondXmlProcessor.prepPayload2xml(), print(), and cond2xml.sanitize().

178  def payload2xml(self, session, payloadHash, destFile):
179 
180  Payload = session.get_dbtype(self.conddb.Payload)
181  # get payload from DB:
182  result = session.query(Payload.data, Payload.object_type).filter(Payload.hash == payloadHash).one()
183  data, plType = result
184  logging.info('Found payload of type %s' %plType)
185 
186  convFuncName = sanitize(plType)+'2xml'
187  xmlConverter = self.prepPayload2xml(plType)
188 
189  if xmlConverter is not None:
190  obj = xmlConverter()
191  resultXML = obj.write( data )
192  if destFile is None:
193  print(resultXML)
194  else:
195  with open(destFile, 'w') as outFile:
196  outFile.write(resultXML)
197  outFile.close()
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def sanitize
Definition: cond2xml.py:42
def cond2xml.CondXmlProcessor.prepPayload2xml (   self,
  payloadType 
)

Definition at line 119 of file cond2xml.py.

References cond2xml.CondXmlProcessor._pl2xml_tmpDir, cond2xml.CondXmlProcessor.discover(), cond2xml.CondXmlProcessor.doCleanup, and cond2xml.localLibName().

Referenced by cond2xml.CondXmlProcessor.payload2xml().

120  def prepPayload2xml(self, payloadType):
121 
122  converter = self.discover(payloadType)
123  if converter: return converter
124 
125  #otherwise, go for the code generation in the local checkout area.
126  startTime = time.time()
127 
128  libName = localLibName( payloadType )
129  pluginName = 'plugin%s' % libName
130  tmpLibName = "Tmp_payload2xml"
131  tmpPluginName = 'plugin%s' %tmpLibName
132 
133  libDir = os.path.join( os.environ["CMSSW_BASE"], 'lib', os.environ["SCRAM_ARCH"] )
134  tmpLibFile = os.path.join( libDir,tmpPluginName+'.so' )
135  code = payload2xmlCodeTemplate %(pluginName,payloadType)
136 
137  tmpSrcFileName = 'Local_2XML.cpp'
138  tmpDir = self._pl2xml_tmpDir
139  if ( os.path.exists( tmpDir ) ) :
140  msg = '\nERROR: %s already exists, please remove if you did not create that manually !!' % tmpDir
141  raise Exception(msg)
142 
143  logging.debug('Creating temporary package %s' %self._pl2xml_tmpDir)
144  os.makedirs( tmpDir+'/plugins' )
145 
146  buildFileName = "%s/plugins/BuildFile.xml" % (tmpDir,)
147  with open(buildFileName, 'w') as buildFile:
148  buildFile.write( buildFileTemplate %(tmpSrcFileName,tmpLibName) )
149  buildFile.close()
150 
151  tmpSrcFilePath = "%s/plugins/%s" % (tmpDir, tmpSrcFileName,)
152  with open(tmpSrcFilePath, 'w') as codeFile:
153  codeFile.write(code)
154  codeFile.close()
155 
156  cmd = "source $CMS_PATH/cmsset_default.sh;"
157  cmd += "(cd %s ; scram b 2>&1 >build.log)" %tmpDir
158  pipe = subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
159  out, err = pipe.communicate()
160  ret = pipe.returncode
161 
162  buildTime = time.time()-startTime
163  logging.info("Building done in %s sec., return code from build: %s" %(buildTime,ret) )
164 
165  if (ret != 0):
166  logging.error("Local build for xml dump failed.")
167  return None
168 
169  libFile = os.path.join(libDir,pluginName + '.so')
170  shutil.copyfile(tmpLibFile,libFile)
171 
172  module = importlib.import_module( pluginName )
173  funcName = payloadType+'2xml'
174  functor = getattr( module, funcName )
175  self.doCleanup = True
176  return functor
def localLibName
Definition: cond2xml.py:45

Member Data Documentation

cond2xml.CondXmlProcessor._pl2xml_tmpDir
private

Definition at line 68 of file cond2xml.py.

Referenced by cond2xml.CondXmlProcessor.prepPayload2xml().

cond2xml.CondXmlProcessor.conddb

Definition at line 62 of file cond2xml.py.

cond2xml.CondXmlProcessor.doCleanup

Definition at line 70 of file cond2xml.py.

Referenced by cond2xml.CondXmlProcessor.__del__(), and cond2xml.CondXmlProcessor.prepPayload2xml().

cond2xml.CondXmlProcessor.fakePkgName

Definition at line 67 of file cond2xml.py.