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:19

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

◆ payload2xml()

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

Definition at line 177 of file cond2xml.py.

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

177  def payload2xml(self, session, payloadHash, destFile):
178 
179  Payload = session.get_dbtype(self.conddb.Payload)
180  # get payload from DB:
181  result = session.query(Payload.data, Payload.object_type).filter(Payload.hash == payloadHash).one()
182  data, plType = result
183  logging.info('Found payload of type %s' %plType)
184 
185  convFuncName = sanitize(plType)+'2xml'
186  xmlConverter = self.prepPayload2xml(plType)
187 
188  if xmlConverter is not None:
189  obj = xmlConverter()
190  resultXML = obj.write( data )
191  if destFile is None:
192  print(resultXML)
193  else:
194  with open(destFile, 'w') as outFile:
195  outFile.write(resultXML)
196  outFile.close()
197 
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 119 of file cond2xml.py.

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

Referenced by cond2xml.CondXmlProcessor.payload2xml().

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