Logo ROOT  
Reference Guide
TVirtualStreamerInfo.cxx
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Rene Brun 05/02/2007
3 /*************************************************************************
4  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
5  * All rights reserved. *
6  * *
7  * For the licensing terms see $ROOTSYS/LICENSE. *
8  * For the list of contributors see $ROOTSYS/README/CREDITS. *
9  *************************************************************************/
10 
11 /** \class TVirtualStreamerInfo
12 Abstract Interface class describing Streamer information for one class.
13 */
14 
15 #include "TROOT.h"
16 #include "TSystem.h"
17 #include "TClass.h"
18 #include "TVirtualMutex.h"
19 #include "TInterpreter.h"
20 #include "TVirtualStreamerInfo.h"
21 #include "TPluginManager.h"
22 #include "TStreamerElement.h"
23 #include "TError.h"
24 #include "TObjArray.h"
25 
27 
31 
33 
34 ////////////////////////////////////////////////////////////////////////////////
35 /// Default constructor.
36 
37 TVirtualStreamerInfo::TVirtualStreamerInfo() : fOptimized(kFALSE), fIsBuilt(kFALSE), fIsCompiled(kFALSE)
38 {
39 }
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// Default constructor.
43 
45  : TNamed(cl->GetName(),""), fOptimized(kFALSE), fIsBuilt(kFALSE), fIsCompiled(kFALSE)
46 {
47 }
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 ///copy constructor
51 
53  : TNamed(info), fOptimized(kFALSE), fIsBuilt(kFALSE), fIsCompiled(kFALSE)
54 {
55 }
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 ///assignment operator
59 
61 {
62  if(this!=&info) {
63  TNamed::operator=(info);
64  }
65  return *this;
66 }
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// Destructor
70 
72 {
73 }
74 
75 ////////////////////////////////////////////////////////////////////////////////
76 /// static function returning true if ReadBuffer can delete object
77 
79 {
80  return fgCanDelete;
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// static function returning true if optimization can be on
85 
87 {
88  return fgOptimize;
89 }
90 
91 ////////////////////////////////////////////////////////////////////////////////
92 /// Given a comment/title declaring an array counter, for example:
93 /// ~~~ {.cpp}
94 /// //[fArraySize] array of size fArraySize
95 /// ~~~
96 /// return the start of the array dimension declaration start in the string
97 /// (so the location of the 'f'.
98 
99 const char *TVirtualStreamerInfo::GetElementCounterStart(const char *dmTitle)
100 {
101  for (const char *lbracket = dmTitle; *lbracket; ++lbracket) {
102  // = ::strchr(dmTitle, '[');
103  if ( (*lbracket) == '[' ) return lbracket;
104  if ( (*lbracket) != '/' && !isspace(*lbracket) ) {
105  // Allow only comment delimiters and white spaces
106  // before the array information.
107  return 0;
108  }
109  }
110  return 0;
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Get pointer to a TStreamerBasicType in TClass *cl
115 ///static function
116 
118 {
119  TVirtualStreamerInfo *info;
120  {
122  const TObjArray *sinfos = cl->GetStreamerInfos();
123  info = (TVirtualStreamerInfo *)sinfos->At(cl->GetClassVersion());
124  }
125 
126  if (!info || !info->IsCompiled()) {
127  // Even if the streamerInfo exist, it could still need to be 'build'
128  // It is important to figure this out, because
129  // a) if it is not build, we need to build
130  // b) if is build, we should not build it (or we could end up in an
131  // infinite loop, if the element and its counter are in the same
132  // class!
133  // Checking IsCompiled is sufficient here even-though it is set only at
134  // the end of the call to Build as this function has an
135  // internal recursion prevention (setting and testing kBuildRunning).
136  info = cl->GetStreamerInfo();
137  }
138  if (!info) return 0;
139  TStreamerElement *element = (TStreamerElement *)info->GetElements()->FindObject(countName);
140  if (!element) return 0;
141  if (element->IsA() == TStreamerBasicType::Class()) return (TStreamerBasicType*)element;
142  return 0;
143 }
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// Return whether the TStreamerInfos will save the collections in
147 /// "member-wise" order whenever possible. The default is to store member-wise.
148 /// - kTRUE indicates member-wise storing
149 /// - kFALSE inddicates object-wise storing
150 ///
151 /// A collection can be saved member wise when it contain is guaranteed to be
152 /// homogeneous. For example std::vector<THit> can be stored member wise,
153 /// while std::vector<THit*> can not (possible use of polymorphism).
154 
156 {
157  return fgStreamMemberWise;
158 }
159 
160 ////////////////////////////////////////////////////////////////////////////////
161 /// This is a static function.
162 /// Set optimization option.
163 /// When this option is activated (default), consecutive data members
164 /// of the same type are merged into an array (faster).
165 /// Optimization must be off in TTree split mode.
166 
168 {
169  fgOptimize = opt;
170 }
171 
172 ////////////////////////////////////////////////////////////////////////////////
173 /// Static function returning a pointer to a new TVirtualStreamerInfo object.
174 /// If the Info factory does not exist, it is created via the plugin manager.
175 /// In reality the factory is an empty TStreamerInfo object.
176 
178 {
179  if (!fgInfoFactory) {
181  TPluginHandler *h;
182  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualStreamerInfo","TStreamerInfo"))) {
183  if (h->LoadPlugin() == -1) {
184  ::Fatal("TVirtualStreamerInfo::Factory",
185  "The plugin handler for TVirtualStreamerInfo was found but failed to load!");
186  }
187  fgInfoFactory = (TVirtualStreamerInfo*) h->ExecPlugin(0);
188  if (fgInfoFactory == 0) {
189  ::Fatal("TVirtualStreamerInfo::Factory",
190  "The plugin handler for TVirtualStreamerInfo was found but failed to create the factory object!");
191  }
192  } else {
193  TString filename("$ROOTSYS/etc/plugins/TVirtualStreamerInfo");
194  gSystem->ExpandPathName(filename);
195  if (gSystem->AccessPathName(filename)) {
196  ::Fatal("TVirtualStreamerInfo::Factory",
197  "Cannot find the plugin handler for TVirtualStreamerInfo! "
198  "$ROOTSYS/etc/plugins/TVirtualStreamerInfo does not exist "
199  "or is inaccessible.");
200  } else {
201  ::Fatal("TVirtualStreamerInfo::Factory",
202  "Cannot find the plugin handler for TVirtualStreamerInfo! "
203  "However $ROOTSYS/etc/plugins/TVirtualStreamerInfo is accessible, "
204  "Check the content of this directory!");
205  }
206  }
207  }
208 
209  return fgInfoFactory;
210 }
211 
212 ////////////////////////////////////////////////////////////////////////////////
213 /// This is a static function.
214 /// Set object delete option.
215 /// When this option is activated (default), ReadBuffer automatically
216 /// delete objects when a data member is a pointer to an object.
217 /// If your constructor is not presetting pointers to 0, you must
218 /// call this static function TStreamerInfo::SetCanDelete(kFALSE);
219 
221 {
222  fgCanDelete = opt;
223 }
224 
225 ////////////////////////////////////////////////////////////////////////////////
226 ///static function: Set the StreamerInfo factory
227 
229 {
231  auto old = fgInfoFactory;
232  fgInfoFactory = factory;
233  if (old) delete old;
234 }
235 
236 ////////////////////////////////////////////////////////////////////////////////
237 /// Set whether the TStreamerInfos will save the collections in
238 /// "member-wise" order whenever possible. The default is to store member-wise.
239 /// - kTRUE indicates member-wise storing
240 /// - kFALSE indicates object-wise storing
241 /// This function returns the previous value of fgStreamMemberWise.
242 
244 {
245  // A collection can be saved member wise when it contain is guaranteed to be
246  // homogeneous. For example std::vector<THit> can be stored member wise,
247  // while std::vector<THit*> can not (possible use of polymorphism).
248 
249  Bool_t prev = fgStreamMemberWise;
250  fgStreamMemberWise = enable;
251  return prev;
252 }
253 
254 ////////////////////////////////////////////////////////////////////////////////
255 /// Stream an object of class TVirtualStreamerInfo.
256 
257 void TVirtualStreamerInfo::Streamer(TBuffer &R__b)
258 {
259  TNamed::Streamer(R__b);
260 }
TClass::GetStreamerInfo
TVirtualStreamerInfo * GetStreamerInfo(Int_t version=0) const
returns a pointer to the TVirtualStreamerInfo object for version If the object does not exist,...
Definition: TClass.cxx:4509
TVirtualStreamerInfo::GetStreamMemberWise
static Bool_t GetStreamMemberWise()
Return whether the TStreamerInfos will save the collections in "member-wise" order whenever possible.
Definition: TVirtualStreamerInfo.cxx:155
TVirtualStreamerInfo::SetStreamMemberWise
static Bool_t SetStreamMemberWise(Bool_t enable=kTRUE)
Set whether the TStreamerInfos will save the collections in "member-wise" order whenever possible.
Definition: TVirtualStreamerInfo.cxx:243
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TObjArray
Definition: TObjArray.h:37
TVirtualStreamerInfo::fgOptimize
static Bool_t fgOptimize
Definition: TVirtualStreamerInfo.h:46
TNamed::operator=
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition: TNamed.cxx:51
TVirtualStreamerInfo::GetElementCounterStart
static const char * GetElementCounterStart(const char *dmTitle)
Given a comment/title declaring an array counter, for example:
Definition: TVirtualStreamerInfo.cxx:99
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TStreamerElement.h
TVirtualStreamerInfo::GetElementCounter
static TStreamerBasicType * GetElementCounter(const char *countName, TClass *cl)
Get pointer to a TStreamerBasicType in TClass *cl static function.
Definition: TVirtualStreamerInfo.cxx:117
TVirtualStreamerInfo::fgCanDelete
static Bool_t fgCanDelete
true if the StreamerInfo has been compiled (i.e. fully built, ready to use for streaming).
Definition: TVirtualStreamerInfo.h:45
TObject::Fatal
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:918
TVirtualStreamerInfo::operator=
TVirtualStreamerInfo & operator=(const TVirtualStreamerInfo &)
assignment operator
Definition: TVirtualStreamerInfo.cxx:60
TClass::GetClassVersion
Version_t GetClassVersion() const
Definition: TClass.h:377
TClass.h
TVirtualStreamerInfo::fgInfoFactory
static TVirtualStreamerInfo * fgInfoFactory
Definition: TVirtualStreamerInfo.h:48
TBuffer
Definition: TBuffer.h:43
TObjArray::At
TObject * At(Int_t idx) const
Definition: TObjArray.h:166
TString
Definition: TString.h:136
TSystem::AccessPathName
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1294
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TVirtualStreamerInfo
Definition: TVirtualStreamerInfo.h:37
bool
TROOT.h
TPluginHandler
Definition: TPluginManager.h:101
TVirtualStreamerInfo::Optimize
static void Optimize(Bool_t opt=kTRUE)
This is a static function.
Definition: TVirtualStreamerInfo.cxx:167
TSystem.h
gInterpreterMutex
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:43
h
#define h(i)
Definition: RSha256.hxx:124
TVirtualStreamerInfo::CanOptimize
static Bool_t CanOptimize()
static function returning true if optimization can be on
Definition: TVirtualStreamerInfo.cxx:86
TNamed
Definition: TNamed.h:29
TVirtualStreamerInfo::TVirtualStreamerInfo
TVirtualStreamerInfo()
Default constructor.
Definition: TVirtualStreamerInfo.cxx:37
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TClass::GetStreamerInfos
const TObjArray * GetStreamerInfos() const
Definition: TClass.h:443
R__LOCKGUARD
#define R__LOCKGUARD(mutex)
Definition: TVirtualMutex.h:104
TVirtualStreamerInfo::Factory
static TVirtualStreamerInfo * Factory()
Static function returning a pointer to a new TVirtualStreamerInfo object.
Definition: TVirtualStreamerInfo.cxx:177
TVirtualStreamerInfo::SetCanDelete
static void SetCanDelete(Bool_t opt=kTRUE)
This is a static function.
Definition: TVirtualStreamerInfo.cxx:220
TSystem::ExpandPathName
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1272
TVirtualStreamerInfo::IsCompiled
Bool_t IsCompiled() const
Definition: TVirtualStreamerInfo.h:156
TVirtualMutex.h
TVirtualStreamerInfo.h
gSystem
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
TPluginManager.h
TObjArray.h
TObjArray::FindObject
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
Definition: TObjArray.cxx:415
TInterpreter.h
TClass
Definition: TClass.h:80
TVirtualStreamerInfo::SetFactory
static void SetFactory(TVirtualStreamerInfo *factory)
static function: Set the StreamerInfo factory
Definition: TVirtualStreamerInfo.cxx:228
TStreamerBasicType
Definition: TStreamerElement.h:269
TVirtualStreamerInfo::CanDelete
static Bool_t CanDelete()
static function returning true if ReadBuffer can delete object
Definition: TVirtualStreamerInfo.cxx:78
TVirtualStreamerInfo::~TVirtualStreamerInfo
virtual ~TVirtualStreamerInfo()
Destructor.
Definition: TVirtualStreamerInfo.cxx:71
Class
void Class()
Definition: Class.C:29
TVirtualStreamerInfo::fgStreamMemberWise
static Bool_t fgStreamMemberWise
Definition: TVirtualStreamerInfo.h:47
TStreamerElement
Definition: TStreamerElement.h:33
TVirtualStreamerInfo::GetElements
virtual TObjArray * GetElements() const =0
gROOT
#define gROOT
Definition: TROOT.h:406
TError.h