CMS 3D CMS Logo

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__ (self)
 
def __init__ (self, condDBIn)
 
def discover (self, payloadType)
 
def payload2xml (self, session, payloadHash, destFile)
 
def prepPayload2xml (self, payloadType)
 

Public Attributes

 conddb
 
 doCleanup
 
 fakePkgName
 

Private Attributes

 _pl2xml_tmpDir
 

Detailed Description

Definition at line 51 of file cond2xml.py.

Constructor & Destructor Documentation

◆ __init__()

def cond2xml.CondXmlProcessor.__init__ (   self,
  condDBIn 
)

Definition at line 53 of file cond2xml.py.

53  def __init__(self, condDBIn):
54  self.conddb = condDBIn
55 
56  if not os.path.exists( os.path.join( os.environ['CMSSW_BASE'], 'src') ):
57  raise Exception("Looks like you are not running in a CMSSW developer area, $CMSSW_BASE/src/ does not exist")
58 
59  self.fakePkgName = "fakeSubSys4pl/fakePkg4pl"
60  self._pl2xml_tmpDir = os.path.join( os.environ['CMSSW_BASE'], 'src', self.fakePkgName )
61 
62  self.doCleanup = False
63 

◆ __del__()

def cond2xml.CondXmlProcessor.__del__ (   self)

Definition at line 64 of file cond2xml.py.

64  def __del__(self):
65 
66  if self.doCleanup:
67  shutil.rmtree( '/'.join( self._pl2xml_tmpDir.split('/')[:-1] ) )
68  return
69 

References cond2xml.CondXmlProcessor._pl2xml_tmpDir, cond2xml.CondXmlProcessor.doCleanup, join(), and submitPVValidationJobs.split().

Member Function Documentation

◆ discover()

def cond2xml.CondXmlProcessor.discover (   self,
  payloadType 
)

Definition at line 70 of file cond2xml.py.

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

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

Referenced by cond2xml.CondXmlProcessor.prepPayload2xml().

◆ payload2xml()

def cond2xml.CondXmlProcessor.payload2xml (   self,
  session,
  payloadHash,
  destFile 
)

Definition at line 169 of file cond2xml.py.

169  def payload2xml(self, session, payloadHash, destFile):
170 
171  Payload = session.get_dbtype(self.conddb.Payload)
172  # get payload from DB:
173  result = session.query(Payload.data, Payload.object_type).filter(Payload.hash == payloadHash).one()
174  data, plType = result
175  logging.info('Found payload of type %s' %plType)
176 
177  convFuncName = sanitize(plType)+'2xml'
178  xmlConverter = self.prepPayload2xml(plType)
179 
180  if xmlConverter is not None:
181  obj = xmlConverter()
182  resultXML = obj.write( str(data) )
183  if destFile is None:
184  print(resultXML)
185  else:
186  with open(destFile, 'w') as outFile:
187  outFile.write(resultXML)
188  outFile.close()

References cond2xml.CondXmlProcessor.conddb, ALCARECOTkAlBeamHalo_cff.filter, SiPixelPI.one, cond2xml.CondXmlProcessor.prepPayload2xml(), print(), cond2xml.sanitize(), and str.

◆ prepPayload2xml()

def cond2xml.CondXmlProcessor.prepPayload2xml (   self,
  payloadType 
)

Definition at line 111 of file cond2xml.py.

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

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

Referenced by cond2xml.CondXmlProcessor.payload2xml().

Member Data Documentation

◆ _pl2xml_tmpDir

cond2xml.CondXmlProcessor._pl2xml_tmpDir
private

◆ conddb

cond2xml.CondXmlProcessor.conddb

Definition at line 54 of file cond2xml.py.

Referenced by cond2xml.CondXmlProcessor.payload2xml().

◆ doCleanup

cond2xml.CondXmlProcessor.doCleanup

◆ fakePkgName

cond2xml.CondXmlProcessor.fakePkgName

Definition at line 59 of file cond2xml.py.

SiPixelPI::one
Definition: SiPixelPayloadInspectorHelper.h:39
cond2xml.localLibName
def localLibName(payloadType)
Definition: cond2xml.py:44
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
cond2xml.sanitize
def sanitize(typeName)
Definition: cond2xml.py:41
getPayloadData.discover
def discover()
Definition: getPayloadData.py:152
submitPVValidationJobs.split
def split(sequence, size)
Definition: submitPVValidationJobs.py:352
str
#define str(s)
Definition: TestProcessor.cc:52
ALCARECOTkAlBeamHalo_cff.filter
filter
Definition: ALCARECOTkAlBeamHalo_cff.py:27
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
Exception
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23