Skip to content

Commit

Permalink
Merge pull request #9047 from ggovi/new-conddb-remove-root-streaming
Browse files Browse the repository at this point in the history
Removed serialization based on Root, since it is not used.
  • Loading branch information
cmsbuild committed May 13, 2015
2 parents b129ff3 + e35247b commit 8014c85
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 180 deletions.
49 changes: 0 additions & 49 deletions CondCore/CondDB/interface/Serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

#include "CondFormats/Serialization/interface/Archive.h"

class RootStreamBuffer;

namespace cond {

// default payload factory
Expand All @@ -37,53 +35,6 @@ namespace cond {
return new T;
}

// Archives for the streaming based on ROOT.

// output
class RootOutputArchive {
public:
RootOutputArchive( std::ostream& dataDest, std::ostream& streamerInfoDest );

template <typename T>
RootOutputArchive& operator<<( const T& instance );
private:
// type and ptr of the object to stream
void write( const std::type_info& sourceType, const void* sourceInstance);
private:
// here is where the write function will write on...
std::ostream& m_dataBuffer;
std::ostream& m_streamerInfoBuffer;
};

template <typename T> inline RootOutputArchive& RootOutputArchive::operator<<( const T& instance ){
write( typeid(T), &instance );
return *this;
}

// input
class RootInputArchive {
public:
RootInputArchive( std::istream& binaryData, std::istream& binaryStreamerInfo );

virtual ~RootInputArchive();

template <typename T>
RootInputArchive& operator>>( T& instance );
private:
// type and ptr of the object to restore
void read( const std::type_info& destinationType, void* destinationInstance);
private:
// copy of the input stream. is referenced by the TBufferFile.
std::string m_dataBuffer;
std::string m_streamerInfoBuffer;
RootStreamBuffer* m_streamer = nullptr;
};

template <typename T> inline RootInputArchive& RootInputArchive::operator>>( T& instance ){
read( typeid(T), &instance );
return *this;
}

class StreamerInfo {
public:
static constexpr char const* TECH_LABEL = "technology";
Expand Down
131 changes: 0 additions & 131 deletions CondCore/CondDB/src/Serialization.cc
Original file line number Diff line number Diff line change
@@ -1,138 +1,7 @@
#include "CondCore/CondDB/interface/Serialization.h"
#include "CondCore/CondDB/interface/Exception.h"
#include "CondCore/CondDB/interface/Utils.h"
#include "FWCore/PluginManager/interface/PluginCapabilities.h"
//
#include <sstream>
#include "boost/version.hpp"
// root includes
#include "TStreamerInfo.h"
#include "TClass.h"
#include "TBufferFile.h"

namespace cond {

// load dictionary when required
TClass* lookUpDictionary( const std::type_info& sourceType ){
TClass* rc = TClass::GetClass(sourceType);
if( !rc ){
static std::string const prefix("LCGReflex/");
std::string name = demangledName(sourceType);
edmplugin::PluginCapabilities::get()->load(prefix + name);
rc = TClass::GetClass(sourceType);
}
return rc;
}
}

class RootStreamBuffer: public TBufferFile {
public:
RootStreamBuffer():
TBufferFile( TBufferFile::kWrite ),
m_streamerInfoBuff( TBufferFile::kWrite ){
}

RootStreamBuffer( const std::string& dataSource, const std::string& streamerInfoSource ):
TBufferFile( TBufferFile::kRead, dataSource.size(), const_cast<char*>( dataSource.c_str()), kFALSE ),
m_streamerInfoBuff( TBufferFile::kRead, streamerInfoSource.size(), const_cast<char*>( streamerInfoSource.c_str()), kFALSE ){
}

void ForceWriteInfo(TVirtualStreamerInfo* sinfo, Bool_t /* force */){
m_streamerInfo.Add( sinfo );
}

void TagStreamerInfo(TVirtualStreamerInfo* sinfo){
m_streamerInfo.Add( sinfo );
}

void write( const void* obj, const TClass* ptrClass ){
m_streamerInfo.Clear();
// this will populate the streamerInfo list 'behind the scenes' - calling the TagStreamerInfo method
StreamObject(const_cast<void*>(obj), ptrClass);
// serialize the StreamerInfo
if(m_streamerInfo.GetEntries() ){
m_streamerInfoBuff.WriteObject( &m_streamerInfo );
}
m_streamerInfo.Clear();
}

void read( void* destinationInstance, const TClass* ptrClass ){
// first "load" the available streaminfo(s)
// code imported from TSocket::RecvStreamerInfos
TList *list = 0;
if(m_streamerInfoBuff.Length()){
list = (TList*)m_streamerInfoBuff.ReadObject( TList::Class() );
TIter next(list);
TStreamerInfo *info;
TObjLink *lnk = list->FirstLink();
// First call BuildCheck for regular class
while (lnk) {
info = (TStreamerInfo*)lnk->GetObject();
TObject *element = info->GetElements()->UncheckedAt(0);
Bool_t isstl = element && strcmp("This",element->GetName())==0;
if (!isstl) {
info->BuildCheck();
}
lnk = lnk->Next();
}
// Then call BuildCheck for stl class
lnk = list->FirstLink();
while (lnk) {
info = (TStreamerInfo*)lnk->GetObject();
TObject *element = info->GetElements()->UncheckedAt(0);
Bool_t isstl = element && strcmp("This",element->GetName())==0;
if (isstl) {
info->BuildCheck();
}
lnk = lnk->Next();
}
}
// then read the object data
StreamObject(destinationInstance, ptrClass);
if( list ) delete list;
}

void copy( std::ostream& destForData, std::ostream& destForStreamerInfo ){
destForData.write( static_cast<const char*>(Buffer()),Length() );
destForStreamerInfo.write( static_cast<const char*>(m_streamerInfoBuff.Buffer()),m_streamerInfoBuff.Length() );
}

private:
TBufferFile m_streamerInfoBuff;
TList m_streamerInfo;
};

cond::RootOutputArchive::RootOutputArchive( std::ostream& dataDest, std::ostream& streamerInfoDest ):
m_dataBuffer( dataDest ),
m_streamerInfoBuffer( streamerInfoDest ){
}

void cond::RootOutputArchive::write( const std::type_info& sourceType, const void* sourceInstance){
TClass* r_class = lookUpDictionary( sourceType );
if (!r_class) throwException( "No ROOT class registered for \"" + demangledName(sourceType)+"\"", "RootOutputArchive::write");
RootStreamBuffer buffer;
buffer.InitMap();
buffer.write(sourceInstance, r_class);
// copy the two streams into the target buffers
buffer.copy( m_dataBuffer, m_streamerInfoBuffer );
}

cond::RootInputArchive::RootInputArchive( std::istream& binaryData, std::istream& binaryStreamerInfo ):
m_dataBuffer( std::istreambuf_iterator<char>( binaryData ), std::istreambuf_iterator<char>()),
m_streamerInfoBuffer( std::istreambuf_iterator<char>( binaryStreamerInfo ), std::istreambuf_iterator<char>()),
m_streamer( new RootStreamBuffer( m_dataBuffer, m_streamerInfoBuffer ) ){
m_streamer->InitMap();
}

cond::RootInputArchive::~RootInputArchive(){
delete m_streamer;
}

void cond::RootInputArchive::read( const std::type_info& destinationType, void* destinationInstance){
TClass* r_class = lookUpDictionary( destinationType );
if (!r_class) throwException( "No ROOT class registered for \"" + demangledName(destinationType) +"\"","RootInputArchive::read");
m_streamer->read( destinationInstance, r_class );
}

std::string cond::StreamerInfo::techVersion(){
return BOOST_LIB_VERSION;
Expand Down

0 comments on commit 8014c85

Please sign in to comment.