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:
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:
85 TConfiguredAction() : fAction(nullptr), fConfiguration(nullptr) {}
87 {
88 // WARNING: Technically this is a move constructor ...
89 const_cast<TConfiguredAction&>(rval).fConfiguration = nullptr;
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 ClassDefOverride(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;
145 ~TNestedIDs();
146
147 TStreamerInfo *fInfo = nullptr; ///< Not owned.
152 };
153
154 // A 'node' in the list of StreamerElement ID, either
155 // the index of the element in the current streamerInfo
156 // or a set of unfolded/extracted StreamerElement for a sub-object.
157 struct TIDNode {
158 TIDNode() = default;
159 TIDNode(Int_t id) : fElemID(id), fElement(nullptr), fInfo(nullptr) {}
160 TIDNode(TStreamerInfo *info, Int_t offset) : fElemID(-1), fElement(nullptr), fInfo(nullptr) {
161 fNestedIDs = std::make_unique<TNestedIDs>(info, offset);
162 }
166 std::unique_ptr<TNestedIDs> fNestedIDs;
167 };
168
169 inline TNestedIDs::TNestedIDs(TStreamerInfo *info, Int_t offset) : fInfo(info), fOffset(offset) {}
172 delete fOnfileObject;
173 }
174
175
176 typedef std::vector<TConfiguredAction> ActionContainer_t;
177 class TActionSequence : public TObject {
179 public:
180 enum class EStatusBits {
182 };
183
184 struct SequencePtr;
185 using SequenceGetter_t = SequencePtr(*)(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *originalClass);
186
188 : fStreamerInfo(info), fLoopConfig(nullptr)
189 {
190 if (isForVecPtr)
192 fActions.reserve(maxdata);
193 };
194 ~TActionSequence() override {
195 delete fLoopConfig;
196 }
197
198 template <typename action_t>
199 void AddAction( action_t action, TConfiguration *conf ) {
200 fActions.emplace_back( action, conf );
201 }
202 void AddAction(const TConfiguredAction &action ) {
203 fActions.push_back( action );
204 }
205
208 }
209
210 TVirtualStreamerInfo *fStreamerInfo; ///< StreamerInfo used to derive these actions.
211 TLoopConfiguration *fLoopConfig; ///< If this is a bundle of memberwise streaming action, this configures the looping
213
214 void AddToOffset(Int_t delta);
215 void SetMissing();
216
220 TActionSequence *CreateSubSequence(const std::vector<Int_t> &element_ids, size_t offset);
221
222 TActionSequence *CreateSubSequence(const TIDs &element_ids, size_t offset, SequenceGetter_t create);
223 void AddToSubSequence(TActionSequence *sequence, const TIDs &element_ids, Int_t offset, SequenceGetter_t create);
224
225 void Print(Option_t * = "") const override;
226
227 // Maybe owner unique_ptr
228 struct SequencePtr {
231
232 SequencePtr() = default;
233
235 from.fOwner = false;
236 }
237
239
241 if (fOwner) delete fSequence;
242 }
243
244 // Accessor to the pointee.
246 return *fSequence;
247 }
248
249 // Accessor to the pointee
251 return fSequence;
252 }
253
254 // Return true is the pointee is not nullptr.
255 operator bool() {
256 return fSequence != nullptr;
257 }
258 };
259
260 // SequenceGetter_t implementations
261
262 static SequencePtr ReadMemberWiseActionsCollectionGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
263 auto seq = info->GetReadMemberWiseActions(kTRUE);
264 return {seq, kFALSE};
265 }
267 auto seq = collectionProxy->GetConversionReadMemberWiseActions(originalClass, info->GetClassVersion());
268 return {seq, kFALSE};
269 }
270 static SequencePtr ReadMemberWiseActionsViaProxyGetter(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass * /* originalClass */) {
271 auto seq = collectionProxy->GetReadMemberWiseActions(info->GetClassVersion());
272 return {seq, kFALSE};
273 }
276 return {seq, kTRUE};
277 }
278 // Creator5() = Creator1;
279 static SequencePtr ReadMemberWiseActionsGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
280 auto seq = info->GetReadMemberWiseActions(kFALSE);
281 return {seq, kFALSE};
282 }
283
284 static SequencePtr WriteMemberWiseActionsCollectionGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
285 auto seq = info->GetWriteMemberWiseActions(kTRUE);
286 return {seq, kFALSE};
287 }
289 auto seq = collectionProxy->GetWriteMemberWiseActions();
290 return {seq, kFALSE};
291 }
294 return {seq, kTRUE};
295 }
296 // Creator5() = Creator1;
297 static SequencePtr WriteMemberWiseActionsGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
298 auto seq = info->GetWriteMemberWiseActions(kFALSE);
299 return {seq, kFALSE};
300 }
302 };
303
304}
305
306#endif // ROOT_TStreamerInfoActions
307
308
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define BIT(n)
Definition Rtypes.h:90
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
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:81
Mother of all ROOT objects.
Definition TObject.h:41
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition TObject.h:296
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:199
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:798
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 '...
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)
void Print(Option_t *="") const override
This method must be overridden when a class wants to print itself.
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.
Int_t GetClassVersion() const override
TStreamerInfoActions::TActionSequence * GetWriteMemberWiseActions(Bool_t forCollection)
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...
Defines a common interface to inspect/change the contents of an object that represents a collection.
virtual TStreamerInfoActions::TActionSequence * GetReadMemberWiseActions(Int_t version)=0
virtual TStreamerInfoActions::TActionSequence * GetWriteMemberWiseActions()=0
void *(* Next_t)(void *iter, const void *end)
iter and end should be pointers to an iterator to be incremented and an iterator that points to the e...
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