Logo ROOT   6.16/01
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 struct SequencePtr;
177 using SequenceGetter_t = SequencePtr(*)(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *originalClass);
178
179 TActionSequence(TVirtualStreamerInfo *info, UInt_t maxdata) : fStreamerInfo(info), fLoopConfig(0) { fActions.reserve(maxdata); };
181 delete fLoopConfig;
182 }
183
184 template <typename action_t>
185 void AddAction( action_t action, TConfiguration *conf ) {
186 fActions.push_back( TConfiguredAction(action, conf) );
187 }
188 void AddAction(const TConfiguredAction &action ) {
189 fActions.push_back( action );
190 }
191
192 TVirtualStreamerInfo *fStreamerInfo; ///< StreamerInfo used to derive these actions.
193 TLoopConfiguration *fLoopConfig; ///< If this is a bundle of memberwise streaming action, this configures the looping
195
196 void AddToOffset(Int_t delta);
197 void SetMissing();
198
202 TActionSequence *CreateSubSequence(const std::vector<Int_t> &element_ids, size_t offset);
203
204 TActionSequence *CreateSubSequence(const TIDs &element_ids, size_t offset, SequenceGetter_t create);
205 void AddToSubSequence(TActionSequence *sequence, const TIDs &element_ids, Int_t offset, SequenceGetter_t create);
206
207 void Print(Option_t * = "") const;
208
209 // Maybe owner unique_ptr
210 struct SequencePtr {
213
214 SequencePtr() = default;
215
217 from.fOwner = false;
218 }
219
221
223 if (fOwner) delete fSequence;
224 }
225
226 // Accessor to the pointee.
228 return *fSequence;
229 }
230
231 // Accessor to the pointee
233 return fSequence;
234 }
235
236 // Return true is the pointee is not nullptr.
237 operator bool() {
238 return fSequence != nullptr;
239 }
240 };
241
242 // SequenceGetter_t implementations
243
244 static SequencePtr ReadMemberWiseActionsCollectionGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
245 auto seq = info->GetReadMemberWiseActions(kTRUE);
246 return {seq, kFALSE};
247 }
249 auto seq = collectionProxy->GetConversionReadMemberWiseActions(originalClass, info->GetClassVersion());
250 return {seq, kFALSE};
251 }
252 static SequencePtr ReadMemberWiseActionsViaProxyGetter(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass * /* originalClass */) {
253 auto seq = collectionProxy->GetReadMemberWiseActions(info->GetClassVersion());
254 return {seq, kFALSE};
255 }
258 return {seq, kTRUE};
259 }
260 // Creator5() = Creator1;
261 static SequencePtr ReadMemberWiseActionsGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
262 auto seq = info->GetReadMemberWiseActions(kFALSE);
263 return {seq, kFALSE};
264 }
265
266 static SequencePtr WriteMemberWiseActionsCollectionGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
267 auto seq = info->GetWriteMemberWiseActions(kTRUE);
268 return {seq, kFALSE};
269 }
271 auto seq = collectionProxy->GetWriteMemberWiseActions();
272 return {seq, kFALSE};
273 }
276 return {seq, kTRUE};
277 }
278 // Creator5() = Creator1;
279 static SequencePtr WriteMemberWiseActionsGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
280 auto seq = info->GetWriteMemberWiseActions(kFALSE);
281 return {seq, kFALSE};
282 }
284 };
285
286}
287
288#endif // ROOT_TStreamerInfoActions
289
290
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:324
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
Mother of all ROOT objects.
Definition: TObject.h:37
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.h:271
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 *)
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 *)
TActionSequence(TVirtualStreamerInfo *info, UInt_t maxdata)
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.
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
void swap(nlohmann::json &j1, nlohmann::json &j2) noexcept(is_nothrow_move_constructible< nlohmann::json >::value and is_nothrow_move_assignable< nlohmann::json >::value)
exchanges the values of two JSON objects
Definition: json.hpp:12929
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)