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 59 of file cond2xml.py.

Constructor & Destructor Documentation

◆ __init__()

def cond2xml.CondXmlProcessor.__init__ (   self,
  condDBIn 
)

Definition at line 61 of file cond2xml.py.

61  def __init__(self, condDBIn):
62  self.conddb = condDBIn
63 
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")
66 
67  self.fakePkgName = "fakeSubSys4pl/fakePkg4pl"
68  self._pl2xml_tmpDir = os.path.join( os.environ['CMSSW_BASE'], 'src', self.fakePkgName )
69 
70  self.doCleanup = False
71 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)

◆ __del__()

def cond2xml.CondXmlProcessor.__del__ (   self)

Definition at line 72 of file cond2xml.py.

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

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

Member Function Documentation

◆ discover()

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  def discover(self, payloadType):
79  libName = 'pluginUtilities_payload2xml.so'
80 
81  isReadOnlyRel = (os.environ['CMSSW_RELEASE_BASE'] == '')
82  if isReadOnlyRel:
83  logging.debug('Looks like the current working environment is a read-only release')
84 
85  # first search CMSSW_BASE (developer area), then CMSSW_RELEASE_BASE (release base),
86  # and finally CMSSW_FULL_RELEASE_BASE (full release base, defined only for patch releases)
87  foundLib = False
88  for cmsswBase in ['CMSSW_BASE', 'CMSSW_RELEASE_BASE', 'CMSSW_FULL_RELEASE_BASE']:
89  # Skip to next in case one is not defined or is empty
90  if not (cmsswBase in os.environ and os.environ[cmsswBase] != ''):
91  continue
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':
95  devLibDir = libDir
96  foundLib = os.path.isfile( libPath )
97  if foundLib:
98  logging.debug('Found built-in library with XML converters: %s' %libPath)
99  break
100  if not foundLib:
101  # this should never happen !!
102  raise Exception('No built-in library found with XML converters (library name: %s).' %libName)
103 
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)
111  if isReadOnlyRel:
112  # give up if it is a read-only release...
113  raise Exception('No XML converter suitable for payload class %s has been found in the built-in library.' %payloadType)
114  libName = 'plugin%s.so' %localLibName( 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)
121  return None
122 
def localLibName(payloadType)
Definition: cond2xml.py:45

◆ payload2xml()

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

Definition at line 181 of file cond2xml.py.

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

181  def payload2xml(self, session, payloadHash, destFile):
182 
183  Payload = session.get_dbtype(self.conddb.Payload)
184  # get payload from DB:
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)
188 
189  convFuncName = sanitize(plType)+'2xml'
190  xmlConverter = self.prepPayload2xml(plType)
191 
192  if xmlConverter is not None:
193  obj = xmlConverter()
194  resultXML = obj.write( data )
195  if destFile is None:
196  print(resultXML)
197  else:
198  with open(destFile, 'a') as outFile:
199  outFile.write(resultXML)
200 
201 
def sanitize(typeName)
Definition: cond2xml.py:42
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ prepPayload2xml()

def cond2xml.CondXmlProcessor.prepPayload2xml (   self,
  payloadType 
)

Definition at line 123 of file cond2xml.py.

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

Referenced by cond2xml.CondXmlProcessor.payload2xml().

123  def prepPayload2xml(self, payloadType):
124 
125  converter = self.discover(payloadType)
126  if converter: return converter
127 
128  #otherwise, go for the code generation in the local checkout area.
129  startTime = time.time()
130 
131  libName = localLibName( payloadType )
132  pluginName = 'plugin%s' % libName
133  tmpLibName = "Tmp_payload2xml"
134  tmpPluginName = 'plugin%s' %tmpLibName
135 
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)
139 
140  tmpSrcFileName = 'Local_2XML.cpp'
141  tmpDir = self._pl2xml_tmpDir
142  if ( os.path.exists( tmpDir ) ) :
143  msg = '\nERROR: %s already exists, please remove if you did not create that manually !!' % tmpDir
144  raise Exception(msg)
145 
146  logging.debug('Creating temporary package %s' %self._pl2xml_tmpDir)
147  os.makedirs( tmpDir+'/plugins' )
148 
149  buildFileName = "%s/plugins/BuildFile.xml" % (tmpDir,)
150  with open(buildFileName, 'w') as buildFile:
151  buildFile.write( buildFileTemplate %(tmpSrcFileName,tmpLibName) )
152  buildFile.close()
153 
154  tmpSrcFilePath = "%s/plugins/%s" % (tmpDir, tmpSrcFileName,)
155  with open(tmpSrcFilePath, 'w') as codeFile:
156  codeFile.write(code)
157  codeFile.close()
158 
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
164 
165  buildTime = time.time()-startTime
166  logging.info("Building done in %s sec., return code from build: %s" %(buildTime,ret) )
167 
168  if (ret != 0):
169  logging.error("Local build for xml dump failed.")
170  return None
171 
172  libFile = os.path.join(libDir,pluginName + '.so')
173  shutil.copyfile(tmpLibFile,libFile)
174 
175  module = importlib.import_module( pluginName )
176  funcName = payloadType+'2xml'
177  functor = getattr( module, funcName )
178  self.doCleanup = True
179  return functor
180 
def localLibName(payloadType)
Definition: cond2xml.py:45

Member Data Documentation

◆ _pl2xml_tmpDir

cond2xml.CondXmlProcessor._pl2xml_tmpDir
private

◆ conddb

cond2xml.CondXmlProcessor.conddb

Definition at line 62 of file cond2xml.py.

Referenced by cond2xml.CondXmlProcessor.payload2xml().

◆ doCleanup

cond2xml.CondXmlProcessor.doCleanup

◆ fakePkgName

cond2xml.CondXmlProcessor.fakePkgName

Definition at line 67 of file cond2xml.py.