Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TStreamerInfo.h
Go to the documentation of this file.
1 // @(#)root/io:$Id$
2 // Author: Rene Brun 12/10/2000
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TStreamerInfo
13 #define ROOT_TStreamerInfo
14 
15 #include <atomic>
16 
17 #include "TVirtualStreamerInfo.h"
18 
19 #include "ThreadLocalStorage.h"
20 
22 
23 /**
24 \class TStreamerInfo
25 \ingroup IO
26 Describe Streamer information for one class version
27 */
28 
29 class TFile;
30 class TClass;
31 class TClonesArray;
32 class TDataMember;
33 class TMemberStreamer;
34 class TStreamerElement;
35 class TStreamerBasicType;
36 class TClassStreamer;
37 class TVirtualArray;
38 namespace ROOT { namespace Detail { class TCollectionProxyInfo; } }
39 namespace ROOT { class TSchemaRule; }
40 
41 namespace TStreamerInfoActions { class TActionSequence; }
42 
43 class TStreamerInfo : public TVirtualStreamerInfo {
44 
45  class TCompInfo {
46  // Class used to cache information (see fComp)
47  private:
48  // TCompInfo(const TCompInfo&) = default;
49  // TCompInfo& operator=(const TCompInfo&) = default;
50  public:
51  Int_t fType;
52  Int_t fNewType;
53  Int_t fOffset;
54  Int_t fLength;
55  TStreamerElement *fElem; ///< Not Owned
56  ULong_t fMethod;
57  TClass *fClass; ///< Not Owned
58  TClass *fNewClass; ///< Not Owned
59  TString fClassName;
60  TMemberStreamer *fStreamer; ///< Not Owned
61  TCompInfo() : fType(-1), fNewType(0), fOffset(0), fLength(0), fElem(0), fMethod(0),
62  fClass(0), fNewClass(0), fClassName(), fStreamer(0) {};
63  ~TCompInfo() {};
64  void Update(const TClass *oldcl, TClass *newcl);
65  };
66  friend class TStreamerInfoActions::TActionSequence;
67 
68 public:
69  // make the opaque pointer public.
70  typedef TCompInfo TCompInfo_t;
71 
72 protected:
73  //---------------------------------------------------------------------------
74  // Adapter class used to handle streaming collection of pointers
75  //---------------------------------------------------------------------------
76  class TPointerCollectionAdapter
77  {
78  public:
79  TPointerCollectionAdapter( TVirtualCollectionProxy *proxy ):
80  fProxy( proxy ) {}
81 
82  char* operator[]( UInt_t idx ) const
83  {
84  char **el = (char**)fProxy->At(idx);
85  return *el;
86  }
87  private:
88  TVirtualCollectionProxy *fProxy;
89  };
90 
91 private:
92  UInt_t fCheckSum; ///<Checksum of original class
93  Int_t fClassVersion; ///<Class version identifier
94  Int_t fOnFileClassVersion;///<!Class version identifier as stored on file.
95  Int_t fNumber; ///<!Unique identifier
96  Int_t fSize; ///<!size of the persistent class
97  Int_t fNdata; ///<!number of optimized elements
98  Int_t fNfulldata; ///<!number of elements
99  Int_t fNslots; ///<!total numbrer of slots in fComp.
100  TCompInfo *fComp; ///<![fNslots with less than fElements->GetEntries()*1.5 used] Compiled info
101  TCompInfo **fCompOpt; ///<![fNdata]
102  TCompInfo **fCompFull; ///<![fElements->GetEntries()]
103  TClass *fClass; ///<!pointer to class
104  TObjArray *fElements; ///<Array of TStreamerElements
105  Version_t fOldVersion; ///<! Version of the TStreamerInfo object read from the file
106  Int_t fNVirtualInfoLoc; ///<! Number of virtual info location to update.
107  ULong_t *fVirtualInfoLoc; ///<![fNVirtualInfoLoc] Location of the pointer to the TStreamerInfo inside the object (when emulated)
108  std::atomic<ULong_t> fLiveCount; ///<! Number of outstanding pointer to this StreamerInfo.
109  TStreamerInfoActions::TActionSequence *fReadObjectWise; ///<! List of read action resulting from the compilation.
110  TStreamerInfoActions::TActionSequence *fReadMemberWise; ///<! List of read action resulting from the compilation for use in member wise streaming.
111  TStreamerInfoActions::TActionSequence *fReadMemberWiseVecPtr; ///<! List of read action resulting from the compilation for use in member wise streaming.
112  TStreamerInfoActions::TActionSequence *fReadText; ///<! List of text read action resulting from the compilation, used for JSON.
113  TStreamerInfoActions::TActionSequence *fWriteObjectWise; ///<! List of write action resulting from the compilation.
114  TStreamerInfoActions::TActionSequence *fWriteMemberWise; ///<! List of write action resulting from the compilation for use in member wise streaming.
115  TStreamerInfoActions::TActionSequence *fWriteMemberWiseVecPtr; ///<! List of write action resulting from the compilation for use in member wise streaming.
116  TStreamerInfoActions::TActionSequence *fWriteText; ///<! List of text write action resulting for the compilation, used for JSON.
117 
118  static std::atomic<Int_t> fgCount; ///<Number of TStreamerInfo instances
119 
120  template <typename T> static T GetTypedValueAux(Int_t type, void *ladd, int k, Int_t len);
121  static void PrintValueAux(char *ladd, Int_t atype, TStreamerElement * aElement, Int_t aleng, Int_t *count);
122 
123  UInt_t GenerateIncludes(FILE *fp, char *inclist, const TList *extrainfos);
124  void GenerateDeclaration(FILE *fp, FILE *sfp, const TList *subClasses, Bool_t top = kTRUE);
125  void InsertArtificialElements(std::vector<const ROOT::TSchemaRule*> &rules);
126  void DestructorImpl(void* p, Bool_t dtorOnly);
127 
128 private:
129  TStreamerInfo(const TStreamerInfo&) = delete; // TStreamerInfo are not copiable. Not Implemented.
130  TStreamerInfo& operator=(const TStreamerInfo&) = delete; // TStreamerInfo are not copiable. Not Implemented.
131  void AddReadAction(TStreamerInfoActions::TActionSequence *readSequence, Int_t index, TCompInfo *compinfo);
132  void AddWriteAction(TStreamerInfoActions::TActionSequence *writeSequence, Int_t index, TCompInfo *compinfo);
133  void AddReadTextAction(TStreamerInfoActions::TActionSequence *readSequence, Int_t index, TCompInfo *compinfo);
134  void AddWriteTextAction(TStreamerInfoActions::TActionSequence *writeSequence, Int_t index, TCompInfo *compinfo);
135  void AddReadMemberWiseVecPtrAction(TStreamerInfoActions::TActionSequence *readSequence, Int_t index, TCompInfo *compinfo);
136  void AddWriteMemberWiseVecPtrAction(TStreamerInfoActions::TActionSequence *writeSequence, Int_t index, TCompInfo *compinfo);
137 
138 public:
139 
140  /// Status bits
141  /// See TVirtualStreamerInfo::EStatusBits for the values.
142 
143  /// EReadWrite Enumerator
144  /// | Enum Constant | Description |
145  /// |-------------|--------------------|
146  /// | kBase | Base class element |
147  /// | kOffsetL | Fixed size array |
148  /// | kOffsetP | Pointer to object |
149  /// | kCounter | Counter for array size |
150  /// | kCharStar | Pointer to array of char |
151  /// | kLegacyChar | Equal to TDataType's kchar |
152  /// | kBits | TObject::fBits in case of a referenced object |
153  /// | kObject | Class derived from TObject, or for TStreamerSTL::fCtype non-pointer elements |
154  /// | kObjectp | Class* derived from TObject and with comment field //->Class, or for TStreamerSTL::fCtype: pointer elements |
155  /// | kObjectP | Class* derived from TObject and with NO comment field //->Class |
156  /// | kAny | Class not derived from TObject |
157  /// | kAnyp | Class* not derived from TObject with comment field //->Class |
158  /// | kAnyP | Class* not derived from TObject with NO comment field //->Class |
159  /// | kAnyPnoVT | Class* not derived from TObject with NO comment field //->Class and Class has NO virtual table |
160  /// | kSTLp | Pointer to STL container |
161  /// | kTString | TString, special case |
162  /// | kTObject | TObject, special case |
163  /// | kTNamed | TNamed , special case |
164  /// | kCache | Cache the value in memory than is not part of the object but is accessible via a SchemaRule |
165  enum EReadWrite {
166  kBase = 0, kOffsetL = 20, kOffsetP = 40, kCounter = 6, kCharStar = 7,
167  kChar = 1, kShort = 2, kInt = 3, kLong = 4, kFloat = 5,
168  kDouble = 8, kDouble32= 9,
169  kLegacyChar = 10, /// Equal to TDataType's kchar
170  kUChar = 11, kUShort = 12, kUInt = 13, kULong = 14, kBits = 15,
171  kLong64 = 16, kULong64 = 17, kBool = 18, kFloat16 = 19,
172  kObject = 61, kAny = 62, kObjectp = 63, kObjectP = 64, kTString = 65,
173  kTObject = 66, kTNamed = 67, kAnyp = 68, kAnyP = 69, kAnyPnoVT = 70,
174  kSTLp = 71,
175  kSkip = 100, kSkipL = 120, kSkipP = 140,
176  kConv = 200, kConvL = 220, kConvP = 240,
177  kSTL = 300, kSTLstring = 365,
178  kStreamer = 500, kStreamLoop = 501,
179  kCache = 600, /// Cache the value in memory than is not part of the object but is accessible via a SchemaRule
180  kArtificial = 1000,
181  kCacheNew = 1001,
182  kCacheDelete = 1002,
183  kNeedObjectForVirtualBaseClass = 99997,
184  kMissing = 99999
185  };
186 
187  TStreamerInfo();
188  TStreamerInfo(TClass *cl);
189  virtual ~TStreamerInfo();
190  void Build();
191  void BuildCheck(TFile *file = 0);
192  void BuildEmulated(TFile *file);
193  void BuildOld();
194  virtual Bool_t BuildFor( const TClass *cl );
195  void CallShowMembers(const void* obj, TMemberInspector &insp, Bool_t isTransient) const;
196  void Clear(Option_t *);
197  TObject *Clone(const char *newname = "") const;
198  Bool_t CompareContent(TClass *cl,TVirtualStreamerInfo *info, Bool_t warn, Bool_t complete, TFile *file);
199  void Compile();
200  void ComputeSize();
201  void ForceWriteInfo(TFile *file, Bool_t force=kFALSE);
202  Int_t GenerateHeaderFile(const char *dirname, const TList *subClasses = 0, const TList *extrainfos = 0);
203  TClass *GetActualClass(const void *obj) const;
204  TClass *GetClass() const {return fClass;}
205  UInt_t GetCheckSum() const {return fCheckSum;}
206  UInt_t GetCheckSum(TClass::ECheckSum code) const;
207  Int_t GetClassVersion() const {return fClassVersion;}
208  Int_t GetDataMemberOffset(TDataMember *dm, TMemberStreamer *&streamer) const;
209  TObjArray *GetElements() const {return fElements;}
210  TStreamerElement *GetElem(Int_t id) const {return fComp[id].fElem;} // Return the element for the list of optimized elements (max GetNdata())
211  TStreamerElement *GetElement(Int_t id) const {return (TStreamerElement*)fElements->At(id);} // Return the element for the complete list of elements (max GetElements()->GetEntries())
212  Int_t GetElementOffset(Int_t id) const {return fCompFull[id]->fOffset;}
213  TStreamerInfoActions::TActionSequence *GetReadMemberWiseActions(Bool_t forCollection) { return forCollection ? fReadMemberWiseVecPtr : fReadMemberWise; }
214  TStreamerInfoActions::TActionSequence *GetReadObjectWiseActions() { return fReadObjectWise; }
215  TStreamerInfoActions::TActionSequence *GetReadTextActions() { return fReadText; }
216  TStreamerInfoActions::TActionSequence *GetWriteMemberWiseActions(Bool_t forCollection) { return forCollection ? fWriteMemberWiseVecPtr : fWriteMemberWise; }
217  TStreamerInfoActions::TActionSequence *GetWriteObjectWiseActions() { return fWriteObjectWise; }
218  TStreamerInfoActions::TActionSequence *GetWriteTextActions() { return fWriteText; }
219  Int_t GetNdata() const {return fNdata;}
220  Int_t GetNelement() const { return fElements->GetEntries(); }
221  Int_t GetNumber() const {return fNumber;}
222  Int_t GetLength(Int_t id) const {return fComp[id].fLength;}
223  ULong_t GetMethod(Int_t id) const {return fComp[id].fMethod;}
224  Int_t GetNewType(Int_t id) const {return fComp[id].fNewType;}
225  Int_t GetOffset(const char *) const;
226  Int_t GetOffset(Int_t id) const {return fComp[id].fOffset;}
227  Version_t GetOldVersion() const {return fOldVersion;}
228  Int_t GetOnFileClassVersion() const {return fOnFileClassVersion;}
229  Int_t GetSize() const;
230  Int_t GetSizeElements() const;
231  TStreamerElement *GetStreamerElement(const char*datamember, Int_t& offset) const;
232  TStreamerElement *GetStreamerElementReal(Int_t i, Int_t j) const;
233  Int_t GetType(Int_t id) const {return fComp[id].fType;}
234  template <typename T> T GetTypedValue(char *pointer, Int_t i, Int_t j, Int_t len) const;
235  template <typename T> T GetTypedValueClones(TClonesArray *clones, Int_t i, Int_t j, Int_t k, Int_t eoffset) const;
236  template <typename T> T GetTypedValueSTL(TVirtualCollectionProxy *cont, Int_t i, Int_t j, Int_t k, Int_t eoffset) const;
237  template <typename T> T GetTypedValueSTLP(TVirtualCollectionProxy *cont, Int_t i, Int_t j, Int_t k, Int_t eoffset) const;
238  Double_t GetValue(char *pointer, Int_t i, Int_t j, Int_t len) const { return GetTypedValue<Double_t>(pointer, i, j, len); }
239  Double_t GetValueClones(TClonesArray *clones, Int_t i, Int_t j, Int_t k, Int_t eoffset) const { return GetTypedValueClones<Double_t>(clones, i, j, k, eoffset); }
240  Double_t GetValueSTL(TVirtualCollectionProxy *cont, Int_t i, Int_t j, Int_t k, Int_t eoffset) const { return GetTypedValueSTL<Double_t>(cont, i, j, k, eoffset); }
241  Double_t GetValueSTLP(TVirtualCollectionProxy *cont, Int_t i, Int_t j, Int_t k, Int_t eoffset) const { return GetTypedValueSTLP<Double_t>(cont, i, j, k, eoffset); }
242  void ls(Option_t *option="") const;
243  Bool_t MatchLegacyCheckSum(UInt_t checksum) const;
244  TVirtualStreamerInfo *NewInfo(TClass *cl) {return new TStreamerInfo(cl);}
245  void *New(void *obj = 0);
246  void *NewArray(Long_t nElements, void* ary = 0);
247  void Destructor(void* p, Bool_t dtorOnly = kFALSE);
248  void DeleteArray(void* p, Bool_t dtorOnly = kFALSE);
249  void PrintValue(const char *name, char *pointer, Int_t i, Int_t len, Int_t lenmax=1000) const;
250  void PrintValueClones(const char *name, TClonesArray *clones, Int_t i, Int_t eoffset, Int_t lenmax=1000) const;
251  void PrintValueSTL(const char *name, TVirtualCollectionProxy *cont, Int_t i, Int_t eoffset, Int_t lenmax=1000) const;
252 
253  template <class T>
254  Int_t ReadBuffer(TBuffer &b, const T &arrptr, TCompInfo *const*const compinfo, Int_t first, Int_t last, Int_t narr=1,Int_t eoffset=0,Int_t mode=0);
255  template <class T>
256  Int_t ReadBufferSkip(TBuffer &b, const T &arrptr, const TCompInfo *compinfo,Int_t kase, TStreamerElement *aElement, Int_t narr, Int_t eoffset);
257  template <class T>
258  Int_t ReadBufferConv(TBuffer &b, const T &arrptr, const TCompInfo *compinfo,Int_t kase, TStreamerElement *aElement, Int_t narr, Int_t eoffset);
259  template <class T>
260  Int_t ReadBufferArtificial(TBuffer &b, const T &arrptr, TStreamerElement *aElement, Int_t narr, Int_t eoffset);
261 
262  Int_t ReadBufferClones(TBuffer &b, TClonesArray *clones, Int_t nc, Int_t first, Int_t eoffset);
263  Int_t ReadBufferSTL(TBuffer &b, TVirtualCollectionProxy *cont, Int_t nc, Int_t eoffset, Bool_t v7 = kTRUE );
264  void SetCheckSum(UInt_t checksum) {fCheckSum = checksum;}
265  void SetClass(TClass *cl) {fClass = cl;}
266  void SetClassVersion(Int_t vers) {fClassVersion=vers;}
267  void SetOnFileClassVersion(Int_t vers) {fOnFileClassVersion=vers;}
268  void TagFile(TFile *fFile);
269 private:
270  // Try to remove those functions from the public interface.
271  Int_t WriteBuffer(TBuffer &b, char *pointer, Int_t first);
272  Int_t WriteBufferClones(TBuffer &b, TClonesArray *clones, Int_t nc, Int_t first, Int_t eoffset);
273  Int_t WriteBufferSTL (TBuffer &b, TVirtualCollectionProxy *cont, Int_t nc);
274  Int_t WriteBufferSTLPtrs( TBuffer &b, TVirtualCollectionProxy *cont, Int_t nc, Int_t first, Int_t eoffset);
275 public:
276  virtual void Update(const TClass *oldClass, TClass *newClass);
277 
278  virtual TVirtualCollectionProxy *GenEmulatedProxy(const char* class_name, Bool_t silent);
279  virtual TClassStreamer *GenEmulatedClassStreamer(const char* class_name, Bool_t silent);
280  virtual TVirtualCollectionProxy *GenExplicitProxy( const ::ROOT::Detail::TCollectionProxyInfo &info, TClass *cl );
281  virtual TClassStreamer *GenExplicitClassStreamer( const ::ROOT::Detail::TCollectionProxyInfo &info, TClass *cl );
282 
283  static TStreamerElement *GetCurrentElement();
284 
285 public:
286  // For access by the StreamerInfoActions.
287  template <class T>
288  Int_t WriteBufferAux (TBuffer &b, const T &arr, TCompInfo *const*const compinfo, Int_t first, Int_t last, Int_t narr,Int_t eoffset,Int_t mode);
289 
290  //WARNING this class version must be the same as TVirtualStreamerInfo
291  ClassDef(TStreamerInfo,9) //Streamer information for one class version
292 };
293 
294 
295 #endif