8 if os.path.join( os.environ[
'CMSSW_BASE'],
'src')
not in sys.path:
9 sys.path.append( os.path.join( os.environ[
'CMSSW_BASE'],
'src') )
13 payload2xmlCodeTemplate =
"""
19 #include <boost/python/class.hpp>
20 #include <boost/python/module.hpp>
21 #include <boost/python/init.hpp>
22 #include <boost/python/def.hpp>
27 #include "boost/archive/xml_oarchive.hpp"
28 #include "CondFormats/Serialization/interface/Serializable.h"
29 #include "CondFormats/Serialization/interface/Archive.h"
31 #include "CondCore/Utilities/src/CondFormats.h"
33 namespace { // Avoid cluttering the global namespace.
35 std::string payload2xml( const std::string &payloadData, const std::string &payloadType ) {
38 std::unique_ptr< %(plType)s > payload;
40 std::stringbuf sdataBuf;
41 sdataBuf.pubsetbuf( const_cast<char *> ( payloadData.c_str() ), payloadData.size() );
43 std::istream inBuffer( &sdataBuf );
44 eos::portable_iarchive ia( inBuffer );
45 payload.reset( new %(plType)s );
48 // now we have the object in memory, convert it to xml in a string and return it
50 std::ostringstream outBuffer;
51 boost::archive::xml_oarchive xmlResult( outBuffer );
52 xmlResult << boost::serialization::make_nvp( "cmsCondPayload", *payload );
54 return outBuffer.str();
60 BOOST_PYTHON_MODULE(%(mdName)s)
62 using namespace boost::python;
63 def ("payload2xml", payload2xml);
68 buildFileTemplate =
"""
69 <flags CXXFLAGS="-Wno-sign-compare -Wno-unused-variable -Os"/>
71 <use name="boost_python"/>
72 <use name="boost_iostreams"/>
73 <use name="boost_serialization"/>
74 <use name="boost_program_options"/>
75 <use name="CondCore/DBCommon"/>
76 <use name="CondCore/IOVService"/>
77 <use name="CondCore/MetaDataService"/>
78 <use name="CondCore/TagCollection"/>
79 <use name="CondCore/CondDB"/>
80 <use name="CondFormats/HLTObjects"/>
81 <use name="CondFormats/Alignment"/>
82 <use name="CondFormats/BeamSpotObjects"/>
83 <use name="CondFormats/CastorObjects"/>
84 <use name="CondFormats/HIObjects"/>
85 <use name="CondFormats/CSCObjects"/>
86 <use name="CondFormats/DTObjects"/>
87 <use name="CondFormats/ESObjects"/>
88 <use name="CondFormats/EcalObjects"/>
89 <use name="CondFormats/EgammaObjects"/>
90 <use name="CondFormats/Luminosity"/>
91 <use name="CondFormats/HcalObjects"/>
92 <use name="CondFormats/JetMETObjects"/>
93 <use name="CondFormats/L1TObjects"/>
94 <use name="CondFormats/PhysicsToolsObjects"/>
95 <use name="CondFormats/GeometryObjects"/>
96 <use name="CondFormats/RecoMuonObjects"/>
97 <use name="CondFormats/RPCObjects"/>
98 <use name="CondFormats/RunInfo"/>
99 <use name="CondFormats/SiPixelObjects"/>
100 <use name="CondFormats/SiStripObjects"/>
101 <use name="CondFormats/Common"/>
102 <use name="CondFormats/BTauObjects"/>
103 <use name="CondFormats/MFObjects"/>
115 if not os.path.exists( os.path.join( os.environ[
'CMSSW_BASE'],
'src') ):
116 raise Exception(
"Looks like you are not running in a CMSSW developer area, $CMSSW_BASE/src/ does not exist")
118 self.fakePkgName =
"fakeSubSys4pl/fakePkg4pl"
119 self._pl2xml_tmpDir = os.path.join( os.environ[
'CMSSW_BASE'],
'src', self.fakePkgName )
126 shutil.rmtree(
'/'.
join( self._pl2xml_tmpDir.split(
'/')[:-1] ) )
127 os.unlink( os.path.join( os.environ[
'CMSSW_BASE'],
'src',
'./pl2xmlComp.so') )
132 startTime = time.time()
135 result = session.query(self.conddb.Payload.data, self.conddb.Payload.object_type).
filter(self.conddb.Payload.hash == payload).
one()
136 data, plType = result
138 info = {
"mdName" :
"pl2xmlComp",
142 code = payload2xmlCodeTemplate % info
144 tmpDir = self._pl2xml_tmpDir
145 if ( os.path.exists( tmpDir ) ) :
146 msg =
'\nERROR: %s already exists, please remove if you did not create that manually !!' % tmpDir
150 os.makedirs( tmpDir+
'/src' )
152 buildFileName =
"%s/BuildFile.xml" % (tmpDir,)
153 with open(buildFileName,
'w')
as buildFile:
154 buildFile.write( buildFileTemplate )
157 tmpFileName =
"%s/src/%s" % (tmpDir, info[
'mdName'],)
158 with open(tmpFileName+
'.cpp',
'w')
as codeFile:
162 libDir = os.path.join( os.environ[
"CMSSW_BASE"],
'tmp', os.environ[
"SCRAM_ARCH"],
'src', self.fakePkgName,
'src', self.fakePkgName.replace(
'/',
''))
163 libName = libDir +
'/lib%s.so' % self.fakePkgName.replace(
'/',
'')
164 cmd =
"source /afs/cern.ch/cms/cmsset_default.sh;"
165 cmd +=
"(cd %s ; scram b 2>&1 >build.log && cp %s $CMSSW_BASE/src/pl2xmlComp.so )" % (tmpDir, libName)
169 buildTime = time.time()-startTime
170 print >> sys.stderr,
"buillding done in ", buildTime,
'sec., return code from build: ', ret
178 msg =
"Error preparing code for "+payload
183 result = session.query(self.conddb.Payload.data, self.conddb.Payload.object_type).
filter(self.conddb.Payload.hash == payload).
one()
184 data, plType = result
188 resultXML = pl2xmlComp.payload2xml( str(data), str(plType) )
static std::string join(char **cmd)