Logo ROOT  
Reference Guide
TStreamerInfoActions.h
Go to the documentation of this file.
1// @(#)root/io:$Id$
2// Author: Philippe Canal 05/2010
3
4/*************************************************************************
5 * Copyright (C) 1995-2004, 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_TStreamerInfoActions
13#define ROOT_TStreamerInfoActions
14
15#include <vector>
16#include <ROOT/RMakeUnique.hxx>
17
18#include "TStreamerInfo.h"
19#include "TVirtualArray.h"
20#include <assert.h>
21
22/**
23\class TStreamerInfoActions::TConfiguration
24\ingroup IO
25*/
26
27namespace TStreamerInfoActions {
28
29 /// Base class of the Configurations.
31 protected:
32 public:
34 TVirtualStreamerInfo *fInfo; ///< TStreamerInfo form which the action is derived
35 UInt_t fElemId; ///< Identifier of the TStreamerElement
36 TCompInfo_t *fCompInfo;///< Access to compiled information (for legacy code)
37 Int_t fOffset; ///< Offset within the object
38 UInt_t fLength; ///< Number of element in a fixed length array.
39 public:
40 TConfiguration(TVirtualStreamerInfo *info, UInt_t id, TCompInfo_t *compinfo, Int_t offset) : fInfo(info), fElemId(id), fCompInfo(compinfo), fOffset(offset),fLength(1) {};
41 TConfiguration(TVirtualStreamerInfo *info, UInt_t id, TCompInfo_t *compinfo, Int_t offset, UInt_t length) : fInfo(info), fElemId(id), fCompInfo(compinfo), fOffset(offset),fLength(length) {};
42 virtual ~TConfiguration() {};
43
44 virtual void AddToOffset(Int_t delta);
45 virtual void SetMissing();
46
47 virtual TConfiguration *Copy() { return new TConfiguration(*this); }
48
49 virtual void Print() const;
50 virtual void PrintDebug(TBuffer &buffer, void *object) const;
51 };
52
53 /// Base class of the Configurations for the member wise looping routines.
55 public:
57 public:
58 TLoopConfiguration() = default;
60
61 // virtual void PrintDebug(TBuffer &buffer, void *object) const;
62 virtual ~TLoopConfiguration() {};
63 virtual void Print() const;
64 virtual void *GetFirstAddress(void *start, const void *end) const = 0;
65 virtual TLoopConfiguration* Copy() const = 0; // { return new TLoopConfiguration(*this); }
67 };
68
70
71 typedef Int_t (*TStreamerInfoAction_t)(TBuffer &buf, void *obj, const TConfiguration *conf);
72 typedef Int_t (*TStreamerInfoVecPtrLoopAction_t)(TBuffer &buf, void *iter, const void *end, const TConfiguration *conf);
73 typedef Int_t (*TStreamerInfoLoopAction_t)(TBuffer &buf, void *iter, const void *end, const TLoopConfiguration *loopconf, const TConfiguration *conf);
74
75 class TConfiguredAction : public TObject {
76 public:
77 union {
81 };
83 private:
84 // assignment operator must be the default because the 'copy' constructor is actually a move constructor and must be used.
85 public:
88 {
89 // WARNING: Technically this is a move constructor ...
90 const_cast<TConfiguredAction&>(rval).fConfiguration = 0;
91 }
93 {
94 // WARNING: Technically this is a move assignment!.
95
96 TConfiguredAction tmp(rval); // this does a move.
97 TObject::operator=(tmp); // we are missing TObject::Swap
100 return *this;
101 };
102
104 {
105 // Usual constructor.
106 }
108 {
109 // Usual constructor.
110 }
112 {
113 // Usual constructor.
114 }
116 // Usual destructor.
117 // Idea: the configuration ownership might be moved to a single list so that
118 // we can shared them between the optimized and non-optimized list of actions.
119 delete fConfiguration;
120 }
121 void PrintDebug(TBuffer &buffer, void *object) const;
122
123 inline Int_t operator()(TBuffer &buffer, void *object) const {
124 return fAction(buffer, object, fConfiguration);
125 }
126
127 inline Int_t operator()(TBuffer &buffer, void *start_collection, const void *end_collection) const {
128 return fVecPtrLoopAction(buffer, start_collection, end_collection, fConfiguration);
129 }
130
131 inline Int_t operator()(TBuffer &buffer, void *start_collection, const void *end_collection, const TLoopConfiguration *loopconf) const {
132 return fLoopAction(buffer, start_collection, end_collection, loopconf, fConfiguration);
133 }
134
135 ClassDef(TConfiguredAction,0); // A configured action
136 };
137
138 struct TIDNode;
139 using TIDs = std::vector<TIDNode>;
140
141 // Hold information about unfolded/extracted StreamerElement for
142 // a sub-object
143 struct TNestedIDs {
144 TNestedIDs() = default;
145 TNestedIDs(TStreamerInfo *info, Int_t offset) : fInfo(info), fOffset(offset) {}
148 delete fOnfileObject;
149 }
150 TStreamerInfo *fInfo = nullptr; ///< Not owned.
155 };
156
157 // A 'node' in the list of StreamerElement ID, either
158 // the index of the element in the current streamerInfo
159 // or a set of unfolded/extracted StreamerElement for a sub-object.
160 struct TIDNode {
161 TIDNode() = default;
162 TIDNode(Int_t id) : fElemID(id), fElement(nullptr), fInfo(nullptr) {}
163 TIDNode(TStreamerInfo *info, Int_t offset) : fElemID(-1), fElement(nullptr), fInfo(nullptr) {
164 fNestedIDs = std::make_unique<TNestedIDs>(info, offset);
165 }
169 std::unique_ptr<TNestedIDs> fNestedIDs;
170 };
171
172 typedef std::vector<TConfiguredAction> ActionContainer_t;
173 class TActionSequence : public TObject {
175 public:
176 enum class EStatusBits {
178 };
179
180 struct SequencePtr;
181 using SequenceGetter_t = SequencePtr(*)(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *originalClass);
182
184 : fStreamerInfo(info), fLoopConfig(0)
185 {
186 if (isForVecPtr)
188 fActions.reserve(maxdata);
189 };
191 delete fLoopConfig;
192 }
193
194 template <typename action_t>
195 void AddAction( action_t action, TConfiguration *conf ) {
196 fActions.push_back( TConfiguredAction(action, conf) );
197 }
198 void AddAction(const TConfiguredAction &action ) {
199 fActions.push_back( action );
200 }
201
204 }
205
206 TVirtualStreamerInfo *fStreamerInfo; ///< StreamerInfo used to derive these actions.
207 TLoopConfiguration *fLoopConfig; ///< If this is a bundle of memberwise streaming action, this configures the looping
209
210 void AddToOffset(Int_t delta);
211 void SetMissing();
212
216 TActionSequence *CreateSubSequence(const std::vector<Int_t> &element_ids, size_t offset);
217
218 TActionSequence *CreateSubSequence(const TIDs &element_ids, size_t offset, SequenceGetter_t create);
219 void AddToSubSequence(TActionSequence *sequence, const TIDs &element_ids, Int_t offset, SequenceGetter_t create);
220
221 void Print(Option_t * = "") const;
222
223 // Maybe owner unique_ptr
224 struct SequencePtr {
227
228 SequencePtr() = default;
229
231 from.fOwner = false;
232 }
233
235
237 if (fOwner) delete fSequence;
238 }
239
240 // Accessor to the pointee.
242 return *fSequence;
243 }
244
245 // Accessor to the pointee
247 return fSequence;
248 }
249
250 // Return true is the pointee is not nullptr.
251 operator bool() {
252 return fSequence != nullptr;
253 }
254 };
255
256 // SequenceGetter_t implementations
257
258 static SequencePtr ReadMemberWiseActionsCollectionGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
259 auto seq = info->GetReadMemberWiseActions(kTRUE);
260 return {seq, kFALSE};
261 }
263 auto seq = collectionProxy->GetConversionReadMemberWiseActions(originalClass, info->GetClassVersion());
264 return {seq, kFALSE};
265 }
266 static SequencePtr ReadMemberWiseActionsViaProxyGetter(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass * /* originalClass */) {
267 auto seq = collectionProxy->GetReadMemberWiseActions(info->GetClassVersion());
268 return {seq, kFALSE};
269 }
272 return {seq, kTRUE};
273 }
274 // Creator5() = Creator1;
275 static SequencePtr ReadMemberWiseActionsGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
276 auto seq = info->GetReadMemberWiseActions(kFALSE);
277 return {seq, kFALSE};
278 }
279
280 static SequencePtr WriteMemberWiseActionsCollectionGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
281 auto seq = info->GetWriteMemberWiseActions(kTRUE);
282 return {seq, kFALSE};
283 }
285 auto seq = collectionProxy->GetWriteMemberWiseActions();
286 return {seq, kFALSE};
287 }
290 return {seq, kTRUE};
291 }
292 // Creator5() = Creator1;
293 static SequencePtr WriteMemberWiseActionsGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
294 auto seq = info->GetWriteMemberWiseActions(kFALSE);
295 return {seq, kFALSE};
296 }
298 };
299
300}
301
302#endif // ROOT_TStreamerInfoActions
303
304
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassDef(name, id)
Definition: Rtypes.h:326
#define BIT(n)
Definition: Rtypes.h:83
XFontStruct * id
Definition: TGX11.cxx:108
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:75
Mother of all ROOT objects.
Definition: TObject.h:37
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.h:268
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:694
EStatusBits
Definition: TObject.h:57
static SequencePtr WriteMemberWiseActionsViaProxyGetter(TStreamerInfo *, TVirtualCollectionProxy *collectionProxy, TClass *)
static TActionSequence * CreateReadMemberWiseActions(TVirtualStreamerInfo *info, TVirtualCollectionProxy &proxy)
Create the bundle of the actions necessary for the streaming memberwise of the content described by '...
void Print(Option_t *="") const
This method must be overridden when a class wants to print itself.
TLoopConfiguration * fLoopConfig
If this is a bundle of memberwise streaming action, this configures the looping.
void AddAction(const TConfiguredAction &action)
static SequencePtr WriteMemberWiseActionsGetter(TStreamerInfo *info, TVirtualCollectionProxy *, TClass *)
static SequencePtr ConversionReadMemberWiseActionsViaProxyGetter(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *originalClass)
static SequencePtr WriteMemberWiseActionsCollectionCreator(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *)
TVirtualStreamerInfo * fStreamerInfo
StreamerInfo used to derive these actions.
static SequencePtr ReadMemberWiseActionsCollectionCreator(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *)
static SequencePtr ReadMemberWiseActionsGetter(TStreamerInfo *info, TVirtualCollectionProxy *, TClass *)
TActionSequence(TVirtualStreamerInfo *info, UInt_t maxdata, Bool_t isForVecPtr=kFALSE)
static TActionSequence * CreateWriteMemberWiseActions(TVirtualStreamerInfo *info, TVirtualCollectionProxy &proxy)
Create the bundle of the actions necessary for the streaming memberwise of the content described by '...
SequencePtr(*)(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *originalClass) SequenceGetter_t
static SequencePtr WriteMemberWiseActionsCollectionGetter(TStreamerInfo *info, TVirtualCollectionProxy *, TClass *)
void AddToSubSequence(TActionSequence *sequence, const TIDs &element_ids, Int_t offset, SequenceGetter_t create)
TActionSequence * CreateSubSequence(const std::vector< Int_t > &element_ids, size_t offset)
static SequencePtr ReadMemberWiseActionsCollectionGetter(TStreamerInfo *info, TVirtualCollectionProxy *, TClass *)
void AddAction(action_t action, TConfiguration *conf)
static SequencePtr ReadMemberWiseActionsViaProxyGetter(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *)
Base class of the Configurations.
virtual void PrintDebug(TBuffer &buffer, void *object) const
TVirtualStreamerInfo * fInfo
TStreamerInfo form which the action is derived.
Int_t fOffset
Offset within the object.
TConfiguration(TVirtualStreamerInfo *info, UInt_t id, TCompInfo_t *compinfo, Int_t offset, UInt_t length)
TCompInfo_t * fCompInfo
Access to compiled information (for legacy code)
UInt_t fLength
Number of element in a fixed length array.
TConfiguration(TVirtualStreamerInfo *info, UInt_t id, TCompInfo_t *compinfo, Int_t offset)
UInt_t fElemId
Identifier of the TStreamerElement.
TStreamerInfo::TCompInfo_t TCompInfo_t
Int_t operator()(TBuffer &buffer, void *start_collection, const void *end_collection, const TLoopConfiguration *loopconf) const
TStreamerInfoVecPtrLoopAction_t fVecPtrLoopAction
Int_t operator()(TBuffer &buffer, void *object) const
TConfiguredAction & operator=(const TConfiguredAction &rval)
Int_t operator()(TBuffer &buffer, void *start_collection, const void *end_collection) const
TConfiguredAction(TStreamerInfoAction_t action, TConfiguration *conf)
TConfiguredAction(TStreamerInfoLoopAction_t action, TConfiguration *conf)
TConfiguredAction(const TConfiguredAction &rval)
TConfiguredAction(TStreamerInfoVecPtrLoopAction_t action, TConfiguration *conf)
void PrintDebug(TBuffer &buffer, void *object) const
Base class of the Configurations for the member wise looping routines.
virtual void * GetFirstAddress(void *start, const void *end) const =0
TLoopConfiguration(TVirtualCollectionProxy *proxy)
virtual TVirtualCollectionProxy * GetCollectionProxy() const
virtual TLoopConfiguration * Copy() const =0
Describe Streamer information for one class version.
Definition: TStreamerInfo.h:43
TStreamerInfoActions::TActionSequence * GetWriteMemberWiseActions(Bool_t forCollection)
Int_t GetClassVersion() const
TStreamerInfoActions::TActionSequence * GetReadMemberWiseActions(Bool_t forCollection)
Wrapper around an object and giving indirect access to its content even if the object is not of a cla...
Definition: TVirtualArray.h:26
virtual TStreamerInfoActions::TActionSequence * GetReadMemberWiseActions(Int_t version)=0
virtual TStreamerInfoActions::TActionSequence * GetWriteMemberWiseActions()=0
void *(* Next_t)(void *iter, const void *end)
virtual TStreamerInfoActions::TActionSequence * GetConversionReadMemberWiseActions(TClass *oldClass, Int_t version)=0
Abstract Interface class describing Streamer information for one class.
void swap(RDirectoryEntry &e1, RDirectoryEntry &e2) noexcept
Int_t(* TStreamerInfoAction_t)(TBuffer &buf, void *obj, const TConfiguration *conf)
Int_t(* TStreamerInfoVecPtrLoopAction_t)(TBuffer &buf, void *iter, const void *end, const TConfiguration *conf)
std::vector< TIDNode > TIDs
Int_t(* TStreamerInfoLoopAction_t)(TBuffer &buf, void *iter, const void *end, const TLoopConfiguration *loopconf, const TConfiguration *conf)
std::vector< TConfiguredAction > ActionContainer_t
TVirtualCollectionProxy::Next_t Next_t
TStreamerInfoActions::TActionSequence & operator*() const
TStreamerInfoActions::TActionSequence * fSequence
SequencePtr(TStreamerInfoActions::TActionSequence *sequence, Bool_t owner)
TStreamerInfoActions::TActionSequence * operator->() const
TIDNode(TStreamerInfo *info, Int_t offset)
std::unique_ptr< TNestedIDs > fNestedIDs
TNestedIDs(TStreamerInfo *info, Int_t offset)