1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include "FWCore/PluginManager/interface/PluginManager.h"
#include "FWCore/PluginManager/interface/standard.h"
#include "FWCore/Reflection/interface/TypeWithDict.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "MyTestData.h"
//
#include <iostream>
#include <sstream>
#include "TClass.h"
#include "TBufferFile.h"
int main(int argc, char** argv) {
int ret = 0;
edmplugin::PluginManager::Config config;
edmplugin::PluginManager::configure(edmplugin::standard::config());
if (!edm::TypeWithDict::byName("MyTestData")) {
throw cms::Exception("DictionaryMissingClass") << "The dictionary of class 'MyTestData' is missing!";
}
MyTestData d0(17);
d0.print();
TClass* r_class = TClass::GetClass(typeid(MyTestData));
if (!r_class)
throw std::string("No ROOT class registered for MyTestData");
TBufferFile wstreamer(TBufferFile::kWrite);
wstreamer.InitMap();
//wstreamer.StreamObject(&d0, r_class);
wstreamer.WriteObjectAny(&d0, r_class);
std::ostringstream wbuff;
wbuff.write(static_cast<const char*>(wstreamer.Buffer()), wstreamer.Length());
//
std::string rbuff = wbuff.str();
TBufferFile rstreamer(TBufferFile::kRead, rbuff.size(), const_cast<char*>(rbuff.c_str()), kFALSE);
rstreamer.InitMap();
//MyTestData d1;
//rstreamer.StreamObject(&d1, r_class);
void* obj = rstreamer.ReadObjectAny(r_class);
MyTestData& d1 = *(static_cast<MyTestData*>(obj));
d1.print();
return ret;
}
|