Logo ROOT   6.12/07
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 
27 namespace 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 
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:
55  TVirtualCollectionProxy *fProxy = nullptr;
56  public:
57  TLoopConfiguration() = default;
58  TLoopConfiguration(TVirtualCollectionProxy *proxy) : fProxy(proxy) {}
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); }
65  virtual TVirtualCollectionProxy* GetCollectionProxy() const { return fProxy; }
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(0), fConfiguration(0) {}
86  TConfiguredAction(const TConfiguredAction &rval) : TObject(rval), fAction(rval.fAction), fConfiguration(rval.fConfiguration)
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 
102  TConfiguredAction(TStreamerInfoAction_t action, TConfiguration *conf) : fAction(action), fConfiguration(conf)
103  {
104  // Usual constructor.
105  }
106  TConfiguredAction(TStreamerInfoVecPtrLoopAction_t action, TConfiguration *conf) : fVecPtrLoopAction(action), fConfiguration(conf)
107  {
108  // Usual constructor.
109  }
110  TConfiguredAction(TStreamerInfoLoopAction_t action, TConfiguration *conf) : fLoopAction(action), fConfiguration(conf)
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) {}
146  if (fOwnOnfileObject)
147  delete fOnfileObject;
148  }
149  TStreamerInfo *fInfo = nullptr; ///< Not owned.
150  TVirtualArray *fOnfileObject = nullptr;
151  Bool_t fOwnOnfileObject = kFALSE;
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  }
165  Int_t fElemID = -1;
166  TStreamerElement *fElement = nullptr;
167  TStreamerInfo *fInfo = nullptr;
168  std::unique_ptr<TNestedIDs> fNestedIDs;
169  };
170 
171  typedef std::vector<TConfiguredAction> ActionContainer_t;
172  class TActionSequence : public TObject {
174  public:
175  struct SequencePtr;
176  using SequenceGetter_t = SequencePtr(*)(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *originalClass);
177 
178  TActionSequence(TVirtualStreamerInfo *info, UInt_t maxdata) : fStreamerInfo(info), fLoopConfig(0) { fActions.reserve(maxdata); };
180  delete fLoopConfig;
181  }
182 
183  template <typename action_t>
184  void AddAction( action_t action, TConfiguration *conf ) {
185  fActions.push_back( TConfiguredAction(action, conf) );
186  }
187  void AddAction(const TConfiguredAction &action ) {
188  fActions.push_back( action );
189  }
190 
191  TVirtualStreamerInfo *fStreamerInfo; ///< StreamerInfo used to derive these actions.
192  TLoopConfiguration *fLoopConfig; ///< If this is a bundle of memberwise streaming action, this configures the looping
193  ActionContainer_t fActions;
194 
195  void AddToOffset(Int_t delta);
196 
197  TActionSequence *CreateCopy();
198  static TActionSequence *CreateReadMemberWiseActions(TVirtualStreamerInfo *info, TVirtualCollectionProxy &proxy);
199  static TActionSequence *CreateWriteMemberWiseActions(TVirtualStreamerInfo *info, TVirtualCollectionProxy &proxy);
200  TActionSequence *CreateSubSequence(const std::vector<Int_t> &element_ids, size_t offset);
201 
202  TActionSequence *CreateSubSequence(const TIDs &element_ids, size_t offset, SequenceGetter_t create);
203  void AddToSubSequence(TActionSequence *sequence, const TIDs &element_ids, Int_t offset, SequenceGetter_t create);
204 
205  void Print(Option_t * = "") const;
206 
207  // Maybe owner unique_ptr
208  struct SequencePtr {
210  Bool_t fOwner = kFALSE;
211 
212  SequencePtr() = default;
213  SequencePtr(TStreamerInfoActions::TActionSequence *sequence, Bool_t owner) : fSequence(sequence), fOwner(owner) {}
214 
216  if (fOwner) delete fSequence;
217  }
218 
219  // Accessor to the pointee.
221  return *fSequence;
222  }
223 
224  // Accessor to the pointee
226  return fSequence;
227  }
228 
229  // Return true is the pointee is not nullptr.
230  operator bool() {
231  return fSequence != nullptr;
232  }
233  };
234 
235  // SequenceGetter_t implementations
236 
237  static SequencePtr ReadMemberWiseActionsCollectionGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
238  auto seq = info->GetReadMemberWiseActions(kTRUE);
239  return {seq, kFALSE};
240  }
242  auto seq = collectionProxy->GetConversionReadMemberWiseActions(originalClass, info->GetClassVersion());
243  return {seq, kFALSE};
244  }
245  static SequencePtr ReadMemberWiseActionsViaProxyGetter(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass * /* originalClass */) {
246  auto seq = collectionProxy->GetReadMemberWiseActions(info->GetClassVersion());
247  return {seq, kFALSE};
248  }
249  static SequencePtr ReadMemberWiseActionsCollectionCreator(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass * /* originalClass */) {
251  return {seq, kTRUE};
252  }
253  // Creator5() = Creator1;
254  static SequencePtr ReadMemberWiseActionsGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
255  auto seq = info->GetReadMemberWiseActions(kFALSE);
256  return {seq, kFALSE};
257  }
258 
259  static SequencePtr WriteMemberWiseActionsCollectionGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
260  auto seq = info->GetWriteMemberWiseActions(kTRUE);
261  return {seq, kFALSE};
262  }
264  auto seq = collectionProxy->GetWriteMemberWiseActions();
265  return {seq, kFALSE};
266  }
267  static SequencePtr WriteMemberWiseActionsCollectionCreator(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass * /* originalClass */) {
269  return {seq, kTRUE};
270  }
271  // Creator5() = Creator1;
272  static SequencePtr WriteMemberWiseActionsGetter(TStreamerInfo *info, TVirtualCollectionProxy * /* collectionProxy */, TClass * /* originalClass */) {
273  auto seq = info->GetWriteMemberWiseActions(kFALSE);
274  return {seq, kFALSE};
275  }
277  };
278 
279 }
280 
281 #endif // ROOT_TStreamerInfoActions
282 
283 
Describe Streamer information for one class version.
Definition: TStreamerInfo.h:43
std::vector< TConfiguredAction > ActionContainer_t
TVirtualStreamerInfo * fInfo
TStreamerInfo form which the action is derived.
static SequencePtr WriteMemberWiseActionsCollectionCreator(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *)
virtual TStreamerInfoActions::TActionSequence * GetReadMemberWiseActions(Int_t version)=0
TNestedIDs(TStreamerInfo *info, Int_t offset)
std::vector< TIDNode > TIDs
TLoopConfiguration * fLoopConfig
If this is a bundle of memberwise streaming action, this configures the looping.
virtual TStreamerInfoActions::TActionSequence * GetConversionReadMemberWiseActions(TClass *oldClass, Int_t version)=0
TStreamerInfoActions::TActionSequence * operator->() const
const char Option_t
Definition: RtypesCore.h:62
void swap(TDirectoryEntry &e1, TDirectoryEntry &e2) noexcept
void AddAction(action_t action, TConfiguration *conf)
virtual void PrintDebug(TBuffer &buffer, void *object) const
Int_t operator()(TBuffer &buffer, void *start_collection, const void *end_collection) const
TConfiguredAction(const TConfiguredAction &rval)
TActionSequence(TVirtualStreamerInfo *info, UInt_t maxdata)
TConfiguredAction(TStreamerInfoLoopAction_t action, TConfiguration *conf)
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
TLoopConfiguration(TVirtualCollectionProxy *proxy)
UInt_t fElemId
Identifier of the TStreamerElement.
static SequencePtr ReadMemberWiseActionsViaProxyGetter(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *)
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void AddAction(const TConfiguredAction &action)
static TActionSequence * CreateReadMemberWiseActions(TVirtualStreamerInfo *info, TVirtualCollectionProxy &proxy)
Create the bundle of the actions necessary for the streaming memberwise of the content described by &#39;...
TVirtualCollectionProxy::Next_t Next_t
static SequencePtr ConversionReadMemberWiseActionsViaProxyGetter(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *originalClass)
static SequencePtr WriteMemberWiseActionsCollectionGetter(TStreamerInfo *info, TVirtualCollectionProxy *, TClass *)
#define ClassDef(name, id)
Definition: Rtypes.h:320
TStreamerInfoActions::TActionSequence & operator*() const
TConfiguredAction(TStreamerInfoVecPtrLoopAction_t action, TConfiguration *conf)
static SequencePtr WriteMemberWiseActionsGetter(TStreamerInfo *info, TVirtualCollectionProxy *, TClass *)
Int_t(* TStreamerInfoLoopAction_t)(TBuffer &buf, void *iter, const void *end, const TLoopConfiguration *loopconf, const TConfiguration *conf)
std::unique_ptr< TNestedIDs > fNestedIDs
TConfiguredAction & operator=(const TConfiguredAction &rval)
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.h:271
Base class of the Configurations for the member wise looping routines.
static SequencePtr ReadMemberWiseActionsCollectionGetter(TStreamerInfo *info, TVirtualCollectionProxy *, TClass *)
SequencePtr(TStreamerInfoActions::TActionSequence *sequence, Bool_t owner)
Int_t(* TStreamerInfoAction_t)(TBuffer &buf, void *obj, const TConfiguration *conf)
static SequencePtr ReadMemberWiseActionsGetter(TStreamerInfo *info, TVirtualCollectionProxy *, TClass *)
TConfiguration(TVirtualStreamerInfo *info, UInt_t id, TCompInfo_t *compinfo, Int_t offset)
TStreamerInfoVecPtrLoopAction_t fVecPtrLoopAction
virtual TVirtualCollectionProxy * GetCollectionProxy() const
static SequencePtr WriteMemberWiseActionsViaProxyGetter(TStreamerInfo *, TVirtualCollectionProxy *collectionProxy, TClass *)
TStreamerInfo::TCompInfo_t TCompInfo_t
Wrapper around an object and giving indirect access to its content even if the object is not of a cla...
Definition: TVirtualArray.h:26
Int_t fOffset
Offset within the object.
static TActionSequence * CreateWriteMemberWiseActions(TVirtualStreamerInfo *info, TVirtualCollectionProxy &proxy)
Create the bundle of the actions necessary for the streaming memberwise of the content described by &#39;...
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual TStreamerInfoActions::TActionSequence * GetWriteMemberWiseActions()=0
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
Int_t operator()(TBuffer &buffer, void *object) const
TStreamerInfoActions::TActionSequence * GetReadMemberWiseActions(Bool_t forCollection)
static SequencePtr ReadMemberWiseActionsCollectionCreator(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *)
Int_t(* TStreamerInfoVecPtrLoopAction_t)(TBuffer &buf, void *iter, const void *end, const TConfiguration *conf)
const Bool_t kFALSE
Definition: RtypesCore.h:88
Int_t operator()(TBuffer &buffer, void *start_collection, const void *end_collection, const TLoopConfiguration *loopconf) const
Mother of all ROOT objects.
Definition: TObject.h:37
TConfiguration(TVirtualStreamerInfo *info, UInt_t id, TCompInfo_t *compinfo, Int_t offset, UInt_t length)
SequencePtr(*)(TStreamerInfo *info, TVirtualCollectionProxy *collectionProxy, TClass *originalClass) SequenceGetter_t
Int_t GetClassVersion() const
void *(* Next_t)(void *iter, const void *end)
Abstract Interface class describing Streamer information for one class.
TConfiguredAction(TStreamerInfoAction_t action, TConfiguration *conf)
Base class of the Configurations.
const Bool_t kTRUE
Definition: RtypesCore.h:87
UInt_t fLength
Number of element in a fixed length array.
TStreamerInfoActions::TActionSequence * GetWriteMemberWiseActions(Bool_t forCollection)
TIDNode(TStreamerInfo *info, Int_t offset)
TVirtualStreamerInfo * fStreamerInfo
StreamerInfo used to derive these actions.
TCompInfo_t * fCompInfo
Access to compiled information (for legacy code)