Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:29

0001 #include "FWCore/PluginManager/interface/PluginManager.h"
0002 #include "FWCore/PluginManager/interface/standard.h"
0003 #include "FWCore/Reflection/interface/TypeWithDict.h"
0004 #include "FWCore/Utilities/interface/Exception.h"
0005 #include "MyTestData.h"
0006 //
0007 #include <iostream>
0008 #include <sstream>
0009 #include "TClass.h"
0010 #include "TBufferFile.h"
0011 
0012 int main(int argc, char** argv) {
0013   int ret = 0;
0014   edmplugin::PluginManager::Config config;
0015   edmplugin::PluginManager::configure(edmplugin::standard::config());
0016 
0017   if (!edm::TypeWithDict::byName("MyTestData")) {
0018     throw cms::Exception("DictionaryMissingClass") << "The dictionary of class 'MyTestData' is missing!";
0019   }
0020 
0021   MyTestData d0(17);
0022   d0.print();
0023   TClass* r_class = TClass::GetClass(typeid(MyTestData));
0024   if (!r_class)
0025     throw std::string("No ROOT class registered for MyTestData");
0026   TBufferFile wstreamer(TBufferFile::kWrite);
0027   wstreamer.InitMap();
0028   //wstreamer.StreamObject(&d0, r_class);
0029   wstreamer.WriteObjectAny(&d0, r_class);
0030 
0031   std::ostringstream wbuff;
0032   wbuff.write(static_cast<const char*>(wstreamer.Buffer()), wstreamer.Length());
0033   //
0034   std::string rbuff = wbuff.str();
0035   TBufferFile rstreamer(TBufferFile::kRead, rbuff.size(), const_cast<char*>(rbuff.c_str()), kFALSE);
0036   rstreamer.InitMap();
0037   //MyTestData d1;
0038   //rstreamer.StreamObject(&d1, r_class);
0039   void* obj = rstreamer.ReadObjectAny(r_class);
0040   MyTestData& d1 = *(static_cast<MyTestData*>(obj));
0041   d1.print();
0042 
0043   return ret;
0044 }