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 "TList.h"
11 #include "TBufferFile.h"
12 #include "Cintex/Cintex.h"
13 
14 namespace cond {
15 
18  ROOT::Cintex::Cintex::Enable();
19  }
20  };
21 
22  // initialize Cintex and load dictionary when required
23  TClass* lookUpDictionary( const std::type_info& sourceType ){
24  static const CintexIntializer initializer;
25  TClass* rc = TClass::GetClass(sourceType);
26  if( !rc ){
27  static std::string const prefix("LCGReflex/");
28  std::string name = demangledName(sourceType);
29  edmplugin::PluginCapabilities::get()->load(prefix + name);
30  rc = TClass::GetClass(sourceType);
31  }
32  return rc;
33  }
34 }
35 
36 class RootStreamBuffer: public TBufferFile {
37 public:
39  TBufferFile( TBufferFile::kWrite ),
40  m_streamerInfoBuff( TBufferFile::kWrite ){
41  }
42 
43  RootStreamBuffer( const std::string& dataSource, const std::string& streamerInfoSource ):
44  TBufferFile( TBufferFile::kRead, dataSource.size(), const_cast<char*>( dataSource.c_str()), kFALSE ),
45  m_streamerInfoBuff( TBufferFile::kRead, streamerInfoSource.size(), const_cast<char*>( streamerInfoSource.c_str()), kFALSE ){
46  }
47 
48  void ForceWriteInfo(TVirtualStreamerInfo* sinfo, Bool_t /* force */){
49  m_streamerInfo.Add( sinfo );
50  }
51 
52  void TagStreamerInfo(TVirtualStreamerInfo* sinfo){
53  m_streamerInfo.Add( sinfo );
54  }
55 
56  void write( const void* obj, const TClass* ptrClass ){
57  m_streamerInfo.Clear();
58  // this will populate the streamerInfo list 'behind the scenes' - calling the TagStreamerInfo method
59  StreamObject(const_cast<void*>(obj), ptrClass);
60  // serialize the StreamerInfo
61  if(m_streamerInfo.GetEntries() ){
62  m_streamerInfoBuff.WriteObject( &m_streamerInfo );
63  }
64  m_streamerInfo.Clear();
65  }
66 
67  void read( void* destinationInstance, const TClass* ptrClass ){
68  // first "load" the available streaminfo(s)
69  // code imported from TSocket::RecvStreamerInfos
70  TList *list = 0;
71  if(m_streamerInfoBuff.Length()){
72  list = (TList*)m_streamerInfoBuff.ReadObject( TList::Class() );
73  TIter next(list);
74  TStreamerInfo *info;
75  TObjLink *lnk = list->FirstLink();
76  // First call BuildCheck for regular class
77  while (lnk) {
78  info = (TStreamerInfo*)lnk->GetObject();
79  TObject *element = info->GetElements()->UncheckedAt(0);
80  Bool_t isstl = element && strcmp("This",element->GetName())==0;
81  if (!isstl) {
82  info->BuildCheck();
83  }
84  lnk = lnk->Next();
85  }
86  // Then call BuildCheck for stl class
87  lnk = list->FirstLink();
88  while (lnk) {
89  info = (TStreamerInfo*)lnk->GetObject();
90  TObject *element = info->GetElements()->UncheckedAt(0);
91  Bool_t isstl = element && strcmp("This",element->GetName())==0;
92  if (isstl) {
93  info->BuildCheck();
94  }
95  lnk = lnk->Next();
96  }
97  }
98  // then read the object data
99  StreamObject(destinationInstance, ptrClass);
100  if( list ) delete list;
101  }
102 
103  void copy( std::ostream& destForData, std::ostream& destForStreamerInfo ){
104  destForData.write( static_cast<const char*>(Buffer()),Length() );
105  destForStreamerInfo.write( static_cast<const char*>(m_streamerInfoBuff.Buffer()),m_streamerInfoBuff.Length() );
106  }
107 
108 private:
109  TBufferFile m_streamerInfoBuff;
111 };
112 
113 cond::RootOutputArchive::RootOutputArchive( std::ostream& dataDest, std::ostream& streamerInfoDest ):
114  m_dataBuffer( dataDest ),
115  m_streamerInfoBuffer( streamerInfoDest ){
116 }
117 
118 void cond::RootOutputArchive::write( const std::type_info& sourceType, const void* sourceInstance){
119  TClass* r_class = lookUpDictionary( sourceType );
120  if (!r_class) throwException( "No ROOT class registered for \"" + demangledName(sourceType)+"\"", "RootOutputArchive::write");
121  RootStreamBuffer buffer;
122  buffer.InitMap();
123  buffer.write(sourceInstance, r_class);
124  // copy the two streams into the target buffers
125  buffer.copy( m_dataBuffer, m_streamerInfoBuffer );
126 }
127 
128 cond::RootInputArchive::RootInputArchive( std::istream& binaryData, std::istream& binaryStreamerInfo ):
129  m_dataBuffer( std::istreambuf_iterator<char>( binaryData ), std::istreambuf_iterator<char>()),
130  m_streamerInfoBuffer( std::istreambuf_iterator<char>( binaryStreamerInfo ), std::istreambuf_iterator<char>()),
131  m_streamer( new RootStreamBuffer( m_dataBuffer, m_streamerInfoBuffer ) ){
132  m_streamer->InitMap();
133 }
134 
136  delete m_streamer;
137 }
138 
139 void cond::RootInputArchive::read( const std::type_info& destinationType, void* destinationInstance){
140  TClass* r_class = lookUpDictionary( destinationType );
141  if (!r_class) throwException( "No ROOT class registered for \"" + demangledName(destinationType) +"\"","RootInputArchive::read");
142  m_streamer->read( destinationInstance, r_class );
143 }
144 
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:82
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)