Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix conversion to XML for objects with template names #11120

Merged
merged 7 commits into from
Oct 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions CondCore/CondDB/test/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@
<use name="DataFormats/StdDictionaries"/>
<use name="FWCore/PluginManager"/>
<use name="FWCore/Utilities"/>
<library name="testCondDBDict" file="">
</library>
<bin file="testConditionDatabase_0.cpp" name="testConditionDatabase_0">
<lib name="testCondDBDict"/>

<bin file="testReadWritePayloads.cpp" name="testReadWritePayloads">
<lib name="testCondDBDict"/>
</bin>

<bin file="testConditionDatabase_1.cpp" name="testConditionDatabase_1">
</bin>

<bin file="testConditionDatabase_2.cpp" name="testConditionDatabase_2">
</bin>

<bin file="testRootStreaming.cpp" name="testRootStreaming">
<lib name="testCondDBDict"/>
</bin>

<bin file="testPayloadProxy.cpp" name="testPayloadProxy">
<lib name="testCondDBDict"/>
</bin>

<bin file="testFrontier.cpp" name="testFrontier">
</bin>

8 changes: 8 additions & 0 deletions CondCore/EcalPlugins/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,11 @@
<use name="boost_regex"/>
<flags EDM_PLUGIN="1"/>
</library>

<flags CXXFLAGS="-Wno-sign-compare -Wno-unused-variable"/>
<library file="EcalCondObjectContainer_EcalTPGCrystalStatusCode_toXML.cc" name="EcalCondObjectContainer_EcalTPGCrystalStatusCode_toXML">
<use name="CondCore/Utilities"/>
<use name="CondCore/CondDB"/>
<use name="CondFormats/Common"/>
<use name="boost_python"/>
</library>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#include "CondCore/Utilities/interface/PayloadToXML.h"
#include "CondCore/Utilities/src/CondFormats.h"

namespace { // Avoid cluttering the global namespace.

// converter methods
std::string EcalCondObjectContainer_EcalTPGCrystalStatusCode2xml( std::string const &payloadData, std::string const &payloadType ) {
return cond::convertToXML<EcalCondObjectContainer<EcalTPGCrystalStatusCode> > (payloadData, payloadType);
}

} // end namespace


BOOST_PYTHON_MODULE( pluginEcalCondObjectContainer_EcalTPGCrystalStatusCode_toXML )
{
using namespace boost::python;
def ("EcalCondObjectContainer_EcalTPGCrystalStatusCode2xml" , &EcalCondObjectContainer_EcalTPGCrystalStatusCode2xml);

}
26 changes: 18 additions & 8 deletions CondCore/Utilities/python/cond2xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

namespace { // Avoid cluttering the global namespace.

std::string %(plType)s2xml( const std::string &payloadData, const std::string &payloadType ) {
std::string %(plTypeSan)s2xml( const std::string &payloadData, const std::string &payloadType ) {

// now to convert
std::unique_ptr< %(plType)s > payload;
Expand Down Expand Up @@ -62,7 +62,7 @@
BOOST_PYTHON_MODULE(%(mdName)s)
{
using namespace boost::python;
def ("%(plType)s2xml", %(plType)s2xml);
def ("%(plTypeSan)s2xml", %(plTypeSan)s2xml);
}

"""
Expand Down Expand Up @@ -108,6 +108,10 @@ def ("%(plType)s2xml", %(plType)s2xml);
</export>
"""

# helper function
def sanitize(typeName):
return typeName.replace(' ','').replace('<','_').replace('>','')

class CondXmlProcessor(object):

def __init__(self, condDBIn):
Expand All @@ -131,24 +135,29 @@ def __del__(self):

def discover(self, payloadType):

# print "discover> checking for plugin of type %s" % payloadType

# first search in developer area:
libDir = os.path.join( os.environ["CMSSW_BASE"], 'lib', os.environ["SCRAM_ARCH"] )
pluginList = glob.glob( libDir + '/plugin%s_toXML.so' % payloadType )
pluginList = glob.glob( libDir + '/plugin%s_toXML.so' % sanitize(payloadType) )

# if nothing found there, check release:
if not pluginList:
libDir = os.path.join( os.environ["CMSSW_RELEASE_BASE"], 'lib', os.environ["SCRAM_ARCH"] )
pluginList = glob.glob( libDir + '/plugin%s_toXML.so' % payloadType )
pluginList = glob.glob( libDir + '/plugin%s_toXML.so' % sanitize(payloadType) )

# print "found plugin for %s (in %s) : %s " % (payloadType, libDir, pluginList)
# if pluginList:
# print "found plugin for %s (in %s) : %s " % (payloadType, libDir, pluginList)
# else:
# print "no plugin found for type %s" % payloadType

xmlConverter = None
if len(pluginList) > 0:
dirPath, libName = os.path.split( pluginList[0] )
sys.path.append(dirPath)
# print "going to import %s from %s" % (libName, dirPath)
xmlConverter = importlib.import_module( libName.replace('.so', '') )
# print "found : ", dir(xmlConverter)
# print "found methods: ", dir(xmlConverter)
self.doCleanup = False

return xmlConverter
Expand All @@ -162,7 +171,8 @@ def prepPayload2xml(self, session, payload):
data, plType = result

info = { "mdName" : "pl2xmlComp",
'plType' : plType,
'plType' : plType,
'plTypeSan' : sanitize(plType),
}

converter = self.discover(plType)
Expand Down Expand Up @@ -217,7 +227,7 @@ def payload2xml(self, session, payload):
result = session.query(self.conddb.Payload.data, self.conddb.Payload.object_type).filter(self.conddb.Payload.hash == payload).one()
data, plType = result

convFuncName = plType+'2xml'
convFuncName = sanitize(plType)+'2xml'
sys.path.append('.')
func = getattr(xmlConverter, convFuncName)
resultXML = func( str(data), str(plType) )
Expand Down