Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <memory>
16#include <vector>
17
18#include "TStreamerInfo.h"
19#include "TVirtualArray.h"
20
21/**
22\class TStreamerInfoActions::TConfiguration
23\ingroup IO
24*/
25
26namespace TStreamerInfoActions {
27
28 /// Base class of the Configurations.
30 protected:
31 public:
33 TVirtualStreamerInfo *fInfo; ///< TStreamerInfo form which the action is derived
34 UInt_t fElemId; ///< Identifier of the TStreamerElement
35 TCompInfo_t *fCompInfo;///< Access to compiled information (for legacy code)
36 Int_t fOffset; ///< Offset within the object
37 UInt_t fLength; ///< Number of element in a fixed length array.
38 public:
39 TConfiguration(TVirtualStreamerInfo *info, UInt_t id, TCompInfo_t *compinfo, Int_t offset) : fInfo(info), fElemId(id), fCompInfo(compinfo), fOffset(offset),fLength(1) {};
40 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) {};
41 virtual ~TConfiguration() {};
42
43 virtual void AddToOffset(Int_t delta);
44 virtual void SetMissing();
45
46 virtual TConfiguration *Copy() { return new TConfiguration(*this); }
47
48 virtual void Print() const;
49 virtual void PrintDebug(TBuffer &buffer, void *object) const;
50 };
51
52 /// Base class of the Configurations for the member wise looping routines.
54 public:
56 public:
57 TLoopConfiguration() = default;
59
60 // virtual void PrintDebug(TBuffer &buffer, void *object) const;
61 virtual ~TLoopConfiguration() {};
62 virtual void Print() const;
63 virtual void *GetFirstAddress(void *start, const void *end) const = 0;
64 virtual TLoopConfiguration* Copy() const = 0; // { return new TLoopConfiguration(*this); }
66 };
67
69
70 typedef Int_t (*TStreamerInfoAction_t)(TBuffer &buf, void *obj, const TConfiguration *conf);
71 typedef Int_t (*TStreamerInfoVecPtrLoopAction_t)(TBuffer &buf, void *iter, const void *end, const TConfiguration *conf);
72 typedef Int_t (*TStreamerInfoLoopAction_t)(TBuffer &buf, void *iter, const void *end, const TLoopConfiguration *loopconf, const TConfiguration *conf);
73
74 class TConfiguredAction : public TObject {
75 public:
76 union {
80 };
82 private:
83 // assignment operator must be the default because the 'copy' constructor is actually a move constructor and must be used.
84 public:
87 {
88 // WARNING: Technically this is a move constructor ...
89 const_cast<TConfiguredAction&>(rval).fConfiguration = 0;
90 }
92 {
93 // WARNING: Technically this is a move assignment!.
94
95 TConfiguredAction tmp(rval); // this does a move.
96 TObject::operator=(tmp); // we are missing TObject::Swap
97 std::swap(fAction,tmp.fAction);
98 std::swap(fConfiguration,tmp.fConfiguration);
99 return *this;
100 };
101
103 {
104 // Usual constructor.
105 }
107 {
108 // Usual constructor.
109 }
111 {
112 // Usual constructor.
113 }
115 // Usual destructor.
116 // Idea: the configuration ownership might be moved to a single list so that
117 // we can shared them between the optimized and non-optimized list of actions.
118 delete fConfiguration;
119 }
120 void PrintDebug(TBuffer &buffer, void *object) const;
121
122 inline Int_t operator()(TBuffer &buffer, void *object) const {
123 return fAction(buffer, object, fConfiguration);
124 }
125
126 inline Int_t operator()(TBuffer &buffer, void *start_collection, const void *end_collection) const {
127 return fVecPtrLoopAction(buffer, start_collection, end_collection, fConfiguration);
128 }
129
130 inline Int_t operator()(TBuffer &buffer, void *start_collection, const void *end_collection, const TLoopConfiguration *loopconf) const {
131 return fLoopAction(buffer, start_collection, end_collection, loopconf, fConfiguration);
132 }
133
134 ClassDef(TConfiguredAction,0); // A configured action
135 };
136
137 struct TIDNode;
138 using TIDs = std::vector<TIDNode>;
139
140 // Hold information about unfolded/extracted StreamerElement for
141 // a sub-object
142 struct TNestedIDs {
143 TNestedIDs() = default;
144 TNestedIDs(TStreamerInfo *info, Int_t offset) : fInfo(info), fOffset(offset) {}
147 delete fOnfileObject;
148 }
149 TStreamerInfo *fInfo = nullptr; ///< Not owned.
154 };
155
156 // A 'node' in the list of StreamerElement ID, either
157 // the index of the element in the current streamerInfo
158 // or a set of unfolded/extracted StreamerElement for a sub-object.
159 struct TIDNode {
160 TIDNode() = default;
161 TIDNode(Int_t id) : fElemID(id), fElement(nullptr), fInfo(nullptr) {}
162 TIDNode(TStreamerInfo *info, Int_t offset) : fElemID(-1), fElement(nullptr), fInfo(nullptr) {
163 fNestedIDs = std::make_unique<TNestedIDs>(info, offset);
164 }
168 std::unique_ptr<TNestedIDs> fNestedIDs;
169 };
170
171 typedef std::vector<TConfiguredAction> ActionContainer_t;
172 class TActionSequence : public TObject {
174 public:
175 enum class EStatusBits {
177 };
178
179 struct SequencePtr;
180 using SequenceGetter_t = SequencePtr(*)(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *originalClass);
181
183 : fStreamerInfo(info), fLoopConfig(0)
184 {
185 if (isForVecPtr)
187 fActions.reserve(maxdata);
188 };
190 delete fLoopConfig;
191 }
192
193 template <typename action_t>
194 void AddAction( action_t action, TConfiguration *conf ) {
195 fActions.emplace_back( action, conf );
196 }
197 void AddAction(const TConfiguredAction &action ) {
198 fActions.push_back( action );
199 }
200
203 }
204
205 TVirtualStreamerInfo *fStreamerInfo; ///< StreamerInfo used to derive these actions.
206 TLoopConfiguration *fLoopConfig; ///< If this is a bundle of memberwise streaming action, this configures the looping
208
209 void AddToOffset(Int_t delta);
210 void SetMissing();
211
215 TActionSequence *CreateSubSequence(const std::vector<Int_t> &element_ids, size_t offset);
216
217 TActionSequence *CreateSubSequence(const TIDs &element_ids, size_t offset, SequenceGetter_t create);
218 void AddToSubSequence(TActionSequence *sequence, const TIDs &element_ids, Int_t offset, SequenceGetter_t create);
219
220 void Print(Option_t * = "") const;
221
222 // Maybe owner unique_ptr
223 struct SequencePtr {
226
227 SequencePtr() = default;
228
230 from.fOwner = false;
231 }
232
234
236 if (fOwner) delete fSequence;
237 }
238
239 // Accessor to the pointee.
241 return *fSequence;
242 }
243
244 // Accessor to the pointee
246 return fSequence;
247 }
248
249 // Return true is the pointee is not nullptr.
250 operator bool() {
251 return fSequence != nullptr;
252 }
253 };
254
255 // SequenceGetter_t implementations
256
257 static SequencePtr ReadMemberWiseActionsCollectionGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
258 auto seq = info->GetReadMemberWiseActions(kTRUE);
259 return {seq, kFALSE};
260 }
262 auto seq = collectionProxy->GetConversionReadMemberWiseActions(originalClass, info->GetClassVersion());
263 return {seq, kFALSE};
264 }
265 static SequencePtr ReadMemberWiseActionsViaProxyGetter(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass * /* originalClass */) {
266 auto seq = collectionProxy->GetReadMemberWiseActions(info->GetClassVersion());
267 return {seq, kFALSE};
268 }
271 return {seq, kTRUE};
272 }
273 // Creator5() = Creator1;
274 static SequencePtr ReadMemberWiseActionsGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
275 auto seq = info->GetReadMemberWiseActions(kFALSE);
276 return {seq, kFALSE};
277 }
278
279 static SequencePtr WriteMemberWiseActionsCollectionGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
280 auto seq = info->GetWriteMemberWiseActions(kTRUE);
281 return {seq, kFALSE};
282 }
284 auto seq = collectionProxy->GetWriteMemberWiseActions();
285 return {seq, kFALSE};
286 }
289 return {seq, kTRUE};
290 }
291 // Creator5() = Creator1;
292 static SequencePtr WriteMemberWiseActionsGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
293 auto seq = info->GetWriteMemberWiseActions(kFALSE);
294 return {seq, kFALSE};
295 }
297 };
298
299}
300
301#endif // ROOT_TStreamerInfoActions
302
303
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:101
const Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassDef(name, id)
Definition Rtypes.h:325
#define BIT(n)
Definition Rtypes.h:85
XFontStruct * id
Definition TGX11.cxx:109
Buffer base class used for serializing objects.
Definition TBuffer.h:43
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
Mother of all ROOT objects.
Definition TObject.h:41
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition TObject.h:298
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:201
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:766
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.
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
Describes a persistent version of a class.
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...
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.
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)