10 if os.path.join( os.environ[
'CMSSW_BASE'],
'src')
not in sys.path:
11 sys.path.append( os.path.join( os.environ[
'CMSSW_BASE'],
'src') )
15 payload2xmlCodeTemplate =
"""
21 #include <boost/python/class.hpp>
22 #include <boost/python/module.hpp>
23 #include <boost/python/init.hpp>
24 #include <boost/python/def.hpp>
29 #include "boost/archive/xml_oarchive.hpp"
30 #include "CondFormats/Serialization/interface/Serializable.h"
31 #include "CondFormats/Serialization/interface/Archive.h"
33 #include "CondCore/Utilities/src/CondFormats.h"
35 namespace { // Avoid cluttering the global namespace.
37 std::string %(plType)s2xml( const std::string &payloadData, const std::string &payloadType ) {
40 std::unique_ptr< %(plType)s > payload;
42 std::stringbuf sdataBuf;
43 sdataBuf.pubsetbuf( const_cast<char *> ( payloadData.c_str() ), payloadData.size() );
45 std::istream inBuffer( &sdataBuf );
46 eos::portable_iarchive ia( inBuffer );
47 payload.reset( new %(plType)s );
50 // now we have the object in memory, convert it to xml in a string and return it
52 std::ostringstream outBuffer;
53 boost::archive::xml_oarchive xmlResult( outBuffer );
54 xmlResult << boost::serialization::make_nvp( "cmsCondPayload", *payload );
56 return outBuffer.str();
62 BOOST_PYTHON_MODULE(%(mdName)s)
64 using namespace boost::python;
65 def ("%(plType)s2xml", %(plType)s2xml);
70 buildFileTemplate =
"""
71 <flags CXXFLAGS="-Wno-sign-compare -Wno-unused-variable -Os"/>
73 <use name="boost_python"/>
74 <use name="boost_iostreams"/>
75 <use name="boost_serialization"/>
76 <use name="boost_program_options"/>
77 <use name="CondCore/DBCommon"/>
78 <use name="CondCore/IOVService"/>
79 <use name="CondCore/MetaDataService"/>
80 <use name="CondCore/TagCollection"/>
81 <use name="CondCore/CondDB"/>
82 <use name="CondFormats/HLTObjects"/>
83 <use name="CondFormats/Alignment"/>
84 <use name="CondFormats/BeamSpotObjects"/>
85 <use name="CondFormats/CastorObjects"/>
86 <use name="CondFormats/HIObjects"/>
87 <use name="CondFormats/CSCObjects"/>
88 <use name="CondFormats/DTObjects"/>
89 <use name="CondFormats/ESObjects"/>
90 <use name="CondFormats/EcalObjects"/>
91 <use name="CondFormats/EgammaObjects"/>
92 <use name="CondFormats/Luminosity"/>
93 <use name="CondFormats/HcalObjects"/>
94 <use name="CondFormats/JetMETObjects"/>
95 <use name="CondFormats/L1TObjects"/>
96 <use name="CondFormats/PhysicsToolsObjects"/>
97 <use name="CondFormats/GeometryObjects"/>
98 <use name="CondFormats/RecoMuonObjects"/>
99 <use name="CondFormats/RPCObjects"/>
100 <use name="CondFormats/RunInfo"/>
101 <use name="CondFormats/SiPixelObjects"/>
102 <use name="CondFormats/SiStripObjects"/>
103 <use name="CondFormats/Common"/>
104 <use name="CondFormats/BTauObjects"/>
105 <use name="CondFormats/MFObjects"/>
117 if not os.path.exists( os.path.join( os.environ[
'CMSSW_BASE'],
'src') ):
118 raise Exception(
"Looks like you are not running in a CMSSW developer area, $CMSSW_BASE/src/ does not exist")
120 self.fakePkgName =
"fakeSubSys4pl/fakePkg4pl"
121 self._pl2xml_tmpDir = os.path.join( os.environ[
'CMSSW_BASE'],
'src', self.fakePkgName )
123 self.doCleanup =
True
128 shutil.rmtree(
'/'.
join( self._pl2xml_tmpDir.split(
'/')[:-1] ) )
129 os.unlink( os.path.join( os.environ[
'CMSSW_BASE'],
'src',
'./pl2xmlComp.so') )
135 libDir = os.path.join( os.environ[
"CMSSW_BASE"],
'lib', os.environ[
"SCRAM_ARCH"] )
136 pluginList = glob.glob( libDir +
'/plugin%s_toXML.so' % payloadType )
140 libDir = os.path.join( os.environ[
"CMSSW_RELEASE_BASE"],
'lib', os.environ[
"SCRAM_ARCH"] )
141 pluginList = glob.glob( libDir +
'/plugin%s_toXML.so' % payloadType )
146 if len(pluginList) > 0:
147 dirPath, libName = os.path.split( pluginList[0] )
148 sys.path.append(dirPath)
150 xmlConverter = importlib.import_module( libName.replace(
'.so',
'') )
152 self.doCleanup =
False
158 startTime = time.time()
161 result = session.query(self.conddb.Payload.data, self.conddb.Payload.object_type).
filter(self.conddb.Payload.hash == payload).
one()
162 data, plType = result
164 info = {
"mdName" :
"pl2xmlComp",
169 if converter:
return converter
171 code = payload2xmlCodeTemplate % info
173 tmpDir = self._pl2xml_tmpDir
174 if ( os.path.exists( tmpDir ) ) :
175 msg =
'\nERROR: %s already exists, please remove if you did not create that manually !!' % tmpDir
176 self.doCleanup =
False
179 os.makedirs( tmpDir+
'/src' )
181 buildFileName =
"%s/BuildFile.xml" % (tmpDir,)
182 with open(buildFileName,
'w')
as buildFile:
183 buildFile.write( buildFileTemplate )
186 tmpFileName =
"%s/src/%s" % (tmpDir, info[
'mdName'],)
187 with open(tmpFileName+
'.cpp',
'w')
as codeFile:
191 libDir = os.path.join( os.environ[
"CMSSW_BASE"],
'tmp', os.environ[
"SCRAM_ARCH"],
'src', self.fakePkgName,
'src', self.fakePkgName.replace(
'/',
''))
192 libName = libDir +
'/lib%s.so' % self.fakePkgName.replace(
'/',
'')
193 cmd =
"source /afs/cern.ch/cms/cmsset_default.sh;"
194 cmd +=
"(cd %s ; scram b 2>&1 >build.log && cp %s $CMSSW_BASE/src/pl2xmlComp.so )" % (tmpDir, libName)
196 if ret != 0 : self.doCleanup =
False
198 buildTime = time.time()-startTime
199 print >> sys.stderr,
"buillding done in ", buildTime,
'sec., return code from build: ', ret
204 return importlib.import_module(
'pl2xmlComp' )
211 msg =
"Error preparing code for "+payload
217 result = session.query(self.conddb.Payload.data, self.conddb.Payload.object_type).
filter(self.conddb.Payload.hash == payload).
one()
218 data, plType = result
220 convFuncName = plType+
'2xml'
222 func = getattr(xmlConverter, convFuncName)
223 resultXML =
func( str(data), str(plType) )
static std::string join(char **cmd)