CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Serialization.cc
Go to the documentation of this file.
5 //
6 #include <sstream>
7 // root includes
8 #include "TStreamerInfo.h"
9 #include "TClass.h"
10 #include "TBufferFile.h"
11 
12 namespace cond {
13 
14  // load dictionary when required
15  TClass* lookUpDictionary( const std::type_info& sourceType ){
16  TClass* rc = TClass::GetClass(sourceType);
17  if( !rc ){
18  static std::string const prefix("LCGReflex/");
19  std::string name = demangledName(sourceType);
20  edmplugin::PluginCapabilities::get()->load(prefix + name);
21  rc = TClass::GetClass(sourceType);
22  }
23  return rc;
24  }
25 }
26 
27 class RootStreamBuffer: public TBufferFile {
28 public:
30  TBufferFile( TBufferFile::kWrite ),
31  m_streamerInfoBuff( TBufferFile::kWrite ){
32  }
33 
34  RootStreamBuffer( const std::string& dataSource, const std::string& streamerInfoSource ):
35  TBufferFile( TBufferFile::kRead, dataSource.size(), const_cast<char*>( dataSource.c_str()), kFALSE ),
36  m_streamerInfoBuff( TBufferFile::kRead, streamerInfoSource.size(), const_cast<char*>( streamerInfoSource.c_str()), kFALSE ){
37  }
38 
39  void ForceWriteInfo(TVirtualStreamerInfo* sinfo, Bool_t /* force */){
40  m_streamerInfo.Add( sinfo );
41  }
42 
43  void TagStreamerInfo(TVirtualStreamerInfo* sinfo){
44  m_streamerInfo.Add( sinfo );
45  }
46 
47  void write( const void* obj, const TClass* ptrClass ){
48  m_streamerInfo.Clear();
49  // this will populate the streamerInfo list 'behind the scenes' - calling the TagStreamerInfo method
50  StreamObject(const_cast<void*>(obj), ptrClass);
51  // serialize the StreamerInfo
52  if(m_streamerInfo.GetEntries() ){
53  m_streamerInfoBuff.WriteObject( &m_streamerInfo );
54  }
55  m_streamerInfo.Clear();
56  }
57 
58  void read( void* destinationInstance, const TClass* ptrClass ){
59  // first "load" the available streaminfo(s)
60  // code imported from TSocket::RecvStreamerInfos
61  TList *list = 0;
62  if(m_streamerInfoBuff.Length()){
63  list = (TList*)m_streamerInfoBuff.ReadObject( TList::Class() );
64  TIter next(list);
65  TStreamerInfo *info;
66  TObjLink *lnk = list->FirstLink();
67  // First call BuildCheck for regular class
68  while (lnk) {
69  info = (TStreamerInfo*)lnk->GetObject();
70  TObject *element = info->GetElements()->UncheckedAt(0);
71  Bool_t isstl = element && strcmp("This",element->GetName())==0;
72  if (!isstl) {
73  info->BuildCheck();
74  }
75  lnk = lnk->Next();
76  }
77  // Then call BuildCheck for stl class
78  lnk = list->FirstLink();
79  while (lnk) {
80  info = (TStreamerInfo*)lnk->GetObject();
81  TObject *element = info->GetElements()->UncheckedAt(0);
82  Bool_t isstl = element && strcmp("This",element->GetName())==0;
83  if (isstl) {
84  info->BuildCheck();
85  }
86  lnk = lnk->Next();
87  }
88  }
89  // then read the object data
90  StreamObject(destinationInstance, ptrClass);
91  if( list ) delete list;
92  }
93 
94  void copy( std::ostream& destForData, std::ostream& destForStreamerInfo ){
95  destForData.write( static_cast<const char*>(Buffer()),Length() );
96  destForStreamerInfo.write( static_cast<const char*>(m_streamerInfoBuff.Buffer()),m_streamerInfoBuff.Length() );
97  }
98 
99 private:
100  TBufferFile m_streamerInfoBuff;
102 };
103 
104 cond::RootOutputArchive::RootOutputArchive( std::ostream& dataDest, std::ostream& streamerInfoDest ):
105  m_dataBuffer( dataDest ),
106  m_streamerInfoBuffer( streamerInfoDest ){
107 }
108 
109 void cond::RootOutputArchive::write( const std::type_info& sourceType, const void* sourceInstance){
110  TClass* r_class = lookUpDictionary( sourceType );
111  if (!r_class) throwException( "No ROOT class registered for \"" + demangledName(sourceType)+"\"", "RootOutputArchive::write");
112  RootStreamBuffer buffer;
113  buffer.InitMap();
114  buffer.write(sourceInstance, r_class);
115  // copy the two streams into the target buffers
116  buffer.copy( m_dataBuffer, m_streamerInfoBuffer );
117 }
118 
119 cond::RootInputArchive::RootInputArchive( std::istream& binaryData, std::istream& binaryStreamerInfo ):
120  m_dataBuffer( std::istreambuf_iterator<char>( binaryData ), std::istreambuf_iterator<char>()),
121  m_streamerInfoBuffer( std::istreambuf_iterator<char>( binaryStreamerInfo ), std::istreambuf_iterator<char>()),
122  m_streamer( new RootStreamBuffer( m_dataBuffer, m_streamerInfoBuffer ) ){
123  m_streamer->InitMap();
124 }
125 
127  delete m_streamer;
128 }
129 
130 void cond::RootInputArchive::read( const std::type_info& destinationType, void* destinationInstance){
131  TClass* r_class = lookUpDictionary( destinationType );
132  if (!r_class) throwException( "No ROOT class registered for \"" + demangledName(destinationType) +"\"","RootInputArchive::read");
133  m_streamer->read( destinationInstance, r_class );
134 }
135 
void read(void *destinationInstance, const TClass *ptrClass)
static const TGPicture * info(bool iBackgroundIsBlack)
void ForceWriteInfo(TVirtualStreamerInfo *sinfo, Bool_t)
void read(const std::type_info &destinationType, void *destinationInstance)
RootOutputArchive(std::ostream &dataDest, std::ostream &streamerInfoDest)
void write(const void *obj, const TClass *ptrClass)
std::string demangledName(const std::type_info &typeInfo)
Definition: ClassUtils.cc:156
void write(const std::type_info &sourceType, const void *sourceInstance)
static PluginCapabilities * get()
TClass * lookUpDictionary(const std::type_info &sourceType)
void throwException(std::string const &message, std::string const &methodName)
Definition: Exception.cc:17
RootStreamBuffer(const std::string &dataSource, const std::string &streamerInfoSource)
TBufferFile m_streamerInfoBuff
RootStreamBuffer * m_streamer
Definition: Serialization.h:79
void TagStreamerInfo(TVirtualStreamerInfo *sinfo)
void load(const std::string &iName)
void copy(std::ostream &destForData, std::ostream &destForStreamerInfo)
tuple size
Write out results.
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
RootInputArchive(std::istream &binaryData, std::istream &binaryStreamerInfo)